Store timeline derived data

This commit is contained in:
dahyeon committed 2026-07-02 23:13:27 -07:00
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')