Store timeline derived data
This commit is contained in:
1 parent
897e2092a3
commit
1e2f1695ce
3 files changed
+92
-9
No files matched your search
@@ -7,6 +7,7 @@ import type { UserAnalysisJobData } from './analysis.types';
|
||||
import { FeatureExtractorService } from './feature-extractor.service';
|
||||
import { AnalysisPipelineService } from './analysis-pipeline.service';
|
||||
import { ProfileBuilderService } from './profile-builder.service';
|
||||
import { TimelineDerivedService } from './timeline-derived.service';
|
||||
|
||||
function createJobData(): UserAnalysisJobData {
|
||||
return {
|
||||
@@ -71,7 +72,10 @@ function createMatchPayload(matchId = 'KR_1') {
|
||||
};
|
||||
}
|
||||
|
||||
function createTimelinePayload(matchId = 'KR_1') {
|
||||
function createTimelinePayload(
|
||||
matchId = 'KR_1',
|
||||
events: Record<string, unknown>[] = [],
|
||||
) {
|
||||
return {
|
||||
metadata: {
|
||||
matchId,
|
||||
@@ -79,7 +83,7 @@ function createTimelinePayload(matchId = 'KR_1') {
|
||||
},
|
||||
info: {
|
||||
frameInterval: 60_000,
|
||||
frames: [],
|
||||
frames: events.length > 0 ? [{ timestamp: 0, events }] : [],
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -250,6 +254,7 @@ function createPipelineHarness(options: PipelineHarnessOptions = {}) {
|
||||
riotApiClient,
|
||||
new FeatureExtractorService(),
|
||||
new ProfileBuilderService(),
|
||||
new TimelineDerivedService(),
|
||||
),
|
||||
updateAnalysisJob,
|
||||
updatePlayerMatchFeature,
|
||||
@@ -369,6 +374,62 @@ describe('AnalysisPipelineService', () => {
|
||||
expect(timelineSet.timelineFetchedAt).toBeInstanceOf(Date);
|
||||
});
|
||||
|
||||
it('stores derived timeline data when a timeline is available', async () => {
|
||||
const timeline = createTimelinePayload('KR_1', [
|
||||
{
|
||||
type: 'CHAMPION_KILL',
|
||||
timestamp: 10_000,
|
||||
killerId: 1,
|
||||
victimId: 6,
|
||||
assistingParticipantIds: [2],
|
||||
position: { x: 1_000, y: 1_000 },
|
||||
},
|
||||
{
|
||||
type: 'ELITE_MONSTER_KILL',
|
||||
timestamp: 900_000,
|
||||
killerId: 4,
|
||||
killerTeamId: 100,
|
||||
monsterType: 'DRAGON',
|
||||
},
|
||||
]);
|
||||
const getMatchTimeline = jest
|
||||
.fn<Promise<Record<string, unknown>>, [string, string]>()
|
||||
.mockResolvedValue(timeline);
|
||||
const { service, updatePlayerMatchFeature } = createPipelineHarness({
|
||||
getMatchTimeline,
|
||||
});
|
||||
|
||||
await service.processUserAnalysisJob(createJobData(), 'analysis-job-1');
|
||||
|
||||
const playerMatchFeatureSet = asRecord(
|
||||
asRecord(updatePlayerMatchFeature.mock.calls[0][1]).$set,
|
||||
);
|
||||
expect(playerMatchFeatureSet.timelineProcessed).toBe(true);
|
||||
expect(playerMatchFeatureSet.derived).toEqual({
|
||||
fightClusters: [
|
||||
{
|
||||
startTimeMs: 10_000,
|
||||
endTimeMs: 10_000,
|
||||
killCount: 1,
|
||||
participantIds: [1, 2, 6],
|
||||
openerParticipantIds: [1, 2],
|
||||
cleanupParticipantIds: [1, 2, 6],
|
||||
isTeamfight: false,
|
||||
},
|
||||
],
|
||||
objectiveWindows: [
|
||||
{
|
||||
objectiveTimeMs: 900_000,
|
||||
startTimeMs: 780_000,
|
||||
endTimeMs: 930_000,
|
||||
killerParticipantId: 4,
|
||||
killerTeamId: 100,
|
||||
monsterType: 'DRAGON',
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it('continues raw match analysis when timeline fetch fails', async () => {
|
||||
const loggerWarnSpy = jest
|
||||
.spyOn(Logger.prototype, 'warn')
|
||||
|
||||
@@ -21,10 +21,12 @@ import type {
|
||||
} from './analysis.types';
|
||||
import { FeatureExtractorService } from './feature-extractor.service';
|
||||
import { ProfileBuilderService } from './profile-builder.service';
|
||||
import { TimelineDerivedService } from './timeline-derived.service';
|
||||
|
||||
interface MatchRecord {
|
||||
matchId: string;
|
||||
raw: Record<string, unknown>;
|
||||
timeline?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
interface ParsedMatchSummary {
|
||||
@@ -72,6 +74,7 @@ export class AnalysisPipelineService {
|
||||
private readonly riotApiClient: RiotApiClient,
|
||||
private readonly featureExtractorService: FeatureExtractorService,
|
||||
private readonly profileBuilderService: ProfileBuilderService,
|
||||
private readonly timelineDerivedService: TimelineDerivedService,
|
||||
) {}
|
||||
|
||||
public async processUserAnalysisJob(
|
||||
@@ -229,12 +232,16 @@ export class AnalysisPipelineService {
|
||||
|
||||
if (existingMatch) {
|
||||
if (this.isEligibleMatch(existingMatch.raw, data.queueId)) {
|
||||
await this.fetchAndStoreMissingTimeline(
|
||||
const timeline = await this.fetchAndStoreMissingTimeline(
|
||||
matchId,
|
||||
existingMatch.timeline,
|
||||
data.regionalRoute,
|
||||
);
|
||||
matchRecords.push({ matchId, raw: existingMatch.raw });
|
||||
matchRecords.push({
|
||||
matchId,
|
||||
raw: existingMatch.raw,
|
||||
...(timeline ? { timeline } : {}),
|
||||
});
|
||||
}
|
||||
} else {
|
||||
const rawMatch = await this.riotApiClient.getMatch(
|
||||
@@ -243,12 +250,16 @@ export class AnalysisPipelineService {
|
||||
);
|
||||
await this.storeRiotMatch(matchId, rawMatch);
|
||||
if (this.isEligibleMatch(rawMatch, data.queueId)) {
|
||||
await this.fetchAndStoreMissingTimeline(
|
||||
const timeline = await this.fetchAndStoreMissingTimeline(
|
||||
matchId,
|
||||
undefined,
|
||||
data.regionalRoute,
|
||||
);
|
||||
matchRecords.push({ matchId, raw: rawMatch });
|
||||
matchRecords.push({
|
||||
matchId,
|
||||
raw: rawMatch,
|
||||
...(timeline ? { timeline } : {}),
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -299,9 +310,9 @@ export class AnalysisPipelineService {
|
||||
matchId: string,
|
||||
existingTimeline: unknown,
|
||||
regionalRoute: UserAnalysisJobData['regionalRoute'],
|
||||
): Promise<void> {
|
||||
): Promise<Record<string, unknown> | undefined> {
|
||||
if (isRecordValue(existingTimeline)) {
|
||||
return;
|
||||
return existingTimeline;
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -310,10 +321,12 @@ export class AnalysisPipelineService {
|
||||
regionalRoute,
|
||||
);
|
||||
await this.storeRiotMatchTimeline(matchId, timeline);
|
||||
return timeline;
|
||||
} catch (error) {
|
||||
this.logger.warn(
|
||||
`Skipping timeline fetch for matchId="${this.safeLogText(matchId)}": ${this.safeLogText(errorMessage(error))}`,
|
||||
);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -352,6 +365,14 @@ export class AnalysisPipelineService {
|
||||
puuid,
|
||||
);
|
||||
if (feature.queueId !== queueId) continue;
|
||||
if (matchRecord.timeline) {
|
||||
feature.derived = {
|
||||
...this.timelineDerivedService.buildDerivedData(
|
||||
matchRecord.timeline,
|
||||
),
|
||||
};
|
||||
feature.timelineProcessed = true;
|
||||
}
|
||||
|
||||
await playerMatchFeatureModel
|
||||
.updateOne(
|
||||
|
||||
@@ -30,8 +30,9 @@ export interface ExtractedPlayerMatchFeature {
|
||||
featureSchemaVersion: number;
|
||||
normalizationMethod: 'registry-baseline';
|
||||
confidence: number;
|
||||
timelineProcessed: false;
|
||||
timelineProcessed: boolean;
|
||||
laneOpponent?: LaneOpponentRef;
|
||||
derived?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export interface BuiltPlayerProfile {
|
||||
|
||||
Reference in new issue
Block a user