This project contains tools for analyzing delivery coverage data and generating visualizations and statistics.
The project is organized into the following directories:
- run_coverage.py - Main entry point for generating Coverage HTML reports and visualizations
- run_report_generator.py - Launches a GUI interface for generating additional specialized reports
- src/ - Contains all the source code organized into modules:
-
coverage_master.py- The main command that coordinates the coverage analysis workflow -
create_delivery_map.py- Creates an interactive map of delivery units -
create_statistics.py- Generates statistical analysis and visualizations -
create_flw_views.py- Generates Field-Level Worker performance analysis -
opportunity_comparison_statistics.py- Generates comparison statistics between opportunities -
report_generator_gui.py- GUI interface for report generation -
models/ - Data models for coverage analysis:
coverage_data.py- Main coverage data modeldelivery_unit.py- Delivery unit data modelflw.py- Field-Level Worker data modelservice_delivery_point.py- Service delivery point data modelservice_area.py- Service area data model
-
utils/ - Utility functions and data handling:
data_loader.py- Data loading utility functionssuperset_export.py- Superset data export utilities
-
reports/ - Specialized report generation modules:
base_report.py- Base class for report generationmicroplan_review.py- Microplan review report generatorflw_visit_count.py- FLW visit count analysis report
-
- Coverage Data Guide - Comprehensive guide explaining the data flow into the CoverageData object and data dictionary for all models
- tests/ - Contains unit tests for the application
- data/ - Directory for input data files
This requires numerous Python packages, You can install them with:
pip install -r requirements.txt
You will need to create a .env file that includes:
COMMCARE_API_KEY
COMMCARE_USERNAME
USE_API=TRUE or False
OPPORTUNITY_DOMAIN_MAPPING={"ZEGCAWIS | CHC Givewell Scale Up": "ccc-chc-zegcawis-2024-25", "COWACDI | CHC Givewell Scale Up": "ccc-chc-cowacdi-2024-25", "Name of Opp in Connect": "Name of project space in HQ"}
SUPERSET_URL
SUPERSET_USERNAME
SUPERSET_PASSWORD
SUPERSET_QUERY_ID
The simplest way to use these tools is through the main entry point script:
python run_coverage.py
This will:
- Load environment variables from .env file (including API credentials and opportunity-domain mappings)
- Check if USE_API is set to True in environment variables:
- API Mode: Load service delivery data from Superset, then fetch delivery unit data from CommCare API for each opportunity found in the CSV
- Local File Mode: Prompt you to select input Excel and CSV files (if there is only one excel and/or one csv, it will use those without asking)
- Create coverage data objects for each project/opportunity (Local File Mode will only let you select on xls and csv, API mode must be used for multiple oppurtunities)
- Create a timestamped output directory (unless custom directory specified)
- For each project, generate outputs in separate subdirectories:
- Generate the delivery map
- Generate the statistics report
- Generate the FLW analysis report
- Create a main index HTML dashboard page linking to all project reports
- Automatically open the dashboard in your default web browser
The tools expect input files:
-
Excel File (Delivery Unit Data Exported from CommCareHQ if using local mode) - Contains delivery unit data with the following columns like:
- du_id
- service_area or service_area_number
- buildings
- delivery_count
- delivery_target
- du_status
- owner_name (used as FLW identifier)
- WKT (geographic boundaries)
- surface_area
-
CSV File (Service Delivery Data exported from Connect Superset) - Contains service delivery points with columns like:
- lattitude, longitude (coordinates)
- flw_id, flw_name (field worker identifiers)
- service_date or date (when available)
When in API mode, if the Superset query contains multiple oppurtunities, Delivery Unit data for each oppurtunityw will be retrieved.