Add informations to the history

This commit is contained in:
2023-05-23 18:23:11 +09:00
parent 155e6f49af
commit b1d2027d4b
5 changed files with 20 additions and 1 deletions

View 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;

View File

@@ -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())
}

View File

@@ -16,4 +16,7 @@ export class SongHistoryDto {
@ApiProperty()
difficulties: Record<string, number>
@ApiProperty()
info: Record<string, number>
}

View File

@@ -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,

View File

@@ -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,
},
)