Skip to content

Commit dff3aec

Browse files
committed
new pkg
1 parent d6c2ae5 commit dff3aec

File tree

4 files changed

+43
-7
lines changed

4 files changed

+43
-7
lines changed

.github/workflows/workflow.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Publish Python 🐍 distribution 📦 to PyPI
1+
name: Publish to PyPI
22

33
on:
44
push:
@@ -7,7 +7,7 @@ on:
77

88
jobs:
99
build:
10-
name: Build distribution 📦
10+
name: Build distribution
1111
runs-on: ubuntu-latest
1212

1313
steps:
@@ -30,7 +30,7 @@ jobs:
3030
path: dist/
3131

3232
publish-to-pypi:
33-
name: Publish Python 🐍 distribution 📦 to PyPI
33+
name: Publish to PyPI
3434
needs:
3535
- build
3636
runs-on: ubuntu-latest

codegreen_core/data/entsoe.py

+34
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
"Biomass": ["Biomass"],
4848
}
4949

50+
51+
5052
# helper methods
5153

5254

@@ -287,6 +289,7 @@ def get_actual_production_percentage(country, start, end, interval60=False) -> d
287289
- `data_available`: A boolean indicating if data was successfully retrieved.
288290
- `data`: A pandas DataFrame containing the energy data if available, empty DataFrame if not.
289291
- `time_interval` : the time interval of the DataFrame
292+
- `columns` : a dict with column description
290293
:rtype: dict
291294
"""
292295
try:
@@ -371,6 +374,7 @@ def get_actual_production_percentage(country, start, end, interval60=False) -> d
371374
"data": _format_energy_data(table),
372375
"data_available": True,
373376
"time_interval": duration,
377+
"columns":gen_cols_from_data(table)
374378
}
375379
except Exception as e:
376380
# print(e)
@@ -380,8 +384,38 @@ def get_actual_production_percentage(country, start, end, interval60=False) -> d
380384
"data_available": False,
381385
"error": e,
382386
"time_interval": 0,
387+
"columns":None
383388
}
384389

390+
def gen_cols_from_data(df):
391+
"""generates list of columns for the given energy generation dataframe"""
392+
allAddkeys = [
393+
"Wind",
394+
"Solar",
395+
"Nuclear",
396+
"Hydroelectricity",
397+
"Geothermal",
398+
"Natural Gas",
399+
"Petroleum",
400+
"Coal",
401+
"Biomass",
402+
]
403+
404+
allCols = df.columns.tolist()
405+
# find out which columns are present in the data out of all the possible columns in both the categories
406+
renPresent = list(set(allCols).intersection(renewableSources))
407+
nonRenPresent = list(set(allCols).intersection(nonRenewableSources))
408+
409+
cols = {
410+
"renewable" : renPresent,
411+
"nonRenewable": nonRenPresent,
412+
"percentage":[]
413+
}
414+
for ky in allAddkeys:
415+
fieldName = ky + "_per"
416+
cols["percentage"].append(fieldName)
417+
return cols
418+
385419

386420
def get_forecast_percent_renewable(
387421
country: str, start: datetime, end: datetime

codegreen_core/data/main.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def energy(country, start_time, end_time, type="generation") -> dict:
5858
- **data** (*pandas.DataFrame*): The retrieved energy data if available; an empty DataFrame otherwise.
5959
- **time_interval** (*int*): The time interval of the DataFrame (constant value: ``60``).
6060
- **source** (*str*): Specifies the origin of the retrieved data. Defaults to ``'public_data'``, indicating it was fetched from an external source. If the offline storage feature is enabled, this value may change if the data is available locally.
61+
- **columns** : a dict of columns for renewable and non renewable energy sources in the data
6162
6263
:rtype: dict
6364
@@ -99,15 +100,16 @@ def energy(country, start_time, end_time, type="generation") -> dict:
99100
offline_data = off.get_offline_data(country,start_time,end_time)
100101
if offline_data["available"] is True and offline_data["partial"] is False and offline_data["data"] is not None:
101102
# todo fix this if partial get remaining data and merge instead of fetching the complete data
102-
return {"data":offline_data["data"],"data_available":True,"error":"None","time_interval":60,"source":offline_data["source"]}
103+
return {"data":offline_data["data"],"data_available":True,"error":"None","time_interval":60,"source":offline_data["source"],"columns":et.gen_cols_from_data(offline_data["data"])}
103104
else:
104105
energy_data = et.get_actual_production_percentage(country, start_time, end_time, interval60=True)
105-
energy_data["data"] = energy_data["data"]
106+
#energy_data["data"] = energy_data["data"]
106107
energy_data["source"] = "public_data"
108+
#energy_data["columns"] =
107109
return energy_data
108110
elif type == "forecast":
109111
energy_data = et.get_forecast_percent_renewable(country, start_time, end_time)
110-
energy_data["data"] = energy_data["data"]
112+
# energy_data["data"] = energy_data["data"]
111113
return energy_data
112114
else:
113115
raise CodegreenDataError(Message.NO_ENERGY_SOURCE)

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "codegreen_core"
3-
version = "0.0.4"
3+
version = "0.0.5"
44
description = "This package helps you become aware of the carbon footprint of your computation"
55
authors = ["Anne Hartebrodt <anne.hartebrodt@fau.de>","Shubh Vardhan Jain <shubh.v.jain@fau.de>"]
66
readme = "README.md"

0 commit comments

Comments
 (0)