From 418bbcec2cdcfab417c79db8cc7454d9f034dc0d Mon Sep 17 00:00:00 2001 From: Thomas Tu Date: Fri, 10 Apr 2020 15:55:43 -0700 Subject: [PATCH] better API and actually fix meter costs --- pyproject.toml | 2 +- ubc/calculator.py | 14 ++++++++++---- ubc/rates/openei/__init__.py | 3 +++ 3 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 ubc/rates/openei/__init__.py diff --git a/pyproject.toml b/pyproject.toml index 467bf1e..525aae6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "ubc" -version = "0.0.3" +version = "0.0.4" description = "Utility Bill Calculator" authors = ["Thomas Tu "] diff --git a/ubc/calculator.py b/ubc/calculator.py index ddb8ed3..f3ccc12 100644 --- a/ubc/calculator.py +++ b/ubc/calculator.py @@ -1,5 +1,10 @@ -from ubc.rates.openei.api import RateSchedule from dataclasses import dataclass +from pandas import Timedelta + +from ubc.rates.openei.api import RateSchedule + + +DELTA_HOUR = Timedelta("1 hour") @dataclass @@ -113,14 +118,15 @@ def calculate_meter_charges(self, load): cost = num_days*self.schedule.meter return cost.rename("cost") - def calculate_total(self, load_kw, interval=1): + def calculate_total(self, load_kw): """ Args: load_kw (pd.Series): timestamp series of demand data. - interval (float): Fraction of an hour for timestamp. """ + + interval = load_kw.index.freq.delta / DELTA_HOUR energy_charges = self.calculate_energy_charges(load_kw*interval)["cost"].resample("M").sum() demand_charges = self.calculate_demand_charges(load_kw)["cost"].sum(axis=1) flatdemand_charges = self.calculate_flatdemand_charges(load_kw)["cost"] - meter_charges = self.calculate_meter_charges(load_kw)["cost"] + meter_charges = self.calculate_meter_charges(load_kw) return (meter_charges + energy_charges + demand_charges + flatdemand_charges).rename("total_cost") diff --git a/ubc/rates/openei/__init__.py b/ubc/rates/openei/__init__.py new file mode 100644 index 0000000..6d26571 --- /dev/null +++ b/ubc/rates/openei/__init__.py @@ -0,0 +1,3 @@ +from .api import RateSchedule as OpenEI + +__all__ = ["OpenEI"] \ No newline at end of file