Skip to content

Commit 081b060

Browse files
committed
main energy code
1 parent 397b0b5 commit 081b060

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,4 @@ poetry.lock
177177

178178
codegreen_core/tools/test.py
179179
codegreen_core/data/test.py
180+
tests/test_notebook.ipynb

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
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/).
44

5+
# Development
6+
7+
## Installation
8+
- `git clone`
9+
- install poetry
10+
- install in editable mode : `poetry install`
11+
12+
## Github workflows
13+
Changes in the repo also triggers github actions
14+
515
## Development workflow
616
- the `release` branch contains the latest stable version of the released python package
717
- the `main` branch contains stable, tested code ready to be released.

codegreen_core/data/main.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,12 @@
33

44
from ..utilities.message import Message, CodegreenDataError
55
from ..utilities import metadata as meta
6-
from . import entsoe as et
7-
6+
from ..utilities.config import Config
87

9-
def _format_energy_data(df):
10-
start_time_column = df.pop("startTimeUTC")
11-
df.insert(0, "startTime", start_time_column)
12-
local_timezone = datetime.now().astimezone().tzinfo
13-
df["startTime"] = pd.to_datetime(df["startTime"], format="%Y%m%d%H%M").dt.tz_localize("UTC").dt.tz_convert(local_timezone)
14-
df.insert(1, "startTimeUTC", start_time_column)
15-
return df
8+
from . import entsoe as et
9+
from . import offline as off
1610

17-
def energy(country, start_time, end_time, type="generation", interval60=True) -> dict:
11+
def energy(country, start_time, end_time, type="generation") -> dict:
1812
"""
1913
Returns hourly time series of energy production mix for a specified country and time range.
2014
@@ -81,14 +75,25 @@ def energy(country, start_time, end_time, type="generation", interval60=True) ->
8175
e_source = meta.get_country_energy_source(country)
8276
if e_source == "ENTSOE":
8377
if type == "generation":
84-
energy_data = et.get_actual_production_percentage(
85-
country, start_time, end_time, interval60
86-
)
87-
energy_data["data"] = _format_energy_data(energy_data["data"])
88-
return energy_data
78+
"""
79+
let local_found= false
80+
see if caching is enabled, if yes, first check in the cache
81+
if not,
82+
check if offline data is enabled
83+
if yes, check is data is available locally
84+
if no, go online
85+
"""
86+
offline_data = off.get_offline_data(country,start_time,end_time)
87+
if offline_data["available"] is True and offline_data["partial"] is False:
88+
# todo fix this if partial get remaining data and merge instead of fetching the complete data
89+
return {"data":offline_data["data"],"data_available":True,"error":"None","time_interval":60,"message":"Data from offline source"}
90+
else:
91+
energy_data = et.get_actual_production_percentage(country, start_time, end_time, interval60=True)
92+
energy_data["data"] = energy_data["data"]
93+
return energy_data
8994
elif type == "forecast":
9095
energy_data = et.get_forecast_percent_renewable(country, start_time, end_time)
91-
energy_data["data"] = _format_energy_data(energy_data["data"])
96+
energy_data["data"] = energy_data["data"]
9297
return energy_data
9398
else:
9499
raise CodegreenDataError(Message.NO_ENERGY_SOURCE)

0 commit comments

Comments
 (0)