Skip to content

Commit

Permalink
Rename classes (#278)
Browse files Browse the repository at this point in the history
* Refactor Home.calculate

Co-authored-by: Ethan Strominger <ethanstrominger2@gmail.com>

* Refactor "SummaryInput" to "HeatLoadInput", "summary_input" to "heat_load_input"

Co-authored-by: Ethan Strominger <ethanstrominger2@gmail.com>

* (Issue #264) Refactor: Rename "SummaryOnput" to "HeatLoadOuput", "summary_output" to "heat_load_output"

Co-authored-by: Ethan Strominger <ethanstrominger2@gmail.com>

* (Issue #264) Refactor: Rename "ProcessedBill" to "ProcessedEnergyBillIntermediate", "processed_bill" to "processed_energy_bill_intermediate"

Co-authored-by: Ethan Strominger <ethanstrominger2@gmail.com>

* add "balance_point = 0"

* update the return type annotation of class Home._init  [no-untyped-def]

* update

* update

* (Issue #264) Refactor: Rename "NormalizedBillingPeriodRecordBase" to "ProcessedEnergyBillInput"

Co-authored-by: Ethan Strominger <ethanstrominger2@gmail.com>

* (Issue #264) Refactor: Rename "NormalizedBillingPeriodRecord" to "ProcessedEnergyBill"

Co-authored-by: Ethan Strominger <ethanstrominger2@gmail.com>

* (Issue #264) Refactor: Rename "NormalizedBillingPeriodRecord" to "ProcessedEnergyBill"

Co-authored-by: Ethan Strominger <ethanstrominger2@gmail.com>

* Update the "recommendations.json"

Co-authored-by: Ethan-Strominger <ethanstrominger@users.noreply.github.com>

* Refactor: rename + setup-python.sh

1. Renamed to "IntermediateProcessedEnergyBill"
2. Created the "setup-python.sh" file.

Co-authored-by: Ethan-Strominger <ethanstrominger@users.noreply.github.com>

* Refactor: rename

 Renamed to "processed_energy_bill_inputs_bill_inputs"

    Co-authored-by: Ethan-Strominger <ethanstrominger@users.noreply.github.com>

* Refactor: rename

"billing_period" to "processed_energy_bill_input"

Co-authored-by: Ethan-Strominger <ethanstrominger@users.noreply.github.com>

* Refactor: rename

"billing_record" to "processed_energy_bill"

Co-authored-by: Ethan-Strominger <ethanstrominger@users.noreply.github.com>
Co-authored-by: AdamFinkle <AdamFinkle@users.noreply.github.com>

* update the Lint format

* Refactor: rename

"processed_energy_bill_inputs_bill_inputs" to "processed_energy_bill_inputs"

Co-authored-by: Ethan-Strominger <ethanstrominger@users.noreply.github.com>
Co-authored-by: AdamFinkle <AdamFinkle@users.noreply.github.com>

* temporary save

Co-authored-by: Ethan-Strominger <ethanstrominger@users.noreply.github.com>
Co-authored-by: AdamFinkle <AdamFinkle@users.noreply.github.com>

* Refactor: fix "billing_period" renaming issue.

Co-authored-by: Ethan-Strominger <ethanstrominger@users.noreply.github.com>

* Refactor: fix "billing_period" renaming issue.

Co-authored-by: Ethan-Strominger <ethanstrominger@users.noreply.github.com>

* Refactor: removed the commented out code

Co-authored-by: Ethan-Strominger <ethanstrominger@users.noreply.github.com>

* Refactor: fix "billing_records" renaming issue.

Co-authored-by: Ethan-Strominger <ethanstrominger@users.noreply.github.com>

* Refactor: Rename "sample_summary_inputs" to "sample_heat_load_inputs"

Co-authored-by: AdamFinkle <AdamFinkle@users.noreply.github.com>
Co-authored-by: Ethan-Strominger <ethanstrominger@users.noreply.github.com>

* Refactor: Rename "dummy_processed_energy_bill_input_record" to "_dummy_processed_energy_bill_input"

Co-authored-by: AdamFinkle <AdamFinkle@users.noreply.github.com>
Co-authored-by: Ethan-Strominger <ethanstrominger@users.noreply.github.com>

* Refactor: corrected variable naming issue of "IntermediateEnergyBill"

Co-authored-by: AdamFinkle <AdamFinkle@users.noreply.github.com>
Co-authored-by: Ethan-Strominger <ethanstrominger@users.noreply.github.com>

---------

Co-authored-by: Ethan Strominger <ethanstrominger2@gmail.com>
Co-authored-by: Ethan-Strominger <ethanstrominger@users.noreply.github.com>
Co-authored-by: AdamFinkle <AdamFinkle@users.noreply.github.com>
  • Loading branch information
4 people authored Dec 16, 2024
1 parent 9039590 commit 790b019
Show file tree
Hide file tree
Showing 16 changed files with 335 additions and 286 deletions.
5 changes: 4 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"qwtel.sqlite-viewer",
"yoavbls.pretty-ts-errors",
"github.vscode-github-actions",
"ms-vsliveshare.vsliveshare"
"ms-vsliveshare.vsliveshare",
"ms-python.python",
"eamodio.gitlens",
"MS-vsliveshare.vsliveshare"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ export function AnalysisHeader({ usage_data }: { usage_data: UsageDataSchema}) {
// 3312125.0171753373
// ]])

// Extract the summary_output from usage_data
const summaryOutputs = usage_data?.summary_output;
// Extract the heat_load_output from usage_data
const summaryOutputs = usage_data?.heat_load_output;

const totalRecords = usage_data?.billing_records?.length || "-"
const totalRecords = usage_data?.processed_energy_bills?.length || "-"

// Calculate the number of billing periods included in Heating calculations
const heatingAnalysisTypeRecords = usage_data?.billing_records?.filter(
const heatingAnalysisTypeRecords = usage_data?.processed_energy_bills?.filter(
(billingRecord) => billingRecord.analysis_type === 1,
// Do wee need this code instead? (billingRecord) => billingRecord.analysis_type !== "NOT_ALLOWED_IN_CALCULATIONS",
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ export function EnergyUseHistoryChart({ usage_data }: { usage_data: UsageDataSch
const [billingRecords, setBillingRecords] = useState<BillingRecordsSchema>([])

useEffect(() => {
if (usage_data?.billing_records) {
if (usage_data?.processed_energy_bills) {
// Process the billing records directly without converting from Map
setBillingRecords(usage_data.billing_records)
setBillingRecords(usage_data.processed_energy_bills)
}
}, [usage_data])

Expand Down
56 changes: 25 additions & 31 deletions heat-stack/app/routes/_heat+/single.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
from rules_engine import parser
from rules_engine.pydantic_models import (
FuelType,
SummaryInput,
HeatLoadInput,
TemperatureInput
)
from rules_engine import engine
Expand Down Expand Up @@ -302,7 +302,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
from rules_engine import parser
from rules_engine.pydantic_models import (
FuelType,
SummaryInput,
HeatLoadInput,
TemperatureInput
)
from rules_engine import engine, helpers
Expand All @@ -313,7 +313,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
# two new geocode parameters may be needed for design temp:
# watch out for helpers.get_design_temp( addressMatches[0].geographies.counties[0]['STATE'] , addressMatches[0].geographies.counties[0]['COUNTY'] county_id)
# in addition to latitude and longitude from GeocodeUtil.ts object .
# pack the get_design_temp output into summary_input
# pack the get_design_temp output into heat_load_input
"""
summaryInputFromJs = summaryInputJs.as_object_map().values()._mapping
Expand All @@ -323,7 +323,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
naturalGasInputRecords = parser.parse_gas_bill(csvDataJs, parser.NaturalGasCompany.NATIONAL_GRID)
design_temp_looked_up = helpers.get_design_temp(state_id, county_id)
summaryInput = SummaryInput( **summaryInputFromJs, design_temperature=design_temp_looked_up)
summaryInput = HeatLoadInput( **summaryInputFromJs, design_temperature=design_temp_looked_up)
temperatureInput = TemperatureInput(**temperatureInputFromJs)
Expand All @@ -335,7 +335,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
// type Analytics = z.infer<typeof Analytics>;
const foo: any = executeGetAnalyticsFromFormJs(parsedAndValidatedFormSchema, convertedDatesTIWD, uploadedTextFile, state_id, county_id).toJs()

//console.log("foo billing records [0]", foo.get('billing_records')[0] )
//console.log("foo billing records [0]", foo.get('processed_energy_bills')[0] )

/**
* second time and after, when table is modified, this becomes entrypoint
Expand All @@ -344,40 +344,34 @@ export async function action({ request, params }: ActionFunctionArgs) {
from rules_engine import parser
from rules_engine.pydantic_models import (
FuelType,
SummaryInput,
HeatLoadInput,
TemperatureInput,
NormalizedBillingPeriodRecordBase
ProcessedEnergyBillInput
)
from rules_engine import engine, helpers
# def get_outputs_normalized(
# summary_input: SummaryInput,
# dhw_input: Optional[DhwInput],
# temperature_input: TemperatureInput,
# billing_periods: list[NormalizedBillingPeriodRecordBase],
# )
def executeRoundtripAnalyticsFromForm(summaryInputJs, temperatureInputJs, userAdjustedData, state_id, county_id):
"""
"billing_records" is the "roundtripping" parameter to be passed as userAdjustedData.
"processed_energy_bills" is the "roundtripping" parameter to be passed as userAdjustedData.
"""
summaryInputFromJs = summaryInputJs.as_object_map().values()._mapping
temperatureInputFromJs =temperatureInputJs.as_object_map().values()._mapping
design_temp_looked_up = helpers.get_design_temp(state_id, county_id)
# expect 1 for middlesex county: print("design temp check ",design_temp_looked_up, state_id, county_id)
summaryInput = SummaryInput( **summaryInputFromJs, design_temperature=design_temp_looked_up)
summaryInput = HeatLoadInput( **summaryInputFromJs, design_temperature=design_temp_looked_up)
temperatureInput = TemperatureInput(**temperatureInputFromJs)
# third step, re-run of the table data
userAdjustedDataFromJsToPython = [NormalizedBillingPeriodRecordBase(**record) for record in userAdjustedData['billing_records'] ]
userAdjustedDataFromJsToPython = [ProcessedEnergyBillInput(**record) for record in userAdjustedData['processed_energy_bills'] ]
# print("py", userAdjustedDataFromJsToPython[0])
outputs2 = engine.get_outputs_normalized(summaryInput, None, temperatureInput, userAdjustedDataFromJsToPython)
# print("py2", outputs2.billing_records[0])
# print("py2", outputs2.processed_energy_bills[0])
return outputs2.model_dump(mode="json")
executeRoundtripAnalyticsFromForm
`)
Expand All @@ -390,7 +384,7 @@ Traceback (most recent call last): File "<exec>", line 32,
*/
/*
For
'billing_records' => [
'processed_energy_bills' => [
Map(9) {
'period_start_date' => '2020-10-02',
'period_end_date' => '2020-11-04',
Expand All @@ -403,22 +397,22 @@ Traceback (most recent call last): File "<exec>", line 32,
'whole_home_heat_loss_rate' => undefined
}, */

const gasBillDataWithUserAdjustments = foo; /* billing_records is untested here */
const gasBillDataWithUserAdjustments = foo; /* processed_energy_bills is untested here */

const billingRecords = foo.get('billing_records')
const billingRecords = foo.get('processed_energy_bills')
billingRecords.forEach((record: any) => {
record.set('inclusion_override', true);
});
// foo.set('billing_records', null)
// foo.set('billing_records', billingRecords)
//console.log("(after customization) gasBillDataWithUserAdjustments billing records[0]", gasBillDataWithUserAdjustments.get('billing_records')[0])
// foo.set('processed_energy_bills', null)
// foo.set('processed_energy_bills', billingRecords)
//console.log("(after customization) gasBillDataWithUserAdjustments billing records[0]", gasBillDataWithUserAdjustments.get('processed_energy_bills')[0])
/* why is inclusion_override still false after roundtrip */

const foo2: any = executeRoundtripAnalyticsFromFormJs(parsedAndValidatedFormSchema, convertedDatesTIWD, gasBillDataWithUserAdjustments, state_id, county_id).toJs()

// console.log("foo2 billing records[0]", foo2.get('billing_records')[0]);
// console.log("foo2 billing records[0]", foo2.get('processed_energy_bills')[0]);
// console.log("foo2", foo2);
// console.log("(after round trip) gasBillDataWithUserAdjustments billing records[0]", gasBillDataWithUserAdjustments.get('billing_records')[0])
// console.log("(after round trip) gasBillDataWithUserAdjustments billing records[0]", gasBillDataWithUserAdjustments.get('processed_energy_bills')[0])

// const otherResult = executePy(summaryInput, convertedDatesTIWD, exampleNationalGridCSV);

Expand Down Expand Up @@ -496,22 +490,22 @@ export default function Inputs() {
/**
* Where temp1 is a temporary variable with the main Map of Maps (or undefined if page not yet submitted).
*
* temp1.get('summary_output'): Map(9) { estimated_balance_point → 61.5, other_fuel_usage → 0.2857142857142857, average_indoor_temperature → 67, difference_between_ti_and_tbp → 5.5, design_temperature → 1, whole_home_heat_loss_rate → 48001.81184312083, standard_deviation_of_heat_loss_rate → 0.08066745182677547, average_heat_load → 3048115.0520381727, maximum_heat_load → 3312125.0171753373 }
* temp1.get('heat_load_output'): Map(9) { estimated_balance_point → 61.5, other_fuel_usage → 0.2857142857142857, average_indoor_temperature → 67, difference_between_ti_and_tbp → 5.5, design_temperature → 1, whole_home_heat_loss_rate → 48001.81184312083, standard_deviation_of_heat_loss_rate → 0.08066745182677547, average_heat_load → 3048115.0520381727, maximum_heat_load → 3312125.0171753373 }
*/
/* @ts-ignore */
// console.log("Summary Output", lastResult !== undefined ? JSON.parse(lastResult.data, reviver)?.get('summary_output'): undefined)
// console.log("Summary Output", lastResult !== undefined ? JSON.parse(lastResult.data, reviver)?.get('heat_load_output'): undefined)

/**
* Where temp1 is a temporary variable with the main Map of Maps (or undefined if page not yet submitted).
* temp1.get('billing_records')
* temp1.get('processed_energy_bills')
* Array(25) [ Map(9), Map(9), Map(9), Map(9), Map(9), Map(9), Map(9), Map(9), Map(9), Map(9), … ]
* temp1.get('billing_records')[0]
* temp1.get('processed_energy_bills')[0]
* Map(9) { period_start_date → "2020-10-02", period_end_date → "2020-11-04", usage → 29, analysis_type_override → null, inclusion_override → true, analysis_type → 0, default_inclusion_by_calculation → false, eliminated_as_outlier → false, whole_home_heat_loss_rate → null }
* temp1.get('billing_records')[0].get('period_start_date')
* temp1.get('processed_energy_bills')[0].get('period_start_date')
* "2020-10-02"
*/
/* @ts-ignore */
// console.log("EnergyUseHistoryChart table data", lastResult !== undefined ? JSON.parse(lastResult.data, reviver)?.get('billing_records'): undefined)
// console.log("EnergyUseHistoryChart table data", lastResult !== undefined ? JSON.parse(lastResult.data, reviver)?.get('processed_energy_bills'): undefined)

/**
* Where temp1 is a temporary variable with the main Map of Maps (or undefined if page not yet submitted).
Expand Down
Loading

0 comments on commit 790b019

Please sign in to comment.