Skip to content

Commit

Permalink
path shenanigans
Browse files Browse the repository at this point in the history
  • Loading branch information
nl32 committed Nov 17, 2024
1 parent d4c2fa5 commit 978748f
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/data.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import sqlite3 from 'sqlite3';
import { open } from 'sqlite';
import path from 'path';
import { env } from './env.mjs';

const db = await open({
filename:
env.NODE_ENV == 'production'
? path.join(process.cwd() + 'data.db')
: 'data.db',
driver: sqlite3.Database,
});

export type regions = 'Northeast' | 'Midwest' | 'South' | 'West';
export async function averageEnergy(sqft: number, region: regions) {
const db = await open({
filename: 'data.db',
driver: sqlite3.Database,
});
const average = (await db.get(
`SELECT avg(ELBTU) from energy where SQFTC=${sqftCategory(sqft)} and region=${regionId(region)}`,
)) as { 'avg(ELBTU)': number };
Expand Down Expand Up @@ -39,13 +45,8 @@ function regionId(region: regions) {
}

export async function averageWater(sqft: number, region: regions) {
const db = await open({
filename: 'data.db',
driver: sqlite3.Database,
});
const query = (await db.get(
`SELECT total(WTCNS),total(SQFT) from water where region=${regionId(region)}`,
)) as { 'total(WTCNS)': number; 'total(SQFT)': number };
console.log(query);
return ((query['total(WTCNS)'] / query['total(SQFT)']) * sqft) / 12;
}

0 comments on commit 978748f

Please sign in to comment.