This commit is contained in:
GitBluub
2023-03-03 22:12:15 +09:00
committed by Bluub
parent b9513ad154
commit 9d74673cff
5 changed files with 50 additions and 10 deletions

View File

@@ -11,6 +11,9 @@ import operator
import json
from mido import MidiFile
BACK_URL = os.environ.get('BACK_URL') or "http://back:3000"
MUSICS_FOLDER = os.environ.get('MUSICS_FOLDER') or "/musics/"
RATIO = float(sys.argv[2] if len(sys.argv) > 2 else 1)
OCTAVE = 5
OCTAVE_AMOUNT_KEYS = 12
@@ -193,13 +196,13 @@ def handleStartMessage(start_message):
song_id = start_message["id"]
# TODO: use something secure here but I don't find sending a jwt something elegant.
user_id = start_message["user_id"]
song_path = requests.get(f"http://back:3000/song/{song_id}").json()["midiPath"]
song_path = requests.get(f"{BACK_URL}/song/{song_id}").json()["midiPath"];song_path = song_path.replace("/musics/", MUSICS_FOLDER)
return mode, song_path, song_id, user_id
def sendScore(score, difficulties, song_id, user_id):
send({"overallScore": score, "score": difficulties})
requests.post(f"http://back:3000/history", json={
requests.post(f"{BACK_URL}/history", json={
"songID": song_id,
"userID": user_id,
"score": score,

View File

@@ -1,2 +1,23 @@
{"type":"start", "id": 1, "mode": "normal", "user_id": 1}
{"type": "note_on", "id": 1, "time": 3500, "note": 68}
{"type": "note_off", "id": 1, "time": 3740, "note": 68}
{"type": "note_on", "id": 2, "time": 3750, "note": 67}
{"type": "note_off", "id": 2, "time": 3980, "note": 67}
{"type": "note_on", "id": 3, "time": 4000, "note": 62}
{"type": "note_off", "id": 3, "time": 4240, "note": 62}
{"type": "note_on", "id": 4, "time": 4000, "note": 64}
{"type": "note_off", "id": 4, "time": 4240, "note": 64}
{"type": "note_on", "id": 5, "time": 4000, "note": 60}
{"type": "note_off", "id": 5, "time": 4240, "note": 60}
{"type": "note_on", "id": 6, "time": 4500, "note": 63}
{"type": "note_off", "id": 6, "time": 4740, "note": 63}
{"type": "note_on", "id": 7, "time": 4750, "note": 63}
{"type": "note_off", "id": 7, "time": 4980, "note": 63}
{"type": "note_on", "id": 8, "time": 5000, "note": 63}
{"type": "note_off", "id": 8, "time": 5990, "note": 63}
{"type": "note_on", "id": 9, "time": 6500, "note": 62}
{"type": "note_off", "id": 9, "time": 6990, "note": 62}
{"type": "note_on", "id": 10, "time": 6750, "note": 60}
{"type": "note_off", "id": 10, "time": 7240, "note": 60}
{}

View File

@@ -1,2 +1,11 @@
wowoa
{"id": 1, "timingScore": "perfect", "timingInformation": "perfect"}
{"id": 2, "timingScore": "perfect", "timingInformation": "perfect"}
{"id": 3, "timingScore": "perfect", "timingInformation": "perfect"}
{"id": 4, "timingScore": "perfect", "timingInformation": "perfect"}
{"id": 5, "timingScore": "perfect", "timingInformation": "perfect"}
{"id": 6, "timingScore": "perfect", "timingInformation": "perfect"}
{"id": 7, "timingScore": "perfect", "timingInformation": "perfect"}
{"id": 8, "timingScore": "perfect", "timingInformation": "perfect"}
{"id": 9, "timingScore": "perfect", "timingInformation": "perfect"}
{"id": 10, "timingScore": "perfect", "timingInformation": "perfect"}
{"overallScore": 1000, "score": {}}

View File

@@ -1,13 +1,20 @@
#!/bin/sh
EMPTY_DB=$(curl localhost:3000/song/1 -s | jq '.statusCode == 404')
if [[ $EMPTY_DB == "true" ]]; then
curl localhost:3000/song -X POST --data '{"name": "SCORO_TEST", "difficulties": {}, "midiPath": "/musics/SCORO_TEST/SCORO_TEST.midi", "musicXmlPath": "/musics/SCORO_TEST/SCORO_TEST.mxl"}' -H "Content-Type: application/json" &> /dev/null
fi
TESTS_DONE=0
TESTS_SUCCESS=0
TESTS_FAILED=0
function test {
cat $1/input | python3 ../main.py &> /tmp/scorometer_res
cat $1/input | BACK_URL="http://localhost:3000" MUSICS_FOLDER="../../musics/" python3 ../main.py | grep -v '"type": "log"' &> /tmp/scorometer_res
TESTS_DONE=$((TESTS_DONE + 1))
if ! diff $1/output /tmp/scorometer_res &>/dev/null; then
echo "$t failed, do runner.sh $t for more info"
TESTS_FAILED=$((TESTS_FAILED + 1))
else
TESTS_SUCCESS=$((TESTS_SUCCESS + 1))
fi
@@ -18,18 +25,18 @@ then
for t in */; do
test $t
done
echo "$TESTS_SUCCESS succeeded"
echo "$TESTS_DONE done"
exit $TESTS_FAILED
else
cat $1/input | python3 ../main.py &> /tmp/scorometer_res
cho "=========== CURRENT OUTPUT ==========="
cat $1/input | BACK_URL="http://localhost:3000" MUSICS_FOLDER="../../musics/" python3 ../main.py | grep -v '"type": "log"' &> /tmp/scorometer_res
echo "=========== CURRENT OUTPUT ==========="
cat /tmp/scorometer_res
echo "======================================"
echo "=========== EXPECTED OUTPUT =========="
cat $1/output
echo "======================================"
echo "=============== DIFF ================="
diff --side-by-side /tmp/scorometer_res $1/output
RET=$(diff --side-by-side -q /tmp/scorometer_res $1/output)
echo "======================================"
exit $RET
fi;

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB