SPB Git

spb/qwhpi Public

QHPI — Quebec Housing Price Index: quality-adjusted, hierarchically pooled housing price indexes.

Python 63.9% TypeScript 25.4% CSS 5.5% TeX 3.5% SQL 0.8% Makefile 0.5% Dockerfile 0.5%
1.3 KB · 42 lines python
Raw Blame History
1# =============================================================================2# QWHPI — Quebec Weekly Housing Price Index3# Author  : Simon-Pierre Boucher4# Contact : contact@spboucher.ai5# File    : api/app/routers/meta.py6# Purpose : /v1/meta and /health endpoints.7# =============================================================================8"""Metadata and health endpoints."""910from __future__ import annotations1112import polars as pl13from fastapi import APIRouter1415from app.schemas import MetaResponse16from app.services import data1718router = APIRouter()192021@router.get("/v1/meta", response_model=MetaResponse)22def meta():23    c = data.canonical()24    return MetaResponse(25        model_version=data.model_version(),26        data_vintage=data.data_vintage(),27        series_count=c.select("geography_id", "property_type").unique().height,28        periods=c["period"].n_unique(),29        latest_complete_period=str(30            c.filter(~pl.col("is_partial_month"))["period"].max()),31    )323334@router.get("/health")35def health():36    try:37        rows = data.canonical().height38        return {"status": "ok", "canonical_rows": rows,39                "data_vintage": data.data_vintage()}40    except Exception as exc:  # pragma: no cover41        return {"status": "degraded", "error": str(exc)}42