Add timeline death events

This commit is contained in:
dahyeon committed 2026-07-02 23:43:09 -07:00
1 parent d35843a8e2
commit df0e43d884
5 files changed
+528 -12

No files matched your search

@@ -13,6 +13,24 @@ function createTimelinePayload(
};
}
function createTimelinePayloadWithFrames(
frames: Array<{
timestamp?: number;
events?: Record<string, unknown>[];
participantFrames?: Record<string, unknown>;
}>,
) {
return {
info: {
frames: frames.map((frame, index) => ({
timestamp: frame.timestamp ?? index * 60_000,
events: frame.events ?? [],
participantFrames: frame.participantFrames ?? {},
})),
},
};
}
describe('TimelineDerivedService', () => {
const service = new TimelineDerivedService();
@@ -270,6 +288,133 @@ describe('TimelineDerivedService', () => {
expect(derived.objectiveWindows[0].monsterType).toBe('BARON_NASHOR');
});
it('builds death events with shutdown bounty, zone, and nearest ally approximation', () => {
const derived = service.buildDerivedData(
createTimelinePayloadWithFrames([
{
timestamp: 0,
participantFrames: {
'1': { position: { x: 9_870, y: 4_414 } },
'7': { position: { x: 9_000, y: 4_000 } },
'8': { position: { x: 12_000, y: 4_000 } },
},
},
{
timestamp: 30_000,
events: [
{
type: 'CHAMPION_KILL',
timestamp: 30_000,
killerId: 1,
victimId: 6,
shutdownBounty: 277,
position: { x: 9_866, y: 4_414 },
},
],
},
{
timestamp: 60_000,
participantFrames: {
'1': { position: { x: 9_870, y: 4_414 } },
'7': { position: { x: 10_000, y: 4_000 } },
'8': { position: { x: 12_000, y: 4_000 } },
},
},
]),
);
expect(derived.deathEvents).toEqual([
{
t: 30_000,
victimParticipantId: 6,
x: 9_866,
y: 4_414,
zone: 'dragonPit',
shutdownBountyGiven: 277,
nearestAllyDistanceApprox: 553,
},
]);
});
it('interpolates missing death positions from victim frames', () => {
const derived = service.buildDerivedData(
createTimelinePayloadWithFrames([
{
timestamp: 0,
participantFrames: {
'1': { position: { x: 4_020, y: 6_000 } },
'6': { position: { x: 3_000, y: 6_000 } },
'7': { position: { x: 8_000, y: 6_000 } },
},
},
{
timestamp: 30_000,
events: [
{
type: 'CHAMPION_KILL',
timestamp: 30_000,
killerId: 1,
victimId: 6,
},
],
},
{
timestamp: 60_000,
participantFrames: {
'1': { position: { x: 4_020, y: 6_000 } },
'6': { position: { x: 5_000, y: 6_000 } },
'7': { position: { x: 10_000, y: 6_000 } },
},
},
]),
);
expect(derived.deathEvents).toEqual([
{
t: 30_000,
victimParticipantId: 6,
x: 4_000,
y: 6_000,
zone: 'southWestJungle',
shutdownBountyGiven: 0,
nearestAllyDistanceApprox: 5_000,
},
]);
});
it('classifies representative Summoner Rift death zones', () => {
const positions = [
{ x: 600, y: 600, zone: 'blueBase' },
{ x: 14_200, y: 14_200, zone: 'redBase' },
{ x: 1_000, y: 9_000, zone: 'topLane' },
{ x: 6_500, y: 6_500, zone: 'middleLane' },
{ x: 9_000, y: 1_000, zone: 'bottomLane' },
{ x: 8_000, y: 7_000, zone: 'river' },
{ x: 2_500, y: 8_500, zone: 'northWestJungle' },
{ x: 12_000, y: 9_000, zone: 'northEastJungle' },
{ x: 4_000, y: 6_000, zone: 'southWestJungle' },
{ x: 13_000, y: 5_000, zone: 'southEastJungle' },
{ x: 9_866, y: 4_414, zone: 'dragonPit' },
{ x: 5_007, y: 10_471, zone: 'baronPit' },
{ x: -1, y: 7_500, zone: 'unknown' },
];
const derived = service.buildDerivedData(
createTimelinePayload([
positions.map((position, index) => ({
type: 'CHAMPION_KILL',
timestamp: (index + 1) * 1_000,
killerId: 1,
victimId: 6,
position: { x: position.x, y: position.y },
})),
]),
);
expect(derived.deathEvents.map((deathEvent) => deathEvent.zone)).toEqual(
positions.map((position) => position.zone),
);
});
it('builds weighted advantage events for kills, plates, towers, and objectives', () => {
const derived = service.buildDerivedData(
createTimelinePayload([