Skip to content
This repository has been archived by the owner on Aug 17, 2020. It is now read-only.

Commit

Permalink
fix: fix error when generating data files for municipality without tests
Browse files Browse the repository at this point in the history
  • Loading branch information
severo committed Apr 19, 2019
1 parent b5e03b3 commit 97da3cb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
6 changes: 3 additions & 3 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<title>Quem bebe agrotóxicos?</title>
<!-- TODO: bundle at build -->
<script defer src="https://bundle.run/fuzzball@1.2.0"></script>
<script defer src="lib/main.pt.js?v=1555656014"></script>
<link rel="stylesheet" href="css/main.css?v=1555656014" />
<script defer src="lib/main.pt.js?v=1555657051"></script>
<link rel="stylesheet" href="css/main.css?v=1555657051" />
</head>
<body>
<section id="page-title" class="hero is-small is-primary cocktail">
Expand Down Expand Up @@ -114,7 +114,7 @@ <h2 class="subtitle is-4">
>GitHub</a
>
</strong>
- v1555656014
- v1555657051
</p>
<p>
<small>
Expand Down
2 changes: 1 addition & 1 deletion docs/lib/main.pt.js

Large diffs are not rendered by default.

26 changes: 14 additions & 12 deletions src/_javascript/details/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,9 @@ function generateBySubstanceJson(mun, data) {
const json = Object.keys(data.substancesLut)
.sort((key1, key2) => key1.localeCompare(key2, '{{locale}}'))
.map(key => {
const substanceTest = mun.properties.tests.find(
test => test.substance.code === key
);
const substanceTest =
'tests' in mun.properties &&
mun.properties.tests.find(test => test.substance.code === key);
return {
'{{details.csv.substances.columns.name}}': data.substancesLut[key].name,
'{{details.csv.substances.columns.supbr}}': substanceTest
Expand Down Expand Up @@ -490,15 +490,17 @@ function generateBySubstanceCsvBlob(mun, data) {
}

function generateByDateJson(mun) {
const resultsByDate = mun.properties.tests.reduce((acc, testsSubstance) => {
testsSubstance.testsByDate.forEach(testsDate => {
if (!(testsDate.date in acc)) {
acc[testsDate.date] = 0;
}
acc[testsDate.date] += testsDate.tests.length;
});
return acc;
}, {});
const resultsByDate =
'tests' in mun.properties &&
mun.properties.tests.reduce((acc, testsSubstance) => {
testsSubstance.testsByDate.forEach(testsDate => {
if (!(testsDate.date in acc)) {
acc[testsDate.date] = 0;
}
acc[testsDate.date] += testsDate.tests.length;
});
return acc;
}, {});
const dates = Object.keys(resultsByDate).sort(
(date1, date2) => date1 > date2
);
Expand Down

0 comments on commit 97da3cb

Please sign in to comment.