Alpha Release 0.5.0 #153

Merged
niggl merged 30 commits from dev into main 2021-03-04 16:22:40 +00:00
2 changed files with 18 additions and 7 deletions
Showing only changes of commit aa833736d3 - Show all commits

View File

@ -44,6 +44,7 @@ export class CreateTrackScan {
} }
newScan.timestamp = Math.round(new Date().getTime() / 1000); newScan.timestamp = Math.round(new Date().getTime() / 1000);
newScan.lapTime = await this.getLaptime(newScan)
newScan.valid = await this.validateScan(newScan); newScan.valid = await this.validateScan(newScan);
return newScan; return newScan;
@ -65,15 +66,15 @@ export class CreateTrackScan {
return station; return station;
} }
public async validateScan(scan: TrackScan): Promise<boolean> { public validateScan(scan: TrackScan): boolean {
return (scan.lapTime > scan.track.minimumLapTime);
}
public async getLaptime(scan: TrackScan): Promise<number> {
const scans = await getConnection().getRepository(TrackScan).find({ where: { runner: scan.runner, valid: true }, relations: ["track"] }); const scans = await getConnection().getRepository(TrackScan).find({ where: { runner: scan.runner, valid: true }, relations: ["track"] });
if (scans.length == 0) { return true; } if (scans.length == 0) { return 0; }
const newestScan = scans[scans.length - 1]; const newestScan = scans[scans.length - 1];
if ((scan.timestamp - newestScan.timestamp) > scan.track.minimumLapTime) { return (scan.timestamp - newestScan.timestamp);
return true;
}
return false;
} }
} }

View File

@ -2,6 +2,8 @@ import {
IsInt, IsInt,
IsNotEmpty, IsNotEmpty,
IsNumber,
IsPositive IsPositive
} from "class-validator"; } from "class-validator";
import { ChildEntity, Column, ManyToOne } from "typeorm"; import { ChildEntity, Column, ManyToOne } from "typeorm";
@ -59,6 +61,14 @@ export class TrackScan extends Scan {
@IsInt() @IsInt()
timestamp: number; timestamp: number;
/**
* The scan's lap time.
* This simply get's calculated from the last lap time;
*/
@Column()
@IsNumber()
lapTime: number;
/** /**
* Turns this entity into it's response class. * Turns this entity into it's response class.
*/ */