code quality
Some checks failed
CI / lint-typecheck (pull_request) Failing after 12s
CI / tests (pull_request) Has been skipped
CI / contract-tests (pull_request) Has been skipped
CI / e2e-tests (pull_request) Has been skipped
CI / comment-pr (pull_request) Has been skipped
CI / commit-types (pull_request) Has been skipped
Some checks failed
CI / lint-typecheck (pull_request) Failing after 12s
CI / tests (pull_request) Has been skipped
CI / contract-tests (pull_request) Has been skipped
CI / e2e-tests (pull_request) Has been skipped
CI / comment-pr (pull_request) Has been skipped
CI / commit-types (pull_request) Has been skipped
This commit is contained in:
@@ -14,6 +14,7 @@ import { RatingComponents } from '../../domain/RatingComponents';
|
||||
import { RatingCalculatedEvent } from '../../domain/events/RatingCalculatedEvent';
|
||||
import { DriverId } from '../../../racing/domain/entities/DriverId';
|
||||
import { RaceId } from '../../../racing/domain/entities/RaceId';
|
||||
import { Result as RaceResult } from '../../../racing/domain/entities/result/Result';
|
||||
|
||||
export interface CalculateRatingUseCasePorts {
|
||||
driverRepository: DriverRepository;
|
||||
@@ -84,12 +85,12 @@ export class CalculateRatingUseCase {
|
||||
}
|
||||
}
|
||||
|
||||
private calculateComponents(driverResult: any, allResults: any[]): RatingComponents {
|
||||
const position = typeof driverResult.position === 'object' ? (typeof driverResult.position.toNumber === 'function' ? driverResult.position.toNumber() : driverResult.position.value) : driverResult.position;
|
||||
private calculateComponents(driverResult: RaceResult, allResults: RaceResult[]): RatingComponents {
|
||||
const position = driverResult.position.toNumber();
|
||||
const totalDrivers = allResults.length;
|
||||
const incidents = typeof driverResult.incidents === 'object' ? (typeof driverResult.incidents.toNumber === 'function' ? driverResult.incidents.toNumber() : driverResult.incidents.value) : driverResult.incidents;
|
||||
const lapsCompleted = typeof driverResult.lapsCompleted === 'object' ? (typeof driverResult.lapsCompleted.toNumber === 'function' ? driverResult.lapsCompleted.toNumber() : driverResult.lapsCompleted.value) : (driverResult.lapsCompleted !== undefined ? driverResult.lapsCompleted : (driverResult.totalTime === 0 && (typeof position === 'object' ? position.value : position) > 0 ? 5 : (driverResult.points === 0 && (typeof position === 'object' ? position.value : position) > 0 ? 5 : 20)));
|
||||
const startPosition = typeof driverResult.startPosition === 'object' ? driverResult.startPosition.toNumber() : driverResult.startPosition;
|
||||
const incidents = driverResult.incidents.toNumber();
|
||||
const startPosition = driverResult.startPosition.toNumber();
|
||||
const points = driverResult.points;
|
||||
|
||||
// Results Strength: Based on position relative to field size
|
||||
const resultsStrength = this.calculateResultsStrength(position, totalDrivers);
|
||||
@@ -104,10 +105,12 @@ export class CalculateRatingUseCase {
|
||||
const racecraft = this.calculateRacecraft(position, startPosition);
|
||||
|
||||
// Reliability: Based on laps completed and DNF/DNS
|
||||
const reliability = this.calculateReliability(lapsCompleted, position, driverResult.points);
|
||||
// For the Result entity, we need to determine reliability based on position and points
|
||||
// If position is 0 (DNS) or points are 0 (DNF), reliability is low
|
||||
const reliability = this.calculateReliabilityFromResult(position, points);
|
||||
|
||||
// Team Contribution: Based on points scored
|
||||
const teamContribution = this.calculateTeamContribution(driverResult.points);
|
||||
const teamContribution = this.calculateTeamContribution(points);
|
||||
|
||||
return {
|
||||
resultsStrength,
|
||||
@@ -119,6 +122,21 @@ export class CalculateRatingUseCase {
|
||||
};
|
||||
}
|
||||
|
||||
private calculateReliabilityFromResult(position: number, points: number): number {
|
||||
// DNS (Did Not Start) - position 0
|
||||
if (position === 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// DNF (Did Not Finish) - no points but finished (position > 0)
|
||||
if (points === 0 && position > 0) {
|
||||
return 20;
|
||||
}
|
||||
|
||||
// Finished with points - high reliability
|
||||
return 100;
|
||||
}
|
||||
|
||||
private calculateResultsStrength(position: number, totalDrivers: number): number {
|
||||
if (position <= 0) return 1; // DNF/DNS (ensure > 0)
|
||||
const drivers = totalDrivers || 1;
|
||||
|
||||
Reference in New Issue
Block a user