Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Include Csv.ahk
- #NoEnv
- SetWorkingDir %A_ScriptDir%
- promptedSuccessLength()
- {
- global
- return CurrentCycleLength + 60
- }
- volunteeredFailureLength()
- {
- global
- return 60
- }
- promptedFailureLength()
- {
- ;msgbox entered prompted failure length
- return 60
- }
- voluntaryResumeLength()
- {
- global
- return 60
- }
- forcedResumeLength()
- {
- global
- return 60
- }
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- boundCycleLength()
- {
- global
- if(currentCycleLength < cycleFloor)
- {
- ;msgbox applied cycle bound
- currentCycleLength := cycleFloor
- }
- if (currentCycleLength > cycleCeiling)
- {
- msgbox applied cycle bound
- currentCycleLength := cycleCeiling
- }
- }
- #Persistent
- ;msgbox Start
- consecutiveFocusSeconds := 0
- ; TODO generalize task padding length (25)
- ; TODO Choose Cycle Alterations, Speed bump, etc.
- ; TODO Running Debug
- ; TODO Cancel Activity
- ; TODO DeterminateTask
- ; TODO BrainDump
- ; TODO Clock Align and Clock Report Time
- ; TODO Smart Speed Bumps?
- ; TODO Subtasking
- ; TODO RandomReminders
- ; TODO RandomTimers, NewTaskAt
- ; TODO Distraction Tabbing
- ;makes inputboxes on top
- Gui +LastFound +OwnDialogs +AlwaysOnTop
- goSub IniRead
- CSV_Load("OpenTasks.csv",OpenTasks,",")
- %OpenTasks%CSV_TotalCols := 5
- CSV_Load("FinishedTasks.csv",FinishedTasks,",")
- %FinishedTasks%CSV_TotalCols := 5
- CSV_Load("AbandonedTasks.csv",AbandonedTasks,",")
- %AbandondedTasks%CSV_TotalCols := 5
- ;Determine How Long The Program Was Not Running For!
- x := A_Now
- EnvSub, x, %LastNow%, Seconds
- SecondsAsleep := x
- TotalSecondsElapsed := TotalSecondsElapsed + SecondsAsleep
- ;Padding := nChar(ceil(CycleCeiling/60)," ")
- FileAppend,`n`nProgram Off for %SecondsAsleep%s.`n`n%A_Now%, gtimer.log
- ;intialize values
- inWorkCycle := 0
- inBreak := 0
- SetTimer, EverySecondDo, 1000, 2147483647
- Gosub, CycleStart
- return
- breakString()
- {
- global
- ConsecutiveBreakMinutes := Ceil(ConsecutiveBreakSeconds/ 60)
- StringLen, sumChars, ConsecutiveBreakMinutes
- BreakMinutesElapsed := Ceil(BreakSecondsElapsed / 60)
- CycleCeilingInMinutes := Ceil(CycleCeiling / 60)
- Padding := CycleCeilingInMinutes - BreakMinutesElapsed
- nChar := nChar(BreakMinutesElapsed,0)
- nCharPad := nchar(Padding," ")
- blankTask := nChar(25," ")
- String := "`t" . blankTask . "`t" . nChar . nCharPad . "`t" . ConsecutiveBreakMinutes
- return String
- }
- updateTaskNow:
- TaskRow := CSV_MatchCellColumn(OpenTasks,TASK,1)
- if( TaskRow == 0)
- {
- CSV_AddRow(OpenTasks,TASK . "," . A_Now . "," . A_Now . ",0,0")
- } else {
- CSV_ModifyCell(OpenTasks,A_Now,TaskRow,3)
- TaskActiveSeconds := 1 + CSV_ReadCell(OpenTasks,TaskRow,4)
- CSV_ModifyCell(OpenTasks,TaskActiveSeconds,TaskRow,4)
- }
- CSV_Save("OpenTasks.csv",OpenTasks,1)
- return
- AddTaskFocusTime(Time){
- global TASK
- TaskRow := CSV_MatchCellColumn(OpenTasks,TASK,1)
- TaskFocusSeconds := Time + CSV_ReadCell(OpenTasks,TaskRow,5)
- ;msgbox taskrow %taskrow% time %time% taskfocus seonds %taskfocusseconds%
- CSV_ModifyCell(OpenTasks,TaskFocusSeconds,TaskRow,5)
- }
- isInitialSegment(A,B)
- {
- ;msgbox %A% %B%
- if (RegExMatch(B,"^" . A))
- {
- ;msgbox is initial
- return 1
- } else {
- ;msgbox notintial
- return 0
- }
- }
- getAggregateTaskLastNow()
- {
- global TASK
- AggregateTaskLastNow := 16010101000000
- rows := CSV_TotalRows(OpenTasks)
- currentRow := 1
- while (currentRow <= rows)
- {
- rowTask := CSV_ReadCell(OpenTasks,currentRow,1)
- if(isInitialSegment(TASK,rowTask))
- {
- rowLastNow := CSV_ReadCell(OpenTasks,currentRow,3)
- x := rowLastNow
- ;msgbox %rowLastNow% %AggregateTaskLastNow%
- EnvSub, x, %AggregateTaskLastNow%, Seconds
- ;msgbox %x%
- if(x>0)
- {
- AggregateTaskLastNow := rowLastNow
- }
- }
- currentRow++
- }
- return AggregateTaskLastNow
- }
- getAggregateTaskActiveTime()
- {
- global TASK
- AggregateTaskActiveTime := 0
- rows := CSV_TotalRows(OpenTasks)
- currentRow := 1
- while (currentRow <= rows)
- {
- rowTask := CSV_ReadCell(OpenTasks,currentRow,1)
- if(isInitialSegment(TASK,rowTask))
- {
- rowActiveTime := CSV_ReadCell(OpenTasks,currentRow,4)
- AggregateTaskActiveTime := AggregateTaskActiveTime + rowActiveTime
- }
- currentRow++
- }
- return AggregateTaskActiveTime
- }
- getAggregateTaskFocusTime()
- {
- global TASK
- AggregateTaskFocusTime := 0
- rows := CSV_TotalRows(OpenTasks)
- currentRow := 1
- while (currentRow <= rows)
- {
- rowTask := CSV_ReadCell(OpenTasks,currentRow,1)
- if(isInitialSegment(TASK,rowTask))
- {
- rowFocusTime := CSV_ReadCell(OpenTasks,currentRow,5)
- AggregateTaskFocusTime := AggregateTaskFocusTime + rowFocusTime
- }
- currentRow++
- }
- return AggregateTaskFocusTime
- }
- getAggregateTaskFirstNow()
- {
- global TASK
- TaskRow := CSV_MatchCellColumn(OpenTasks,TASK,1)
- StartTime := CSV_ReadCell(OpenTasks,TaskRow,2)
- return StartTime
- }
- Close::
- global TASK
- childFocusTime := getAggregateTaskFocusTime()
- childActiveTime := getAggregateTaskActiveTime()
- childLastNow := getAggregateTaskLastNow()
- childFirstNow := getAggregateTaskFirstNow()
- CSV_AddRow(closeType . "Tasks",TASK . "," . childFirstNow . "," . childLastNow . "," . childActiveTime . "," . childFocusTime
- CSV_Save("FinishedTasks.csv",FinishedTasks,1)
- CSV_Save("AbandonedTasks.csv",AbandonedTasks,1)
- TASKlen := StringLen(TASK)
- maxLen := 0
- maxLenRow := 0
- rows := CSV_TotalRows(OpenTasks)
- currentRow := 1
- while (currentRow <= rows)
- {
- rowTask := CSV_ReadCell(OpenTasks,currentRow,1)
- if(isInitialSegment(rowTask,TASK))
- {
- rowLen := StringLen(rowTask)
- if (rowLen < TASKlen)
- {
- if(rowLen > maxLen)
- {
- maxLen := rowLen
- maxLenRow := currentRow
- }
- }
- }
- if(isInitialSegment(TASK,rowtask)
- {
- CSV_DeleteRow(CSV_Identifier,currentRow)
- }
- currentRow++
- }
- if (maxLen != 0)
- {
- parentRow := maxLenRow
- parentFocusTime := CSV_ReadCell(OpenTasks,parentRow,5)
- parentActiveTime := CSV_ReadCell(OpenTasks,parentRow,4)
- parentLastNow := CSV_ReadCell(OpenTass,parentRow,3)
- newParentFocusTime := parentFocusTime + childFocusTime
- newParentActiveTime := parentActiveTime + childActiveTime
- x := parentLastNow
- EnvSub, x, %childLastNow%, Seconds
- if (x < 0)
- {
- newParentLastNow := childLastNow
- } else {
- newParentLastNow := parentLastNow
- }
- CSV_ModifyCell(OpenTasks,newParentLastNow,parentRow,3)
- CSV_ModifyCell(OpenTasks,newParentActiveTime,parentRow,4)
- CSV_MOdifyCell(OpenTasks,newParentFocusTie,parentRow,5)
- }
- }
- EverySecondDo:
- ;restart the script if it appears to have been asleep for more than 5 seconds
- x := A_Now
- EnvSub, x, %lastNow%, Seconds
- if(x > 10)
- {
- FileAppend,`n`nThe Program Appears to have been inactive for more than 10 seconds. Restarting.`n,gtimer.log
- reload
- }
- lastNow := A_Now
- gosub IniWrite
- TotalSecondsElapsed++
- if (inWorkCycle)
- {
- gosub updateTaskNow
- BreakSecondsElapsed := 0
- ConsecutiveBreakSeconds := 0
- CycleSecondsElapsed++
- ConsecutiveFocusSeconds++
- if(ConsecutiveFocusSeconds > LongestConsecutiveFocus){
- LongestConsecutiveFocus := ConsecutiveFocusSeconds
- }
- }
- if (inBreak)
- {
- BreakSecondsElapsed++
- ConsecutiveFocusSeconds := 0
- ConsecutiveBreakSeconds++
- if(ConsecutiveBreakSeconds > LongestConsecutiveBreak)
- {
- LongestConsecutiveBreak := ConsecutiveBreakSeconds
- }
- BREAKTIME--
- if (OutOfFreeTime())
- {
- Suspend On
- inBreak := 0
- MsgBox, 262144, ,No Break time is left!
- ;not sure about these two lines
- CurrentCycleLength := forcedResumeLength()
- str := breakString()
- FileAppend,%str%, gtimer.log
- FileAppend,`t(Forced), gtimer.log
- SetTimer, CycleStart, -1
- Suspend Off
- }
- if (BREAKTIME < 0)
- {
- inBreak := 0
- SetTimer, PlannedBreakEnd, -1
- }
- }
- if (inWorkCycle & (CycleSecondsElapsed > CurrentCycleLength))
- {
- inWorkCycle := 0
- CycleSecondsElapsed := CurrentCycleLength
- SetTimer, CycleEnd, -1
- }
- return
- plannedBreakEnd:
- str := breakString()
- FileAppend,%str%, gtimer.log
- FileAppend,`t(Prompted), gtimer.log
- Suspend On
- BREAKTIME := 0
- MsgBox, 262148, ,that's the end of your planned break. Ready to resume focus?
- IfMsgBox, Yes
- SetTimer, CycleStart, -1
- IfMsgBox, No
- {
- inBreak := 0
- SetTimer, Break, -1
- }
- return
- CycleStart:
- inbreak := 0
- inWorkCycle := 0
- Suspend, On
- CycleSecondsElapsed := -1
- boundCycleLength()
- ;SpeedBump("Until you've decided what course of action is best for you, close your eyes.")
- Gui +LastFound +OwnDialogs +AlwaysOnTop
- mins := (CurrentCycleLength / 60)
- InputBox, TASK, ,What would be best`,`nFor you to do`,`nWithin the next:`n%mins% minutes?
- if(ErrorLevel)
- {
- inBreak := 0
- gosub break
- } else {
- ;MsgBox, 262144,, Focus your mind for the next cycle (%CurrentCycleLength% seconds). Press Ok when you are ready.
- inWorkCycle := 1
- inBreak := 0
- Suspend, Off
- seconds := ceil(CurrentCycleLength)
- sizedTask := resizeString(TASK,25)
- FileAppend,`n%A_Now%`t%CurrentCycleLength%s`t%sizedTask%, gtimer.log
- }
- return
- CycleString()
- {
- global
- ConsecutiveFocusMinutes := Floor(ConsecutiveFocusSeconds/ 60)
- StringLen, sumChars, ConsecutiveFocusMinutes
- CycleMinutesElapsed := Ceil(CycleSecondsElapsed / 60)
- CycleCeilingInMinutes := Ceil(CycleCeiling / 60)
- Padding := CycleCeilingInMinutes - CycleMinutesElapsed
- nChar := nChar(CycleMinutesElapsed,1)
- nCharPad := nchar(Padding," ")
- String := "`t" . nChar . nCharPad . "`t" . ConsecutiveFocusMinutes
- return String
- }
- FailBox:
- ;speedBump("Close your eyes until you can remember what *first* distracted you.")
- Gui +LastFound +OwnDialogs +AlwaysOnTop
- mins := cycleSecondsElapsed/60
- InputBox, DISTRACTION, ,Of what you did that differed`nMuch from what you labelled:`n"%TASK%"`,`nHow would you label what you`nCan recall that differed earliest?
- FileAppend,`tDistraction:`t%DISTRACTION%, gtimer.log
- return
- RShift & PgUp::
- CurrentCycleLength := 60
- RShift::
- Gosub EarlyCycleEnd
- return
- RShift & PgDn::
- finish := 1
- closeType := "Finished"
- Gosub EarlyCycleEnd
- return
- RShift & Esc::
- abandon := 1
- closeType := "Abandoned"
- Gosub EarlyCycleEnd
- return
- EarlyCycleEnd:
- inWorkCycle := 0
- minlapsed := CycleSecondsElapsed/60
- minlength := CurrentCycleLength/60
- Suspend, On
- str := CycleString()
- FileAppend,%str%, gtimer.log
- FileAppend,`t(Voluntary) , gtimer.log
- ;SpeedBump("Cycle Ended Early. Until you've decided if, during this cycle, you did deviated from the task """ . TASK . """, close your eyes.")
- MsgBox, 262148, ,%minlength%-minute cycle ended`,`n%minlapsed%-minutes in.`n`nOf what you did, did any of it`,`ndiffer much from:`n`n"%TASK%"?
- IfMsgBox Yes
- {
- ;EARLY FAIL --- no focused time is logged, but time elapses
- CurrentCycleLength := volunteeredFailureLength()
- gosub FailBox
- }
- else
- {
- ;EARLY PASS
- TotalSecondsFocused := TotalSecondsFocused + CycleSecondsElapsed
- AddTaskFocusTime(CycleSecondsElapsed)
- ;FileAppend,`tSuccess!`t`t, gtimer.log
- }
- ;;moved the line below this down
- ;;** do I need this??CycleSecondsElapsed := CurrentCycleLength
- if (finish)
- {
- finish := 0
- gosub close
- }
- if (abaondon)
- {
- abandon := 0
- gosub close
- }
- gosub, CycleStart
- Suspend, Off
- return
- CycleEnd:
- inWorkCycle := 0
- CycleSecondsElapsed := CurrentCycleLength
- Suspend, On
- str := CycleString()
- FileAppend,%str%, gtimer.log
- FileAppend,`t(Prompted), gtimer.log
- inWorkCycle := 0
- mins := CurrentCycleLength/60
- SpeedBump(mins . "-minute cycle through.`nDetermine whether what you did then`nDiffered much from:`n`n""" . TASK . """.")
- MsgBox, 262148, ,Of what you did, did any of it`,`ndiffer much from:`n"%TASK%"?
- IfMsgBox Yes
- Gosub Fail
- else
- Gosub Pass
- Suspend, Off
- return
- Pass:
- Suspend, On
- TotalSecondsFocused := TotalSecondsFocused + CurrentCycleLength
- AddTaskFocusTime(CurrentCycleLength)
- CurrentCycleLength := promptedSuccessLength()
- ;Msgbox, 262144,, You Passed! Your cycle length is now %currentcyclelength%.
- ;FileAppend,`tSuccess!,`t gtimer.log
- Gosub, CycleStart
- Suspend, Off
- return
- Fail:
- Suspend On
- CurrentCycleLength := promptedFailureLength()
- ;Msgbox,262144,, You Failed! Your cycle length is now %currentcyclelength%.
- Gosub, FailBox
- Gosub, CycleStart
- Suspend, Off
- return
- RShift & Ins::
- gosub Break
- return
- Break:
- Suspend, On
- if (!inBreak)
- {
- if(inWorkCycle)
- {
- str := CycleString()
- FileAppend,%str%`t(Voluntary), gtimer.log
- }
- breakSecondsElapsed := 0
- inWorkCycle := 0
- avail := FreeSecondsAvailable() / 60
- Gui +LastFound +OwnDialogs +AlwaysOnTop
- InputBox, BREAKTIME, , You have %avail% minutes of free time earned. How many minutes do you want to break for? (You can resume work early by pressing 'break')
- BREAKTIME := BREAKTIME * 60
- LASTBREAKTIME := BREAKTIME
- inBreak := 1
- CycleSecondsElapsed := 0
- seconds := ceil(BREAKTIME)
- FileAppend,`n%A_Now%`t%seconds%s, gtimer.log
- } else if (inBreak)
- {
- inBreak := 0
- str := BreakString()
- FileAppend,%str%`t(Voluntary), gtimer.log
- CurrentCycleLength := voluntaryResumeLength()
- Gosub CycleStart
- }
- Suspend, Off
- return
- SpeedBump(DecisionText){
- global SpeedBumpLength
- StartTick := A_TickCount
- Loop
- {
- if (SpeedBumpLength = 0)
- {
- break
- }
- MsgBox, 262144, , %DecisionText%
- IfMsgBox, OK
- ElapsedSeconds := (A_TickCount - StartTick)/1000
- if (ElapsedSeconds < SpeedBumpLength)
- {
- ;msgbox here1
- MsgBox, 262144,, You must close your eyes for at least %SpeedBumpLength% seconds. (%ElapsedSeconds% elapsed.)
- } else {
- break
- }
- }
- }
- OutOfFreeTime()
- {
- ;MsgBox Descriptive %Descriptive%
- global TotalSecondsFocused
- global TotalSecondsElapsed
- global TargetFocusPercentage
- global Descriptive
- if(Descriptive)
- {
- ;MsgBox Descriptive %Descriptive%
- return 0
- } else
- {
- return (TotalSecondsFocused/TotalSecondsElapsed < TargetFocusPercentage)
- }
- }
- FreeSecondsAvailable()
- {
- global TotalSecondsFocused
- global TotalSecondsElapsed
- global TargetFocusPercentage
- return TotalSecondsFocused/TargetFocusPercentage - TotalSecondsElapsed
- }
- TargetWorkBreakRatio()
- {
- global TargetFocusPercentage
- return (TargetFocusPercentage / (1 - TargetFocusPercentage) )
- }
- PercentTimeInFocus()
- {
- global TotalSecondsFocused
- global TotalSecondsElapsed
- return TotalSecondsFocused / TotalSecondsElapsed
- }
- ;#n::
- ; inputbox n
- ; inputbox char
- ; msgbox % nChar(n,char)
- ; return
- nChar(n,char)
- {
- String := ""
- while(n>0)
- {
- String := String . char
- n--
- }
- return String
- }
- IniRead:
- IniRead, LastNow, gtimer.ini, data, LastNow, %A_Now%
- IniRead, TotalSecondsElapsed, gtimer.ini, data, TotalSecondsElapsed,-1
- IniRead, CurrentCycleLength, gtimer.ini, data, CurrentCycleLength, 60
- IniRead, TotalSecondsFocused, gtimer.ini, data, TotalSecondsFocused, 0
- IniRead, TASK, gtimer.ini, data, TASK, ""
- IniRead, LongestConsecutiveBreak, gtimer.ini, data, LongestConsecutiveBreak, 0
- IniRead, LongestConsecutiveFocus, gtimer.ini, data, LongestConsecutiveFocus, 0
- IniRead, Descriptive, gtimer.ini, options, Descriptive, 1
- IniRead, TargetFocusPercentage, gtimer.ini, options, TargetFocusPercentage, 0.125
- IniRead, CycleFloor, gtimer.ini, options, CycleFloor,10
- IniRead, CycleCeiling, gtimer.ini, options, CycleCeiling, 1800
- IniRead, SpeedBumpLength, gtimer.ini, options, SpeedBumpLength,2
- return
- IniWrite:
- IniWrite, %A_Now%, gtimer.ini, data, LastNow
- IniWrite, %TotalSecondsElapsed%, gtimer.ini, data, TotalSecondsElapsed
- IniWrite, %CurrentCycleLength%, gtimer.ini, data, CurrentCycleLength
- IniWrite, %TotalSecondsFocused%, gtimer.ini, data, TotalSecondsFocused
- IniWrite, %TASK%, gtimer.ini, data, TASK
- IniWrite, %LongestConsecutiveBreak%, gtimer.ini, data, LongestConsecutiveBreak
- IniWrite, %LongestConsecutiveFocus%, gtimer.ini, data, LongestConsecutiveFocus
- IniWrite, %Descriptive%, gtimer.ini, options, Descriptive
- IniWrite, %TargetFocusPercentage%, gtimer.ini, options, TargetFocusPercentage
- IniWrite, %CycleFloor%, gtimer.ini, options, CycleFloor
- IniWrite, %CycleCeiling%, gtimer.ini, options, CycleCeiling
- IniWrite, %SpeedBumpLength%, gtimer.ini, options, SpeedBumpLength
- return
- Rshift & /::
- Suspend, On
- ;listvars
- temp := inWorkCycle
- inWorkCycle := 0
- ATLN := getAggregateTaskLastNow()
- ATAT := getAggregateTaskActiveTime()
- ATFT := getAggregateTaskFocusTime()
- String := "Cycle: " . CycleSecondsElapsed . " of " . CurrentCycleLength . "`nTotal: " . TotalSecondsElapsed . "`nEarned: " . FreeSecondsAvailable() . "`nTotal Seconds Focused: " . TotalSecondsFocused . "`nTarget Focus Percentage: " . TargetFocusPercentage . "`nFocus Percentage: " . PercentTimeInFocus() . "`nLongest Consecutive Break: " . LongestConsecutiveBreak . "`nLongest Consecutive Focus: " . LongestConsecutiveFocus . "`n`nAggregate Task Last Now: " . ATLN . "`nAggregate Task Active Time: " . ATAT . "`nAggregate Task Focus Time: " . ATFT
- MsgBox 262144, ,%String%
- IfMsgBox, Ok
- Suspend Off
- inWorkCycle := temp
- Suspend, Off
- return
- ;#r::
- ; Inputbox String
- ; Inputbox Size
- ; output := resizeString(String,Size)
- ; msgbox %output%
- ; return
- resizeString(String,Size){
- StringLeft, Trunc, String, Size
- Pad := Size - StrLen(Trunc)
- out := Trunc . nchar(Pad," ")
- return out
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement