Skip to content

Commit

Permalink
Merge b88dea2 into 2973868
Browse files Browse the repository at this point in the history
  • Loading branch information
craigmaloney committed Aug 20, 2018
2 parents 2973868 + b88dea2 commit 7e647a3
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 37 deletions.
41 changes: 41 additions & 0 deletions scripts/logging.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": 1,
"disable_existing_loggers": false,
"formatters": {
"simple": {
"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
}
},

"handlers": {
"console": {
"class": "logging.StreamHandler",
"level": "INFO",
"formatter": "simple",
"stream": "ext://sys.stdout"
},

"file_handler": {
"class": "logging.handlers.RotatingFileHandler",
"level": "INFO",
"formatter": "simple",
"filename": "epathermostat.log",
"maxBytes": 10485760,
"backupCount": 20,
"encoding": "utf8"
}
},

"loggers": {
"epathermostat": {
"level": "INFO",
"handlers": ["console"],
"propagate": "no"
}
},

"root": {
"level": "INFO",
"handlers": ["console", "file_handler"]
}
}
41 changes: 41 additions & 0 deletions scripts/logging_noisy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": 1,
"disable_existing_loggers": false,
"formatters": {
"simple": {
"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
}
},

"handlers": {
"console": {
"class": "logging.StreamHandler",
"level": "DEBUG",
"formatter": "simple",
"stream": "ext://sys.stdout"
},

"file_handler": {
"class": "logging.handlers.RotatingFileHandler",
"level": "DEBUG",
"formatter": "simple",
"filename": "epathermostat.log",
"maxBytes": 10485760,
"backupCount": 20,
"encoding": "utf8"
}
},

"loggers": {
"epathermostat": {
"level": "DEBUG",
"handlers": ["console"],
"propagate": "no"
}
},

"root": {
"level": "INFO",
"handlers": ["console", "file_handler"]
}
}
41 changes: 41 additions & 0 deletions scripts/logging_quiet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": 1,
"disable_existing_loggers": false,
"formatters": {
"simple": {
"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
}
},

"handlers": {
"console": {
"class": "logging.StreamHandler",
"level": "ERROR",
"formatter": "simple",
"stream": "ext://sys.stdout"
},

"file_handler": {
"class": "logging.handlers.RotatingFileHandler",
"level": "ERROR",
"formatter": "simple",
"filename": "epathermostat.log",
"maxBytes": 10485760,
"backupCount": 20,
"encoding": "utf8"
}
},

"loggers": {
"epathermostat": {
"level": "ERROR",
"handlers": ["console"],
"propagate": "no"
}
},

"root": {
"level": "INFO",
"handlers": ["console", "file_handler"]
}
}
18 changes: 16 additions & 2 deletions scripts/multi_thermostat_tutorial.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
import logging
import logging.config
import json
from thermostat.importers import from_csv
from thermostat.exporters import metrics_to_csv
from thermostat.stats import compute_summary_statistics
Expand All @@ -15,13 +17,25 @@


def main():
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)

logging.basicConfig()
# Example logging configuration for file and console output
# logging.json: Normal logging example
# logging_noisy.json: Turns on all debugging information
# logging_quiet.json: Only logs error messages
with open("logging.json", "r") as logging_config:
logging.config.dictConfig(json.load(logging_config))

logger = logging.getLogger('epathermostat') # Uses the 'epathermostat' logging
logging.captureWarnings(True) # Set to True to log additional warning messages, False to only display on console

data_dir = os.path.join("..", "tests", "data")
metadata_filename = os.path.join(data_dir, "metadata.csv")

# Use this to save the weather cache to local disk files
# thermostats = from_csv(metadata_filename, verbose=True, save_cache=True, cache_path='/tmp/epa_weather_files/')

# Verbose will override logging to display the imported thermostats. Set to "False" to use the logging level instead
thermostats = from_csv(metadata_filename, verbose=True)

output_dir = "."
Expand Down
26 changes: 11 additions & 15 deletions scripts/tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@
"from thermostat.stats import summary_statistics_to_csv\n",
"from thermostat.multiple import multiple_thermostat_calculate_epa_field_savings_metrics\n",
"\n",
"logger = logging.getLogger()\n",
"logger.setLevel(logging.DEBUG)\n",
"logger = logging.getLogger('epathermostat')\n",
"# Set this to 'DEBUG' for more logging messages (default: WARNING)\n",
"# See `multi_thermostat_tutorial.py` for how to \n",
"# use a logging configuration file which logs to console / file\n",
"logger.setLevel(logging.WARNING)\n",
"\n",
"data_dir = os.path.join(expanduser(\"~\"), \"Downloads\")"
]
Expand Down Expand Up @@ -68,17 +71,8 @@
"outputs": [],
"source": [
"metadata_filename = os.path.join(data_dir, \"metadata.csv\")\n",
"thermostats = from_csv(metadata_filename, verbose=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# dev specific\n",
"metadata_filename = os.path.join(data_dir, \"metadata.csv\")\n",
"# verbose=True will override logging to display the imported thermostats\n",
"# Set verbose to \"False\" to use the logging level instead\n",
"thermostats = from_csv(metadata_filename, verbose=True)"
]
},
Expand Down Expand Up @@ -110,13 +104,15 @@
"outputs": [],
"source": [
"# Use this to process each thermostat one-at-a-time\n",
"'''\n",
"metrics = []\n",
"ts = []\n",
"\n",
"for thermostat_ in thermostats:\n",
" outputs = thermostat_.calculate_epa_field_savings_metrics()\n",
" metrics.extend(outputs)\n",
" ts.append(thermostat_)"
" ts.append(thermostat_)\n",
"'''"
]
},
{
Expand Down Expand Up @@ -176,7 +172,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.5"
"version": "3.6.6"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/thermostats.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def metrics_type_1_data():
'root_mean_sq_err': 19.47517001343749,
'start_date': '2011-01-01T00:00:00',
'station': '725314',
'sw_version': '1.5.0',
'sw_version': '1.5.1',
'tau': -0.8165326352929079,
'total_core_cooling_runtime': 73087.0,
'zipcode': '62223'
Expand Down Expand Up @@ -254,7 +254,7 @@ def metrics_type_1_data():
'root_mean_sq_err': 83.04860314852706,
'start_date': '2011-01-01T00:00:00',
'station': '725314',
'sw_version': '1.5.0',
'sw_version': '1.5.1',
'tau': -2.3486605751007135,
'total_auxiliary_heating_core_day_runtime': 144794.0,
'total_core_heating_runtime': 691905.0,
Expand Down
2 changes: 1 addition & 1 deletion thermostat/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = (1, 5, 0)
VERSION = (1, 5, 1)

def get_version():
return '{}.{}.{}'.format(VERSION[0], VERSION[1], VERSION[2])
Expand Down
31 changes: 17 additions & 14 deletions thermostat/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from itertools import repeat
import inspect
from warnings import warn
import logging

import pandas as pd
import numpy as np
Expand All @@ -25,6 +26,9 @@
["name", "daily", "hourly", "start_date", "end_date"]
)

logger = logging.getLogger('epathermostat')


class Thermostat(object):
""" Main thermostat data container. Each parameter which contains
timeseries data should be a pandas.Series with a datetimeIndex, and that
Expand Down Expand Up @@ -541,8 +545,7 @@ def get_resistance_heat_utilization_bins(self, core_heating_day_set):
try:
rhu = float(R_aux + R_emg) / float(R_heat + R_emg)
except ZeroDivisionError:
warn(
'WARNING: '
logger.debug(
'rhu calculation divided by zero (%s + %s / %s + %s) '
'for thermostat_id %s '
'from %s to %s inclusive' % (
Expand Down Expand Up @@ -624,8 +627,8 @@ def get_inputfile_date_range(self, core_day_set):
try:
result = int(delta.astype('timedelta64[D]') / np.timedelta64(1, 'D'))
except ZeroDivisionError:
warn(
'WARNING: Date Range divided by zero: %s / %s '
logger.debug(
'Date Range divided by zero: %s / %s '
'for thermostat_id %s' % (
delta.astype('timedelta64[D]'), np.timedelta64(1, 'D'),
self.thermostat_id))
Expand Down Expand Up @@ -715,8 +718,8 @@ def calc_estimates(tau):
try:
alpha_estimate = total_runtime / total_cdd
except ZeroDivisionError:
warn(
'WARNING: Alpha Estimate divided by zero: %s / %s'
logger.debug(
'Alpha Estimate divided by zero: %s / %s'
'for thermostat %s' % (
total_runtime, total_cdd,
self.thermostat_id))
Expand Down Expand Up @@ -745,8 +748,8 @@ def estimate_errors(tau_estimate):
try:
cvrmse = rmse / mean_daily_runtime
except ZeroDivisionError:
warn(
'WARNING: CVRMSE divided by zero: %s / %s '
logger.debug(
'CVRMSE divided by zero: %s / %s '
'for thermostat_id %s ' % (
rmse, mean_daily_runtime,
self.thermostat_id))
Expand Down Expand Up @@ -837,8 +840,8 @@ def calc_estimates(tau):
try:
alpha_estimate = total_runtime / total_hdd
except ZeroDivisionError:
warn(
'WARNING: alpha_estimate divided by zero: %s / %s '
logger.debug(
'alpha_estimate divided by zero: %s / %s '
'for thermostat_id %s ' % (
total_runtime, total_hdd,
self.thermostat_id))
Expand Down Expand Up @@ -868,8 +871,8 @@ def estimate_errors(tau_estimate):
try:
cvrmse = rmse / mean_daily_runtime
except ZeroDivisionError:
warn(
'WARNING: CVRMSE divided by zero: %s / %s '
logger.warn(
'CVRMSE divided by zero: %s / %s '
'for thermostat_id %s ' % (
rmse, mean_daily_runtime,
self.thermostat_id))
Expand Down Expand Up @@ -1145,8 +1148,8 @@ def percent_savings(avoided, baseline):
try:
savings = (avoided.mean() / baseline.mean()) * 100.0
except ZeroDivisionError:
warn(
'WARNING: percent_savings divided by zero: %s / %s '
logger.debug(
'percent_savings divided by zero: %s / %s '
'for thermostat_id %s ' % (
avoided.mean(), baseline.mean(),
self.thermostat_id))
Expand Down
Loading

0 comments on commit 7e647a3

Please sign in to comment.