Jump to content

How do I summarize the time in a .log file?


 Share

Recommended Posts

Hello forum

2019-08-15 13:50:16 : Close
2019-08-15 13:50:33 : Open
2019-08-15 13:50:40 : Close
2019-08-15 13:51:00 : Open
2019-08-15 13:51:49 : Close
2019-08-15 13:51:52 : Open
2019-08-15 13:51:59 : Close
2019-08-15 13:52:20 : Open
2019-08-15 13:52:26 : Close
2019-08-15 13:52:30 : Open
2019-08-15 13:52:38 : Close

I have .log file see above. Made with _FileWriteLog function.

So my question is how that I want to summarize the overall usage of the program using this .log file.

#include <File.au3>


 Local $aRetArray, $sFilePath = @ScriptDir & "\Log.log"
    ; Re-read it - with count
    _FileReadToArray($sFilePath, $aRetArray)
    _ArrayDisplay($aRetArray, "1D array - count", Default, 😎
    

Dim s=0 
For $i = 0 To Ubound($aRetArray)

 s+=$Date

Next

 

Link to comment
Share on other sites

Get the first and the last time and then use e.g. _DateDiff to get the seconds between those time.

You could use a _TimeDiff directly in your script.

Edited by Xenobiologist

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Use _DateDiff to get the difference between two dates in seconds, sum them up then calculate the duration.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

#include <File.au3>

Global $aLogArray, $sFilePath = @ScriptDir & "\Log.log", $iDuration = 0, $sOpenDate = ""
_FileReadToArray($sFilePath, $aLogArray, $FRTA_NOCOUNT)
For $i = 0 To UBound($aLogArray) - 1
    $aTemp = StringSplit($aLogArray[$i], " ", $STR_NOCOUNT)
    $aTemp[0] = StringReplace($aTemp[0], "-", "/")
    If $aTemp[3] = "Close" Then
        $iDuration = $iDuration + _DateDiff("s", $sOpenDate, $aTemp[0] & " " & $aTemp[1])
    Else
        $sOpenDate = $aTemp[0] & " " & $aTemp[1]
    EndIf
Next
MsgBox(0, "Runtime", "Run time in seconds: " & $iDuration)

I assume that there is always an Open/Close pair of records and there is only "Open" or "Close" in the log record.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

To make it 100% fool-proof I would add a GUID to the OPEN and CLOSE token. So the script would be able to identify the correct pair.
I would then use a dictionary to store the OPEN/CLOSE information and the overall usage. On success I would remove the OPEN/CLOSE info from the dictionary.
At the end the problems you describe would be solved.

Example:

2019-08-15 13:50:33 : Open {0335E874-FBD1-4CBF-A354-8B9D536B40A7}
2019-08-15 13:51:16 : Close {0335E874-FBD1-4CBF-A354-8B9D536B40A7}

 

Instead of a GUID you could store the time including milliseconds. I would then add this exact start time to the CLOSE token. Rest as described above.

Example:

2019-08-15 13:49:38.102 : Open
2019-08-15 13:51:16.582 : Close 13:49:38.102

 

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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