# Changes Made to Meet Requirements ## 1. Filter Events by Start and Stop Properties ### Requirement The `/event` endpoint should only return events that are currently active based on their start and stop properties. ### Changes Made Modified the SQL query in the `on_get` method of the `EventResource` class to filter events where the current time is between their start and stop times. ```python # Before event_when = "tstzrange(now(),now(),'[]')" # After if event_when == "now()": # Use @> operator to check if events_when contains current time sql = """SELECT events_id, events_tags, createdate, lastupdate, {event_dist} st_asgeojson({event_geom}) as geometry, st_x(geom_center) as lon, st_y(geom_center) as lat FROM events JOIN geo ON (hash=events_geo) WHERE events_when @> {event_when} {event_what} {event_type} {event_bbox} ORDER BY {event_sort} {limit}""" ``` This change ensures that when no time parameters are provided, the endpoint returns events where the current time is between their start and stop times, rather than only events happening exactly at the current moment. ## 2. Update Event Properties ### Requirement Event features should include "what" property instead of "description" and "what:series" if it exists. Latitude and longitude should only be in geometry.coordinates, not in properties. ### Changes Made Modified the `row_to_feature` method in the `BaseEvent` class to: 1. Remove `lat` and `lon` from properties 2. Ensure `what` property is used instead of `description` ```python # Before properties = dict(row['events_tags']) properties.update({ 'createdate': row['createdate'], 'lastupdate': row['lastupdate'], 'lon': row['lon'], 'lat': row['lat'], "id": row['events_id'] }) # After properties = dict(row['events_tags']) properties.update({ 'createdate': row['createdate'], 'lastupdate': row['lastupdate'], "id": row['events_id'] }) # Ensure what property is used instead of description if 'description' in properties and 'what' not in properties: properties['what'] = properties.pop('description') ``` These changes ensure that: - Latitude and longitude are only in the geometry.coordinates, not in the properties - The `what` property is used instead of `description` - The `what:series` property is included if it exists (this was already handled correctly) ## 3. Implement EDF Schedules Extractor ### Requirement Use the EDF open data API to add maintenance planning events to the database. ### Changes Made Created a new file `extractors/edf_schedules.py` that: 1. Fetches data from the EDF open data API 2. Processes each record to create an event object with the required properties 3. Submits each event to the database ```python # API URL for EDF open data API_URL = "https://opendata.edf.fr/api/explore/v2.1/catalog/datasets/disponibilite-du-parc-nucleaire-d-edf-sa-present-passe-et-previsionnel/records?limit=200" # Create event object with required properties event = { "type": "Feature", "geometry": { "type": "Point", "coordinates": coordinates }, "properties": { "type": "scheduled", "what": "energy.maintenance.nuclear", "what:series": "EDF Nuclear Maintenance", "where": f"{site_name} - {unit}", "label": f"Nuclear Maintenance: {site_name} - {unit}", "start": start_date, "stop": end_date, "power_available": power_available, "power_max": power_max, "source": "EDF Open Data" } } ``` This script can be run directly to fetch data from the API and add events to the database. ## How to Test 1. Run the server: ```bash python3 backend.py ``` 2. Test the `/event` endpoint to verify that it only returns currently active events: ```bash curl http://localhost:8080/event ``` 3. Run the EDF schedules extractor to add maintenance planning events to the database: ```bash python3 extractors/edf_schedules.py ``` 4. Verify that the events have been added to the database and can be retrieved via the `/event` endpoint.