Add timeline vector metrics
This commit is contained in:
1 parent
77ba93b94a
commit
a69e86f2bc
13 files changed
+1543
-37
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { Logger } from '@nestjs/common';
|
||||
import { FEATURE_SCHEMA_VERSION } from '@persona-lenz/shared';
|
||||
import { FEATURE_SCHEMA_VERSION, VECTOR_METRICS } from '@persona-lenz/shared';
|
||||
import type { ConnectionService } from '../global/database/connection.service';
|
||||
import type { Account } from '../global/database/schemas';
|
||||
import { RiotNotFoundError, type RiotApiClient } from '../riot/riot-api.client';
|
||||
@@ -8,6 +8,7 @@ import { FeatureExtractorService } from './feature-extractor.service';
|
||||
import { AnalysisPipelineService } from './analysis-pipeline.service';
|
||||
import { ProfileBuilderService } from './profile-builder.service';
|
||||
import { TimelineDerivedService } from './timeline-derived.service';
|
||||
import { TimelineMetricService } from './timeline-metric.service';
|
||||
|
||||
function createJobData(): UserAnalysisJobData {
|
||||
return {
|
||||
@@ -69,6 +70,15 @@ function createMatchPayload(matchId = 'KR_1') {
|
||||
kills: 10,
|
||||
totalDamageDealtToChampions: 30_000,
|
||||
},
|
||||
{
|
||||
participantId: 6,
|
||||
puuid: 'enemy-puuid',
|
||||
teamId: 200,
|
||||
teamPosition: 'MIDDLE',
|
||||
championId: 134,
|
||||
kills: 4,
|
||||
totalDamageDealtToChampions: 16_000,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -85,7 +95,7 @@ function createTimelinePayload(
|
||||
},
|
||||
info: {
|
||||
frameInterval: 60_000,
|
||||
frames: events.length > 0 ? [{ timestamp: 0, events }] : [],
|
||||
frames: [{ timestamp: 0, events, participantFrames: {} }],
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -281,6 +291,7 @@ function createPipelineHarness(options: PipelineHarnessOptions = {}) {
|
||||
new FeatureExtractorService(),
|
||||
new ProfileBuilderService(),
|
||||
new TimelineDerivedService(),
|
||||
new TimelineMetricService(),
|
||||
),
|
||||
updateAnalysisJob,
|
||||
updatePlayerMatchFeature,
|
||||
@@ -400,6 +411,20 @@ describe('AnalysisPipelineService', () => {
|
||||
expect(timelineSet.timelineFetchedAt).toBeInstanceOf(Date);
|
||||
});
|
||||
|
||||
it('refetches cached timeline data when it is malformed', async () => {
|
||||
const { getMatchTimeline, service, updateRiotMatch } =
|
||||
createPipelineHarness({
|
||||
existingMatchRaw: createMatchPayload(),
|
||||
existingTimeline: {},
|
||||
});
|
||||
|
||||
await service.processUserAnalysisJob(createJobData(), 'analysis-job-1');
|
||||
|
||||
expect(getMatchTimeline).toHaveBeenCalledWith('KR_1', 'asia');
|
||||
const timelineSet = findTimelineSet(updateRiotMatch);
|
||||
expect(timelineSet.timeline).toEqual(createTimelinePayload());
|
||||
});
|
||||
|
||||
it('stores derived timeline data when a timeline is available', async () => {
|
||||
const timeline = createTimelinePayloadWithFrames('KR_1', [
|
||||
{
|
||||
@@ -440,12 +465,18 @@ describe('AnalysisPipelineService', () => {
|
||||
{
|
||||
timestamp: 900_000,
|
||||
events: [
|
||||
{
|
||||
type: 'WARD_PLACED',
|
||||
timestamp: 850_000,
|
||||
creatorId: 1,
|
||||
},
|
||||
{
|
||||
type: 'ELITE_MONSTER_KILL',
|
||||
timestamp: 900_000,
|
||||
killerId: 4,
|
||||
killerTeamId: 100,
|
||||
monsterType: 'DRAGON',
|
||||
assistingParticipantIds: [1],
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -453,16 +484,39 @@ describe('AnalysisPipelineService', () => {
|
||||
const getMatchTimeline = jest
|
||||
.fn<Promise<Record<string, unknown>>, [string, string]>()
|
||||
.mockResolvedValue(timeline);
|
||||
const { service, updatePlayerMatchFeature } = createPipelineHarness({
|
||||
getMatchTimeline,
|
||||
});
|
||||
const { service, updatePlayerMatchFeature, updatePlayerProfile } =
|
||||
createPipelineHarness({
|
||||
getMatchTimeline,
|
||||
});
|
||||
|
||||
await service.processUserAnalysisJob(createJobData(), 'analysis-job-1');
|
||||
|
||||
const playerMatchFeatureSet = asRecord(
|
||||
asRecord(updatePlayerMatchFeature.mock.calls[0][1]).$set,
|
||||
);
|
||||
const playerMatchFeatureSetFeatures = asRecord(
|
||||
playerMatchFeatureSet.features,
|
||||
);
|
||||
const playerMatchFeatureSetNormalized = asRecord(
|
||||
playerMatchFeatureSet.normalized,
|
||||
);
|
||||
const playerMatchFeatureSetVector =
|
||||
playerMatchFeatureSet.vector as number[];
|
||||
expect(playerMatchFeatureSet.timelineProcessed).toBe(true);
|
||||
expect(playerMatchFeatureSetFeatures).toMatchObject({
|
||||
objectivePreWardRateNumerator: 1,
|
||||
objectivePreWardRateDenominator: 1,
|
||||
eliteObjectiveParticipationRateNumerator: 1,
|
||||
eliteObjectiveParticipationRateDenominator: 1,
|
||||
});
|
||||
expect(playerMatchFeatureSetNormalized.objectivePreWardRate).toBe(1);
|
||||
expect(
|
||||
playerMatchFeatureSetVector[
|
||||
VECTOR_METRICS.findIndex(
|
||||
(metric) => metric.id === 'objectivePreWardRate',
|
||||
)
|
||||
],
|
||||
).toBe(1);
|
||||
expect(playerMatchFeatureSet.derived).toEqual({
|
||||
fightClusters: [
|
||||
{
|
||||
@@ -524,6 +578,19 @@ describe('AnalysisPipelineService', () => {
|
||||
},
|
||||
],
|
||||
});
|
||||
const playerProfileSet = asRecord(
|
||||
asRecord(updatePlayerProfile.mock.calls[0][1]).$set,
|
||||
);
|
||||
const playerProfileSetProfile = asRecord(playerProfileSet.profile);
|
||||
const playerProfileSetVector = playerProfileSet.vector as number[];
|
||||
expect(playerProfileSetProfile.objectivePreWardRate).toBe(1);
|
||||
expect(
|
||||
playerProfileSetVector[
|
||||
VECTOR_METRICS.findIndex(
|
||||
(metric) => metric.id === 'objectivePreWardRate',
|
||||
)
|
||||
],
|
||||
).toBe(1);
|
||||
});
|
||||
|
||||
it('continues raw match analysis when timeline fetch fails', async () => {
|
||||
|
||||
Reference in new issue
Block a user