Skip to content

Commit

Permalink
annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
JrtPec committed Dec 8, 2023
1 parent d1ca1c0 commit 38912be
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
2 changes: 1 addition & 1 deletion openenergyid/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Open Energy ID Python SDK."""

__version__ = "0.1.1"
__version__ = "0.1.3"

from .enums import Granularity
from .models import TimeSeries
Expand Down
17 changes: 17 additions & 0 deletions openenergyid/mvlr/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,20 @@ def resample_input_data(
return data.resample(rule=pandas_granularity_map[granularity]).agg(
aggregation_methods,
)


def temperature_equivalent_to_degree_days(
temperature_equivalent: pd.Series, base_temperature: float, cooling: bool = False
) -> pd.Series:
"""
Convert temperature equivalent to degree days.
Use cooling=True to convert cooling degree days.
"""

if cooling:
result = temperature_equivalent - base_temperature
else:
result = base_temperature - temperature_equivalent

return result.clip(lower=0)
32 changes: 18 additions & 14 deletions openenergyid/mvlr/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Models for multivariable linear regression."""
from typing import Optional

from pydantic import BaseModel
from pydantic import BaseModel, Field, ConfigDict
import statsmodels.formula.api as fm

from openenergyid.enums import Granularity
Expand All @@ -13,20 +13,24 @@
class ConfidenceInterval(BaseModel):
"""Confidence interval for a coefficient."""

confidence: float
lower: float
upper: float
confidence: float = Field(ge=0, le=1)
lower: float = Field(ge=0, le=1)
upper: float = Field(ge=0, le=1)


class IndependentVariable(BaseModel):
"""Independent variable for a multivariable linear regression model."""

name: str
coef: float
t_stat: Optional[float] = None
p_value: Optional[float] = None
std_err: Optional[float] = None
confidence_interval: Optional[ConfidenceInterval] = None
t_stat: Optional[float] = Field(ge=0, le=1, default=None, alias="tStat")
p_value: Optional[float] = Field(ge=0, le=1, default=None, alias="pValue")
std_err: Optional[float] = Field(ge=0, le=1, default=None, alias="stdErr")
confidence_interval: Optional[ConfidenceInterval] = Field(
default=None, alias="confidenceInterval"
)

model_config = ConfigDict(populate_by_name=True)

@classmethod
def from_fit(cls, fit: fm.ols, name: str) -> "IndependentVariable":
Expand All @@ -48,12 +52,12 @@ def from_fit(cls, fit: fm.ols, name: str) -> "IndependentVariable":
class MultiVariableRegressionResult(BaseModel):
"""Result of a multivariable regression model."""

dependent_variable: str
independent_variables: list[IndependentVariable]
r2: float
r2_adj: float
f_stat: float
prob_f_stat: float
dependent_variable: str = Field(alias="dependentVariable")
independent_variables: list[IndependentVariable] = Field(alias="independentVariables")
r2: float = Field(ge=0, le=1, alias="rSquared")
r2_adj: float = Field(ge=0, le=1, alias="rSquaredAdjusted")
f_stat: float = Field(ge=0, alias="fStat")
prob_f_stat: float = Field(ge=0, le=1, alias="probFStat")
intercept: IndependentVariable
granularity: Granularity
frame: TimeSeries
Expand Down

0 comments on commit 38912be

Please sign in to comment.