def api_post_register(): try: name = request.get_json()['name'] email = request.get_json()['email'] password = request.get_json()['password'] location = request.get_json()['location'] about = request.get_json()['about'] except KeyError: return jsonify({"status": "error"}) if Participants.query.filter_by(email=email).first(): return jsonify({"status": "error"}) participant = Participants(name=name, email=email, password=password, location=location, about=about) db.session.add(participant) db.session.commit() return jsonify( dict(id=Participants.query.count(), name=name, email=email, password=password, location=location, about=about))
def parseCSV(filePath): # CVS Column Names col_names = [ 'visionOuc', 'oucDescription', 'schemeCode', 'accountNo', 'accountName', 'accountOpenDate', 'phoneNumber' ] # Use Pandas to parse the CSV file csvData = pd.read_csv(filePath, names=col_names, sep=';', header=0) # Loop through the Rows for i, row in csvData.iterrows(): participant = Participants(row['visionOuc'], row['oucDescription'], row['schemeCode'], row['accountNo'], row['accountName'], row['accountOpenDate'], row['phoneNumber']) db.session.add(participant) db.session.commit()
def process_match(match): """ 試合履歴を処理する """ try: match_model = Matches.query.filter_by(uuid=match.id).first() if match_model is not None: # 処理済なので処理件数は0で返す return 0 app.logger.info('processing a match : id = ' + match.id) match_model = Matches(uuid=match.id, shardId=match.shardId, gameMode=match.gameMode, duration=match.duration, endGameReason=match.stats['endGameReason'], patchVersion=match.patchVersion, createdAt=datetime.datetime.strptime( match.createdAt, '%Y-%m-%dT%H:%M:%SZ')) db.session.add(match_model) db.session.flush() for roster in match.rosters: roster_model = Rosters( match_id=match_model.id, acesEarned=roster.stats['acesEarned'], gold=roster.stats['gold'], heroKills=roster.stats['heroKills'], krakenCaptures=roster.stats['krakenCaptures'], side=roster.stats['side'], turretKills=roster.stats['turretKills'], turretsRemaining=roster.stats['turretsRemaining'], won=1 if roster.won == 'true' else 0, averageRankedPoint=0, averageRank=0) db.session.add(roster_model) db.session.flush() player_count = 0 total_rank_points = 0 # Role特定の為に Participant のモデル一覧を保持する participant_models = [] for participant in roster.participants: player_count = player_count + 1 player = participant.player player_model = Players.query.filter_by( playerId=player.key_id).first() if player_model is None: player_model = Players(playerId=player.key_id, shardId=player.shardId) player_model.name = player.name player_model.rankPoints = player.stats['rankPoints'] player_model.gamesPlayed = player.stats['gamesPlayed'] player_model.guildTag = player.stats['guildTag'] player_model.karmaLevel = player.stats['karmaLevel'] player_model.level = player.stats['level'] player_model.updatedAt = datetime.datetime.now() db.session.add(player_model) db.session.flush() rank_point_key = 'ranked' if match.gameMode == '5v5_pvp_ranked' or match.gameMode == '5v5_pvp_casual': rank_point_key = 'ranked_5v5' if match.gameMode == 'casual' or match.gameMode == 'ranked': rank_point_key = 'ranked' if match.gameMode == 'blitz_pvp_ranked': rank_point_key == 'blitz' rank_point = player_model.rankPoints[rank_point_key] rank = get_rank(rank_point) total_rank_points = total_rank_points + rank_point items = participant.stats['items'] analyzed_build = analyze_build(items) participant_model = Participants( match_id=match_model.id, roster_id=roster_model.id, player_id=player_model.id, player_name=player_model.name, rankPoint=rank_point, rank=rank, actor=participant.actor, kills=participant.stats['kills'], assists=participant.stats['assists'], deaths=participant.stats['deaths'], gold=participant.stats['gold'], minionKills=participant.stats['minionKills'], jungleKills=participant.stats['jungleKills'], nonJungleMinionKills=participant. stats['nonJungleMinionKills'], items=items, itemUses=participant.stats['itemUses'], is_wp_build=analyzed_build['is_wp_build'], is_cp_build=analyzed_build['is_cp_build'], is_hybrid_build=analyzed_build['is_hybrid_build'], is_utility_build=analyzed_build['is_utility_build'], wentAfk=participant.stats['wentAfk'], skinKey=participant.stats['skinKey'], winner=participant.stats['winner'], ) db.session.add(participant_model) db.session.flush() participant_models.append(participant_model) # ロール計算 if match.gameMode == 'ranked': # 3v3 carry_model = sorted(participant_models, key=lambda x: x.nonJungleMinionKills, reverse=True)[0] carry_model.role = 'laner' db.session.add(carry_model) jungler_model = sorted(participant_models, key=lambda x: x.jungleKills, reverse=True)[0] jungler_model.role = 'jungler' db.session.add(jungler_model) captain_model = sorted(participant_models, key=lambda x: x.minionKills, reverse=False)[0] captain_model.role = 'captain' db.session.add(captain_model) elif match.gameMode == '5v5_pvp_ranked': # 5v5 jungle_or_captain = [] sorted_models = sorted( participant_models, key=lambda x: [x.nonJungleMinionKills, x.jungleKills], reverse=True) for idx in range(len(sorted_models)): participant_model = sorted_models[idx] if idx <= 2: participant_model.role = 'laner' db.session.add(participant_model) else: jungle_or_captain.append(participant_model) sorted_model = sorted(jungle_or_captain, key=lambda x: x.jungleKills, reverse=True) jungle_model = sorted_model[0] jungle_model.role = 'jungler' db.session.add(jungle_model) captain_model = sorted_model[1] captain_model.role = 'captain' db.session.add(captain_model) elif match.gameMode == 'blitz_pvp_ranked': for participant_model in participant_models: participant_model.role = 'laner' db.session.add(participant_model) # 各サイドの平均ランクを保存 roster_model.averageRankedPoint = total_rank_points / player_count roster_model.averageRank = get_rank( roster_model.averageRankedPoint) db.session.add(roster_model) db.session.flush() # 試合を処理したら処理件数(この場合は常に1)を返す db.session.commit() return 1 except: app.logger.error(traceback.print_exc()) db_session.rollback() return 0
def process_match_normal(match): try: app.logger.info('processing a match : id = {}, createdAt = {}'.format( match.id, match.createdAt)) match_model = Matches.query.filter_by(uuid=match.id).first() if match_model is not None: return match_model match_model = Matches(uuid=match.id, shardId=match.shardId, gameMode=match.gameMode, duration=match.duration, endGameReason=match.stats['endGameReason'], patchVersion=match.patchVersion, createdAt=datetime.strptime( match.createdAt, '%Y-%m-%dT%H:%M:%SZ')) db.session.add(match_model) db.session.flush() telemetry_data = {} if match.gameMode in ['5v5_pvp_ranked', '5v5_pvp_casual']: if len(match.assets) > 0: telemetry_url = match.assets[0].url telemetry = requests.get(telemetry_url).json() telemetry_data = analyze_telemetry(telemetry) else: """ Sometimes there's no telemetry data. Perhaps SEMC server's issue. """ app.logger.error('There is no match.assets[0]') app.logger.error(vars(match)) db.session.commit() return None # シナジーデータ計算用に Participant モデルのリストを保持する participant_models_by_rosters = [] is_rank7_or_more = True for roster in match.rosters: roster_model = Rosters( match_id=match_model.id, acesEarned=roster.stats['acesEarned'], gold=roster.stats['gold'], heroKills=roster.stats['heroKills'], krakenCaptures=roster.stats['krakenCaptures'], side=roster.stats['side'], turretKills=roster.stats['turretKills'], turretsRemaining=roster.stats['turretsRemaining'], won=1 if roster.won == 'true' else 0, averageRankedPoint=0, averageRank=0) db.session.add(roster_model) db.session.flush() player_count = 0 total_rank_points = 0 # ロール特定の為に Participant のモデル一覧を保持する participant_models = [] for participant in roster.participants: # プレイヤーの情報を更新 player_count += 1 player = participant.player player_model = Players.query.filter_by( playerId=player.key_id).first() if player_model is None: player_model = Players(playerId=player.key_id, shardId=player.shardId) if player_model.updatedAt is None or player_model.updatedAt > datetime.now( ): player_model.name = player.name player_model.rankPoints = player.stats['rankPoints'] player_model.gamesPlayed = player.stats['gamesPlayed'] player_model.guildTag = player.stats['guildTag'] player_model.karmaLevel = player.stats['karmaLevel'] player_model.level = player.stats['level'] player_model.updatedAt = datetime.now() db.session.add(player_model) db.session.flush() # ヒーローID取得 actor = participant.actor hero = MHeroes.query.filter(MHeroes.actor == actor).first() if hero is None: hero = MHeroes(actor=actor, ja=actor, en=actor) db.session.add(hero) db.session.flush() rank_point_key = 'ranked' if match.gameMode in ['5v5_pvp_ranked', '5v5_pvp_casual']: rank_point_key = 'ranked_5v5' if match.gameMode in ['casual', 'ranked']: rank_point_key = 'ranked' if match.gameMode == 'blitz_pvp_ranked': rank_point_key == 'blitz' rank_point = player_model.rankPoints[rank_point_key] rank = get_rank(rank_point) total_rank_points = total_rank_points + rank_point participant_model = Participants( match_id=match_model.id, roster_id=roster_model.id, player_id=player_model.id, player_name=player_model.name, rankPoint=rank_point, rank=rank, hero_id=hero.id, actor=actor, kills=participant.stats['kills'], assists=participant.stats['assists'], deaths=participant.stats['deaths'], gold=participant.stats['gold'], minionKills=participant.stats['minionKills'], jungleKills=participant.stats['jungleKills'], nonJungleMinionKills=participant. stats['nonJungleMinionKills'], items=participant.stats['items'], itemUses=participant.stats['itemUses'], build_type=get_build_type(participant.stats['items']), wentAfk=participant.stats['wentAfk'], skinKey=participant.stats['skinKey'], winner=participant.stats['winner'], ) participant_models.append(participant_model) db.session.add_all(participant_models) db.session.flush() # ロール割り振り try: patricipant_models_with_role = _assign_role_to_participants( match, participant_models, roster_model.side, telemetry_data) db.session.add_all(patricipant_models_with_role) participant_models_by_rosters.append( patricipant_models_with_role) # ヒーロー統計データ蓄積 stat_hero_models = _create_stat_heroes( match_model, patricipant_models_with_role) db.session.add_all(stat_hero_models) # 各サイドの平均ランクを保存 roster_model.averageRankedPoint = total_rank_points / player_count roster_model.averageRank = get_rank( roster_model.averageRankedPoint) db.session.add(roster_model) db.session.flush() except: # エラーは了解したので、取り敢えず進める # FIXME 後で直す app.logger.error(traceback.print_exc()) db.session.commit() return match_model if roster_model.averageRank < 7: is_rank7_or_more = False # シナジーデータ蓄積 if is_rank7_or_more: hero_synergy_models = _create_hero_synergy( match_model, participant_models_by_rosters) db.session.add_all(hero_synergy_models) db.session.commit() return match_model except: app.logger.error(traceback.print_exc()) db.session.rollback() return None
def manual_signup(): """ Admin signup page, allows signup outside of registration period """ form = SignupForm(request.form) try: event = Events.query.filter(Events.active).first() if event != None: eventid = event.id timeslots = TimeSlots.query.filter( TimeSlots.event_id == eventid).all() if timeslots != None: [available_slots_choices, available_special_slots_choices ] = get_slots_choices(timeslots) form.availableslots.choices = available_slots_choices form.availablespecialslots.choices = available_special_slots_choices except Exception as e: print(e) return render_template('error.html') if request.method == 'POST' and form.validate(): try: timestamp = datetime.now() name = str(request.form['name']) prename = str(request.form['prename']) gender = Gender(int(request.form['gender'])) email = str(request.form['email']) email2 = str(request.form['email2']) if email != email2: message = 'Deine Mailadressen stimmen nicht überein!\ Bitte geh zurück und korrigiere deine Mailadresse.' return render_template('error.html', message=message) mobile = str(request.form['mobile_nr']) address = str(request.form['address']) birthday = str(request.form['birthday']) studycourse = str(request.form['study_course']) studysemester = str(request.form['study_semester']) perfectdate = str(request.form['perfect_date']) fruit = str(request.form['fruit']) availablespecialslots = None if event.special_slots: availablespecialslots = request.form.getlist( 'availablespecialslots') availableslots = request.form.getlist('availableslots') confirmed = False present = False paid = False slots = 0 if availableslots: slots = int(availableslots[0]) elif availablespecialslots: slots = int(availablespecialslots[0]) else: message = 'Du hast kein passendes Datum ausgewählt!\ Bitte geh zurück und wähle ein dir passendes Datum aus.' return render_template('error.html', message=message) bday = datetime.strptime(birthday, '%d.%m.%Y') chosen_timeslot = TimeSlots.query.filter( TimeSlots.id == int(slots)).first() slot_datetime = str( chosen_timeslot.date.strftime("%A %d. %B %Y")) + ' ' + str( chosen_timeslot.start_time.strftime("%H:%M")) try: new_participant = Participants(creation_timestamp=timestamp, event_id=eventid, name=name, prename=prename, email=email, mobile_nr=mobile, address=address, birthday=bday, gender=gender, study_course=studycourse, study_semester=studysemester, perfect_date=perfectdate, fruit=fruit, slot=slots, confirmed=confirmed, present=present, paid=paid) db.session.add(new_participant) db.session.commit() # The participant signed up successfully # Emit signal and show success page SIGNAL_NEW_SIGNUP.send('signup view', participant=new_participant, slot_datetime=slot_datetime) except Participants.AlreadySignedUpException: message = 'Die E-Mail Adresse ' + email + \ ' wurde bereits für das Speeddating angewendet.\ Bitte versuchen Sie es erneut mit einer neuen E-Mail Adresse.' return render_template('error.html', message=message) except Exception as e: print('Exception of type {} occurred: {}'.format(type(e), str(e))) return render_template('error.html') return render_template('success.html', name=('{} {}'.format(prename, name)), mail=email, datetime=slot_datetime) return render_template('manual_signup.html', form=form, event=event)
def process_match(match, now): """ 1つの試合履歴を処理する """ try: app.logger.info('processing a match : id = {}, createdAt = {}'.format( match.id, match.createdAt)) gameMode = match.gameMode if gameMode is None: app.logger.error('gameMode is None!! match = {}'.format( vars(match))) return None match_model = Matches.query.filter_by(uuid=match.id).first() if match_model is not None: app.logger.info('skipped a match : id = {}'.format(match.id)) # 処理済なので処理件数は0で返す return 0 match_model = Matches(uuid=match.id, shardId=match.shardId, gameMode=gameMode, duration=match.duration, endGameReason=match.stats['endGameReason'], patchVersion=match.patchVersion, createdAt=datetime.strptime( match.createdAt, '%Y-%m-%dT%H:%M:%SZ')) db.session.add(match_model) db.session.flush() # テレメトリー解析情報 telemetry_data = {} if gameMode in [ '5v5_pvp_ranked', '5v5_pvp_casual', 'private_party_vg_5v5', 'private_party_draft_match_5v5' ]: if len(match.assets) == 0: # 過去にデータが欠けている事があった pass else: telemetry_url = match.assets[0].url telemetry = requests.get(telemetry_url).json() telemetry_data = analyze_telemetry(telemetry) # シナジーデータ計算用に Participant モデルのリストを保持する participant_models_by_rosters = [] is_rank7_or_more = True roster_by_side = {} for roster in match.rosters: roster_model = Rosters( match_id=match_model.id, acesEarned=roster.stats['acesEarned'], gold=roster.stats['gold'], heroKills=roster.stats['heroKills'], krakenCaptures=roster.stats['krakenCaptures'], side=roster.stats['side'], turretKills=roster.stats['turretKills'], turretsRemaining=roster.stats['turretsRemaining'], won=1 if roster.won == 'true' else 0, averageRankedPoint=0, averageRank=0) db.session.add(roster_model) db.session.flush() roster_by_side[roster_model.side] = roster_model player_count = 0 total_rank_points = 0 # ロール特定の為に Participant のモデル一覧を保持する participant_models = [] for participant in roster.participants: # プレイヤーの情報を更新 player_count += 1 player = participant.player player_model = Players.query.filter_by( playerId=player.key_id).first() if player_model is None: player_model = Players(playerId=player.key_id, shardId=player.shardId) if player_model.updatedAt is None or player_model.updatedAt < datetime.now( ): player_model.name = player.name player_model.rankPoints = player.stats['rankPoints'] player_model.gamesPlayed = player.stats['gamesPlayed'] player_model.guildTag = player.stats['guildTag'] player_model.karmaLevel = player.stats['karmaLevel'] player_model.level = player.stats['level'] player_model.updatedAt = datetime.now() db.session.add(player_model) db.session.flush() # ヒーロー取得 actor = participant.actor hero = MHeroes.query.filter(MHeroes.actor == actor).first() if hero is None: hero = MHeroes(actor=actor, ja=actor, en=actor) db.session.add(hero) db.session.flush() rank_point_key = 'ranked' if gameMode in [ '5v5_pvp_ranked', '5v5_pvp_casual', 'private_party_vg_5v5', 'private_party_draft_match_5v5' ]: rank_point_key = 'ranked_5v5' if gameMode in ['casual', 'ranked']: rank_point_key = 'ranked' if gameMode == 'blitz_pvp_ranked': rank_point_key == 'blitz' rank_point = player_model.rankPoints[rank_point_key] rank = get_rank(rank_point) total_rank_points = total_rank_points + rank_point participant_model = Participants( match_id=match_model.id, roster_id=roster_model.id, player_id=player_model.id, player_name=player_model.name, rankPoint=rank_point, rank=rank, hero_id=hero.id, actor=actor, kills=participant.stats['kills'], assists=participant.stats['assists'], deaths=participant.stats['deaths'], gold=participant.stats['gold'], minionKills=participant.stats['minionKills'], jungleKills=participant.stats['jungleKills'], nonJungleMinionKills=participant. stats['nonJungleMinionKills'], items=participant.stats['items'], itemUses=participant.stats['itemUses'], build_type=get_build_type(participant.stats['items']), wentAfk=participant.stats['wentAfk'], skinKey=participant.stats['skinKey'], winner=participant.stats['winner'], ) participant_models.append(participant_model) db.session.add_all(participant_models) db.session.flush() # ロール割り振り patricipant_models_with_role = _assign_role_to_participants( match, participant_models, roster_model.side, telemetry_data) db.session.add_all(patricipant_models_with_role) participant_models_by_rosters.append(patricipant_models_with_role) # ヒーロー統計データ蓄積 stat_hero_models = _create_stat_heroes( match_model, patricipant_models_with_role) db.session.add_all(stat_hero_models) # 各サイドの平均ランクを保存 roster_model.averageRankedPoint = total_rank_points / player_count roster_model.averageRank = get_rank( roster_model.averageRankedPoint) db.session.add(roster_model) db.session.flush() if roster_model.averageRank < 7: is_rank7_or_more = False # シナジーデータ蓄積 if is_rank7_or_more: hero_synergy_models = _create_hero_synergy( match_model, participant_models_by_rosters) db.session.add_all(hero_synergy_models) if gameMode in ['5v5_pvp_ranked', 'private_party_draft_match_5v5']: if 'banpick_order' in telemetry_data: banpick_order = telemetry_data['banpick_order'] match_extra_model = MatchesExtra.query.filter_by( match_id=match_model.id).first() if match_extra_model is None: match_extra_model = MatchesExtra( match_id=match_model.id, banpick=banpick_order, ) db.session.add(match_extra_model) db.session.flush() for ban_order in range(0, 4): side = 'left/blue' if ban_order % 2 == 0 else 'right/red' roster_model = roster_by_side[side] actor = banpick_order[ban_order] ban_hero_id = get_hero_id_by_actor(actor) if ban_hero_id is not None: stat_ban_hero_model = StatBanHeroes.query_one_or_init({ 'patchVersion': match_model.patchVersion, 'shardId': match_model.shardId, 'gameMode': match_model.gameMode, 'averageRank': roster_model.averageRank, 'side': roster_model.side, 'ban_order': ban_order, 'ban_hero_id': ban_hero_id }) stat_ban_hero_model.games += 1 if roster_model.won == 1: stat_ban_hero_model.wins += 1 stat_ban_hero_model.win_rate = stat_ban_hero_model.wins / stat_ban_hero_model.games db.session.add(stat_ban_hero_model) db.session.flush() db.session.commit() # 試合を処理したら処理件数(この場合は常に1)を返す return 1 except: app.logger.error(traceback.print_exc()) db.session.rollback() return 0