Last active
August 29, 2015 14:20
-
-
Save minorsecond/e7fe68c0ae5b13a62755 to your computer and use it in GitHub Desktop.
Broken function in tc.py. It runs but does not calculate _sum_time correctly. If tworked is > .1, funky things happen.For example, in the job table.. "worked" held 0.2. When .2 was supposed to be added to it, .2 was written again.I suspect my logic is incorrect but I can't find it. Help please?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def clockout(): | |
""" | |
Clocks user out of project. Prints time_out (now) to clocktimes table for whichever row contains the same | |
p_uuid created in project_start(). | |
:rtype : object | |
:return: | |
""" | |
if status == 0: | |
raw_input("You're not currently in a job. Press enter to return to main menu") | |
main_menu() | |
else: | |
global status | |
global start_time | |
global tworked | |
_sum_time = 0 | |
sel = session.query(Job).order_by(Job.id.desc()).first() | |
job_name = sel.name | |
job_abbrev = sel.abbr | |
now = datetime.now() | |
print '\nStopping {0}, project ID {1} at {2}:{3} on {4}/{5}/{6}'.format(job_name, job_abbrev, now.hour, \ | |
now.minute, now.day, now.month, now.year) | |
# Get difference between start time and now, and then convert to tenths of an hour. | |
diff = datetime.now() - start_time | |
time_worked = float(round_to_nearest(diff.seconds, 360)) / 3600 | |
if time_worked < .1: | |
time_worked = .1 | |
if debug == 1: | |
print("Variables -- Start Time {0}. Current Time: {1}. Diff: {2}. Time: {3}") \ | |
.format(start_time, datetime.now(), diff, time_worked) | |
print('diff.seconds = {0}').format(diff.seconds) | |
raw_input("Press enter to continue.") | |
print ("Enjoy! You worked {0} hours on {1}.").format(time_worked, job_name) | |
raw_input("\nPress enter to return to main menu.") | |
status = 0 | |
# Update Clocktime table with time out and time worked. | |
session.query(Clocktime). \ | |
filter(Clocktime.p_uuid == p_uuid). \ | |
update({"time_out": now}, synchronize_session='fetch') | |
# Something is going on with this code or with the _sum_time += i.tworked below. | |
session.query(Clocktime). \ | |
filter(Clocktime.p_uuid == p_uuid). \ | |
update({'tworked': time_worked}, synchronize_session='fetch') | |
# Get all rows in clocktime for current job, by p_uuid and then sum these tenths of an hour. | |
tworked = session.query(Clocktime).filter(Clocktime.p_uuid == p_uuid).order_by(Clocktime.id.desc()).all() | |
for i in tworked: | |
_sum_time += i.tworked | |
if debug == 1: | |
print("Debugging: sum of time for {0} is {1}").format(i.job_id, _sum_time) | |
raw_input() | |
session.query(Job). \ | |
filter(Job.p_uuid == p_uuid). \ | |
update({"worked": _sum_time}, synchronize_session='fetch') | |
session.commit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think issues begin in line 47.