add interactive mode & daly report
This commit is contained in:
119
timeTrack.py
119
timeTrack.py
@@ -3,7 +3,7 @@
|
||||
#
|
||||
# timeTrack.py
|
||||
# by 4nima
|
||||
# v.2.0.4
|
||||
# v.2.1.0
|
||||
#
|
||||
#########################
|
||||
# simple time tracking with database
|
||||
@@ -186,7 +186,7 @@ class TimeTrack:
|
||||
return eventdata[0]
|
||||
|
||||
### 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:
|
||||
logging.debug('Search time entries based on userid: {}'.format(USERID))
|
||||
sql = "SELECT * FROM time_entries WHERE user_id = ?"
|
||||
@@ -230,27 +230,35 @@ class TimeTrack:
|
||||
|
||||
con.close()
|
||||
|
||||
tmp = []
|
||||
if STARTTIME:
|
||||
if DAY:
|
||||
logging.debug('Search time entries by date: {}'.format(DAY))
|
||||
tmp = []
|
||||
for entry in timedata:
|
||||
if entry[1] > STARTTIME:
|
||||
if entry[1].date() == DAY:
|
||||
tmp.append(entry)
|
||||
timedata = tmp[:]
|
||||
pass
|
||||
tmp = []
|
||||
if ENDTIME:
|
||||
for entry in timedata:
|
||||
if entry[2] < ENDTIME:
|
||||
tmp.append(entry)
|
||||
timedata = tmp[:]
|
||||
|
||||
else:
|
||||
tmp = []
|
||||
if STARTTIME:
|
||||
logging.debug('Search time entries by starttime: {}'.format(STARTTIME))
|
||||
for entry in timedata:
|
||||
if entry[1] > STARTTIME:
|
||||
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 == []:
|
||||
logging.debug('No time entries found')
|
||||
return 0
|
||||
else:
|
||||
logging.debug('{} time entries found'.format(len(timedata)))
|
||||
return timedata
|
||||
pass
|
||||
|
||||
## user handling
|
||||
### Creates a user who does not yet exist
|
||||
@@ -514,8 +522,7 @@ class TimeTrack:
|
||||
if userinput == "1":
|
||||
self.time_start()
|
||||
else:
|
||||
logging.debug('Terminated by the user')
|
||||
exit()
|
||||
self.start_interactive_mode()
|
||||
|
||||
elif userinput == "2":
|
||||
logging.info('Event should be deleted (eventid: {})'.format(data[0]))
|
||||
@@ -524,6 +531,13 @@ class TimeTrack:
|
||||
logging.debug('Terminated by the user')
|
||||
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
|
||||
def print_time_entry(self, STARTTIME='', ENDTIME='', ACTIVITY=''):
|
||||
self.clear_screen()
|
||||
@@ -540,10 +554,73 @@ class TimeTrack:
|
||||
print(ACTIVITY)
|
||||
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__":
|
||||
test = TimeTrack()
|
||||
#test.time_start()
|
||||
#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))
|
||||
test.start_interactive_mode()
|
||||
test.DBCON.close()
|
||||
Reference in New Issue
Block a user