Skip to content

Add AEMET integration for /api/conditions with Open‑Meteo fallback; update README and add frontend lockfile#12

Open
Capybla wants to merge 1 commit intomainfrom
add-data-extraction-from-esaemet-3imhzx
Open

Add AEMET integration for /api/conditions with Open‑Meteo fallback; update README and add frontend lockfile#12
Capybla wants to merge 1 commit intomainfrom
add-data-extraction-from-esaemet-3imhzx

Conversation

@Capybla
Copy link
Copy Markdown
Owner

@Capybla Capybla commented Mar 13, 2026

Motivation

  • Provide a higher-quality primary weather source by querying AEMET observations for the nearest station when available using an AEMET_API_KEY.
  • Keep the service working when AEMET is not configured or unavailable by falling back to the existing Open‑Meteo endpoint.
  • Record and lock frontend dependencies for reproducible installs by adding package-lock.json and document new env usage in the README.md.

Description

  • Added AEMET integration in backend/server.py including AEMET_API_KEY, AEMET_BASE_URL, a 6‑hour stations cache and helper functions fetch_aemet_dataset, get_aemet_stations, parse_aemet_coordinate, parse_aemet_observation, and parse_aemet_weather_description to convert AEMET data into the app's FlightCondition model.
  • Updated /api/conditions handler to try AEMET observations first (when AEMET_API_KEY is configured) and fall back to the existing Open‑Meteo call if AEMET is unavailable or fails, preserving existing scoring logic via compute_flight_score.
  • Added parsing logic for AEMET's compact DMS coordinates, safe numeric parsing (to_float), and minor utility imports (timedelta, urlencode) to support the new flows.
  • Updated README.md to document the recommended AEMET_API_KEY environment variable and noted the Open‑Meteo fallback, and added the generated frontend/package-lock.json to lock frontend dependency versions.

Testing

  • No automated tests were added or executed as part of this change.

Codex Task

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a0c45d9fc0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1879 to +1882
nearest_station = min(
stations,
key=lambda station: haversine_distance(lat, lng, station["lat"], station["lng"])
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Fall back when nearest AEMET station is out of range

With AEMET_API_KEY configured, this path always picks the mathematically nearest AEMET station and immediately uses it, but there is no maximum-distance check before returning. For coordinates outside AEMET coverage (or far from any station), /api/conditions will return weather from a distant station instead of the Open-Meteo fallback, producing incorrect flight recommendations for those locations.

Useful? React with 👍 / 👎.

wind_direction = to_float(observation.get("dv"), 0.0)
visibility_km = to_float(observation.get("vis"), 10000.0) / 1000.0

weather_code = 63 if observation.get("prec") not in (None, "Ip", "") else 1
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Parse zero precipitation as non-rain

This condition marks weather as rainy whenever prec is any non-empty value, so numeric zero values like 0/0.0 are treated as rain and mapped to code 63. In those cases, dry observations are scored and recommended as worse-than-actual conditions, which skews flight_score and recommendation; precipitation should be parsed numerically and only considered rain when it is greater than zero (while still handling Ip).

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant