This project involves fetching auction results data from the National Grid ESO API, processing it, and saving it to a local SQLite database. The data includes results for Habitat Energy's participation in the Dynamic Frequency Response (DFR) auction.
- Entry point of the application.
- Fetches data, detects fields, creates/loads tables, and saves results.
- Contains database and API configuration settings.
- Functions to fetch data from the National Grid ESO API.
- Filters and processes the fetched data.
- Functions to dynamically create tables, convert dates, and save records.
- Unit tests for fetching auction results.
- Unit tests for database operations and schema validation.
- Python 3.8 or higher
- SQLite
-
Change directory to the repo directory (optional git clone):
git clone https://github.com/alperenerol/he-tech-challenge.git cd he-tech-challenge
-
Create a virtual environment and activate it:
python -m venv habitat_env source habitat_env/bin/activate # On Windows use `habitat_env\Scripts\activate`
-
Install the dependencies:
pip install -r requirements.txt
-
Run the main script:
python main.py
The config.ini
file contains the configuration for the database and the API.
- api/: Contains the module for fetching data from the API.
- db/: Contains modules for dynamic database schema creation and data saving.
- tests/: Contains unit tests.
Logs are saved to logs.log file. Check this file for detailed information about the execution and any errors encountered.
Run the main script:
bash python main.py
This script will fetch the auction results, process the data, and save it to the SQLite database.
Run the tests:
```bash
python -m unittest tests/test_fetch_data.py
python -m unittest tests/test_database_schema.py
```
Fetch auction results from the API:
The fetch_auction_results function retrieves data from the specified API endpoint.
Detect fields in the fetched data:
The detect_fields function analyzes the data and determines the schema.
Create or load a dynamic table based on the detected fields:
The create_dynamic_table function dynamically creates a table schema.
Save the results into the database without duplication:
The save_results function inserts the data into the database, ensuring no duplicate entries.