Skip to content

Commit

Permalink
fix: updated Zod types for usage_data and refactored type imports
Browse files Browse the repository at this point in the history
  • Loading branch information
TBardini committed Sep 30, 2024
1 parent 1ab7eda commit ce3c3e8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import { type z } from 'zod';
import { usageDataSchema, BillingRecordsSchema, SummaryOutputSchema } from '#types/index'
import { type UsageDataSchema } from '#/types/types.ts';


// type HeatLoadAnalysisZod = z.infer<typeof HeatLoadAnalysisZod>
type usageDataZod = z.infer<typeof usageDataSchema>
type BillingRecordsZod = z.infer<typeof BillingRecordsSchema>
type SummaryOutputZod = z.infer<typeof SummaryOutputSchema>

export function AnalysisHeader({ usage_data }: { usage_data: usageDataZod}) {
export function AnalysisHeader({ usage_data }: { usage_data: UsageDataSchema}) {
// Example usage_data
// new Map([[
// "estimated_balance_point",
Expand Down Expand Up @@ -39,21 +33,21 @@ export function AnalysisHeader({ usage_data }: { usage_data: usageDataZod}) {
// ]])

// Extract the summary_output from usage_data
const summaryOutputs: SummaryOutputZod | undefined = usage_data?.summary_output;
const summaryOutputs = usage_data?.summary_output;

// Calculate the number of billing periods included in Heating calculations
const heatingAnalysisTypeRecords = usage_data?.billing_records?.filter(
(billingRecord: BillingRecordsZod) => billingRecord.analysis_type === 1,
(billingRecord) => billingRecord.analysis_type === 1,
);

const recordsIncludedByDefault = heatingAnalysisTypeRecords?.filter(
(billingRecord:BillingRecordsZod) =>
(billingRecord) =>
billingRecord.default_inclusion_by_calculation === true &&
billingRecord.inclusion_override === false,
).length;

const recordsIncludedByOverride = heatingAnalysisTypeRecords?.filter(
(billingRecord: BillingRecordsZod) =>
(billingRecord) =>
billingRecord.default_inclusion_by_calculation === false &&
billingRecord.inclusion_override === true,
).length;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Upload } from 'lucide-react'

import { Button } from '#/app/components/ui/button.tsx'
import { type usageDataSchema } from '#/types/types.ts'
import { type UsageDataSchema } from '#/types/types.ts';
import { AnalysisHeader } from './AnalysisHeader.tsx'
import { EnergyUseHistoryChart } from './EnergyUseHistoryChart.tsx'

Expand All @@ -14,7 +14,7 @@ import { EnergyUseHistoryChart } from './EnergyUseHistoryChart.tsx'
export function EnergyUseHistory({
usage_data,
}: {
usage_data: usageDataSchema
usage_data: UsageDataSchema
}) {
const titleClass = 'text-5xl font-extrabold tracking-wide mt-10'
// const subtitleClass = 'text-2xl font-semibold text-zinc-950 mt-9'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState, useEffect } from 'react'
import { type z } from 'zod'
import { type usageDataSchema, BillingRecordsSchema } from '#/types/types.ts'
import { type UsageDataSchema, type BillingRecordsSchema } from '#/types/types.ts';
import {
NaturalGasUsageData,
type NaturalGasBillRecord as NaturalGasBillRecordZod,
Expand Down Expand Up @@ -58,7 +58,7 @@ import { tr } from '@faker-js/faker'
// naturalGasBillRecord04,
// ]

export function EnergyUseHistoryChart({ usage_data }: { usage_data: usageDataSchema }) {
export function EnergyUseHistoryChart({ usage_data }: { usage_data: UsageDataSchema }) {
const [billingRecords, setBillingRecords] = useState<BillingRecordsSchema>([])

useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion heat-stack/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ export type BalancePointGraphSchema = z.infer<typeof balancePointGraphSchema>;
export type SummaryOutputSchema = z.infer<typeof summaryOutputSchema>;
export type BillingRecordSchema = z.infer<typeof billingRecordSchema>;
export type BillingRecordsSchema = z.infer<typeof billingRecordsSchema>;
export type usageDataSchema = z.infer<typeof usageDataSchema>;
export type UsageDataSchema = z.infer<typeof usageDataSchema>;

0 comments on commit ce3c3e8

Please sign in to comment.