Add timeline derived builders
This commit is contained in:
1 parent
3460a93eaf
commit
897e2092a3
3 files changed
+664
No files matched your search
@@ -0,0 +1,272 @@
|
||||
import { TimelineDerivedService } from './timeline-derived.service';
|
||||
|
||||
function createTimelinePayload(
|
||||
eventsByFrame: Array<Record<string, unknown>[]>,
|
||||
) {
|
||||
return {
|
||||
info: {
|
||||
frames: eventsByFrame.map((events, index) => ({
|
||||
timestamp: index * 60_000,
|
||||
events,
|
||||
})),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
describe('TimelineDerivedService', () => {
|
||||
const service = new TimelineDerivedService();
|
||||
|
||||
it('clusters champion kills transitively by time and distance', () => {
|
||||
const derived = service.buildDerivedData(
|
||||
createTimelinePayload([
|
||||
[
|
||||
{
|
||||
type: 'CHAMPION_KILL',
|
||||
timestamp: 10_000,
|
||||
killerId: 1,
|
||||
victimId: 6,
|
||||
assistingParticipantIds: [2],
|
||||
position: { x: 1_000, y: 1_000 },
|
||||
victimDamageReceived: [
|
||||
{
|
||||
participantId: 3,
|
||||
magicDamageDone: 100,
|
||||
physicalDamageDone: 50,
|
||||
trueDamageDone: 0,
|
||||
},
|
||||
{
|
||||
participantId: 1,
|
||||
magicDamageDone: 20,
|
||||
physicalDamageDone: 30,
|
||||
trueDamageDone: 0,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: 'CHAMPION_KILL',
|
||||
timestamp: 24_000,
|
||||
killerId: 2,
|
||||
victimId: 7,
|
||||
assistingParticipantIds: null,
|
||||
victimDamageReceived: null,
|
||||
position: { x: 3_400, y: 1_000 },
|
||||
},
|
||||
{
|
||||
type: 'CHAMPION_KILL',
|
||||
timestamp: 38_000,
|
||||
killerId: 4,
|
||||
victimId: 8,
|
||||
assistingParticipantIds: [5],
|
||||
position: { x: 5_800, y: 1_000 },
|
||||
},
|
||||
],
|
||||
]),
|
||||
);
|
||||
|
||||
expect(derived.fightClusters).toEqual([
|
||||
{
|
||||
startTimeMs: 10_000,
|
||||
endTimeMs: 38_000,
|
||||
killCount: 3,
|
||||
participantIds: [1, 2, 3, 4, 5, 6, 7, 8],
|
||||
openerParticipantIds: [1, 2, 3],
|
||||
cleanupParticipantIds: [4, 5, 8],
|
||||
isTeamfight: true,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('separates champion kills that are not connected by both time and distance', () => {
|
||||
const derived = service.buildDerivedData(
|
||||
createTimelinePayload([
|
||||
[
|
||||
{
|
||||
type: 'CHAMPION_KILL',
|
||||
timestamp: 10_000,
|
||||
killerId: 1,
|
||||
victimId: 6,
|
||||
position: { x: 1_000, y: 1_000 },
|
||||
},
|
||||
{
|
||||
type: 'CHAMPION_KILL',
|
||||
timestamp: 20_000,
|
||||
killerId: 2,
|
||||
victimId: 7,
|
||||
position: { x: 7_000, y: 1_000 },
|
||||
},
|
||||
{
|
||||
type: 'CHAMPION_KILL',
|
||||
timestamp: 40_000,
|
||||
killerId: 3,
|
||||
victimId: 8,
|
||||
position: { x: 7_500, y: 1_000 },
|
||||
},
|
||||
],
|
||||
]),
|
||||
);
|
||||
|
||||
expect(derived.fightClusters).toHaveLength(3);
|
||||
expect(derived.fightClusters.map((cluster) => cluster.killCount)).toEqual([
|
||||
1, 1, 1,
|
||||
]);
|
||||
expect(
|
||||
derived.fightClusters.every((cluster) => cluster.isTeamfight === false),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('includes every kill within five seconds of the last kill as cleanup', () => {
|
||||
const derived = service.buildDerivedData(
|
||||
createTimelinePayload([
|
||||
[
|
||||
{
|
||||
type: 'CHAMPION_KILL',
|
||||
timestamp: 10_000,
|
||||
killerId: 1,
|
||||
victimId: 6,
|
||||
position: { x: 1_000, y: 1_000 },
|
||||
},
|
||||
{
|
||||
type: 'CHAMPION_KILL',
|
||||
timestamp: 20_000,
|
||||
killerId: 2,
|
||||
victimId: 7,
|
||||
position: { x: 2_000, y: 1_000 },
|
||||
},
|
||||
{
|
||||
type: 'CHAMPION_KILL',
|
||||
timestamp: 24_000,
|
||||
killerId: 3,
|
||||
victimId: 8,
|
||||
position: { x: 2_500, y: 1_000 },
|
||||
},
|
||||
],
|
||||
]),
|
||||
);
|
||||
|
||||
expect(derived.fightClusters[0].cleanupParticipantIds).toEqual([
|
||||
2, 3, 7, 8,
|
||||
]);
|
||||
});
|
||||
|
||||
it('uses explicit victim damage totals without adding component damage twice', () => {
|
||||
const derived = service.buildDerivedData(
|
||||
createTimelinePayload([
|
||||
[
|
||||
{
|
||||
type: 'CHAMPION_KILL',
|
||||
timestamp: 10_000,
|
||||
killerId: 1,
|
||||
victimId: 6,
|
||||
position: { x: 1_000, y: 1_000 },
|
||||
victimDamageReceived: [
|
||||
{
|
||||
participantId: 3,
|
||||
totalDamageDone: 100,
|
||||
magicDamageDone: 1_000,
|
||||
},
|
||||
{
|
||||
participantId: 4,
|
||||
magicDamageDone: 150,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
]),
|
||||
);
|
||||
|
||||
expect(derived.fightClusters[0].openerParticipantIds).toEqual([1, 4]);
|
||||
});
|
||||
|
||||
it('aggregates duplicate victim damage rows before selecting the opener contributor', () => {
|
||||
const derived = service.buildDerivedData(
|
||||
createTimelinePayload([
|
||||
[
|
||||
{
|
||||
type: 'CHAMPION_KILL',
|
||||
timestamp: 10_000,
|
||||
killerId: 1,
|
||||
victimId: 6,
|
||||
position: { x: 1_000, y: 1_000 },
|
||||
victimDamageReceived: [
|
||||
{
|
||||
participantId: 3,
|
||||
magicDamageDone: 80,
|
||||
},
|
||||
{
|
||||
participantId: 3,
|
||||
physicalDamageDone: 80,
|
||||
},
|
||||
{
|
||||
participantId: 4,
|
||||
magicDamageDone: 150,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
]),
|
||||
);
|
||||
|
||||
expect(derived.fightClusters[0].openerParticipantIds).toEqual([1, 3]);
|
||||
});
|
||||
|
||||
it('builds objective windows around elite monster kill timestamps', () => {
|
||||
const derived = service.buildDerivedData(
|
||||
createTimelinePayload([
|
||||
[
|
||||
{
|
||||
type: 'ELITE_MONSTER_KILL',
|
||||
timestamp: 900_000,
|
||||
killerId: 4,
|
||||
killerTeamId: 100,
|
||||
monsterType: 'DRAGON',
|
||||
monsterSubType: 'HEXTECH_DRAGON',
|
||||
position: { x: 9_800, y: 4_400 },
|
||||
},
|
||||
{
|
||||
type: 'WARD_PLACED',
|
||||
timestamp: 905_000,
|
||||
},
|
||||
],
|
||||
]),
|
||||
);
|
||||
|
||||
expect(derived.objectiveWindows).toEqual([
|
||||
{
|
||||
objectiveTimeMs: 900_000,
|
||||
startTimeMs: 780_000,
|
||||
endTimeMs: 930_000,
|
||||
killerParticipantId: 4,
|
||||
killerTeamId: 100,
|
||||
monsterType: 'DRAGON',
|
||||
monsterSubType: 'HEXTECH_DRAGON',
|
||||
position: { x: 9_800, y: 4_400 },
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('ignores elite monster kills outside dragon, rift herald, and baron', () => {
|
||||
const derived = service.buildDerivedData(
|
||||
createTimelinePayload([
|
||||
[
|
||||
{
|
||||
type: 'ELITE_MONSTER_KILL',
|
||||
timestamp: 900_000,
|
||||
killerId: 4,
|
||||
killerTeamId: 100,
|
||||
monsterType: 'HORDE',
|
||||
},
|
||||
{
|
||||
type: 'ELITE_MONSTER_KILL',
|
||||
timestamp: 1_200_000,
|
||||
killerId: 5,
|
||||
killerTeamId: 200,
|
||||
monsterType: 'BARON_NASHOR',
|
||||
},
|
||||
],
|
||||
]),
|
||||
);
|
||||
|
||||
expect(derived.objectiveWindows).toHaveLength(1);
|
||||
expect(derived.objectiveWindows[0].monsterType).toBe('BARON_NASHOR');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user