Skip to content

Commit

Permalink
Refactor: rename
Browse files Browse the repository at this point in the history
"billing_record" to "processed_energy_bill"

Co-authored-by: Ethan-Strominger <[email protected]>
Co-authored-by: AdamFinkle <[email protected]>
  • Loading branch information
3 people committed Dec 4, 2024
1 parent fa70e09 commit a6778ee
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ export function AnalysisHeader({ usage_data }: { usage_data: UsageDataSchema}) {
// 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
32 changes: 16 additions & 16 deletions heat-stack/app/routes/_heat+/single.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -359,7 +359,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
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
Expand All @@ -372,12 +372,12 @@ export async function action({ request, params }: ActionFunctionArgs) {
temperatureInput = TemperatureInput(**temperatureInputFromJs)
# third step, re-run of the table data
userAdjustedDataFromJsToPython = [ProcessedEnergyBillInput(**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 +390,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 +403,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 @@ -503,15 +503,15 @@ 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('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
2 changes: 1 addition & 1 deletion heat-stack/app/utils/pyodide.test.ts

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions heat-stack/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ export const oneBillingRecordSchema = z.object({
whole_home_heat_loss_rate: z.number(),
});

// Define the schema for the 'billing_records' list
// Define the schema for the 'processed_energy_bills' list
export const allBillingRecordsSchema = z.array(oneBillingRecordSchema);

// Define the schema for the 'usage_data' key
export const usageDataSchema = z.object({
heat_load_output: summaryOutputSchema,
balance_point_graph: balancePointGraphSchema,
billing_records: allBillingRecordsSchema,
processed_energy_bills: allBillingRecordsSchema,
})
8 changes: 4 additions & 4 deletions python/src/rules_engine/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ def get_outputs_normalized(

balance_point_graph = home.balance_point_graph

billing_records = []
processed_energy_bills = []
for processed_energy_bill_input in intermediate_processed_energy_bill_inputs:
billing_record = ProcessedEnergyBill(
processed_energy_bill = ProcessedEnergyBill(
period_start_date=processed_energy_bill_input.input.period_start_date,
period_end_date=processed_energy_bill_input.input.period_end_date,
usage=processed_energy_bill_input.input.usage,
Expand All @@ -148,12 +148,12 @@ def get_outputs_normalized(
eliminated_as_outlier=processed_energy_bill_input.eliminated_as_outlier,
whole_home_heat_loss_rate=processed_energy_bill_input.ua,
)
billing_records.append(billing_record)
processed_energy_bills.append(processed_energy_bill)

result = RulesEngineResult(
heat_load_output=heat_load_output,
balance_point_graph=balance_point_graph,
billing_records=billing_records,
processed_energy_bills=processed_energy_bills,
)
return result

Expand Down
2 changes: 1 addition & 1 deletion python/src/rules_engine/pydantic_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class BalancePointGraph(BaseModel):
class RulesEngineResult(BaseModel):
heat_load_output: HeatLoadOutput
balance_point_graph: BalancePointGraph
billing_records: list[ProcessedEnergyBill]
processed_energy_bills: list[ProcessedEnergyBill]


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion python/src/rules_engine/refactor.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ home variables used
2. Rename rules-engine to "python"
3. Rename NormalizedBillingRecordBase class to BillingInput
4. Rename BillingPeriod to IntermediateProcessedEnergyBill and processed_energy_bill_input to processed_energy_bill_intermediate
5. Combine get_outputs_normalized and convert_to_intermediate_billing_record and get rid of NormalizedBillingRecord. There is only one place NormalizedBillingRecord is used and combining code
5. Combine get_outputs_normalized and convert_to_intermediate_processed_energy_bill and get rid of NormalizedBillingRecord. There is only one place NormalizedBillingRecord is used and combining code
gets rid of the need for the class.
- Change
```
Expand Down
4 changes: 2 additions & 2 deletions python/tests/test_rules_engine/generate_example_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def generate_summary_json(workbook: Any, working_directory: Path) -> str:
return fuel_type


def generate_billing_record_input_csv(
def generate_processed_energy_bill_input_csv(
workbook: Any, fuel_type: str, working_directory: Path
) -> None:
"""
Expand Down Expand Up @@ -192,6 +192,6 @@ def generate_billing_record_input_csv(
continue
print("Processing test directory:", working_directory)
fuel_type = generate_summary_json(workbook, working_directory)
generate_billing_record_input_csv(workbook, fuel_type, working_directory)
generate_processed_energy_bill_input_csv(workbook, fuel_type, working_directory)
workbook.close()
del workbook
6 changes: 3 additions & 3 deletions python/tests/test_rules_engine/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,9 @@ def test_get_outputs_normalized(
rules_engine_result.heat_load_output.standard_deviation_of_heat_loss_rate
== approx(0.0463, abs=0.01)
)
assert rules_engine_result.billing_records[0].usage == 60
assert rules_engine_result.billing_records[0].whole_home_heat_loss_rate != None
assert rules_engine_result.billing_records[5].whole_home_heat_loss_rate == None
assert rules_engine_result.processed_energy_bills[0].usage == 60
assert rules_engine_result.processed_energy_bills[0].whole_home_heat_loss_rate != None
assert rules_engine_result.processed_energy_bills[5].whole_home_heat_loss_rate == None


@pytest.mark.parametrize(
Expand Down
4 changes: 2 additions & 2 deletions python/tests/test_rules_engine/test_natural_gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ def test_maximum_heat_load_natural_gas(data: Example) -> None:
)


def test_billing_records_whole_home_heat_loss_rate(data: Example) -> None:
def test_processed_energy_bills_whole_home_heat_loss_rate(data: Example) -> None:
rules_engine_result = engine.get_outputs_natural_gas(
data.summary, data.temperature_data, data.natural_gas_usage
)

data_iter = iter(data.natural_gas_usage.records)
for result in rules_engine_result.billing_records:
for result in rules_engine_result.processed_energy_bills:
example = next(data_iter)
whole_home_heat_loss_rate = (
example.whole_home_heat_loss_rate
Expand Down

0 comments on commit a6778ee

Please sign in to comment.