summaryrefslogtreecommitdiff
path: root/main.py
blob: 1c3846e47dbec2e7b53893d52e81b7d52125bf10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/python3
import pygal
import csv
import time
import datetime
import hashlib
from collections import OrderedDict
import inputs
import timers
import formatting as f

print("welcome to lock-n-log, the best way to organise and analyse your focus time!")

ratio = 1/3 # default for now
sesh_type = "focus"

print("tag for session? ", end="", flush=True)
tag = input()
if tag == "":
    tag = "work"

valid_timer_types = ('t', 's')
option = False
while not option:
    print("(t)imer or (s)topwatch? ", end="", flush=True)
    option = inputs.get_valid_char(valid_timer_types)
    print("")

if option == 't':
    timer = "timer"
    print("timer length (in minutes)? ", end="", flush=True)
    timer_length = inputs.get_pos_int()
    while not timer_length:
        print("please enter a positive integer")
        print("timer length (in minutes)? ", end="", flush=True)
        timer_length = inputs.get_pos_int()
else:
    timer = "stopwatch"
    timer_length = 0
    print("whenever you're ready, press enter to start", end="", flush=True)
    input()

sesh_list = []
elapsed_total = 0
elapsed, rest, start = timers.timer(timer_length, ratio)
session_id = hashlib.sha256(str(start).encode('utf8')).hexdigest()
while rest > 0:
    session = OrderedDict()
    session["id"] = session_id
    session["date"] = start.strftime("%Y-%m-%d")
    session["start"] = start.strftime("%H:%M:%S")
    session["elapsed"] = int(elapsed)
    session["type"] = sesh_type
    session["tag"] = tag
    session["timer"] = timer
    session["ratio"] = ratio
    sesh_list.append(session)
    elapsed_total += elapsed

    sesh_type = "rest"
    elapsed, dontcare, start = timers.timer(rest, 0, 0)
    if elapsed >= rest: # if exceeded break bank, then focus session ended
        break
    else:
        rest -= elapsed
    session = OrderedDict()
    session["id"] = session_id
    session["date"] = start.strftime("%Y-%m-%d")
    session["start"] = start.strftime("%H:%M:%S")
    session["elapsed"] = int(elapsed)
    session["type"] = sesh_type
    session["tag"] = tag
    session["timer"] = timer
    session["ratio"] = ratio
    sesh_list.append(session)

    sesh_type = "focus"
    elapsed, rest, start = timers.timer(0, ratio, rest, elapsed_total)
    if rest == 0:
        break

print("\nfocus session finished!\nlogging...")
session = OrderedDict()
session["id"] = session_id
session["date"] = start.strftime("%Y-%m-%d")
session["start"] = start.strftime("%H:%M:%S")
session["elapsed"] = int(elapsed)
session["type"] = sesh_type
session["tag"] = tag
session["timer"] = timer
session["ratio"] = ratio
sesh_list.append(session)

for session in sesh_list:
#    print(session)
    f.sesh_to_log(session, "main.csv")