get_database_stats
Retrieve database statistics including entry counts, available years, and insurers to understand the scope of Swiss health insurance premium data for analysis.
Instructions
Zeigt Statistiken zur Datenbank (Anzahl Einträge, verfügbare Jahre, Versicherer).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:425-464 (handler)The main handler function that executes the tool logic. It queries the Supabase database for counts of premiums, insurers, and locations; determines available years by checking counts per year; computes unique insurers from premiums; and formats statistics into a markdown-like string response.async function getDatabaseStats(): Promise<string> { const db = getSupabase(); // Hole Statistiken const [premiumsCount, insurersCount, locationsCount] = await Promise.all([ db.from("premiums").select("*", { count: "exact", head: true }), db.from("insurers").select("*", { count: "exact", head: true }), db.from("locations").select("*", { count: "exact", head: true }) ]); // Prüfe welche Jahre Daten haben (effizienter als alle Zeilen zu holen) const yearsToCheck = [2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026]; const yearChecks = await Promise.all( yearsToCheck.map(year => db.from("premiums").select("year", { count: "exact", head: true }).eq("year", year) ) ); const availableYears = yearsToCheck.filter((year, index) => yearChecks[index].count && yearChecks[index].count > 0 ); // Hole Anzahl unique Versicherer aus premiums (statt insurers-Tabelle) const { data: insurerSample } = await db .from("premiums") .select("insurer_id") .limit(10000); const uniqueInsurers = new Set(insurerSample?.map(p => p.insurer_id) || []); let result = `📊 Datenbank-Statistiken\n\n`; result += `📋 Tabellen:\n`; result += ` • premiums: ${premiumsCount.count?.toLocaleString("de-CH")} Einträge\n`; result += ` • insurers: ${uniqueInsurers.size} aktive Versicherer\n`; result += ` • locations: ${locationsCount.count?.toLocaleString("de-CH")} PLZ-Einträge\n\n`; result += `📅 Verfügbare Jahre: ${availableYears.join(", ")}\n\n`; result += `🔗 Datenquelle: BAG Priminfo (priminfo.admin.ch)\n`; return result; }
- src/index.ts:193-197 (schema)The input schema definition for the tool, specifying no required parameters (empty object).inputSchema: { type: "object" as const, properties: {}, required: [] }
- src/index.ts:190-199 (registration)Tool registration in the TOOLS array used for listing available tools via ListToolsRequestHandler.{ name: "get_database_stats", description: "Zeigt Statistiken zur Datenbank (Anzahl Einträge, verfügbare Jahre, Versicherer).", inputSchema: { type: "object" as const, properties: {}, required: [] } } ];
- src/index.ts:504-506 (registration)Registration in the switch statement of the CallToolRequestHandler that dispatches execution to the handler function.case "get_database_stats": result = await getDatabaseStats(); break;