Process seed accounts through analysis pipeline

This commit is contained in:
dahyeon committed 2026-07-03 01:11:21 -07:00
1 parent 63a4aeace7
commit d18e36e962
7 files changed
+343 -11

No files matched your search

@@ -18,11 +18,14 @@ import {
MAX_ANALYSIS_MATCH_COUNT,
normalizeFeatureRecomputeBatchSize,
normalizeRequestedMatchCount,
SEED_COLLECTION_JOB_NAME,
USER_ANALYSIS_JOB_NAME,
} from './analysis.constants';
import type {
ExtractedPlayerMatchFeature,
FeatureRecomputeJobData,
SeedAccountPipelineData,
SeedAccountPipelineResult,
UserAnalysisJobData,
} from './analysis.types';
import { FeatureExtractorService } from './feature-extractor.service';
@@ -274,6 +277,106 @@ export class AnalysisPipelineService {
}
}
public async processSeedAccountPipeline(
data: SeedAccountPipelineData,
jobId: string,
): Promise<SeedAccountPipelineResult> {
const normalizedData = {
...data,
requestedMatchCount: normalizeRequestedMatchCount(
data.requestedMatchCount,
),
};
const account = await this.findSeedAccount(normalizedData.puuid);
if (!account) {
this.logger.warn(
`Skipping missing seed account puuid="${this.safeLogText(normalizedData.puuid)}"`,
);
return {
puuid: normalizedData.puuid,
fetchedMatches: 0,
extractedFeatures: 0,
profileBuilt: false,
};
}
await this.updateJob(
jobId,
{
puuid: account.puuid,
stage: 'fetch-match-ids',
},
SEED_COLLECTION_JOB_NAME,
);
const matchIds = await this.riotApiClient.getMatchIds(account.puuid, {
count: normalizedData.requestedMatchCount,
queue: normalizedData.queueId,
regionalRoute: normalizedData.regionalRoute,
});
await this.updateJob(
jobId,
{
stage: 'fetch-match-details',
progress: {
fetchedMatches: 0,
totalMatches: matchIds.length,
},
},
SEED_COLLECTION_JOB_NAME,
);
if (matchIds.length === 0) {
return {
puuid: account.puuid,
fetchedMatches: 0,
extractedFeatures: 0,
profileBuilt: false,
};
}
const matchRecords = await this.fetchAndStoreMatches(
matchIds,
normalizedData,
jobId,
SEED_COLLECTION_JOB_NAME,
);
await this.updateJob(
jobId,
{
stage: 'extract-features',
},
SEED_COLLECTION_JOB_NAME,
);
const extractedFeatures = await this.extractAndStoreFeatures(
matchRecords,
account.puuid,
normalizedData.queueId,
);
await this.updateJob(
jobId,
{
stage: 'build-profile',
},
SEED_COLLECTION_JOB_NAME,
);
if (extractedFeatures.length > 0) {
await this.buildAndStoreProfile(
account,
normalizedData,
extractedFeatures,
);
}
return {
puuid: account.puuid,
fetchedMatches: matchRecords.length,
extractedFeatures: extractedFeatures.length,
profileBuilt: extractedFeatures.length > 0,
};
}
private async resolveAndStoreAccount(
data: UserAnalysisJobData,
): Promise<Account> {
@@ -328,8 +431,9 @@ export class AnalysisPipelineService {
private async fetchAndStoreMatches(
matchIds: string[],
data: UserAnalysisJobData,
data: Pick<UserAnalysisJobData, 'queueId' | 'regionalRoute'>,
jobId: string,
jobType = USER_ANALYSIS_JOB_NAME,
): Promise<MatchRecord[]> {
const matchRecords: MatchRecord[] = [];
const riotMatchModel = await this.connectionService.getModel('riotMatch');
@@ -378,12 +482,16 @@ export class AnalysisPipelineService {
`Skipping matchId="${this.safeLogText(matchId)}" after fetch/store failure: ${this.safeLogText(errorMessage(error))}`,
);
} finally {
await this.updateJob(jobId, {
progress: {
fetchedMatches: index + 1,
totalMatches: matchIds.length,
await this.updateJob(
jobId,
{
progress: {
fetchedMatches: index + 1,
totalMatches: matchIds.length,
},
},
});
jobType,
);
}
}
@@ -663,7 +771,7 @@ export class AnalysisPipelineService {
private async buildAndStoreProfile(
account: Account,
data: UserAnalysisJobData,
data: Pick<UserAnalysisJobData, 'queueId'>,
extractedFeatures: ExtractedPlayerMatchFeature[],
): Promise<void> {
await this.storeBuiltProfile({
@@ -703,6 +811,11 @@ export class AnalysisPipelineService {
return remainingTargets.length > 0;
}
private async findSeedAccount(puuid: string): Promise<Account | null> {
const accountModel = await this.connectionService.getModel('account');
return accountModel.findOne({ puuid, isSeed: true }).lean<Account>().exec();
}
private featureRecomputeTargetQuery(params: {
puuid?: string;
queueId: number;