def deleteProj(): projId = request.args.get("projId") res = orm.transaction(dbDeleteProj, projId=projId) if res: projs = orm.getProjs() print(projs) return jsonify({"res": projs, "msg": "add File Succeed!"}) else: return jsonify({"res": False, "msg": "add File Failed!"})
def rmNode(): projId = request.args.get("projId") nodeId = request.args.get("nodeId") print(projId, nodeId) if orm.transaction(dbRmNode, projId=projId, nodeId=nodeId): res= orm.getProjJson(projId) return jsonify({"res": res, "msg": "add File Succeed!"}) else: return jsonify({"res": False, "msg": "add File Failed!"})
def newProj(): name = request.args.get("name") projId = orm.transaction(dbNewProj,name=name) if projId: projs = orm.getProjs() print(projs) return jsonify({"res": projs, "msg": "add File Succeed!"}) else: return jsonify({"res": False, "msg": "add File Failed!"})
def updateNode(): projId = request.args.get("projId") nodeId = request.args.get("nodeId") nodeType = request.args.get("type") extra = request.args.get("extra") if orm.transaction(dbUpdateNode, projId=projId, nodeId=nodeId, nodeType=nodeType, extra=extra): res= orm.getProjJson(projId) return jsonify({"res": res, "msg": "add File Succeed!"}) else: return jsonify({"res": False, "msg": "add File Failed!"})
def addNode(): projId = request.args.get("projId") parentId = request.args.get("parentId") name = request.args.get("name") print(projId, parentId, name) if orm.transaction(dbAddNode, projId=projId, parentId=parentId, name=name): res= orm.getProjJson(projId) print(res) return jsonify({"res": res, "msg": "add File Succeed!"}) else: return jsonify({"res": False, "msg": "add File Failed!"})
def execute_action(cls, context, input): action_time = tools.Profile() tools.log.debug('Action: %s.%s' % (context.model.__name__, context.action.key_id_str)) def execute_plugins(plugins): for plugin in plugins: module = plugin.__module__ plugin_time = tools.Profile() plugin.run(context) tools.log.debug('Plugin: %s.%s in %sms' % (module, plugin.__class__.__name__, plugin_time.miliseconds)) if hasattr(context.model, 'get_plugin_groups') and callable( context.model.get_plugin_groups): try: plugin_groups = context.model.get_plugin_groups(context.action) if len(plugin_groups): for group in plugin_groups: if len(group.plugins): if group.transactional: orm.transaction( lambda: execute_plugins(group.plugins), xg=True) else: execute_plugins(group.plugins) except orm.TerminateAction as e: tools.log.debug('Action terminated with: %s' % e.message) except Exception as e: raise finally: tools.log.debug('Completed action in %sms' % action_time.miliseconds) if context._callbacks: tools.log.warn('Unhandled callbacks: %s' % context._callbacks)
def delete(season_id): with orm.transaction(): orm.apply_musigma_team_penalties(season_id) orm.terminate_season(season_id, datetime.datetime.now()) # Award stars ranked_users = orm.to_json( orm.get_ranked_users_musigma_team(season_id)) if len(ranked_users) > 1: orm.award_gold_star(ranked_users[0]['user_id']) orm.award_loser_star(ranked_users[-1]['user_id']) if len(ranked_users) > 2: orm.award_silver_star(ranked_users[1]['user_id']) if len(ranked_users) > 3: orm.award_copper_star(ranked_users[2]['user_id']) return { 'message': 'Season finished', }
def update(match_id, season_id, r_ids, b_ids, r_score, b_score): def get_rates(ids): # Get musigma user / create it if none res = [] for user_id in ids: pl = orm.to_json( orm.get_user_musigma_team.first(user_id, season_id)) rating = Rating(float(pl['mu']), float( pl['sigma'])) if pl is not None else Rating() res.append(rating) return res env_name = 'global' if not season_id else 'season' set_trueskill_env(env_name) env = get_trueskill_env(env_name) r_ids = [user_id for user_id in r_ids if user_id is not None] b_ids = [user_id for user_id in b_ids if user_id is not None] r_rates = get_rates(r_ids) b_rates = get_rates(b_ids) new_r_rates, new_b_rates = rate([r_rates, b_rates], ranks=[b_score, r_score]) # Lower is better new_rates = new_r_rates + new_b_rates new_expositions = [expose(r) for r in new_rates] with orm.transaction(): for idx, user_id in enumerate(r_ids + b_ids): # Init user to default stats if not already in base user_musigma_team = orm.to_json( orm.get_user_musigma_team(user_id, season_id)) if len(user_musigma_team) == 0: init_user(user_id, season_id) orm.create_user_musigma_team(user_id, match_id, season_id, new_expositions[idx], new_rates[idx].mu, new_rates[idx].sigma)
def convert(match_id, validator): pending_match = orm.to_json(orm.get_pending_match_by_id.first(match_id)) # pending_stats = orm.to_json(orm.get_pending_match_stats(match_id)) if pending_match is None: abort(404, "Pending match not found") ids = {'r': [], 'b': []} for team in ['r', 'b']: for idx in range(1, 7): pseudo = pending_match[team + str(idx)]['user_pseudo'] if pseudo is None: pending_match[team + str(idx)] = None continue player = orm.to_json(orm.get_user_by_pseudo.first(pseudo)) if player is None: abort( 400, "Pseudo {} can't be matched against existing players". format(pseudo)) pending_match[team + str(idx)]['user_id'] = player['id'] ids[team].append(player['id']) try: with orm.transaction(): new_match_id = matches_controller.create( pending_match['b_score'], pending_match['r_score'], pending_match['duration'], pending_match['datetime'], pending_match['b1']['user_id'] if pending_match['b1'] else None, pending_match['b2']['user_id'] if pending_match['b2'] else None, pending_match['b3']['user_id'] if pending_match['b3'] else None, pending_match['b4']['user_id'] if pending_match['b4'] else None, pending_match['b5']['user_id'] if pending_match['b5'] else None, pending_match['b6']['user_id'] if pending_match['b6'] else None, pending_match['r1']['user_id'] if pending_match['r1'] else None, pending_match['r2']['user_id'] if pending_match['r2'] else None, pending_match['r3']['user_id'] if pending_match['r3'] else None, pending_match['r4']['user_id'] if pending_match['r4'] else None, pending_match['r5']['user_id'] if pending_match['r5'] else None, pending_match['r6']['user_id'] if pending_match['r6'] else None, validator)['value'] for team in ['r', 'b']: for idx in range(1, 7): player = pending_match[team + str(idx)] if player is None: continue matches_stats_controller.create( new_match_id, player['user_id'], player['score'], player['tags'], player['popped'], player['grabs'], player['drops'], player['hold'], player['captures'], player['prevent'], player['returns'], player['support'], player['pups']) matchespending_stats_controller.delete_all(new_match_id) delete(match_id) # Link match to season season = seasons_controller.show_current() if season is not None: seasons_matches_controller.create(season['id'], new_match_id) # Update algo # TODO: All player stats will probably need to be passed here to update algo algos_controller.update(new_match_id, r_ids=ids['r'], b_ids=ids['b'], r_score=pending_match['r_score'], b_score=pending_match['b_score']) except postgresql.exceptions.ForeignKeyError: abort(400, "Something failed. Confident in all user ids ?") return { 'message': 'Match validated', 'value': new_match_id, }