def get_team_attributes_page(global_config): global_config['logger'].debug( 'GET Team Attributes' ) session = DbSession.open_db_session(global_config['db_name'] + global_config['this_season']) comp = global_config['this_competition'] + global_config['this_season'] attrdef_filename = WebCommonUtils.get_attrdef_filename(comp=comp) attr_definitions = AttributeDefinitions.AttrDefinitions(global_config) attr_definitions.parse(attrdef_filename) web.header('Content-Type', 'application/json') result = [] result.append('{ "attributes": [\n') team_rankings = DataModel.getTeamsInRankOrder(session, comp) for team_entry in team_rankings: result.append("{ 'Team': " + str(team_entry.team)) result.append(", 'Score': " + '%.2f' % team_entry.score ) team_attributes = DataModel.getTeamAttributesInOrder(session, team_entry.team, comp) for attribute in team_attributes: attr_def = attr_definitions.get_definition( attribute.attr_name ) if attr_def: weight = int(float(attr_def['Weight'])) if weight != 0: result.append( ", '" + attribute.attr_name + "': ") if ( attr_def['Statistic_Type'] == 'Total'): #result.append( str(attribute.cumulative_value) ) result.append( DataModel.mapValueToString(attribute.cumulative_value, attribute.all_values, attr_def, True) ) elif ( attr_def['Statistic_Type'] == 'Average'): #result.append( str(attribute.avg_value) ) result.append( DataModel.mapValueToString(attribute.avg_value, attribute.all_values, attr_def, True) ) else: #result.append( str(attribute.attr_value) ) result.append( DataModel.mapValueToString(attribute.attr_value, attribute.all_values, attr_def, True) ) result.append(' }') result.append(',\n') if len(team_rankings) > 0: result = result[:-1] result.append('\n') result.append(']}') session.remove() return ''.join(result)
# Get the list of teams in rank order, then loop through teams and dump their stored # attribute values team_rankings = DataModel.getTeamsInRankOrder(session, competition) for team_entry in team_rankings: mystring = str(team_entry.team) + ',' + str(team_entry.score) # retrieve each attribute from the database in the proper order for attr_def in attr_order: if attr_def['Database_Store'] == 'Yes': attribute = DataModel.getTeamAttribute(session, team_entry.team, competition, attr_def['Name']) # if the attribute doesn't exist, just put in an empty field so that the columns # stay aligned if attribute == None: mystring += ',' elif ( attr_def['Statistic_Type'] == 'Total'): #mystring += ',' + str(attribute.cumulative_value) mystring += ',' + DataModel.mapValueToString(attribute.cumulative_value, attribute.all_values, attr_def) elif ( attr_def['Statistic_Type'] == 'Average'): #mystring += ',' + str(attribute.avg_value) mystring += ',' + DataModel.mapValueToString(attribute.avg_value, attribute.all_values, attr_def) else: #mystring += ',' + str(attribute.attr_value) mystring += ',' + DataModel.mapValueToString(attribute.attr_value, attribute.all_values, attr_def) mystring += '\n' fo.write( mystring ) fo.close() def process_files(session, db_name, attr_definitions, input_dir, recursive, test): # The following regular expression will select all files that conform to # the file naming format Team*.txt. Build a list of all datafiles that match