Inspiration

Living in Khulna Division, Bangladesh, the operational reality after a cyclone or storm surge (such as in Koyra Upazila) is a race against saltwater intrusion across dozens of community ponds. Local field teams face two distinct operational bottlenecks under tight budgets:

  1. Constrained Daily Retesting ($K \ll N$): When 50 water sources are affected by storm surge and subsurface seepage, field teams may only have time and kits to retest $K = 5$ ponds per day. Naive rules—like retesting the pond with the highest last Electrical Conductivity (EC) reading or visiting the nearest pond—waste scarce tests on sources where the restriction decision is already certain, while missing uncertain sources near the safety threshold (false reassurance).
  2. Intervention Verification & Accountability: After contractors dewater and flush a salinized pond, a simple before-and-after EC drop does not prove the work succeeded—regional monsoon rainfall dilutes untreated ponds too. Furthermore, when the same entity logs the work and attests to the retest, conflicts of interest arise.

Scope & Safety Disclosure: Electrical Conductivity (EC, in $\text{dS/m}$) is used strictly as a proxy for dissolved-ion salinity risk (per Bangladesh Department of Environment guidance) to prioritize field retesting. It never certifies microbial, pathogen, arsenic, or overall drinking-water safety. All pond coordinates and trajectories in this prototype are synthetic test scenarios.


What It Does

FreshTrace is a budget-aware post-cyclone water-source retesting and auditable intervention-assessment system built for Track 4: Climate Data & Environmental Monitoring:

  • Bayesian EVSI Prioritization (Tab 1): Models each pond's posterior salinity distribution $S_i \mid \mathcal{D} \sim \mathcal{N}(\mu_i, \sigma_i^2)$ and computes the Expected Value of Sample Information ($\mathrm{EVSI}_i$) under asymmetric decision loss ($c_{\text{hazard}} > c_{\text{restrict}}$) using Normal–Normal conjugate updates and 21-point Gauss–Hermite quadrature.
  • Explicit Dual-Queue Scheduling ($K = K_{\text{verify}} + K_{\text{evsi}}$): Separates overdue independent post-intervention verification (Queue B) from Bayesian salinity-risk information gain (Queue A) so neither objective crowds out the other.
  • Three-State Intervention-Effect Evidence Assessment (Tab 2): Evaluates a treated pond's pre/post EC reduction against matched untreated control ponds using a 90% normal-approximation interval ($z = 1.645$) over control change variance ($s^2_{\Delta C}$), classifying outcomes into:
    1. Consistent with an intervention effect ($\rightarrow$ ApprovedForRelease)
    2. Effect inconclusive ($\rightarrow$ NeedsFollowUpTest)
    3. Result inconsistent with claimed effect ($\rightarrow$ Disputed)
  • Session-Local Tamper-Evident Audit Demo & Solidity State Machine (Tab 3 & Remix): Demonstrates post-hoc tamper detection via SHA-256 hash links and demo HMAC tags, paired with a Manual Remix Parameter Helper for FreshTraceStateMachine.sol to enforce role separation between Operator, DesignatedTester, and Coordinator.
  • Reproducible Common-Random-Numbers (CRN) Benchmark (Tab 4): Compares 5 strategies across 50 synthetic ponds under identical environmental drift and sensor noise realizations.

How I Built It

1. Normal–Normal Conjugate Updates & 21-Point Gauss–Hermite Quadrature (freshtrace_core.py)

Given prior $S_i \sim \mathcal{N}(\mu_i, \sigma_i^2)$ and noisy sensor observation $Y_i \mid S_i \sim \mathcal{N}(S_i, \sigma_{\text{obs}}^2)$, the posterior variance $\sigma_{\text{post},i}^2$ and preposterior variance of the posterior mean $\sigma_{\text{pre},i}^2$ are:

$$\sigma_{\text{post},i}^2 = \frac{\sigma_i^2 \sigma_{\text{obs}}^2}{\sigma_i^2 + \sigma_{\text{obs}}^2}, \qquad \sigma_{\text{pre},i}^2 = \frac{\sigma_i^4}{\sigma_i^2 + \sigma_{\text{obs}}^2}$$

At threshold $\tau = 2.0\text{ dS/m}$ with asymmetric loss ratio $c_{\text{hazard}} / c_{\text{restrict}} = 10$, the prior Bayes risk is:

$$L_{\text{prior}}(\mu_i, \sigma_i) = \min\Big(c_{\text{hazard}}\big[1 - \Phi\big(\tfrac{\tau - \mu_i}{\sigma_i}\big)\big],\; c_{\text{restrict}}\Phi\big(\tfrac{\tau - \mu_i}{\sigma_i}\big)\Big)$$

We integrate the expected posterior Bayes loss over 21 Gauss–Hermite quadrature nodes ${z_m, w_m}{m=1}^{21}$ to obtain $\mathrm{EVSI}_i = \max\big(0,\, L{\text{prior}} - \mathbb{E}Y[L{\text{post}}]\big)$. In Tab 1, three hand-checkable presets verify this behavior:

  • Case 1 (Boundary Source: $\mu = 1.85, \sigma = 0.55\text{ dS/m}$): $\mathrm{EVSI} = 0.3553$ (High priority: resolves threshold ambiguity).
  • Case 2 (Clearly Saline, Low Uncertainty: $\mu = 5.50, \sigma = 0.30\text{ dS/m}$): $\mathrm{EVSI} = 0.000000$ (Near zero: retesting will not flip the restriction decision).
  • Case 3 (High Reading, High Uncertainty: $\mu = 3.20, \sigma = 1.80\text{ dS/m}$): $\mathrm{EVSI} = 0.1392$ (Non-zero value driven by wide prior uncertainty).

2. Controlled Before–After Intervention Assessment

For a treated pond with reduction $\Delta T = y_{\text{pre}} - y_{\text{post}}$ and $m = 4$ matched untreated control ponds with reductions $\Delta C_j = c_{\text{pre},j} - c_{\text{post},j}$, the net differential reduction and standard error are:

$$\Delta_{\text{net}} = \Delta T - \overline{\Delta C}, \qquad \mathrm{SE}(\Delta_{\text{net}}) = \sqrt{\sigma_{\text{pre}}^2 + \sigma_{\text{post}}^2 + \frac{s_{\Delta C}^2}{m}}$$

Comparing the 90% normal-approximation interval $\Delta_{\text{net}} \pm 1.645\,\mathrm{SE}(\Delta_{\text{net}})$ against $\delta_{\min} = 0.50\text{ dS/m}$ prevents natural monsoon dilution from being rubber-stamped as contractor success, while transparently reporting Effect inconclusive when control variance is high.

3. Solidity Accountability State Machine (FreshTraceStateMachine.sol)

Written in Solidity ^0.8.20 and deployed on Remix VM, the contract enforces onlyOperator, onlyTester (requiring msg.sender != rec.operator), and onlyCoordinator modifiers, storing scaled measurements, model version strings (FreshTrace-DiD-v1.2), and SHA-256 bytes32 evidence hashes.


Challenges I Ran Into

  1. Decoupling Environmental Randomness from Policy Randomness in Monte Carlo Trials: Initially, calling a random baseline inside the simulation loop shifted the pseudo-random number generator stream for subsequent environmental drift. I solved this by implementing Common Random Numbers (CRN)—pre-generating daily_drift_matrix, daily_obs_noise_matrix, and ctrl_noise_matrix per trial seed so all 5 strategies face the exact same physical world.
  2. Defining Rigorous Benchmark Metrics & Edge-Case Guards: Simply counting how often a hazardous source is tested overstates performance if the decision was already Restrict. I tightened Post-Update Hazard Catch (%) to count a catch only when a truly hazardous pond ($S_i > \tau$) was classified as acceptable prior to testing and the Bayesian update flipped the decision to Restrict. I also added explicit np.nan zero-denominator guards on the False-Reassurance Rate and separated Intervention Retest Coverage (%), conditional Accuracy Among Retested (%), and unconditional Retested-and-Correct (%).
  3. EVM Stack Depth (Stack too deep) & Plotly 6.x API Changes: A 13-field public struct mapping triggered Solidity's 16-slot stack limit in the auto-generated getter; switching to a private mapping with an explicit getRecord(bytes32) external view returns (InterventionRecord memory) resolved it cleanly without altering function signatures. I also replaced deprecated scatter_mapbox calls with native Plotly px.scatter + go.Scatter layers so the Koyra Upazila polder grid runs out-of-the-box without external API keys.

What I Learned

Building FreshTrace reinforced that environmental AI and blockchain prototypes are strongest when they are honest about their statistical and cryptographic boundaries:

  • Value of Information vs. Raw Risk: High contamination and high value of information are not the same thing—testing resources yield the highest decision gain near the action threshold where uncertainty can flip a human decision.
  • Honest Prototype Disclosures: Clearly distinguishing a session-local tamper-detection demo and manual Remix parameter helper from production identity management makes a prototype far more credible and useful to engineering judges.

What's Next for FreshTrace

  • Spatial Gaussian Process (Kriging) Priors: Coupling neighboring ponds within the same coastal polder via a Matérn covariance kernel so a single field test updates beliefs across hydrologically connected sources.
  • Travel-Time Routing Constraints: Extending the Queue A + Queue B selector into a distance-constrained orienteering problem from the Koyra depot.
  • Hardware Wallet Signing: Connecting the Streamlit frontend directly to an L2 testnet via Web3/EIP-712 typed signatures from field tablets.

Built With

Share this project:

Updates

Submission history