def process_user(uid, follower_of=None, top_level_followee=None, nest_level=0, no_followers=False): cur.execute( "insert into metadata (uid, follower_of, top_level_followee, nest_level) values (%s, %s, %s, %s) on conflict (uid) do update set nest_level = least(metadata.nest_level, excluded.nest_level)", (uid, follower_of, top_level_followee, nest_level)) if follower_of: cur.execute( "insert into followers (follower_uid, folowee_uid) values (%s, %s) on conflict (follower_uid, folowee_uid) do nothing", (uid, follower_of)) if aggregate("users", uid) >= 100: users = get_aggregate("users", 100) command("post", "users/lookup", {"user_id": ",".join(users)}, "users") if not no_followers: command("get", "followers/ids", { "user_id": uid, "stringify_ids": True }, "followers", { "user_id": uid, "top_level_followee": top_level_followee, "nest_level": nest_level }) command( "get", "statuses/user_timeline", { "user_id": uid, "trim_user": True, "count": 200, "include_rts": True, "exclude_replies": False }, "tweets", {"user_id": uid})
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)
def CreateJobsheet(jobcode, job_times, d, title, outdir): out = rtf.Rtf() common.assert_job(d, jobcode, "In tblTimeItems, but not jobs") job = d['jobs'][jobcode] sheets = aggregate(job_times, lambda x: (x['Task'], x['Person'])) last_key = sheets[-1][0] for key, values in sheets: task, initials = key taskTitle = task + ' - ' + db.task_desc(d, jobcode, task) person_name = db.initials_to_name(d, initials) AddHeader(title, jobcode, job['title'], taskTitle, person_name, out) #pdb.set_trace() AddPersonToJobsheet(initials, values, out) out.annotation(job) if key != last_key: out.page() out.save(outdir, jobcode + ".rtf" )
def create_timesheets(d): title = 'Timesheet: ' + period.mmmmyyyy() outdir = period.perioddir() + '\\timesheets' for jobKey, job_items in aggregate(d['timeItems'], common.mkKeyFunc('JobCode')): #pdb.set_trace() CreateJobsheet(jobKey, job_items, d, title, outdir)
import pdb import pickle import pprint import common import db def pic(): data = db.fetch() db.save_state(data) #pic() #data = db.load_state() #pic() data = db.fetch() pp = pprint.PrettyPrinter(indent=4) for e in sorted(data['employees']): print e times = filter(lambda x: x['Person'] == e, data['timeItems']) aggregates = common.aggregate(times, lambda x: (x['JobCode'], x['Task'])) for key, vals in aggregates: total_times = common.summate(vals, common.mkKeyFunc('TimeVal')) print key, " ", total_times #pdb.set_trace() #pp.pprint(aggregates) print #print data['timeItems'] print "Finished"