add interactive mode & daly report
This commit is contained in:
119
timeTrack.py
119
timeTrack.py
@@ -3,7 +3,7 @@
|
|||||||
#
|
#
|
||||||
# timeTrack.py
|
# timeTrack.py
|
||||||
# by 4nima
|
# by 4nima
|
||||||
# v.2.0.4
|
# v.2.1.0
|
||||||
#
|
#
|
||||||
#########################
|
#########################
|
||||||
# simple time tracking with database
|
# simple time tracking with database
|
||||||
@@ -186,7 +186,7 @@ class TimeTrack:
|
|||||||
return eventdata[0]
|
return eventdata[0]
|
||||||
|
|
||||||
### Get time entries based on various criteria
|
### Get time entries based on various criteria
|
||||||
def get_time_entry(self, USERID='', TIMEID='', CATEGORYID='', CLIENTID='', REFERENCE='', STARTTIME='', ENDTIME=''):
|
def get_time_entry(self, USERID='', TIMEID='', CATEGORYID='', CLIENTID='', REFERENCE='', STARTTIME='', ENDTIME='', DAY=''):
|
||||||
if USERID:
|
if USERID:
|
||||||
logging.debug('Search time entries based on userid: {}'.format(USERID))
|
logging.debug('Search time entries based on userid: {}'.format(USERID))
|
||||||
sql = "SELECT * FROM time_entries WHERE user_id = ?"
|
sql = "SELECT * FROM time_entries WHERE user_id = ?"
|
||||||
@@ -230,27 +230,35 @@ class TimeTrack:
|
|||||||
|
|
||||||
con.close()
|
con.close()
|
||||||
|
|
||||||
tmp = []
|
if DAY:
|
||||||
if STARTTIME:
|
logging.debug('Search time entries by date: {}'.format(DAY))
|
||||||
|
tmp = []
|
||||||
for entry in timedata:
|
for entry in timedata:
|
||||||
if entry[1] > STARTTIME:
|
if entry[1].date() == DAY:
|
||||||
tmp.append(entry)
|
tmp.append(entry)
|
||||||
timedata = tmp[:]
|
timedata = tmp[:]
|
||||||
pass
|
else:
|
||||||
tmp = []
|
tmp = []
|
||||||
if ENDTIME:
|
if STARTTIME:
|
||||||
for entry in timedata:
|
logging.debug('Search time entries by starttime: {}'.format(STARTTIME))
|
||||||
if entry[2] < ENDTIME:
|
for entry in timedata:
|
||||||
tmp.append(entry)
|
if entry[1] > STARTTIME:
|
||||||
timedata = tmp[:]
|
tmp.append(entry)
|
||||||
|
timedata = tmp[:]
|
||||||
|
pass
|
||||||
|
tmp = []
|
||||||
|
if ENDTIME:
|
||||||
|
logging.debug('Search time entrie by endtime: {}'.format(ENDTIME))
|
||||||
|
for entry in timedata:
|
||||||
|
if entry[2] < ENDTIME:
|
||||||
|
tmp.append(entry)
|
||||||
|
timedata = tmp[:]
|
||||||
if timedata == []:
|
if timedata == []:
|
||||||
logging.debug('No time entries found')
|
logging.debug('No time entries found')
|
||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
logging.debug('{} time entries found'.format(len(timedata)))
|
logging.debug('{} time entries found'.format(len(timedata)))
|
||||||
return timedata
|
return timedata
|
||||||
pass
|
|
||||||
|
|
||||||
## user handling
|
## user handling
|
||||||
### Creates a user who does not yet exist
|
### Creates a user who does not yet exist
|
||||||
@@ -514,8 +522,7 @@ class TimeTrack:
|
|||||||
if userinput == "1":
|
if userinput == "1":
|
||||||
self.time_start()
|
self.time_start()
|
||||||
else:
|
else:
|
||||||
logging.debug('Terminated by the user')
|
self.start_interactive_mode()
|
||||||
exit()
|
|
||||||
|
|
||||||
elif userinput == "2":
|
elif userinput == "2":
|
||||||
logging.info('Event should be deleted (eventid: {})'.format(data[0]))
|
logging.info('Event should be deleted (eventid: {})'.format(data[0]))
|
||||||
@@ -524,6 +531,13 @@ class TimeTrack:
|
|||||||
logging.debug('Terminated by the user')
|
logging.debug('Terminated by the user')
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
|
def timedela_to_string(self, TIME):
|
||||||
|
s = TIME.seconds
|
||||||
|
hours, remainder = divmod(s, 3600)
|
||||||
|
minutes, seconds = divmod(remainder, 60)
|
||||||
|
output = '{:02}:{:02}:{:02}'.format(int(hours), int(minutes), int(seconds))
|
||||||
|
return output
|
||||||
|
|
||||||
# Shows a time entry
|
# Shows a time entry
|
||||||
def print_time_entry(self, STARTTIME='', ENDTIME='', ACTIVITY=''):
|
def print_time_entry(self, STARTTIME='', ENDTIME='', ACTIVITY=''):
|
||||||
self.clear_screen()
|
self.clear_screen()
|
||||||
@@ -540,10 +554,73 @@ class TimeTrack:
|
|||||||
print(ACTIVITY)
|
print(ACTIVITY)
|
||||||
print(50*"-")
|
print(50*"-")
|
||||||
|
|
||||||
|
def report_by_day(self, DATE=datetime.date.today(), USER=''):
|
||||||
|
if not USER:
|
||||||
|
USER = self.USERID
|
||||||
|
timedata = self.get_time_entry(DAY=DATE, USERID=USER)
|
||||||
|
|
||||||
|
STARTTIMES = []
|
||||||
|
ENDTIMES = []
|
||||||
|
DURATIONS = []
|
||||||
|
|
||||||
|
for entry in timedata:
|
||||||
|
STARTTIMES.append(entry[1])
|
||||||
|
ENDTIMES.append(entry[2])
|
||||||
|
DURATIONS.append(entry[2] - entry[1])
|
||||||
|
|
||||||
|
if timedata:
|
||||||
|
FIRSTSTARTTIME = min(STARTTIMES)
|
||||||
|
LASTENDTIME = max(ENDTIMES)
|
||||||
|
TRACKEDTIMESPAN = (LASTENDTIME - FIRSTSTARTTIME)
|
||||||
|
TRACKEDTIME = sum(DURATIONS, datetime.timedelta())
|
||||||
|
NONTRACKEDTIME = (TRACKEDTIMESPAN - TRACKEDTIME)
|
||||||
|
ENTRIECOUNT = len(timedata)
|
||||||
|
|
||||||
|
self.clear_screen()
|
||||||
|
print('{:40} {}'.format("Beginn des ersten Zeiteintrags:", FIRSTSTARTTIME.strftime('%d.%m.%Y %H:%M')))
|
||||||
|
print('{:40} {}'.format("Ende des letzen Zeiteintrags:", LASTENDTIME.strftime('%d.%m.%Y %H:%M')))
|
||||||
|
print('{:40} {}'.format("Maximal erfassbare Zeit:", self.timedela_to_string(TRACKEDTIMESPAN)))
|
||||||
|
print('{:40} {}'.format("Nicht erfasste Zeit:", self.timedela_to_string(NONTRACKEDTIME)))
|
||||||
|
print('{:40} {}'.format("Erfasste Zeit:", self.timedela_to_string(TRACKEDTIME)))
|
||||||
|
print('{:40} {}'.format("Zeiteinträge:", ENTRIECOUNT))
|
||||||
|
|
||||||
|
def start_interactive_mode(self):
|
||||||
|
self.clear_screen()
|
||||||
|
userinput = 0
|
||||||
|
while not 0 < int(userinput) < 4:
|
||||||
|
print('Was willst du tun?')
|
||||||
|
print('[1] für Zeiterfassung starten')
|
||||||
|
print('[2] für heutiger Report')
|
||||||
|
print('[3] für Report für Tag x')
|
||||||
|
print('[9] für Programm verlassen')
|
||||||
|
userinput = input('Aktion: ')
|
||||||
|
logging.debug('User input: {}'.format(userinput))
|
||||||
|
try:
|
||||||
|
int(userinput)
|
||||||
|
except ValueError:
|
||||||
|
userinput = 0
|
||||||
|
else:
|
||||||
|
if int(userinput) == 9:
|
||||||
|
logging.debug('Terminated by the user')
|
||||||
|
exit()
|
||||||
|
self.clear_screen()
|
||||||
|
|
||||||
|
if userinput == "1":
|
||||||
|
logging.debug('Start TimeTrack')
|
||||||
|
self.time_start()
|
||||||
|
elif userinput == "2":
|
||||||
|
logging.info('Print todays report')
|
||||||
|
self.report_by_day()
|
||||||
|
input()
|
||||||
|
self.start_interactive_mode()
|
||||||
|
elif userinput == "3":
|
||||||
|
print('commig soon ...')
|
||||||
|
input()
|
||||||
|
self.start_interactive_mode()
|
||||||
|
|
||||||
|
print(userinput)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test = TimeTrack()
|
test = TimeTrack()
|
||||||
#test.time_start()
|
test.start_interactive_mode()
|
||||||
#test.DBCON.close()
|
test.DBCON.close()
|
||||||
start = datetime.datetime(2021,6,4,18)
|
|
||||||
end = datetime.datetime(2021,6,5,11,30)
|
|
||||||
print(test.get_time_entry(STARTTIME=start, ENDTIME=end))
|
|
||||||
Reference in New Issue
Block a user