범인찾기 C4: 기록 점수 (OP.GG OP스코어 방식) + LOL.PS 라인전
- packages/shared/src/rating.ts: 발로란트(라운드 승률 · KAST · ACS · 피해 격차) · 롤(킬 관여 · 데스 · 딜/받은 피해/골드 비중 · CS · 레벨 · CC · 와드) 0~10 점수, 경기/팀 순위, MVP · ACE, 점수를 올리고 깎은 지표, 롤 15분 맞라인 비교 - 계수: OP.GG 공식 MCP 로 받은 실제 경기의 OP스코어에 맞춤 (tools/opscore-fit). 교차 검증 발로란트 상관 0.968 · 오차 0.49, 롤 상관 0.943 · 오차 0.60 · 팀 최하위 일치 85% - 발로란트 경기 상세에 KAST 라운드 수(5초 트레이드) · 받은 피해 저장 - AI 자료에 '# 기록 점수' 칸, 참가자 줄에 KAST · 피해 격차, OP.GG 에서 경기를 찾을 정보(lookup), 참가자에 태그 · 기록 점수 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,7 +8,9 @@ import type {
|
||||
CulpritRefTarget,
|
||||
MatchPlayer,
|
||||
MatchRound,
|
||||
PlayerRating,
|
||||
} from '@gvr/shared';
|
||||
import { rateLol, rateValorant } from '@gvr/shared';
|
||||
import type { EventRow, MatchRow, Store, UtteranceRow } from './db/db.js';
|
||||
import type { GameManager } from './games/manager.js';
|
||||
import { safeJson, type Timeline } from './timeline.js';
|
||||
@@ -159,6 +161,7 @@ export class Culprit {
|
||||
const sorted = [...raw.filter(isAlly), ...raw.filter((p) => !isAlly(p))];
|
||||
const accounts = this.store.listAccounts();
|
||||
const speakers = new Set(this.usableUtterances(m.id).map((u) => u.user_id));
|
||||
const ratings = ratePlayers(m, det, raw);
|
||||
return sorted.map((p, i) => {
|
||||
const userId = p.puuid ? accounts.find((a) => a.puuid === p.puuid)?.user_id : undefined;
|
||||
return {
|
||||
@@ -169,6 +172,8 @@ export class Culprit {
|
||||
character: p.character ?? null,
|
||||
userId: userId ?? null,
|
||||
voice: !!userId && speakers.has(userId),
|
||||
...(p.tag ? { tag: p.tag } : {}),
|
||||
...(ratings.get(p.puuid) ? { rating: ratings.get(p.puuid) } : {}),
|
||||
hasExtraStats: !!p.stats,
|
||||
};
|
||||
});
|
||||
@@ -218,7 +223,7 @@ export class Culprit {
|
||||
// 참가자
|
||||
if (m.game === 'valorant') {
|
||||
const nRounds = rounds.length || 1;
|
||||
out.push('# 참가자 (번호 이름 팀 요원(역할) K/D/A ACS 라운드당피해 첫킬/첫데스 헤드샷 설치/해체 스킬사용 음성)');
|
||||
out.push('# 참가자 (번호 이름 팀 요원(역할) K/D/A ACS 라운드당피해 KAST 라운드당피해격차 첫킬/첫데스 헤드샷 설치/해체 스킬사용 음성)');
|
||||
for (const p of players) {
|
||||
const s = statsOf(p);
|
||||
const x = s?.stats;
|
||||
@@ -230,6 +235,8 @@ export class Culprit {
|
||||
`${s?.kills ?? 0}/${s?.deaths ?? 0}/${s?.assists ?? 0}`,
|
||||
`ACS${Math.round((s?.score ?? 0) / (x?.rounds || nRounds))}`,
|
||||
x ? `ADR${Math.round((x.damage ?? 0) / (x.rounds || nRounds))}` : 'ADR?',
|
||||
x?.kastRounds !== undefined ? `KAST${Math.round((x.kastRounds / (x.rounds || nRounds)) * 100)}%` : '',
|
||||
x?.damageTaken !== undefined ? `피해격차${signedNum(Math.round(((x.damage ?? 0) - x.damageTaken) / (x.rounds || nRounds)))}` : '',
|
||||
x ? `첫킬${x.firstKills ?? 0}/첫데스${x.firstDeaths ?? 0}` : '',
|
||||
x?.headshotPct !== undefined ? `HS${x.headshotPct}%` : '',
|
||||
x ? `설치${x.plants ?? 0}/해체${x.defuses ?? 0}` : '',
|
||||
@@ -261,6 +268,7 @@ export class Culprit {
|
||||
}
|
||||
}
|
||||
for (const p of players) refs[`s:${p.id}`] = { kind: 'stat', pid: p.id };
|
||||
out.push(...ratingLines(m.game, players));
|
||||
|
||||
// 게임 계정이 연결되지 않은 화자
|
||||
const others = [...new Set(utts.map((u) => u.user_id))].filter((uid) => !byUser.has(uid));
|
||||
@@ -325,10 +333,57 @@ export class Culprit {
|
||||
refs,
|
||||
players: players.map(({ hasExtraStats: _x, ...p }) => p),
|
||||
stats: { utterances: utts.length, utterancesTotal: totalUtts, events: ei, chats: ci, rounds: rounds.length, basic },
|
||||
lookup: {
|
||||
riotMatchId: m.id.replace(/^(val|lol)-/, '') || null,
|
||||
startedAt: realStart(m),
|
||||
endedAt: m.ended_at ?? realStart(m),
|
||||
durationSec: Math.round(((m.ended_at ?? realStart(m)) - realStart(m)) / 1000),
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/** 기록 점수 (OP.GG OP스코어 방식, packages/shared/src/rating.ts). 경기 결과가 없으면 빈 값 */
|
||||
function ratePlayers(m: MatchRow, det: any, list: MatchPlayer[]): Map<string, PlayerRating> {
|
||||
if (det.live || list.length < 2) return new Map();
|
||||
const selfTeam = det.self ? list.find((p) => p.puuid === det.self)?.team : undefined;
|
||||
const raw = list.map((p) => ({ ...p, ally: p.ally ?? (selfTeam ? p.team === selfTeam : false) }));
|
||||
if (m.game === 'valorant') {
|
||||
const rounds: MatchRound[] = det.roundsDetail || [];
|
||||
return rounds.length ? rateValorant(raw, rounds) : new Map();
|
||||
}
|
||||
const minutes = m.ended_at ? (m.ended_at - realStart(m)) / 60000 : 0;
|
||||
if (minutes < 1) return new Map();
|
||||
const win = safeJson<{ win?: boolean | null }>(m.result, {}).win;
|
||||
return rateLol(raw, minutes, typeof win === 'boolean' ? win : null);
|
||||
}
|
||||
|
||||
/** AI 자료의 "기록 점수" 칸: 점수 · 순위 · MVP/ACE · 점수를 올리고 깎은 지표 · 롤 라인전 */
|
||||
function ratingLines(game: string, players: CulpritPlayer[]): string[] {
|
||||
if (!players.some((p) => p.rating)) return [];
|
||||
const head =
|
||||
game === 'valorant'
|
||||
? '# 기록 점수 (0~10, OP.GG OP스코어 방식: 라운드 승률 · KAST · ACS · 피해 격차를 실제 OP.GG 점수에 맞춘 계산. 경기 순위/팀 순위, 경기 평균보다 점수를 올린 강점 · 깎은 약점)'
|
||||
: '# 기록 점수 (0~10, OP.GG OP스코어 방식: 킬 관여 · 데스 · 딜/받은 피해 · 골드 · CS · 레벨 · CC · 와드를 실제 OP.GG 점수에 맞춘 계산. 경기 순위/팀 순위, 경기 평균보다 점수를 올린 강점 · 깎은 약점, 라인전 = LOL.PS 방식 15분 맞라인 상대와의 차)';
|
||||
const out = [head];
|
||||
if (players.some((p) => p.rating?.basic)) out.push('# (추가 지표가 없어 K/D/A · 골드 · CS 같은 기본 기록으로만 낸 점수다)');
|
||||
const idOf = new Map(players.map((p) => [p.puuid, p.id]));
|
||||
for (const p of players) {
|
||||
const r = p.rating;
|
||||
if (!r) continue;
|
||||
const up = r.parts.filter((x) => x.good).map((x) => x.text);
|
||||
const down = r.parts.filter((x) => !x.good).map((x) => x.text);
|
||||
const parts = [up.length ? `강점 ${up.join(', ')}` : '', down.length ? `약점 ${down.join(', ')}` : ''].filter(Boolean).join(' / ');
|
||||
const lane = r.lane ? ` 라인전(15분 vs ${idOf.get(r.lane.vs) ?? '?'}) CS${signedNum(r.lane.cs)} 골드${signedNum(r.lane.gold)} 경험치${signedNum(r.lane.xp)}` : '';
|
||||
out.push(`${p.id} ${r.score.toFixed(1)}점 ${r.rank}위/팀${r.teamRank}위${r.badge ? ` ${r.badge}` : ''}${parts ? ` · ${parts}` : ''}${lane ? ` ·${lane}` : ''}`);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function signedNum(n: number): string {
|
||||
return `${n >= 0 ? '+' : ''}${n.toLocaleString('en-US')}`;
|
||||
}
|
||||
|
||||
function realStart(m: MatchRow): number {
|
||||
return m.started_at + m.clock_offset;
|
||||
}
|
||||
|
||||
@@ -381,8 +381,8 @@ export function processMatchDetails(md: any, selfPuuid: string, assets: GameAsse
|
||||
combat[i] = prev !== null ? prev + avg : next !== null ? next : BUY_MS + i * avg;
|
||||
}
|
||||
// 범인찾기용 선수별 누적 지표
|
||||
const tallies: Record<string, { damage: number; head: number; shots: number; firstKills: number; firstDeaths: number; plants: number; defuses: number }> = {};
|
||||
const tally = (puuid: string) => (tallies[puuid] ||= { damage: 0, head: 0, shots: 0, firstKills: 0, firstDeaths: 0, plants: 0, defuses: 0 });
|
||||
const tallies: Record<string, Tally> = {};
|
||||
const tally = (puuid: string) => (tallies[puuid] ||= { damage: 0, taken: 0, head: 0, shots: 0, firstKills: 0, firstDeaths: 0, plants: 0, defuses: 0, kast: 0 });
|
||||
// 공격 팀: 전반 12라운드는 Red, 후반은 Blue, 연장은 매 라운드 바뀜. 스파이크를 설치한 팀이 공격이므로 설치 기록이 반대면 뒤집는다
|
||||
const ruleAttacker = (i: number) => (i < 12 ? 'Red' : i < 24 ? 'Blue' : i % 2 === 0 ? 'Red' : 'Blue');
|
||||
let agree = 0;
|
||||
@@ -420,6 +420,7 @@ export function processMatchDetails(md: any, selfPuuid: string, assets: GameAsse
|
||||
const t = tally(ps.subject);
|
||||
t.damage += dmg;
|
||||
for (const d of ps.damage || []) {
|
||||
if (d.receiver) tally(d.receiver).taken += d.damage ?? 0;
|
||||
t.head += d.headshots ?? 0;
|
||||
t.shots += (d.headshots ?? 0) + (d.bodyshots ?? 0) + (d.legshots ?? 0);
|
||||
}
|
||||
@@ -456,6 +457,7 @@ export function processMatchDetails(md: any, selfPuuid: string, assets: GameAsse
|
||||
if (kills[0].killer) tally(kills[0].killer).firstKills++;
|
||||
if (kills[0].victim) tally(kills[0].victim).firstDeaths++;
|
||||
}
|
||||
for (const puuid of kastRound(r, kills, players)) tally(puuid).kast++;
|
||||
for (const k of kills) {
|
||||
const killer = ref(k.killer);
|
||||
const victim = ref(k.victim)!;
|
||||
@@ -573,12 +575,41 @@ export function processMatchDetails(md: any, selfPuuid: string, assets: GameAsse
|
||||
};
|
||||
}
|
||||
|
||||
function playerStats(p: any, t: { damage: number; head: number; shots: number; firstKills: number; firstDeaths: number; plants: number; defuses: number } | undefined, assets: GameAssets): PlayerStats {
|
||||
type Tally = { damage: number; taken: number; head: number; shots: number; firstKills: number; firstDeaths: number; plants: number; defuses: number; kast: number };
|
||||
|
||||
/** 트레이드로 치는 시간: 죽은 뒤 이 안에 팀원이 그 킬러를 잡으면 (vlr · tracker.gg 와 같은 5초) */
|
||||
const TRADE_MS = 5000;
|
||||
|
||||
/** 이 라운드에서 KAST(킬 · 어시 · 생존 · 트레이드 중 하나)를 한 선수 */
|
||||
export function kastRound(r: any, kills: any[], players: Record<string, any>): string[] {
|
||||
const out: string[] = [];
|
||||
for (const ps of r.playerStats || []) {
|
||||
const me = ps.subject;
|
||||
if (kills.some((k) => k.killer === me || (k.assistants || []).includes(me))) {
|
||||
out.push(me);
|
||||
continue;
|
||||
}
|
||||
const death = kills.find((k) => k.victim === me);
|
||||
if (!death) {
|
||||
out.push(me);
|
||||
continue;
|
||||
}
|
||||
const traded = kills.some(
|
||||
(k) => k.victim === death.killer && k.gameTime >= death.gameTime && k.gameTime - death.gameTime <= TRADE_MS && players[k.killer]?.teamId === players[me]?.teamId,
|
||||
);
|
||||
if (traded) out.push(me);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function playerStats(p: any, t: Tally | undefined, assets: GameAssets): PlayerStats {
|
||||
const ac = p.stats?.abilityCasts;
|
||||
return {
|
||||
role: assets.agentRole(p.characterId) ?? undefined,
|
||||
rounds: p.stats?.roundsPlayed ?? undefined,
|
||||
damage: t?.damage ?? 0,
|
||||
damageTaken: t?.taken ?? 0,
|
||||
kastRounds: t?.kast ?? 0,
|
||||
headshotPct: t && t.shots ? Math.round((t.head / t.shots) * 100) : undefined,
|
||||
firstKills: t?.firstKills ?? 0,
|
||||
firstDeaths: t?.firstDeaths ?? 0,
|
||||
|
||||
Reference in New Issue
Block a user