Add data infrastructure modules

This commit is contained in:
dahyeon committed 2026-07-02 13:35:34 -07:00
1 parent b4196c6afe
commit 4115646d66
60 files changed
+9642 -2

No files matched your search

@@ -0,0 +1,50 @@
import { HydratedDocument, Schema } from 'mongoose';
import { MongooseTimestamps, TEAM_POSITIONS, TeamPosition } from './common';
export type BaselineCohort = 'MASTER_PLUS' | 'ALL';
export const BASELINE_COHORTS: BaselineCohort[] = ['MASTER_PLUS', 'ALL'];
/**
* metricId × role × cohort × patch 조합별 인구 분위값 (MVP 3, docs/PLAN.md §12.2).
* 정규화 v2(population-percentile)의 근거 데이터. baseline-computation 잡이 생성한다.
*/
export interface MetricBaseline extends MongooseTimestamps {
metricId: string;
role: TeamPosition;
cohort: BaselineCohort;
patch: string; // '26.13' 또는 'ALL'
featureSchemaVersion: number;
sampleCount: number;
/** p5~p95, 5% 간격 19개 분위값. 정규화 = 선형 보간 percentile rank */
percentileBreakpoints: number[];
computedAt: Date;
}
export const MetricBaselineSchema = new Schema<MetricBaseline>(
{
metricId: { type: String, required: true },
role: { type: String, enum: TEAM_POSITIONS, required: true },
cohort: {
type: String,
enum: BASELINE_COHORTS,
required: true,
default: 'MASTER_PLUS',
},
patch: { type: String, required: true, default: 'ALL' },
featureSchemaVersion: { type: Number, required: true },
sampleCount: { type: Number, required: true, default: 0 },
percentileBreakpoints: { type: [Number], required: true, default: [] },
computedAt: { type: Date, required: true, default: Date.now },
},
{
timestamps: true,
collection: 'metric_baseline',
},
);
MetricBaselineSchema.index(
{ metricId: 1, role: 1, cohort: 1, patch: 1, featureSchemaVersion: 1 },
{ unique: true },
);
export type MetricBaselineDocument = HydratedDocument<MetricBaseline>;