def schedulematchv1(self, map_name, mod_name, ais, options, speed, softtimeout, hardtimeout): map = Session.query(Map).filter(Map.map_name == map_name).first() mod = Session.query(Mod).filter(Mod.mod_name == mod_name).first() ai0 = Session.query(AI).filter(AI.ai_name == ais[0]['ai_name']).\ filter(AI.ai_version == ais[0]['ai_version']).first() ai1 = Session.query(AI).filter(AI.ai_name == ais[1]['ai_name']).\ filter(AI.ai_version == ais[1]['ai_version']).first() ai0Side = Session.query(ModSide).filter(ModSide.mod_side_name == \ ais[0]['ai_side']).filter(ModSide.mod_id == mod.mod_id).first() ai1Side = Session.query(ModSide).filter(ModSide.mod_side_name == \ ais[1]['ai_side']).filter(ModSide.mod_id == mod.mod_id).first() if map == None or mod == None or ai0 == None or ai1 == None: return [False, 'one of your parameters did not correspond to an existing map, mod or ai. Please check and try again.'] if softtimeout == None or hardtimeout == None: return [False, 'you need to specify both a hard timeout and a soft timeout for the match'] if speed == None: speed = 1 matchrequest = MatchRequest(ai0 = ai0, ai1 = ai1, map = map, mod = mod, speed = speed, softtimeout = softtimeout, hardtimeout = hardtimeout, ai0_side = ai0Side, ai1_side = ai1Side) Session.add(matchrequest) # add options: availableoptions = Session.query(AIOption) for option in availableoptions: if option.option_name in options: matchrequest.options.append(option) Session.commit() return [True, matchrequest.matchrequest_id]
def schedulematchesv1(self,matches): matchrequest_ids = [] for match in matches: map_name = match["map_name"] mod_name = match["mod_name"] options = match["options"] ais = match["ais"] softtimeout = match["softtimeout"] hardtimeout = match["hardtimeout"] speed = match["speed"] ai0_side = ais[0]['ai_side'] ai1_side = ais[1]['ai_side'] try: map = Session.query(Map).filter(Map.map_name == map_name ).first() mod = Session.query(Mod).filter(Mod.mod_name == mod_name ).first() ai0 = Session.query(AI).filter(AI.ai_name == ais[0]['ai_name']).filter(AI.ai_version == ais[0]['ai_version'] ).first() ai1 = Session.query(AI).filter(AI.ai_name == ais[1]['ai_name']).filter(AI.ai_version == ais[1]['ai_version'] ).first() ai0_side = Session.query(ModSide).filter(ModSide.mod_side_id == ai0_side).first() ai1_side = Session.query(ModSide).filter(ModSide.mod_side_id == ai1_side).first() if map == None or mod == None or ai0 == None or ai1 == None or ai0_side == None or ai1_side == None: return [False,'one of your parameters did not correspond to an existing map, mod, ai or ai sides. Please check and try again.'] if softtimeout == None or hardtimeout == None: return [False,'you need to specify both a hard timeout and a soft timeout for the match'] if speed == None: speed = 1 matchrequest = MatchRequest( ai0 = ai0, ai1 = ai1, map = map, mod = mod, speed = speed, softtimeout = softtimeout, hardtimeout = hardtimeout, ai0_side = ai0_side, ai1_side = ai1_side ) Session.add( matchrequest ) # add options: availableoptions = Session.query(AIOption) for option in availableoptions: if option.option_name in options: matchrequest.options.append( option ) matchrequest_ids.append(matchrequest.matchrequest_id) except: return (False,"An unexpected exception occurred: " + str( sys.exc_info() ) + "\n" + str( traceback.extract_tb( sys.exc_traceback ) ) ) Session.commit() return [True, matchrequest_ids]