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

100% Statements 8/8
50% Branches 9/18
100% Functions 5/5
100% Lines 8/8

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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62                                                        2x         2x 4x 2x           2x 4x 2x                 2x                  
/**
 * @module CIA/Loaders/Documents
 * @category Intelligence Platform - Data Acquisition & Pipeline Management
 *
 * @description
 * Builds the parliamentary document activity dashboard from CIA CSV exports.
 * Joins annual document type counts with monthly decision approval trends.
 *
 * @author Hack23 AB - Data Pipeline Engineering
 * @license Apache-2.0
 * @since 2026
 */
 
import type {
  DecisionTrendEntry,
  DocumentActivityDashboard,
  DocumentTypeEntry
} from '../types.js';
import type { LoadCSV } from '../csv-utils.js';
import { CSV_SOURCES } from '../sources.js';
 
/**
 * Build `DocumentActivityDashboard` from CSV sources.
 *
 * @param loadCSV - CSV loader closure
 * @returns Document type and decision trend rows with zero-row filtering
 */
export async function loadDocumentActivity(loadCSV: LoadCSV): Promise<DocumentActivityDashboard> {
  const [docTypeRows, decisionRows] = await Promise.all([
    loadCSV(CSV_SOURCES.annualDocTypes.local),
    loadCSV(CSV_SOURCES.decisionTrends.local)
  ]);
 
  const documentTypes: DocumentTypeEntry[] = docTypeRows
    .filter(r => (r.doc_count as number) > 0)
    .map(r => ({
      year: (r.year as number) || 0,
      documentType: (r.document_type as string) || '',
      docCount: (r.doc_count as number) || 0
    }));
 
  const decisionTrends: DecisionTrendEntry[] = decisionRows
    .filter(r => (r.decision_count as number) > 0)
    .map(r => ({
      year: (r.year as number) || 0,
      month: (r.month as number) || 0,
      decisionCount: (r.decision_count as number) || 0,
      approvedDecisions: (r.approved_decisions as number) || 0,
      rejectedDecisions: (r.rejected_decisions as number) || 0,
      approvalRate: (r.approval_rate as number) || 0
    }));
 
  return {
    title: 'Parliamentary Document Activity',
    description: 'Document production and decision trends from CIA database exports',
    lastUpdated: new Date().toISOString(),
    documentTypes,
    decisionTrends,
    _source: 'csv'
  };
}