How to sum and divide result to show in GUI Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Yatendra3192
Posts: 89
Joined: 10 Dec 2017, 06:57

How to sum and divide result to show in GUI

20 Sep 2018, 06:47

Hi can anyone help me with how to modify below script to show the result in the last column? Result = (Active + Not Active / 60)

Active min of that day + Not Active min of that day divided by 60

Code: Select all

#NoEnv
#SingleInstance, Force

myFile =
(
"Date","Username","Computername","State","Minutes at State","State Start time"
"12-17-2017","YATENDRA","YATENDRA-PC","Active","1","06:14 AM"
"12-29-2017","YATENDRA","YATENDRA-PC","Active","1","02:24 AM"
"12-29-2017","YATENDRA","YATENDRA-PC","Active","4","02:25 AM"
"12-17-2017","YATENDRA","YATENDRA-PC","Active","1","06:15 AM"
"12-17-2017","YATENDRA","YATENDRA-PC","Not Active","1","06:08 AM"
"12-17-2017","YATENDRA","YATENDRA-PC","Active","3","06:12 AM"
)

    Gui, Add, Edit, w80 vID, 303016
    Gui, Add, Button, x+10, Go
    Gui, Add, ListView, xm w330 Grid, ID|Date|active|NotActive

    LV_ModifyCol(1, "50")
    LV_ModifyCol(2, "70")
    LV_ModifyCol(3, "50 Center")
    LV_ModifyCol(4, "80 Center")

    Gui, Show

Return



GuiClose:
ExitApp



;-------------------------------------------------------------------------------
ButtonGo:
;-------------------------------------------------------------------------------
    GuiControlGet, ID
    ;~ FileRead, myFile, D:\Network Drive\Timetracker\%ID%\Timetrack.csv

    TT := new Timetrack(ID)
    Loop, Parse, myFile, `n, `r
        If (A_Index > 1) ; skip header
            TT.add( toRecord(A_LoopField) )

    LV_Delete()
    For Date, AllRecords in TT
        LV_Add("", ID, Date, AllRecords.Active, AllRecords.NotActive)

Return



;-------------------------------------------------------------------------------
toRecord(Line) {
;-------------------------------------------------------------------------------
    Record := []
    Loop, Parse, Line, CSV
        If A_Index in 1,4,5
            Record.Push(A_LoopField)
    Return, Record
}



;-------------------------------------------------------------------------------
class Timetrack {
;-------------------------------------------------------------------------------
    add(Record) {

        Date  := Record[1]
        Bool  := StrReplace(Record[2], A_Space)
        Value := Record[3]

        If Not this.hasKey(Date)
            this[Date] := {Active: 0, NotActive: 0}

        this[Date][Bool] += Value
    }
}

Any kind of help will be or right direction is much appreciated.

Image
Yatendra3192
Posts: 89
Joined: 10 Dec 2017, 06:57

Re: How to sum and divide result to show in GUI

20 Sep 2018, 07:24

able to get so far by modifying wolf_II code

Code: Select all

#NoEnv
#SingleInstance, Force
SetWorkingDir, %A_ScriptDir%

Totalhr = %Bool% + %Value% / 60

myFile =
(
"Date","Username","Computername","State","Minutes at State","State Start time"
"12-17-2017","YATENDRA","YATENDRA-PC","Active","1","06:14 AM"
"12-29-2017","YATENDRA","YATENDRA-PC","Active","1","02:24 AM"
"12-29-2017","YATENDRA","YATENDRA-PC","Active","4","02:25 AM"
"12-17-2017","YATENDRA","YATENDRA-PC","Active","1","06:15 AM"
"12-17-2017","YATENDRA","YATENDRA-PC","idle","1","06:08 AM"
"12-17-2017","YATENDRA","YATENDRA-PC","Active","3","06:12 AM"
)

    Gui, Add, ListView, xm w400 h600 Grid,Date|Active Min|Idle Min|Total Hours

    LV_ModifyCol(1, "70")
    LV_ModifyCol(2, "70 Center")
    LV_ModifyCol(3, "70 Center")

    Gui, Show

    FileRead, myFile, TimeRecord.CSV
    TT := new Timetrack(ID)
    Loop, Parse, myFile, `n, `r
        If (A_Index > 1) ; skip header
            TT.add( toRecord(A_LoopField) )

    LV_Delete()
    For Date, AllRecords in TT
        LV_Add("",Date, AllRecords.Active, AllRecords.idle, Totalhr)

Return






;-------------------------------------------------------------------------------
toRecord(Line) {
;-------------------------------------------------------------------------------
    Record := []
    Loop, Parse, Line, CSV
        If A_Index in 1,4,5
            Record.Push(A_LoopField)
    Return, Record
}



;-------------------------------------------------------------------------------
class Timetrack {
;-------------------------------------------------------------------------------
    add(Record) {

        Date  := Record[1]
        Bool  := StrReplace(Record[2], A_Space)
        Value := Record[3]

        If Not this.hasKey(Date)
            this[Date] := {Active: 0, idle: 0}

        this[Date][Bool] += Value
    }
}
 
GuiClose:
ExitApp


Image

Need help for the last column
User avatar
AlphaBravo
Posts: 586
Joined: 29 Sep 2013, 22:59

Re: How to sum and divide result to show in GUI  Topic is solved

20 Sep 2018, 08:35

is this what you're asking for?
update this line.

Code: Select all

LV_Add("",Date, AllRecords.Active, AllRecords.idle, (AllRecords.Active+AllRecords.idle) / 60)
Yatendra3192
Posts: 89
Joined: 10 Dec 2017, 06:57

Re: How to sum and divide result to show in GUI

20 Sep 2018, 08:47

wolf_II also solved it for me with this

Code: Select all

LV_Delete()
    For Date, Records in TT {
         Result := (Records.Active + Records.NotActive) / 60
        LV_Add("", ID, Date, Records.Active, Records.NotActive, Result)
    }
AHK community is awesome you guys are so nice and very helpful :clap:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: CastleChou, TAC109 and 126 guests