Skip to content

Dev/hourly forecast history#85

Merged
fedjo merged 6 commits intoagstack:mainfrom
openagri-eu:dev/hourly-forecast-history
Mar 3, 2026
Merged

Dev/hourly forecast history#85
fedjo merged 6 commits intoagstack:mainfrom
openagri-eu:dev/hourly-forecast-history

Conversation

@fedjo
Copy link
Collaborator

@fedjo fedjo commented Mar 3, 2026

This PR introduces two new hourly forecast endpoints backed by Open-Meteo, providing full-day timelines (including past hours) plus multiple forecast days.

Summary of Changes

  • New endpoint: GET /api/v1/forecast/hourly/

    • Returns HourlyResponse with 1‑hour resolution from 00:00 of today through 23:00 of the last forecast day.
    • Always includes all 24 hours of the current day (no past-hour filtering).
    • Uses WeatherClientFactory to query Open-Meteo and wraps results with location and source metadata.
  • New endpoint: GET /api/v1/forecast/hourly/spray/

    • Returns a list of SprayForecastResponse entries, one per hour, for today + next days.
    • Computes spray suitability per hour using:
      • Temperature, relative humidity, wind speed, precipitation, and delta‑T (via calculate_wet_bulb).
    • Classifies each hour as optimal, marginal, or unsuitable using evaluate_spray_conditions.
    • Converts SprayStatus enums to strings for a JSON‑friendly detailed_status payload.
    • Includes GeoJSON location and source="open-meteo" metadata.

Notes

  • Resolves Hourly historical & forecast weather data #84
  • Ensures downstream clients always receive complete daily timelines
  • Input validation on days enforces 1–16 days (inclusive).
  • Returns 502 with a clear error message if Open-Meteo data cannot be retrieved.

arruda and others added 5 commits December 1, 2025 15:04
This should avoid issues on the fetch_or_create methods accessing
position [0] in an empty list of the given activity type respose.
adding the push thi/fligh/spray flags to the setup of the FC jobs
…rror when connection lost (#14)

* Handle error on no internet

* Handle empty json response from FC

* Add a safer check on empty graph list

* Add farm name and parcel to the obs title and desc

* Eagerly fetch parcels from FC
@fedjo fedjo requested a review from Copilot March 3, 2026 10:32
@fedjo fedjo self-assigned this Mar 3, 2026
@fedjo fedjo added the bug Something isn't working label Mar 3, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds new API v1 endpoints to serve hourly full-day timelines (including past hours) backed by Open-Meteo, and updates FarmCalendar integration to attach farm/parcel metadata when scheduling and posting observations.

Changes:

  • Added GET /api/v1/forecast/hourly/ and GET /api/v1/forecast/hourly/spray/ endpoints for hourly weather + hourly spray suitability.
  • Extended OpenMeteoClient with a Forecast-API-backed get_hourly_forecast() and shared fetch/error handling.
  • Updated FarmCalendar location fetching + scheduler/job posting to carry farm/parcel identifiers instead of raw lat/lon.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
src/api/api_v1/endpoints/forecast.py New hourly forecast + spray endpoints using Open-Meteo hourly data.
src/external_services/openmeteo.py Adds hourly forecast method and shared HTTP fetch helper.
src/api/api_v1/api.py Registers the new /forecast routes in API v1.
src/openagri_services/farmcalendar_service.py Enriches locations with farm/parcel metadata and includes it in posted observations.
src/scheduler.py Switches scheduled FarmCalendar pushes to use enriched location info and adjusts refresh scheduling.
src/core/app.py Only fetches FarmCalendar activity types when corresponding push flags are enabled.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@fedjo fedjo merged commit 365849b into agstack:main Mar 3, 2026
@fedjo fedjo deleted the dev/hourly-forecast-history branch March 3, 2026 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hourly historical & forecast weather data

3 participants