Skip to content

Commit

Permalink
add aggregate heating and cooling data
Browse files Browse the repository at this point in the history
  • Loading branch information
nl32 committed Nov 17, 2024
1 parent 2956dee commit 8b6d5f1
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/app/building/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import NavBar from 'src/components/navBar';
import { db } from 'src/db';
import { eq } from 'drizzle-orm';
import { notFound } from 'next/navigation';
import { averageEnergy, averageWater, regions } from 'src/data';
import {
averageEnergy,
averageWater,
coolingMode,
heatingMode,
regions,
} from 'src/data';

export default async function Building({
params,
Expand All @@ -26,6 +32,14 @@ export default async function Building({
building.squareFeet,
building.region as regions,
);
const heatMode = await heatingMode(
building.squareFeet,
building.region as regions,
);
const coolMode = await coolingMode(
building.squareFeet,
building.region as regions,
);
return (
<>
<NavBar />
Expand Down Expand Up @@ -126,7 +140,7 @@ export default async function Building({
Buildings this size
</Typography>
<Typography variant="body1" gutterBottom className="inline">
{'MAINHT' + ' '}
{heatMode + ' '}
</Typography>
<Typography
variant="body2"
Expand All @@ -137,7 +151,7 @@ export default async function Building({
</Typography>
<br />
<Typography variant="body1" gutterBottom className="inline">
{'MAINCL' + ' '}
{coolMode + ' '}
</Typography>
<Typography
variant="body2"
Expand Down
79 changes: 79 additions & 0 deletions src/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,71 @@ import sqlite3 from 'sqlite3';
import { open } from 'sqlite';
import path from 'path';

const heatingOptions = [
'Electric furnace',
'Electric packaged unit',
'Electric boiler',
'Electric heat pump',
'Electric space heater',
'Electric fireplace',
'Electric duct reheat',
'Other electric heating equipment',
'Natural gas furnace',
'Natural gas packaged unit',
'Natural gas boiler',
'Natural gas heat pump',
'Natural gas space heater',
'Natural gas fireplace',
'Other natural gas heating equipment',
'Fuel oil furnace',
'Fuel oil boiler',
'Fuel oil space heater',
'Other fuel oil heating equipment',
'Propane furnace',
'Propane packaged unit',
'Propane boiler',
'Propane heat pump',
'Propane space heater',
'Propane fireplace',
'Other propane heating equipment',
'District steam heating system',
'District hot water heating system',
'Wood furnace',
'Wood space heater',
'Wood fireplace',
'Other wood heating equipment',
'Coal furnace',
'Coal boiler',
'Other coal heating equipment',
'Solar thermal heating',
'Other source furnace',
'Other source packaged unit',
'Other source boiler',
'Other source space heater',
'Other source fireplace',
'Other source other heating equipment',
];

const coolingOptions = [
'Residential-type split system',
'Packaged unit',
'Electric chiller',
'Heat pump',
'Individual air conditioner',
'Swamp cooler',
'Other electric air conditioning equipment',
'Natural gas chiller',
'Other natural gas air conditioning equipment',
'Fuel oil/diesel/kerosone chiller',
'Other fuel oil/diesel/kerosene air conditioning equipment',
'Propane chiller',
'Other propane air conditioning equipment',
'Steam chiller',
'Other steam air conditioning equipment',
'District chilled water system',
'Other source air conditioning equipment',
];

const db = await open({
filename: path.join(process.cwd(), 'src/app/data.db'),
driver: sqlite3.Database,
Expand Down Expand Up @@ -45,3 +110,17 @@ export async function averageWater(sqft: number, region: regions) {
)) as { 'total(WTCNS)': number; 'total(SQFT)': number };
return ((query['total(WTCNS)'] / query['total(SQFT)']) * sqft) / 12;
}

export async function heatingMode(sqft: number, region: regions) {
const query = (await db.get(
`select MAINHT from energy where SQFTC=${sqftCategory(sqft)} and region=${regionId(region)} group by MAINHT order by count(MAINHT) desc limit 1;`,
)) as { MAINHT: number };
return heatingOptions[query.MAINHT - 1];
}

export async function coolingMode(sqft: number, region: regions) {
const query = (await db.get(
`select MAINCL from energy where SQFTC=${sqftCategory(sqft)} and region=${regionId(region)} group by MAINCL order by count(MAINCL) desc limit 1;`,
)) as { MAINCL: number };
return coolingOptions[query.MAINCL - 1];
}

0 comments on commit 8b6d5f1

Please sign in to comment.