本文整理汇总了Python中DbSession.open_db_session方法的典型用法代码示例。如果您正苦于以下问题:Python DbSession.open_db_session方法的具体用法?Python DbSession.open_db_session怎么用?Python DbSession.open_db_session使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DbSession
的用法示例。
在下文中一共展示了DbSession.open_db_session方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_team_attr_rankings_page
# 需要导入模块: import DbSession [as 别名]
# 或者: from DbSession import open_db_session [as 别名]
def get_team_attr_rankings_page(global_config, comp, attr_name):
global_config['logger'].debug( 'GET Team Attribute Rankings' )
session = DbSession.open_db_session(global_config['db_name'])
attrdef_filename = './config/' + global_config['attr_definitions']
attr_definitions = AttributeDefinitions.AttrDefinitions()
attr_definitions.parse(attrdef_filename)
attr = attr_definitions.get_definition(attr_name)
try:
stat_type = attr['Statistic_Type']
except:
stat_type = 'Total'
web.header('Content-Type', 'application/json')
result = []
result.append('{ "rankings": [\n')
team_rankings = DataModel.getTeamAttributesInRankOrder(session, comp, attr_name, False)
for team in team_rankings:
if stat_type == 'Average':
value = int(team.cumulative_value/team.num_occurs)
else:
value = int(team.cumulative_value)
data_str = '{ "team": %d, "value": %d }' % (team.team,value)
result.append(data_str)
result.append(',\n')
if len(team_rankings) > 0:
result = result[:-1]
result.append('\n')
result.append(']}')
return ''.join(result)
示例2: recalculate_scoring
# 需要导入模块: import DbSession [as 别名]
# 或者: from DbSession import open_db_session [as 别名]
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: get_user_form
# 需要导入模块: import DbSession [as 别名]
# 或者: from DbSession import open_db_session [as 别名]
def get_user_form(global_config, username):
global_config['logger'].debug( 'GET User Form For: %s', username )
session = DbSession.open_db_session(global_config['users_db_name'] + global_config['this_season'])
user = UsersDataModel.getUser(session, username)
form = userform()
if user:
form[user_username_label].value = user.username
form[user_emailaddress_label].value = user.email_address
form[user_cellphone_label].value = user.cellphone
form[user_carrier_label].value = user.carrier
form[user_subgroup_label].value = user.subgroup
form[user_password_label].value = user.password
form[user_display_name_label].value = user.display_name
form[user_role_label].value = user.role
form[user_contact_mode_label].value = user.contact_mode
form[user_nickname_label].value = user.altname
form[user_access_level_label].value = user.access_level
form[user_state_label].value = user.state
form[user_taskgroups_label].value = UsersDataModel.getUserTaskgroups(session, user.username)
else:
form[user_access_level_label].value = 10
form[user_role_label].value = 'Guest'
session.remove()
return form
示例4: get_user_list_json
# 需要导入模块: import DbSession [as 别名]
# 或者: from DbSession import open_db_session [as 别名]
def get_user_list_json(global_config):
global_config['logger'].debug( 'GET User List' )
session = DbSession.open_db_session(global_config['users_db_name'] + global_config['this_season'])
user_list = UsersDataModel.getUserList(session)
session.remove()
web.header('Content-Type', 'application/json')
result = []
result.append('{ "users" : [\n')
for user in user_list:
result.append(' { "username": "%s", "email_address": "%s", "display_name": "%s", "nickname": "%s", "access_level": "%s", \
"role": "%s", "subgroup": "%s", "contact_mode": "%s", "cellphone": "%s", "carrier": "%s", "state": "%s" }' % \
(user.username,user.email_address,user.display_name,user.altname, user.access_level, user.role, user.subgroup, user.contact_mode, user.cellphone, user.carrier, user.state))
result.append(',\n')
if len(user_list) > 0:
result = result[:-1]
result.append(' ] }\n')
return ''.join(result)
示例5: delete_comment
# 需要导入模块: import DbSession [as 别名]
# 或者: from DbSession import open_db_session [as 别名]
def delete_comment(global_config, competition, match_str, tag):
session = DbSession.open_db_session(global_config["debriefs_db_name"] + global_config["this_season"])
DebriefDataModel.deleteDebriefCommentsByTag(session, competition, match_str, tag)
session.commit()
return "/debrief/%s/%s" % (competition, match_str)
示例6: process_form
# 需要导入模块: import DbSession [as 别名]
# 或者: from DbSession import open_db_session [as 别名]
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
示例7: process_files
# 需要导入模块: import DbSession [as 别名]
# 或者: from DbSession import open_db_session [as 别名]
def process_files(global_config, attr_definitions, input_dir, recursive=True):
start_time = datetime.datetime.now()
# Initialize the database session connection
db_name = global_config['db_name']
session = DbSession.open_db_session(db_name)
some_files_processed = False
# 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
# the naming format within the directory passed in via command line
# arguments.
file_regex = re.compile('Team[a-zA-Z0-9_]+.txt')
files = get_files(global_config, session, db_name, input_dir, file_regex, recursive)
print 'files retrieved, elapsed time - %s' % (str(datetime.datetime.now()-start_time))
# Process data files
for data_filename in files:
try:
process_file( global_config, session, attr_definitions, data_filename)
except Exception, e:
# log the exception but continue processing other files
log_exception(global_config['logger'], e)
# add the file to the set of processed files so that we don't process it again. Do it outside the
# try/except block so that we don't try to process a bogus file over and over again.
DataModel.addProcessedFile(session, data_filename)
some_files_processed = True
# Commit all updates to the database
session.commit()
示例8: get_team_participation_json
# 需要导入模块: import DbSession [as 别名]
# 或者: from DbSession import open_db_session [as 别名]
def get_team_participation_json():
team_participation = {}
filename = "team_participation"
my_config = ScoutingAppMainWebServer.global_config
session = DbSession.open_db_session(my_config["db_name"] + my_config["this_season"])
teams = session.query(DataModel.TeamInfo).all()
for team in teams:
team_key = "frc%d" % team.team
if team.first_competed is not None:
info = {}
info["first_competed"] = team.first_competed
info["last_competed"] = team.last_competed
team_participation[team_key] = info
team_participation_json = json.dumps(team_participation)
team_participation_js = "var %s = '%s';" % (filename, team_participation_json)
# store the geo location information to a file, too
try:
FileSync.put(my_config, "GlobalData/%s.json" % (filename), "text", team_participation_json)
FileSync.put(my_config, "GlobalData/%s.js" % (filename), "text", team_participation_js)
except:
raise
return team_participation_json
示例9: get_team_list_json
# 需要导入模块: import DbSession [as 别名]
# 或者: from DbSession import open_db_session [as 别名]
def get_team_list_json(global_config, comp):
global team_info_dict
global_config['logger'].debug( 'GET Team List For Competition %s', comp )
session = DbSession.open_db_session(global_config['db_name'])
web.header('Content-Type', 'application/json')
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')
if len(team_list) > 0:
result = result[:-1]
result.append(' ] }\n')
return ''.join(result)
else:
return get_team_list_json_from_tba(global_config, comp)
示例10: process_files
# 需要导入模块: import DbSession [as 别名]
# 或者: from DbSession import open_db_session [as 别名]
def process_files(global_config, attr_definitions, input_dir, recursive=True):
start_time = datetime.datetime.now()
# Initialize the database session connection
db_name = global_config["db_name"] + global_config["this_season"]
session = DbSession.open_db_session(db_name)
some_files_processed = False
# read the ignore file list config each time through the loop. Any files
# in the ignore list will be skipped
ignore_filelist = read_ignore_filelist_cfg(input_dir + "IgnoreFiles.txt")
# 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
# the naming format within the directory passed in via command line
# arguments.
file_regex = re.compile("Team[a-zA-Z0-9_]+.txt")
files = get_files(global_config, session, db_name, input_dir, file_regex, recursive)
if len(files) > 0:
log_msg = "files retrieved, elapsed time - %s" % (str(datetime.datetime.now() - start_time))
print log_msg
global_config["logger"].debug("%s - %s" % (process_files.__name__, log_msg))
global_config["logger"].debug("%s - %d Files to be processed" % (process_files.__name__, len(files)))
# Process data files
for data_filename in files:
# If the file is on the ignore list (quarantined), then skip it
if data_filename.split("/")[-1] in ignore_filelist:
global_config["logger"].debug("%s - Ignoring file: %s" % (process_files.__name__, data_filename))
continue
# Make sure that the data file has not already been processed. We have seen cases
# where the data file gets inserted into the list of files to be processed more than
# once.
file_processed = isFileProcessed(global_config, session, db_name, data_filename)
if not file_processed:
try:
global_config["logger"].debug("%s - Processing file: %s" % (process_files.__name__, data_filename))
process_file(global_config, session, attr_definitions, data_filename)
except Exception, e:
global_config["logger"].debug(
"%s - Error processing file: %s" % (process_files.__name__, data_filename)
)
# log the exception but continue processing other files
log_exception(global_config["logger"], e)
# add the file to the set of processed files so that we don't process it again. Do it outside the
# try/except block so that we don't try to process a bogus file over and over again.
DataModel.addProcessedFile(session, data_filename)
some_files_processed = True
else:
global_config["logger"].debug(
"%s - Skipping file: %s, already processed" % (process_files.__name__, data_filename)
)
# Commit all updates to the database
session.commit()
示例11: get_event_geo_location
# 需要导入模块: import DbSession [as 别名]
# 或者: from DbSession import open_db_session [as 别名]
def get_event_geo_location(global_config, event_key=None):
session = DbSession.open_db_session(global_config['db_name'] + global_config['this_season'])
DataModel.setEventsGeoLocation(session, event_key)
session.remove()
示例12: auth_user
# 需要导入模块: import DbSession [as 别名]
# 或者: from DbSession import open_db_session [as 别名]
def auth_user(global_config, desired_path='/home'):
auth = web.ctx.env.get('HTTP_AUTHORIZATION')
authreq = False
if auth is None:
authreq = True
else:
auth = re.sub('^Basic ','',auth)
username,password = base64.decodestring(auth).split(':')
if logged_out_users.has_key(username):
del logged_out_users[username]
else:
session = DbSession.open_db_session(global_config['users_db_name'] + global_config['this_season'])
user = UsersDataModel.getUser(session, username)
session.remove()
if user:
if user.state == 'Disabled':
raise web.seeother('/accountdisabled')
#if (username,password) in allowed:
if user.check_password(password) == True:
raise web.seeother(desired_path)
authreq = True
if authreq:
web.header('WWW-Authenticate','Basic realm="FRC1073 ScoutingAppCentral"')
web.ctx.status = '401 Unauthorized'
return
示例13: process_delete_attr_form
# 需要导入模块: import DbSession [as 别名]
# 或者: from DbSession import open_db_session [as 别名]
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
示例14: process_delete_file_form
# 需要导入模块: import DbSession [as 别名]
# 或者: from DbSession import open_db_session [as 别名]
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
示例15: get_team_score_json
# 需要导入模块: import DbSession [as 别名]
# 或者: from DbSession import open_db_session [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