Leaderboard
Popular Content
Showing content with the highest reputation on 02/01/2013 in all areas
-
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 ExitLoop EndIf corrected: 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 EndIf full script: #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 ;==>ArrayDelete2d1 point
-
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: #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.1 point
-
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) #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 EndFunc fileoutput: 09.12.2012 process unavailable for 91.52 minutes 15.12.2012 process unavailable for 0.55 minutes 21.12.2012 process unavailable for 347.77 minutes 22.12.2012 process unavailable for 1440 minutes 23.12.2012 process unavailable for 592.02 minutes1 point
-
nandy12, As the problem seems to be the other app not responding to your script, you might like to try checking that it is responsive using something along these lines before each Send. Then you can abort if the app is not in the mood to play after a certain time (TimerInit/Diff will help here) - assuming that you get a suitable response from the query. M231 point
-
If you want an installer launcher look at the Vollatran project (link in my signature)1 point