GUI to pull data from different CSV files

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

GUI to pull data from different CSV files

10 Jan 2018, 08:31

Hi All
I have a more than 1000 folders in the same location containing Timetrack.csv file with the data in below format-
  • "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"
The path of the CSV is almost same just folder name is different like 303001 to 304000
Path -
  • D:\Network Drive\Timetracker\303016
    D:\Network Drive\Timetracker\303017
What i want to do is create a GUI where user select the date and and GUI show the calculated data for all the comma seprated folder name , like eg. sum all the active min of the selected date, first time of that day, last time of that day and show a report like below for all the folder name i'm gonna put in input box separated by comma

input box for date - [12-29-2017] Inputbox for Foldername [303016,303017,303018] Go button [Go]
  • ID_______Date_______active____Notactive___SatrtTime____EndTime
    303016___12-29-2017___5_________1________02:24 AM_______02:25 AM
    303017___12-29-2017___5_________0________06:08 AM_______06:15 AM
    303018___12-29-2017___5_________1________02:24 AM_______02:25 AM
    303019___12-29-2017___5_________0________06:08 AM_______06:15 AM
Wolf_II help me with the previews GUI which pull the data on folder name basis but we got stuck on how to Pull _StartTime____EndTime into the GUI. Here is the code from Wolf_II
Thread -

Code: Select all

#NoEnv
#SingleInstance, Force

    Gui, Add, Edit, w80 vID, 303016
    Gui, Add, Button, x+10, Go
    Gui, Add, ListView, xm w300 Grid, ID|Date|active|NotActive
    Gui, Add, Button, xm+250 w50, Export
    Gui, Show

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

Return



GuiClose:
ExitApp



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

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

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

Return



;-------------------------------------------------------------------------------
ButtonExport: ; export report to csv-file
;-------------------------------------------------------------------------------
    Filename := ""
    FileSelectFile, Filename, S16, %A_ScriptDir%, Export report, *.csv
    IfEqual, Filename,, Return ; user cancelled
    If Not (SubStr(Filename, -3) = ".csv")
        Filename .= ".csv"

    CSV_Data := "ID,Date,Active,Aot Active`n"
    Rows := LV_GetCount()
    Cols := LV_GetCount("Col")

    Loop, %Rows% {
        r := A_Index
        newRow := ""
        Loop, %Cols% {
            c := A_Index
            LV_GetText(txt, r, c)
            newRow .= (A_Index = 2 ? convertDateFormat(txt) : txt) ","
        }
        CSV_Data .= RTrim(newRow, ",") "`n"
    }

    ; overwrite Filename
    FileDelete, %Filename%
    FileAppend, %CSV_Data%, %Filename%

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



;-------------------------------------------------------------------------------
convertDateFormat(Date) { ; input format: MM-DD-YYYY
;-------------------------------------------------------------------------------
    static Months := [ "Jan", "Feb", "Mar", "Apr", "May", "Jun"
                     , "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]
    Return, Months[SubStr(Date, 1, 2)] SubStr(Date, 3)
}
User avatar
divanebaba
Posts: 805
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: GUI to pull data from different CSV files

10 Jan 2018, 11:17

This website is offering tools to create handsome threads.

Code: Select all

This, for example, is for code.
  • And this could be for
  • any lists
  • any questions
Your thread is not clear enough, that it makes fun to read.
Your thread is supporterkiller one.
Einfach nur ein toller Typ. :mrgreen:
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: GUI to pull data from different CSV files

10 Jan 2018, 13:05

divanebaba wrote:This website is offering tools to create handsome threads.

Code: Select all

This, for example, is for code.
  • And this could be for
  • any lists
  • any questions
Your thread is not clear enough, that it makes fun to read.
Your thread is supporterkiller one.
Thy for your (more or less valid) statement. I've re-formatted the initial thread on Yatendra3192's behalf to become more supporter friendly.
Let's guess you're more than happy now to support him/her. :)
User avatar
divanebaba
Posts: 805
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: GUI to pull data from different CSV files

10 Jan 2018, 14:10

BoBo wrote:... Let's guess you're more than happy now to support him/her. ...
I'm not glad at all.
Yatendra3192 wrote:... but we got stuck on how to Pull _StartTime____EndTime into the GUI
There is no entry for EndTime in your CSV. Maybe you could calculate the EndTime by adding the minutes of "Minutes at State" onto "State Start time"?

As I have seen, you do not often modify example scripts, so I don't believe that my suggestions could help.

I could not read out the variable called TT. Very interesting, how the programmer has created this variable. TT.add( ... )
Do you know, how I can display the content of TT after the loop?
Einfach nur ein toller Typ. :mrgreen:
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: GUI to pull data from different CSV files

10 Jan 2018, 14:57

I could not read out the variable called TT. Very interesting, how the programmer has created this variable. TT.add( ... )
:arrow: https://autohotkey.com/docs/objects/Object.htm
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: GUI to pull data from different CSV files

10 Jan 2018, 17:03

TT is an instance of the class Timetracker.
TT is created with new, not with TT.add().
I used DebugVars to see it during development.
User avatar
divanebaba
Posts: 805
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: GUI to pull data from different CSV files

10 Jan 2018, 19:15

Thanks for the explanation, wolf_II, but I still did not understand (anything) enough.
For a possible project I want to turn classic row-based search into column-based search.
I thought, two dimensional arrays must be first choice for such a task.
I have similar task as Yatendra3192, many csv-like files, in which I search for strings and display matches in a ListView.

BTW: DebugVars?? I don't have found this command. I've used ListVars but with not much success. But I have found CSVQF. Very nice stuff.
Einfach nur ein toller Typ. :mrgreen:
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: GUI to pull data from different CSV files

10 Jan 2018, 20:29

DebugVars is a gift of god. It's an AHK-script written by Lexikos. You don't know what you are missing.
User avatar
divanebaba
Posts: 805
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: GUI to pull data from different CSV files

11 Jan 2018, 04:07

wolf_II wrote:... is a gift of god ...
hmmm, I thought, God is a DJ, now I know, he is AHK-developer :mrgreen: :mrgreen:

Yatendra3192, I do not have forgotten you. As I know, as a beginner like you, you love Plug&Play solutions.
Here is a more, exactly said, more less than more, beginner friendly code for you. Put a MsgBox whereever you want and look for the content of the variables, to understand my ugly nightwork.
I have deactivated most professional code, appropriated by wolf_II, because I was not able to easy understand what the hell he has done.
To try it out, you need a bit preparation. The Edit-control has three rows, input your unlimited ID's with an `n LineBreak (that means, you have to hit {Enter} between every ID).
To calculate the EndTime there where too much Unknown Flying Objects in shape of original geman beer bottle's in my room. The same fate as that of my favorite author the awesome, great, unbelievable "Franz Ferzak", the daredevil himself.
I'm sorry, I loose the fight. It was too much alcohol and I was not strong enough to resist.
Maybee you're on your way, you will find it out for your own, how to manipulate the items, created by StringSplit.
If not, here is another Depp who will help work for free.
BoBo wrote:... Let's guess you're more than happy now to support him/her. ...
I'm more than drunken now. :HeHe: :HeHe:
Einfach nur ein toller Typ. :mrgreen:
Yatendra3192
Posts: 89
Joined: 10 Dec 2017, 06:57

Re: GUI to pull data from different CSV files

23 Jan 2018, 09:41

divanebaba wrote:
wolf_II wrote:... is a gift of god ...
hmmm, I thought, God is a DJ, now I know, he is AHK-developer :mrgreen: :mrgreen:

Yatendra3192, I do not have forgotten you. As I know, as a beginner like you, you love Plug&Play solutions.
Here is a more, exactly said, more less than more, beginner friendly code for you. Put a MsgBox whereever you want and look for the content of the variables, to understand my ugly nightwork.
I have deactivated most professional code, appropriated by wolf_II, because I was not able to easy understand what the hell he has done.
To try it out, you need a bit preparation. The Edit-control has three rows, input your unlimited ID's with an `n LineBreak (that means, you have to hit {Enter} between every ID).
To calculate the EndTime there where too much Unknown Flying Objects in shape of original geman beer bottle's in my room. The same fate as that of my favorite author the awesome, great, unbelievable "Franz Ferzak", the daredevil himself.
I'm sorry, I loose the fight. It was too much alcohol and I was not strong enough to resist.
Maybee you're on your way, you will find it out for your own, how to manipulate the items, created by StringSplit.
If not, here is another Depp who will help work for free.
BoBo wrote:... Let's guess you're more than happy now to support him/her. ...
I'm more than drunken now. :HeHe: :HeHe:
Hi divanebaba, Thank you for putting so much effort but your script dose not help me at all or point me in the right direction but i'm able to do this task i need in the excel so for now everything is good but i'm still learning AHK and find a way to do what i want .
01.png
01.png (147.12 KiB) Viewed 1358 times
Yatendra3192
Posts: 89
Joined: 10 Dec 2017, 06:57

Re: GUI to pull data from different CSV files

23 Jan 2018, 09:55

divanebaba wrote: As I know, as a beginner like you, you love Plug&Play solutions.
BoBo wrote:... Let's guess you're more than happy now to support him/her. ...
I'm more than drunken now. :HeHe: :HeHe:
Yes I'm a beginner but don't want others to write cods for me i only want help when i'm stuck and have no idea which direction to go i have write all the codes below and when i cant find the solution for my problems i come to ASK FOR HELP.

Auto start script - to run my time tracker
-----------------------------------------------------------
#NoTrayIcon
#SingleInstance force
#Persistent
DetectHiddenWindows, On
SetTitleMatchMode, RegEx

SetTimer, Check, 60000 ;check every one min
return

Check:
IfWinNotExist, Timetrack.ahk
IfWinNotExist, search and run script.ahk
IfWinNotExist, Changepass.ahk
IfWinNotExist, ^30\d{4}\.ahk

Run,search and run script.ahk
return

^!e::
sleep 500
send ^!q
sleep 500
send ^!q
sleep 500
Run,search and run script.ahk
return
_____________________________________________________

search and run script - to find the employeeID of a employee
-----------------------------------------------------------------------------
#SingleInstance force

Gui +LastFound +OwnDialogs +AlwaysOnTop
TempVar := A_ScreenHeight +100
path:="D:\Network Drive\Timetracker"
ext:="ahk"
Gui,Show, h%TempVar% w%A_ScreenWidth%
;//InputBox, OutputVar[, Title, Prompt , HIDE, Width, Height, X , Y, Font, Timeout, Default]
InputBox , file , Log-in , Enter Your employee ID... If you are a guest enter Guest and iksula as a password, , , , , , , , Employee ID Eg. 303016
;// *** NOTE *** Did you want Height & X or Width/Height or X/Y???.........^^^.....^^^
if (errorlevel=0) {
file=%path%\%file%\%file%.%ext%
if (FileExist(file)) {
Run, %file%, , UseErrorlevel
if (errorlevel!=0) {
msgbox, 16, , Error: Run failed...`n`n%file%
}
} else Run,\search and run script.ahk
}


ExitApp
Return
_________________________________________

Password verifier
-----------------------------------------------------------
#NoTrayIcon
#SingleInstance force
#Persistent
SetWorkingDir, %A_ScriptDir%
IniRead, validPassword, SETTINGS.INI, Login, Password, %A_Space%
validPassword = %validPassword%
TempVar := A_ScreenHeight +100
Gui -Sysmenu +LastFound +OwnDialogs +AlwaysOnTop
Gui, Margin, 5,5
Gui, Add, Groupbox, w220 h50, Enter Password
Gui, Add, Text,,Press Ctrl+Alt+C to change your password
Gui, Font, S10, Verdana
Gui, Add, Edit, x15 y20 r1 Limit20 w200 h20 0x20 vTypedPassWord
Gui, Add, Button, x+15 y10 w45 h45 0x8000 +Default gVerifyPassword, &Ok
Gui,2:Show, h%TempVar% w%A_ScreenWidth%
Gui, Show, AutoSize ,

Return

VerifyPassword:
Gui,Submit, Nohide

ChkPassword := TypedPassword

If ( validPassword = "" AND TypedPassword = "" )
ExitApp

If ( validPassword = "" AND ChkPassword != "" )
{
IniWrite, %ChkPassword%, SETTINGS.INI, Login, Password
ExitApp
}

If ( ChkPassword != validPassword )
{
Run,cant\give\you\the\addressTimetracker\search and run script.ahk
Exitapp
}
Else
{
Run,Timetrack.ahk
Exitapp
}
Return

GuiEscape:
ExitApp
Return

^!c::
Run,Changepass.ahk

^!l::
exitapp
___________________________________________

Password changer
-------------------------------------------------------------
#NoTrayIcon
#SingleInstance force
#Persistent
IniRead, validPassword, SETTINGS.INI, Login, Password, %A_Space%
validPassword = %validPassword%
SetTimer, ForceExitApp, 20000 ; 2 minutes
TempVar := A_ScreenHeight +100
Gui, Margin, 5,5
Gui, Add, Groupbox, w220 h50, Enter Password
Gui, Font, S10, Verdana
Gui, Add, Edit, x15 y20 r1 Limit20 w200 h20 0x20 vTypedPassWord
Gui, Add, Button, x+15 y10 w45 h45 0x8000 +Default gVerifyPassword, &Ok
Gui,2:Show, h%TempVar% w%A_ScreenWidth%
Gui, Show, AutoSize ,Change password
Return

VerifyPassword:
Gui,Submit, Nohide

ChkPassword := TypedPassword

If ( validPassword = "" AND TypedPassword = "" )
ExitApp

If ( validPassword = "" AND ChkPassword != "" )
{
IniWrite, %ChkPassword%, SETTINGS.INI, Login, Password
ExitApp
}

If ( ChkPassword != validPassword )
{
Msgbox, 16, Login Error!, Invalid Password!, 5
Return
}
Else
{
FileDelete,SETTINGS.INI
Msgbox,, correct, choose new Password!, 5
Reload
send,^!l
send,^!e
}
Return

GuiEscape:
ExitApp
Return

ForceExitApp:
SetTimer, ForceExitApp, Off
ExitApp
Return
_________________________________________________

and real mess - the time tracker
----------------------------------------------------------------------

#NoTrayIcon
#SingleInstance force
#InstallKeybdHook
#InstallMouseHook
#Persistent
SetWorkingDir, %A_ScriptDir%

idleLimit:= 180000 ; three min
SetTimer, CloseOnIdle, % idleLimit+150

OnExit, ExitSub ; run some extra stuff before exiting

gosub,ddlx
WayfairMedia=WL Editing|Creative Brief|Image Association|VSP|Events Editing|Angle & Tilt|Batch Image Tickets||Batch PDF Tickets
PA=task1||task2|task3|task4|task5
SOUQ=Image||International|UAE
Finance=Invoice Ticketing(EU/US)||Payment|Credit Notes|Statement|Offshore Ticketing|WMS|Chargeback|Wizardview|No DFI
NOON=NOON1||

Gui -Sysmenu +LastFound +OwnDialogs +AlwaysOnTop
Gui, Add, Tab2,W450 h300, Continue/Start new Task|End a Running Task
Gui, Add, Text,, Select Task:
Gui, Add, DDL, w400 vDDL,Continue to work||Starting New task
Gui, Add, Text,, Select Type of Work:
Gui, Add, DDL,w400 vDDL2, QC|Production|other task
Gui, Add, Text,, Enter Unit Count:
Gui, Add, edit,w400 number vDDL3,
Gui, Add, Text,, Select Images or SKUs:
Gui, Add, DDL,w400 vDDL5, Images|SKUs
Gui, Add, Text,, Select Team and Subprocess:
Gui, Add, DDL,gAPLY W400 vDROPDOWN, %LST%
Gui, Add, DDL, W400 vLISTBOXM
Gui, Tab, 2
Gui, Add, Text,, Count of completed work:
Gui, Add, edit,w400 number vDDL8
GuiControl,1: Choose,dropdown,SOUQ ;-- << preselect
gosub,aply
return

;-- this can be interessant instead using a very long line --
DDLX:
LST=
(Ltrim Join|
WayfairMedia
PA
SOUQ
Finance
NOON
)
return


APLY:
gui,1:submit,nohide
guicontrol,1:,LISTBOXM,|
listboxm=
If DROPDOWN=WayfairMedia
LISTBOXM=%WayfairMedia%
If DROPDOWN=PA
LISTBOXM=%PA%
If DROPDOWN=SOUQ
LISTBOXM=%SOUQ%
If DROPDOWN=Finance
LISTBOXM=%Finance%
If DROPDOWN=NOON
LISTBOXM=%NOON%
guicontrol,1:,LISTBOXM,%LISTBOXM%

Gui, Tab ; i.e. subsequently-added controls will not belong to the tab control.

Gui, Add, Button, Default xm, Input
Gui, +AlwaysOnTop
Gui, Show

return
GuiClose:
MsgBox, 16, Attandance Manager, You can not close the program
ButtonInput:
Gui, Submit, Hide
if ErrorLevel
Run,cant\give\you\the\addressTimetracker\search and run script.ahk
else
MsgBox, You are %DDL% of %DDL2%. Your work count is %DDL3% and Your Process is %LISTBOXM% and Team is %DROPDOWN%

OneMinute := 60000 ; if you change this from 60000, then times will not accurately display in "hours and minutes"
OutputFileName := "TimeRecord.CSV"
OutputFileName2 := "TaskRecord.CSV"
ForceUpdate := false ; dont change this manually
BlockCount := 0 ; init to zero

SetTimer, CheckTime, %OneMinute% ; updates every 1 minute
FormatTime, BlockStartTime, , HH:mm tt ; initialise this
Return

CheckTime:
FormatTime, TheDateToday,,MM-dd-yyyy
BlockCount++

CurrentResult := A_TimeIdlePhysical < OneMinute ? "Active" : "Idle" ; determine current activity state

If ( (LastResult AND (CurrentResult != LastResult)) or ForceUpdate )
{
BlockTracker .= BlockTracker ? "`n" : "" ; add a carriage return if the var is not empty
BlockTracker .= BlockStartTime . " " . LastResult . "= " . BlockCountFormatted ; add the string you requested

IfNotExist, %OutputFileName% ; if the file doesn't already exist, write the column title line to it
FileAppend, "Date"`,"Username"`,"Computername"`,"State"`,"Minutes at State"`,"State Start time"`n, %OutputFileName%

FileAppend, "%TheDateToday%"`,"%A_UserName%"`,"%A_ComputerName%"`,"%LastResult%"`,"%BlockCount%"`,"%BlockStartTime%"`n, %OutputFileName%


BlockCount := 0 ; reset this back to zero as the user switched states
FormatTime, BlockStartTime, , HH:mm tt ; get the new time
}

LastResult := CurrentResult ; save this for next time the check is made
Return


CloseOnIdle:
if (A_TimeIdlePhysical>=idleLimit)
{
ExitApp
}
else
{
SetTimer,CloseOnIdle, % idleLimit-A_TimeIdlePhysical+150
}
return

ExitSub:
OnExit, ; stop this calling itself a second time
ForceUpdate := true ; force capture of most recent 'block' of activity
GoSub, CheckTime ; run this one last time before exiting to capture the info in the csv file

IfNotExist, %OutputFileName2% ; if the file doesn't already exist, write the column title line to it
FileAppend, "Date"`,"State Start time"`,"Choose Task"`,"Work Type"`,"Unit Count"`,"Image/Sku"`,"Completed Work"`,"Process"`,"Team"`n, %OutputFileName2%

FileAppend, "%TheDateToday%"`,"%BlockStartTime%"`,"%DDL%"`,"%DDL2%"`,"%DDL3%"`,"%DDL5%"`,"%DDL8%"`,"%LISTBOXM%"`,"%DROPDOWN%"`n, %OutputFileName2%

Return

^!y::
Run,"%A_ScriptFullPath%"
Return

^!q::
exitapp
Return

^!r::
Send ^!q
Send ^!y
Return

____________________________________________________

So you see not an average newbie here 8-)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 240 guests