Resolve lane opponents during extraction
This commit is contained in:
1 parent
43662a86d8
commit
02538ae300
3 files changed
+81
-3
No files matched your search
@@ -1,5 +1,8 @@
|
||||
import type { Role } from '@persona-lenz/shared';
|
||||
import type { TeamPositionOrUnknown } from '../global/database/schemas';
|
||||
import type {
|
||||
LaneOpponentRef,
|
||||
TeamPositionOrUnknown,
|
||||
} from '../global/database/schemas';
|
||||
import type { RiotPlatformRoute, RiotRegionalRoute } from '../riot/riot.types';
|
||||
|
||||
export interface UserAnalysisJobData {
|
||||
@@ -28,6 +31,7 @@ export interface ExtractedPlayerMatchFeature {
|
||||
normalizationMethod: 'registry-baseline';
|
||||
confidence: number;
|
||||
timelineProcessed: false;
|
||||
laneOpponent?: LaneOpponentRef;
|
||||
}
|
||||
|
||||
export interface BuiltPlayerProfile {
|
||||
|
||||
@@ -78,6 +78,10 @@ describe('FeatureExtractorService', () => {
|
||||
|
||||
expect(feature.matchId).toBe('KR_1');
|
||||
expect(feature.role).toBe('MIDDLE');
|
||||
expect(feature.laneOpponent).toEqual({
|
||||
puuid: 'enemy-puuid',
|
||||
championId: 134,
|
||||
});
|
||||
expect(feature.patch).toBe('26.13');
|
||||
expect(feature.features).toMatchObject({
|
||||
kda: 7,
|
||||
@@ -174,6 +178,43 @@ describe('FeatureExtractorService', () => {
|
||||
expect(feature.confidence).toBe(0.5);
|
||||
});
|
||||
|
||||
it('omits lane opponent and lowers confidence when same-position enemy is missing', () => {
|
||||
const payload = createMatchPayload({
|
||||
participants: [
|
||||
{
|
||||
puuid: 'target-puuid',
|
||||
teamId: 100,
|
||||
teamPosition: 'MIDDLE',
|
||||
championId: 103,
|
||||
kills: 6,
|
||||
deaths: 2,
|
||||
assists: 8,
|
||||
totalDamageDealtToChampions: 24_000,
|
||||
goldEarned: 12_000,
|
||||
totalMinionsKilled: 210,
|
||||
neutralMinionsKilled: 12,
|
||||
visionScore: 24,
|
||||
wardsKilled: 4,
|
||||
detectorWardsPlaced: 3,
|
||||
win: true,
|
||||
},
|
||||
{
|
||||
puuid: 'enemy-puuid',
|
||||
teamId: 200,
|
||||
teamPosition: 'TOP',
|
||||
championId: 266,
|
||||
kills: 4,
|
||||
totalDamageDealtToChampions: 16_000,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const feature = service.extractPlayerMatchFeature(payload, 'target-puuid');
|
||||
|
||||
expect(feature.laneOpponent).toBeUndefined();
|
||||
expect(feature.confidence).toBe(0.7);
|
||||
});
|
||||
|
||||
it('marks known-role short games with short-game confidence only', () => {
|
||||
const payload = createMatchPayload({
|
||||
gameDuration: 900,
|
||||
|
||||
@@ -5,7 +5,10 @@ import {
|
||||
type Role,
|
||||
} from '@persona-lenz/shared';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import type { TeamPositionOrUnknown } from '../global/database/schemas';
|
||||
import type {
|
||||
LaneOpponentRef,
|
||||
TeamPositionOrUnknown,
|
||||
} from '../global/database/schemas';
|
||||
import type { ExtractedPlayerMatchFeature } from './analysis.types';
|
||||
|
||||
interface MatchParticipant {
|
||||
@@ -105,6 +108,31 @@ function resolvePatch(gameVersion: string | undefined): string {
|
||||
return `${major}.${minor}`;
|
||||
}
|
||||
|
||||
function resolveLaneOpponent(
|
||||
participant: MatchParticipant,
|
||||
participants: MatchParticipant[],
|
||||
role: TeamPositionOrUnknown,
|
||||
): LaneOpponentRef | undefined {
|
||||
if (role === 'UNKNOWN' || participant.teamId === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const opponent = participants.find(
|
||||
(candidate) =>
|
||||
candidate.teamId !== participant.teamId &&
|
||||
candidate.teamPosition === role &&
|
||||
typeof candidate.puuid === 'string',
|
||||
);
|
||||
if (!opponent?.puuid) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return {
|
||||
puuid: opponent.puuid,
|
||||
championId: asNumber(opponent.championId),
|
||||
};
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class FeatureExtractorService {
|
||||
public extractPlayerMatchFeature(
|
||||
@@ -178,6 +206,7 @@ export class FeatureExtractorService {
|
||||
};
|
||||
|
||||
const role = resolveRole(participant.teamPosition);
|
||||
const laneOpponent = resolveLaneOpponent(participant, participants, role);
|
||||
const normalizationRole = resolveNormalizationRole(role);
|
||||
const normalized = Object.fromEntries(
|
||||
METRICS.map((metric) => [
|
||||
@@ -201,17 +230,21 @@ export class FeatureExtractorService {
|
||||
vector: METRICS.map((metric) => normalized[metric.id]),
|
||||
featureSchemaVersion: FEATURE_SCHEMA_VERSION,
|
||||
normalizationMethod: 'registry-baseline',
|
||||
confidence: this.resolveConfidence(role, gameDurationSec),
|
||||
confidence: this.resolveConfidence(role, gameDurationSec, laneOpponent),
|
||||
timelineProcessed: false,
|
||||
...(laneOpponent ? { laneOpponent } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
private resolveConfidence(
|
||||
role: TeamPositionOrUnknown,
|
||||
gameDurationSec: number,
|
||||
laneOpponent: LaneOpponentRef | undefined,
|
||||
): number {
|
||||
let confidence = 1;
|
||||
if (role === 'UNKNOWN') confidence = Math.min(confidence, 0.5);
|
||||
if (role !== 'UNKNOWN' && !laneOpponent)
|
||||
confidence = Math.min(confidence, 0.7);
|
||||
if (gameDurationSec < 1200) confidence = Math.min(confidence, 0.8);
|
||||
return confidence;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user