🐛 Fixes #107
This commit is contained in:
@@ -42,6 +42,7 @@ black = "*"
|
|||||||
pytest-dependency = "*"
|
pytest-dependency = "*"
|
||||||
pytest-order = "*"
|
pytest-order = "*"
|
||||||
pre-commit = "*"
|
pre-commit = "*"
|
||||||
|
python-socketio = {extras = ["client"], version = "*"}
|
||||||
|
|
||||||
[requires]
|
[requires]
|
||||||
python_version = "3.10"
|
python_version = "3.10"
|
||||||
|
|||||||
Generated
+648
-549
File diff suppressed because it is too large
Load Diff
@@ -32,10 +32,9 @@
|
|||||||
);
|
);
|
||||||
|
|
||||||
function sortObjectbyValue(obj) {
|
function sortObjectbyValue(obj) {
|
||||||
const asc = false;
|
|
||||||
const ret = {};
|
const ret = {};
|
||||||
Object.keys(obj)
|
Object.keys(obj)
|
||||||
.sort((a, b) => obj[asc ? a : b] - obj[asc ? b : a])
|
.sort((a, b) => obj[b] - obj[a])
|
||||||
.forEach((s) => (ret[s] = obj[s]));
|
.forEach((s) => (ret[s] = obj[s]));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -56,9 +55,18 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
winners_arr = Object.keys(winners);
|
|
||||||
|
let close_to_res = sortObjectbyValue(winners);
|
||||||
|
winners_arr = [];
|
||||||
|
for (const i in close_to_res) {
|
||||||
|
winners_arr.push([i, close_to_res[i]]);
|
||||||
|
}
|
||||||
|
|
||||||
|
winners_arr = winners_arr.sort(function (a, b) {
|
||||||
|
return b[1] - a[1];
|
||||||
|
});
|
||||||
data_available = true;
|
data_available = true;
|
||||||
return sortObjectbyValue(winners);
|
return close_to_res;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
data_available = false;
|
data_available = false;
|
||||||
}
|
}
|
||||||
@@ -75,10 +83,10 @@
|
|||||||
<div class="flex mx-auto w-fit flex-col pt-8 gap-2">
|
<div class="flex mx-auto w-fit flex-col pt-8 gap-2">
|
||||||
<div>
|
<div>
|
||||||
<p class="text-3xl text-center">
|
<p class="text-3xl text-center">
|
||||||
{$t('play_page.1st_place')}: <span class="underline">{winners_arr[0]}</span>
|
{$t('play_page.1st_place')}: <span class="underline">{winners_arr[0][0]}</span>
|
||||||
<span
|
<span
|
||||||
>{$t('play_page.with_out_of', {
|
>{$t('play_page.with_out_of', {
|
||||||
correct_questions: winners[winners_arr[0]] ?? 0,
|
correct_questions: winners_arr[0][1] ?? 0,
|
||||||
total_question_count: quiz_data.questions.length
|
total_question_count: quiz_data.questions.length
|
||||||
})}</span
|
})}</span
|
||||||
>
|
>
|
||||||
@@ -87,10 +95,11 @@
|
|||||||
{#if winners_arr.length >= 2}
|
{#if winners_arr.length >= 2}
|
||||||
<div>
|
<div>
|
||||||
<p class="text-2xl text-center">
|
<p class="text-2xl text-center">
|
||||||
{$t('play_page.2nd_place')}: <span class="underline">{winners_arr[1]}</span>
|
{$t('play_page.2nd_place')}:
|
||||||
|
<span class="underline">{winners_arr[1][0]}</span>
|
||||||
<span
|
<span
|
||||||
>{$t('play_page.with_out_of', {
|
>{$t('play_page.with_out_of', {
|
||||||
correct_questions: winners[winners_arr[1]] ?? 0,
|
correct_questions: winners_arr[1][1] ?? 0,
|
||||||
total_question_count: quiz_data.questions.length
|
total_question_count: quiz_data.questions.length
|
||||||
})}</span
|
})}</span
|
||||||
>
|
>
|
||||||
@@ -100,10 +109,11 @@
|
|||||||
{#if winners_arr.length >= 3}
|
{#if winners_arr.length >= 3}
|
||||||
<div>
|
<div>
|
||||||
<p class="text-xl text-center">
|
<p class="text-xl text-center">
|
||||||
{$t('play_page.3rd place')}: <span class="underline">{winners_arr[2]}</span>
|
{$t('play_page.3rd place')}:
|
||||||
|
<span class="underline">{winners_arr[2][0]}</span>
|
||||||
<span>
|
<span>
|
||||||
{$t('play_page.with_out_of', {
|
{$t('play_page.with_out_of', {
|
||||||
correct_questions: winners[winners_arr[2]] ?? 0,
|
correct_questions: winners_arr[2][1] ?? 0,
|
||||||
total_question_count: quiz_data.questions.length
|
total_question_count: quiz_data.questions.length
|
||||||
})}
|
})}
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
import json
|
||||||
|
import random
|
||||||
|
import time
|
||||||
|
|
||||||
|
import socketio
|
||||||
|
|
||||||
|
NUMBER_OF_PLAYERS = 20
|
||||||
|
GAME_PIN = 35490014
|
||||||
|
quiz = [None]
|
||||||
|
|
||||||
|
|
||||||
|
def __main__():
|
||||||
|
arr_of_sio_instances = []
|
||||||
|
for i in range(NUMBER_OF_PLAYERS):
|
||||||
|
arr_of_sio_instances.append(socketio.Client())
|
||||||
|
|
||||||
|
def joined_game(data):
|
||||||
|
print("JOINED!!!!")
|
||||||
|
print(data)
|
||||||
|
quiz[0] = json.loads(data)
|
||||||
|
print(type(quiz[0]))
|
||||||
|
|
||||||
|
def set_question_number(data):
|
||||||
|
for i in arr_of_sio_instances:
|
||||||
|
# print(int(data))
|
||||||
|
# print("hi!", data)
|
||||||
|
random_num = random.randint(0, len(quiz[0]["questions"][int(data)]["answers"]) - 1)
|
||||||
|
print(random_num)
|
||||||
|
i.emit(
|
||||||
|
"submit_answer",
|
||||||
|
{
|
||||||
|
"question_index": int(data),
|
||||||
|
"answer": quiz[0]["questions"][int(data)]["answers"][random_num]["answer"],
|
||||||
|
},
|
||||||
|
)
|
||||||
|
print(i.sid)
|
||||||
|
time.sleep(0.1)
|
||||||
|
print("Everyone answered!")
|
||||||
|
|
||||||
|
for i in arr_of_sio_instances:
|
||||||
|
i.connect("http://localhost:8080/socket.io/")
|
||||||
|
|
||||||
|
arr_of_sio_instances[3].on("joined_game", joined_game)
|
||||||
|
arr_of_sio_instances[3].on("set_question_number", set_question_number)
|
||||||
|
for i in arr_of_sio_instances:
|
||||||
|
i.emit("join_game", {"username": random.randint(0, 30), "game_pin": GAME_PIN, "captcha": None})
|
||||||
|
time.sleep(0.1)
|
||||||
|
print("Everyone joined!")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
try:
|
||||||
|
__main__()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
exit(1)
|
||||||
Reference in New Issue
Block a user