codeforboston / home-energy-analysis-tool

https://www.codeforboston.org/projects/
MIT License
8 stars 25 forks source link

created objects #133

Closed jkoren closed 3 months ago

jkoren commented 5 months ago

Created Classes for HEAT Calculator.

There are 8 classes, as described in this comment of Issue 124.

  1. [Case]()
  2. [Home]()
  3. [Location]()
  4. [Heat Load Analysis]()
  5. [Natural Gas Bill]()
  6. [Natural Gas Bill Records]()
  7. [Oil Propane Bill]()
  8. [Oil Propane Bill Records]()

The models are stored in the /models directory The object fields will map to database fields.

image

thadk commented 5 months ago

I used (a pydantic2 fork of) pydantic2ts to generate this Typescript of the rules engine (not their schema) in case we find it useful at any point in this process.

pydantic2ts --json2ts-cmd "../heat-stack/node_modules/.bin/json2ts" --module src/rules_engine/pydantic_models.py --output ./pydanticTypes.ts ```typescript /* tslint:disable */ /* eslint-disable */ /** /* This file was automatically generated from pydantic models by running pydantic2ts. /* Do not modify it by hand - just update the pydantic models and then re-run the script */ export type Dates = string[]; export type Temperatures = number[]; /** * Summary!G33:35 */ export type BalancePoint = number; /** * Summary!H33:35 */ export type HeatLossRate = number; /** * Summary!I33:35 */ export type ChangeInHeatLossRate = number; /** * Summary!J33:35 */ export type PercentChangeInHeatLossRate = number; /** * Summary!K33:35 */ export type StandardDeviation = number; export type Records = BalancePointGraphRow[]; /** * DHW!B4 */ export type NumberOfOccupants = number; /** * DHW!B5 */ export type EstimatedWaterHeatingEfficiency = number; /** * DHW!B6 */ export type StandByLosses = number; /** * Natural Gas!A */ export type PeriodStartDate = string; /** * Natural Gas!B */ export type PeriodEndDate = string; /** * Natural Gas!D */ export type UsageTherms = number; export type AnalysisType = 0 | 1 | -1; export type Records1 = NaturalGasBillingRecordInput[]; export type PeriodStartDate1 = string; export type PeriodEndDate1 = string; export type Usage = number; /** * Oil-Propane!B */ export type PeriodEndDate2 = string; /** * Oil-Propane!C */ export type Gallons = number; /** * Oil-Propane!F */ export type InclusionOverride = boolean | null; export type Records2 = OilPropaneBillingRecordInput[]; /** * Oil-Propane!B6 */ export type PrecedingDeliveryDate = string; /** * Summary!B10 */ export type LivingArea = number; /** * Enum for fuel types. Values are BTU per usage */ export type FuelType = 100000 | 139600 | 91333; /** * Summary!B12 */ export type HeatingSystemEfficiency = number; /** * Summary!B17 */ export type ThermostatSetPoint = number; /** * Summary!B18 */ export type SetbackTemperature = number | null; /** * Summary!B19 */ export type SetbackHoursPerDay = number | null; /** * TDesign */ export type DesignTemperature = number; /** * Summary!B20 */ export type EstimatedBalancePoint = number; /** * Summary!B15 */ export type OtherFuelUsage = number; /** * Summary!B24 */ export type AverageIndoorTemperature = number; /** * Summary!B25 */ export type DifferenceBetweenTiAndTbp = number; /** * Summary!B26 */ export type DesignTemperature1 = number; /** * Summary!B27 */ export type WholeHomeHeatLossRate = number; /** * Summary!B28 */ export type StandardDeviationOfHeatLossRate = number; /** * Summary!B29 */ export type AverageHeatLoad = number; /** * Summary!B30 */ export type MaximumHeatLoad = number; export type Dates1 = string[]; export type Temperatures1 = number[]; /** * From Summary page */ export interface BalancePointGraph { records: Records; } /** * From Summary page */ export interface BalancePointGraphRow { balance_point: BalancePoint; heat_loss_rate: HeatLossRate; change_in_heat_loss_rate: ChangeInHeatLossRate; percent_change_in_heat_loss_rate: PercentChangeInHeatLossRate; standard_deviation: StandardDeviation; } /** * From DHW (Domestic Hot Water) Tab */ export interface DhwInput { number_of_occupants: NumberOfOccupants; estimated_water_heating_efficiency: EstimatedWaterHeatingEfficiency; stand_by_losses: StandByLosses; } /** * From Natural Gas tab. Container for holding all rows of the billing input table. */ export interface NaturalGasBillingInput { records: Records1; } /** * From Natural Gas tab. A single row of the Billing input table. */ export interface NaturalGasBillingRecordInput { period_start_date: PeriodStartDate; period_end_date: PeriodEndDate; usage_therms: UsageTherms; /** * Natural Gas!E */ inclusion_override: AnalysisType | null; } export interface NormalizedBillingPeriodRecordInput { period_start_date: PeriodStartDate1; period_end_date: PeriodEndDate1; usage: Usage; inclusion_override: AnalysisType | null; } /** * From Oil-Propane tab. Container for holding all rows of the billing input table. */ export interface OilPropaneBillingInput { records: Records2; preceding_delivery_date: PrecedingDeliveryDate; } /** * From Oil-Propane tab */ export interface OilPropaneBillingRecordInput { period_end_date: PeriodEndDate2; gallons: Gallons; inclusion_override: InclusionOverride; } /** * From Summary Tab */ export interface SummaryInput { living_area: LivingArea; /** * Summary!B11 */ fuel_type: FuelType; heating_system_efficiency: HeatingSystemEfficiency; thermostat_set_point: ThermostatSetPoint; setback_temperature: SetbackTemperature; setback_hours_per_day: SetbackHoursPerDay; design_temperature: DesignTemperature; } /** * From Summary tab */ export interface SummaryOutput { estimated_balance_point: EstimatedBalancePoint; other_fuel_usage: OtherFuelUsage; average_indoor_temperature: AverageIndoorTemperature; difference_between_ti_and_tbp: DifferenceBetweenTiAndTbp; design_temperature: DesignTemperature1; whole_home_heat_loss_rate: WholeHomeHeatLossRate; standard_deviation_of_heat_loss_rate: StandardDeviationOfHeatLossRate; average_heat_load: AverageHeatLoad; maximum_heat_load: MaximumHeatLoad; } export interface TemperatureInput { dates: Dates1; temperatures: Temperatures1; } ```
thadk commented 5 months ago

Have you used types/interfaces instead of classes before? I wanted to talk to you about that but we ran out of time. Essentially I’m trying to realize what is the benefit for us in stateful class instance objects as here vs simple stateless plain typescript objects re-created much like the classes in your PRs?

thadk commented 5 months ago

In Slack, Jeff asked the difference between type syntax, interface syntax and even class syntax. I found an awesome SO answer that explains the syntax and other (sorta minor) differences around choosing Types vs Interfaces https://stackoverflow.com/a/52682220

jkoren commented 5 months ago

I read the article, and updated PR 133 to use interfaces. good suggestion!

jkoren commented 5 months ago

@alanisaac Yes NaturalGasBill is an aggregate root and would have an array of NaturalGasBillRecords as part of the object.

thadk commented 5 months ago

@jkoren What if we combine and move all the typescript files from heat-stack/model in to the heat-stack/types/index.d.ts or heat-stack/types/index.ts file if that doesn't work for some reason?

jkoren commented 5 months ago

Hey @thadk thanks for looking at the PR. I looked at heat-stack/types and don't see an index file. Combining is ok with me. Is this a more standard place to put model definitions?

thadk commented 4 months ago

@jkoren Yep, please create heat-stack/types/index.d.ts with the combined set of those and we can probably merge this. I think combining related types is pretty common.

Also I think heat-stack/models is a bit inaccurate naming since the database schemas won't be controlled by these files, only the types.

The SQLite database schema is controlled by the schema.prisma file I believe.

jkoren commented 4 months ago

@thadk combined interfaces into single file

thadk commented 4 months ago

@jkoren Oop, tests aren't passing though. Looks like some references might still be on the old setup.

jkoren commented 4 months ago

I saw that .. its funny it’s working when running locally. I’ll take a look later.

On Tue, Feb 6, 2024 at 11:40 AM Thad Kerosky @.***> wrote:

@jkoren https://github.com/jkoren Oop, tests aren't passing though. Looks like some references might still be on the old setup.

— Reply to this email directly, view it on GitHub https://github.com/codeforboston/home-energy-analysis-tool/pull/133#issuecomment-1930298856, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQBW5U747XKN7TFYDXJ5JV3YSJMJLAVCNFSM6AAAAABBVZGYOGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMZQGI4TQOBVGY . You are receiving this because you were mentioned.Message ID: @.***>

thadk commented 3 months ago

Thanks so much Jeff and all on this one.