diff --git a/CHANGES.md b/CHANGES.md deleted file mode 100644 index b3ab18a..0000000 --- a/CHANGES.md +++ /dev/null @@ -1,123 +0,0 @@ -# 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. \ No newline at end of file diff --git a/CSV_IMPORT_FIX.md b/CSV_IMPORT_FIX.md deleted file mode 100644 index e453f9a..0000000 --- a/CSV_IMPORT_FIX.md +++ /dev/null @@ -1,98 +0,0 @@ -# CSV Import Fix - -## Issue Description - -The CSV import script (`import_example_from_csv_co2db.py`) was encountering an error when processing rows with empty latitude values: - -``` -Skipping row with empty latitude: ['22/04/2019', 'OK', 'Non', "Etape du challenge Ardeche de course d'orientation", 'Plateau des Gras (commune de balazuc)', '7', 'Départementale Moyenne Distance', 'Départemental', 'Pédestre', 'MD', '7', 'Ardèche', '', '', '', '', 'pardoen Toma', '607966486', 'evenements@cdco07.fr', 'http://cdco07.fr/', '', '', '', '', '', '', '', '', '', '', '', '', '', ''] -Event could not be created (500): {"title": "500 Internal Server Error"} -``` - -The script was correctly identifying and skipping rows with empty latitude values, but then it was still trying to submit an event to the API, resulting in a 500 Internal Server Error. Additionally, the script was using an external API endpoint instead of the local server. - -## Solution - -The following changes were made to fix the issues: - -1. **Changed the API endpoint**: Updated the script to use the local API endpoint (`http://127.0.0.1:8080/event`) instead of the external one (`http://api.openeventdatabase.org/event`). - -2. **Improved error handling**: Modified the script to continue processing even when an event submission fails, instead of exiting with an error code. - -3. **Fixed file path issue**: Updated the script to use the correct path to the CSV file, using `os.path` to determine the script's directory. - -4. **Added detailed logging**: Added code to print the event data being submitted, which helps diagnose any issues with the data format. - -5. **Added simulation mode**: Added an option to simulate successful submissions for testing purposes, which allows testing without a running server. - -## Technical Details - -### Changes Made - -1. Updated the API endpoint: - ```python - url = "http://127.0.0.1:8080/event" # Changed from "http://api.openeventdatabase.org/event" - ``` - -2. Improved error handling: - ```python - # Commented out sys.exit(1) to continue processing - # sys.exit(1) - ``` - -3. Fixed file path issue: - ```python - # Use the correct path to the CSV file - import os - script_dir = os.path.dirname(os.path.abspath(__file__)) - csv_path = os.path.join(script_dir, "calendrierv3.csv") - eventReader = csv.reader(open(csv_path), delimiter=",") - ``` - -4. Added detailed logging and simulation mode: - ```python - def submit_event(data, simulate=True): - """ - Submit an event to the OpenEventDatabase API. - - Args: - data: The event data to submit as a JSON string. - simulate: If True, simulate a successful submission instead of actually submitting. - - Returns: - None - """ - # Print the event data being submitted (first 200 characters) - print(f"Submitting event data: {data[:200]}...") - - if simulate: - print("Simulation mode: Simulating successful event submission") - print("Event created successfully (201): {\"id\":\"simulated-id\"}") - return - - # Rest of the function... - ``` - -## How to Test - -1. Run the script with simulation mode enabled (default): - ```bash - python3 data/import_example_from_csv_co2db.py - ``` - This will process all rows in the CSV file, skipping rows with empty coordinates and simulating successful submissions for the rest. - -2. To test with actual submissions to the local server, modify the `submit_event` call in the `process_csv` function to pass `simulate=False`: - ```python - submit_event(json.dumps(obj), simulate=False) - ``` - Make sure the local server is running at `http://127.0.0.1:8080` before testing. - -## Additional Notes - -If you continue to experience issues with the CSV import, check the following: - -1. Make sure the CSV file has the expected format and column structure. -2. Verify that the local server is running and properly configured to handle event submissions. -3. Check the server logs for more detailed error messages. - -The simulation mode is useful for testing the script without a running server, but it doesn't actually submit events to the database. To import events into the database, you'll need to run the script with `simulate=False` and ensure the server is running. \ No newline at end of file diff --git a/DB_CONNECTION_FIX.md b/DB_CONNECTION_FIX.md deleted file mode 100644 index a2089e2..0000000 --- a/DB_CONNECTION_FIX.md +++ /dev/null @@ -1,86 +0,0 @@ -# PostgreSQL Authentication Fix - -## Issue Description - -The server was failing to connect to the PostgreSQL database with the following error: - -``` -[OEDB] [ERROR] Failed to connect to PostgreSQL database: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: Peer authentication failed for user "cipherbliss" -``` - -This error occurs because the application was trying to connect to PostgreSQL using Unix socket connections, which default to "peer" authentication (using the operating system username). However, the database was configured to use password authentication, as evidenced by the fact that DBeaver could connect using the password from the `.env` file. - -## Solution - -The fix involves modifying the database connection logic in `oedb/utils/db.py` to: - -1. Force TCP/IP connections instead of Unix socket connections by setting the host to "localhost" when it's empty -2. Add appropriate connection parameters for local connections -3. Improve debug logging to help with troubleshooting - -These changes ensure that the application uses password authentication instead of peer authentication when connecting to the database. - -## Testing the Fix - -A test script has been created to verify that the database connection works with the new changes: - -```bash -./test_db_connection.py -``` - -This script attempts to connect to the database using the same connection logic as the main application and reports whether the connection was successful. - -## Technical Details - -### Changes Made - -1. Modified `db_connect()` function to set host to "localhost" when it's empty: - ```python - # If host is empty, set it to localhost to force TCP/IP connection - # instead of Unix socket (which uses peer authentication) - if not host: - host = "localhost" - ``` - -2. Added appropriate connection parameters for local connections: - ```python - # For localhost connections, add additional parameters to ensure proper connection - if host in ('localhost', '127.0.0.1'): - logger.debug("Using TCP/IP connection with additional parameters") - return psycopg2.connect( - dbname=dbname, - host=host, - password=password, - user=user, - options="-c client_encoding=utf8 -c statement_timeout=3000", - connect_timeout=3, - application_name="oedb", - # Disable SSL for local connections - sslmode='disable') - ``` - -3. Improved debug logging to help with troubleshooting: - ```python - logger.debug(f"Connecting to database: {dbname} on {host} as user {user}") - ``` - -### Why This Works - -By setting the host to "localhost" when it's empty, we force psycopg2 to use TCP/IP connections instead of Unix socket connections. TCP/IP connections typically use password authentication, which is what the database is configured to use. - -The additional connection parameters for local connections help ensure that the connection is established correctly and provide useful information for debugging. - -## Additional Notes - -If you continue to experience authentication issues, check the following: - -1. Make sure your `.env` file contains the correct database credentials: - ``` - DB_NAME=oedb - DB_USER=cipherbliss - POSTGRES_PASSWORD=your_password - ``` - -2. Verify that your PostgreSQL server is configured to allow password authentication for the specified user. - -3. Check the PostgreSQL logs for more detailed error messages. \ No newline at end of file diff --git a/DEMO_POPUP_ENHANCEMENT.md b/DEMO_POPUP_ENHANCEMENT.md deleted file mode 100644 index ff764ba..0000000 --- a/DEMO_POPUP_ENHANCEMENT.md +++ /dev/null @@ -1,122 +0,0 @@ -# Demo Page Popup Enhancement - -## Overview - -The `/demo` endpoint of the OpenEventDatabase API provides an interactive map that displays current events from the database. This document describes the enhancement made to the event popups on the map, which now display all properties of each event. - -## Changes Made - -Previously, the event popups only displayed a few selected properties: -- Event name (label) -- Date (when) -- Type (what) -- A link to more information (if available) - -Now, the popups display **all properties** of each event, providing a more comprehensive view of the event data. The enhancements include: - -1. **Complete Property Display**: All properties from the event's JSON object are now displayed in the popup. -2. **Organized Layout**: Properties are displayed in a table format with property names in the left column and values in the right column. -3. **Alphabetical Sorting**: Properties are sorted alphabetically for easier navigation. -4. **Scrollable Container**: A scrollable container is used to handle events with many properties without making the popup too large. -5. **Smart Formatting**: - - Objects are displayed as formatted JSON - - URLs are displayed as clickable links - - Null values are displayed as "null" in italics - - Other values are displayed as strings - -## Example - -When you click on an event marker on the map, a popup will appear showing all properties of the event. For example: - -``` -Event Name - -createdate: 2023-09-15T12:00:00Z -id: 123e4567-e89b-12d3-a456-426614174000 -lastupdate: 2023-09-15T12:00:00Z -source: https://example.com/event -start: 2023-09-15T12:00:00Z -stop: 2023-09-16T12:00:00Z -type: scheduled -what: sport.match.football -what:series: Euro 2024 -where: Stadium Name -``` - -## Technical Implementation - -The enhancement was implemented by modifying the JavaScript code in the `demo.py` file. The key changes include: - -```javascript -// Create popup content -let popupContent = '
${key}: | -${displayValue} | -
+ + + +
+ +