Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
f755aea
Add Gravity Forms integration with quiz data hashing and category map…
Copilot Mar 27, 2026
dfb8ea6
Improve field extraction to support both custom names and Gravity For…
Copilot Mar 27, 2026
ecfaf09
Address code review feedback: add constants, caching, and security do…
Copilot Mar 27, 2026
1db876a
Merge branch 'main' of https://github.com/OpenNews/emergencymode.news…
tiffehr Mar 27, 2026
9641c9e
Merge branch 'staging' of https://github.com/OpenNews/emergencymode.n…
tiffehr Mar 27, 2026
0ededb8
Reduce EMFN_Gravity_Forms_Handler; some logic moved client-side for e…
tiffehr Mar 27, 2026
977b88a
Update pre-commit hooks to ensure filenames are passed and scripts al…
tiffehr Mar 27, 2026
0c8a79d
Refactor Gravity Forms integration: move hashing logic to client-side…
tiffehr Mar 27, 2026
21a04b9
Split custom functionality into two plugins: risk assessment (client-…
tiffehr Apr 3, 2026
867ad5a
rename plugin to `emfn-action-pack-plugin`; lotta optimizations
tiffehr Apr 3, 2026
b470d10
Update .gitignore to cover Override dev-tools plugin residue and zip …
tiffehr Apr 4, 2026
9c34473
refactor Gravity Forms integration for improved form handling and sub…
tiffehr Apr 4, 2026
d984337
Cleanup `sessionStorage` and hashing logic
tiffehr Apr 4, 2026
39200bb
Fix comment formatting in main plugin class header
tiffehr Apr 4, 2026
7c3a4a0
Update .gitignore and notebooks to reflect plugin name change to `emf…
tiffehr Apr 4, 2026
c28bb05
Update README.md
tiffehr Apr 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ xmlrpc.php
license.txt
readme.html

# dev tools short-term integrations
plugins/emfn-action-pack-plugin/assets/js/emergencymode.newspackstaging.com/
plugins/emfn-rich-search-plugin/assets/js/emergencymode.newspackstaging.com/
plugins/*.zip

# Environment / config
.env
wp-config.php
Expand All @@ -31,7 +36,8 @@ build/
vendor/

# ZIP of plugin
emfn-behavior-plugin.zip
emfn-action-pack-plugin.zip
emfn-rich-search-plugin.zip

# IDE / editor
.idea/
Expand Down
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ repos:
name: Strip notebook outputs
entry: scripts/strip-notebook-outputs.sh
language: system
pass_filenames: true
always_run: false
files: ^notebooks/.*\.ipynb$
- id: check-notebooks-clean
name: Check notebooks are clean
entry: scripts/check-notebooks-clean.sh
language: system
pass_filenames: true
always_run: false
files: ^notebooks/.*\.ipynb$
261 changes: 166 additions & 95 deletions README.md

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "esnext",
"moduleDetection": "force",
"checkJs": false,
"lib": ["DOM", "ES2022"]
},
"include": [
"plugins/**/*.js",
"plugins/**/*.d.ts"
],
"exclude": [
"node_modules",
".venv",
"tmp"
]
}
4 changes: 2 additions & 2 deletions notebooks/CA-MX_disaster_risk_analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"\n",
"## The core problem\n",
"\n",
"The client-side JS in `emfn-behavior-plugin.js` works like this for US users:\n",
"The client-side JS in `emfn-risk-assessment-plugin.js` works like this for US users:\n",
Comment thread
tiffehr marked this conversation as resolved.
"\n",
"```\n",
"Google Places v2 (address) → lat/lng\n",
Expand Down Expand Up @@ -518,7 +518,7 @@
"---\n",
"\n",
"**Next step:** implement Option A in `CA-MX_disaster_risk_analysis.ipynb`\n",
"and the corresponding JS change in `emfn-behavior-plugin.js`."
"and the corresponding JS change in `emfn-risk-assessment-plugin.js`."
]
}
],
Expand Down
4 changes: 2 additions & 2 deletions notebooks/FIPS_risk_lookup_dev.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"source": [
"# FIPS Risk Lookup (Notebook Dev Tool)\n",
"\n",
"Notebook version of the standalone lookup tool. It reads FEMA NRI state CSV files from `plugins/emfn-behavior-plugin/assets/data/` and renders county hazard results directly in notebook output.\n",
"Notebook version of the standalone lookup tool. It reads FEMA NRI state CSV files from `plugins/emfn-action-pack-plugin/assets/data/` and renders county hazard results directly in notebook output.\n",
"\n",
"## Usage\n",
"1. Run all cells in order.\n",
Expand All @@ -28,7 +28,7 @@
"from IPython.display import HTML, display\n",
"\n",
"RISK_THRESHOLD = 50.0\n",
"DATA_DIR = Path.cwd().parent / \"plugins\" / \"emfn-behavior-plugin\" / \"assets\" / \"data\"\n",
"DATA_DIR = Path.cwd().parent / \"plugins\" / \"emfn-action-pack-plugin\" / \"assets\" / \"data\"\n",
"\n",
Comment thread
tiffehr marked this conversation as resolved.
"NRI_HAZARD_LABELS = {\n",
" \"avln\": \"Avalanche\",\n",
Expand Down
107 changes: 65 additions & 42 deletions notebooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,47 @@

## Overview

Three notebooks:
The notebooks in this directory support the EMFN Action Pack plugin's location-based risk workflow.

- **`US_disaster_risk_analysis.ipynb`** — downloads FEMA NRI data and generates
per-state CSV files for US states + DC.
- **`CA-MX_disaster_risk_analysis.ipynb`** — research notebook documenting the data
source and client-side lookup gap for Canada and Mexico. Makes live calls to
ThinkHazard and FCC APIs to demonstrate the issues. Does not yet generate output files.
- **`FIPS_risk_lookup_dev.ipynb`** — notebook-native county FIPS lookup UI for local
testing. Reads generated CSVs from `plugins/emfn-behavior-plugin/assets/data/` and
renders hazard results in notebook output.
Current notebooks:

## Setup
- **`US_disaster_risk_analysis.ipynb`** downloads FEMA National Risk Index county data and generates per-state CSV files for US states plus DC.
- **`CA-MX_disaster_risk_analysis.ipynb`** is a research notebook that documents the data and lookup gaps for Canada and Mexico. It makes exploratory live API calls but does not currently generate runtime output files for the site.
- **`FIPS_risk_lookup_dev.ipynb`** is a notebook-native lookup and rendering tool for local testing against the generated CSVs.

This project uses `uv` for dependency management.
## Current Output Location

Preferred workflow: open the repository in the VS Code devcontainer first, then run:
Generated runtime data for the Action Pack plugin lives in:

```bash
uv sync
uv run jupyter lab
```

Then open any notebook in `notebooks/`.

### Why the devcontainer matters

Notebook execution depends on a specific Python environment and supporting tooling. The devcontainer provides that baseline automatically so results are consistent across machines.
`plugins/emfn-action-pack-plugin/assets/data/`

- Standardized OS/runtime (Debian + configured Python stack)
- Automatic setup via `.devcontainer/setup.sh` (installs `uv` and project deps)
- Fewer environment-specific failures from local Python/package differences
That directory currently contains committed US state files plus DC:

Using the devcontainer is the easiest way to keep notebook outputs reproducible and avoid setup issues.
- `AK.csv` through `WY.csv`
- `DC.csv`

## Data source
There are no committed Canada or Mexico runtime CSVs in the current branch.

- **[FEMA National Risk Index (NRI)](https://hazards.fema.gov/nri/data-resources)**:
18 natural-hazard risk scores for every US county (December 2025, v3).
Downloaded automatically on first run and cached in `notebooks/cache/`.
## Data Source

Canadian provinces and Mexican states use mocked data (no equivalent public
source is available via FEMA or RAPT).
- **[FEMA National Risk Index (NRI)](https://hazards.fema.gov/nri/data-resources)** provides the county-level US hazard data used by the US notebook.
- The cached upstream county table is stored in `notebooks/cache/NRI_Table_Counties.csv` after download.
- Canada and Mexico work is still exploratory; this repo does not currently ship equivalent non-US generated files.

## Output
## Output Schema

Files are written to `plugins/emfn-behavior-plugin/assets/data/`:
The generated CSV files used by the plugin contain:

| Region | Files | Source |
|--------|-------|--------|
| US states + DC | `AL.csv` … `WY.csv` | NRI real data (US notebook) |
| Canadian provinces/territories | `AB.csv` … `YT.csv` | Mocked (pending CA-MX notebook) |
| Mexican states | `AGU.csv` … `ZAC.csv` | Mocked (pending CA-MX notebook) |
- `county_fips`
- `state`
- `county`
- `{HAZARD}_risk_score` columns for 18 NRI hazard families

Each file has columns: `county_fips`, `state`, `county`, `{HAZARD}_risk_score` × 18.
The Action Pack plugin matches rows by `county_fips` and filters hazards in client-side JS using its `riskThreshold` setting.

## Hazard Codes (NRI v3)
## Hazard Codes

The notebook uses these 18 hazard types:
The current US notebook and plugin use these 18 NRI hazard families:

| Code | Hazard Type |
|------|-------------|
Expand All @@ -81,3 +64,43 @@ The notebook uses these 18 hazard types:
| VLCN | Volcanic Activity |
| WFIR | Wildfire |
| WNTW | Winter Weather |

## Recommended Workflow

Use the VS Code devcontainer for notebook work. It provides the expected Debian and Python environment and runs the repo setup automatically.

Typical setup:

```bash
uv sync
uv run jupyter lab
```

Then open the desired notebook from `notebooks/`.

Python dependencies are managed in `pyproject.toml` and currently include:

- `jupyterlab`
- `pandas`
- `requests`
- `numpy`
- `ipykernel`
- `tqdm`

## Notebook Hygiene

This repo keeps notebooks in a clean, unexecuted state in commits.

Available commands:

- `npm run notebooks:strip`
- `npm run notebooks:check-clean`

To enable local hooks:

```bash
uv tool install pre-commit
pre-commit install
```

The configured hooks strip outputs from changed notebooks and fail commits if executed notebook state remains.
8 changes: 4 additions & 4 deletions notebooks/US_disaster_risk_analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"\n",
"## Output\n",
"\n",
"Per-state CSV files written to `../plugins/emfn-behavior-plugin/assets/data/`:\n",
"Per-state CSV files written to `../plugins/emfn-action-pack-plugin/assets/data/`:\n",
"\n",
"| Region | Files | Source |\n",
"|--------|-------|--------|\n",
Expand Down Expand Up @@ -72,7 +72,7 @@
"# Paths\n",
"NRI_ZIP_URL = \"https://www.fema.gov/about/reports-and-data/openfema/nri/v120/NRI_Table_Counties.zip\"\n",
"NRI_CSV_CACHE = Path(\"cache/NRI_Table_Counties.csv\")\n",
"OUTPUT_DIR = Path(\"../plugins/emfn-behavior-plugin/assets/data\")\n",
"OUTPUT_DIR = Path(\"../plugins/emfn-action-pack-plugin/assets/data\")\n",
"OUTPUT_DIR.mkdir(parents=True, exist_ok=True)\n",
Comment thread
tiffehr marked this conversation as resolved.
"\n",
"# NRI hazard codes (December 2025, v3) — order matches AL.csv sample\n",
Expand Down Expand Up @@ -238,7 +238,7 @@
"source": [
"### Integration tests\n",
"\n",
"Validates that every generated CSV satisfies the schema contract expected by the JS client (`emfn-behavior-plugin.js`).\n",
"Validates that every generated CSV satisfies the schema contract expected by the JS client (`emfn-action-pack-plugin.js`).\n",
"\n",
"| Test | What it checks |\n",
"|------|---------------|\n",
Expand All @@ -260,7 +260,7 @@
"import gc\n",
"import re as _re\n",
"\n",
"# Hazard codes the JS client maps via NRI_HAZARD_LABELS — order must match emfn-behavior-plugin.js\n",
"# Hazard codes the JS client maps via NRI_HAZARD_LABELS — order must match emfn-action-pack-plugin.js\n",
"JS_HAZARD_CODES = [\n",
" \"AVLN\", \"CFLD\", \"CWAV\", \"DRGT\", \"ERQK\", \"HAIL\",\n",
" \"HWAV\", \"HRCN\", \"ISTM\", \"LNDS\", \"LTNG\", \"IFLD\",\n",
Expand Down
Loading
Loading