本文整理汇总了Python中WebCommonUtils类的典型用法代码示例。如果您正苦于以下问题:Python WebCommonUtils类的具体用法?Python WebCommonUtils怎么用?Python WebCommonUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WebCommonUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_team_score_breakdown_json
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
示例2: recalculate_scoring
def recalculate_scoring(global_config, competition=None, attr_definitions=None):
if competition is None:
competition = global_config['this_competition'] + global_config['this_season']
if competition == None or competition == '':
raise Exception( 'Competition Not Specified!')
# Build the attribute definition dictionary from the definitions csv file
if global_config['attr_definitions'] == None:
return
if attr_definitions is None:
attrdef_filename = WebCommonUtils.get_attrdef_filename(competition)
if attrdef_filename is not None:
attr_definitions = AttributeDefinitions.AttrDefinitions(global_config)
attr_definitions.parse(attrdef_filename)
else:
return
session = DbSession.open_db_session(global_config['db_name'] + global_config['this_season'])
team_rankings = getTeamsInRankOrder(session, competition)
for team_entry in team_rankings:
score = calculateTeamScore(session, team_entry.team, competition, attr_definitions)
setTeamScore(session, team_entry.team, competition, score)
session.commit()
dump_database_as_csv_file(session, global_config, attr_definitions, competition)
session.remove()
示例3: process_form
def process_form(global_config, form):
global_config['logger'].debug( 'Process Attribute Modify Form' )
season = form[attr_modify_season_label].value
comp = form[attr_modify_comp_label].value
team = form[attr_modify_team_number_label].value
attr_name = form[attr_modify_attribute_name_label].value
old_value = form[attr_modify_old_value_label].value
new_value = form[attr_modify_new_value_label].value
# Initialize the database session connection
db_name = global_config['db_name'] + global_config['this_season']
session = DbSession.open_db_session(db_name)
attrdef_filename = WebCommonUtils.get_attrdef_filename(short_comp=comp)
if attrdef_filename is not None:
attr_definitions = AttributeDefinitions.AttrDefinitions(global_config)
attr_definitions.parse(attrdef_filename)
attr_def = attr_definitions.get_definition(attr_name)
try:
DataModel.modifyAttributeValue(session, team, comp+season, attr_name, old_value, new_value, attr_def)
result = 'Attribute %s Modified From %s to %s For Team %s' % (attr_name,old_value,new_value,team)
session.commit()
except ValueError as reason:
result = 'Error Modifying Scouting Addribute %s For Team %s: %s' % (attr_name,team,reason)
session.remove()
return result
示例4: get_team_scouting_notes_json
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
示例5: get_data_from_first
def get_data_from_first(global_config, year, event_code, query_str, round_str = '', table_to_parse=2):
result = []
store_data_to_file = False
# derive our competition name from the FIRST event code
competition = WebCommonUtils.map_event_code_to_comp(year+event_code)
result.append('{ "event" : "%s",\n' % (event_code.lower()))
try:
opener = urllib2.build_opener()
opener.addheaders = [('Authorization', 'Basic a3N0aGlsYWlyZTozMDMyRTUxRS1CNkFBLTQ2QzgtOEY5Qy05QzdGM0EzM0Q4RjI='),('Accept','application/json')]
#first_url_str = 'http://frc-events.usfirst.org/%s/%s/%s' % (year,event_code.upper(),query_str)
first_url_str = 'https://frc-api.usfirst.org/api/v1.0/rankings/%s/%s' % (year,event_code.upper())
print 'GET - %s' % first_url_str
rank_data = opener.open(first_url_str)
my_parser = RankParser()
rankings, _ = my_parser.parse( rank_data, table_to_parse )
# rankings is now a list of lists, with the first element of the list being the list of column headings
# take the list of columngs and apply to each of the subsequent rows to build the json response
result.append(' "last_updated": "%s",\n' % time.strftime('%c'))
headings = rankings[0]
result.append(' "columns" : [\n')
for heading in headings:
result.append(' { "sTitle": "%s" }' % heading)
result.append(',\n')
if len(headings)>0:
result = result[:-1]
result.append(' ],\n')
result.append(' "%s" : [\n' % (query_str))
for line in rankings[1:]:
result.append(' [ ')
for i in range(0,len(headings)):
if need_team_hyperlink(headings[i]):
#result.append('"%s"' % (line[i]))
result.append(('"<a href=\\"/teamdata/%s/'% competition)+line[i]+'\\">'+line[i]+'</a>"')
else:
#result.append('"%s": "%s"' % (headings[i].title(),line[i]))
result.append('"%s"' % (line[i]))
result.append(', ')
if len(line) > 0:
result = result[:-1]
result.append(' ],\n')
if len(rankings) > 1:
result = result[:-1]
result.append(' ]\n')
store_data_to_file = True
except Exception, err:
print 'Caught exception:', err
示例6: process_delete_file_form
def process_delete_file_form(global_config, form):
global_config['logger'].debug( 'Process Attribute Delete Form' )
data_filename = form[attr_delete_file_label].value
if form[attr_remove_file_processed_label].value == 'Yes':
remove_from_processed_files = True
else:
remove_from_processed_files = False
# Initialize the database session connection
db_name = global_config['db_name'] + global_config['this_season']
session = DbSession.open_db_session(db_name)
attrdef_filename = WebCommonUtils.get_attrdef_filename(short_comp=global_config['this_competition'])
if attrdef_filename is not None:
attr_definitions = AttributeDefinitions.AttrDefinitions(global_config)
attr_definitions.parse(attrdef_filename)
try:
ProcessFiles.remove_file_data(global_config, session, attr_definitions, \
data_filename, remove_from_processed_files)
result = 'Scouting Data File %s Attributes Successfully Removed' % (data_filename)
session.commit()
except ValueError as reason:
result = 'Error Removing Scouting Data File %s: %s' % (data_filename, reason)
session.remove()
return result
示例7: init_issue_tracker
def init_issue_tracker():
global issueform
global new_issueform
global commentform
issue_platforms = WebCommonUtils.get_issue_types()
issueform = pureform(
form.Textbox(issue_id_label, size=20),
form.Dropdown(issue_platform_label, issue_platforms),
form.Textbox(issue_summary_label, size=60),
form.Dropdown(issue_status_label, issue_statuses),
form.Dropdown(issue_priority_label, issue_priorities),
form.Dropdown(issue_subgroup_label, issue_subgroups),
form.Dropdown(issue_component_label, issue_components),
form.Dropdown(issue_owner_label, issue_username_list),
form.Dropdown(issue_submitter_label, issue_username_list),
form.Textarea(issue_description_label, size=1024),
form.Textarea(issue_comment_label, size=1024))
new_issueform = pureform(
form.Dropdown(issue_platform_label, issue_platforms),
form.Textbox(issue_summary_label, size=60),
form.Dropdown(issue_status_label, issue_statuses),
form.Dropdown(issue_priority_label, issue_priorities),
form.Dropdown(issue_subgroup_label, issue_subgroups),
form.Dropdown(issue_component_label, issue_components),
form.Dropdown(issue_owner_label, issue_username_list),
form.Dropdown(issue_submitter_label, issue_username_list),
form.Textarea(issue_description_label, size=1024))
commentform = pureform(
form.Textarea(issue_comment_label, size=1024))
示例8: get_team_score_json
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
示例9: process_delete_attr_form
def process_delete_attr_form(global_config, form):
global_config['logger'].debug( 'Process Attribute Delete Form' )
season = form[attr_delete_season_label].value
comp = form[attr_delete_comp_label].value
team = form[attr_delete_team_number_label].value
attr_name = form[attr_delete_attribute_name_label].value
old_value = form[attr_delete_old_value_label].value
# Initialize the database session connection
db_name = global_config['db_name'] + global_config['this_season']
session = DbSession.open_db_session(db_name)
attrdef_filename = WebCommonUtils.get_attrdef_filename(short_comp=comp)
if attrdef_filename is not None:
attr_definitions = AttributeDefinitions.AttrDefinitions(global_config)
attr_definitions.parse(attrdef_filename)
attr_def = attr_definitions.get_definition(attr_name)
try:
DataModel.deleteAttributeValue(session, team, comp+season, attr_name, old_value, attr_def)
result = 'Scouting Data Attribute Value %s Successfully Removed From %s' % (old_value,attr_name)
session.commit()
except ValueError as reason:
result = 'Error Removing Scouting Data Attribute Value %s From %s: %s' % (old_value,attr_name,reason)
session.remove()
return result
示例10: get_data_from_first
def get_data_from_first(global_config, year, event_code, query_str, table_to_parse=2):
web.header('Content-Type', 'application/json')
result = []
result.append('{ "event" : "%s",\n' % (event_code.lower()))
try:
first_url_str = 'http://www2.usfirst.org/%scomp/events/%s/%s.html' % (year,event_code.upper(),query_str)
rank_data = urllib2.urlopen(first_url_str).read()
my_parser = RankParser()
rankings, _ = my_parser.parse( rank_data, table_to_parse )
# derive our competition name from the FIRST event code
competition = WebCommonUtils.map_event_code_to_comp(year+event_code)
# rankings is now a list of lists, with the first element of the list being the list of column headings
# take the list of columngs and apply to each of the subsequent rows to build the json response
headings = rankings[0]
result.append(' "columns" : [\n')
for heading in headings:
result.append(' { "sTitle": "%s" }' % heading)
result.append(',\n')
if len(headings)>0:
result = result[:-1]
result.append(' ],\n')
result.append(' "%s" : [\n' % (query_str))
for line in rankings[1:]:
result.append(' [ ')
for i in range(0,len(headings)):
if need_team_hyperlink(headings[i]):
#result.append('"%s"' % (line[i]))
result.append(('"<a href=\\"/teamdata/%s/'% competition)+line[i]+'\\">'+line[i]+'</a>"')
else:
#result.append('"%s": "%s"' % (headings[i].title(),line[i]))
result.append('"%s"' % (line[i]))
result.append(', ')
if len(line) > 0:
result = result[:-1]
result.append(' ],\n')
if len(rankings) > 1:
result = result[:-1]
result.append(' ]\n')
except:
pass
result.append(' ] }\n')
return ''.join(result)
示例11: get_team_list_json_from_tba
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)
示例12: get_event_rank_list_json
def get_event_rank_list_json(global_config, year, event_code):
global_config['logger'].debug( 'GET Event Rank List Json' )
# derive our competition name from the FIRST event code
competition = WebCommonUtils.map_event_code_to_comp(year+event_code)
#return get_data_from_first(global_config, year, event_code, 'rankings')
store_data_to_file = False
result = []
rankings_data = get_event_data_from_tba( '%s%s/rankings' % (year,event_code.lower()) )
result.append('{ "event" : "%s",\n' % (event_code.lower()))
rankings = rankings_data.get('rankings', [])
if len(rankings):
# rankings is now a list of lists, with the first element of the list being the list of column headings
# take the list of columngs and apply to each of the subsequent rows to build the json response
result.append(' "last_updated": "%s",\n' % time.strftime('%c'))
result.append(' "rankings" : [\n')
for team_rank in rankings:
result.append(' { "rank": %d, "team_number": %s, "status": "available" }' % (team_rank['rank'],team_rank['team_key'].replace('frc','')))
result.append(',\n')
if len(rankings) > 1:
result = result[:-1]
result.append(' ]\n')
store_data_to_file = True
else:
# we were not able to retrieve the data from FIRST, so let's return any stored file with the
# information, otherwise we will return an empty json payload
stored_file_data = FileSync.get( global_config, '%s/EventData/ranklist.json' % (competition) )
if stored_file_data != '':
return stored_file_data
else:
# no stored data either, so let's just return a formatted, but empty payload
result.append(' "last_updated": "%s",\n' % time.strftime('%c'))
result.append(' "rankings" : []\n')
result.append(' }\n')
json_str = ''.join(result)
if store_data_to_file:
try:
FileSync.put( global_config, '%s/EventData/ranklist.json' % (competition), 'text', json_str)
except:
raise
return json_str
示例13: get_team_list_json
def get_team_list_json(global_config, season, event, store_json_file=False):
global team_info_dict
global_config['logger'].debug( 'GET Team List For Competition %s', event )
comp = WebCommonUtils.map_event_code_to_comp(event, season)
session = DbSession.open_db_session(global_config['db_name'] + season)
result = []
result.append('{ "teams" : [\n')
'''
team_list = DataModel.getTeamsInNumericOrder(session, comp)
for team in team_list:
team_info = None
# TODO - Remove this hardcoded number for the valid team number. This check prevents
# requesting information for invalid team numbers, which has been known to happen when
# tablet operators enter bogus team numbers by mistake
if team.team < 10000:
team_info = DataModel.getTeamInfo(session, int(team.team))
if team_info:
result.append(' { "team_number": "%s", "nickname": "%s" }' % (team.team,team_info.nickname))
result.append(',\n')
else:
result.append(' { "team_number": "%s", "nickname": "%s" }' % (team.team,'Unknown'))
result.append(',\n')
if len(team_list) > 0:
result = result[:-1]
result.append(' ] }\n')
json_str = ''.join(result)
else:
'''
json_str = get_team_list_json_from_tba(global_config, comp)
if store_json_file is True:
try:
FileSync.put( global_config, '%s/EventData/%s.json' % (comp,'teams'), 'text', json_str)
except:
raise
session.remove()
return json_str
示例14: get_team_event_list_from_tba
def get_team_event_list_from_tba(global_config, team, season):
global_config['logger'].debug( 'GET Team Event List TBA' )
result = []
url_str = '/api/v2/team/frc%s/%s/events' % (team,season)
try:
event_dict = TbaIntf.get_from_tba_parsed(url_str)
for event in event_dict:
comp = WebCommonUtils.map_event_code_to_comp(event['event_code'], season)
result.append(comp)
except:
pass
return result
示例15: process_attr_def_form
def process_attr_def_form(global_config, form):
global_config['logger'].debug( 'Process Attribute Definitions Form' )
attrdef_filename = WebCommonUtils.get_attrdef_filename(global_config['this_competition'])
if attrdef_filename is not None:
attr_definitions = AttributeDefinitions.AttrDefinitions(global_config)
attr_definitions.parse(attrdef_filename)
attr_dict = attr_definitions.get_definitions()
for key, attr_def in sorted(attr_dict.items()):
attr_def['Weight'] = form[key].value
attr_definitions.write_attr_overrides();
competition = global_config['this_competition'] + global_config['this_season']
if competition == None:
raise Exception( 'Competition Not Specified!')
DataModel.recalculate_scoring(global_config, competition, attr_definitions)