diff --git a/flask/testapp/static/javascript/beautyVote.js b/flask/testapp/static/javascript/beautyVote.js index f48b218..4e5adae 100644 --- a/flask/testapp/static/javascript/beautyVote.js +++ b/flask/testapp/static/javascript/beautyVote.js @@ -2,29 +2,17 @@ class Question{ constructor(){ this.question = 0; - this.answer1 = 0; - this.answer2 = 0; - this.answer3 = 0; - this.answer4 = 0; - this.people1 = 0; - this.people2 = 0; - this.people3 = 0; - this.people4 = 0; + this.answer = new Array(CHOICE_NUMBER).fill(0); + this.people = new Array(CHOICE_NUMBER).fill(0); + this.realAnswer = 0; this.choiceA = 0; this.choiceB = 0; this.choiceC = 0; this.choiceD = 0; } - join(question, answer1, answer2, answer3, answer4, people1, people2, people3, people4, choiceA, choiceB, choiceC, choiceD){ + join(question, realAnswer, choiceA, choiceB, choiceC, choiceD){ this.question = question; - this.answer1 = answer1; - this.answer2 = answer2; - this.answer3 = answer3; - this.answer4 = answer4; - this.people1 = people1; - this.people2 = people2; - this.people3 = people3; - this.people4 = people4; + this.realAnwer = realAnswer; this.choiceA = choiceA; this.choiceB = choiceB; this.choiceC = choiceC; @@ -34,7 +22,7 @@ class Player{ constructor(){ - this.points = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + this.points = Array(MAX_ROUND).fill(0); this.choice = 0; this.name = 0; this.number = 0; @@ -138,14 +126,14 @@ console.log("show round"+i) showOtherResult(i) view_result = i - scene = CHEAK_RESUlT + scene = CHECK_RESULT } } } } break; - case CHEAK_RESUlT: + case CHECK_RESULT: showOtherResult(view_result); if(tapC == 1){ tapC ++; @@ -170,27 +158,33 @@ function setQuestion(round){ - question[round].join(questions[round], answer1[round], answer2[round], answer3[round], answer4[round], people1[round], people2[round], - people3[round], people4[round], choices[round][A], choices[round][B], choices[round][C], choices[round][D]); + question[round].join(questions[round], realAnswer[round],choices[round][A], choices[round][B], choices[round][C], choices[round][D]); } function checkAnswer(){ - if(player.choice == question[round].answer1){ + for(var i = 0; i < CHOICE_NUMBER; i ++){ + if(player.choice == question[round].answer[i]){ + player.points[round] = String(4-i); + break; + } + } +/* + if(player.choice == question[round].answer[0]){ player.points[round] = "4"; } - else if(player.choice == question[round].answer2){ + else if(player.choice == question[round].answer[1]){ player.points[round] = "3"; } - else if(player.choice == question[round].answer3){ + else if(player.choice == question[round].answer[2]){ player.points[round] = "2"; } - else if(player.choice == question[round].answer4){ + else if(player.choice == question[round].answer[3]){ player.points[round] = "1"; } else{ player.points[round] = "0"; - } + }*/ round ++; console.log(player.points[round]) if(round < MAX_ROUND){ @@ -258,7 +252,7 @@ //他の参加者が集まるまで待機 else{ var max_current_player = xhr.responseText - let splitplayer = max_current_player.split(" "); + var splitplayer = max_current_player.split(" "); max_player = splitplayer[0] current_player = splitplayer[1] console.log(max_player); @@ -284,7 +278,14 @@ timer = 0; console.log(xhr.responseText); answerTable = xhr.responseText - let splitAnswer = answerTable.split("\n"); + var splitAnswer = answerTable.split("\n"); + for(var i = 0; i < CHOICE_NUMBER; i ++){ + // i番目に多かった答えと人数 + var arr_answer = splitAnswer[i].split(" "); + question[round].answer[i] = arr_answer[0]; + question[round].people[i] = arr_answer[1]; + } + /* // 1番目に多かった答えと人数 let arr_answer1 = splitAnswer[0].split(" "); question[round].answer1 = arr_answer1[0]; @@ -302,7 +303,7 @@ question[round].answer4 = arr_answer4[0]; question[round].people4 = arr_answer4[1]; console.log(question[round].answer4) - console.log(question[round].people4) + console.log(question[round].people4)*/ //正解判定 checkAnswer(); if(round < MAX_ROUND) @@ -342,7 +343,8 @@ var round = 0; //変更 -var MAX_ROUND = 2; +var MAX_ROUND = 5; +var CHOICE_NUMBER = 4; var max_player = 0; // 最大のplayer数(変更不要) var current_player = 0; @@ -365,7 +367,7 @@ var WAIT_SCENE = 4; // nemoto追記 var WAIT_RESULT = 5; var WAIT_START = 6; // nemoto追記 -var CHEAK_RESUlT = 7; +var CHECK_RESULT = 7; var scene = START_SCENE; @@ -389,16 +391,11 @@ "名前が人物に由来しているのは?", "ジンベイザメは英語で何シャーク?", "心臓がない生き物は?"]; - -var answer1 = [0]*MAX_ROUND; -var answer2 = [0]*MAX_ROUND; -var answer3 = [0]*MAX_ROUND; -var answer4 = [0]*MAX_ROUND; - -var people1 = [0]*MAX_ROUND; -var people2 = [0]*MAX_ROUND; -var people3 = [0]*MAX_ROUND; -var people4 = [0]*MAX_ROUND; +/* +var answers = new Array(MAX_ROUND); +for (var i = 0; i < MAX_ROUND; i++) { + answers[i] = new Array(CHOICE_NUMBER).fill(0); +}*/ var choices = [["がっくり", "げっそり", "むっつり", "しっとり"], ["ドナルド・トランプ", "ボリス・ジョンソン", "ウラジーミル・プーチン", "アンゲラ・メルケル"], @@ -411,4 +408,6 @@ ["エレファント", "ホエール", "ダイナソー", "メガ"], ["カニ", "ナマコ", "タコ", "ホタテ"]]; +var realAnswer = new Array(MAX_ROUND).fill(0); + var view_result = 0; \ No newline at end of file diff --git a/flask/testapp/static/javascript/resultScreen.js b/flask/testapp/static/javascript/resultScreen.js index 950dff9..d7035f7 100644 --- a/flask/testapp/static/javascript/resultScreen.js +++ b/flask/testapp/static/javascript/resultScreen.js @@ -187,6 +187,8 @@ fText(question[show_round].choiceA, 275, 425, 25, "white"); fText(CheckPeople(0, show_round) +"人", 275, 425, 50, "black"); + fText(CheckPeople(0, show_round) +"人", 275, 425, 50, "black"); + fText(question[show_round].choiceB, 725, 425, 25, "white"); fText(CheckPeople(1, show_round)+"人", 725, 425, 50, "black"); @@ -211,10 +213,9 @@ function CheckPeople(i, show_round){ - let question_values = [int(question[show_round].answer1), int(question[show_round].answer2), int(question[show_round].answer3), int(question[show_round].answer4)] - let people_values = [int(question[show_round].people1), int(question[show_round].people2), int(question[show_round].people3), int(question[show_round].people4)] + let question_values = [int(question[show_round].answer[0]), int(question[show_round].answer[1]), int(question[show_round].answer[2]), int(question[show_round].answer[3])] + let people_values = [int(question[show_round].people[0]), int(question[show_round].people[1]), int(question[show_round].people[2]), int(question[show_round].people[3])] let index = question_values.indexOf(i); - console.log(index) if (index !== -1) { return people_values[index]; } else { diff --git a/flask/testapp/views.py b/flask/testapp/views.py index 6293cfc..eb1de1d 100644 --- a/flask/testapp/views.py +++ b/flask/testapp/views.py @@ -6,7 +6,7 @@ user_score = {} # playerの数 -MAX_PLAYER = 4 +MAX_PLAYER = 3 # 何位まで表示するか(nemoto) max_order = 5 @@ -19,6 +19,8 @@ # ゲーム中の選択肢を保存 choices = [] +current_player = MAX_PLAYER + # 各回のゲーム結果を保存 frequent_table = "" @@ -44,6 +46,9 @@ if request.form.get("username"): # ユーザー名を取得し,ユーザー情報を登録 username = request.form.get("username") + if(user_number >= MAX_PLAYER): + return "Capasity ERROR" + user[user_number] = username print("Received name:", username, "UserNumber:", user_number) @@ -99,7 +104,9 @@ if data_count >= MAX_PLAYER: scores_order, user_number_order = calculate_order(data) print(scores_order, user_number_order) - order_table = create_order_table(scores_order, user_number_order, max_order) + order_table = create_order_table( + scores_order, user_number_order, max_order + ) return "WAIT" @@ -119,30 +126,52 @@ counter = Counter(get_data) get_frequent_table = "" # 最も多く出現する要素を取得する - most_common = counter.most_common() # 出現回数が多い順に要素とその出現回数のリストを取得 + most_common = ( + counter.most_common() + ) # 出現回数が多い順に要素とその出現回数のリストを取得 # 最も多く出現する要素 get_most_common_option = str(most_common[0][0]) get_most_common_count = str(most_common[0][1]) get_frequent_table += get_most_common_option + " " + get_most_common_count + "\n" # 2番目に多い要素 - get_second_most_common_option = str(most_common[1][0]) if len(most_common) > 1 else str(4) - get_second_most_common_count = str(most_common[1][1]) if len(most_common) > 1 else str(0) - get_frequent_table += get_second_most_common_option + " " + get_second_most_common_count + "\n" + get_second_most_common_option = ( + str(most_common[1][0]) if len(most_common) > 1 else str(4) + ) + get_second_most_common_count = ( + str(most_common[1][1]) if len(most_common) > 1 else str(0) + ) + get_frequent_table += ( + get_second_most_common_option + " " + get_second_most_common_count + "\n" + ) # 3番目に多い要素 - get_third_most_common_option = str(most_common[2][0]) if len(most_common) > 2 else str(4) - get_third_most_common_count = str(most_common[2][1]) if len(most_common) > 2 else str(0) - get_frequent_table += get_third_most_common_option + " " + get_third_most_common_count + "\n" + get_third_most_common_option = ( + str(most_common[2][0]) if len(most_common) > 2 else str(4) + ) + get_third_most_common_count = ( + str(most_common[2][1]) if len(most_common) > 2 else str(0) + ) + get_frequent_table += ( + get_third_most_common_option + " " + get_third_most_common_count + "\n" + ) # 4番目に多い要素 - get_fourth_most_common_option = str(most_common[3][0]) if len(most_common) > 3 else str(4) - get_fourth_most_common_count = str(most_common[3][1]) if len(most_common) > 3 else str(0) - get_frequent_table += get_fourth_most_common_option + " " + get_fourth_most_common_count + get_fourth_most_common_option = ( + str(most_common[3][0]) if len(most_common) > 3 else str(4) + ) + get_fourth_most_common_count = ( + str(most_common[3][1]) if len(most_common) > 3 else str(0) + ) + get_frequent_table += ( + get_fourth_most_common_option + " " + get_fourth_most_common_count + ) return get_frequent_table # ランキング上位の計算 def calculate_order(get_data): - get_sorted_numbers_with_indices = sorted(enumerate(get_data), key=lambda x: x[1], reverse=True) + get_sorted_numbers_with_indices = sorted( + enumerate(get_data), key=lambda x: x[1], reverse=True + ) get_scores = [item[1] for item in get_sorted_numbers_with_indices] get_labels = [item[0] for item in get_sorted_numbers_with_indices] @@ -161,7 +190,16 @@ for i in range(max): if i + j >= max: # 参照する配列がこれ以上ない時 break - order_table += str(i + 1 + j) + "位" + " " + user[int(labels[i + j])] + " " + str(scores[i + j]) + "pt" + "\n" + order_table += ( + str(i + 1 + j) + + "位" + + " " + + user[int(labels[i + j])] + + " " + + str(scores[i + j]) + + "pt" + + "\n" + ) now_order = i + 1 + j # 今の順位 if i + j + 1 == max: # 先ほどorder_tableに挿入した配列が,最後であった時 break @@ -169,7 +207,14 @@ while str(scores[i + j]) == str(scores[i + 1 + j]): j += 1 order_table += ( - str(now_order) + "位" + " " + user[int(labels[i + j])] + " " + str(scores[i + j]) + "pt" + "\n" + str(now_order) + + "位" + + " " + + user[int(labels[i + j])] + + " " + + str(scores[i + j]) + + "pt" + + "\n" ) if i + j + 1 >= max: # (i+j)と比較する配列(i+j+1)がない時 break