Skip to content

Commit

Permalink
Merge pull request #137 from vkoves/fix-years-reported
Browse files Browse the repository at this point in the history
Fix Years Reported Graph
  • Loading branch information
vkoves authored Nov 20, 2024
2 parents 6b38990 + 69d5575 commit 726d074
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 35 deletions.
55 changes: 22 additions & 33 deletions src/components/ReportingTile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
{{ grade }}
</span>
</p>

<ul>
<li
v-for="item in reportingHistory"
Expand All @@ -35,6 +36,12 @@
<p>{{ item.year }}</p>
</li>
</ul>

<p class="footnote">
<strong>Note:</strong> Buildings are marked as reporting when we have greenhouse gas intensity
values for them, but some buildings are missing GHG intensity values but have reported the
underlying energy use data, but we're unsure why this is the case.
</p>
</div>
</template>

Expand All @@ -45,15 +52,15 @@ import { IHistoricData } from "../common-functions.vue";
import { LatestDataYear } from "../constants/globals.vue";
/**
* A tile that shows the reporting history of a building. For each year, it shows a
* checkmark if there is data available and a cross if there is no data. It starts
* from the year that the building first reported their data and goes to the last year
* A tile that shows the reporting history of a building. For each year, it shows a
* checkmark if there is data available and a cross if there is no data. It starts
* from the year that the building first reported their data and goes to the last year
* of data that the website shows. It also shows a score and a letter grade depending on
* how many years were successfully reported.
*
*
* TODO:
* Some examples that can be used for testing:
* 1. United Center (reporting stops before the latest year of data -> therefore, adding the
* 1. United Center (reporting stops before the latest year of data -> therefore, adding the
* missing years)
* 2. Digital Printer's Row (missing reports in between years that are reported)
* 3. Searle Chemistry Laboratory (all years reported)
Expand Down Expand Up @@ -88,36 +95,18 @@ export default class ReportingTile extends Vue {
return this.reportingHistory.filter((entry) => entry.isReported).length;
}
/**
* Based on the historic data, create a simplified mapping of whether data was reported
*/
get reportingHistory(): { year: number; isReported: boolean }[] {
if (!this.historicData || this.historicData.length === 0) return [];
const reportingHistory = [];
const reportedYears = this.historicData.map((entry) =>
parseInt(entry.DataYear),
);
let currentYear = reportedYears[0];
for (let reportedYear of reportedYears) {
// take care of missing years that lie in between reported years
while (currentYear !== reportedYear) {
reportingHistory.push({ year: currentYear, isReported: false });
currentYear++;
}
// if year is reported (standard case)
reportingHistory.push({ year: currentYear, isReported: true });
currentYear++;
}
/**
* if a building stopped reporting before the latest year that we have data for,
* add the missing years to history and mark them as not reported
*/
while (currentYear <= LatestDataYear) {
reportingHistory.push({ year: currentYear, isReported: false });
currentYear++;
}
return reportingHistory;
return this.historicData.map((datum: IHistoricData) => {
return {
year: parseInt(datum.DataYear),
isReported: !isNaN(parseInt(datum.GHGIntensity)),
};
});
}
}
</script>
Expand Down Expand Up @@ -200,7 +189,7 @@ export default class ReportingTile extends Vue {
ul {
column-gap: 1.5rem;
}
.marker {
width: 1.75rem;
height: 1.75rem;
Expand Down
2 changes: 0 additions & 2 deletions src/components/graphs/SparkLine.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ export default class BarGraph extends Vue {
}
renderGraph(): void {
console.log(this.graphData);
// Empty the SVG
this.svg.html(null);
Expand Down

0 comments on commit 726d074

Please sign in to comment.