From e933feb76425f4bea06c97e29ae882ee90330f57 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Wed, 10 Jul 2024 17:37:17 +0100 Subject: [PATCH] Added the solar scenario table --- src/app/db/migrations/meta/_journal.json | 7 +++++ src/app/db/schema/solar.ts | 27 +++++++++++++++++++ .../[propertyId]/solar-analysis/page.tsx | 22 ++++++++++++++- .../solar-analysis/roof-segments-table.tsx | 5 ---- .../[propertyId]/solar-analysis/utils.tsx | 21 ++++++++++++++- tsconfig.json | 4 +-- 6 files changed, 77 insertions(+), 9 deletions(-) diff --git a/src/app/db/migrations/meta/_journal.json b/src/app/db/migrations/meta/_journal.json index e42f3c5..5db0d3b 100644 --- a/src/app/db/migrations/meta/_journal.json +++ b/src/app/db/migrations/meta/_journal.json @@ -519,6 +519,13 @@ "when": 1720605222664, "tag": "0073_youthful_havok", "breakpoints": true + }, + { + "idx": 74, + "version": "5", + "when": 1720629405710, + "tag": "0074_regular_blonde_phantom", + "breakpoints": true } ] } \ No newline at end of file diff --git a/src/app/db/schema/solar.ts b/src/app/db/schema/solar.ts index 59a8cc3..93ff6d5 100644 --- a/src/app/db/schema/solar.ts +++ b/src/app/db/schema/solar.ts @@ -5,8 +5,12 @@ import { real, jsonb, bigint, + pgEnum, + integer, + boolean, } from "drizzle-orm/pg-core"; import { InferModel } from "drizzle-orm"; +import { C } from "drizzle-orm/db.d-cf0abe10"; export const solar = pgTable("solar", { id: bigserial("id", { mode: "bigint" }).primaryKey(), @@ -28,8 +32,31 @@ export const solar = pgTable("solar", { googleApiResponse: jsonb("google_api_response").notNull(), }); +// Create a table with the solar panel scenarios +export const scenarioType: [string, ...string[]] = ["unit", "building"]; +export const scenarioTypeEnum = pgEnum("scenario_type", scenarioType); + +export const solarSenario = pgTable("solar_scenario", { + id: bigserial("id", { mode: "bigint" }).primaryKey(), + solar_id: bigint("solar_id", { mode: "bigint" }) + .notNull() + .references(() => solar.id), + scenrioType: scenarioTypeEnum("scenario_type").notNull(), + numberPanels: integer("number_panels").notNull(), + arrayKwhp: integer("array_kwhp").notNull(), + lifetimeDcKwh: real("lifetime_dc_kwh").notNull(), + yearlyDcKwh: real("yearly_dc_kwh").notNull(), + lifetimeAcKwh: real("lifetime_ac_kwh"), + yearlyAcKwh: real("yearly_ac_kwh"), + cost: real("cost").notNull(), + expectedPaybackYears: real("expected_payback_years"), + panelledRoofArea: real("panelled_roof_area").notNull(), + isDefault: boolean("is_default").notNull(), +}); + // Define types for selecting and inserting data export type Solar = InferModel; +export type SolarScenario = InferModel; interface Center { latitude: number; diff --git a/src/app/portfolio/[slug]/building-passport/[propertyId]/solar-analysis/page.tsx b/src/app/portfolio/[slug]/building-passport/[propertyId]/solar-analysis/page.tsx index 06eb3c2..792f30f 100644 --- a/src/app/portfolio/[slug]/building-passport/[propertyId]/solar-analysis/page.tsx +++ b/src/app/portfolio/[slug]/building-passport/[propertyId]/solar-analysis/page.tsx @@ -7,7 +7,7 @@ import { SparklesIcon, } from "@heroicons/react/24/outline"; import { getPropertyMeta } from "../utils"; -import { getSolarData } from "./utils"; +import { getSolarData, getSolarScenarioData } from "./utils"; import FeatureTable from "@/app/components/building-passport/FeatureTable"; import { roofSegmentsColumns } from "./roof-segments-table"; @@ -18,6 +18,7 @@ export default async function SolarAnalysisPage({ }) { const propertyMeta = await getPropertyMeta(params.propertyId); const solarData = await getSolarData(Number(propertyMeta.uprn)); + const solarScenarioData = await getSolarScenarioData(String(solarData.id)); if (!solarData) { return ( @@ -134,6 +135,25 @@ export default async function SolarAnalysisPage({ columns={roofSegmentsColumns} /> + +
+

+ Recommended Solar Configuration +

+ {/* + We want to show: + - Number of panels + - Array ouput + - lifetime dc energy + - yearly dc energy + - lifetime ac energy + - yearly ac energy + - cost + - roi + - expected payback years + - pannelled roof area + */} +
); diff --git a/src/app/portfolio/[slug]/building-passport/[propertyId]/solar-analysis/roof-segments-table.tsx b/src/app/portfolio/[slug]/building-passport/[propertyId]/solar-analysis/roof-segments-table.tsx index 37b22ca..0a98066 100644 --- a/src/app/portfolio/[slug]/building-passport/[propertyId]/solar-analysis/roof-segments-table.tsx +++ b/src/app/portfolio/[slug]/building-passport/[propertyId]/solar-analysis/roof-segments-table.tsx @@ -38,9 +38,4 @@ export const roofSegmentsColumns: ColumnDef[] = [ header: "Direction", size: 50, }, - { - accessorKey: "planeHeightAtCenterMeters", - header: "Plane Height at Center (m)", - size: 100, - }, ]; diff --git a/src/app/portfolio/[slug]/building-passport/[propertyId]/solar-analysis/utils.tsx b/src/app/portfolio/[slug]/building-passport/[propertyId]/solar-analysis/utils.tsx index 7388bb5..371704a 100644 --- a/src/app/portfolio/[slug]/building-passport/[propertyId]/solar-analysis/utils.tsx +++ b/src/app/portfolio/[slug]/building-passport/[propertyId]/solar-analysis/utils.tsx @@ -1,5 +1,10 @@ import { db } from "@/app/db/db"; -import { SolarInterface, solar } from "@/app/db/schema/solar"; +import { + SolarInterface, + solar, + SolarScenario, + solarSenario, +} from "@/app/db/schema/solar"; import { eq } from "drizzle-orm"; export async function getSolarData(uprn: number): Promise { @@ -13,3 +18,17 @@ export async function getSolarData(uprn: number): Promise { return data as SolarInterface; } + +export async function getSolarScenarioData( + solarId: string +): Promise { + const data = await db.query.solarSenario.findFirst({ + where: eq(solarSenario.solar_id, BigInt(solarId)), + }); + + if (!data) { + throw new Error("Network response was not ok"); + } + + return data; +} diff --git a/tsconfig.json b/tsconfig.json index 6468155..7f10c94 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,8 +1,8 @@ { "compilerOptions": { "allowSyntheticDefaultImports": true, - "target": "es5", - // "target": "ESNext", + // "target": "es5", + "target": "ESNext", "lib": ["dom", "dom.iterable", "esnext"], "allowJs": true, "skipLibCheck": true,