def create_recovery_report(d, the_tweaks): camel_recoveries = tweaks.tweak_recoveries(the_tweaks) jobcodes_to_process = set(tweaks.tweaked_jobs(the_tweaks)) db_recoveries = get_dbase_recoveries(d) for k, v in db_recoveries.items(): if abs(v) >= 0.01: jobcodes_to_process.add(k) jobcodes_to_process = sorted(list(jobcodes_to_process)) output = ['RECOVERY RECONILIATION', ''] tweaks_grand_total = 0.0 pms_grand_total = 0.0 for job_code in jobcodes_to_process: job = d['jobs'][job_code] # TODO - d['jobs'][job_code] is a common idiom which ought to be abstracted camel_job_recoveries = dget(camel_recoveries, job_code, []) db_job_recovery = dget(db_recoveries, job_code) tweak_amount, recovery_text = create_recovery_text(job, camel_job_recoveries, db_job_recovery) output += recovery_text tweaks_grand_total += tweak_amount pms_grand_total += db_job_recovery output.append('SUMMARY:') output.append(line(tweaks_grand_total, 'TWEAKS GRAND TOTAL')) output.append(line(pms_grand_total, 'PMS GRAND TOTAL')) output.append(line(tweaks_grand_total - pms_grand_total, 'OVERALL DIFF')) period.save_report('recoveries.txt', output)
def create_health_report(d): #db.save_state(d) global debug stats = {} total_all_hours = 0.0 total_staff_hours = 0.0 total_leave_and_sickness = 0.0 time_items = d['timeItems'] las_test = lambda(x): employee['IsStaff'] and (x['JobCode'] == '010400' or x['JobCode'] == '010500') #fmt = '{0:4} {1:15} {2:>10} {3:>10} {4:>10}' output = [] def add_line(text): output.append(text) def add_formatted_line(*fields): text = [] for fmt, value in zip('{0:4} {0:15} {0:>10} {0:>10} {0:>10}'.split(' '), fields): #pdb.set_trace() #print fmt, "---", value text.append(fmt.format(value)) text = ' '.join(text) add_line(text) #dir = period.reportdir(d['period']) #filename = dir +'\\health.txt' #output = file(filename, "w") add_formatted_line('INI', 'NAME', 'LEAV/SICK', 'STAFF', 'ALL') for employee_initials, worker_times in common.aggregate(time_items, common.mkKeyFunc('Person')): try: employee = d['employees'][employee_initials] except KeyError: continue full_name = employee['PersonNAME'] time_val = mkKeyFunc('TimeVal') #if debug and employee_initials == "AM": pdb.set_trace() staff_hours = summate(worker_times, time_val, lambda(x): employee['IsStaff']) total_staff_hours += staff_hours leave_and_sickness = summate(worker_times, time_val, las_test) total_leave_and_sickness += leave_and_sickness all_hours = summate(worker_times, time_val) total_all_hours += all_hours add_formatted_line(employee_initials, full_name, leave_and_sickness, staff_hours, all_hours) add_formatted_line('', 'TOTALS' , total_leave_and_sickness, total_staff_hours, total_all_hours) add_line('\nHealth & Safety Stats:') add_line('Staff hours less leave & sickness: {0} - * this goes into cell I8'.format(total_staff_hours - total_leave_and_sickness)) add_line('Total all hours: {0}'.format(total_all_hours)) #output.close() period.save_report('health.txt', output)