Created
April 30, 2015 11:16
-
-
Save minorsecond/49cc31e4c6cffcf7a653 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 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 = float(diff.seconds / 3600) | |
# Short tasks (6 minutes or less) still count as .1 of an hour per my company's policy. | |
if time < .1: | |
time = .1 | |
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) | |
print('time = {0}').format(time) | |
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') | |
clk = session.query(Clocktime).order_by(Clocktime.id.desc()).first() | |
clock_id = clk.id | |
print(clock_id) | |
session.query(Clocktime). \ | |
filter(Clocktime.id == clock_id). \ | |
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() | |
# Round the sum of tenths of an hour worked to the nearest tenth and then update to job table. | |
sum_time = float(round_to_nearest(_sum_time, .1)) | |
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