def GenerateProjectReport(): outfile = open("./DssProjectReport.txt", 'w') outfile.write("Project | Type | Sessions | Not Enabled | Observers | Complete | Incomplete | Avail / Rem Hrs | Obs Hrs | Blackout | Backup | Receivers\n") count = 0 open_projects = sorted(Project.objects.filter(complete = False) , lambda x, y: cmp(x.pcode, y.pcode)) for p in open_projects: for typ in get_type(p): if count % 5 == 0: outfile.write("-------------------------------------------------------------------------------------------------------------------------------------------\n") count += 1 outfile.write( "%s | %s | %s | %s | %s | %s | %s | %s | %s | %s | %s | %s\n" % \ (p.pcode.ljust(11) , typ.center(8) , str(len(p.sesshun_set.all())).center(8) , str(len(get_sessions(p, typ, False))).center(11) , str(len(p.get_observers())).center(9) , str(len([s for s in p.sesshun_set.all() \ if s.status.complete == True])).center(8) , str(len(get_sessions(p, typ))).center(10) , "".join([str(get_rem_schedulable_hours(p, typ)), " / ", str(get_rem_hours(p,typ))]).rjust(16) , str(get_obs_hours(p,typ)).center(7) , "Yes".center(8) if any([len(o.user.blackout_set.all()) == 0 for o in p.get_observers()]) else " " , "Yes".center(6) if any([s.status.backup for s in p.sesshun_set.all()]) else " " , get_rcvrs(p, typ) ) ) semester = Semester.getCurrentSemester() SEMESTER_HOURS = (semester.end() - semester.start()).days * 24. semester_hrs_left = (semester.end() - datetime.today()).days * 24. outfile.write("\nTotal hours in this semester = %.1f"% SEMESTER_HOURS) outfile.write("\nTotal hours left this semester = %.1f\n" % \ semester_hrs_left) ta = TimeAccounting() hours = sum([ta.getTimeLeft(p) for p in open_projects]) remainingRatio = float(hours / semester_hrs_left * 100.) if semester_hrs_left != 0 else 0.0 outfile.write("\nSum of all incomplete projects' hours remaining = %.1f" % hours) outfile.write("\nHours remaining / Trimester Hours = %.1f%%" % (hours / SEMESTER_HOURS * 100.)) outfile.write("\nHours remaining / Trimester Hours Left = %.1f%%\n" % remainingRatio) hours = sum([ta.getProjectSchedulableTotalTime(p) for p in open_projects]) schedulableRatio = float(hours / semester_hrs_left * 100.) if semester_hrs_left != 0 else 0.0 outfile.write("\nSum of all schedulable time = %.1f" % \ hours) outfile.write("\nSchedulable time / Trimester Hours = %.1f%%" % (hours / SEMESTER_HOURS * 100.)) outfile.write("\nSchedulable time / Trimester Hours Left = %.1f%%\n" % schedulableRatio) outfile.close()
def get_rem_schedulable_hours(project, typ): ta = TimeAccounting() return sum([ta.getTimeLeft(s) for s in get_sessions(project, typ) \ if s.schedulable() and project.has_sanctioned_observers()])
def get_rem_hours(project, typ): ta = TimeAccounting() return sum([ta.getTimeLeft(s) for s in get_sessions(project, typ)])
def GenerateReport(start): outfile = open("./DssSessionReport.txt", 'w') scs = [1, 13, 5, 3, 6, 4, 10, 11, 6, 6, 6, 6, 5, 15] scss = " %s" * len(scs) hdrFormat = "\n\n\t " + scss dataFormat = "\n\t " + scss semesters = sorted(Semester.objects.all() , lambda x,y:cmp(x.semester,y.semester)) ta = TimeAccounting() for s in semesters: projects = sorted([p for p in s.project_set.all() if not p.complete] , lambda x,y:cmp(x.pcode, y.pcode)) if projects: outfile.write("\n\n") outfile.write("=" * 100) outfile.write("\n\nTrimester: %s\n" %s.semester) outfile.write("-" * 14) for p in projects: outfile.write("\n\n\t%s, %s, PI: %s, Rem/Tot: %.1f/%.1f" % \ (p.pcode , p.name[:50] , p.principal_investigator().last_name if p.principal_investigator() else "None" , ta.getTimeLeft(p) , ta.getProjectTotalTime(p))) outfile.write(hdrFormat % \ (ljust("", scs[0]) , ljust("name", scs[1]) , center("orgID", scs[2]) , center("sch", scs[3]) , center("obs", scs[4]) , ljust("type", scs[5]) , center("RA", scs[6]) , center("Dec", scs[7]) , center("rem", scs[8]) , center("tot", scs[9]) , rjust("min", scs[10]) , rjust("max", scs[11]) , rjust("btwn", scs[12]) , ljust("rcvrs", scs[13]))) sessions = sorted(p.sesshun_set.all() , lambda x,y:cmp(x.name, y.name)) for s in sessions: target = s.getTarget() outfile.write(dataFormat % \ (ljust(bl(s.status.complete), scs[0]) , ljust(s.name, scs[1]) , rjust(s.original_id, scs[2]) , center(scheduable(s), scs[3]) , center(s.observing_type.type[:6], scs[4]) , center(s.session_type.type[0], scs[5]) , ljust(target.get_horizontal(), scs[6]) , ljust(target.get_vertical(), scs[7]) , rjust(ta.getTimeLeft(s), scs[8]) , rjust(s.allotment.total_time, scs[9]) , rjust(s.min_duration, scs[10]) , rjust(s.max_duration, scs[11]) , rjust(s.time_between, scs[12]) , ljust("".join(s.rcvrs_specified()), scs[13]) )) if p != projects[-1]: outfile.write("\n\t" + ("-" * 96))