Add timeline advantage events
This commit is contained in:
1 parent
1e2f1695ce
commit
d35843a8e2
5 files changed
+342
-1
No files matched your search
@@ -417,6 +417,22 @@ describe('AnalysisPipelineService', () => {
|
|||||||
isTeamfight: false,
|
isTeamfight: false,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
advantageEvents: [
|
||||||
|
{
|
||||||
|
timestampMs: 10_000,
|
||||||
|
teamId: 100,
|
||||||
|
type: 'championKill',
|
||||||
|
score: 1,
|
||||||
|
participantIds: [1, 2],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
timestampMs: 900_000,
|
||||||
|
teamId: 100,
|
||||||
|
type: 'dragon',
|
||||||
|
score: 1.5,
|
||||||
|
participantIds: [4],
|
||||||
|
},
|
||||||
|
],
|
||||||
objectiveWindows: [
|
objectiveWindows: [
|
||||||
{
|
{
|
||||||
objectiveTimeMs: 900_000,
|
objectiveTimeMs: 900_000,
|
||||||
|
|||||||
@@ -269,4 +269,121 @@ describe('TimelineDerivedService', () => {
|
|||||||
expect(derived.objectiveWindows).toHaveLength(1);
|
expect(derived.objectiveWindows).toHaveLength(1);
|
||||||
expect(derived.objectiveWindows[0].monsterType).toBe('BARON_NASHOR');
|
expect(derived.objectiveWindows[0].monsterType).toBe('BARON_NASHOR');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('builds weighted advantage events for kills, plates, towers, and objectives', () => {
|
||||||
|
const derived = service.buildDerivedData(
|
||||||
|
createTimelinePayload([
|
||||||
|
[
|
||||||
|
{
|
||||||
|
type: 'CHAMPION_KILL',
|
||||||
|
timestamp: 10_000,
|
||||||
|
killerId: 1,
|
||||||
|
victimId: 6,
|
||||||
|
assistingParticipantIds: [2],
|
||||||
|
victimDamageReceived: [{ participantId: 3, magicDamageDone: 80 }],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'TURRET_PLATE_DESTROYED',
|
||||||
|
timestamp: 20_000,
|
||||||
|
killerId: 0,
|
||||||
|
teamId: 200,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'BUILDING_KILL',
|
||||||
|
timestamp: 30_000,
|
||||||
|
killerId: 2,
|
||||||
|
assistingParticipantIds: [3, 4],
|
||||||
|
buildingType: 'TOWER_BUILDING',
|
||||||
|
teamId: 200,
|
||||||
|
towerType: 'OUTER_TURRET',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'ELITE_MONSTER_KILL',
|
||||||
|
timestamp: 40_000,
|
||||||
|
killerId: 3,
|
||||||
|
killerTeamId: 100,
|
||||||
|
monsterType: 'RIFTHERALD',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'ELITE_MONSTER_KILL',
|
||||||
|
timestamp: 50_000,
|
||||||
|
killerId: 8,
|
||||||
|
killerTeamId: 200,
|
||||||
|
monsterType: 'BARON_NASHOR',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(derived.advantageEvents).toEqual([
|
||||||
|
{
|
||||||
|
timestampMs: 10_000,
|
||||||
|
teamId: 100,
|
||||||
|
type: 'championKill',
|
||||||
|
score: 1,
|
||||||
|
participantIds: [1, 2, 3],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
timestampMs: 20_000,
|
||||||
|
teamId: 100,
|
||||||
|
type: 'turretPlate',
|
||||||
|
score: 0.5,
|
||||||
|
participantIds: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
timestampMs: 30_000,
|
||||||
|
teamId: 100,
|
||||||
|
type: 'tower',
|
||||||
|
score: 1.5,
|
||||||
|
participantIds: [2, 3, 4],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
timestampMs: 40_000,
|
||||||
|
teamId: 100,
|
||||||
|
type: 'riftHerald',
|
||||||
|
score: 1.5,
|
||||||
|
participantIds: [3],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
timestampMs: 50_000,
|
||||||
|
teamId: 200,
|
||||||
|
type: 'baron',
|
||||||
|
score: 3,
|
||||||
|
participantIds: [8],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('omits advantage events when the scoring team cannot be inferred', () => {
|
||||||
|
const derived = service.buildDerivedData(
|
||||||
|
createTimelinePayload([
|
||||||
|
[
|
||||||
|
{
|
||||||
|
type: 'CHAMPION_KILL',
|
||||||
|
timestamp: 10_000,
|
||||||
|
killerId: 0,
|
||||||
|
victimId: 6,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'TURRET_PLATE_DESTROYED',
|
||||||
|
timestamp: 20_000,
|
||||||
|
killerId: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'BUILDING_KILL',
|
||||||
|
timestamp: 30_000,
|
||||||
|
buildingType: 'TOWER_BUILDING',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'ELITE_MONSTER_KILL',
|
||||||
|
timestamp: 40_000,
|
||||||
|
killerId: 0,
|
||||||
|
monsterType: 'DRAGON',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(derived.advantageEvents).toEqual([]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -1,3 +1,7 @@
|
|||||||
|
import {
|
||||||
|
ADVANTAGE_EVENT_WEIGHTS,
|
||||||
|
type AdvantageEventType,
|
||||||
|
} from '@persona-lenz/shared';
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
interface TimelinePosition {
|
interface TimelinePosition {
|
||||||
@@ -47,8 +51,17 @@ export interface TimelineObjectiveWindow {
|
|||||||
position?: TimelinePosition;
|
position?: TimelinePosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface TimelineAdvantageEvent {
|
||||||
|
timestampMs: number;
|
||||||
|
teamId: number;
|
||||||
|
type: AdvantageEventType;
|
||||||
|
score: number;
|
||||||
|
participantIds: number[];
|
||||||
|
}
|
||||||
|
|
||||||
export interface TimelineDerivedData {
|
export interface TimelineDerivedData {
|
||||||
fightClusters: TimelineFightCluster[];
|
fightClusters: TimelineFightCluster[];
|
||||||
|
advantageEvents: TimelineAdvantageEvent[];
|
||||||
objectiveWindows: TimelineObjectiveWindow[];
|
objectiveWindows: TimelineObjectiveWindow[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,6 +180,61 @@ function isObjectiveMonsterType(monsterType: string | undefined): boolean {
|
|||||||
return monsterType !== undefined && OBJECTIVE_MONSTER_TYPES.has(monsterType);
|
return monsterType !== undefined && OBJECTIVE_MONSTER_TYPES.has(monsterType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function objectiveAdvantageEventType(
|
||||||
|
monsterType: string | undefined,
|
||||||
|
): AdvantageEventType | undefined {
|
||||||
|
switch (monsterType) {
|
||||||
|
case 'DRAGON':
|
||||||
|
return 'dragon';
|
||||||
|
case 'RIFTHERALD':
|
||||||
|
return 'riftHerald';
|
||||||
|
case 'BARON_NASHOR':
|
||||||
|
return 'baron';
|
||||||
|
default:
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function teamIdFromParticipantId(
|
||||||
|
participantId: number | undefined,
|
||||||
|
): 100 | 200 | undefined {
|
||||||
|
if (participantId === undefined) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
if (participantId >= 1 && participantId <= 5) {
|
||||||
|
return 100;
|
||||||
|
}
|
||||||
|
if (participantId >= 6 && participantId <= 10) {
|
||||||
|
return 200;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
function toTeamId(value: unknown): 100 | 200 | undefined {
|
||||||
|
const teamId = asNumber(value);
|
||||||
|
return teamId === 100 || teamId === 200 ? teamId : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
function opposingTeamId(teamId: 100 | 200 | undefined): 100 | 200 | undefined {
|
||||||
|
if (teamId === 100) {
|
||||||
|
return 200;
|
||||||
|
}
|
||||||
|
if (teamId === 200) {
|
||||||
|
return 100;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
function scoringParticipantIds(event: TimelineChampionKillEvent): number[] {
|
||||||
|
return toSortedIds(
|
||||||
|
[
|
||||||
|
event.killerId,
|
||||||
|
...event.assistingParticipantIds,
|
||||||
|
...event.victimDamageReceived.map((damage) => damage.participantId),
|
||||||
|
].filter((id): id is number => id !== undefined),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function parseAssistingParticipantIds(value: unknown): number[] {
|
function parseAssistingParticipantIds(value: unknown): number[] {
|
||||||
return toSortedIds(
|
return toSortedIds(
|
||||||
asArray(value).flatMap((item) => {
|
asArray(value).flatMap((item) => {
|
||||||
@@ -239,11 +307,97 @@ function parseEliteMonsterKillEvent(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function structureParticipantIds(event: Record<string, unknown>): number[] {
|
||||||
|
return toSortedIds(
|
||||||
|
[
|
||||||
|
asParticipantId(event.killerId),
|
||||||
|
...parseAssistingParticipantIds(event.assistingParticipantIds),
|
||||||
|
].filter((id): id is number => id !== undefined),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function createStructureAdvantageEvent(
|
||||||
|
event: Record<string, unknown>,
|
||||||
|
type: AdvantageEventType,
|
||||||
|
): TimelineAdvantageEvent | undefined {
|
||||||
|
const timestamp = asNumber(event.timestamp);
|
||||||
|
const participantIds = structureParticipantIds(event);
|
||||||
|
const teamId =
|
||||||
|
teamIdFromParticipantId(participantIds[0]) ??
|
||||||
|
opposingTeamId(toTeamId(event.teamId));
|
||||||
|
if (timestamp === undefined || !teamId) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
timestampMs: timestamp,
|
||||||
|
teamId,
|
||||||
|
type,
|
||||||
|
score: ADVANTAGE_EVENT_WEIGHTS[type],
|
||||||
|
participantIds,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function createChampionKillAdvantageEvent(
|
||||||
|
event: TimelineChampionKillEvent,
|
||||||
|
): TimelineAdvantageEvent | undefined {
|
||||||
|
const teamId = teamIdFromParticipantId(event.killerId);
|
||||||
|
if (event.killerId === undefined || !teamId) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
timestampMs: event.timestamp,
|
||||||
|
teamId,
|
||||||
|
type: 'championKill',
|
||||||
|
score: ADVANTAGE_EVENT_WEIGHTS.championKill,
|
||||||
|
participantIds: scoringParticipantIds(event),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function createEliteMonsterAdvantageEvent(
|
||||||
|
event: TimelineEliteMonsterKillEvent,
|
||||||
|
): TimelineAdvantageEvent | undefined {
|
||||||
|
const type = objectiveAdvantageEventType(event.monsterType);
|
||||||
|
if (!type) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
const teamId =
|
||||||
|
toTeamId(event.killerTeamId) ??
|
||||||
|
teamIdFromParticipantId(event.killerParticipantId);
|
||||||
|
if (!teamId) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
timestampMs: event.timestamp,
|
||||||
|
teamId,
|
||||||
|
type,
|
||||||
|
score: ADVANTAGE_EVENT_WEIGHTS[type],
|
||||||
|
participantIds:
|
||||||
|
event.killerParticipantId === undefined
|
||||||
|
? []
|
||||||
|
: [event.killerParticipantId],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function createBuildingAdvantageEvent(
|
||||||
|
event: Record<string, unknown>,
|
||||||
|
): TimelineAdvantageEvent | undefined {
|
||||||
|
const buildingType = asString(event.buildingType);
|
||||||
|
const towerType = asString(event.towerType);
|
||||||
|
if (buildingType !== 'TOWER_BUILDING' && towerType === undefined) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return createStructureAdvantageEvent(event, 'tower');
|
||||||
|
}
|
||||||
|
|
||||||
function extractTimelineEvents(timeline: Record<string, unknown>) {
|
function extractTimelineEvents(timeline: Record<string, unknown>) {
|
||||||
const info = asRecord(timeline.info);
|
const info = asRecord(timeline.info);
|
||||||
const frames = asArray(info.frames).map(asRecord);
|
const frames = asArray(info.frames).map(asRecord);
|
||||||
const championKills: TimelineChampionKillEvent[] = [];
|
const championKills: TimelineChampionKillEvent[] = [];
|
||||||
const eliteMonsterKills: TimelineEliteMonsterKillEvent[] = [];
|
const eliteMonsterKills: TimelineEliteMonsterKillEvent[] = [];
|
||||||
|
const advantageEvents: TimelineAdvantageEvent[] = [];
|
||||||
|
|
||||||
for (const frame of frames) {
|
for (const frame of frames) {
|
||||||
for (const rawEvent of asArray(frame.events)) {
|
for (const rawEvent of asArray(frame.events)) {
|
||||||
@@ -253,6 +407,11 @@ function extractTimelineEvents(timeline: Record<string, unknown>) {
|
|||||||
const championKill = parseChampionKillEvent(event);
|
const championKill = parseChampionKillEvent(event);
|
||||||
if (championKill) {
|
if (championKill) {
|
||||||
championKills.push(championKill);
|
championKills.push(championKill);
|
||||||
|
const advantageEvent =
|
||||||
|
createChampionKillAdvantageEvent(championKill);
|
||||||
|
if (advantageEvent) {
|
||||||
|
advantageEvents.push(advantageEvent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -260,6 +419,28 @@ function extractTimelineEvents(timeline: Record<string, unknown>) {
|
|||||||
const eliteMonsterKill = parseEliteMonsterKillEvent(event);
|
const eliteMonsterKill = parseEliteMonsterKillEvent(event);
|
||||||
if (eliteMonsterKill) {
|
if (eliteMonsterKill) {
|
||||||
eliteMonsterKills.push(eliteMonsterKill);
|
eliteMonsterKills.push(eliteMonsterKill);
|
||||||
|
const advantageEvent =
|
||||||
|
createEliteMonsterAdvantageEvent(eliteMonsterKill);
|
||||||
|
if (advantageEvent) {
|
||||||
|
advantageEvents.push(advantageEvent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'TURRET_PLATE_DESTROYED': {
|
||||||
|
const advantageEvent = createStructureAdvantageEvent(
|
||||||
|
event,
|
||||||
|
'turretPlate',
|
||||||
|
);
|
||||||
|
if (advantageEvent) {
|
||||||
|
advantageEvents.push(advantageEvent);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'BUILDING_KILL': {
|
||||||
|
const advantageEvent = createBuildingAdvantageEvent(event);
|
||||||
|
if (advantageEvent) {
|
||||||
|
advantageEvents.push(advantageEvent);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -274,6 +455,9 @@ function extractTimelineEvents(timeline: Record<string, unknown>) {
|
|||||||
eliteMonsterKills: eliteMonsterKills.sort(
|
eliteMonsterKills: eliteMonsterKills.sort(
|
||||||
(left, right) => left.timestamp - right.timestamp,
|
(left, right) => left.timestamp - right.timestamp,
|
||||||
),
|
),
|
||||||
|
advantageEvents: advantageEvents.sort(
|
||||||
|
(left, right) => left.timestampMs - right.timestampMs,
|
||||||
|
),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -379,11 +563,12 @@ export class TimelineDerivedService {
|
|||||||
public buildDerivedData(
|
public buildDerivedData(
|
||||||
timeline: Record<string, unknown>,
|
timeline: Record<string, unknown>,
|
||||||
): TimelineDerivedData {
|
): TimelineDerivedData {
|
||||||
const { championKills, eliteMonsterKills } =
|
const { advantageEvents, championKills, eliteMonsterKills } =
|
||||||
extractTimelineEvents(timeline);
|
extractTimelineEvents(timeline);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
fightClusters: buildFightClusters(championKills),
|
fightClusters: buildFightClusters(championKills),
|
||||||
|
advantageEvents,
|
||||||
objectiveWindows: buildObjectiveWindows(eliteMonsterKills),
|
objectiveWindows: buildObjectiveWindows(eliteMonsterKills),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
ADVANTAGE_EVENT_WEIGHTS,
|
||||||
FEATURE_SCHEMA_VERSION,
|
FEATURE_SCHEMA_VERSION,
|
||||||
METRICS,
|
METRICS,
|
||||||
VECTOR_DIMENSION,
|
VECTOR_DIMENSION,
|
||||||
@@ -61,6 +62,17 @@ describe('shared feature registry', () => {
|
|||||||
METRICS.find((metric) => metric.id === 'deathsPerMin')?.direction,
|
METRICS.find((metric) => metric.id === 'deathsPerMin')?.direction,
|
||||||
).toBe('lowerIsBetter');
|
).toBe('lowerIsBetter');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('defines shared advantage event weights for timeline-derived metrics', () => {
|
||||||
|
expect(ADVANTAGE_EVENT_WEIGHTS).toEqual({
|
||||||
|
championKill: 1,
|
||||||
|
turretPlate: 0.5,
|
||||||
|
tower: 1.5,
|
||||||
|
dragon: 1.5,
|
||||||
|
riftHerald: 1.5,
|
||||||
|
baron: 3,
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('shared DTO contracts', () => {
|
describe('shared DTO contracts', () => {
|
||||||
|
|||||||
@@ -219,3 +219,14 @@ export const VECTOR_METRICS = METRICS.filter(
|
|||||||
);
|
);
|
||||||
|
|
||||||
export const VECTOR_DIMENSION = VECTOR_METRICS.length;
|
export const VECTOR_DIMENSION = VECTOR_METRICS.length;
|
||||||
|
|
||||||
|
export const ADVANTAGE_EVENT_WEIGHTS = {
|
||||||
|
championKill: 1,
|
||||||
|
turretPlate: 0.5,
|
||||||
|
tower: 1.5,
|
||||||
|
dragon: 1.5,
|
||||||
|
riftHerald: 1.5,
|
||||||
|
baron: 3,
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export type AdvantageEventType = keyof typeof ADVANTAGE_EVENT_WEIGHTS;
|
||||||
Reference in new issue
Block a user