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)
def create_picklist_json(global_config, comp=None, store_json_file=False): global_config['logger'].debug( 'Create Picklist Json' ) global local_picklist store_data_to_file = False if comp == None: comp = global_config['this_competition'] + global_config['this_season'] season = global_config['this_season'] else: season = WebCommonUtils.map_comp_to_season(comp) session = DbSession.open_db_session(global_config['db_name'] + season) result = [] result.append('{ "picklist": [\n') local_picklist = DataModel.getTeamsInRankOrder(session, comp, True) rank = 1 for team in local_picklist: # round the score to an integer value team.score = float(int(team.score)) if team.score > 0: row = '{ "rank" : %d, "team" : %d, "score" : %d, "competition" : "%s" }' % (rank, team.team, int(team.score), team.competition) result.append(row) result.append(',\n') rank += 1 if len(result) > 0: result = result[:-1] result.append(']}') json_str = ''.join(result) if store_json_file is True: try: FileSync.put( global_config, '%s/EventData/%s.json' % (comp,'picklist'), 'text', json_str) except: raise session.remove() return json_str
def get_team_rankings_array(global_config): global_config['logger'].debug( 'GET Team Rankings Array' ) session = DbSession.open_db_session(global_config['db_name'] + global_config['this_season']) web.header('Content-Type', 'application/json') result = [] result.append('[') comp = global_config['this_competition'] + global_config['this_season'] team_rankings = DataModel.getTeamsInRankOrder(session, comp) for team in team_rankings: data_str = '[%d,%d]' % (team.team,int(team.score)) result.append(data_str) result.append(',') if len(team_rankings) > 0: result = result[:-1] result.append(']') return ''.join(result)
def get_team_rankings_page(global_config, comp=None): global_config['logger'].debug( 'GET Team Rankings' ) session = DbSession.open_db_session(global_config['db_name'] + global_config['this_season']) web.header('Content-Type', 'application/json') result = [] result.append('{ "rankings": [\n') if comp == None: comp = global_config['this_competition'] + global_config['this_season'] team_rankings = DataModel.getTeamsInRankOrder(session, comp, False) for team in team_rankings: # round the score to an integer value team.score = float(int(team.score)) result.append(team.json()) result.append(',\n') if len(team_rankings) > 0: result = result[:-1] result.append(']}') return ''.join(result)
# Write out the column headers mystring = 'Team,Score' try: for attr_def in attr_order: if attr_def['Database_Store'] == 'Yes': mystring += ',' + attr_def['Name'] except Exception, e: print 'Exception: %s' % str(e) mystring += '\n' fo.write( mystring ) # 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)
def get_team_rankings_json(global_config, season, event, attr_filters=[], filter_name=None, thumbnails = False, store_json_file=False): global_config['logger'].debug( 'GET Team Rankings Json' ) store_data_to_file = False comp = WebCommonUtils.map_event_code_to_comp(event, season) session = DbSession.open_db_session(global_config['db_name'] + season) result = [] result.append('{ "rankings": [\n') rank_added = False if len(attr_filters) == 0: team_rankings = DataModel.getTeamsInRankOrder(session, comp, False) for team in team_rankings: # round the score to an integer value team.score = float(int(team.score)) if team.score > 0: thumbnails_snippet = '' if thumbnails: thumbnails_snippet = ',\n' + get_team_scouting_thumbnails_json_snippet(global_config, comp, str(team.team)) result.append( ' { "score": %0.1f, "competition": "%s", "team": %d%s }' % (team.score, comp, team.team,thumbnails_snippet)) result.append(',\n') rank_added = True else: # we'll need the attribute definitions in order to retrieve the correct attribute value # and attribute weighting attrdef_filename = WebCommonUtils.get_attrdef_filename(comp=comp) attr_definitions = AttributeDefinitions.AttrDefinitions(global_config) attr_definitions.parse(attrdef_filename) team_rank_dict = dict() for attr_filter in attr_filters: try: attr_name, attr_value = attr_filter.split('=') except: attr_name = attr_filter attr_value = None attr_def = attr_definitions.get_definition(attr_name) if attr_value is None: team_rankings = DataModel.getTeamAttributesInRankOrder(session, comp, attr_name, False) for team in team_rankings: try: stat_type = attr_def['Statistic_Type'] except: stat_type = 'Total' weight = int(float(attr_def['Weight'])) if stat_type == 'Average': score = int(team.cumulative_value/team.num_occurs*weight) else: score = int(team.cumulative_value*weight) try: team_rank_dict[team.team] += score except: team_rank_dict[team.team] = score else: team_rankings = DataModel.getTeamAttributesWithValue(session, comp, attr_name, attr_value, False) for team in team_rankings: score = team.all_values.count(attr_value) try: team_rank_dict[team.team] += score except: team_rank_dict[team.team] = score sorted_team_rank = sorted(team_rank_dict.items(), key=operator.itemgetter(1)) for team, score in sorted_team_rank: # round the score to an integer value score = float(int(score)) if score > 0: thumbnails_snippet = '' if thumbnails: thumbnails_snippet = ',\n' + get_team_scouting_thumbnails_json_snippet(global_config, comp, str(team)) result.append( ' { "score": %0.1f, "competition": "%s", "team": %d%s }' % (score, comp, team, thumbnails_snippet)) result.append(',\n') rank_added = True if rank_added == True: result = result[:-1] result.append(']}') json_str = ''.join(result) if store_json_file is True: try: if filter_name is None: file_name = 'scoutingrankings' else: file_name = 'scoutingrankings_%s' % filter_name FileSync.put( global_config, '%s/EventData/%s.json' % (comp,file_name), 'text', json_str) except: raise session.remove() return json_str