114 lines
3.6 KiB
TypeScript
114 lines
3.6 KiB
TypeScript
import { HydratedDocument, Schema } from 'mongoose';
|
|
import {
|
|
MongooseTimestamps,
|
|
NORMALIZATION_METHODS,
|
|
NormalizationMethod,
|
|
TEAM_POSITIONS,
|
|
TeamPosition,
|
|
} from './common';
|
|
|
|
export interface ChampionPoolEntry {
|
|
championId: number;
|
|
games: number;
|
|
wins: number;
|
|
}
|
|
|
|
const ChampionPoolEntrySubSchema = new Schema<ChampionPoolEntry>(
|
|
{
|
|
championId: { type: Number, required: true },
|
|
games: { type: Number, required: true, default: 0 },
|
|
wins: { type: Number, required: true, default: 0 },
|
|
},
|
|
{ _id: false },
|
|
);
|
|
|
|
const RoleDistributionSubSchema = new Schema<
|
|
Partial<Record<TeamPosition, number>>
|
|
>(
|
|
{
|
|
TOP: { type: Number },
|
|
JUNGLE: { type: Number },
|
|
MIDDLE: { type: Number },
|
|
BOTTOM: { type: Number },
|
|
UTILITY: { type: Number },
|
|
},
|
|
{ _id: false },
|
|
);
|
|
|
|
/**
|
|
* 최근 N게임을 집계한 플레이어 프로필. Atlas Vector Search의 검색 대상 컬렉션.
|
|
*
|
|
* $vectorSearch는 같은 컬렉션의 필드로만 filter할 수 있으므로,
|
|
* 검색 필터에 필요한 값(tier, isSeed 등)을 profile build 시점에 account에서 비정규화해 저장한다.
|
|
* Vector Search 인덱스 정의는 docs/PLAN.md §12.3 (MVP 3에서 생성).
|
|
*/
|
|
export interface PlayerProfile extends MongooseTimestamps {
|
|
puuid: string;
|
|
queueId: number; // MVP 1은 420(솔로랭크) 고정
|
|
mainRole: TeamPosition;
|
|
roleDistribution: Partial<Record<TeamPosition, number>>; // 게임 수 비율 0~1
|
|
sampleGameCount: number;
|
|
championPool: ChampionPoolEntry[]; // games 내림차순. re-rank의 championPoolSim에 사용
|
|
|
|
profile: Record<string, number>; // metricId → 집계된 0~1 값
|
|
vector: number[];
|
|
featureSchemaVersion: number;
|
|
normalizationMethod: NormalizationMethod;
|
|
confidence: number;
|
|
patches: string[]; // 집계에 포함된 패치 목록
|
|
lastMatchAt?: Date; // 집계에 포함된 가장 최근 게임 시각. recency re-rank용
|
|
|
|
// ---- MVP 3: $vectorSearch filter용 비정규화 (build 시점 account.tiers에서 복사) ----
|
|
tier?: string; // RANKED_SOLO_5x5 기준. 'MASTER' 등
|
|
division?: string; // 'I'~'IV' (Master+는 없음)
|
|
leaguePoints?: number;
|
|
isSeed: boolean;
|
|
}
|
|
|
|
export const PlayerProfileSchema = new Schema<PlayerProfile>(
|
|
{
|
|
puuid: { type: String, required: true },
|
|
queueId: { type: Number, required: true },
|
|
mainRole: { type: String, enum: TEAM_POSITIONS, required: true },
|
|
roleDistribution: {
|
|
type: RoleDistributionSubSchema,
|
|
required: true,
|
|
default: () => ({}),
|
|
},
|
|
sampleGameCount: { type: Number, required: true },
|
|
championPool: {
|
|
type: [ChampionPoolEntrySubSchema],
|
|
required: true,
|
|
default: [],
|
|
},
|
|
|
|
profile: { type: Schema.Types.Mixed, required: true, default: () => ({}) },
|
|
vector: { type: [Number], required: true, default: [] },
|
|
featureSchemaVersion: { type: Number, required: true },
|
|
normalizationMethod: {
|
|
type: String,
|
|
enum: NORMALIZATION_METHODS,
|
|
required: true,
|
|
default: 'registry-baseline',
|
|
},
|
|
confidence: { type: Number, required: true, default: 1 },
|
|
patches: { type: [String], required: true, default: [] },
|
|
lastMatchAt: { type: Date },
|
|
|
|
tier: { type: String },
|
|
division: { type: String },
|
|
leaguePoints: { type: Number },
|
|
isSeed: { type: Boolean, required: true, default: false },
|
|
},
|
|
{
|
|
timestamps: true,
|
|
collection: 'player_profile',
|
|
},
|
|
);
|
|
|
|
PlayerProfileSchema.index({ puuid: 1, queueId: 1 }, { unique: true });
|
|
// 운영 조회용 (유사 유저 검색 자체는 Atlas Vector Search 인덱스 사용)
|
|
PlayerProfileSchema.index({ isSeed: 1, mainRole: 1, tier: 1 });
|
|
|
|
export type PlayerProfileDocument = HydratedDocument<PlayerProfile>;
|