Added the solar scenario table

This commit is contained in:
Khalim Conn-Kowlessar 2024-07-10 17:37:17 +01:00
parent 28a8308215
commit e933feb764
6 changed files with 77 additions and 9 deletions

View file

@ -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
}
]
}

View file

@ -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<typeof solar, "select">;
export type SolarScenario = InferModel<typeof solarSenario, "select">;
interface Center {
latitude: number;

View file

@ -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}
/>
</div>
<div className="bg-white shadow-md rounded-lg p-6 mb-8 w-full">
<h2 className="text-l font-semibold text-gray-800 mb-4">
Recommended Solar Configuration
</h2>
{/*
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
*/}
</div>
</div>
</div>
);

View file

@ -38,9 +38,4 @@ export const roofSegmentsColumns: ColumnDef<RoofSegment>[] = [
header: "Direction",
size: 50,
},
{
accessorKey: "planeHeightAtCenterMeters",
header: "Plane Height at Center (m)",
size: 100,
},
];

View file

@ -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<SolarInterface> {
@ -13,3 +18,17 @@ export async function getSolarData(uprn: number): Promise<SolarInterface> {
return data as SolarInterface;
}
export async function getSolarScenarioData(
solarId: string
): Promise<SolarScenario> {
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;
}

View file

@ -1,8 +1,8 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"target": "es5",
// "target": "ESNext",
// "target": "es5",
"target": "ESNext",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,