add function userchoise and print time entries by daly report
This commit is contained in:
139
timeTrack.py
139
timeTrack.py
@@ -38,6 +38,7 @@ class TimeTrack:
|
|||||||
self.DBCON.close()
|
self.DBCON.close()
|
||||||
|
|
||||||
## Prepartation
|
## Prepartation
|
||||||
|
#==============
|
||||||
### Check OS and clear screen
|
### Check OS and clear screen
|
||||||
def clear_screen(self):
|
def clear_screen(self):
|
||||||
if os.name == 'posix':
|
if os.name == 'posix':
|
||||||
@@ -261,6 +262,7 @@ class TimeTrack:
|
|||||||
return timedata
|
return timedata
|
||||||
|
|
||||||
## user handling
|
## user handling
|
||||||
|
#===============
|
||||||
### Creates a user who does not yet exist
|
### Creates a user who does not yet exist
|
||||||
def create_user(self, USER=''):
|
def create_user(self, USER=''):
|
||||||
if USER == '':
|
if USER == '':
|
||||||
@@ -336,6 +338,7 @@ class TimeTrack:
|
|||||||
self.USERNAME = data[0][1]
|
self.USERNAME = data[0][1]
|
||||||
|
|
||||||
## Time handling
|
## Time handling
|
||||||
|
#===============
|
||||||
### Creates an active event if none exists for the user
|
### Creates an active event if none exists for the user
|
||||||
def save_event(self, TIME=datetime.datetime.now()):
|
def save_event(self, TIME=datetime.datetime.now()):
|
||||||
if not self.get_active_event(USERID=self.USERID):
|
if not self.get_active_event(USERID=self.USERID):
|
||||||
@@ -386,7 +389,7 @@ class TimeTrack:
|
|||||||
else:
|
else:
|
||||||
logging.debug('Event was successfully deleted')
|
logging.debug('Event was successfully deleted')
|
||||||
|
|
||||||
# Checks for existing time entries and creates a new one if none is available.
|
### Checks for existing time entries and creates a new one if none is available.
|
||||||
def time_start(self, AUTOFORWARD=True):
|
def time_start(self, AUTOFORWARD=True):
|
||||||
self.clear_screen()
|
self.clear_screen()
|
||||||
starttime = datetime.datetime.now()
|
starttime = datetime.datetime.now()
|
||||||
@@ -445,7 +448,7 @@ class TimeTrack:
|
|||||||
print('Event von {} Uhr geladen'.format(data[1].strftime("%H:%M")))
|
print('Event von {} Uhr geladen'.format(data[1].strftime("%H:%M")))
|
||||||
self.time_stop()
|
self.time_stop()
|
||||||
|
|
||||||
# Stops existing time entries
|
### Stops existing time entries
|
||||||
def time_stop(self):
|
def time_stop(self):
|
||||||
data = self.get_active_event(USERID=self.USERID)
|
data = self.get_active_event(USERID=self.USERID)
|
||||||
logging.debug('Event stop progess is started')
|
logging.debug('Event stop progess is started')
|
||||||
@@ -504,6 +507,7 @@ class TimeTrack:
|
|||||||
logging.info('Time entry was created successfully')
|
logging.info('Time entry was created successfully')
|
||||||
|
|
||||||
self.delete_event(data[0])
|
self.delete_event(data[0])
|
||||||
|
self.clear_screen()
|
||||||
self.print_time_entry(STARTTIME=data[1], ENDTIME=endtime, ACTIVITY=action)
|
self.print_time_entry(STARTTIME=data[1], ENDTIME=endtime, ACTIVITY=action)
|
||||||
print('Zeiteintrag wurde gespeichert.')
|
print('Zeiteintrag wurde gespeichert.')
|
||||||
userinput = 0
|
userinput = 0
|
||||||
@@ -531,30 +535,41 @@ class TimeTrack:
|
|||||||
logging.debug('Terminated by the user')
|
logging.debug('Terminated by the user')
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
def timedela_to_string(self, TIME):
|
## Interactive mode
|
||||||
s = TIME.seconds
|
#==================
|
||||||
hours, remainder = divmod(s, 3600)
|
### Main menu of the interactive menu
|
||||||
minutes, seconds = divmod(remainder, 60)
|
def start_interactive_mode(self):
|
||||||
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()
|
self.clear_screen()
|
||||||
s = (ENDTIME - STARTTIME).seconds
|
printtext = [
|
||||||
hours, remainder = divmod(s, 3600)
|
'Was willst du tun?',
|
||||||
minutes, seconds = divmod(remainder, 60)
|
'[1] Zeiterfassung starten',
|
||||||
|
'[2] heutiger Report',
|
||||||
print(50*"-")
|
'[3] Report für Tag x',
|
||||||
print('Start: {} Uhr'.format(STARTTIME.strftime('%H:%M')))
|
'[0] Programm verlassen'
|
||||||
print('Ende: {} Uhr'.format(ENDTIME.strftime('%H:%M')))
|
]
|
||||||
print('Dauer: {:02}:{:02}:{:02}'.format(int(hours), int(minutes), int(seconds)))
|
userinput = self.userchoise(printtext, 4)
|
||||||
if not ACTIVITY == '':
|
|
||||||
print('Aktivität:')
|
|
||||||
print(ACTIVITY)
|
|
||||||
print(50*"-")
|
|
||||||
|
|
||||||
def report_by_day(self, DATE=datetime.date.today(), USER=''):
|
if userinput == 1:
|
||||||
|
logging.debug('Start TimeTrack')
|
||||||
|
self.time_start()
|
||||||
|
elif userinput == 2:
|
||||||
|
logging.info('Print todays report')
|
||||||
|
self.report_by_day(DETAIL=True)
|
||||||
|
input()
|
||||||
|
self.start_interactive_mode()
|
||||||
|
elif userinput == 3:
|
||||||
|
print('commig soon ...')
|
||||||
|
input()
|
||||||
|
self.start_interactive_mode()
|
||||||
|
elif userinput == 4:
|
||||||
|
print('commig soon ...')
|
||||||
|
input()
|
||||||
|
self.start_interactive_mode()
|
||||||
|
|
||||||
|
## Reports
|
||||||
|
#=========
|
||||||
|
### One day report, optionally with time entries
|
||||||
|
def report_by_day(self, DATE=datetime.date.today(), USER='', DETAIL=''):
|
||||||
if not USER:
|
if not USER:
|
||||||
USER = self.USERID
|
USER = self.USERID
|
||||||
timedata = self.get_time_entry(DAY=DATE, USERID=USER)
|
timedata = self.get_time_entry(DAY=DATE, USERID=USER)
|
||||||
@@ -584,41 +599,61 @@ class TimeTrack:
|
|||||||
print('{:40} {}'.format("Erfasste Zeit:", self.timedela_to_string(TRACKEDTIME)))
|
print('{:40} {}'.format("Erfasste Zeit:", self.timedela_to_string(TRACKEDTIME)))
|
||||||
print('{:40} {}'.format("Zeiteinträge:", ENTRIECOUNT))
|
print('{:40} {}'.format("Zeiteinträge:", ENTRIECOUNT))
|
||||||
|
|
||||||
def start_interactive_mode(self):
|
printtext = [
|
||||||
self.clear_screen()
|
'Zeiteinträge anzeigen?',
|
||||||
userinput = 0
|
'[1] Ja',
|
||||||
while not 0 < int(userinput) < 4:
|
'[0] Nein'
|
||||||
print('Was willst du tun?')
|
]
|
||||||
print('[1] für Zeiterfassung starten')
|
userinput = self.userchoise(printtext)
|
||||||
print('[2] für heutiger Report')
|
if userinput == 1:
|
||||||
print('[3] für Report für Tag x')
|
for entry in timedata:
|
||||||
print('[9] für Programm verlassen')
|
self.print_time_entry(entry[1], entry[2], entry[4])
|
||||||
|
else:
|
||||||
|
self.start_interactive_mode()
|
||||||
|
|
||||||
|
## Outputs
|
||||||
|
#=========
|
||||||
|
### Shows a time entry
|
||||||
|
def print_time_entry(self, STARTTIME='', ENDTIME='', ACTIVITY=''):
|
||||||
|
s = (ENDTIME - STARTTIME).seconds
|
||||||
|
hours, remainder = divmod(s, 3600)
|
||||||
|
minutes, seconds = divmod(remainder, 60)
|
||||||
|
|
||||||
|
print(50*"-")
|
||||||
|
print('Start: {} Uhr'.format(STARTTIME.strftime('%H:%M')))
|
||||||
|
print('Ende: {} Uhr'.format(ENDTIME.strftime('%H:%M')))
|
||||||
|
print('Dauer: {:02}:{:02}:{:02}'.format(int(hours), int(minutes), int(seconds)))
|
||||||
|
if not ACTIVITY == '':
|
||||||
|
print('Aktivität:')
|
||||||
|
print(ACTIVITY)
|
||||||
|
print(50*"-")
|
||||||
|
|
||||||
|
## Miscellaneous
|
||||||
|
#===============
|
||||||
|
### User selection
|
||||||
|
def userchoise(self, TEXT='', MAX=2):
|
||||||
|
userinput = -1
|
||||||
|
while not -1 < int(userinput) < MAX:
|
||||||
|
for text in TEXT:
|
||||||
|
print(text)
|
||||||
userinput = input('Aktion: ')
|
userinput = input('Aktion: ')
|
||||||
logging.debug('User input: {}'.format(userinput))
|
logging.debug('User input: {}'.format(userinput))
|
||||||
try:
|
try:
|
||||||
int(userinput)
|
int(userinput)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
userinput = 0
|
userinput = -1
|
||||||
else:
|
else:
|
||||||
if int(userinput) == 9:
|
self.clear_screen()
|
||||||
logging.debug('Terminated by the user')
|
return int(userinput)
|
||||||
exit()
|
|
||||||
self.clear_screen()
|
|
||||||
|
|
||||||
if userinput == "1":
|
### Conversion to string of Timedelta typ
|
||||||
logging.debug('Start TimeTrack')
|
def timedela_to_string(self, TIME):
|
||||||
self.time_start()
|
s = TIME.seconds
|
||||||
elif userinput == "2":
|
hours, remainder = divmod(s, 3600)
|
||||||
logging.info('Print todays report')
|
minutes, seconds = divmod(remainder, 60)
|
||||||
self.report_by_day()
|
output = '{:02}:{:02}:{:02}'.format(int(hours), int(minutes), int(seconds))
|
||||||
input()
|
return output
|
||||||
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()
|
||||||
|
|||||||
Reference in New Issue
Block a user