mirror of
https://github.com/djhackersdev/minime.git
synced 2026-08-26 04:25:55 -05:00
chuni: Add recent rating response to fix rating calculation
This commit is contained in:
@@ -1,16 +1,22 @@
|
||||
import { Repositories } from "../repo";
|
||||
import { GetUserRecentRatingRequest } from "../request/getUserRecentRating";
|
||||
import { GetUserRecentRatingResponse } from "../response/getUserRecentRating";
|
||||
import { readAimeId } from "../proto/base";
|
||||
import { writeUserRecentRatingFromLog } from "../proto/userRecentRating";
|
||||
|
||||
export default async function getUserRecentRating(
|
||||
rep: Repositories,
|
||||
req: GetUserRecentRatingRequest
|
||||
): Promise<GetUserRecentRatingResponse> {
|
||||
// I don't really know what subset of data to return here.
|
||||
const aimeId = readAimeId(req.userId);
|
||||
|
||||
const profileId = await rep.userData().lookup(aimeId);
|
||||
// Return recent 30 plays to calculate rating
|
||||
const items = await rep.userPlaylog().loadLatest(profileId, 30);
|
||||
|
||||
return {
|
||||
userId: req.userId,
|
||||
length: "0",
|
||||
userRecentRatingList: [],
|
||||
length: items.length.toString(),
|
||||
userRecentRatingList: items.map(writeUserRecentRatingFromLog),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { UserPlaylogItem } from "./../model/userPlaylog";
|
||||
import { Crush, writeObject } from "./base";
|
||||
import { UserRecentRatingItem } from "../model/userRecentRating";
|
||||
|
||||
@@ -19,3 +20,15 @@ export function writeUserRecentRating(
|
||||
): UserRecentRatingJson {
|
||||
return writeObject(obj);
|
||||
}
|
||||
|
||||
export function writeUserRecentRatingFromLog(
|
||||
obj: UserPlaylogItem
|
||||
): UserRecentRatingJson {
|
||||
return {
|
||||
musicId: obj.musicId.toString(),
|
||||
difficultId: obj.level.toString(),
|
||||
// game version not saved in play log, just return a fixed version now
|
||||
romVersionCode: "1030000",
|
||||
score: obj.score.toString(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -7,4 +7,5 @@ export interface UserPlaylogRepository {
|
||||
// is nice to have.
|
||||
|
||||
save(profileId: Id<UserDataItem>, obj: UserPlaylogItem): Promise<void>;
|
||||
loadLatest(profileId: Id<UserDataItem>, size: number): Promise<UserPlaylogItem[]>;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import { UserPlaylogRepository } from "../repo/userPlaylog";
|
||||
import { Transaction } from "../../sql";
|
||||
import { T, createSqlMapper } from "../../sql/util";
|
||||
|
||||
const { writeRow } = createSqlMapper({
|
||||
const { readRow, writeRow } = createSqlMapper({
|
||||
orderId: T.number,
|
||||
sortNumber: T.number,
|
||||
placeId: T.number,
|
||||
@@ -72,4 +72,16 @@ export class SqlUserPlaylogRepository implements UserPlaylogRepository {
|
||||
|
||||
return this._txn.modify(stmt);
|
||||
}
|
||||
|
||||
async loadLatest(profileId: Id<UserDataItem>, size: number): Promise<UserPlaylogItem[]> {
|
||||
const stmt = sql
|
||||
.select("music_id", "score", "level","user_play_date")
|
||||
.from("cm_user_playlog")
|
||||
.where("profile_id", profileId)
|
||||
.limit(size).order("user_play_date DESC");
|
||||
|
||||
const rows = await this._txn.fetchRows(stmt);
|
||||
|
||||
return rows.map(readRow);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user