All files / src/browser/cia/loaders ministries.ts

100% Statements 6/6
58.33% Branches 7/12
100% Functions 4/4
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47                                                2x   2x 5x 3x               1x   2x                
/**
 * @module CIA/Loaders/Ministries
 * @category Intelligence Platform - Data Acquisition & Pipeline Management
 *
 * @description
 * Builds the ministry effectiveness dashboard from CIA CSV exports.
 * Filters out rows without a ministry name or zero documents produced.
 *
 * @author Hack23 AB - Data Pipeline Engineering
 * @license Apache-2.0
 * @since 2026
 */
 
import type { MinistryDashboard, MinistryEntry } from '../types.js';
import type { LoadCSV } from '../csv-utils.js';
import { CSV_SOURCES } from '../sources.js';
 
/**
 * Build `MinistryDashboard` from CSV sources.
 *
 * @param loadCSV - CSV loader closure
 * @returns Ministry effectiveness rows sorted by documents produced descending
 */
export async function loadMinistryDashboard(loadCSV: LoadCSV): Promise<MinistryDashboard> {
  const rows = await loadCSV(CSV_SOURCES.ministryEffectiveness.local);
 
  const ministries: MinistryEntry[] = rows
    .filter(r => r.ministry_name && (r.documents_produced as number) > 0)
    .map(r => ({
      name: r.ministry_name as string,
      effectiveness: (r.effectiveness_assessment as string) || '',
      documentsProduced: (r.documents_produced as number) || 0,
      governmentBills: (r.government_bills as number) || 0,
      year: (r.year as number) || 0,
      quarter: (r.quarter as number) || 0
    }))
    .sort((a, b) => b.documentsProduced - a.documentsProduced);
 
  return {
    title: 'Ministry Performance',
    description: 'Ministry effectiveness from CIA database exports',
    lastUpdated: new Date().toISOString(),
    ministries,
    _source: 'csv'
  };
}