本文整理汇总了Python中DataModel.mapAllValuesToDict方法的典型用法代码示例。如果您正苦于以下问题:Python DataModel.mapAllValuesToDict方法的具体用法?Python DataModel.mapAllValuesToDict怎么用?Python DataModel.mapAllValuesToDict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataModel
的用法示例。
在下文中一共展示了DataModel.mapAllValuesToDict方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_team_attr_rankings_json
# 需要导入模块: import DataModel [as 别名]
# 或者: from DataModel import mapAllValuesToDict [as 别名]
def get_team_attr_rankings_json(global_config, comp=None, attr_name=None):
global_config['logger'].debug( 'GET Team Attribute Rankings Json' )
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)
attrdef_filename = WebCommonUtils.get_attrdef_filename(comp=comp)
attr_definitions = AttributeDefinitions.AttrDefinitions()
attr_definitions.parse(attrdef_filename)
attr_def = attr_definitions.get_definition(attr_name)
try:
stat_type = attr_def['Statistic_Type']
except:
stat_type = 'Total'
web.header('Content-Type', 'application/json')
result = []
result.append('{ "attr_name" : "%s",\n' % attr_name)
# add the columns bases on the attribute definition type
result.append(' "columns" : [\n')
result.append(' { "sTitle": "Team" }')
result.append(',\n')
columns = []
if attr_def['Type'] == 'Map_Integer':
map_values = attr_def['Map_Values'].split(':')
for map_value in map_values:
item_name = map_value.split('=')[0]
columns.append(item_name)
result.append(' { "sTitle": "%s" }' % item_name)
result.append(',\n')
result = result[:-1]
result.append('\n')
result.append(' ],\n')
if stat_type == 'Average':
team_rankings = DataModel.getTeamAttributesInAverageRankOrder(session, comp, attr_name)
else:
team_rankings = DataModel.getTeamAttributesInRankOrder(session, comp, attr_name)
result.append(' "rankings" : [\n')
for team_attr in team_rankings:
data_str = ' [ %d,' % team_attr.team
value_dict = DataModel.mapAllValuesToDict(attr_def, team_attr.all_values)
for column in columns:
try:
value = value_dict[column]
except:
value = 0
data_str += ' %d,' % value
data_str = data_str.rstrip(',')
data_str += ' ]'
result.append(data_str)
result.append(',\n')
if len(team_rankings) > 0:
result = result[:-1]
result.append('\n')
result.append(' ]\n}')
json_str = ''.join(result)
if store_data_to_file is True:
try:
file_name = 'attrrankings_%s' % attr_name
FileSync.put( global_config, '%s/EventData/%s.json' % (comp,file_name), 'text', json_str)
except:
raise
session.remove()
return json_str