feat: enrich internal match game analysis
This commit is contained in:
1 parent
9f698a8fec
commit
aa675199af
22 files changed
+3123
-241
No files matched your search
@@ -100,6 +100,24 @@ describe('MatchStatsFragmentBuilder', () => {
|
||||
it('builds rich set detail from raw Riot match data', () => {
|
||||
const builder = new MatchStatsFragmentBuilder();
|
||||
const match = makeMatch();
|
||||
const redUserId = new mongoose.Types.ObjectId();
|
||||
match.participants.push({
|
||||
userId: redUserId,
|
||||
puuid: 'puuid-2',
|
||||
gameName: 'Opponent',
|
||||
profileIconId: 8,
|
||||
});
|
||||
match.teams[1].members.push({ userId: redUserId, assignedPosition: 'TOP' });
|
||||
match.result?.games[0].participants.push({
|
||||
userId: redUserId,
|
||||
teamIndex: 2,
|
||||
side: 'red',
|
||||
championId: 24,
|
||||
kills: 1,
|
||||
deaths: 3,
|
||||
assists: 0,
|
||||
win: false,
|
||||
});
|
||||
const raw = {
|
||||
metadata: {
|
||||
dataVersion: '2',
|
||||
@@ -206,6 +224,51 @@ describe('MatchStatsFragmentBuilder', () => {
|
||||
],
|
||||
},
|
||||
};
|
||||
raw.info.participants.push(
|
||||
{
|
||||
...raw.info.participants[0],
|
||||
assists: 0,
|
||||
championId: 24,
|
||||
championName: 'Jax',
|
||||
deaths: 3,
|
||||
kills: 1,
|
||||
participantId: 2,
|
||||
puuid: 'puuid-2',
|
||||
riotIdGameName: 'Opponent',
|
||||
summonerId: 'summoner-2',
|
||||
summonerName: 'Opponent',
|
||||
teamId: 200,
|
||||
win: false,
|
||||
},
|
||||
{
|
||||
...raw.info.participants[0],
|
||||
assists: 2,
|
||||
championId: 64,
|
||||
championName: 'LeeSin',
|
||||
deaths: 0,
|
||||
kills: 1,
|
||||
participantId: 3,
|
||||
puuid: 'puuid-3',
|
||||
riotIdGameName: 'Jungler',
|
||||
summonerId: 'summoner-3',
|
||||
summonerName: 'Jungler',
|
||||
teamId: 100,
|
||||
},
|
||||
);
|
||||
raw.info.teams.push({
|
||||
bans: [],
|
||||
objectives: {
|
||||
baron: { first: false, kills: 0 },
|
||||
champion: { first: false, kills: 3 },
|
||||
dragon: { first: false, kills: 0 },
|
||||
horde: { first: false, kills: 0 },
|
||||
inhibitor: { first: false, kills: 0 },
|
||||
riftHerald: { first: false, kills: 0 },
|
||||
tower: { first: false, kills: 0 },
|
||||
},
|
||||
teamId: 200,
|
||||
win: false,
|
||||
});
|
||||
const timeline = {
|
||||
metadata: {
|
||||
dataVersion: '2',
|
||||
@@ -218,7 +281,20 @@ describe('MatchStatsFragmentBuilder', () => {
|
||||
{
|
||||
timestamp: 0,
|
||||
participantFrames: {
|
||||
'1': { participantId: 1, totalGold: 500, xp: 0 },
|
||||
'1': {
|
||||
participantId: 1,
|
||||
totalGold: 500,
|
||||
xp: 0,
|
||||
minionsKilled: 0,
|
||||
jungleMinionsKilled: 0,
|
||||
},
|
||||
'2': {
|
||||
participantId: 2,
|
||||
totalGold: 500,
|
||||
xp: 0,
|
||||
minionsKilled: 0,
|
||||
jungleMinionsKilled: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -291,7 +367,137 @@ describe('MatchStatsFragmentBuilder', () => {
|
||||
},
|
||||
],
|
||||
participantFrames: {
|
||||
'1': { participantId: 1, totalGold: 1_150, xp: 550 },
|
||||
'1': {
|
||||
participantId: 1,
|
||||
totalGold: 1_150,
|
||||
xp: 550,
|
||||
minionsKilled: 5,
|
||||
jungleMinionsKilled: 1,
|
||||
},
|
||||
'2': {
|
||||
participantId: 2,
|
||||
totalGold: 1_050,
|
||||
xp: 500,
|
||||
minionsKilled: 4,
|
||||
jungleMinionsKilled: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
timestamp: 540_000,
|
||||
events: [
|
||||
{
|
||||
type: 'CHAMPION_KILL',
|
||||
timestamp: 300_000,
|
||||
killerId: 1,
|
||||
victimId: 2,
|
||||
assistingParticipantIds: [3],
|
||||
},
|
||||
{
|
||||
type: 'CHAMPION_KILL',
|
||||
timestamp: 400_000,
|
||||
killerId: 0,
|
||||
victimId: 1,
|
||||
},
|
||||
{
|
||||
type: 'BUILDING_KILL',
|
||||
timestamp: 450_000,
|
||||
killerId: 0,
|
||||
teamId: 200,
|
||||
buildingType: 'TOWER_BUILDING',
|
||||
towerType: 'OUTER_TURRET',
|
||||
},
|
||||
{
|
||||
type: 'BUILDING_KILL',
|
||||
timestamp: 450_000,
|
||||
killerId: 1,
|
||||
teamId: 200,
|
||||
buildingType: 'INHIBITOR_BUILDING',
|
||||
},
|
||||
{
|
||||
type: 'CHAMPION_KILL',
|
||||
timestamp: 500_000,
|
||||
killerId: 3,
|
||||
victimId: 2,
|
||||
assistingParticipantIds: [1],
|
||||
},
|
||||
],
|
||||
participantFrames: {
|
||||
'1': {
|
||||
participantId: 1,
|
||||
totalGold: 4_900,
|
||||
xp: 3_900,
|
||||
minionsKilled: 72,
|
||||
jungleMinionsKilled: 8,
|
||||
},
|
||||
'2': {
|
||||
participantId: 2,
|
||||
totalGold: 4_300,
|
||||
xp: 3_500,
|
||||
minionsKilled: 68,
|
||||
jungleMinionsKilled: 2,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
timestamp: 590_000,
|
||||
events: [],
|
||||
participantFrames: {
|
||||
'1': {
|
||||
participantId: 1,
|
||||
totalGold: 5_200,
|
||||
xp: 4_200,
|
||||
minionsKilled: 80,
|
||||
jungleMinionsKilled: 10,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
timestamp: 900_000,
|
||||
events: [
|
||||
{
|
||||
type: 'CHAMPION_KILL',
|
||||
timestamp: 900_000,
|
||||
killerId: 1,
|
||||
victimId: 2,
|
||||
assistingParticipantIds: [3],
|
||||
},
|
||||
],
|
||||
participantFrames: {
|
||||
'1': {
|
||||
participantId: 1,
|
||||
totalGold: 8_100,
|
||||
xp: 7_300,
|
||||
minionsKilled: 130,
|
||||
jungleMinionsKilled: 15,
|
||||
},
|
||||
'2': {
|
||||
participantId: 2,
|
||||
totalGold: 6_700,
|
||||
xp: 6_100,
|
||||
minionsKilled: 115,
|
||||
jungleMinionsKilled: 5,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
timestamp: 1_800_000,
|
||||
events: [],
|
||||
participantFrames: {
|
||||
'1': {
|
||||
participantId: 1,
|
||||
totalGold: 12_500,
|
||||
xp: 14_000,
|
||||
minionsKilled: 205,
|
||||
jungleMinionsKilled: 23,
|
||||
},
|
||||
'2': {
|
||||
participantId: 2,
|
||||
totalGold: 10_200,
|
||||
xp: 12_700,
|
||||
minionsKilled: 190,
|
||||
jungleMinionsKilled: 10,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
@@ -329,19 +535,105 @@ describe('MatchStatsFragmentBuilder', () => {
|
||||
{
|
||||
timestamp: 0,
|
||||
blue: { gold: 500, xp: 0 },
|
||||
red: { gold: 0, xp: 0 },
|
||||
goldDiff: 500,
|
||||
red: { gold: 500, xp: 0 },
|
||||
goldDiff: 0,
|
||||
xpDiff: 0,
|
||||
},
|
||||
{
|
||||
timestamp: 60,
|
||||
blue: { gold: 1_150, xp: 550 },
|
||||
red: { gold: 1_050, xp: 500 },
|
||||
goldDiff: 100,
|
||||
xpDiff: 50,
|
||||
},
|
||||
{
|
||||
timestamp: 540,
|
||||
blue: { gold: 4_900, xp: 3_900 },
|
||||
red: { gold: 4_300, xp: 3_500 },
|
||||
goldDiff: 600,
|
||||
xpDiff: 400,
|
||||
},
|
||||
{
|
||||
timestamp: 590,
|
||||
blue: { gold: 5_200, xp: 4_200 },
|
||||
red: { gold: 0, xp: 0 },
|
||||
goldDiff: 1_150,
|
||||
xpDiff: 550,
|
||||
goldDiff: 5_200,
|
||||
xpDiff: 4_200,
|
||||
},
|
||||
{
|
||||
timestamp: 900,
|
||||
blue: { gold: 8_100, xp: 7_300 },
|
||||
red: { gold: 6_700, xp: 6_100 },
|
||||
goldDiff: 1_400,
|
||||
xpDiff: 1_200,
|
||||
},
|
||||
{
|
||||
timestamp: 1_800,
|
||||
blue: { gold: 12_500, xp: 14_000 },
|
||||
red: { gold: 10_200, xp: 12_700 },
|
||||
goldDiff: 2_300,
|
||||
xpDiff: 1_300,
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(fragment.gameDetails[0].timelineEvents).toEqual([
|
||||
{
|
||||
timestamp: 20,
|
||||
side: 'blue',
|
||||
type: 'dragon',
|
||||
monsterSubType: 'FIRE_DRAGON',
|
||||
},
|
||||
{
|
||||
timestamp: 30,
|
||||
side: 'blue',
|
||||
type: 'elderDragon',
|
||||
monsterSubType: 'ELDER_DRAGON',
|
||||
},
|
||||
{ timestamp: 40, side: 'blue', type: 'voidGrub' },
|
||||
{ timestamp: 50, side: 'blue', type: 'baron' },
|
||||
{ timestamp: 55, side: 'blue', type: 'riftHerald' },
|
||||
{
|
||||
timestamp: 300,
|
||||
side: 'blue',
|
||||
type: 'championKill',
|
||||
killerParticipantId: 1,
|
||||
victimParticipantId: 2,
|
||||
assistingParticipantIds: [3],
|
||||
},
|
||||
{
|
||||
timestamp: 400,
|
||||
type: 'championKill',
|
||||
victimParticipantId: 1,
|
||||
},
|
||||
{
|
||||
timestamp: 450,
|
||||
side: 'blue',
|
||||
type: 'tower',
|
||||
towerType: 'OUTER_TURRET',
|
||||
},
|
||||
{
|
||||
timestamp: 450,
|
||||
side: 'blue',
|
||||
type: 'inhibitor',
|
||||
killerParticipantId: 1,
|
||||
},
|
||||
{
|
||||
timestamp: 500,
|
||||
side: 'blue',
|
||||
type: 'championKill',
|
||||
killerParticipantId: 3,
|
||||
victimParticipantId: 2,
|
||||
assistingParticipantIds: [1],
|
||||
},
|
||||
{
|
||||
timestamp: 900,
|
||||
side: 'blue',
|
||||
type: 'championKill',
|
||||
killerParticipantId: 1,
|
||||
victimParticipantId: 2,
|
||||
assistingParticipantIds: [3],
|
||||
},
|
||||
]);
|
||||
expect(fragment.gameDetails[0].teams[0].bans).toEqual([
|
||||
{ championId: 14, pickTurn: 1 },
|
||||
{ championId: 43, pickTurn: 2 },
|
||||
@@ -356,6 +648,27 @@ describe('MatchStatsFragmentBuilder', () => {
|
||||
voidGrub: 1,
|
||||
});
|
||||
expect(fragment.records[0]).toMatchObject({
|
||||
participantId: 1,
|
||||
checkpoints: {
|
||||
at10: {
|
||||
timestamp: 590,
|
||||
gold: 5_200,
|
||||
cs: 90,
|
||||
xp: 4_200,
|
||||
kills: 1,
|
||||
deaths: 1,
|
||||
assists: 1,
|
||||
},
|
||||
at15: {
|
||||
timestamp: 900,
|
||||
gold: 8_100,
|
||||
cs: 145,
|
||||
xp: 7_300,
|
||||
kills: 2,
|
||||
deaths: 1,
|
||||
assists: 1,
|
||||
},
|
||||
},
|
||||
championLevel: 15,
|
||||
cs: 228,
|
||||
damageDealtToChampions: 18_765,
|
||||
@@ -392,5 +705,118 @@ describe('MatchStatsFragmentBuilder', () => {
|
||||
{ timestamp: 45, skillSlot: 3, level: 2, levelUpType: 'NORMAL' },
|
||||
],
|
||||
});
|
||||
expect(fragment.records[1]).toMatchObject({
|
||||
participantId: 2,
|
||||
checkpoints: {
|
||||
at15: {
|
||||
timestamp: 900,
|
||||
gold: 6_700,
|
||||
cs: 120,
|
||||
xp: 6_100,
|
||||
kills: 0,
|
||||
deaths: 3,
|
||||
assists: 0,
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(fragment.records[1].checkpoints).not.toHaveProperty('at10');
|
||||
|
||||
const timelineWithoutEvents = {
|
||||
...timeline,
|
||||
info: {
|
||||
...timeline.info,
|
||||
frames: timeline.info.frames.map((frame) => ({
|
||||
...frame,
|
||||
events: [],
|
||||
})),
|
||||
},
|
||||
} as RiotMatchTimelineDto;
|
||||
const objectiveFallback = builder.buildFragment({
|
||||
match,
|
||||
rawByRiotMatchId: new Map([['KR_1', raw as RiotMatchDto]]),
|
||||
timelineByRiotMatchId: new Map([['KR_1', timelineWithoutEvents]]),
|
||||
});
|
||||
expect(objectiveFallback.gameDetails[0].teams[0].objectives).toMatchObject({
|
||||
baron: 1,
|
||||
dragon: 2,
|
||||
elderDragon: 0,
|
||||
riftHerald: 0,
|
||||
voidGrub: 3,
|
||||
});
|
||||
|
||||
const dragonOnlyTimeline = {
|
||||
...timeline,
|
||||
info: {
|
||||
...timeline.info,
|
||||
frames: timeline.info.frames.map((frame) => ({
|
||||
...frame,
|
||||
events: (frame.events ?? []).filter(
|
||||
(event) =>
|
||||
event.type !== 'ELITE_MONSTER_KILL' ||
|
||||
event.monsterType === 'DRAGON',
|
||||
),
|
||||
})),
|
||||
},
|
||||
} as RiotMatchTimelineDto;
|
||||
const partialObjectiveFallback = builder.buildFragment({
|
||||
match,
|
||||
rawByRiotMatchId: new Map([['KR_1', raw as RiotMatchDto]]),
|
||||
timelineByRiotMatchId: new Map([['KR_1', dragonOnlyTimeline]]),
|
||||
});
|
||||
expect(
|
||||
partialObjectiveFallback.gameDetails[0].teams[0].objectives,
|
||||
).toMatchObject({
|
||||
baron: 1,
|
||||
dragon: 1,
|
||||
elderDragon: 1,
|
||||
riftHerald: 0,
|
||||
voidGrub: 3,
|
||||
});
|
||||
|
||||
const shortMatch = {
|
||||
...match,
|
||||
result: {
|
||||
...match.result!,
|
||||
games: match.result!.games.map((game) => ({
|
||||
...game,
|
||||
gameDuration: 599,
|
||||
})),
|
||||
},
|
||||
} as MatchDocument;
|
||||
const shortFragment = builder.buildFragment({
|
||||
match: shortMatch,
|
||||
rawByRiotMatchId: new Map([
|
||||
[
|
||||
'KR_1',
|
||||
{
|
||||
...raw,
|
||||
info: { ...raw.info, gameDuration: 599 },
|
||||
} as RiotMatchDto,
|
||||
],
|
||||
]),
|
||||
timelineByRiotMatchId: new Map([
|
||||
['KR_1', timeline as RiotMatchTimelineDto],
|
||||
]),
|
||||
});
|
||||
expect(
|
||||
shortFragment.records.every((record) => record.checkpoints === undefined),
|
||||
).toBe(true);
|
||||
|
||||
const invalidIntervalTimeline = {
|
||||
...timeline,
|
||||
info: { ...timeline.info, frameInterval: Number.NaN },
|
||||
} as RiotMatchTimelineDto;
|
||||
const invalidIntervalFragment = builder.buildFragment({
|
||||
match,
|
||||
rawByRiotMatchId: new Map([['KR_1', raw as RiotMatchDto]]),
|
||||
timelineByRiotMatchId: new Map([['KR_1', invalidIntervalTimeline]]),
|
||||
});
|
||||
expect(invalidIntervalFragment.gameDetails[0].timelineLoaded).toBe(false);
|
||||
expect(invalidIntervalFragment.gameDetails[0].timeline).toEqual([]);
|
||||
expect(
|
||||
invalidIntervalFragment.records.every(
|
||||
(record) => record.checkpoints === undefined,
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user