108 lines
3.1 KiB
TypeScript
108 lines
3.1 KiB
TypeScript
import {
|
|
IsInt
|
|
} from "class-validator";
|
|
import { Donation } from '../entities/Donation';
|
|
import { ResponseObjectType } from '../enums/ResponseObjectType';
|
|
import { IResponse } from './IResponse';
|
|
|
|
/**
|
|
* Defines the stats response.
|
|
* The stats response calculates some basic stats for a dashboard or public display.
|
|
*/
|
|
export class ResponseStats implements IResponse {
|
|
/**
|
|
* The responseType.
|
|
* This contains the type of class/entity this response contains.
|
|
*/
|
|
responseType: ResponseObjectType = ResponseObjectType.STATS;
|
|
|
|
/**
|
|
* The amount of runners registered in the system.
|
|
*/
|
|
@IsInt()
|
|
total_runners: number;
|
|
|
|
/**
|
|
* The amount of teams registered in the system.
|
|
*/
|
|
@IsInt()
|
|
total_teams: number;
|
|
|
|
/**
|
|
* The amount of organizations registered in the system.
|
|
*/
|
|
@IsInt()
|
|
total_orgs: number;
|
|
|
|
/**
|
|
* The amount of users registered in the system.
|
|
*/
|
|
@IsInt()
|
|
total_users: number;
|
|
|
|
/**
|
|
* The amount of valid scans registered in the system.
|
|
*/
|
|
@IsInt()
|
|
total_scans: number;
|
|
|
|
/**
|
|
* The total distance that all runners ran combined.
|
|
*/
|
|
@IsInt()
|
|
total_distance: number;
|
|
|
|
/**
|
|
* The total donation amount.
|
|
*/
|
|
@IsInt()
|
|
total_donation: number;
|
|
|
|
/**
|
|
* The total donation count (cent).
|
|
*/
|
|
@IsInt()
|
|
total_donations: number;
|
|
|
|
/**
|
|
* The total donor count.
|
|
*/
|
|
@IsInt()
|
|
total_donors: number;
|
|
|
|
/**
|
|
* The average distance ran per runner.
|
|
*/
|
|
@IsInt()
|
|
average_distance: number;
|
|
|
|
/**
|
|
* The average donation per distance (cent).
|
|
*/
|
|
@IsInt()
|
|
average_donation: number;
|
|
|
|
/**
|
|
* Creates a new stats response containing some basic statistics for a dashboard or public display.
|
|
* @param runners Array containing all runners - the following relations have to be resolved: scans, scans.track
|
|
* @param teams Array containing all teams - no relations have to be resolved.
|
|
* @param orgs Array containing all orgs - no relations have to be resolved.
|
|
* @param users Array containing all users - 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
|
|
*/
|
|
public constructor(runners: number, teams: number, orgs: number, users: number, scans: number, donations: Donation[], distance: number, donors: 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.total_donations = donations.length;
|
|
this.average_donation = this.total_donation / this.total_donations
|
|
this.total_donors = donors;
|
|
this.average_distance = this.total_distance / this.total_runners;
|
|
}
|
|
}
|