Implemented properly ending days.
This commit is contained in:
parent
288a055712
commit
233ca3fcee
33
data.py
33
data.py
@ -114,6 +114,11 @@ class Log:
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._data = Data()
|
self._data = Data()
|
||||||
|
|
||||||
|
def cleanup():
|
||||||
|
self.log("End")
|
||||||
|
|
||||||
|
atexit.register(cleanup)
|
||||||
|
|
||||||
def log(self, task, ptime=None):
|
def log(self, task, ptime=None):
|
||||||
if ptime is None:
|
if ptime is None:
|
||||||
ptime = datetime.now()
|
ptime = datetime.now()
|
||||||
@ -126,11 +131,22 @@ class Log:
|
|||||||
.append(f"{ptime.strftime('%H:%M')} {base64.b64encode(task.encode('utf-8')).decode('utf-8')}")
|
.append(f"{ptime.strftime('%H:%M')} {base64.b64encode(task.encode('utf-8')).decode('utf-8')}")
|
||||||
self._data[ptime.strftime("%Y-%m")] = month
|
self._data[ptime.strftime("%Y-%m")] = month
|
||||||
|
|
||||||
def last_log(self, pdate=date.today()):
|
def last_log(self, pdate=None):
|
||||||
if pdate.strftime("%Y-%m") not in self._data or pdate.strftime("%d") not in self._data[pdate.strftime("%Y-%m")]:
|
if pdate is None:
|
||||||
|
pdate = date.today()
|
||||||
|
if pdate.strftime("%Y-%m") not in self._data \
|
||||||
|
or pdate.strftime("%d") not in self._data[pdate.strftime("%Y-%m")] \
|
||||||
|
or len(self._data[pdate.strftime("%Y-%m")][pdate.strftime("%d")]) == 0:
|
||||||
return None
|
return None
|
||||||
return base64.b64decode(
|
last = base64.b64decode(
|
||||||
self._data[pdate.strftime("%Y-%m")][pdate.strftime("%d")][-1].split()[1].encode("utf-8")).decode("utf-8")
|
self._data[pdate.strftime("%Y-%m")][pdate.strftime("%d")][-1].split()[1].encode("utf-8")).decode("utf-8")
|
||||||
|
if last == "End":
|
||||||
|
month = self._data[pdate.strftime("%Y-%m")]
|
||||||
|
del month[pdate.strftime("%d")][-1]
|
||||||
|
self._data[pdate.strftime("%Y-%m")] = month
|
||||||
|
last = base64.b64decode(
|
||||||
|
self._data[pdate.strftime("%Y-%m")][pdate.strftime("%d")][-1].split()[1].encode("utf-8")).decode("utf-8")
|
||||||
|
return last
|
||||||
|
|
||||||
def report(self, pdate=None):
|
def report(self, pdate=None):
|
||||||
if pdate is None:
|
if pdate is None:
|
||||||
@ -150,6 +166,8 @@ class Report:
|
|||||||
task = base64.b64decode(b64str.encode("utf-8")).decode("utf-8")
|
task = base64.b64decode(b64str.encode("utf-8")).decode("utf-8")
|
||||||
start_time = datetime.combine(self._date, datetime.strptime(tstr, "%H:%M").time())
|
start_time = datetime.combine(self._date, datetime.strptime(tstr, "%H:%M").time())
|
||||||
tmp.append((task, start_time))
|
tmp.append((task, start_time))
|
||||||
|
if self._date == date.today():
|
||||||
|
tmp.append(("End", datetime.now()))
|
||||||
|
|
||||||
ret = []
|
ret = []
|
||||||
dsum = timedelta()
|
dsum = timedelta()
|
||||||
@ -157,13 +175,13 @@ class Report:
|
|||||||
task, start_time = t
|
task, start_time = t
|
||||||
if i < len(tmp) - 1:
|
if i < len(tmp) - 1:
|
||||||
end_time = tmp[i+1][1]
|
end_time = tmp[i+1][1]
|
||||||
else:
|
|
||||||
end_time = datetime.now()
|
|
||||||
duration = end_time - start_time
|
duration = end_time - start_time
|
||||||
dsum += duration
|
dsum += duration
|
||||||
dhours, rem = divmod(duration.seconds, 3600)
|
dhours, rem = divmod(duration.seconds, 3600)
|
||||||
dmins, _ = divmod(rem, 60)
|
dmins, _ = divmod(rem, 60)
|
||||||
ret.append((task, start_time.strftime("%H:%M"), f"{dhours:02d}:{dmins:02d}"))
|
ret.append((task, start_time.strftime("%H:%M"), f"{dhours:02d}:{dmins:02d}"))
|
||||||
|
else:
|
||||||
|
ret.append((task, start_time.strftime("%H:%M"), ""))
|
||||||
|
|
||||||
ret.append(("", "", ""))
|
ret.append(("", "", ""))
|
||||||
dhours, rem = divmod(dsum.seconds, 3600)
|
dhours, rem = divmod(dsum.seconds, 3600)
|
||||||
@ -172,7 +190,10 @@ class Report:
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
def save(self, report):
|
def save(self, report):
|
||||||
report = report[:-2] # cut of sum display
|
if self._date == date.today():
|
||||||
|
report = report[:-3] # cut off sum display and end time
|
||||||
|
else:
|
||||||
|
report = report[:-2] # cut off sum display
|
||||||
save_list = []
|
save_list = []
|
||||||
for tstr, ttime, _ in report:
|
for tstr, ttime, _ in report:
|
||||||
b64str = base64.b64encode(tstr.encode("utf-8")).decode("utf-8")
|
b64str = base64.b64encode(tstr.encode("utf-8")).decode("utf-8")
|
||||||
|
10
main.py
10
main.py
@ -17,7 +17,7 @@ class App:
|
|||||||
|
|
||||||
self.tasks = Tasks()
|
self.tasks = Tasks()
|
||||||
self.log = Log()
|
self.log = Log()
|
||||||
self.active_task = self.log.last_log() or "Pause"
|
self.active_task = self.log.last_log() or "Nothing"
|
||||||
|
|
||||||
icon = QtGui.QIcon.fromTheme("appointment-new")
|
icon = QtGui.QIcon.fromTheme("appointment-new")
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ class App:
|
|||||||
self.taskEdit.accepted.connect(self.tasks_edited)
|
self.taskEdit.accepted.connect(self.tasks_edited)
|
||||||
|
|
||||||
self.reportDialog = Report(None)
|
self.reportDialog = Report(None)
|
||||||
self.taskEdit.accepted.connect(self.tasks_edited)
|
self.reportDialog.accepted.connect(self.report_done)
|
||||||
|
|
||||||
@QtCore.Slot()
|
@QtCore.Slot()
|
||||||
def tasks_edited(self):
|
def tasks_edited(self):
|
||||||
@ -43,12 +43,12 @@ class App:
|
|||||||
|
|
||||||
@QtCore.Slot()
|
@QtCore.Slot()
|
||||||
def report_done(self):
|
def report_done(self):
|
||||||
self.active_task = self.log.last_log() or "Pause"
|
self.active_task = self.log.last_log() or "Nothing"
|
||||||
self.update_tray_menu()
|
self.update_tray_menu()
|
||||||
|
|
||||||
def change_task(self, task):
|
def change_task(self, task):
|
||||||
self.active_task = task
|
self.active_task = task
|
||||||
if task == "Pause":
|
if task == "Nothing":
|
||||||
return
|
return
|
||||||
self.log.log(task)
|
self.log.log(task)
|
||||||
self.update_tray_menu()
|
self.update_tray_menu()
|
||||||
@ -56,7 +56,7 @@ class App:
|
|||||||
def update_tray_menu(self):
|
def update_tray_menu(self):
|
||||||
self.menu.clear()
|
self.menu.clear()
|
||||||
tasks = list(self.tasks.tasks)
|
tasks = list(self.tasks.tasks)
|
||||||
tasks.append("Pause")
|
tasks.append("Nothing")
|
||||||
|
|
||||||
for t in tasks:
|
for t in tasks:
|
||||||
a = self.menu.addAction(t)
|
a = self.menu.addAction(t)
|
||||||
|
@ -65,7 +65,7 @@ class Report(QtWidgets.QDialog):
|
|||||||
self.tableWidget.setItem(row, 2, item2)
|
self.tableWidget.setItem(row, 2, item2)
|
||||||
item0.setFlags(item0.flags() & QtCore.Qt.ItemIsEnabled)
|
item0.setFlags(item0.flags() & QtCore.Qt.ItemIsEnabled)
|
||||||
item2.setFlags(item2.flags() & QtCore.Qt.ItemIsEnabled)
|
item2.setFlags(item2.flags() & QtCore.Qt.ItemIsEnabled)
|
||||||
if row > len(self._report_data) - 3:
|
if row > len(self._report_data) - 4:
|
||||||
item1.setFlags(item1.flags() & QtCore.Qt.ItemIsEnabled)
|
item1.setFlags(item1.flags() & QtCore.Qt.ItemIsEnabled)
|
||||||
|
|
||||||
self.tableWidget.resizeColumnsToContents()
|
self.tableWidget.resizeColumnsToContents()
|
||||||
@ -87,7 +87,7 @@ class Report(QtWidgets.QDialog):
|
|||||||
@QtCore.Slot()
|
@QtCore.Slot()
|
||||||
def del_log(self):
|
def del_log(self):
|
||||||
row = self.tableWidget.currentRow()
|
row = self.tableWidget.currentRow()
|
||||||
if row > len(self._report_data) - 3:
|
if row > len(self._report_data) - 4:
|
||||||
return
|
return
|
||||||
del self._report_data[row]
|
del self._report_data[row]
|
||||||
self.refresh_table()
|
self.refresh_table()
|
||||||
@ -101,6 +101,7 @@ class Report(QtWidgets.QDialog):
|
|||||||
def previous(self):
|
def previous(self):
|
||||||
self._report.save(self._report_data)
|
self._report.save(self._report_data)
|
||||||
self._report.previous()
|
self._report.previous()
|
||||||
|
self._report_data = self._report.report()
|
||||||
self.refresh_table()
|
self.refresh_table()
|
||||||
self.update_prev_next()
|
self.update_prev_next()
|
||||||
|
|
||||||
@ -108,5 +109,6 @@ class Report(QtWidgets.QDialog):
|
|||||||
def next(self):
|
def next(self):
|
||||||
self._report.save(self._report_data)
|
self._report.save(self._report_data)
|
||||||
self._report.next()
|
self._report.next()
|
||||||
|
self._report_data = self._report.report()
|
||||||
self.refresh_table()
|
self.refresh_table()
|
||||||
self.update_prev_next()
|
self.update_prev_next()
|
||||||
|
Loading…
Reference in New Issue
Block a user