def get_student_first_year_course_grades(dbname): ''' Returns a list of lists. Each sublist represents the grades of one student. The list has grades for all first year courses. ''' # TODO make None default con = database_interface.get_database_connection(dbname, None) courses = map(lambda inf: (inf[0], inf[1] + inf[2]), get_first_year_courses(con)) normalizer = CourseNormalizer(courses) columns = normalizer.get_norm_course_list() columns.append((-1, "Label")) results_table = ResultsTable(columns) students = get_student_grades(con, normalizer) cur = con.cursor() cur.execute(GET_STUDENT_LABELS) for r in cur: sid, label = r students[sid][-1] = label for sid in students.keys(): results_table.add_row(sid, students[sid]) con.close() return results_table
def get_results_for_class(self, dclass=None): # Create table with results result = ResultsTable(self.get_total_rounds(), self.get_grop_rounds(), self.get_rounds_list()) # Determine the directory dirname = self.get_directory() # Determine the file fname = dirname + "/CLASS" if dclass: fname += "-" + dclass fname += ".json" # Read it if os.path.isfile(fname): result.set_table(json.load(open(fname))) return result
def results(): global root, auth ResultsTable(root, auth)
def calc_and_store_points(self): # Read all rounds, calculate points for each, store standings drivers = {} for round_obj in self.get_rounds_list(): if round_obj.exists(): print "Processing round #%s: %s" % (round_obj.get_num(), round_obj.get_directory()) round_obj.read() round_obj.calc_points(drivers, self) round_obj.store_points() # Calculate and store results for each class standings = None standings_prev = None for dclass in self.get_driver_classes(): # Filter out drivers which belong to this class drivers_in_class = [d for d in drivers if dclass in d.get_classes()] # Build table with results (ignore the last round). This is needed to calculate how drivers moved up/down table_prev = ResultsTable(self.get_total_rounds(), self.get_grop_rounds(), self.get_rounds_list()) table_prev.use_drivers(drivers_in_class) table_prev.set_ignore_last_round() table_prev.process() # Build table with results (all rounds) table = ResultsTable(self.get_total_rounds(), self.get_grop_rounds(), self.get_rounds_list()) table.use_drivers(drivers_in_class) table.set_driver_prev_position_map(table_prev.get_driver_position_map()) table.process() # Store final standings if not dclass: standings = table standings_prev = table_prev # Determine the directory dirname = self.get_directory() if not os.path.exists(dirname): os.makedirs(dirname) # Determine the file fname = dirname + "/CLASS" if dclass: fname += "-" + dclass fname += ".json" # Store the table to file print " [x] Saving results to '%s'" % fname with open(fname, "wb") as json_file: json.dump(table.get_table(), json_file) # Calculate and store results for teams table_team_prev = ResultsTableTeam(standings_prev, self.get_driver_teams()) table_team_prev.process() table_team = ResultsTableTeam(standings, self.get_driver_teams()) table_team.set_team_prev_position_map(table_team_prev.get_team_position_map()) table_team.process() # Determine the directory fname = self.get_directory() + "/CLASS-TEAMS.json" # Store the table print " [x] Saving results to '%s'" % fname with open(fname, "wb") as json_file: json.dump(table_team.get_table(), json_file) print "Points calculated, total number of drivers: %d" % len(drivers)