diff --git a/gridsome.server.js b/gridsome.server.js index 67c60b39..09541d3f 100644 --- a/gridsome.server.js +++ b/gridsome.server.js @@ -15,6 +15,7 @@ const parse = require('csv-parse/sync').parse; const DataDirectory = './src/data/dist/'; const BuildingEmissionsDataFile = 'building-benchmarks.csv'; +const HistoricBenchmarkingDataFile = 'benchmarking-all-years.csv'; // This is an array equivalent of Object.keys(BuildingOwners) but this file can't use Typescript and // import that file @@ -34,6 +35,7 @@ module.exports = function(api) { // Use the Data Store API here: https://gridsome.org/docs/data-store-api/ api.loadSource(async (actions) => { loadBuildingBenchmarkData(actions); + loadHistoricBenchmarkDat(actions); }); // Use the Pages API here: https://gridsome.org/docs/pages-api/ @@ -56,19 +58,19 @@ module.exports = function(api) { * @param {unknown} actions The actions class? */ function loadBuildingBenchmarkData(actions) { - const input = readFileSync(`${DataDirectory}${BuildingEmissionsDataFile}`, 'utf8'); + const latestBenchmarksRaw = readFileSync(`${DataDirectory}${BuildingEmissionsDataFile}`, 'utf8'); /** * Load in building benchmarks and expose as Buildings collection */ - const BuildingsData = parse(input, { + const LatestBenchmarksData = parse(latestBenchmarksRaw, { columns: true, skip_empty_lines: true, }); const collection = actions.addCollection({typeName: 'Building'}); - for (const building of BuildingsData) { + for (const building of LatestBenchmarksData) { // Make a slugSource that is the property name or the address as a fallback (skip one letter // names, e.g. '-) building.slugSource = building.PropertyName.length > 1 ? building.PropertyName : building.Address; @@ -80,3 +82,27 @@ function loadBuildingBenchmarkData(actions) { collection.addNode(building); } } + + +/** + * Load in the historic benchmark data + * + * @param {unknown} actions The actions class? + */ +function loadHistoricBenchmarkDat(actions) { + const historicBenchmarksRaw = readFileSync(`${DataDirectory}${HistoricBenchmarkingDataFile}`, 'utf8'); + + /** + * Load in building benchmarks and expose as Buildings collection + */ + const HistoricBenchmarksData = parse(historicBenchmarksRaw, { + columns: true, + skip_empty_lines: true, + }); + + const collection = actions.addCollection({ typeName: 'Benchmark' }); + + for (const benchmark of HistoricBenchmarksData) { + collection.addNode(benchmark); + } +} diff --git a/src/common-functions.vue b/src/common-functions.vue index 31cb5ab5..74ce6695 100644 --- a/src/common-functions.vue +++ b/src/common-functions.vue @@ -56,6 +56,19 @@ export interface IBuilding { /** How GraphQL passes back a building */ export interface IBuildingNode { node: IBuilding } +export interface IHistoricData { + ID: string; + DataYear: string; + GrossFloorArea: string; + ChicagoEnergyRating: string; + ENERGYSTARScore: string; + SourceEUI: string; + ElectricityUse: string; + GHGIntensity: string; + NaturalGasUse: string; + DistrictSteamUse: string; +} + /** * A constant for what we use as min and max values for flagged ranks */ diff --git a/src/components/BuildingsTable.vue b/src/components/BuildingsTable.vue index 1c2adac0..be13e4c9 100644 --- a/src/components/BuildingsTable.vue +++ b/src/components/BuildingsTable.vue @@ -33,7 +33,7 @@ export default class BuildingsTable extends Vue {