Skip to content

Commit

Permalink
Fix - Preparing version 0.6.0, see CHANGELOG
Browse files Browse the repository at this point in the history
  • Loading branch information
davidusb-geek committed Dec 16, 2023
1 parent 53dc763 commit ce01fd9
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 33 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Changelog

## [0.6.0] - 2023-12-16
### Improvement
- Now Python 3.11 is fully supported, thanks to @pail23
- Bumped setuptools, skforecast, numpy, scipy, pandas
- A good bunch of documentation improvements thanks to @g1za
### Fix
- Some fixes managing time zones, thanks to @pail23
- Bug fix on grid cost function equation, thanks to @michaelpiron
- Applying a first set of fixes proposed by @smurfix:
- Don't ignore HTTP errors
- Handle missing variable correctly
- Slight error message improvement
- Just use the default solver
- Get locations from environment in non-app mode
- Tolerate running directly from source

## [0.5.1] - 2023-10-19
### Improvement
- Improved documentation, thanks to @g1za
Expand Down Expand Up @@ -471,6 +487,9 @@
[0.4.13]: https://github.com/davidusb-geek/emhass/releases/tag/v0.4.13
[0.4.14]: https://github.com/davidusb-geek/emhass/releases/tag/v0.4.14
[0.4.15]: https://github.com/davidusb-geek/emhass/releases/tag/v0.4.15
[0.5.0]: https://github.com/davidusb-geek/emhass/releases/tag/v0.5.0
[0.5.1]: https://github.com/davidusb-geek/emhass/releases/tag/v0.5.1
[0.6.0]: https://github.com/davidusb-geek/emhass/releases/tag/v0.6.0

# Notes
All notable changes to this project will be documented in this file.
Expand Down
2 changes: 1 addition & 1 deletion config_emhass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ optim_conf:
- prod_price_forecast_method: 'constant' # options are 'constant' for constant fixed value or 'csv' to load custom price forecast from a CSV file
- prod_sell_price: 0.065 # power production selling price in €/kWh (only needed if prod_price_forecast_method='constant')
- set_total_pv_sell: False # consider that all PV power is injected to the grid (self-consumption with total sell)
- lp_solver: 'PULP_CBC_CMD' # set the name of the linear programming solver that will be used
- lp_solver: 'default' # set the name of the linear programming solver that will be used
- lp_solver_path: 'empty' # set the path to the LP solver
- set_nocharge_from_grid: False # avoid battery charging from the grid
- set_nodischarge_to_grid: True # avoid battery discharging to the grid
Expand Down
6 changes: 3 additions & 3 deletions scripts/load_clustering_stumpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
# fig = (px.line(df, x='Clusters', y='Distortions', template=template)).update_traces(mode='lines+markers')
# fig.show()

# The silouhette metod
# The silouhette method
silhouette_scores = []
K = range(2,12)

Expand All @@ -111,7 +111,7 @@
# The clustering
kmeans = KMeans(n_clusters=6, init='k-means++')
kmeans = kmeans.fit(data_lag)
data['cluster_group'] = kmeans.labels_
data_lag['cluster_group'] = kmeans.labels_

fig = px.scatter(data, x='power_load y(t)', y='power_load y(t+1)', color='cluster_group', template=template)
fig = px.scatter(data_lag, x='power_load y(t)', y='power_load y(t+1)', color='cluster_group', template=template)
fig.show()
2 changes: 1 addition & 1 deletion src/emhass/forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def get_weather_forecast(self, method: Optional[str] = 'scrapper',
# Define index
data.set_index('ts', inplace=True)
else:
self.logger.error("Passed method is not valid")
self.logger.error("Method %r is not valid", method)

Check warning on line 318 in src/emhass/forecast.py

View check run for this annotation

Codecov / codecov/patch

src/emhass/forecast.py#L318

Added line #L318 was not covered by tests
return data

def cloud_cover_to_irradiance(self, cloud_cover: pd.Series,
Expand Down
25 changes: 12 additions & 13 deletions src/emhass/optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,25 +387,24 @@ def perform_optimization(self, data_opt: pd.DataFrame, P_PV: np.array, P_load: n

## Finally, we call the solver to solve our optimization model:
# solving with default solver CBC
try:
if self.lp_solver == 'PULP_CBC_CMD':
opt_model.solve(PULP_CBC_CMD(msg=0))
elif self.lp_solver == 'GLPK_CMD':
opt_model.solve(GLPK_CMD(msg=0))
elif self.lp_solver == 'COIN_CMD':
opt_model.solve(COIN_CMD(msg=0, path=self.lp_solver_path))
else:
self.logger.error("Invalid solver name passed")
except Exception:
self.logger.error("It was not possible to find a valid solver for Pulp package")
if self.lp_solver == 'PULP_CBC_CMD':
opt_model.solve(PULP_CBC_CMD(msg=0))

Check warning on line 391 in src/emhass/optimization.py

View check run for this annotation

Codecov / codecov/patch

src/emhass/optimization.py#L391

Added line #L391 was not covered by tests
elif self.lp_solver == 'GLPK_CMD':
opt_model.solve(GLPK_CMD(msg=0))

Check warning on line 393 in src/emhass/optimization.py

View check run for this annotation

Codecov / codecov/patch

src/emhass/optimization.py#L393

Added line #L393 was not covered by tests
elif self.lp_solver == 'COIN_CMD':
opt_model.solve(COIN_CMD(msg=0, path=self.lp_solver_path))

Check warning on line 395 in src/emhass/optimization.py

View check run for this annotation

Codecov / codecov/patch

src/emhass/optimization.py#L395

Added line #L395 was not covered by tests
else:
self.logger.warning("Solver %s unknown, using default", self.lp_solver)
opt_model.solve()

# The status of the solution is printed to the screen
self.optim_status = plp.LpStatus[opt_model.status]
self.logger.info("Status: " + self.optim_status)
if plp.value(opt_model.objective) is None:
self.logger.warning("Cost function cannot be evaluated, probably None")
self.logger.warning("Cost function cannot be evaluated")
return

Check warning on line 405 in src/emhass/optimization.py

View check run for this annotation

Codecov / codecov/patch

src/emhass/optimization.py#L404-L405

Added lines #L404 - L405 were not covered by tests
else:
self.logger.info("Total value of the Cost function = " + str(round(plp.value(opt_model.objective),2)))
self.logger.info("Total value of the Cost function = %.02f", plp.value(opt_model.objective))

# Build results Dataframe
opt_tp = pd.DataFrame()
Expand Down
18 changes: 9 additions & 9 deletions src/emhass/retrieve_hass.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ def get_data(self, days_list: pd.date_range, var_list: list, minimal_response: O
response = get(url, headers=headers)
except Exception:
return "Request Get Error"
else:
if response.status_code > 299:
return f"Request Get Error: {response.status_code}"

Check warning on line 121 in src/emhass/retrieve_hass.py

View check run for this annotation

Codecov / codecov/patch

src/emhass/retrieve_hass.py#L121

Added line #L121 was not covered by tests
'''import bz2 # Uncomment to save a serialized data for tests
import _pickle as cPickle
with bz2.BZ2File("data/test_response_get_data_get_method.pbz2", "w") as f:
Expand Down Expand Up @@ -174,17 +177,14 @@ def prepare_data(self, var_load: str, load_negative: Optional[bool] = False, set
:rtype: pandas.DataFrame
"""
if load_negative: # Apply the correct sign to load power
try:
try:
if load_negative: # Apply the correct sign to load power
self.df_final[var_load+'_positive'] = -self.df_final[var_load]
except KeyError:
self.logger.error("Variable "+var_load+" was not found. This is typically because no data could be retrieved from Home Assistant")
else:
try:
else:
self.df_final[var_load+'_positive'] = self.df_final[var_load]
except KeyError:
self.logger.error("Variable "+var_load+" was not found. This is typically because no data could be retrieved from Home Assistant")
self.df_final.drop([var_load], inplace=True, axis=1)
self.df_final.drop([var_load], inplace=True, axis=1)
except KeyError:
self.logger.error("Variable "+var_load+" was not found. This is typically because no data could be retrieved from Home Assistant")

Check warning on line 187 in src/emhass/retrieve_hass.py

View check run for this annotation

Codecov / codecov/patch

src/emhass/retrieve_hass.py#L186-L187

Added lines #L186 - L187 were not covered by tests
if set_zero_min: # Apply minimum values
self.df_final.clip(lower=0.0, inplace=True, axis=1)
self.df_final.replace(to_replace=0.0, value=np.nan, inplace=True)
Expand Down
13 changes: 8 additions & 5 deletions src/emhass/web_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from jinja2 import Environment, PackageLoader
from requests import get
from waitress import serve
from importlib.metadata import version
from importlib.metadata import version, PackageNotFoundError
from pathlib import Path
import os, json, argparse, pickle, yaml, logging
from distutils.util import strtobool
Expand Down Expand Up @@ -265,9 +265,9 @@ def action_call(action_name):
app.logger.error("options.json does not exists")
DATA_PATH = "/share/" #"/data/"
else:
CONFIG_PATH = "/app/config_emhass.yaml"
CONFIG_PATH = os.getenv("CONFIG_PATH", default="/app/config_emhass.yaml")
options = None
DATA_PATH = "/app/data/"
DATA_PATH = os.getenv("DATA_PATH", default="/app/data/")
config_path = Path(CONFIG_PATH)
data_path = Path(DATA_PATH)

Expand Down Expand Up @@ -328,7 +328,7 @@ def action_call(action_name):
else:
costfun = os.getenv('LOCAL_COSTFUN', default='profit')
logging_level = os.getenv('LOGGING_LEVEL', default='INFO')
with open('/app/secrets_emhass.yaml', 'r') as file:
with open(os.getenv('SECRETS_PATH', default='/app/secrets_emhass.yaml'), 'r') as file:
params_secrets = yaml.load(file, Loader=yaml.FullLoader)
hass_url = params_secrets['hass_url']

Expand Down Expand Up @@ -364,5 +364,8 @@ def action_call(action_name):
app.logger.info("Launching the emhass webserver at: http://"+web_ui_url+":"+str(port))
app.logger.info("Home Assistant data fetch will be performed using url: "+hass_url)
app.logger.info("The data path is: "+str(data_path))
app.logger.info("Using core emhass version: "+version('emhass'))
try:
app.logger.info("Using core emhass version: "+version('emhass'))
except PackageNotFoundError:
app.logger.info("Using development emhass version")
serve(app, host=web_ui_url, port=port, threads=8)
2 changes: 1 addition & 1 deletion tests/test_retrieve_hass.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np, pandas as pd
import pytz, pathlib, pickle, json, yaml, copy
import bz2
import _pickle as cPickle
import pickle as cPickle

from emhass.retrieve_hass import retrieve_hass
from emhass.utils import get_root, get_yaml_parse, get_days_list, get_logger
Expand Down

0 comments on commit ce01fd9

Please sign in to comment.