Skip to content

Commit

Permalink
feat(altnumber): Add NoLimit, Autocalculate and Autosize objects
Browse files Browse the repository at this point in the history
This commit addresses [this issue here](#30).
  • Loading branch information
chriswmackey committed Feb 4, 2020
1 parent 811be29 commit d046426
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 31 deletions.
17 changes: 17 additions & 0 deletions honeybee_schema/altnumber.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Objects used as alternatives to numerical properties."""
from pydantic import BaseModel, constr


class NoLimit(BaseModel):

type: constr(regex='^NoLimit$') = 'NoLimit'


class Autocalculate(BaseModel):

type: constr(regex='^Autocalculate$') = 'Autocalculate'


class Autosize(BaseModel):

type: constr(regex='^Autosize$') = 'Autosize'
8 changes: 5 additions & 3 deletions honeybee_schema/bc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from pydantic import BaseModel, Field, constr
from typing import List, Union

from .altnumber import Autocalculate


class Outdoors(BaseModel):

Expand All @@ -17,12 +19,12 @@ class Outdoors(BaseModel):
description='A boolean noting whether the boundary is exposed to wind.'
)

view_factor: Union[str, float] = Field(
'autocalculate',
view_factor: Union[Autocalculate, float] = Field(
Autocalculate(),
ge=0,
le=1,
description='A number for the view factor to the ground. This can also be '
'the word "autocalculate" to have the view factor automatically calculated.'
'an Autocalculate object to have the view factor automatically calculated.'
)

class Surface(BaseModel):
Expand Down
32 changes: 10 additions & 22 deletions honeybee_schema/energy/hvac.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from enum import Enum

from ._base import NamedEnergyBaseModel
from ..altnumber import NoLimit, Autosize


class EconomizerType(str, Enum):
Expand Down Expand Up @@ -62,37 +63,24 @@ class IdealAirSystemAbridged(NamedEnergyBaseModel):
description='A number for the minimum cooling supply air temperature [C].'
)

heating_limit: Union[float, str] = Field(
'autosize',
heating_limit: Union[float, Autosize, NoLimit] = Field(
Autosize(),
ge=0,
description='A number for the maximum heating capacity in Watts. This '
'can also be the text "autosize" to indicate that the capacity should '
'can also be an Autosize object to indicate that the capacity should '
'be determined during the EnergyPlus sizing calculation. This can also '
'be the text "NoLimit" to indicate no upper limit to the heating capacity. '
'Note that setting this to None will trigger the default ("autosize").'
'be a NoLimit boject to indicate no upper limit to the heating capacity.'
)

@validator('heating_limit')
def check_heating_limit(cls, v):
if v is not None and not isinstance(v ,float) and v != 'autosize':
raise ValueError( '"{}" is not a valid entry for heating_limit'.format(v))


cooling_limit: Union[float, str] = Field(
'autosize',
cooling_limit: Union[float, Autosize, NoLimit] = Field(
Autosize(),
ge=0,
description='A number for the maximum cooling capacity in Watts. This '
'can also be the text "autosize" to indicate that the capacity should '
'be determined during the sizing calculation. This can also '
'be the text "NoLimit" to indicate no upper limit to the cooling capacity. '
'Note that setting this to None will trigger the default ("autosize").'
'can also be an Autosize object to indicate that the capacity should '
'be determined during the EnergyPlus sizing calculation. This can also '
'be a NoLimit boject to indicate no upper limit to the cooling capacity.'
)

@validator('cooling_limit')
def check_cooling_limit(cls, v):
if v is not None and not isinstance(v, float) and v != 'autosize':
raise ValueError( '"{}" is not a valid entry for cooling_limit'.format(v))

heating_availability: str = Field(
None,
min_length=1,
Expand Down
13 changes: 7 additions & 6 deletions honeybee_schema/energy/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import datetime

from ._base import NamedEnergyBaseModel, DatedBaseModel
from ..altnumber import NoLimit


class ScheduleNumericType (str, Enum):
Expand Down Expand Up @@ -35,14 +36,14 @@ class ScheduleTypeLimit(NamedEnergyBaseModel):

type: constr(regex='^ScheduleTypeLimit$') = 'ScheduleTypeLimit'

lower_limit: float = Field(
default=None,
description='Lower limit for the schedule type is entered.'
lower_limit: Union[NoLimit, float] = Field(
default=NoLimit(),
description='Lower limit for the schedule type or NoLimit.'
)

upper_limit: float = Field(
default=None,
description='Upper limit for the schedule type is entered.'
upper_limit: Union[NoLimit, float] = Field(
default=NoLimit(),
description='Upper limit for the schedule type or NoLimit.'
)

numeric_type: ScheduleNumericType = ScheduleNumericType.continuous
Expand Down

0 comments on commit d046426

Please sign in to comment.