Commit 940b8d7b authored by alain's avatar alain 🐙
Browse files

add download functionality config

parent 3b3f30d6
import { roundBy } from "../../data-on-a-map-app/src/util/math"
//import { roundBy } from "../../data-on-a-map-app/src/util/math"
import { addMissingHours, pad } from "../../data-on-a-map-app/src/util/data"
//const host = "/api"
const host = "http://hl.ao.waag.org/api"
//const host = "http://localhost:4567"
export default {
name: "holu",
sides: 24,
angle: 0,
factor: 0.5,
factor: 0.5,
dataStart: "2019-06-25T00:00:00.000Z",
all: async function getAllHolu(parameter) {
try {
......@@ -13,7 +18,7 @@ export default {
const allResponse = await fetch(`https://data.waag.org/api/getStations`)
const all = await allResponse.json()
const latestResponse = await fetch(`http://localhost:4567/sensor/${parameter}`)
const latestResponse = await fetch(`${host}/sensor/${parameter}`)
let latest = await latestResponse.json()
latest = latest.map(s => {
......@@ -44,27 +49,17 @@ export default {
}
if(sensorData) {
let sensorDataToUse
//if(sensorData.data[0][Object.keys(sensorData.data[0])[0]].value) {
if(sensorData.data[0]) {
sensorDataToUse = sensorData.data[0][Object.keys(sensorData.data[0])[0]]
} else {
sensorDataToUse = sensorData.data[1][Object.keys(sensorData.data[1])[0]]
}
const sensorDataToUse = (sensorData.data[0] ? sensorData.data[0][Object.keys(sensorData.data[0])[0]] : sensorData.data[1][Object.keys(sensorData.data[1])[0]])
console.log(sensor.id, sensorDataToUse.timestamp)
const dataAge = (new Date() - new Date(sensorDataToUse.timestamp))
console.log(`${roundBy(dataAge / 1000 / 60 / 60, 2)} uur`)
// + " (" + (dataAge < 86400000 ? "geen recente data" : "offline" ) + ")"
//console.log(sensor.id, sensorDataToUse.timestamp, `${roundBy(dataAge / 1000 / 60 / 60, 2)} uur`)
if(dataAge < 3600000) {
sensorDataReturn.mean = sensorDataToUse.value
} else {
sensorDataReturn.name = sensorDataReturn.name + " (geen recente data)"
}
} else {
offlineSensors.push(sensor.id)
sensorDataReturn.name = sensorDataReturn.name + " (offline)"
}
......@@ -80,14 +75,14 @@ export default {
console.log(`Offline Sensors (${offlineSensors.length}):`, offlineSensors.sort((a, b) => a - b).join(', '))
console.log(`Unregistered Sensors (${unregisteredSensors.length}):`, unregisteredSensors.sort((a, b) => a - b).join(', '))
Object.keys(places).forEach(function(place) {
places[place].amountOfSensors = places[place].allAverages.length
places[place].averageOfAverages = places[place].allAverages.reduce((a, b) => a + b, 0) / places[place].allAverages.length
places[place].averageOfPeaks = places[place].allPeaks.reduce((a, b) => a + b, 0) / places[place].allPeaks.length
places[place].highestAverage = Math.max(...places[place].allAverages)
places[place].highestPeak = Math.max(...places[place].allPeaks)
})
console.log(places)
// Object.keys(places).forEach(function(place) {
// places[place].amountOfSensors = places[place].allAverages.length
// places[place].averageOfAverages = places[place].allAverages.reduce((a, b) => a + b, 0) / places[place].allAverages.length
// places[place].averageOfPeaks = places[place].allPeaks.reduce((a, b) => a + b, 0) / places[place].allPeaks.length
// places[place].highestAverage = Math.max(...places[place].allAverages)
// places[place].highestPeak = Math.max(...places[place].allPeaks)
// })
// console.log(places)
return data
......@@ -108,7 +103,7 @@ export default {
)
}
const response = await fetch(`http://localhost:4567/sensor/${pad(station.id, 3)}/${parameter}?start=${start.slice(0,10)}&end=${end.slice(0,10)}`)
const response = await fetch(`${host}/sensor/${pad(station.id, 3)}/${parameter}?start=${start.slice(0,10)}&end=${end.slice(0,10)}`)
const responseData = await response.json()
const conformedData = responseData[0][Object.keys(responseData[0])[0]].map(m => {
......@@ -124,5 +119,10 @@ export default {
} catch (error) {
console.log(error)
}
},
download: function(id, parameter, start, end) {
return `${host}/api/sensor/${pad(id, 3)}/${parameter}/csv?start=${start}&end=${end}`
}
}
\ No newline at end of file
:root {
--color-button: #2fb5bb;
--color-loading: #2fb5bb;
--heading-weight: 500;
}
body {
body, input {
font-family: "Maax", sans-serif;
}
#root button.button-text {
font-family: "Maax", sans-serif;
/* padding: 0.6em 0.5em 0.4em; */
}
\ No newline at end of file
......@@ -2,7 +2,7 @@
export const texts = {
about: {
title: "over deze kaart",
body: "<p>Deze kaart visualiseert data afkomstig van 200 HOLU-sensorkits én die van officiële meetpunten van <a href='https://www.luchtmeetnet.nl/' target='_blank' rel='noopener noreferrer'>luchtmeetnet.nl</a>. Hollandse&nbsp;Luchten is een experimenteel project waarin er onderzoek wordt gedaan naar de kwaliteit van de data afkomstig van de HOLU-sensorkits, en naar de beste manier waarop je deze data kunt inzetten.</p><p><a class='more' href='https://hollandseluchten.waag.org/veelgestelde-vragen/over-luchtkwaliteit/'>meer weten</a></p>"
body: "<p>Deze kaart visualiseert data afkomstig van 200 HOLU-sensorkits én die van officiële meetpunten van <a href='https://www.luchtmeetnet.nl/' target='_blank' rel='noopener noreferrer'>luchtmeetnet.nl</a>. Hollandse&nbsp;Luchten is een experimenteel project waarin er onderzoek wordt gedaan naar de kwaliteit van de data afkomstig van de HOLU-sensorkits, en naar de beste manier waarop je deze data kunt inzetten.</p><p><a class='more' href='https://hollandseluchten.waag.org/veelgestelde-vragen/over-luchtkwaliteit/' target='_blank' rel='noopener noreferrer'>meer weten</a></p>"
},
pilotLocations: "Pilot-locaties",
loading: "Bezig met laden...",
......@@ -11,5 +11,10 @@ export const texts = {
lastMean: "laatste uurgemiddelde",
lastPeak: "piekwaarde laatste uur",
mean: "gemiddelde",
peak: "piekwaarde"
peak: "piekwaarde",
downloadData: "download data",
startDate: "startdatum",
endDate: "einddatum",
downloadCsv: "download csv",
downloadInfo: "<small><a class='more' href='https://hollandseluchten.waag.org/data-downloaden/' target='_blank' rel='noopener noreferrer'>meer info over data downloaden en de API</a></small>",
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment