Skip to main content

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.

ClimApp uses two lightweight Python classes to represent its core domain objects. 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

RegistroClimatico(estacion_id, fecha, temperatura, humedad, viento, lluvia)
All four metric arguments are cast to 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.
estacion_id
string
required
Identifier of the weather station or municipality that produced the reading.
fecha
string
required
Date string for the observation. No format is enforced by the model itself; use validar_fecha() upstream.
temperatura
number
required
Air temperature in °C. Cast to float automatically.
humedad
number
required
Relative humidity as a percentage (0–100). Cast to float automatically.
viento
number
required
Wind speed in km/h. Cast to float automatically.
lluvia
number
required
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.
estacion_id
string
Station or municipality identifier, unchanged from construction.
fecha
string
Observation date as stored at construction time.
temperatura
number
Temperature in °C (float).
humedad
number
Relative humidity percentage (float).
viento
number
Wind speed in km/h (float).
lluvia
number
Rainfall in mm (float).

Full class source

class RegistroClimatico:
    def __init__(self, estacion_id, fecha, temperatura, humedad, viento, lluvia):
        self.estacion_id = estacion_id
        self.fecha = fecha
        # Aseguramos que las métricas sean numéricas para evitar errores en cálculos futuros
        self.temperatura = float(temperatura)
        self.humedad = float(humedad)
        self.viento = float(viento)
        self.lluvia = float(lluvia)

    def to_dict(self):
        return {
            "estacion_id": self.estacion_id,
            "fecha": self.fecha,
            "temperatura": self.temperatura,
            "humedad": self.humedad,
            "viento": self.viento,
            "lluvia": self.lluvia
        }

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

JSONRepository(file_path=None)
file_path
string
default:"data/registros_climaticos.json"
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.
registro_dict
object
required
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.
municipio
string
Municipality name to filter by. Comparison is case-insensitive and uses substring matching (via in).
fuente
string
Data source to filter by. Accepted values in practice are "manual" and "aemet". Uses exact match.
fecha
string
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:
FunctionEquivalent 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

Zona(municipio, cod_ine, id_estacion, estacion_referencia)
municipio
string
required
The human-readable municipality name (e.g. "Madrid").
cod_ine
string
required
The INE (Spanish National Statistics Institute) code for the municipality.
id_estacion
string
required
The AEMET station identifier linked to this municipality.
estacion_referencia
string
required
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:
zona = Zona.from_dict({
    "municipio": "Madrid",
    "cod_ine": "28079",
    "id_estacion": "3195",
    "estacion_referencia": "Madrid-Retiro"
})

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.

Build docs developers (and LLMs) love