feat: add area score model runs

This commit is contained in:
2026-06-24 11:34:56 +08:00
parent e5d95c0598
commit db09615004
9 changed files with 853 additions and 8 deletions

View File

@@ -180,6 +180,45 @@ export type ImportExecutionResponse = {
status: string;
};
export type ModelRun = {
model_run_id: number;
model_name: string;
model_version: string;
target_month: string;
status: string;
parameters: Record<string, unknown>;
started_at: string;
finished_at: string | null;
row_count: number | null;
error_message: string | null;
};
export type CreateAreaScoreModelRun = {
month: string;
model_version?: string;
};
export type AreaScoreModelRunResponse = {
model_run: ModelRun;
scores: AreaScore[];
};
export type AreaScoreLineage = {
area_id: string;
area_name: string;
month: string;
investment_score: number;
model_run_id: number | null;
model_version: string;
ingestion_run_id: number | null;
raw_artifact_id: number | null;
raw_uri: string | null;
sha256: string | null;
source_name: string | null;
metric_updated_at: string;
score_computed_at: string;
};
const API_BASE_URL =
process.env.NEXT_PUBLIC_API_BASE_URL?.replace(/\/$/, "") ?? "http://127.0.0.1:8080";
@@ -266,6 +305,24 @@ export async function executeImport(
});
}
export async function createAreaScoreModelRun(
payload: CreateAreaScoreModelRun,
): Promise<AreaScoreModelRunResponse> {
return fetchJson("/api/v1/model-runs/area-scores", {
method: "POST",
body: JSON.stringify(payload),
});
}
export async function fetchAreaScoreLineage(
areaId: string,
month: string,
): Promise<AreaScoreLineage> {
return fetchJson(
`/api/v1/areas/${encodeURIComponent(areaId)}/score-lineage?month=${encodeURIComponent(month)}`,
);
}
async function fetchJson<T>(path: string, init?: RequestInit): Promise<T> {
const response = await fetch(`${API_BASE_URL}${path}`, {
...init,