Apply population percentile normalization

This commit is contained in:
dahyeon committed 2026-07-03 01:26:46 -07:00
1 parent 2935a526c7
commit 9a17502d29
8 files changed
+432 -10

No files matched your search

@@ -8,8 +8,10 @@ import type {
} from '../global/database/schemas';
import { RiotNotFoundError, type RiotApiClient } from '../riot/riot-api.client';
import type { MetricBaselineService } from './metric-baseline.service';
import type { MetricNormalizationService } from './metric-normalization.service';
import type {
BaselineComputationJobData,
ExtractedPlayerMatchFeature,
FeatureRecomputeJobData,
UserAnalysisJobData,
} from './analysis.types';
@@ -270,6 +272,7 @@ interface PipelineHarnessOptions {
[string, string]
>;
matchIds?: string[];
normalizeFeature?: jest.Mock;
storedAccount?: Account;
}
@@ -368,6 +371,8 @@ function createPipelineHarness(options: PipelineHarnessOptions = {}) {
patch: 'ALL',
samplesRead: 30,
});
const normalizeFeature =
options.normalizeFeature ?? jest.fn((feature) => Promise.resolve(feature));
const riotApiClient = {
getAccountByRiotId,
getSummonerByPuuid: jest.fn().mockResolvedValue({
@@ -388,6 +393,7 @@ function createPipelineHarness(options: PipelineHarnessOptions = {}) {
getMatchIds,
getMatch,
getMatchTimeline,
normalizeFeature,
service: new AnalysisPipelineService(
connectionService,
riotApiClient,
@@ -398,6 +404,9 @@ function createPipelineHarness(options: PipelineHarnessOptions = {}) {
{
computeMetricBaselines,
} as unknown as MetricBaselineService,
{
normalizeFeature,
} as unknown as MetricNormalizationService,
),
updateAnalysisJob,
updatePlayerMatchFeature,
@@ -630,6 +639,37 @@ describe('AnalysisPipelineService', () => {
expect(seedStageUpdate).toBeDefined();
});
it('stores population-percentile normalized features and profiles when baselines are available', async () => {
const normalizeFeature = jest.fn((feature: ExtractedPlayerMatchFeature) =>
Promise.resolve({
...feature,
normalized: {
...feature.normalized,
kda: 0.42,
},
normalizationMethod: 'population-percentile',
}),
);
const { service, updatePlayerMatchFeature, updatePlayerProfile } =
createPipelineHarness({
normalizeFeature,
});
await service.processUserAnalysisJob(createJobData(), 'analysis-job-1');
expect(normalizeFeature).toHaveBeenCalledTimes(1);
const featureSet = asRecord(
asRecord(updatePlayerMatchFeature.mock.calls[0]?.[1]).$set,
);
expect(asRecord(featureSet.normalized).kda).toBe(0.42);
expect(featureSet.normalizationMethod).toBe('population-percentile');
const profileSet = asRecord(
asRecord(updatePlayerProfile.mock.calls[0]?.[1]).$set,
);
expect(profileSet.normalizationMethod).toBe('population-percentile');
});
it('skips seed pipeline processing when the seed account is missing', async () => {
const { findOneAccount, getMatchIds, service, updatePlayerProfile } =
createPipelineHarness({