| """Shared cached data loaders for the Streamlit app.""" | |
| from pathlib import Path | |
| import pandas as pd | |
| import streamlit as st | |
| repo_root = Path(__file__).resolve().parent | |
| facilities_csv = repo_root / "market_intel" / "data" / "fasyankes_satusehat_20260719.csv" | |
| vendors_csv = repo_root / "market_intel" / "data" / "vendors_satusehat_20260719.csv" | |
| snapshot_date = "2026-07-19" | |
| # facility-type display order (main categories in the SATUSEHAT list) | |
| type_options = [ | |
| "Klinik", | |
| "Tempat Praktik Mandiri Tenaga Kesehatan", | |
| "Pusat Kesehatan Masyarakat", | |
| "Rumah Sakit", | |
| "Laboratorium Kesehatan", | |
| ] | |
| def load_facilities(): | |
| df = pd.read_csv(facilities_csv, encoding="utf-8-sig") | |
| df["create_at"] = pd.to_datetime(df["create_at"]) | |
| df["month"] = df["create_at"].dt.to_period("M").dt.to_timestamp() | |
| df["is_klinik"] = df["type_facility"].str.contains("Klinik", na=False) | |
| return df | |
| def load_vendors(): | |
| return pd.read_csv(vendors_csv, encoding="utf-8-sig") | |
| def monthly_adoption(): | |
| """Long-form monthly counts for the adoption chart (two fixed series).""" | |
| df = load_facilities() | |
| all_m = df.groupby("month").size().rename("count").reset_index() | |
| all_m["series"] = "All facilities" | |
| kl_m = df[df["is_klinik"]].groupby("month").size().rename("count").reset_index() | |
| kl_m["series"] = "Klinik" | |
| return pd.concat([all_m, kl_m], ignore_index=True) | |