Skip to content

H-06: Species-Specific Temporal Freshness Decay Projection & Line Chart #55

@diyamajee-spec

Description

@diyamajee-spec

Description

This issue targets the "Temporal Freshness Tracking" item on the Phase 2 roadmap. Because different fish species spoil at different rates depending on biological factors and ambient storage conditions, users need to know when their fish will cross critical freshness thresholds (e.g., moving from Grade B to C, or C to Spoiled).
This issue involves creating a backend decay-calculation model and displaying an interactive decay-rate timeline chart on the frontend dashboard.

Proposed Solution

1. Backend (Model & Endpoint)

  • Decay Constants: In backend/fusion.py (or a new module), define baseline freshness decay coefficients (or half-life rates) for major species categories (e.g., Freshwater like Rohu Carp vs. Saltwater species).
  • Projection Logic: Write a formula to calculate freshness scores at 4-hour intervals for the next 48 hours based on:
    • Selected storage temperature: Refrigerated/Iced (0-4°C) vs. Ambient (25°C).
    • Baseline species decay speed.
    • The initial scanned freshness_index.
  • API Route: Add a new endpoint GET /api/v1/scans/{scan_id}/decay-projection?temp=ambient (or return the data array within the existing /api/v1/scans/{scan_id} JSON response under a new decay_projection field).

2. Frontend (Decay Chart & Temperature Toggle)

  • Interactive Chart: Embed a responsive line chart (e.g., using recharts or a similar lightweight chart library) in src/pages/AnalysisDashboard.tsx.
  • Threshold Reference Bands: Color-code zones on the chart:
    • Fresh Zone (Score >= 80)
    • Caution Zone (50-79)
    • Spoiled Zone (Score < 50)
  • Temperature Switch: Provide a simple UI toggle tab (e.g., [ Iced (0-4°C) ] vs [ Room Temp (25°C) ]) that dynamically re-renders or updates the graph projection to visually demonstrate how refrigeration preserves fish shelf-life.

Tasks & Checklists

Backend:

  • Implement species decay coefficients registry in backend/fusion.py.
  • Create the decay projection formula calculating 48-hour timelines.
  • Add the API endpoint /api/v1/scans/{scan_id}/decay-projection in backend/main.py.
  • Add unit tests in backend/tests/ to verify the projection math limits bounds (must stay between 0 and 100).
Frontend:
  • Add the decay_projection field to client TypeScript types in src/lib/types.ts.
  • Update src/lib/api.ts to support fetching the projection data.
  • Create the chart component card in src/pages/AnalysisDashboard.tsx.
  • Add the interactive Temperature Switch tabs.

Files to Modify

  • backend/fusion.py
  • backend/main.py
  • src/lib/types.ts
  • src/lib/api.ts
  • src/pages/AnalysisDashboard.tsx

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions