diff --git a/flask/testapp/static/javascript/beautyVote.js b/flask/testapp/static/javascript/beautyVote.js index 9732288..9c0e218 100644 --- a/flask/testapp/static/javascript/beautyVote.js +++ b/flask/testapp/static/javascript/beautyVote.js @@ -30,7 +30,7 @@ calcScore(){ var score = 0; for(var i = 0; i < MAX_ROUND; i ++){ - score += int(this.points[i]); + score += this.points[i]; } return score; } @@ -173,11 +173,11 @@ if(player.choice == question[round].answer[i]){ // 未選択を選んだ場合 if(player.choice == E){ - player.points[round] = String(0); + player.points[round] = 0; break; } else{ - player.points[round] = String(4-i+j); + player.points[round] = 4-i+j; } break; } diff --git a/flask/testapp/views.py b/flask/testapp/views.py index eb1de1d..028b5ef 100644 --- a/flask/testapp/views.py +++ b/flask/testapp/views.py @@ -46,9 +46,9 @@ if request.form.get("username"): # ユーザー名を取得し,ユーザー情報を登録 username = request.form.get("username") - if(user_number >= MAX_PLAYER): + if user_number >= MAX_PLAYER: return "Capasity ERROR" - + user[user_number] = username print("Received name:", username, "UserNumber:", user_number) @@ -104,9 +104,7 @@ 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" @@ -126,52 +124,30 @@ 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] @@ -190,16 +166,7 @@ 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 @@ -207,14 +174,7 @@ 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