This repository was archived by the owner on Aug 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuserHistoric.py
86 lines (77 loc) · 3.84 KB
/
userHistoric.py
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
from datetime import date, time, datetime
from qgis.core import QgsSettings
class UserHistoric:
# TODO UserHistoric should be a singleton
def __init__(self):
self.s = QgsSettings()
variables = ['dateLastAcess', 'sThisSession', 'fThisSession',
'workTime', 'idleTime',
'greatWorkTime', 'greatIdleTime', 'tmpGreatWorkTime',
'tmpGreatIdleTime', 'idleSince', 'timeFirstAcess']
dateLastAcess = self.s.value("pomodoro/dateLastAcess", None)
self.lastStatus = True
self.tick = 1
# TODO after implementing a singleton, date.today() should be updated inside init
if dateLastAcess == date.today().isoformat():
self.vars = {x: self.s.value(f"pomodoro/{x}", 0)
for x in variables}
else:
self.restartVariables()
self.vars = {x: self.s.value(f"pomodoro/{x}", 0)
for x in variables}
self.vars['timeFirstAcess'] = datetime.time(
datetime.now()).isoformat(timespec='minutes')
self.s.setValue('pomodoro/timeFirstAcess', self.vars['timeFirstAcess'])
self.s.setValue('pomodoro/dateLastAcess', date.today().isoformat())
# TODO setValue should be called from an unique function which receives the param name
def updateSucess(self):
self.vars['sThisSession'] = int(self.vars['sThisSession']) + self.tick
self.s.setValue('pomodoro/sThisSession', self.vars['sThisSession'])
def updateFail(self):
self.vars['fThisSession'] = int(self.vars['fThisSession']) + self.tick
self.s.setValue('pomodoro/fThisSession', self.vars['fThisSession'])
def updateWorkTime(self):
self.vars['workTime'] = int(self.vars['workTime']) + self.tick
self.s.setValue('pomodoro/workTime', self.vars['workTime'])
self.vars['idleSince'] = 0
if self.lastStatus:
self.vars['tmpGreatWorkTime'] = int(
self.vars['tmpGreatWorkTime']) + self.tick
else:
self.vars['tmpGreatWorkTime'] = 0
self.lastStatus = True
self.updatelongestWorkTime()
def updateIdleTime(self):
# TODO idleSince not updating correctly
self.vars['idleTime'] = int(self.vars['idleTime']) + self.tick
self.s.setValue('pomodoro/idleTime', self.vars['idleTime'])
if not self.lastStatus:
self.vars['tmpGreatIdleTime'] = int(
self.vars['tmpGreatIdleTime']) + self.tick
self.vars['idleSince'] = self.vars['tmpGreatIdleTime']
else:
self.vars['tmpGreatIdleTime'] = 0
self.lastStatus = False
self.updatelongestWorkTime()
def updatelongestWorkTime(self):
tmpGreatWorkTime, greatWorkTime, tmpGreatIdleTime, greatIdleTime = [
int(self.vars['tmpGreatWorkTime']), int(
self.vars['greatWorkTime']),
int(self.vars['tmpGreatIdleTime']), int(self.vars['greatIdleTime'])
]
if tmpGreatWorkTime > greatWorkTime:
self.vars['greatWorkTime'] = tmpGreatWorkTime
self.s.setValue('pomodoro/greatWorkTime',
self.vars['greatWorkTime'])
if tmpGreatIdleTime > greatIdleTime:
self.vars['greatIdleTime'] = tmpGreatIdleTime
self.s.setValue('pomodoro/greatIdleTime',
self.vars['greatIdleTime'])
self.s.setValue('pomodoro/dateLastAcess', date.today().isoformat())
def restartVariables(self):
variables = ['dateLastAcess', 'sThisSession', 'fThisSession',
'workTime', 'idleTime',
'greatWorkTime', 'greatIdleTime', 'tmpGreatWorkTime',
'tmpGreatIdleTime', 'idleSince', 'timeFirstAcess']
for item in variables:
self.s.setValue(f'pomodoro/{item}', 0)