superbosu Posted January 31, 2013 Share Posted January 31, 2013 (edited) Hi all, I have a big question and I need some help. in the attached file there are the data when a process has gone down. I need to take for a specific month (for example december 2012), day by day, the number of minutes that the process is unavailable and put them into a new txt file in the following way: 09.12.2012 process unavailable for 420 minutes 15.12.2012 process unavailable for "??" minutes 21.12.2012 process unavailable for "??" minutes 22.12.2012 process unavailable for "??" minutes 23.12.2012 process unavailable for "??" minutes ....... Yes I know, this is difficult exercise and maybe I'm asking too much but I hope that someone can help me. thanks in advanceavailable.txt Edited January 31, 2013 by superbosu Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 31, 2013 Moderators Share Posted January 31, 2013 (edited) superbosu,Looks like fun - but complicated. Be patient. M23Edit: Go away for a few minutes to prepare dinner and someone spoils my fun! Now I am going to sulk for a while! But not really! Nice work! ) Edited January 31, 2013 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
jdelaney Posted January 31, 2013 Share Posted January 31, 2013 (edited) this should do it...i noticed that sometimes it's down for 0 seconds? anyways, you can logically not write if that is the case, and you want to exclude it. expandcollapse popup#include <Array.au3> #include <Date.au3> #include <File.au3> $file = @DesktopDir & "\raw.txt" $text = FileRead ($file) $text = StringRegExpReplace ($text, "Available.*\s", "") $text = StringRegExpReplace ($text, "Unavailable\s", "") ;ConsoleWrite($text) $text = StringRegExpReplace ($text, "(\d{2})\.(\d{2})\.(\d{4})", "$3/$2/$1") $aData = StringSplit ($text, @CRLF, 2) Dim $aFormatted[UBound($aData)][2] ; $aFormatted will include the date, and the seconds unavail For $i = 0 To UBound($aData)-1 If StringLen ($aData[$i]) >0 Then $aTemp = StringRegExp($aData[$i], "(.*)\s\-\s(.*)", 3) ;ConsoleWrite($aTemp[0] & " " & $aTemp[1] & @CRLF) $aDate = StringRegExp($aTemp[0],"(.*)\s",3) $aFormatted[$i][0]=$aDate[0] $diff = _DateDiff ("s",$aTemp[0], $aTemp[1]) If @error Then ConsoleWrite ( $aTemp[0] & " " & $aTemp[1] & " " & @error & @CRLF) $aFormatted[$i][1]= $diff EndIf Next _FileCreate(@DesktopDir & "\formatted.txt") $file = FileOpen(@DesktopDir & "\formatted.txt",2) $lastdate="" $iSumSeconds = 0 $iCounter = 0 For $i = 0 To UBound ($aFormatted)-1 If StringLen ($aFormatted[$i][0]) >0 Then If $aFormatted[$i][0] = $lastdate Then $iSumSeconds += $aFormatted[$i][1] $iCounter += 1 Else If $lastDate <> "" Then $formatteddate = StringRegExpReplace($lastdate, "(\d{4})/(\d{2})/(\d{2})", "$3\.$2\.$1") If $iCounter <> 0 Then FileWrite($file, $formatteddate & " process unavailable for " & Round($iSumSeconds/60,2) & " minutes" & @CRLF) EndIf $iCounter = 1 EndIf $iSumSeconds = $aFormatted[$i][1] $lastdate = $aFormatted[$i][0] EndIf EndIf Next oops, the 0 seconds down time was a logical flaw, updated also, sorry Melba Edited January 31, 2013 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
superbosu Posted January 31, 2013 Author Share Posted January 31, 2013 WOW jdelaney you did it so fast!!! tnx a lot for your time!I tested your script with the file attached with only one month, but I think that in this case didn't works at 100%For example with one month (new attached file) the result is:09.12.2012 process unavailable for 91.52 minutes15.12.2012 process unavailable for 0.55 minutes The script did the job but didn't work when there are more then one unavailable before an available: Unavailable 09.12.2012 04:47:58 - 09.12.2012 04:47:58 -> _DateDiff = 0 sAvailable 09.12.2012 04:49:44 - 09.12.2012 10:20:46Unavailable 09.12.2012 10:21:10 - 09.12.2012 10:53:25 -> _DateDiff = 1935 sUnavailable 09.12.2012 11:39:53 - 09.12.2012 12:38:53 -> _DateDiff = 3540 s but there is also to add 2788s (10:53:25 - 11:39:53)Unavailable 09.12.2012 15:42:33 - 09.12.2012 15:42:49 -> _DateDiff = 16s also there is missing 11020s (12:38:53 -15:42:33)Available 09.12.2012 15:43:00 - 15.12.2012 11:02:57 so for day 09.12.2012 the result should be:09.12.2012 process unavailable for 321,65 minutes (0 + 1935+2788+ 3540 +11020 + 16 = 19299s/60= 321,65 minutes)there are problems also when the unavailable duration is more then 1 day :Unavailable 21.12.2012 18:12:14 - 23.12.2012 09:52:01Available 23.12.2012 09:53:01 - 31.01.2013 17:37:11the script unfortunately didn't write the result for this case:it would be nice if it exceeds 24 hours also the day after it will be written. in this case:21.12.2012 process unavailable for 347,77 minutes diff(21.12.2012 18:12:14 - 22.12.2012 00:00:00) 22.12.2012 process unavailable for 1440 minutes diff (22.12.2012 00:00:00 - 23.12.2012 00:00:00)23.12.2012 process unavailable for 592,02 minutes diff (23.12.2012 00:00:00 - 23.12.2012 09:52:01)is this impossible to do? :S for me it is... I'm in your hand expertsavailable.txt Link to comment Share on other sites More sharing options...
jdelaney Posted January 31, 2013 Share Posted January 31, 2013 (edited) update to this to grab the last record (notice the comments): For $i = 0 To UBound ($aFormatted)-1 ; If StringLen ($aFormatted[$i][0]) >0 Then If $aFormatted[$i][0] = $lastdate Then $iSumSeconds += $aFormatted[$i][1] $iCounter += 1 Else If $lastDate <> "" Then $formatteddate = StringRegExpReplace($lastdate, "(\d{4})/(\d{2})/(\d{2})", "$3\.$2\.$1") If $i>0 Then FileWrite($file, $formatteddate & " process unavailable for " & Round($iSumSeconds/60,2) & " minutes" & @CRLF) EndIf $iCounter = 1 EndIf $iSumSeconds = $aFormatted[$i][1] $lastdate = $aFormatted[$i][0] EndIf ; EndIf Next yes, the days piece is possible, will have to do that later though. Need to add an additional element to the array (the begin time) logically determine if it goes past midnight...if so, only include seconds from start till midnight, add an additional array element right below it with the remainder of seconds, so the loop can conditionally add that new time to the file Edited January 31, 2013 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
kylomas Posted January 31, 2013 Share Posted January 31, 2013 suprbosu, I trimmed jdelaney's example a bit. Run the following and it will display an array with unavailability in minutes after the entry. If this is the result you are looking for then just use string functions to format an output file however you like. #include <Array.au3> #include <Date.au3> #include <File.au3> local $text = fileread(@DesktopDir & "\available2.txt") $text = StringRegExpReplace($text, "(\d{2})\.(\d{2})\.(\d{4})", "$3/$2/$1") $aData = StringSplit($text, @CRLF, 2) For $i = 0 To UBound($aData) - 1 If StringLen($aData[$i]) > 0 Then if stringleft($aData[$i],11) = 'Unavailable' then $aTemp = StringRegExp($aData[$i], "(\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2})", 3) if @error = 1 then ConsoleWrite('No matches' & @LF) if @error = 2 then ConsoleWrite('Bad pattern' & @LF) $diff = _DateDiff("s", $aTemp[0], $aTemp[1]) If @error Then ConsoleWrite($aTemp[0] & " " & $aTemp[1] & " " & @error & @CRLF) $aData[$i] = $aData[$i] & stringformat(' [%08.2f]',round($diff/60,2)) & ' minutes ' endif EndIf Next _arraydisplay($aData) kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
jdelaney Posted February 1, 2013 Share Posted February 1, 2013 (edited) All set, if the seconds + start time> midnight, then I carry the remainding seconds to the next day, where if it happens again, it continues to add to the next day (max minutes a day is 24*60)expandcollapse popup#include <Array.au3> #include <Date.au3> #include <File.au3> $file = @DesktopDir & "\raw.txt" $text = FileRead ($file) $text = StringRegExpReplace ($text, "Available.*\s", "") $text = StringRegExpReplace ($text, "Unavailable\s", "") ;ConsoleWrite($text) $text = StringRegExpReplace ($text, "(\d{2})\.(\d{2})\.(\d{4})", "$3/$2/$1") $aData = StringSplit ($text, @CRLF, 2) ;_ArrayDisplay($aData) Dim $aFormatted[UBound($aData)][3] ; $aFormatted will include the date, and the seconds unavail For $i = 0 To UBound($aData)-1 If StringLen ($aData[$i]) >0 Then $aTemp = StringRegExp($aData[$i], "(.*)\s\-\s(.*)", 3) ;ConsoleWrite($aTemp[0] & " " & $aTemp[1] & @CRLF) $aDate = StringRegExp($aTemp[0],"(.*)\s",3) $aBeginTime = StringRegExp($aTemp[0],"\s(.*)",3) $aFormatted[$i][0]=$aDate[0] $diff = _DateDiff ("s",$aTemp[0], $aTemp[1]) If @error Then ConsoleWrite ( $aTemp[0] & " " & $aTemp[1] & " " & @error & @CRLF) $aFormatted[$i][1]= $diff $aFormatted[$i][2]=$aBeginTime[0] EndIf Next _FileCreate(@DesktopDir & "\formatted.txt") $file = FileOpen(@DesktopDir & "\formatted.txt",2) $lastdate="" $iSumSeconds = 0 $iCounter = 0 $uBound = UBound ($aFormatted)-1 ConsoleWrite("UBOUND=" & $uBound & @CRLF) $i = 0 While True ; check if runs over 24 If _DateDiff('D', $aFormatted[$i][0], _DateAdd ('s',$aFormatted[$i][1],$aFormatted[$i][0] & " " & $aFormatted[$i][2]))> 0 Then ;ConsoleWrite($aFormatted[$i][0] & " " & $aFormatted[$i][1] & " " & $aFormatted[$i][2] & @CRLF) $begin = $aFormatted[$i][1] $seconds = _DateDiff('s',_DateAdd ("D",-1,$aFormatted[$i][0]) & " " & $aFormatted[$i][2], $aFormatted[$i][0] & " 00:00:00") $aFormatted[$i][1] = $seconds Dim $temp[3]=[_DateAdd("D",1,$aFormatted[$i][0]),$begin-$seconds,"00:00:00"] $aFormatted = ArrayAdd2d ($aFormatted, $i+1, $temp) $uBound+=1 ConsoleWrite("UBOUND=" & $uBound & @CRLF) EndIf ; If StringLen ($aFormatted[$i][0]) >0 Then If $aFormatted[$i][0] = $lastdate Then $iSumSeconds += $aFormatted[$i][1] $iCounter += 1 Else If $lastDate <> "" Then $formatteddate = StringRegExpReplace($lastdate, "(\d{4})/(\d{2})/(\d{2})", "$3\.$2\.$1") If $i>0 Then ; Check if the total minutes of the current itteration pushes the date past midnight...if so, only add FileWrite($file, $formatteddate & " process unavailable for " & Round($iSumSeconds/60,2) & " minutes" & @CRLF) ConsoleWrite($formatteddate & " process unavailable for " & Round($iSumSeconds/60,2) & " minutes" & @CRLF) EndIf $iCounter = 1 EndIf $iSumSeconds = $aFormatted[$i][1] $lastdate = $aFormatted[$i][0] EndIf ; EndIf ConsoleWrite($i & @CRLF) $i += 1 If $i = UBound($aFormatted) Then ExitLoop WEnd Func ArrayAdd2d ($sCallersArray, $iAddAfter, $aDataToAdd) dim $newArray[UBound($sCallersArray)+1][UBound($sCallersArray,2)] $iCurrent = 0 For $i = 0 To UBound ($sCallersArray)-1 If $i >= $iAddAfter Then If $i = $iAddAfter Then For $j = 0 To UBound($aDataToAdd)-1 $newArray[$i][$j] = $aDataToAdd[$j] Next EndIf For $j = 0 To UBound($sCallersArray,2)-1 $newArray[$i+1][$j] = $sCallersArray[$i][$j] Next Else For $j = 0 To UBound($sCallersArray,2)-1 $newArray[$i][$j] = $sCallersArray[$i][$j] Next EndIf Next Return $newArray EndFuncfileoutput:09.12.2012 process unavailable for 91.52 minutes15.12.2012 process unavailable for 0.55 minutes21.12.2012 process unavailable for 347.77 minutes22.12.2012 process unavailable for 1440 minutes23.12.2012 process unavailable for 592.02 minutes Edited February 1, 2013 by jdelaney superbosu 1 IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
superbosu Posted February 1, 2013 Author Share Posted February 1, 2013 jdelaney !!! realy impressive it works like a charm! you worked so hard to help me, tnx a lot again.the only thing that I have to fix is the unavailable time that is not reported:how the log works:If the service notices that the last update to ‘available.log’ is older than 60 secs (e.g. due to computer shutdown), it will always start a new line in ‘available.log’, for example you may see:Unavailable 09.12.2012 10:21:10 - 09.12.2012 10:53:25Unavailable 09.12.2012 11:39:53 - 09.12.2012 12:38:53Unavailable 09.12.2012 15:42:33 - 09.12.2012 15:42:49instead ofUnavailable 09.12.2012 10:21:10 – 09.12.2012 15:42:49I think that a possible way is to read the available.txt file with _FileReadToArray before start the script and join the concatenates unavailable date in one (Unavailable 09.12.2012 10:21:10 – 09.12.2012 15:42:49)But I think that also this thing is not so easy to do ... Link to comment Share on other sites More sharing options...
jdelaney Posted February 1, 2013 Share Posted February 1, 2013 (edited) Yep, thank you for the brain teaser; and it doesn't take long. okay, I see what youre saying, where unavailable logs that are in sequence should be combined. That would require a little rework, since I was initially just stripping out lines. Try this out: expandcollapse popup#include <Array.au3> #include <Date.au3> #include <File.au3> $file = @DesktopDir & "\raw.txt" $text = FileRead($file) dim $array[2][2]=[[1,2],[3,4]] Dim $aText[1] _FileReadToArray($file, $aText) Dim $aTemp[UBound($aText) - 1][2] ; Split out the file to begin time, and end time For $i = 1 To UBound($aText) - 1 $aTempSplit = StringRegExp($aText[$i], "(.*)\s\-\s(.*)", 3) $aTemp[$i - 1][0] = $aTempSplit[0] $aTemp[$i - 1][1] = $aTempSplit[1] Next ;_ArrayDisplay($aTemp) ; loop through, and update the end time of first instance of Unavail, with the end time of the last consecutive Unavil For $i = 0 To UBound($aTemp) - 1 If $i = UBound($aTemp) Then ExitLoop If StringRegExp($aTemp[$i][0], "Avail", 0) Then ContinueLoop $tempEnd = "" ; Sub loop For $j = $i + 1 To UBound($aTemp) - 1 If StringRegExp($aTemp[$j][0], "Avail", 0) Then ExitLoop $tempEnd = $aTemp[$j][1] $aTemp = ArrayDelete2d($aTemp, $j) $j-=1 ;~ If $j = UBound($aTemp) Then ExitLoop ;~ _ArrayDisplay($aTemp) Next If $tempEnd <> "" Then $aTemp[$i][1] = $tempEnd EndIf ;_ArrayDisplay($aTemp) If $i = UBound($aTemp) Then ExitLoop Next ; Final setup, to remove the Availables For $i = UBound($aTemp)-1 To 0 Step -1 If StringRegExp($aTemp[$i][0], "Avail", 0) Then $aTemp = ArrayDelete2d($aTemp, $i) ContinueLoop EndIf $aTemp[$i][0] = StringRegExpReplace($aTemp[$i][0], "Unavailable\s", "") $aTemp[$i][0] = StringRegExpReplace($aTemp[$i][0], "(\d{2})\.(\d{2})\.(\d{4})", "$3/$2/$1") $aTemp[$i][1] = StringRegExpReplace($aTemp[$i][1], "(\d{2})\.(\d{2})\.(\d{4})", "$3/$2/$1") Next Dim $aFormatted[UBound($aTemp)][3] ; $aFormatted will include the date, and the seconds unavail For $i = 0 To UBound($aTemp) - 1 ; begin date $aDate = StringRegExp($aTemp[$i][0], "(.*)\s", 3) $aFormatted[$i][0] = $aDate[0] ; Time Diff in sec $aFormatted[$i][1] = _DateDiff("s", $aTemp[$i][0], $aTemp[$i][1]) ; begin time $aBeginTime = StringRegExp($aTemp[$i][0], "\s(.*)", 3) $aFormatted[$i][2] = $aBeginTime[0] Next _FileCreate(@DesktopDir & "\formatted.txt") $file = FileOpen(@DesktopDir & "\formatted.txt", 2) $lastdate = "" $iSumSeconds = 0 $i = 0 $iUbound = UBound($aFormatted)-1 $counter = 0 While True ; check if runs over 24 If _DateDiff('D', $aFormatted[$i][0], _DateAdd('s', $aFormatted[$i][1], $aFormatted[$i][0] & " " & $aFormatted[$i][2])) > 0 Then ;ConsoleWrite($aFormatted[$i][0] & " " & $aFormatted[$i][1] & " " & $aFormatted[$i][2] & @CRLF) $begin = $aFormatted[$i][1] $seconds = _DateDiff('s', _DateAdd("D", -1, $aFormatted[$i][0]) & " " & $aFormatted[$i][2], $aFormatted[$i][0] & " 00:00:00") $aFormatted[$i][1] = $seconds Dim $temp[3] = [_DateAdd("D", 1, $aFormatted[$i][0]), $begin - $seconds, "00:00:00"] $aFormatted = ArrayAdd2d($aFormatted, $i + 1, $temp) $iUbound = UBound($aFormatted)-1 EndIf ; If StringLen ($aFormatted[$i][0]) >0 Then If $aFormatted[$i][0] = $lastdate Then $iSumSeconds += $aFormatted[$i][1] $counter += 1 Else If $lastdate <> "" Then $formatteddate = StringRegExpReplace($lastdate, "(\d{4})/(\d{2})/(\d{2})", "$3\.$2\.$1") If $i > 0 Then ; Check if the total minutes of the current itteration pushes the date past midnight...if so, only add FileWrite($file, $formatteddate & " process unavailable for " & Round($iSumSeconds / 60, 2) & " minutes" & @CRLF) ConsoleWrite($formatteddate & " process unavailable for " & Round($iSumSeconds / 60, 2) & " minutes" & @CRLF) $counter = 0 EndIf EndIf $iSumSeconds = $aFormatted[$i][1] $lastdate = $aFormatted[$i][0] EndIf ; EndIf ConsoleWrite($i & @CRLF) If $i = $iUbound Then If $counter = 0 Then $iSumSeconds += $aFormatted[$i][1] $formatteddate = StringRegExpReplace($lastdate, "(\d{4})/(\d{2})/(\d{2})", "$3\.$2\.$1") FileWrite($file, $formatteddate & " process unavailable for " & Round($iSumSeconds / 60, 2) & " minutes" & @CRLF) EndIf ExitLoop EndIf $i += 1 WEnd Func ArrayAdd2d($sCallersArray, $iAddAfter, $aDataToAdd) Dim $newArray[UBound($sCallersArray) + 1][UBound($sCallersArray, 2)] If $iAddAfter > UBound($sCallersArray)-1 Then For $j = 0 To UBound($aDataToAdd) - 1 $newArray[UBound($newArray)-1][$j] = $aDataToAdd[$j] Next EndIf $iCurrent = 0 For $i = 0 To UBound($sCallersArray) - 1 If $i >= $iAddAfter Then If $i = $iAddAfter Then For $j = 0 To UBound($aDataToAdd) - 1 $newArray[$i][$j] = $aDataToAdd[$j] Next EndIf For $j = 0 To UBound($sCallersArray, 2) - 1 $newArray[$i + 1][$j] = $sCallersArray[$i][$j] Next Else For $j = 0 To UBound($sCallersArray, 2) - 1 $newArray[$i][$j] = $sCallersArray[$i][$j] Next EndIf Next Return $newArray EndFunc ;==>ArrayAdd2d Func ArrayDelete2d($sCallersArray, $iDeleteRow) Dim $newArray[UBound($sCallersArray) - 1][UBound($sCallersArray, 2)] $iCurrent = 0 For $i = 0 To UBound($sCallersArray) - 2 If $i >= $iDeleteRow Then If $i = $iDeleteRow Then For $j = 0 To UBound($sCallersArray,2) - 1 $newArray[$i][$j] = $sCallersArray[$i+1][$j] Next Else For $j = 0 To UBound($sCallersArray, 2) - 1 $newArray[$i][$j] = $sCallersArray[$i+1][$j] Next EndIf Else For $j = 0 To UBound($sCallersArray, 2) - 1 $newArray[$i][$j] = $sCallersArray[$i][$j] Next EndIf Next Return $newArray EndFunc ;==>ArrayDelete2d I'm almost certain this will error out in some conditions, but for the file provided, it works fine. Mostly concerned with the array being added, and subtracted from. Edited February 1, 2013 by jdelaney superbosu 1 IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
superbosu Posted February 1, 2013 Author Share Posted February 1, 2013 HI jdelaney this did the job only one thing I don't understand why the last row give me a wrong result:for example with :Unavailable 18.01.2013 18:36:35 - 21.01.2013 01:38:22Available 21.01.2013 01:38:30 - 30.01.2013 19:58:04Unavailable 30.01.2013 19:58:15 - 30.01.2013 20:14:52Available 30.01.2013 20:15:51 - 01.02.2013 15:57:58 the result is:18.01.2013 process unavailable for 323 minutes ok19.01.2013 process unavailable for 1440 minutes ok20.01.2013 process unavailable for 1440 minutes ok21.01.2013 process unavailable for 98 minutes ok30.01.2013 process unavailable for 33 minutes ??? should be 16.62 minutes or 17 minutes with round Link to comment Share on other sites More sharing options...
jdelaney Posted February 1, 2013 Share Posted February 1, 2013 (edited) haha, I was adding the number to it's self in the last block:If $i = $iUbound Then If $counter = 0 Then $iSumSeconds += $aFormatted[$i][1] $formatteddate = StringRegExpReplace($lastdate, "(d{4})/(d{2})/(d{2})", "$3.$2.$1") FileWrite($file, $formatteddate & " process unavailable for " & Round($iSumSeconds / 60, 2) & " minutes" & @CRLF) ConsoleWrite($formatteddate & " process unavailable for " & Round($iSumSeconds / 60, 2) & " minutes" & @CRLF) EndIf ExitLoopEndIfcorrected:If $i = $iUbound Then If $counter = 0 Then ;$iSumSeconds += $aFormatted[$i][1] $formatteddate = StringRegExpReplace($lastdate, "(\d{4})/(\d{2})/(\d{2})", "$3\.$2\.$1") FileWrite($file, $formatteddate & " process unavailable for " & Round($iSumSeconds / 60, 2) & " minutes" & @CRLF) ConsoleWrite($formatteddate & " process unavailable for " & Round($iSumSeconds / 60, 2) & " minutes" & @CRLF) EndIf ExitLoop EndIffull script:expandcollapse popup#include <Array.au3> #include <Date.au3> #include <File.au3> $file = @DesktopDir & "\raw.txt" $text = FileRead($file) Dim $array[2][2] = [[1, 2],[3, 4]] Dim $aText[1] _FileReadToArray($file, $aText) Dim $aTemp[UBound($aText) - 1][2] ; Split out the file to begin time, and end time For $i = 1 To UBound($aText) - 1 $aTempSplit = StringRegExp($aText[$i], "(.*)\s\-\s(.*)", 3) $aTemp[$i - 1][0] = $aTempSplit[0] $aTemp[$i - 1][1] = $aTempSplit[1] Next ;_ArrayDisplay($aTemp) ; loop through, and update the end time of first instance of Unavail, with the end time of the last consecutive Unavil For $i = 0 To UBound($aTemp) - 1 If $i = UBound($aTemp) Then ExitLoop If StringRegExp($aTemp[$i][0], "Avail", 0) Then ContinueLoop $tempEnd = "" ; Sub loop For $j = $i + 1 To UBound($aTemp) - 1 If StringRegExp($aTemp[$j][0], "Avail", 0) Then ExitLoop $tempEnd = $aTemp[$j][1] $aTemp = ArrayDelete2d($aTemp, $j) $j -= 1 ;~ If $j = UBound($aTemp) Then ExitLoop ;~ _ArrayDisplay($aTemp) Next If $tempEnd <> "" Then $aTemp[$i][1] = $tempEnd EndIf ;_ArrayDisplay($aTemp) If $i = UBound($aTemp) Then ExitLoop Next ; Final setup, to remove the Availables For $i = UBound($aTemp) - 1 To 0 Step -1 If StringRegExp($aTemp[$i][0], "Avail", 0) Then $aTemp = ArrayDelete2d($aTemp, $i) ContinueLoop EndIf $aTemp[$i][0] = StringRegExpReplace($aTemp[$i][0], "Unavailable\s", "") $aTemp[$i][0] = StringRegExpReplace($aTemp[$i][0], "(\d{2})\.(\d{2})\.(\d{4})", "$3/$2/$1") $aTemp[$i][1] = StringRegExpReplace($aTemp[$i][1], "(\d{2})\.(\d{2})\.(\d{4})", "$3/$2/$1") Next Dim $aFormatted[UBound($aTemp)][3] ; $aFormatted will include the date, and the seconds unavail For $i = 0 To UBound($aTemp) - 1 ; begin date $aDate = StringRegExp($aTemp[$i][0], "(.*)\s", 3) $aFormatted[$i][0] = $aDate[0] ; Time Diff in sec $aFormatted[$i][1] = _DateDiff("s", $aTemp[$i][0], $aTemp[$i][1]) ; begin time $aBeginTime = StringRegExp($aTemp[$i][0], "\s(.*)", 3) $aFormatted[$i][2] = $aBeginTime[0] Next _FileCreate(@DesktopDir & "\formatted.txt") $file = FileOpen(@DesktopDir & "\formatted.txt", 2) $lastdate = "" $iSumSeconds = 0 $i = 0 $iUbound = UBound($aFormatted) - 1 $counter = 0 While True ; check if runs over 24 If _DateDiff('D', $aFormatted[$i][0], _DateAdd('s', $aFormatted[$i][1], $aFormatted[$i][0] & " " & $aFormatted[$i][2])) > 0 Then ;ConsoleWrite($aFormatted[$i][0] & " " & $aFormatted[$i][1] & " " & $aFormatted[$i][2] & @CRLF) $begin = $aFormatted[$i][1] $seconds = _DateDiff('s', _DateAdd("D", -1, $aFormatted[$i][0]) & " " & $aFormatted[$i][2], $aFormatted[$i][0] & " 00:00:00") $aFormatted[$i][1] = $seconds Dim $temp[3] = [_DateAdd("D", 1, $aFormatted[$i][0]), $begin - $seconds, "00:00:00"] $aFormatted = ArrayAdd2d($aFormatted, $i + 1, $temp) $iUbound = UBound($aFormatted) - 1 EndIf ; If StringLen ($aFormatted[$i][0]) >0 Then If $aFormatted[$i][0] = $lastdate Then $iSumSeconds += $aFormatted[$i][1] $counter += 1 Else If $lastdate <> "" Then $formatteddate = StringRegExpReplace($lastdate, "(\d{4})/(\d{2})/(\d{2})", "$3\.$2\.$1") If $i > 0 Then ; Check if the total minutes of the current itteration pushes the date past midnight...if so, only add FileWrite($file, $formatteddate & " process unavailable for " & Round($iSumSeconds / 60, 2) & " minutes" & @CRLF) ConsoleWrite($formatteddate & " process unavailable for " & Round($iSumSeconds / 60, 2) & " minutes" & @CRLF) $counter = 0 EndIf EndIf $iSumSeconds = $aFormatted[$i][1] $lastdate = $aFormatted[$i][0] EndIf ; EndIf ConsoleWrite($i & @CRLF) If $i = $iUbound Then If $counter = 0 Then $formatteddate = StringRegExpReplace($lastdate, "(\d{4})/(\d{2})/(\d{2})", "$3\.$2\.$1") FileWrite($file, $formatteddate & " process unavailable for " & Round($iSumSeconds / 60, 2) & " minutes" & @CRLF) ConsoleWrite($formatteddate & " process unavailable for " & Round($iSumSeconds / 60, 2) & " minutes" & @CRLF) EndIf ExitLoop EndIf $i += 1 WEnd Func ArrayAdd2d($sCallersArray, $iAddAfter, $aDataToAdd) Dim $newArray[UBound($sCallersArray) + 1][UBound($sCallersArray, 2)] If $iAddAfter > UBound($sCallersArray) - 1 Then For $j = 0 To UBound($aDataToAdd) - 1 $newArray[UBound($newArray) - 1][$j] = $aDataToAdd[$j] Next EndIf $iCurrent = 0 For $i = 0 To UBound($sCallersArray) - 1 If $i >= $iAddAfter Then If $i = $iAddAfter Then For $j = 0 To UBound($aDataToAdd) - 1 $newArray[$i][$j] = $aDataToAdd[$j] Next EndIf For $j = 0 To UBound($sCallersArray, 2) - 1 $newArray[$i + 1][$j] = $sCallersArray[$i][$j] Next Else For $j = 0 To UBound($sCallersArray, 2) - 1 $newArray[$i][$j] = $sCallersArray[$i][$j] Next EndIf Next Return $newArray EndFunc ;==>ArrayAdd2d Func ArrayDelete2d($sCallersArray, $iDeleteRow) Dim $newArray[UBound($sCallersArray) - 1][UBound($sCallersArray, 2)] $iCurrent = 0 For $i = 0 To UBound($sCallersArray) - 2 If $i >= $iDeleteRow Then If $i = $iDeleteRow Then For $j = 0 To UBound($sCallersArray, 2) - 1 $newArray[$i][$j] = $sCallersArray[$i + 1][$j] Next Else For $j = 0 To UBound($sCallersArray, 2) - 1 $newArray[$i][$j] = $sCallersArray[$i + 1][$j] Next EndIf Else For $j = 0 To UBound($sCallersArray, 2) - 1 $newArray[$i][$j] = $sCallersArray[$i][$j] Next EndIf Next Return $newArray EndFunc ;==>ArrayDelete2d Edited February 1, 2013 by jdelaney superbosu 1 IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
superbosu Posted February 1, 2013 Author Share Posted February 1, 2013 perfect! it works with all my logs tnx again for all!Can I ask you a question jdelaney ? how mutch time did you spend to generate this code? cause I think a code like this thaks a lot of time.... realy a good workNow I will add some gui for month selection, when is ready I will share the code maybe somebody will need the same thing ... Link to comment Share on other sites More sharing options...
jdelaney Posted February 2, 2013 Share Posted February 2, 2013 (edited) Once you learn the basics, and know of the available functions, the time to write something like that doesn't take much time. Actually though, that last change took me a little bit of time (25 min maybe?); i was brain dead at the time. Edited February 2, 2013 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now