Skip to content

Commit 85eed61

Browse files
authored
Merge pull request #7 from codegreen-framework/main
doc test
2 parents 12d29e8 + ec9bbae commit 85eed61

File tree

8 files changed

+114
-46
lines changed

8 files changed

+114
-46
lines changed

.github/workflows/test.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Run Tests on main
2+
3+
# Trigger this workflow when pushing to the main branch
4+
on:
5+
push:
6+
branches:
7+
- main
8+
pull_request:
9+
branches:
10+
- main
11+
12+
# Define the job to run the tests
13+
jobs:
14+
test:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
# Checkout the code from the repository
19+
- name: Checkout repository
20+
uses: actions/checkout@v3
21+
22+
# Set up Python environment
23+
- name: Set up Python
24+
uses: actions/setup-python@v4
25+
with:
26+
python-version: '3.12.5' # Specify Python version (e.g., '3.9')
27+
28+
# Install dependencies (you can specify requirements.txt or pyproject.toml)
29+
- name: Install dependencies
30+
run: |
31+
python -m pip install --upgrade pip
32+
pip install pytest pandas numpy entsoe-py redis tensorflow scikit-learn sphinx
33+
pip install .
34+
35+
# Run pytest to execute tests
36+
- name: Generate .config file inside the test folder
37+
run: |
38+
echo "[codegreen]" > .codegreencore.config
39+
echo "ENTSOE_token=${{ secrets.ENTSOE_TOKEN }}" >> .codegreencore.config
40+
echo "enable_energy_caching=false" >> .codegreencore.config
41+
- name: Run tests
42+
run: |
43+
pytest

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,21 @@
1-
The core business logic of codegreen. Please see the documentation website for more details about the project.
1+
[![Run Tests](https://github.com/codegreen-framework/codegreen-core/actions/workflows/test.yml/badge.svg)](https://github.com/codegreen-framework/codegreen-core/actions/workflows/test.yml)
2+
3+
This repository contains the main functionality of the codegreen project. The complete documentation including installation and usage are available on the [documentation website](https://codegreen-framework.github.io/codegreen-core/).
4+
5+
## Development workflow
6+
- the `release` branch contains the latest stable version of the released python package
7+
- the `main` branch contains stable, tested code ready to be released.
8+
- the `dev` branch is the main working branch. All feature branches are merged to `dev`
9+
10+
### Releasing the package
11+
- Ensure new changes are merged to `dev` and the version number is bumped according to [sematic versioning](https://semver.org/).
12+
- Merge `dev`to `main`. This should trigger tests.
13+
- Create a git tag for the new version :
14+
```
15+
git checkout main
16+
git pull
17+
git tag vX.Y.Z # Replace X.Y.Z with the new version number
18+
git push origin vX.Y.Z
19+
```
20+
- Create a PR from `main` to `release` and get one approval
21+
- Once the PR is merged, it will trigger the release of the new package version and publish the documentation.

codegreen_core/utilities/log.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# to log stuff
2+
3+
from .config import Config
4+
from datetime import datetime
5+
import os
6+
import csv
7+
8+
9+
def time_prediction(data):
10+
if Config.get("enable_time_prediction_logging")==True:
11+
current_date = datetime.now()
12+
file_name = f"{current_date.strftime('%B')}_{current_date.year}.csv"
13+
file_location = os.path.join(Config.get("time_prediction_log_folder_path"), file_name)
14+
file_exists = os.path.exists(file_location)
15+
# Open the file in append mode
16+
with open(file_location, mode='a', newline='') as file:
17+
writer = csv.DictWriter(file, fieldnames=data.keys())
18+
# If the file doesn't exist, write the header
19+
if not file_exists:
20+
writer.writeheader()
21+
# Append the data to the file
22+
writer.writerow(data)
23+
else:
24+
print("Logging not enabled")

docs/models.rst

Lines changed: 0 additions & 20 deletions
This file was deleted.

tests/test_predictions.py renamed to tests/test1_predictions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# this code is not yet used
12
from codegreen_core.models import predict
23
from codegreen_core.data import energy
34
from datetime import datetime

tests/test_data.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
2-
from codegreen_core.data import entsoe,energy,carbon_intensity
2+
from codegreen_core.data import energy
3+
from codegreen_core.data.entsoe import renewableSources
34
from codegreen_core.utilities.message import CodegreenDataError
45
from datetime import datetime
56
import pandas as pd
@@ -32,15 +33,15 @@ def test_entsoe_generation_data(self):
3233
"start":datetime(2024,2,1),
3334
"end":datetime(2024,2,2),
3435
"dtype": 'generation' ,
35-
"file": "data/generation_DE_24_downloaded.csv",
36+
"file": "tests/data/generation_DE_24_downloaded.csv",
3637
"interval60": False
3738
},
3839
{
3940
"country":"DE",
4041
"start":datetime(2024,3,20),
4142
"end":datetime(2024,3,24),
4243
"dtype": 'generation' ,
43-
"file": "data/generation_DE_24_downloaded.csv",
44+
"file": "tests/data/generation_DE_24_downloaded.csv",
4445
"interval60": False
4546
},
4647
# {
@@ -57,15 +58,15 @@ def test_entsoe_generation_data(self):
5758
"start":datetime(2024,3,20),
5859
"end":datetime(2024,3,24),
5960
"dtype": 'generation' ,
60-
"file": "data/generation_GR_24_downloaded.csv",
61+
"file": "tests/data/generation_GR_24_downloaded.csv",
6162
"interval60": True
6263
},
6364
{
6465
"country":"GR",
6566
"start":datetime(2024,1,25),
6667
"end":datetime(2024,1,28),
6768
"dtype": 'generation' ,
68-
"file": "data/generation_GR_24_downloaded.csv",
69+
"file": "tests/data/generation_GR_24_downloaded.csv",
6970
"interval60": True
7071
}
7172

@@ -84,7 +85,7 @@ def test_entsoe_generation_data(self):
8485
end_utc = pd.to_datetime(case["end"]) #case["end"].astimezone(pd.Timestamp.now(tz='UTC').tzinfo) if case["end"].tzinfo is None else case["end"]
8586
filtered_df = data_verify[(data_verify['start_date'] >= start_utc) & (data_verify['start_date'] < end_utc)]
8687
allCols = data.columns.tolist()
87-
renPresent = list(set(allCols).intersection(entsoe.renewableSources))
88+
renPresent = list(set(allCols).intersection(renewableSources))
8889
for e in renPresent:
8990
difference = filtered_df[e+" - Actual Aggregated [MW]"] - data[e]
9091
sum_of_differences = difference.sum()

tests/test_loadshift_location.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def test_location_now():
1010
# test_location_now()
1111

1212
def fetch_data(month_no,countries):
13-
data = pd.read_csv("data/prediction_testing_data.csv")
13+
data = pd.read_csv("tests/data/prediction_testing_data.csv")
1414
forecast_data = {}
1515
for c in countries:
1616
filter = data["file_id"] == c+""+str(month_no)
@@ -40,4 +40,4 @@ def test_locations():
4040
a,b,c,d = predict_optimal_location(data,case["h"],case["m"],case["p"],end,start)
4141
print(a,b,c,d)
4242

43-
test_locations()
43+
# test_locations()

tests/test_loadshift_time.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import codegreen_core.tools as tools
21
import pytest
32
from codegreen_core.utilities.message import CodegreenDataError,Message
43
from datetime import datetime,timezone,timedelta
@@ -69,13 +68,13 @@ def test_less_energy_data(self):
6968

7069
def test_if_incorrect_data_provided(self):
7170
"""this is to test if energy data provided does not contain the data for the request time """
72-
data = pd.read_csv("data/DE_forecast1.csv")
71+
data = pd.read_csv("tests/data/DE_forecast1.csv")
7372
timestamp, message, average_percent_renewable = ts.predict_optimal_time(data,20,0,10,self.hard_finish_time_2,self.request_time_2)
7473
assert timestamp == int(self.request_time_2.timestamp())
7574
assert message == Message.NO_DATA
7675

7776
def test_multiple(self):
78-
data = pd.read_csv("data/DE_forecast1.csv")
77+
data = pd.read_csv("tests/data/DE_forecast1.csv")
7978
hard_finish_time = datetime(2024,1,7,0,0)
8079
request_time = datetime(2024,1,5,0,0)
8180
cases = [
@@ -179,17 +178,17 @@ def test_data_validation_country(self):
179178
print(timestamp1,timestamp, message)
180179
assert timestamp - timestamp1 <= 10
181180
assert message == Message.ENERGY_DATA_FETCHING_ERROR
182-
def test_all_country_test(self):
183-
test_cases = pd.read_csv("./data/test_cases_time.csv")
184-
data = pd.read_csv("./data/prediction_testing_data.csv")
185-
for index, row in test_cases.iterrows():
186-
edata_filter = data["file_id"] == row["country"]
187-
energy_data = data[edata_filter].copy()
188-
start = datetime.strptime(row["start_time"], '%Y-%m-%d %H:%M:%S')
189-
end = (start + timedelta(hours=row["hard_deadline_hour"]))
190-
a,b,c = ts.predict_optimal_time(energy_data,row["runtime_hour"],row["runtime_min"],row["percent_renewable"],end,start)
191-
print(a,b,c)
192-
assert int(a) == row["expected_timestamp"]
181+
# def test_all_country_test(self):
182+
# test_cases = pd.read_csv("./data/test_cases_time.csv")
183+
# data = pd.read_csv("./data/prediction_testing_data.csv")
184+
# for index, row in test_cases.iterrows():
185+
# edata_filter = data["file_id"] == row["country"]
186+
# energy_data = data[edata_filter].copy()
187+
# start = datetime.strptime(row["start_time"], '%Y-%m-%d %H:%M:%S')
188+
# end = (start + timedelta(hours=row["hard_deadline_hour"]))
189+
# a,b,c = ts.predict_optimal_time(energy_data,row["runtime_hour"],row["runtime_min"],row["percent_renewable"],end,start)
190+
# print(a,b,c)
191+
# assert int(a) == row["expected_timestamp"]
193192

194193
# for case in cases:
195194
# #print(case)
@@ -201,8 +200,8 @@ def test_all_country_test(self):
201200

202201
# test if request time is none current time is being used
203202
def test_all_country():
204-
test_cases = pd.read_csv("./data/test_cases_time.csv")
205-
data = pd.read_csv("./data/prediction_testing_data.csv")
203+
test_cases = pd.read_csv("tests/data/test_cases_time.csv")
204+
data = pd.read_csv("tests/data/prediction_testing_data.csv")
206205
for _ , row in test_cases.iterrows():
207206
print(row)
208207
edata_filter = data["file_id"] == row["country"]
@@ -218,7 +217,7 @@ def test_all_country():
218217
assert int(a) == row["expected_timestamp"]
219218
print("====")
220219

221-
test_all_country()
220+
# test_all_country()
222221

223222

224223
# def data_validation_country():

0 commit comments

Comments
 (0)