added additional summary metrics

This commit is contained in:
Khalim Conn-Kowlessar 2025-08-21 23:40:05 +00:00
parent 8a5e029b03
commit f18b819992
4 changed files with 83 additions and 7 deletions

View file

@ -14,6 +14,8 @@ export async function GET(request: NextRequest, props: { params: Promise<{ scena
.select({
name: scenario.name,
cost: scenario.cost,
funding: scenario.funding,
contingency: scenario.contingency,
epcBreakdownPostRetrofit: scenario.epcBreakdownPostRetrofit,
numberOfProperties: scenario.numberOfProperties,
nUnitsToRetrofit: scenario.nUnitsToRetrofit,
@ -99,7 +101,7 @@ export async function GET(request: NextRequest, props: { params: Promise<{ scena
],
},
{
title: "Cost (£)",
title: "Cost of works (£)",
scenarios: [
{
scenarioName: scenarioName,
@ -108,10 +110,34 @@ export async function GET(request: NextRequest, props: { params: Promise<{ scena
],
},
{
title: "Cost (£)/unit",
title: "Cost of works (£)/unit",
scenarios: [
{ scenarioName: scenarioName, data: data[0].costPerUnit || "" },
],
},
{
title: "Funding (£)",
scenarios: [
{ scenarioName: scenarioName, data: "£" + formatNumber(data[0].funding || 0) },
],
},
{
title: "Funding (£)/unit",
scenarios: [
{ scenarioName: scenarioName, data: "£" + formatNumber((data[0].funding || 0) / (data[0].nUnitsToRetrofit || 1)) },
],
},
{
title: "Contingency (£)",
scenarios: [
{ scenarioName: scenarioName, data: "£" + formatNumber(data[0].contingency || 0) },
],
},
{
title: "Contingency (£)/unit",
scenarios: [
{ scenarioName: scenarioName, data: "£" + formatNumber((data[0].contingency || 0) / (data[0].nUnitsToRetrofit || 1)) },
],
},
{
title: "£ per CO2 reduction",

View file

@ -184,7 +184,7 @@ const SummaryTable = ({
<div className="my-8">
<button
onClick={() => setIsModalOpen(true)}
className="mb-4 p-2 bg-brandgold text-white rounded disabled:opacity-50"
className="mb-4 p-2 bg-brandbrown text-white rounded disabled:opacity-50"
// If scenarios is empty, we disable this button
disabled={scenarios.length === 0}
>

View file

@ -17,6 +17,8 @@ export default async function PortfolioSummary(
// Get user id from the session
const scenarios = await getNonDefaultPortfolioScenarios(portfolioId);
console.log(data)
return (
<div className="container mx-auto px-4">
<h1 className="text-3xl text-gray-700 font-bold my-4">Summary</h1>

View file

@ -114,6 +114,7 @@ export interface DataItem {
scenarios: Scenario[];
}
export async function getOverviewPortfolioData(
portfolioId: string
): Promise<DataItem[]> {
@ -126,6 +127,8 @@ export async function getOverviewPortfolioData(
.select({
name: scenario.name,
cost: scenario.cost,
funding: scenario.funding,
contingency: scenario.contingency,
epcBreakdownPreRetrofit: scenario.epcBreakdownPreRetrofit,
epcBreakdownPostRetrofit: scenario.epcBreakdownPostRetrofit,
numberOfProperties: scenario.numberOfProperties,
@ -154,7 +157,7 @@ export async function getOverviewPortfolioData(
if (data.length === 0) {
// If we have no data, we fetch it from the scenarios. This will facilitate this for older portfolios
data = await db
const fallback = await db
.select({
name: portfolio.name,
cost: portfolio.cost,
@ -179,7 +182,12 @@ export async function getOverviewPortfolioData(
.from(portfolio)
.where(eq(portfolio.id, BigInt(portfolioId)));
// If we still have no data, we throw and error
// funding and contingency are not available so we insert them
data = fallback.map((x) => ({
...x,
funding: 0,
contingency: 0,
}));
if (data.length === 0) {
throw new Error("Portfolio not found");
}
@ -270,7 +278,7 @@ export async function getOverviewPortfolioData(
],
},
{
title: "Cost (£)",
title: "Cost of works (£)",
scenarios: [
{ scenarioName: "Today", data: "" },
{
@ -280,7 +288,7 @@ export async function getOverviewPortfolioData(
],
},
{
title: "Cost (£)/unit",
title: "Cost of works (£)/unit",
scenarios: [
{ scenarioName: "Today", data: "" },
{
@ -289,6 +297,46 @@ export async function getOverviewPortfolioData(
},
],
},
{
title: "Funding (£)",
scenarios: [
{ scenarioName: "Today", data: "" },
{
scenarioName: portfolioName || "Default",
data: "£" + formatNumber(data[0].funding || 0),
},
],
},
{
title: "Funding (£)/unit",
scenarios: [
{ scenarioName: "Today", data: "" },
{
scenarioName: portfolioName || "Default",
data: "£" + formatNumber((data[0].funding || 0) / (data[0].nUnitsToRetrofit || 1)),
},
],
},
{
title: "Contingency (£)",
scenarios: [
{ scenarioName: "Today", data: "" },
{
scenarioName: portfolioName || "Default",
data: "£" + formatNumber(data[0].contingency || 0),
},
],
},
{
title: "Contingency (£)/unit",
scenarios: [
{ scenarioName: "Today", data: "" },
{
scenarioName: portfolioName || "Default",
data: "£" + formatNumber((data[0].contingency || 0) / (data[0].nUnitsToRetrofit || 1)),
},
],
},
{
title: "£ per CO2 reduction",
scenarios: [