From ac6ecf3299d91bebffad6c91404e9f33efa455d6 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Thu, 27 Jul 2023 17:41:36 +0100 Subject: [PATCH] Adding functionality to recommendations page --- .../building-passport/RecommendationCard.tsx | 6 ++ src/app/db/schema/property.ts | 1 + src/app/db/schema/recommendations.ts | 1 + .../building-passport/[propertyId]/layout.tsx | 1 + .../building-passport/[propertyId]/page.tsx | 1 + .../[propertyId]/recommendations/page.tsx | 91 ++++++++++++++++++- src/app/utils.ts | 22 +++++ 7 files changed, 122 insertions(+), 1 deletion(-) diff --git a/src/app/components/building-passport/RecommendationCard.tsx b/src/app/components/building-passport/RecommendationCard.tsx index f04b8973..fb06508b 100644 --- a/src/app/components/building-passport/RecommendationCard.tsx +++ b/src/app/components/building-passport/RecommendationCard.tsx @@ -199,6 +199,12 @@ export default function RecommendationCard({ {cardComponent.newUValue} )} + {cardComponent.sapPoints && ( + + SAP Points: + {cardComponent.sapPoints} + + )} rec.default + ) || { estimatedCost: 0, sapPoints: 0 }; + + const defaultFloorRecommendations = recommendations.Floor?.find( + (rec: ComponentRecommendation) => rec.default + ) || { estimatedCost: 0, sapPoints: 0 }; + + const defaultVentiliationRecommendations = recommendations.Ventilation?.find( + (rec: ComponentRecommendation) => rec.default + ) || { estimatedCost: 0, sapPoints: 0 }; + + const totalEstimatedCost = + (defaultWallsRecommendations.estimatedCost || 0) + + (defaultFloorRecommendations.estimatedCost || 0) + + (defaultVentiliationRecommendations.estimatedCost || 0); + + const totalSapPoints = + (defaultWallsRecommendations.sapPoints || 0) + + (defaultFloorRecommendations.sapPoints || 0) + + (defaultVentiliationRecommendations.sapPoints || 0); + + const currentEpcRating = propertyMeta.currentEpcRating; + const currentSapPoints = propertyMeta.currentSapPoints; + + const expectedSapPoints = currentSapPoints + totalSapPoints; + const expectedEpcRating = sapToEpc(expectedSapPoints); + return (
Recommendations
+ +
+ + + + + + + + + + + + +
Total Cost:{"£" + formatNumber(totalEstimatedCost)}
+ Total SAP Points Improvement: + {totalSapPoints}
+ + + + + + + + + + + + + +
Current EPC Rating:{currentEpcRating}
Expected EPC Rating:{expectedEpcRating}
+
{Object.entries(recommendations).map( ([componentType, recommendationData], idx) => { diff --git a/src/app/utils.ts b/src/app/utils.ts index 7c710755..1468ab83 100644 --- a/src/app/utils.ts +++ b/src/app/utils.ts @@ -1,3 +1,25 @@ +export function sapToEpc(sapPoints: number): string { + if (sapPoints <= 0 || sapPoints > 100) { + throw new Error("SAP points should be between 1 and 100."); + } + + if (sapPoints > 91) { + return "A"; + } else if (sapPoints > 80) { + return "B"; + } else if (sapPoints > 69) { + return "C"; + } else if (sapPoints > 55) { + return "D"; + } else if (sapPoints > 39) { + return "E"; + } else if (sapPoints > 21) { + return "F"; + } else { + return "G"; + } +} + export function formatDateTime(dateTimeString: string): string { // Create a new Date object const dateTime = new Date(dateTimeString);