Skip to content

Commit

Permalink
Double baseline
Browse files Browse the repository at this point in the history
  • Loading branch information
TyHil committed Nov 17, 2024
1 parent f5337a6 commit d0cc9d8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
21 changes: 14 additions & 7 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PieChart from 'src/components/pieChart';
import NavBar from 'src/components/navBar';
import Image from 'next/image';
import { db } from 'src/db';
import { genericAverageEnergy } from 'src/data';
import { genericAverageEnergy, genericAverageFuel } from 'src/data';

export default async function Home() {
const buildings = await db.query.building.findMany();
Expand All @@ -13,8 +13,9 @@ export default async function Home() {
const gasSums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
const buildingTypes = [0, 0, 0];

const averageEnergy = await genericAverageEnergy() * buildings.length;

const averageEnergy = (await genericAverageEnergy()) * buildings.length;
const averageFuel = (await genericAverageFuel()) * buildings.length;

await buildings.forEach((building) => {
for (let i = 0; i < 12; i++) {
energySums[i] += building.energy[i];
Expand Down Expand Up @@ -77,10 +78,16 @@ export default async function Home() {
'Sep',
'Oct',
]}
annotation={{
name: 'Energy Baseline',
value: averageEnergy,
}}
annotations={[
{
name: 'Electricity Baseline',
value: averageEnergy,
},
{
name: 'Fuel Baseline',
value: averageFuel,
},
]}
className="h-1/2 bg-background"
/>
</div>
Expand Down
11 changes: 7 additions & 4 deletions src/components/building.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ export default function Building({ building }: BuildingCardProps) {

const totalEnergyUsage = building.energy.reduce((a, b) => a + b) / 12;
const key =
totalEnergyUsage > 0 && totalEnergyUsage < 500000 ? 'green' :
totalEnergyUsage > 0 && totalEnergyUsage < 800000 ? 'yellow' :
totalEnergyUsage > 0 && totalEnergyUsage < 1050000 ? 'orange' :
'red';
totalEnergyUsage > 0 && totalEnergyUsage < 500000
? 'green'
: totalEnergyUsage > 0 && totalEnergyUsage < 800000
? 'yellow'
: totalEnergyUsage > 0 && totalEnergyUsage < 1050000
? 'orange'
: 'red';
return (
<Link className="m-5" href={`/building/${building.id}`}>
<Card className="flex flex-row items-center justify-between rounded-lg bg-white p-5">
Expand Down
19 changes: 10 additions & 9 deletions src/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,11 @@ export async function averageEnergy(sqft: number, region: regions) {
)) as { 'avg(ELBTU)': number };
return average['avg(ELBTU)'] / 12;
}
export async function averageGas(sqft: number, region: regions) {
const average = (await db.get(
`SELECT avg(MFBTU) from energy where SQFTC=${sqftCategory(sqft)} and region=${regionId(region)}`,
)) as { 'avg(MFBTU)': number };
return average['avg(MFBTU)'] / 12;
}

export async function genericAverageEnergy() {
const average = (await db.get(
`SELECT avg(ELBTU) from energy`,
)) as { 'avg(ELBTU)': number };
const average = (await db.get(`SELECT avg(ELBTU) from energy`)) as {
'avg(ELBTU)': number;
};
return average['avg(ELBTU)'] / 12;
}

Expand All @@ -99,6 +93,13 @@ export async function averageFuel(sqft: number, region: regions) {
return average['avg(MFBTU)'] / 12;
}

export async function genericAverageFuel() {
const average = (await db.get(`SELECT avg(MFBTU) from energy`)) as {
'avg(MFBTU)': number;
};
return average['avg(MFBTU)'] / 12;
}

function sqftCategory(sqft: number) {
if (sqft < 5001) return 2;
if (sqft < 10001) return 3;
Expand Down

0 comments on commit d0cc9d8

Please sign in to comment.