Jump to content

unavailability in minutes from txt of the month


Recommended Posts

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 advance

available.txt

Edited by superbosu
Link to comment
Share on other sites

  • Moderators

superbosu,

Looks like fun - but complicated. Be patient. ;)

M23

Edit: 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!

:thumbsup:)

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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.

#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 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

WOW jdelaney you did it so fast!!! :o 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 minutes

15.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 s

Available 09.12.2012 04:49:44 - 09.12.2012 10:20:46

Unavailable 09.12.2012 10:21:10 - 09.12.2012 10:53:25 -> _DateDiff = 1935 s

Unavailable 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:01

Available 23.12.2012 09:53:01 - 31.01.2013 17:37:11

the 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 experts

available.txt

Link to comment
Share on other sites

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 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

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

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 minutes

Edited 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

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:25

Unavailable 09.12.2012 11:39:53 - 09.12.2012 12:38:53

Unavailable 09.12.2012 15:42:33 - 09.12.2012 15:42:49

instead of

Unavailable 09.12.2012 10:21:10 – 09.12.2012 15:42:49

I 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

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.

Edited 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

HI jdelaney this did the job :):thumbsup:

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:22

Available 21.01.2013 01:38:30 - 30.01.2013 19:58:04

Unavailable 30.01.2013 19:58:15 - 30.01.2013 20:14:52

Available 30.01.2013 20:15:51 - 01.02.2013 15:57:58

the result is:

18.01.2013 process unavailable for 323 minutes ok

19.01.2013 process unavailable for 1440 minutes ok

20.01.2013 process unavailable for 1440 minutes ok

21.01.2013 process unavailable for 98 minutes ok

30.01.2013 process unavailable for 33 minutes ??? should be 16.62 minutes or 17 minutes with round

Link to comment
Share on other sites

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   ;==>ArrayDelete2d
Edited 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

perfect! it works with all my logs :thumbsup: 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 work

Now 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

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 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...