ClimApp uses two lightweight Python classes to represent its core domain objects.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/adrianaarang/climapp/llms.txt
Use this file to discover all available pages before exploring further.
RegistroClimatico captures a single meteorological observation from any source (manual entry or AEMET live feed), while JSONRepository handles all persistence to the local JSON file. Together they form a clean separation between the data shape and storage concerns.
RegistroClimatico
RegistroClimatico is the primary domain model. It wraps one climate reading and guarantees that numeric fields are stored as floats, even if a controller passes string values from a form submission.
Constructor
float inside __init__. This means the constructor will raise a ValueError if a non-numeric string (e.g. "N/A") is passed — validate inputs before instantiating.
Identifier of the weather station or municipality that produced the reading.
Date string for the observation. No format is enforced by the model itself; use
validar_fecha() upstream.Air temperature in °C. Cast to
float automatically.Relative humidity as a percentage (0–100). Cast to
float automatically.Wind speed in km/h. Cast to
float automatically.Rainfall in mm. Cast to
float automatically.to_dict()
Returns a plain dictionary suitable for JSON serialisation. The JSONRepository calls this before writing to disk; the Flask routes return it directly to the frontend.
Station or municipality identifier, unchanged from construction.
Observation date as stored at construction time.
Temperature in °C (float).
Relative humidity percentage (float).
Wind speed in km/h (float).
Rainfall in mm (float).
Full class source
JSONRepository
JSONRepository manages the flat JSON file that stores all climate records. It is instantiated once at module level and exposed through three convenience functions.
Constructor
Path to the JSON storage file. When
None, defaults to data/registros_climaticos.json relative to the working directory. The constructor creates the file (and any missing parent directories) automatically if it does not exist.guardar(registro_dict)
Appends a single record dictionary to the JSON array on disk. Reads the entire file, appends, then writes back with indent=4. Returns True on success, False if any exception is raised.
A plain dictionary representing one climate record, typically produced by
RegistroClimatico.to_dict().filtrar_registros(municipio, fuente, fecha)
Returns a filtered list of records from the JSON file. All parameters are optional; omitting one skips that filter.
Municipality name to filter by. Comparison is case-insensitive and uses substring matching (via
in).Data source to filter by. Accepted values in practice are
"manual" and "aemet". Uses exact match.Date string to filter by. Uses exact string match against the
fecha field.obtener_ultimo_registro(municipio, fuente)
Scans the JSON array in reverse and returns the first record whose municipio field matches (case-insensitive, exact). Returns None if no match is found or if the file cannot be read.
The
fuente parameter is accepted in the method signature but the current implementation only filters by municipio. The source filter is not applied in this method.Module-level convenience functions
A shared_repo = JSONRepository() instance is created at import time. Use these functions instead of instantiating the class directly:
| Function | Equivalent call |
|---|---|
filter_records(**kwargs) | _repo.filtrar_registros(municipio, fuente, fecha) |
find_latest_by_municipio_and_source(municipio, fuente) | _repo.obtener_ultimo_registro(municipio, fuente) |
guardar_registro(registro_dict) | _repo.guardar(registro_dict) |
Zona
Zona maps a Spanish municipality to its corresponding AEMET reference station. It is used alongside estacion_por_municipio.json to resolve municipality names and station identifiers.
Constructor
The human-readable municipality name (e.g.
"Madrid").The INE (Spanish National Statistics Institute) code for the municipality.
The AEMET station identifier linked to this municipality.
The human-readable name of the AEMET reference station.
Zona.from_dict(data)
Static factory method. Creates a Zona from a single entry in estacion_por_municipio.json:
to_dict()
Serializes the zone back to a plain dictionary with keys municipio, cod_ine, id_estacion, and estacion_referencia. Useful for returning municipality lists through a future API endpoint.