Commit b4f46cc7 authored by alain's avatar alain 🐙

add no2 settings

parent a7cb36a4
......@@ -127,7 +127,8 @@ export const dataGroups = [
more: "https://www.luchtmeetnet.nl/uitleg",
type: "StationLayer",
sources: [
luchtmeetnet
luchtmeetnet,
holu
]
},
......
......@@ -28,6 +28,11 @@ export default {
minmax: { key: "pm10_cal_minmax", type: "area", active: true, color: true },
mean: { key: "pm10_cal_mean", type: "line", active: true, color: true }
}
},
no2: {
single: {
mean: { key: "no2_mean", type: "line", active: true, color: true }
}
}
},
......@@ -46,13 +51,20 @@ export default {
let unregisteredSensors = []
//let places = {}
const data = all.map(sensor => {
const filterExtended = parameter === "no2" ? true : false
const data = all
.filter(sensor => {
return filterExtended ? sensor.extended : true
})
.map(sensor => {
const sensorData = latest.find(o => +o.id === +sensor.id)
const sensorDataReturn = {
id: sensor.id.toString(),
name: "HOLU-sensor " + sensor.id.toString() + ": " + sensor.name,
source: "holu",
type: sensor.extended ? "extended" : "basic",
coordinates: [sensor.longitude, sensor.latitude],
mean: null,
timestamp: null,
......@@ -124,58 +136,80 @@ export default {
var prefix
if (parameter === "pm25") prefix = parameter
if (parameter === "pm10") prefix = parameter
if (parameter === "no2") prefix = parameter
if (parameter === "temperature") prefix = "t_out"
if (parameter === "humidity") prefix = "h_out"
let data = []
const responseRaw = await fetch(`https://data.waag.org/api/getHourlyValuesSensor?sensor_id=${station.id}&start=${start}&end=${end}`)
const jsonRaw = await responseRaw.json()
if(parameter === "pm25" || parameter === "pm10") {
const responseRaw = await fetch(`https://data.waag.org/api/getHourlyValuesSensor?sensor_id=${station.id}&start=${start}&end=${end}`)
const jsonRaw = await responseRaw.json()
let dataRaw = jsonRaw.map(m => {
return {
timestamp: new Date(m.time).getTime(),
mean: m[`${prefix}_mean`],
minmax: [m[`${prefix}_min`], m[`${prefix}_max`]]
}
})
let dataRaw = jsonRaw.map(m => {
return {
timestamp: new Date(m.time).getTime(),
mean: m[`${prefix}_mean`],
minmax: [m[`${prefix}_min`], m[`${prefix}_max`]]
}
})
const responseCal = await fetch(`https://data.waag.org/api/holu/holukit/calibrated/hourly?sensor_id=${station.id}&start=${start}&end=${end}`)
const jsonCal = await responseCal.json()
let dataCal = jsonCal.map(m => {
return {
timestamp: new Date(m.time).getTime(),
mean: m[`${prefix}_mean`],
fac: m[`${prefix}_fac`],
}
})
const responseCal = await fetch(`https://data.waag.org/api/holu/holukit/calibrated/hourly?sensor_id=${station.id}&start=${start}&end=${end}`)
const jsonCal = await responseCal.json()
if(dataRaw[0] && dataCal[0]) {
const dataStart = (dataRaw[0].timestamp < dataCal[0].timestamp ? dataRaw[0].timestamp : dataCal[0].timestamp)
const dataEnd = new Date(end).getTime()
let dataCal = jsonCal.map(m => {
return {
timestamp: new Date(m.time).getTime(),
mean: m[`${prefix}_mean`],
fac: m[`${prefix}_fac`],
dataRaw = addMissingDataPoints(dataRaw, dataStart, dataEnd, granularity)
dataCal = addMissingDataPoints(dataCal, dataStart, dataEnd, granularity)
}
})
if(dataRaw[0] && dataCal[0]) {
const dataStart = (dataRaw[0].timestamp < dataCal[0].timestamp ? dataRaw[0].timestamp : dataCal[0].timestamp)
const dataEnd = new Date(end).getTime()
for (let i = 0; i < dataRaw.length; i++) {
const r = dataRaw[i]
const c = dataCal[i]
dataRaw = addMissingDataPoints(dataRaw, dataStart, dataEnd, granularity)
dataCal = addMissingDataPoints(dataCal, dataStart, dataEnd, granularity)
}
const o = {
timestamp: r.timestamp
}
let data = []
for (let i = 0; i < dataRaw.length; i++) {
const r = dataRaw[i]
const c = dataCal[i]
o[`${prefix}_raw_mean`] = r.mean
o[`${prefix}_raw_minmax`] = r.minmax
o[`${prefix}_cal_mean`] = c.mean
if(r.mean && c.mean) {
o[`${prefix}_cal_minmax`] = [r.minmax[0] * c.fac, r.minmax[1] * c.fac]
}
const o = {
timestamp: r.timestamp
data.push(o)
}
} else {
const response = await fetch(`https://data.waag.org/api/holu/holukit/calibrated/hourly?sensor_id=${station.id}&start=${start}&end=${end}`)
const json = await response.json()
o[`${prefix}_raw_mean`] = r.mean
o[`${prefix}_raw_minmax`] = r.minmax
o[`${prefix}_cal_mean`] = c.mean
if(r.mean && c.mean) {
o[`${prefix}_cal_minmax`] = [r.minmax[0] * c.fac, r.minmax[1] * c.fac]
}
data = json.map(m => {
m.timestamp = new Date(m.time).getTime()
delete m.time
if(m[`${prefix}_mean`] === -999) m[`${prefix}_mean`] = null
return m
})
data.push(o)
if(data[0]) {
const dataStart = data[0].timestamp
const dataEnd = new Date(end).getTime()
data = addMissingDataPoints(data, dataStart, dataEnd, granularity)
}
}
return { status: "success", data }
......
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