本文整理汇总了Python中WebCommonUtils.map_comp_to_season方法的典型用法代码示例。如果您正苦于以下问题:Python WebCommonUtils.map_comp_to_season方法的具体用法?Python WebCommonUtils.map_comp_to_season怎么用?Python WebCommonUtils.map_comp_to_season使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebCommonUtils
的用法示例。
在下文中一共展示了WebCommonUtils.map_comp_to_season方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_team_scouting_notes_json
# 需要导入模块: import WebCommonUtils [as 别名]
# 或者: from WebCommonUtils import map_comp_to_season [as 别名]
def get_team_scouting_notes_json(global_config, comp, name, store_json_file=False):
global_config['logger'].debug( 'GET Team %s Scouting Notes For Competition %s', name, comp )
season = WebCommonUtils.map_comp_to_season(comp)
session = DbSession.open_db_session(global_config['db_name'] + season)
result = []
result.append('{ "competition" : "%s", "team" : "%s",\n' % (comp,name))
result.append(' "scouting_notes" : [\n')
team_notes = DataModel.getTeamNotes(session, name, comp)
for note in team_notes:
result.append(' { "tag": "%s", "note": "%s" }' % (note.tag,note.data))
result.append(',\n')
if len(team_notes) > 0:
result = result[:-1]
result.append(' ] }\n')
json_str = ''.join(result)
if store_json_file is True:
try:
FileSync.put( global_config, '%s/EventData/TeamData/team%s_scouting_notes.json' % (comp,name), 'text', json_str)
except:
raise
session.remove()
return json_str
示例2: get_team_score_json
# 需要导入模块: import WebCommonUtils [as 别名]
# 或者: from WebCommonUtils import map_comp_to_season [as 别名]
def get_team_score_json(global_config, name, comp, store_json_file=False):
global_config['logger'].debug( 'GET Team %s Score For Competition %s', name, comp )
season = WebCommonUtils.map_comp_to_season(comp)
session = DbSession.open_db_session(global_config['db_name'] + season)
result = []
result.append('{ "competition" : "%s", "team" : "%s", ' % (comp,name))
team_scores = DataModel.getTeamScore(session, name, comp)
if len(team_scores)==1:
result.append('"score": "%s" }' % team_scores[0].score)
else:
result.append(' "score": [')
for score in team_scores:
result.append(score.json())
result.append(',\n')
if len(team_scores) > 0:
result = result[:-1]
result.append(']}')
json_str = ''.join(result)
if store_json_file is True:
try:
FileSync.put( global_config, '%s/EventData/TeamData/team%s_scouting_score.json' % (comp,name), 'text', json_str)
except:
raise
session.remove()
return json_str
示例3: get_team_score_breakdown_json
# 需要导入模块: import WebCommonUtils [as 别名]
# 或者: from WebCommonUtils import map_comp_to_season [as 别名]
def get_team_score_breakdown_json(global_config, name, comp=None, store_json_file=False):
global_config['logger'].debug( 'GET Team Score Breakdown: %s', name )
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(global_config)
attr_definitions.parse(attrdef_filename)
result = []
result.append('{ "score_breakdown": [\n')
team_attributes = DataModel.getTeamAttributesInOrder(session, name, comp)
for attribute in team_attributes:
attr_def = attr_definitions.get_definition( attribute.attr_name )
if attr_def:
try:
stat_type = attr_def['Statistic_Type']
except:
stat_type = 'Total'
weight = int(float(attr_def['Weight']))
if weight != 0:
if stat_type == 'Average':
value = int(attribute.cumulative_value/attribute.num_occurs)
else:
value = int(attribute.cumulative_value)
data_str = '{"attr_name": "%s", "raw_score": %d, "weighted_score": %d}' % (attribute.attr_name,int(value),int(weight*value))
result.append(data_str)
result.append(',\n')
if len(team_attributes) > 0:
result = result[:-1]
result.append('\n')
result.append(']}')
json_str = ''.join(result)
if store_json_file is True:
try:
FileSync.put( global_config, '%s/EventData/TeamData/team%s_scouting_scorebreakdown.json' % (comp,name), 'text', json_str)
except:
raise
session.remove()
return json_str
示例4: create_picklist_json
# 需要导入模块: import WebCommonUtils [as 别名]
# 或者: from WebCommonUtils import map_comp_to_season [as 别名]
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
示例5: get_team_list_json_from_tba
# 需要导入模块: import WebCommonUtils [as 别名]
# 或者: from WebCommonUtils import map_comp_to_season [as 别名]
def get_team_list_json_from_tba(global_config, comp):
global_config['logger'].debug( 'GET Team List For Competition From TBA %s', comp )
web.header('Content-Type', 'application/json')
result = []
result.append('{ "teams" : ')
event_code = WebCommonUtils.map_comp_to_event_code(comp)
season = WebCommonUtils.map_comp_to_season(comp)
url_str = 'http://www.thebluealliance.com/api/v2/event/%s%s/teams?X-TBA-App-Id=frc1073:scouting-system:v01' % (season,event_code)
event_data = ''
try:
event_data = urllib2.urlopen(url_str).read()
except:
event_data = '[ ]'
pass
result.append( event_data )
result.append(' }\n')
return ''.join(result)
示例6: get_team_attr_rankings_json
# 需要导入模块: import WebCommonUtils [as 别名]
# 或者: from WebCommonUtils import map_comp_to_season [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
示例7: get_team_scouting_data_summary_json
# 需要导入模块: import WebCommonUtils [as 别名]
# 或者: from WebCommonUtils import map_comp_to_season [as 别名]
def get_team_scouting_data_summary_json(global_config, comp, name, attr_filter=[], filter_name=None, store_json_file=False):
global_config['logger'].debug( 'GET Team %s Scouting Data For Competition %s', name, comp )
season = WebCommonUtils.map_comp_to_season(comp)
session = DbSession.open_db_session(global_config['db_name'] + season)
if global_config['attr_definitions'] == None:
return None
attrdef_filename = WebCommonUtils.get_attrdef_filename(comp=comp)
attr_definitions = AttributeDefinitions.AttrDefinitions(global_config)
attr_definitions.parse(attrdef_filename)
result = []
result.append('{ "competition" : "%s", "team" : "%s",\n' % (comp,name))
result.append(' "scouting_data_summary" : [\n')
team_attributes = DataModel.getTeamAttributesInOrder(session, name, comp)
if len(team_attributes) > 0:
some_attr_added = False
for attribute in team_attributes:
attr_def = attr_definitions.get_definition( attribute.attr_name )
include_attr = False
if attr_def:
if attr_def.has_key('Include_In_Team_Display') \
and attr_def['Include_In_Team_Display'] == 'Yes':
include_attr = True
elif attr_def.has_key('Include_In_Report') \
and attr_def['Include_In_Report'] == 'Yes':
include_attr = True
elif attr_def.has_key('Weight') \
and attr_def['Weight'] != '0':
include_attr = True
# if an attribute filter has been provided, only include the attribute data if the
# attribute is in the filter
if len(attr_filter) > 0:
if attr_def['Name'] not in attr_filter:
include_attr = False
if include_attr == True:
some_attr_added = True
if attr_def.has_key('Display_Name'):
attr_name = attr_def['Display_Name']
else:
attr_name = attr_def['Name']
category = attr_def.get('Sub_Category', '')
result.append(' { "name": "%s", "matches": "%s", "cumulative_value": "%s", "average_value": "%s", "all_values": "%s", "category": "%s" }' % \
(attr_name,str(attribute.num_occurs),str(attribute.cumulative_value),str(round(attribute.avg_value,1)),\
DataModel.mapAllValuesToShortenedString(attr_def, attribute.all_values), category) )
result.append(',\n')
if some_attr_added:
result = result[:-1]
result.append(' ] }\n')
json_str = ''.join(result)
if store_json_file is True:
try:
FileSync.put( global_config, '%s/EventData/TeamData/team%s_scouting_data_summary.json' % (comp,name), 'text', json_str)
except:
raise
session.remove()
return json_str