Denormalize profile tier fields

This commit is contained in:
dahyeon committed 2026-07-03 01:31:22 -07:00
1 parent 89eafb8770
commit fafacec781
5 files changed
+76 -1

No files matched your search

@@ -670,6 +670,36 @@ describe('AnalysisPipelineService', () => {
expect(profileSet.normalizationMethod).toBe('population-percentile'); expect(profileSet.normalizationMethod).toBe('population-percentile');
}); });
it('denormalizes ranked solo tier fields when storing player profiles', async () => {
const { service, updatePlayerProfile } = createPipelineHarness({
storedAccount: createStoredAccount({
tiers: [
{
fetchedAt: new Date('2026-07-03T00:00:00.000Z'),
leaguePoints: 987,
losses: 10,
queueType: 'RANKED_SOLO_5x5',
rank: '',
tier: 'CHALLENGER',
wins: 20,
},
],
}),
});
await service.processUserAnalysisJob(createJobData(), 'analysis-job-1');
const profileSet = asRecord(
asRecord(updatePlayerProfile.mock.calls[0]?.[1]).$set,
);
expect(profileSet).toMatchObject({
isSeed: false,
tier: 'CHALLENGER',
division: '',
leaguePoints: 987,
});
});
it('skips seed pipeline processing when the seed account is missing', async () => { it('skips seed pipeline processing when the seed account is missing', async () => {
const { findOneAccount, getMatchIds, service, updatePlayerProfile } = const { findOneAccount, getMatchIds, service, updatePlayerProfile } =
createPipelineHarness({ createPipelineHarness({
@@ -16,6 +16,7 @@ import {
import { import {
FEATURE_RECOMPUTE_JOB_NAME, FEATURE_RECOMPUTE_JOB_NAME,
BASELINE_COMPUTATION_JOB_NAME, BASELINE_COMPUTATION_JOB_NAME,
DEFAULT_SEED_COLLECTION_QUEUE_TYPE,
MAX_ANALYSIS_MATCH_COUNT, MAX_ANALYSIS_MATCH_COUNT,
normalizeFeatureRecomputeBatchSize, normalizeFeatureRecomputeBatchSize,
normalizeRequestedMatchCount, normalizeRequestedMatchCount,
@@ -833,7 +834,7 @@ export class AnalysisPipelineService {
const accountModel = await this.connectionService.getModel('account'); const accountModel = await this.connectionService.getModel('account');
const account = await accountModel const account = await accountModel
.findOne({ puuid }) .findOne({ puuid })
.lean<Pick<Account, 'isSeed' | 'puuid'> | null>() .lean<Pick<Account, 'isSeed' | 'puuid' | 'tiers'> | null>()
.exec(); .exec();
const features = await playerMatchFeatureModel const features = await playerMatchFeatureModel
.find({ .find({
@@ -853,6 +854,7 @@ export class AnalysisPipelineService {
await this.storeBuiltProfile({ await this.storeBuiltProfile({
features, features,
isSeed: account?.isSeed ?? false, isSeed: account?.isSeed ?? false,
tierInfo: account ? this.resolveRankedSoloTier(account) : undefined,
puuid, puuid,
queueId, queueId,
}); });
@@ -866,6 +868,7 @@ export class AnalysisPipelineService {
await this.storeBuiltProfile({ await this.storeBuiltProfile({
features: extractedFeatures, features: extractedFeatures,
isSeed: account.isSeed, isSeed: account.isSeed,
tierInfo: this.resolveRankedSoloTier(account),
puuid: account.puuid, puuid: account.puuid,
queueId: data.queueId, queueId: data.queueId,
}); });
@@ -928,12 +931,16 @@ export class AnalysisPipelineService {
private async storeBuiltProfile(params: { private async storeBuiltProfile(params: {
features: PlayerMatchFeature[] | ExtractedPlayerMatchFeature[]; features: PlayerMatchFeature[] | ExtractedPlayerMatchFeature[];
isSeed: boolean; isSeed: boolean;
tierInfo?: TierInfo;
puuid: string; puuid: string;
queueId: number; queueId: number;
}): Promise<void> { }): Promise<void> {
const profile = this.profileBuilderService.buildProfile({ const profile = this.profileBuilderService.buildProfile({
features: params.features, features: params.features,
isSeed: params.isSeed, isSeed: params.isSeed,
tier: params.tierInfo?.tier,
division: params.tierInfo?.rank,
leaguePoints: params.tierInfo?.leaguePoints,
puuid: params.puuid, puuid: params.puuid,
queueId: params.queueId, queueId: params.queueId,
}); });
@@ -952,6 +959,14 @@ export class AnalysisPipelineService {
.exec(); .exec();
} }
private resolveRankedSoloTier(
account: Pick<Account, 'tiers'>,
): TierInfo | undefined {
return account.tiers.find(
(tier) => tier.queueType === DEFAULT_SEED_COLLECTION_QUEUE_TYPE,
);
}
private async completeJob( private async completeJob(
jobId: string, jobId: string,
jobType = USER_ANALYSIS_JOB_NAME, jobType = USER_ANALYSIS_JOB_NAME,
@@ -92,4 +92,7 @@ export interface BuiltPlayerProfile {
patches: string[]; patches: string[];
lastMatchAt?: Date; lastMatchAt?: Date;
isSeed: boolean; isSeed: boolean;
tier?: string;
division?: string;
leaguePoints?: number;
} }
@@ -160,6 +160,25 @@ describe('ProfileBuilderService', () => {
expect(mixedProfile.normalizationMethod).toBe('registry-baseline'); expect(mixedProfile.normalizationMethod).toBe('registry-baseline');
}); });
it('denormalizes ranked solo tier fields into built profiles', () => {
const profile = service.buildProfile({
features: [createFeature()],
isSeed: true,
puuid: 'seed-puuid',
queueId: 420,
tier: 'CHALLENGER',
division: '',
leaguePoints: 987,
});
expect(profile).toMatchObject({
isSeed: true,
tier: 'CHALLENGER',
division: '',
leaguePoints: 987,
});
});
it('aggregates ratio metrics from raw numerator and denominator counts', () => { it('aggregates ratio metrics from raw numerator and denominator counts', () => {
const metrics: MetricDefinition[] = [ const metrics: MetricDefinition[] = [
{ {
@@ -27,10 +27,13 @@ type ProfileSourceFeature = Pick<
>; >;
export interface BuildProfileParams { export interface BuildProfileParams {
division?: string;
features: ProfileSourceFeature[]; features: ProfileSourceFeature[];
isSeed: boolean; isSeed: boolean;
leaguePoints?: number;
puuid: string; puuid: string;
queueId: number; queueId: number;
tier?: string;
} }
const ROLE_ORDER: Role[] = ['TOP', 'JUNGLE', 'MIDDLE', 'BOTTOM', 'UTILITY']; const ROLE_ORDER: Role[] = ['TOP', 'JUNGLE', 'MIDDLE', 'BOTTOM', 'UTILITY'];
@@ -202,6 +205,11 @@ export class ProfileBuilderService {
Math.max(...params.features.map((feature) => feature.gameCreation)), Math.max(...params.features.map((feature) => feature.gameCreation)),
), ),
isSeed: params.isSeed, isSeed: params.isSeed,
...(params.tier ? { tier: params.tier } : {}),
...(params.division !== undefined ? { division: params.division } : {}),
...(params.leaguePoints !== undefined
? { leaguePoints: params.leaguePoints }
: {}),
}; };
} }