Add timeline roam frames
This commit is contained in:
1 parent
df0e43d884
commit
d4e7cb6e8b
4 files changed
+296
No files matched your search
@@ -33,6 +33,7 @@ function createMatchPayload(matchId = 'KR_1') {
|
||||
queueId: 420,
|
||||
participants: [
|
||||
{
|
||||
participantId: 1,
|
||||
puuid: 'target-puuid',
|
||||
teamId: 100,
|
||||
teamPosition: 'MIDDLE',
|
||||
@@ -60,6 +61,7 @@ function createMatchPayload(matchId = 'KR_1') {
|
||||
},
|
||||
},
|
||||
{
|
||||
participantId: 2,
|
||||
puuid: 'ally-puuid',
|
||||
teamId: 100,
|
||||
teamPosition: 'JUNGLE',
|
||||
@@ -428,6 +430,13 @@ describe('AnalysisPipelineService', () => {
|
||||
'7': { position: { x: 14_000, y: 6_000 } },
|
||||
},
|
||||
},
|
||||
{
|
||||
timestamp: 8 * 60_000,
|
||||
participantFrames: {
|
||||
'1': { position: { x: 8_000, y: 7_000 } },
|
||||
'2': { position: { x: 8_000, y: 7_000 } },
|
||||
},
|
||||
},
|
||||
{
|
||||
timestamp: 900_000,
|
||||
events: [
|
||||
@@ -503,6 +512,17 @@ describe('AnalysisPipelineService', () => {
|
||||
monsterType: 'DRAGON',
|
||||
},
|
||||
],
|
||||
roamFrames: [
|
||||
{
|
||||
t: 8 * 60_000,
|
||||
participantId: 1,
|
||||
teamId: 100,
|
||||
x: 8_000,
|
||||
y: 7_000,
|
||||
zone: 'river',
|
||||
assignedLaneZone: 'middleLane',
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -369,6 +369,7 @@ export class AnalysisPipelineService {
|
||||
feature.derived = {
|
||||
...this.timelineDerivedService.buildDerivedData(
|
||||
matchRecord.timeline,
|
||||
matchRecord.raw,
|
||||
),
|
||||
};
|
||||
feature.timelineProcessed = true;
|
||||
|
||||
@@ -415,6 +415,148 @@ describe('TimelineDerivedService', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('builds roam frames for non-jungle laners between 8 and 14 minutes', () => {
|
||||
const rawMatch = {
|
||||
info: {
|
||||
participants: [
|
||||
{ participantId: 1, teamId: 100, teamPosition: 'TOP' },
|
||||
{ participantId: 2, teamId: 100, teamPosition: 'JUNGLE' },
|
||||
{ participantId: 6, teamId: 200, teamPosition: 'MIDDLE' },
|
||||
],
|
||||
},
|
||||
};
|
||||
const derived = service.buildDerivedData(
|
||||
createTimelinePayloadWithFrames([
|
||||
{
|
||||
timestamp: 7 * 60_000,
|
||||
participantFrames: {
|
||||
'1': { position: { x: 8_000, y: 7_000 } },
|
||||
},
|
||||
},
|
||||
{
|
||||
timestamp: 8 * 60_000,
|
||||
participantFrames: {
|
||||
'1': { position: { x: 8_000, y: 7_000 } },
|
||||
'2': { position: { x: 8_000, y: 7_000 } },
|
||||
'6': { position: { x: 14_200, y: 14_200 } },
|
||||
},
|
||||
},
|
||||
{
|
||||
timestamp: 9 * 60_000,
|
||||
participantFrames: {
|
||||
'1': { position: { x: 1_000, y: 9_000 } },
|
||||
'6': { position: { x: 8_000, y: 7_000 } },
|
||||
},
|
||||
},
|
||||
{
|
||||
timestamp: 14 * 60_000,
|
||||
participantFrames: {
|
||||
'1': { position: { x: 9_000, y: 1_000 } },
|
||||
},
|
||||
},
|
||||
{
|
||||
timestamp: 15 * 60_000,
|
||||
participantFrames: {
|
||||
'1': { position: { x: 8_000, y: 7_000 } },
|
||||
},
|
||||
},
|
||||
]),
|
||||
rawMatch,
|
||||
);
|
||||
|
||||
expect(derived.roamFrames).toEqual([
|
||||
{
|
||||
t: 8 * 60_000,
|
||||
participantId: 1,
|
||||
teamId: 100,
|
||||
x: 8_000,
|
||||
y: 7_000,
|
||||
zone: 'river',
|
||||
assignedLaneZone: 'topLane',
|
||||
},
|
||||
{
|
||||
t: 9 * 60_000,
|
||||
participantId: 6,
|
||||
teamId: 200,
|
||||
x: 8_000,
|
||||
y: 7_000,
|
||||
zone: 'river',
|
||||
assignedLaneZone: 'middleLane',
|
||||
},
|
||||
{
|
||||
t: 14 * 60_000,
|
||||
participantId: 1,
|
||||
teamId: 100,
|
||||
x: 9_000,
|
||||
y: 1_000,
|
||||
zone: 'bottomLane',
|
||||
assignedLaneZone: 'topLane',
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('uses the participant own base only when filtering roam frames', () => {
|
||||
const rawMatch = {
|
||||
info: {
|
||||
participants: [{ participantId: 1, teamId: 100, teamPosition: 'TOP' }],
|
||||
},
|
||||
};
|
||||
const derived = service.buildDerivedData(
|
||||
createTimelinePayloadWithFrames([
|
||||
{
|
||||
timestamp: 8 * 60_000,
|
||||
participantFrames: {
|
||||
'1': { position: { x: 600, y: 600 } },
|
||||
},
|
||||
},
|
||||
{
|
||||
timestamp: 9 * 60_000,
|
||||
participantFrames: {
|
||||
'1': { position: { x: 14_200, y: 14_200 } },
|
||||
},
|
||||
},
|
||||
]),
|
||||
rawMatch,
|
||||
);
|
||||
|
||||
expect(derived.roamFrames).toEqual([
|
||||
{
|
||||
t: 9 * 60_000,
|
||||
participantId: 1,
|
||||
teamId: 100,
|
||||
x: 14_200,
|
||||
y: 14_200,
|
||||
zone: 'redBase',
|
||||
assignedLaneZone: 'topLane',
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('omits roam frames when participant id or map zone is unknown', () => {
|
||||
const rawMatch = {
|
||||
info: {
|
||||
participants: [
|
||||
{ teamId: 100, teamPosition: 'TOP' },
|
||||
{ participantId: 2, teamId: 100, teamPosition: 'MIDDLE' },
|
||||
],
|
||||
},
|
||||
};
|
||||
const derived = service.buildDerivedData(
|
||||
createTimelinePayloadWithFrames([
|
||||
{
|
||||
timestamp: 8 * 60_000,
|
||||
participantFrames: {
|
||||
'1': { position: { x: 8_000, y: 7_000 } },
|
||||
'2': { position: { x: -1, y: 7_500 } },
|
||||
},
|
||||
},
|
||||
]),
|
||||
rawMatch,
|
||||
);
|
||||
|
||||
expect(derived.roamFrames).toEqual([]);
|
||||
});
|
||||
|
||||
it('builds weighted advantage events for kills, plates, towers, and objectives', () => {
|
||||
const derived = service.buildDerivedData(
|
||||
createTimelinePayload([
|
||||
|
||||
@@ -38,6 +38,13 @@ interface TimelineFrameSnapshot {
|
||||
participantPositions: Map<number, TimelinePosition>;
|
||||
}
|
||||
|
||||
interface TimelineRoamParticipant {
|
||||
participantId: number;
|
||||
teamId: 100 | 200;
|
||||
assignedLaneZone: SummonersRiftMapZone;
|
||||
baseZone: SummonersRiftMapZone;
|
||||
}
|
||||
|
||||
export interface TimelineFightCluster {
|
||||
startTimeMs: number;
|
||||
endTimeMs: number;
|
||||
@@ -77,11 +84,22 @@ export interface TimelineDeathEvent {
|
||||
nearestAllyDistanceApprox: number | null;
|
||||
}
|
||||
|
||||
export interface TimelineRoamFrame {
|
||||
t: number;
|
||||
participantId: number;
|
||||
teamId: number;
|
||||
x: number;
|
||||
y: number;
|
||||
zone: SummonersRiftMapZone;
|
||||
assignedLaneZone: SummonersRiftMapZone;
|
||||
}
|
||||
|
||||
export interface TimelineDerivedData {
|
||||
fightClusters: TimelineFightCluster[];
|
||||
advantageEvents: TimelineAdvantageEvent[];
|
||||
deathEvents: TimelineDeathEvent[];
|
||||
objectiveWindows: TimelineObjectiveWindow[];
|
||||
roamFrames: TimelineRoamFrame[];
|
||||
}
|
||||
|
||||
const FIGHT_CLUSTER_MAX_GAP_MS = 15_000;
|
||||
@@ -89,6 +107,8 @@ const FIGHT_CLUSTER_MAX_DISTANCE = 3_000;
|
||||
const CLEANUP_WINDOW_MS = 5_000;
|
||||
const OBJECTIVE_WINDOW_BEFORE_MS = 120_000;
|
||||
const OBJECTIVE_WINDOW_AFTER_MS = 30_000;
|
||||
const ROAM_FRAME_START_MS = 8 * 60_000;
|
||||
const ROAM_FRAME_END_MS = 14 * 60_000;
|
||||
const OBJECTIVE_MONSTER_TYPES = new Set([
|
||||
'DRAGON',
|
||||
'RIFTHERALD',
|
||||
@@ -320,6 +340,68 @@ function opposingTeamId(teamId: 100 | 200 | undefined): 100 | 200 | undefined {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function assignedLaneZoneForRole(
|
||||
teamPosition: string | undefined,
|
||||
): SummonersRiftMapZone | undefined {
|
||||
switch (teamPosition) {
|
||||
case 'TOP':
|
||||
return 'topLane';
|
||||
case 'MIDDLE':
|
||||
return 'middleLane';
|
||||
case 'BOTTOM':
|
||||
case 'UTILITY':
|
||||
return 'bottomLane';
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function baseZoneForTeamId(
|
||||
teamId: 100 | 200 | undefined,
|
||||
): SummonersRiftMapZone | undefined {
|
||||
switch (teamId) {
|
||||
case 100:
|
||||
return 'blueBase';
|
||||
case 200:
|
||||
return 'redBase';
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function parseRoamParticipants(
|
||||
rawMatch: Record<string, unknown> | undefined,
|
||||
): TimelineRoamParticipant[] {
|
||||
const info = asRecord(rawMatch?.info);
|
||||
return asArray(info.participants)
|
||||
.map(asRecord)
|
||||
.flatMap((participant) => {
|
||||
const participantId = asParticipantId(participant.participantId);
|
||||
const teamId = toTeamId(participant.teamId);
|
||||
const assignedLaneZone = assignedLaneZoneForRole(
|
||||
asString(participant.teamPosition),
|
||||
);
|
||||
const baseZone = baseZoneForTeamId(teamId);
|
||||
if (
|
||||
participantId === undefined ||
|
||||
teamId === undefined ||
|
||||
assignedLaneZone === undefined ||
|
||||
baseZone === undefined
|
||||
) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
{
|
||||
participantId,
|
||||
teamId,
|
||||
assignedLaneZone,
|
||||
baseZone,
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
function scoringParticipantIds(event: TimelineChampionKillEvent): number[] {
|
||||
return toSortedIds(
|
||||
[
|
||||
@@ -802,10 +884,60 @@ function buildDeathEvents(
|
||||
});
|
||||
}
|
||||
|
||||
function buildRoamFrames(
|
||||
frameSnapshots: TimelineFrameSnapshot[],
|
||||
rawMatch: Record<string, unknown> | undefined,
|
||||
): TimelineRoamFrame[] {
|
||||
const roamParticipants = parseRoamParticipants(rawMatch);
|
||||
if (roamParticipants.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return frameSnapshots.flatMap((frame) => {
|
||||
if (
|
||||
frame.timestamp < ROAM_FRAME_START_MS ||
|
||||
frame.timestamp > ROAM_FRAME_END_MS
|
||||
) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return roamParticipants.flatMap((participant) => {
|
||||
const position = frame.participantPositions.get(
|
||||
participant.participantId,
|
||||
);
|
||||
if (!position) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const zone = classifySummonersRiftPosition(position);
|
||||
if (
|
||||
zone === 'unknown' ||
|
||||
zone === participant.assignedLaneZone ||
|
||||
zone === participant.baseZone
|
||||
) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
{
|
||||
t: frame.timestamp,
|
||||
participantId: participant.participantId,
|
||||
teamId: participant.teamId,
|
||||
x: position.x,
|
||||
y: position.y,
|
||||
zone,
|
||||
assignedLaneZone: participant.assignedLaneZone,
|
||||
},
|
||||
];
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class TimelineDerivedService {
|
||||
public buildDerivedData(
|
||||
timeline: Record<string, unknown>,
|
||||
rawMatch?: Record<string, unknown>,
|
||||
): TimelineDerivedData {
|
||||
const {
|
||||
advantageEvents,
|
||||
@@ -819,6 +951,7 @@ export class TimelineDerivedService {
|
||||
advantageEvents,
|
||||
deathEvents: buildDeathEvents(championKills, frameSnapshots),
|
||||
objectiveWindows: buildObjectiveWindows(eliteMonsterKills),
|
||||
roamFrames: buildRoamFrames(frameSnapshots, rawMatch),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user