practice scoro rework

This commit is contained in:
GitBluub
2024-01-15 02:56:50 +01:00
committed by Clément Le Bihan
parent 8c2a53aa41
commit b80167001f

View File

@@ -88,7 +88,7 @@ class Scorometer:
self.practice_partition: list[list[Key]] = self.getPracticePartition(mode) self.practice_partition: list[list[Key]] = self.getPracticePartition(mode)
# the log generated is so long that it's longer than the stderr buffer resulting in a crash # the log generated is so long that it's longer than the stderr buffer resulting in a crash
# logging.debug({"partition": self.partition.notes}) # logging.debug({"partition": self.partition.notes})
self.keys_down = [] self.keys_down: list[Key] = []
self.mode: int = mode self.mode: int = mode
self.song_id: int = song_id self.song_id: int = song_id
self.user_id: int = user_id self.user_id: int = user_id
@@ -106,6 +106,11 @@ class Scorometer:
"max_streak": 0, "max_streak": 0,
} }
# Practice variables
self.to_play = set([x.key for x in self.practice_partition.pop(0)])
self.keys_down_practice: set = set()
def send(self, obj): def send(self, obj):
obj["info"] = self.info obj["info"] = self.info
obj["game_id"] = str(game_uuid) if not testing else "test" obj["game_id"] = str(game_uuid) if not testing else "test"
@@ -195,11 +200,20 @@ class Scorometer:
logging.warning("note_off: no key to play but it was not a wrong note_on") logging.warning("note_off: no key to play but it was not a wrong note_on")
def handleNoteOnPractice(self, message: NoteOnMessage): def handleNoteOnPractice(self, message: NoteOnMessage):
is_down = any(x[0] == message.note for x in self.keys_down) #is_down = any(x[0] == message.note for x in self.keys_down)
logging.debug({"note_on": message.note}) logging.debug({"note_on": message.note})
if is_down: #if is_down:
return # return
self.keys_down.append((message.note, message.time)) #self.keys_down.append((message.note, message.time))
self.keys_down_practice.add(message.note)
if self.to_play == self.keys_down_practice:
self.send({"type": "step", "message": "Good"})
if len(self.practice_partition) == 0:
self.endGamePractice()
self.to_play = set([x.key for x in self.practice_partition.pop(0)])
'''
self.to_play
key = Key(key=message.note, start=message.time, duration=0) key = Key(key=message.note, start=message.time, duration=0)
keys_to_play = next( keys_to_play = next(
(i for i in self.practice_partition if any(x.done is not True for x in i)), (i for i in self.practice_partition if any(x.done is not True for x in i)),
@@ -221,9 +235,12 @@ class Scorometer:
logging.debug({"note_on": f"wrong key {message.note}"}) logging.debug({"note_on": f"wrong key {message.note}"})
self.info["current_streak"] = 0 self.info["current_streak"] = 0
self.send({"type": "timing", "id": message.id, "timing": "wrong"}) self.send({"type": "timing", "id": message.id, "timing": "wrong"})
'''
def handleNoteOffPractice(self, message: NoteOffMessage): def handleNoteOffPractice(self, message: NoteOffMessage):
logging.debug({"note_off": message.note}) logging.debug({"note_off": message.note})
self.keys_down_practice.remove(message.note)
'''
down_since = next( down_since = next(
since for (h_key, since) in self.keys_down if h_key == message.note since for (h_key, since) in self.keys_down if h_key == message.note
) )
@@ -256,6 +273,7 @@ class Scorometer:
self.send({"type": "duration", "id": message.id, "duration": perf}) self.send({"type": "duration", "id": message.id, "duration": perf})
else: else:
self.send({"type": "duration", "id": message.id, "duration": "wrong"}) self.send({"type": "duration", "id": message.id, "duration": "wrong"})
'''
def getDurationScore(self, key: Key, to_play: Key): def getDurationScore(self, key: Key, to_play: Key):
tempo_percent = abs((key.duration / to_play.duration) - 1) tempo_percent = abs((key.duration / to_play.duration) - 1)
@@ -345,6 +363,17 @@ class Scorometer:
headers=auth_header headers=auth_header
) )
exit() exit()
def endGamePractice(self):
send(
{
"type": "end",
#"overallScore": self.info["score"],
#"precision": round(((self.info["perfect"] + self.info["great"] + self.info["good"]) / (len(self.partition.notes) + self.info["wrong"]) * 100), 2),
#"score": self.info,
}
)
exit()
def handleStartMessage(start_message: StartMessage): def handleStartMessage(start_message: StartMessage):