This project implements a data processing pipeline for wind turbine data. It processes raw CSV files in raw folder, cleans the data, identifies anomalies, and computes statistics for further analysis. The pipeline also stores the results in a SQL Server database and handles incremental data loading efficiently.
-
Incremental Data Processing:
- Only processes new data since the last load timestamp for each turbine group.
-
Data Cleaning:
- Fills missing
power_outputvalues with the mean of the respective turbine group. - Removes outliers based on a configurable threshold 2
- Fills missing
-
Anomaly Detection:
- Flags anomalies using z-scores or standard deviation thresholds.
- Configurable sensitivity using
ANOMALY_THRESHOLD3
-
Statistics Computation:
- Computes daily minimum, maximum, and mean
power_outputvalues for each turbine.
- Computes daily minimum, maximum, and mean
-
Database Integration:
- Uses SQLAlchemy with
pyodbcto store cleaned data, statistics, and anomaly flags. - Maintains an audit table to track the last processed timestamp for each turbine group.
- Uses SQLAlchemy with
-
Concurrency:
- Processes multiple files concurrently using Python’s
concurrent.futuresmodule.
- Processes multiple files concurrently using Python’s
-
Logging:
- Detailed logs for debugging and monitoring stored in
pipeline.logfile.
- Detailed logs for debugging and monitoring stored in
- The pipeline connects to a SQL Server database using the following configuration:
CONNECTION_STRING = (
"DRIVER={ODBC Driver 17 for SQL Server};"
"SERVER=LAPTOP-MBV00UBE\\SQLEXPRESS;"
"DATABASE=test;"
"Trusted_Connection=yes;"
)
water mark table used for incrimental loading
CREATE TABLE [audit].[watermark](
[lastLoadedTimeStamp] [datetime2](3) NULL,
[groupName] [nvarchar](50) NULL,
[UpdatedTimeStamp] [datetime2](3) NULL
) ON [PRIMARY]
GO
ALTER TABLE [audit].[watermark] ADD DEFAULT (getdate()) FOR [UpdatedTimeStamp]
GO
statastics data stored in turbine_statastics
CREATE TABLE [dbo].[turbine_statastics](
[turbine_id] [bigint] NULL,
[period] [datetime] NULL,
[min_power_output] [float] NULL,
[max_power_output] [float] NULL,
[mean_power_output] [float] NULL,
[UpdatedTimestamp] [datetime] default getDate()
) ON [PRIMARY]
GO
turbine data stored in turbine_data
CREATE TABLE [dbo].[turbine_data](
[timestamp] [datetime] NULL,
[turbine_id] [bigint] NULL,
[wind_speed] [float] NULL,
[wind_direction] [bigint] NULL,
[power_output] [float] NULL,
[is_anomaly] [bit] NULL,
[UpdatedTimestamp] [datetime] default getDate()
) ON [PRIMARY]
GO- Modify the connection string to point to your database server and instance.
OUTLIER_THRESHOLD: Defines the number of standard deviations to filter outliers.ANOMALY_THRESHOLD: Defines the number of standard deviations to flag anomalies.
project/
├── raw/ # Directory containing raw CSV files
├── pipeline.log # Log file for the pipeline
├── main.py # Main script
├── HelperFunctions/ # Directory for helper modules
│ ├── __init__.py
│ ├── data_cleaning.py # Functions for cleaning data
│ ├── db_utils.py # Functions for database interactions
│ ├── anomaly_detection.py # Functions for detecting anomalies
├── tests/ # Unit tests for the pipeline
│ ├── test_data_cleaning.py
│ ├── test_db_utils.py
│ ├── test_anomaly_detection.py
└── requirements.txt # Python dependencies
- Python 3.8 or later
- SQL Server with necessary tables:
audit.watermark: Tracks last loaded timestamps.turbine_data: Stores cleaned turbine data.turbine_statastics: Stores computed statistics.
Install the required Python libraries using pip:
pip install -r requirements.txt- Place raw CSV files in the
raw/directory. Each file should follow this format:
timestamp,turbine_id,wind_speed,wind_direction,power_output
2022-03-01 00:00,1,11.8,169,2.7
2022-03-01 00:00,2,11.6,24,2.2
...Run the main script:
python main.py- Database: Cleaned data, statistics, and anomalies are stored in SQL Server.
- Logs: Detailed logs are available in
pipeline.log.
Run unit tests using pytest:
pytest tests/- Reads raw CSV files and cleans the data.
- Handles missing values and removes outliers.
- Flags anomalies in
power_outputbased on z-scores or thresholds.
- Computes daily statistics (
min,max,mean) forpower_output.
- Updates the
audit.watermarktable with the latest timestamp.
- Processes multiple files concurrently.
- Data will always append to the existing file
- No updates will happen to the existing data
- Outliers considered when the power_output outside of 3 standard deviations from the mean.
- Fork the repository.
- Create a new branch for your feature (
git checkout -b feature-name). - Commit your changes (
git commit -m 'Add some feature'). - Push to the branch (
git push origin feature-name). - Open a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
- Python Community
- SQLAlchemy and Pandas Documentation