def result_multi(): correct_songs = session['correct'] game_id = session['id'] game_instance = Game.query.filter(Game.id == game_id).first() # 正解曲の内容を出力 correct_song_list = Song.dump_correct_songs_list(correct_songs) # 参加したuserのidを取得 users_id_list = Game.fetch_users_id(game_instance) # ユーザーごとの得点を集計 order_score = Log.calc_score(game_id, users_id_list) # 発表用にユーザー名と得点を対応させる display_rank = User.bind_name_score(users_id_list, order_score) # Gameのゴールド、シルバー、ブロンズ内容をupdate Game.update_game(order_score, game_instance) game = { 'judge': session['judge'], 'correct_song_list': correct_song_list, 'count_judge': session['judge'].count(1), 'display_rank': display_rank } return render_template('games/result_multi.html', game=game)
def question_multi(): # 参加が1人なら、ゲーム不成立。 chk_entry = Game.query.with_entities( Game.entry_user2).filter(Game.id == session['id']).all() if not chk_entry[0][0]: return redirect(url_for('failure_multi')) # 10問やってるなら、resultに送る if session['num'] > MAX_QUESTION: return redirect(url_for('result_multi')) num = session['num'] correct = session['correct'] selects = session['select'] # クイズ用の曲をシリアライズして用意する correct_song, select_songs = Song.dump_question_song(correct, selects, num) session['correct_song'] = correct_song game = { 'num': session['num'], 'correct_song': correct_song, 'select_song': select_songs, 'limit_time': round(session['created_timestamp'] + START_WAITING_TIME + QUESTION_TIME * num + ANSWER_TIME * (num - 1)), 'DISPLAY_TIME': DISPLAY_TIME, } return render_template('games/question_multi.html', game=game)
def result(): # 正解曲の内容をダンプ correct_songs = session['correct'] correct_song_list = Song.dump_correct_songs_list(correct_songs) game = { 'judge': session['judge'], 'correct_song_list': correct_song_list, 'count_judge': session['judge'].count(1) } return render_template('games/result.html', game=game)
def add_song(): term = request.form['term'] limit = request.form['limit'] attribute = request.form['attribute'] validate, _status_code = Song.add_song(term, attribute, limit) if validate: flash('新曲が登録されました') else: flash('楽曲の取得に失敗しました・・') print('status code: ', _status_code) return redirect('/admin/song')
def test_add_song(self, mocker): # ダミーのレスポンス作成 responseMock = mocker.Mock() responseMock.status_code = 404 # requests.getの戻り値をpatch mock_res = mocker.patch('requests.get') mock_res.return_value = responseMock term = 'Shmi' attribute = ' Skywalker' limit = 9 validate, status_code = Song.add_song(term, attribute, limit) assert validate == False assert status_code == 404
def question(): # 10問やってるなら、resultに送る if session['num'] > MAX_QUESTION: return redirect(url_for('result')) num = session['num'] correct = session['correct'] selects = session['select'] # クイズ用の曲をシリアライズして用意する correct_song, select_songs = Song.dump_question_song(correct, selects, num) session['correct_song'] = correct_song game = { 'num': session['num'], 'correct_song': correct_song, 'select_song': select_songs } return render_template('games/question.html', game=game)
def start_multi(): # 1人目ならgameを作る if session['creatable']: form = SettingForm() user_id = current_user.id artist = form.artist.data genre = form.genre.data release_from = form.release_from.data release_end = form.release_end.data validate_make_q = None flash_message = '' correct_id = [] select_id = [] # 1度ループ 曲チェック=>追加のため count_loop = 0 while count_loop < 2: # クイズを作る validate_make_q, flash_message, correct_id, select_id = Song.make_question( artist, genre, release_from, release_end) # クイズを作れた場合 if validate_make_q: break # クイズを作れない場合 # ループ 初回 if count_loop < 1: term = '' if artist and genre: term = artist + "+" + genre elif artist and not genre: term = artist elif not artist and genre: term = genre # itunesからDBに曲追加 Song.add_song(term) count_loop += 1 # ループ済みなら抜ける else: break # ループ後 # クイズが作れなかった場合 if not validate_make_q: flash(flash_message) return render_template('games/setting_multi.html', form=form) else: game_id, game_created_at = Game.create_game( correct_id, select_id, user_id) session['id'] = game_id session['correct'] = correct_id session['select'] = select_id session['created_timestamp'] = datetime.timestamp(game_created_at) session['creatable'] = False session['num'] = 1 session['answer'] = [] session['judge'] = [] session['correct_song'] = {} game = { 'limit_time': round(session['created_timestamp'] + START_WAITING_TIME), 'DISPLAY_TIME': DISPLAY_TIME, 'game_id': session['id'], 'START_WAITING_TIME': START_WAITING_TIME, 'MAX_MEMBER': MAX_MEMBER } return render_template('games/start_multi.html', game=game)
def setting_game(): form = SettingForm() if request.method != 'POST': return render_template('games/setting.html', form=form) else: user_id = None if current_user.is_authenticated: user_id = current_user.id artist = form.artist.data genre = form.genre.data release_from = form.release_from.data release_end = form.release_end.data validate_make_q = None flash_message = '' correct_id = [] select_id = [] # 1度ループ 曲チェック=>追加のため count_loop = 0 while count_loop < 2: # クイズを作る validate_make_q, flash_message, correct_id, select_id = Song.make_question( artist, genre, release_from, release_end) # クイズを作れた場合 if validate_make_q: break # クイズを作れない場合 # ループ 初回 if count_loop < 1: term = '' if artist and genre: term = artist + "+" + genre elif artist and not genre: term = artist elif not artist and genre: term = genre # itunesからDBに曲追加 Song.add_song(term) count_loop += 1 # ループ済みなら抜ける else: break # ループ後 # クイズが作れなかった場合 if not validate_make_q: flash(flash_message) return render_template('games/setting.html', form=form) else: game_id, game_created_at = Game.create_game( correct_id, select_id, user_id) session['num'] = 1 session['answer'] = [] session['judge'] = [] session['id'] = game_id session['correct'] = correct_id session['select'] = select_id session['correct_song'] = {} session['created_timestamp'] = None return redirect(url_for('question'))