Commit 2803fadc authored by alain's avatar alain 🐙
Browse files

holu-rivm data source

parent 4ab2cb84
import luchtmeetnet from "./sources/luchtmeetnet"
import teom from "./sources/teom"
import holu from "./sources/holu"
import holu from "./sources/holu-rivm"
//import sentinel from "./sources/sentinel"
const colors = {
......
import { addMissingHours } from "../../data-on-a-map-app/src/util/data"
export default {
name: "holu",
sides: 24,
angle: 0,
factor: 0.5,
all: async function getAllHolu(parameter) {
try {
const allResponse = await fetch(`https://data.waag.org/api/getStations`)
const all = await allResponse.json()
const latestResponse = await fetch(`http://localhost:4567/sensor/${parameter}`)
let latest = await latestResponse.json()
latest = latest.map(s => {
const key = Object.keys(s)[0]
return {
id: key.slice(-3),
data: s[key]
}
})
let offlineSensors = []
let unregisteredSensors = []
let places = {}
const data = all.map(sensor => {
const sensorData = latest.find(o => {
//console.log(+o.id, +sensor.id)
//return +o.id === +sensor.id
return +o.id === 211
})
let sensorDataToUse
if(sensorData.data[0][Object.keys(sensorData.data[0])[0]].value) {
sensorDataToUse = sensorData.data[0][Object.keys(sensorData.data[0])[0]]
} else {
sensorDataToUse = sensorData.data[1][Object.keys(sensorData.data[1])[0]]
}
const dataAge = (new Date() - new Date(sensorDataToUse.timestamp))
if(dataAge < 3600000) {
return {
id: sensor.id.toString(),
name: "HoLu-kit " + sensor.id.toString() + ": " + sensor.name,
source: "holu",
coordinates: [sensor.longitude, sensor.latitude],
mean: sensorDataToUse.value,
max: null
}
} else {
return {
id: sensor.id.toString(),
name: "HoLu-kit " + sensor.id.toString() + ": " + sensor.name + " (" + (dataAge < 86400000 ? "geen recente data" : "offline" ) + ")",
source: "holu",
coordinates: [sensor.longitude, sensor.latitude],
mean: null,
max: null
}
}
})
latest.forEach(sensor => {
if(!all.find(o => +o.id === +sensor.id)) {
unregisteredSensors.push(sensor.id)
}
})
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)
return data
} catch (error) {
console.log(error)
}
},
detail: async function getDetailHolu(station, parameter, start, end) {
try {
const stationMeta = {
name: station.name,
description: (station.type === "extended" ? (
'<span>Dit is een extended HOLU-meetstation. Dit prototype meet PM2.5 en PM10 en ook NO2 en O3. Als onderdeel van de pilot wordt er onderzoek gedaan naar de kwaliteit van de data afkomstig van deze meetstations.<br /><a class="more" href="https://hollandseluchten.waag.org/holu-sensorkit/">Lees meer over de HOLU kit</a></span>'
) : (
'<span>Dit is een basic HOLU-meetstation. Dit prototype meet PM2.5 en PM10. Als onderdeel van de pilot wordt er onderzoek gedaan naar de kwaliteit van de data afkomstig van deze meetstations.<br /><a class="more" href="https://hollandseluchten.waag.org/holu-sensorkit/">Lees meer over de HOLU kit</a></span>'
)
)
}
//const response = await fetch(`https://data.waag.org/api/getHourlyValuesSensor?sensor_id=${station.id}&start=${start}&end=${end}`)
//const response = await fetch(`http://localhost:4567/sensor/${station.id}/${parameter}?start=${start.slice(0,10)}&end=${end.slice(0,10)}`)
const response = await fetch(`http://localhost:4567/sensor/211/${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 => {
return {
timestamp: new Date(m.timestamp).getTime(),
value: m.value,
}
})
const data = addMissingHours(conformedData)
return { stationMeta, data }
} catch (error) {
console.log(error)
}
}
}
\ No newline at end of file
......@@ -13,19 +13,8 @@ export default {
const all = await allResponse.json()
const latestResponse = await fetch(`https://data.waag.org/api/getAllSensors`)
//const latestResponse = await fetch(`http://localhost:4567/sensor/${parameter}`)
let latest = await latestResponse.json()
// NEW
// latest = latest.map(s => {
// const key = Object.keys(s)[0]
// return {
// id: key.slice(-3),
// data: s[key]
// }
// })
let offlineSensors = []
let unregisteredSensors = []
let places = {}
......@@ -37,37 +26,6 @@ export default {
//return +o.id === 219
})
// NEW
// let sensorDataToUse
// if(sensorData.data[0][Object.keys(sensorData.data[0])[0]].value) {
// sensorDataToUse = sensorData.data[0][Object.keys(sensorData.data[0])[0]]
// } else {
// sensorDataToUse = sensorData.data[1][Object.keys(sensorData.data[1])[0]]
// }
// const dataAgeInDays = (new Date() - new Date(sensorDataToUse.timestamp)) / 86400000
// if(dataAgeInDays === 0) {
// return {
// id: sensor.id.toString(),
// name: "HOLU-sensor " + sensor.id.toString() + ": " + sensor.name,
// type: "HOLU-sensor",
// source: "holu",
// coordinates: [sensor.longitude, sensor.latitude],
// mean: sensorDataToUse.value,
// max: null
// }
// } else {
// return {
// id: sensor.id.toString(),
// name: "HOLU-sensor " + sensor.id.toString() + ": " + sensor.name + " (" + (dataAgeInDays < 1 ? "geen data van laatste uur" : "offline" ) + ")",
// type: "HOLU-sensor",
// source: "holu",
// coordinates: [sensor.longitude, sensor.latitude],
// mean: null,
// max: null
// }
// }
// OLD
if(sensorData) {
......@@ -140,10 +98,7 @@ export default {
)
}
//console.log(start.slice(0,10))
const response = await fetch(`https://data.waag.org/api/getHourlyValuesSensor?sensor_id=${station.id}&start=${start}&end=${end}`)
//const response = await fetch(`http://localhost:4567/sensor/${station.id}/${parameter}?start=${start.slice(0,10)}&end=${end.slice(0,10)}`)
const responseData = await response.json()
var prefix
......
data-on-a-map-app @ 0c98dc82
Subproject commit 9bf5a2ac88c7bb0f74ba9036cd7f9b0dfff29ddd
Subproject commit 0c98dc825fce89a9fc384175831d943c9142c8fd
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