Add informations to the history
This commit is contained in:
8
back/prisma/migrations/20230523091443_/migration.sql
Normal file
8
back/prisma/migrations/20230523091443_/migration.sql
Normal file
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- Added the required column `info` to the `SongHistory` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "SongHistory" ADD COLUMN "info" JSONB NOT NULL;
|
||||
@@ -67,6 +67,7 @@ model SongHistory {
|
||||
user User @relation(fields: [userID], references: [id], onDelete: Cascade, onUpdate: Cascade)
|
||||
userID Int
|
||||
score Int
|
||||
info Json
|
||||
difficulties Json
|
||||
playDate DateTime @default(now())
|
||||
}
|
||||
|
||||
@@ -16,4 +16,7 @@ export class SongHistoryDto {
|
||||
|
||||
@ApiProperty()
|
||||
difficulties: Record<string, number>
|
||||
|
||||
@ApiProperty()
|
||||
info: Record<string, number>
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ export class HistoryService {
|
||||
songID,
|
||||
userID,
|
||||
score,
|
||||
info,
|
||||
difficulties,
|
||||
}: SongHistoryDto): Promise<SongHistory> {
|
||||
await this.prisma.user.update({
|
||||
@@ -26,6 +27,7 @@ export class HistoryService {
|
||||
data: {
|
||||
score,
|
||||
difficulties,
|
||||
info,
|
||||
song: {
|
||||
connect: {
|
||||
id: songID,
|
||||
|
||||
@@ -41,6 +41,7 @@ PRACTICE = 1
|
||||
class ScoroInfo(TypedDict):
|
||||
max_score: int
|
||||
score: int
|
||||
wrong: int
|
||||
missed: int
|
||||
perfect: int
|
||||
great: int
|
||||
@@ -65,6 +66,7 @@ class Scorometer:
|
||||
self.info: ScoroInfo = {
|
||||
"max_score": len(self.partition.notes) * 100,
|
||||
"score": 0,
|
||||
"wrong": 0,
|
||||
"missed": 0,
|
||||
"perfect": 0,
|
||||
"great": 0,
|
||||
@@ -105,10 +107,12 @@ class Scorometer:
|
||||
)
|
||||
if to_play:
|
||||
perf = self.getTimingScore(key, to_play)
|
||||
self.info[perf] += 1
|
||||
logging.debug({"note_on": f"{perf} on {message.note}"})
|
||||
self.send({"type": "timing", "id": message.id, "timing": perf})
|
||||
else:
|
||||
self.info["score"] -= 50
|
||||
self.info["missed"] += 1
|
||||
self.wrong_ids += [message.id]
|
||||
logging.debug({"note_on": f"wrong key {message.note}"})
|
||||
self.send({"type": "timing", "id": message.id, "timing": "wrong"})
|
||||
@@ -143,7 +147,6 @@ class Scorometer:
|
||||
if perf == "short" or perf == "long"
|
||||
else 50
|
||||
)
|
||||
to_play.done = True
|
||||
logging.debug({"note_off": f"{perf} on {message.note}"})
|
||||
self.send({"type": "duration", "id": message.id, "duration": perf})
|
||||
else:
|
||||
@@ -184,6 +187,7 @@ class Scorometer:
|
||||
if message.id in self.wrong_ids:
|
||||
logging.debug({"note_off": f"wrong key {message.note}"})
|
||||
self.send({"type": "duration", "id": message.id, "duration": "wrong"})
|
||||
self.info["wrong"] += 1;
|
||||
return
|
||||
key = Key(
|
||||
key=message.note, start=down_since, duration=(message.time - down_since)
|
||||
@@ -295,6 +299,7 @@ class Scorometer:
|
||||
"songID": self.song_id,
|
||||
"userID": self.user_id,
|
||||
"score": self.info["score"],
|
||||
"info": self.info,
|
||||
"difficulties": self.difficulties,
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user