Skip to content

Commit

Permalink
Fix - Added possibility to set logging level and prepared new version
Browse files Browse the repository at this point in the history
  • Loading branch information
davidusb-geek committed May 27, 2023
1 parent 0de77aa commit df86537
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Added new constraint to avoid battery discharging to the grid
### Fix
- Bumped version of skforecast from 0.6.0 to 0.8.0. Doing this mainly implies changing how the exogenous data is passed to fit and predict methods.
- Fixed wrong path for csv files when using load cost and prod price forecasts.

## [0.4.10] - 2023-05-21
### Fix
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
author = 'David HERNANDEZ'

# The full version, including alpha/beta/rc tags
release = '0.4.10'
release = '0.4.11'

# -- General configuration ---------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

setup(
name='emhass', # Required
version='0.4.10', # Required
version='0.4.11', # Required
description='An Energy Management System for Home Assistant', # Optional
long_description=long_description, # Optional
long_description_content_type='text/markdown', # Optional (see note above)
Expand Down
2 changes: 1 addition & 1 deletion src/emhass/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h4 style="font-family: Helvetica;color: darkblue;">Use the buttons below to fit
<button type="button" id="forecast-model-fit" class="button button1" >ML forecast model fit</button>
<button type="button" id="forecast-model-predict" class="button button2" >ML forecast model predict</button>
<button type="button" id="forecast-model-tune" class="button button3" >ML forecast model tune</button>
<<!-- h4 style="font-family: Helvetica;color: darkblue;">Pass any needed data dictionary here</h4>
<!-- h4 style="font-family: Helvetica;color: darkblue;">Pass any needed data dictionary here</h4>
<div class="input-group">
<textarea id="runtimeparams" name="runtimeparams" rows="6" cols="65"></textarea>
</div> -->
Expand Down
31 changes: 24 additions & 7 deletions src/emhass/web_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,8 @@
from emhass.command_line import forecast_model_fit, forecast_model_predict, forecast_model_tune
from emhass.command_line import publish_data


# Define the Flask instance
app = Flask(__name__)
app.logger.setLevel(logging.DEBUG)
app.logger.propagate = False
ch = logging.StreamHandler()
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
app.logger.addHandler(ch)

def get_injection_dict(df, plot_size = 1366):
# Create plots
Expand Down Expand Up @@ -301,6 +294,7 @@ def action_call(action_name):
# The cost function
costfun = options['costfun']
# Some data from options
logging_level = options['logging_level']
url_from_options = options['hass_url']
if url_from_options == 'empty':
url = hass_url+"/config"
Expand Down Expand Up @@ -328,6 +322,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:
params_secrets = yaml.load(file, Loader=yaml.FullLoader)
hass_url = params_secrets['hass_url']
Expand All @@ -337,6 +332,28 @@ def action_call(action_name):
with open(str(data_path / 'params.pkl'), "wb") as fid:
pickle.dump((config_path, params), fid)

# Define logger
ch = logging.StreamHandler()
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
if logging_level == "DEBUG":
app.logger.setLevel(logging.DEBUG)
ch.setLevel(logging.DEBUG)
elif logging_level == "INFO":
app.logger.setLevel(logging.INFO)
ch.setLevel(logging.INFO)
elif logging_level == "WARNING":
app.logger.setLevel(logging.WARNING)
ch.setLevel(logging.WARNING)
elif logging_level == "ERROR":
app.logger.setLevel(logging.ERROR)
ch.setLevel(logging.ERROR)
else:
app.logger.setLevel(logging.DEBUG)
ch.setLevel(logging.DEBUG)
app.logger.propagate = False
app.logger.addHandler(ch)

# Launch server
port = int(os.environ.get('PORT', 5000))
app.logger.info("Launching the emhass webserver at: http://"+web_ui_url+":"+str(port))
Expand Down

0 comments on commit df86537

Please sign in to comment.