Skip to content

Commit

Permalink
Changing missing data to days; adding logging
Browse files Browse the repository at this point in the history
  • Loading branch information
craigmaloney committed Feb 26, 2021
1 parent c7ac44d commit 1233448
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions thermostat/importers.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,21 +356,32 @@ def get_single_thermostat(thermostat_id, zipcode,
cool_runtime = _calculate_cool_runtime(df, thermostat_id, cool_type, cool_stage, hourly_index)
heat_runtime = _calculate_heat_runtime(df, thermostat_id, heat_type, heat_stage, hourly_index)

if cool_runtime is not None and cool_runtime.empty is False:
cool_runtime_daily = cool_runtime.resample('D').agg(pd.Series.sum, skipna=False)
else:
cool_runtime_daily = None
if heat_runtime is not None and heat_runtime.empty is False:
heat_runtime_daily = heat_runtime.resample('D').agg(pd.Series.sum, skipna=False)
else:
heat_runtime_daily = None

# Give the thermostats the benefit of the doubt (especially if the runtime is None)
enough_cool_runtime = True
enough_heat_runtime = True

if cool_runtime is not None:
enough_cool_runtime = _enough_daily_runtume(cool_runtime)
if heat_runtime is not None:
enough_heat_runtime = _enough_daily_runtume(heat_runtime)
if cool_runtime_daily is not None:
enough_cool_runtime = _enough_daily_runtime(cool_runtime_daily)
if heat_runtime_daily is not None:
enough_heat_runtime = _enough_daily_runtime(heat_runtime_daily)

if not(enough_cool_runtime and enough_heat_runtime):
message = "Not enough runtime for thermostat %s\n" % thermostat_id
if not enough_heat_runtime:
message += "Heat runtime has over 5% missing data.\n"
message += "Heat runtime has over 5% missing data."
message += " (have {days} days.)\n".format(days=len(heat_runtime_daily.dropna()))
if not enough_cool_runtime:
message += "Cool runtime has over 5% missing data.\n"
message += "Cool runtime has over 5% missing data."
message += " (have {days} days.)\n".format(days=len(cool_runtime_daily.dropna()))
raise ValueError(message)

# create thermostat instance
Expand Down Expand Up @@ -474,7 +485,7 @@ def _create_series(df, index):
return series


def _enough_daily_runtume(series):
def _enough_daily_runtime(series):
if series is None:
return False

Expand Down

0 comments on commit 1233448

Please sign in to comment.