idz: TA world record fixes

This commit is contained in:
Tau
2019-11-06 17:28:30 -05:00
parent a3705730ce
commit af8cdf3072
6 changed files with 23 additions and 9 deletions
+5 -1
View File
@@ -11,12 +11,16 @@ import { generateId } from "../../db";
export class SqlTimeAttackRepository implements TimeAttackRepository {
constructor(private readonly _conn: ClientBase) {}
async loadTopTen(routeNo: RouteNo): Promise<TopTenResult[]> {
async loadTopTen(
routeNo: RouteNo,
minTimestamp: Date
): Promise<TopTenResult[]> {
const loadSql = sql
.select("p.name", "ta.*")
.from("idz.ta_best ta")
.join("idz.profile p", { "ta.profile_id": "p.id" })
.where("ta.route_no", routeNo)
.where(sql.gt("ta.timestamp", minTimestamp))
.orderBy(["ta.total_time asc", "ta.timestamp asc"])
.limit(10)
.toParams();
+1 -1
View File
@@ -16,7 +16,7 @@ export function loadTopTen1(buf: Buffer): LoadTopTenRequest {
for (let i = 0; i < 32; i++) {
selectors.push({
routeNo: (buf.readUInt16LE(0x0004 + 2 * i) >> 1) as RouteNo,
field_44: buf.readUInt32LE(0x0044 + 4 * i),
minTimestamp: new Date(buf.readUInt32LE(0x0044 + 4 * i) * 1000 + 1000),
});
}
+1 -1
View File
@@ -16,7 +16,7 @@ export function loadTopTen2(buf: Buffer): LoadTopTenRequest {
for (let i = 0; i < 40; i++) {
selectors.push({
routeNo: (buf.readUInt16LE(0x0004 + 2 * i) >> 1) as RouteNo,
field_44: buf.readUInt32LE(0x0054 + 4 * i),
minTimestamp: new Date(buf.readUInt32LE(0x0054 + 4 * i) * 1000 + 1000),
});
}
+11 -4
View File
@@ -4,7 +4,7 @@ import {
LoadTopTenResponseCourse,
LoadTopTenResponseRow,
} from "../response/loadTopTen";
import { Repositories } from "../repo";
import { Repositories, TopTenResult } from "../repo";
export async function loadTopTen(
w: Repositories,
@@ -17,12 +17,19 @@ export async function loadTopTen(
break;
}
if (selector.field_44 === 0) {
const { routeNo, minTimestamp } = selector;
let src: TopTenResult[];
if (req.teamId !== undefined) {
src = []; // TODO
} else {
src = await w.timeAttack().loadTopTen(routeNo, minTimestamp);
}
if (src.length === 0) {
continue;
}
const { routeNo } = selector;
const src = await w.timeAttack().loadTopTen(routeNo);
const dest = new Array<LoadTopTenResponseRow>();
for (const srcItem of src) {
+4 -1
View File
@@ -72,7 +72,10 @@ export interface TopTenResult {
}
export interface TimeAttackRepository {
loadTopTen(routeNo: Model.RouteNo): Promise<TopTenResult[]>;
loadTopTen(
routeNo: Model.RouteNo,
minTimestamp: Date
): Promise<TopTenResult[]>;
loadAll(
profileId: Model.ExtId<Model.Profile>
+1 -1
View File
@@ -4,7 +4,7 @@ import { Team } from "../model/team";
export interface LoadTopTenRequestSelector {
routeNo: RouteNo;
field_44: number;
minTimestamp: Date;
}
export interface LoadTopTenRequest {