Compare commits
2 Commits
Author | SHA1 | Date |
---|---|---|
Nicolai Ort | 3909ed34f7 | |
Nicolai Ort | b2ac70e0ae |
|
@ -2,8 +2,15 @@
|
|||
|
||||
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)
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@odit/lfk-backend",
|
||||
"version": "0.15.2",
|
||||
"version": "0.15.3",
|
||||
"main": "src/app.ts",
|
||||
"repository": "https://git.odit.services/lfk/backend",
|
||||
"engines": {
|
||||
|
|
|
@ -22,13 +22,17 @@ export class StatsController {
|
|||
@OpenAPI({ description: "A very basic stats endpoint providing basic counters for a dashboard or simmilar" })
|
||||
async get() {
|
||||
let connection = getConnection();
|
||||
let runners = await connection.getRepository(Runner).find({ relations: ['scans', 'scans.track'] });
|
||||
let teams = await connection.getRepository(RunnerTeam).find();
|
||||
let orgs = await connection.getRepository(RunnerOrganization).find();
|
||||
let users = await connection.getRepository(User).find();
|
||||
let scans = await connection.getRepository(Scan).find();
|
||||
let runners = await connection.getRepository(Runner).count();
|
||||
let teams = await connection.getRepository(RunnerTeam).count();
|
||||
let orgs = await connection.getRepository(RunnerOrganization).count();
|
||||
let users = await connection.getRepository(User).count();
|
||||
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'] });
|
||||
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")
|
||||
|
|
|
@ -2,11 +2,6 @@ import {
|
|||
IsInt
|
||||
} from "class-validator";
|
||||
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 { 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 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[]) {
|
||||
this.total_runners = runners.length;
|
||||
this.total_teams = teams.length;
|
||||
this.total_orgs = orgs.length;
|
||||
this.total_users = users.length;
|
||||
this.total_scans = scans.filter(scan => { scan.valid === true }).length;
|
||||
this.total_distance = runners.reduce((sum, current) => sum + current.distance, 0);
|
||||
public constructor(runners: number, teams: number, orgs: number, users: number, scans: number, donations: Donation[], distance: number) {
|
||||
this.total_runners = runners;
|
||||
this.total_teams = teams;
|
||||
this.total_orgs = orgs;
|
||||
this.total_users = users;
|
||||
this.total_scans = scans;
|
||||
this.total_distance = distance;
|
||||
this.total_donation = donations.reduce((sum, current) => sum + current.amount, 0);
|
||||
this.average_distance = this.total_distance / this.total_runners;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue