Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
3909ed34f7
|
|||
|
b2ac70e0ae
|
|||
|
5f17e7f783
|
|||
|
a5a56a263a
|
|||
|
2d8f7528d9
|
|||
|
9581185b24
|
|||
|
2905884c02
|
|||
|
e9914e317b
|
|||
|
702070da66
|
24
CHANGELOG.md
24
CHANGELOG.md
@@ -2,9 +2,33 @@
|
|||||||
|
|
||||||
All notable changes to this project will be documented in this file. Dates are displayed in UTC.
|
All notable changes to this project will be documented in this file. Dates are displayed in UTC.
|
||||||
|
|
||||||
|
#### [v0.15.3](https://git.odit.services/lfk/backend/compare/v0.15.2...v0.15.3)
|
||||||
|
|
||||||
|
- Faster stats (not including donations) [`b2ac70e`](https://git.odit.services/lfk/backend/commit/b2ac70e0aec1064e54a5043a104e7892984b2338)
|
||||||
|
|
||||||
|
#### [v0.15.2](https://git.odit.services/lfk/backend/compare/v0.15.1...v0.15.2)
|
||||||
|
|
||||||
|
> 15 April 2023
|
||||||
|
|
||||||
|
- 🚀Bumped version to v0.15.2 [`5f17e7f`](https://git.odit.services/lfk/backend/commit/5f17e7f783a7e8e2efc8f7dbbf2c98bcd1d80240)
|
||||||
|
- Don't resolve runner group and parten with get all card requests [`2d8f752`](https://git.odit.services/lfk/backend/commit/2d8f7528d98144832e7609f5aa6fac8de4723c4a)
|
||||||
|
- Resolve groups again for card generation [`a5a56a2`](https://git.odit.services/lfk/backend/commit/a5a56a263a01dbd911a799ab57084166e17b80ac)
|
||||||
|
|
||||||
|
#### [v0.15.1](https://git.odit.services/lfk/backend/compare/v0.15.0...v0.15.1)
|
||||||
|
|
||||||
|
> 15 April 2023
|
||||||
|
|
||||||
|
- 🚀Bumped version to v0.15.1 [`9581185`](https://git.odit.services/lfk/backend/commit/9581185b24039338e7f238ecdcc3881bb5203759)
|
||||||
|
- Faster trackscan creation by only loading the latest scan [`e9914e3`](https://git.odit.services/lfk/backend/commit/e9914e317b7fd78863cfd8549bad65da9292b7ca)
|
||||||
|
- Log batch time in mass scan script [`2905884`](https://git.odit.services/lfk/backend/commit/2905884c024d7f275b3ad2c2858a2f0911adb95b)
|
||||||
|
- Dont load cards with get all runners request [`702070d`](https://git.odit.services/lfk/backend/commit/702070da669cc605b93e6f5b62d712c28f079dd0)
|
||||||
|
|
||||||
#### [v0.15.0](https://git.odit.services/lfk/backend/compare/v0.14.6...v0.15.0)
|
#### [v0.15.0](https://git.odit.services/lfk/backend/compare/v0.14.6...v0.15.0)
|
||||||
|
|
||||||
|
> 15 April 2023
|
||||||
|
|
||||||
- Added test script for creating mass scans [`8007117`](https://git.odit.services/lfk/backend/commit/80071174342d87199fcbd981cd8c92300b0a51e4)
|
- Added test script for creating mass scans [`8007117`](https://git.odit.services/lfk/backend/commit/80071174342d87199fcbd981cd8c92300b0a51e4)
|
||||||
|
- 🚀Bumped version to v0.15.0 [`cc89ba8`](https://git.odit.services/lfk/backend/commit/cc89ba8afb3120569613a889baf962555612e95a)
|
||||||
- Get all scans speed improvement [`23fa78e`](https://git.odit.services/lfk/backend/commit/23fa78eb9dcc01ecc036347f6703aacc0d163d7d)
|
- Get all scans speed improvement [`23fa78e`](https://git.odit.services/lfk/backend/commit/23fa78eb9dcc01ecc036347f6703aacc0d163d7d)
|
||||||
- More scan request optimizations [`7c4ff42`](https://git.odit.services/lfk/backend/commit/7c4ff42a3b3e7b186e16c85a97d9ecc854a32cb0)
|
- More scan request optimizations [`7c4ff42`](https://git.odit.services/lfk/backend/commit/7c4ff42a3b3e7b186e16c85a97d9ecc854a32cb0)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@odit/lfk-backend",
|
"name": "@odit/lfk-backend",
|
||||||
"version": "0.15.0",
|
"version": "0.15.3",
|
||||||
"main": "src/app.ts",
|
"main": "src/app.ts",
|
||||||
"repository": "https://git.odit.services/lfk/backend",
|
"repository": "https://git.odit.services/lfk/backend",
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Authorized, Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put, QueryParam } from 'routing-controllers';
|
import { Authorized, Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put, QueryParam } from 'routing-controllers';
|
||||||
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||||
import { getConnectionManager, Repository } from 'typeorm';
|
import { Repository, getConnectionManager } from 'typeorm';
|
||||||
import { RunnerCardHasScansError, RunnerCardIdsNotMatchingError, RunnerCardNotFoundError } from '../errors/RunnerCardErrors';
|
import { RunnerCardHasScansError, RunnerCardIdsNotMatchingError, RunnerCardNotFoundError } from '../errors/RunnerCardErrors';
|
||||||
import { RunnerNotFoundError } from '../errors/RunnerErrors';
|
import { RunnerNotFoundError } from '../errors/RunnerErrors';
|
||||||
import { CreateRunnerCard } from '../models/actions/create/CreateRunnerCard';
|
import { CreateRunnerCard } from '../models/actions/create/CreateRunnerCard';
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Authorized, Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put, QueryParam } from 'routing-controllers';
|
import { Authorized, Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put, QueryParam } from 'routing-controllers';
|
||||||
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||||
import { getConnectionManager, Repository } from 'typeorm';
|
import { Repository, getConnectionManager } from 'typeorm';
|
||||||
import { RunnerGroupNeededError, RunnerHasDistanceDonationsError, RunnerIdsNotMatchingError, RunnerNotFoundError } from '../errors/RunnerErrors';
|
import { RunnerGroupNeededError, RunnerHasDistanceDonationsError, RunnerIdsNotMatchingError, RunnerNotFoundError } from '../errors/RunnerErrors';
|
||||||
import { RunnerGroupNotFoundError } from '../errors/RunnerGroupErrors';
|
import { RunnerGroupNotFoundError } from '../errors/RunnerGroupErrors';
|
||||||
import { CreateRunner } from '../models/actions/create/CreateRunner';
|
import { CreateRunner } from '../models/actions/create/CreateRunner';
|
||||||
@@ -32,7 +32,7 @@ export class RunnerController {
|
|||||||
@OpenAPI({ description: 'Lists all runners from all teams/orgs. <br> This includes the runner\'s group and distance ran.' })
|
@OpenAPI({ description: 'Lists all runners from all teams/orgs. <br> This includes the runner\'s group and distance ran.' })
|
||||||
async getAll() {
|
async getAll() {
|
||||||
let responseRunners: ResponseRunner[] = new Array<ResponseRunner>();
|
let responseRunners: ResponseRunner[] = new Array<ResponseRunner>();
|
||||||
const runners = await this.runnerRepository.find({ relations: ['scans', 'group', 'group.parentGroup', 'scans.track', 'cards'] });
|
const runners = await this.runnerRepository.find({ relations: ['scans', 'group', 'group.parentGroup', 'scans.track'] });
|
||||||
runners.forEach(runner => {
|
runners.forEach(runner => {
|
||||||
responseRunners.push(new ResponseRunner(runner));
|
responseRunners.push(new ResponseRunner(runner));
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -22,13 +22,17 @@ export class StatsController {
|
|||||||
@OpenAPI({ description: "A very basic stats endpoint providing basic counters for a dashboard or simmilar" })
|
@OpenAPI({ description: "A very basic stats endpoint providing basic counters for a dashboard or simmilar" })
|
||||||
async get() {
|
async get() {
|
||||||
let connection = getConnection();
|
let connection = getConnection();
|
||||||
let runners = await connection.getRepository(Runner).find({ relations: ['scans', 'scans.track'] });
|
let runners = await connection.getRepository(Runner).count();
|
||||||
let teams = await connection.getRepository(RunnerTeam).find();
|
let teams = await connection.getRepository(RunnerTeam).count();
|
||||||
let orgs = await connection.getRepository(RunnerOrganization).find();
|
let orgs = await connection.getRepository(RunnerOrganization).count();
|
||||||
let users = await connection.getRepository(User).find();
|
let users = await connection.getRepository(User).count();
|
||||||
let scans = await connection.getRepository(Scan).find();
|
let scans = await connection.getRepository(Scan).count({ where: { valid: true } });
|
||||||
|
let distance_query = await connection.getRepository(Scan).createQueryBuilder('scan')
|
||||||
|
.leftJoinAndSelect("scan.track", "track").where("scan.valid = TRUE")
|
||||||
|
.select("SUM(track.distance)", "sum_track").addSelect("SUM(_distance)", "sum_distance")
|
||||||
|
.getRawOne();
|
||||||
let donations = await connection.getRepository(Donation).find({ relations: ['runner', 'runner.scans', 'runner.scans.track'] });
|
let donations = await connection.getRepository(Donation).find({ relations: ['runner', 'runner.scans', 'runner.scans.track'] });
|
||||||
return new ResponseStats(runners, teams, orgs, users, scans, donations)
|
return new ResponseStats(runners, teams, orgs, users, scans, donations, distance_query.sum_track + distance_query.sum_distance)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get("/runners/distance")
|
@Get("/runners/distance")
|
||||||
|
|||||||
@@ -86,14 +86,13 @@ export class CreateTrackScan {
|
|||||||
* @returns The validated scan with it's laptime set.
|
* @returns The validated scan with it's laptime set.
|
||||||
*/
|
*/
|
||||||
public async validateScan(scan: TrackScan): Promise<TrackScan> {
|
public async validateScan(scan: TrackScan): Promise<TrackScan> {
|
||||||
const scans = await getConnection().getRepository(TrackScan).find({ where: { runner: scan.runner, valid: true }, relations: ["track"] });
|
const latestScan = await getConnection().getRepository(TrackScan).findOne({ where: { runner: scan.runner, valid: true }, relations: ["track"], order: { id: 'DESC' } });
|
||||||
if (scans.length == 0) {
|
if (!latestScan) {
|
||||||
scan.lapTime = 0;
|
scan.lapTime = 0;
|
||||||
scan.valid = true;
|
scan.valid = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const newestScan = scans[scans.length - 1];
|
scan.lapTime = scan.timestamp - latestScan.timestamp;
|
||||||
scan.lapTime = scan.timestamp - newestScan.timestamp;
|
|
||||||
scan.valid = (scan.lapTime > scan.track.minimumLapTime);
|
scan.valid = (scan.lapTime > scan.track.minimumLapTime);
|
||||||
}
|
}
|
||||||
return scan;
|
return scan;
|
||||||
|
|||||||
@@ -2,11 +2,6 @@ import {
|
|||||||
IsInt
|
IsInt
|
||||||
} from "class-validator";
|
} from "class-validator";
|
||||||
import { Donation } from '../entities/Donation';
|
import { Donation } from '../entities/Donation';
|
||||||
import { Runner } from '../entities/Runner';
|
|
||||||
import { RunnerOrganization } from '../entities/RunnerOrganization';
|
|
||||||
import { RunnerTeam } from '../entities/RunnerTeam';
|
|
||||||
import { Scan } from '../entities/Scan';
|
|
||||||
import { User } from '../entities/User';
|
|
||||||
import { ResponseObjectType } from '../enums/ResponseObjectType';
|
import { ResponseObjectType } from '../enums/ResponseObjectType';
|
||||||
import { IResponse } from './IResponse';
|
import { IResponse } from './IResponse';
|
||||||
|
|
||||||
@@ -78,13 +73,13 @@ export class ResponseStats implements IResponse {
|
|||||||
* @param scans Array containing all scans - no relations have to be resolved.
|
* @param scans Array containing all scans - no relations have to be resolved.
|
||||||
* @param donations Array containing all donations - the following relations have to be resolved: runner, runner.scans, runner.scans.track
|
* @param donations Array containing all donations - the following relations have to be resolved: runner, runner.scans, runner.scans.track
|
||||||
*/
|
*/
|
||||||
public constructor(runners: Runner[], teams: RunnerTeam[], orgs: RunnerOrganization[], users: User[], scans: Scan[], donations: Donation[]) {
|
public constructor(runners: number, teams: number, orgs: number, users: number, scans: number, donations: Donation[], distance: number) {
|
||||||
this.total_runners = runners.length;
|
this.total_runners = runners;
|
||||||
this.total_teams = teams.length;
|
this.total_teams = teams;
|
||||||
this.total_orgs = orgs.length;
|
this.total_orgs = orgs;
|
||||||
this.total_users = users.length;
|
this.total_users = users;
|
||||||
this.total_scans = scans.filter(scan => { scan.valid === true }).length;
|
this.total_scans = scans;
|
||||||
this.total_distance = runners.reduce((sum, current) => sum + current.distance, 0);
|
this.total_distance = distance;
|
||||||
this.total_donation = donations.reduce((sum, current) => sum + current.amount, 0);
|
this.total_donation = donations.reduce((sum, current) => sum + current.amount, 0);
|
||||||
this.average_distance = this.total_distance / this.total_runners;
|
this.average_distance = this.total_distance / this.total_runners;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
console.time("batches")
|
||||||
for (let i = 0; i < 100; i++) {
|
for (let i = 0; i < 100; i++) {
|
||||||
const batch = [];
|
const batch = [];
|
||||||
for (let i = 0; i < 20; i++) {
|
for (let i = 0; i < 6; i++) {
|
||||||
batch.push(axios.post('http://localhost:4010/api/scans/trackscans', { card: 200000000001, station: 2 }, {
|
batch.push(axios.post('http://localhost:4010/api/scans/trackscans', { card: 200000000001, station: 2 }, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: 'Bearer 10F2E64.BB4F6CC5-2148-4CCF-88B5-0AA85D0508A9'
|
Authorization: 'Bearer 10F2E64.BB4F6CC5-2148-4CCF-88B5-0AA85D0508A9'
|
||||||
@@ -11,7 +12,8 @@ async function main() {
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
await Promise.all(batch)
|
await Promise.all(batch)
|
||||||
console.log(`Finished batch ${i}`)
|
console.timeLog("batches", `Finished batch ${i}`)
|
||||||
}
|
}
|
||||||
|
console.timeEnd("batches")
|
||||||
}
|
}
|
||||||
main();
|
main();
|
||||||
Reference in New Issue
Block a user