Commit 0c917fd4 authored by alain's avatar alain 🐙
Browse files

amsterdam sounds settings

parent b1f86e73
import cidata from "./sources/cidata"
import asokit from "./sources/asokit"
const colors = [
"#2FB6BC",
"#DA0812"
]
export const initialLayers = ["db"]
export const dataGroups = [
{
title: "layers",
parameters: {
"db": {
id: "db",
label: "geluidsniveau (dB)",
type: "StationLayer",
sources: [ cidata, asokit ],
tooltip: "",
more: "",
units: [
{
id: "db",
label: " dB",
range: [0, 120],
ticks: [0, 60, 120],
legend: {
0: { label: "", color: colors[0] },
80: { label: "", color: colors[0] },
120: { label: "", color: colors[1] },
}
}
]
}
}
}
]
This diff is collapsed.
import { roundBy } from "../../data-on-a-map-app/src/util/math"
import { addMissingHours } from "../../data-on-a-map-app/src/util/data"
export default {
name: "asokit",
sides: 6,
angle: 0,
factor: 1,
all: async function getAll(parameter) {
try {
const allResponse = await fetch(`https://data.waag.org/api/asounds/asokit/stations`)
const all = await allResponse.json()
const latestResponse = await fetch(`https://data.waag.org/api/asounds/asokit/recent`)
const latest = await latestResponse.json()
let offlineSensors = []
let unregisteredSensors = []
const data = all.map(sensor => {
let sensorData = latest.find(o => o.id === sensor.id)
const sensorDataReturn = {
id: sensor.id,
name: sensor.id,
source: "asokit",
coordinates: sensor.coordinates.reverse(),
mean: null
}
if(sensorData) {
const dataAge = (new Date() - new Date(sensorData.time))
//console.log(sensor.id, sensorData.timestamp, `${roundBy(dataAge / 1000 / 60 / 60, 2)} uur`)
// 3 hours
if(dataAge < 10800000) {
sensorDataReturn.mean = sensorData.db_avg
} else {
sensorDataReturn.name = sensorDataReturn.name + " (geen recente data)"
}
} else {
offlineSensors.push(sensor.id)
sensorDataReturn.name = sensorDataReturn.name + " (offline)"
}
return sensorDataReturn
})
latest.forEach(sensor => {
const dataAge = (new Date() - new Date(sensor.timestamp))
//console.log(sensor.id, dataAge, `${roundBy(dataAge / 1000 / 60 / 60, 2)} uur`)
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(', '))
return data
} catch (error) {
console.log(error)
}
},
detail: async function getDetail(station, parameter, start, end) {
try {
const stationMeta = {
type: station.id,
name: station.name,
description: ""
}
const response = await fetch(`https://data.waag.org/api/asounds/asokit?granularity=hourly&sensor_id=${station.id}&start=${start}&end=${end}`)
const responseData = await response.json()
const conformedData = responseData.map(d => {
d.timestamp = new Date(d.time).getTime()
delete d.time
d.value = d.db_avg
delete d.db_avg
d.minmax = [d.db_min, d.db_max]
delete d.db_min
delete d.db_max
return d
})
const data = addMissingHours(conformedData)
return { stationMeta, data }
} catch (error) {
console.log(error)
}
}
}
\ No newline at end of file
import { roundBy } from "../../data-on-a-map-app/src/util/math"
import { addMissingHours } from "../../data-on-a-map-app/src/util/data"
export default {
name: "cidata",
sides: 6,
angle: 0,
factor: 1,
all: async function getAll(parameter) {
try {
const allResponse = await fetch(`https://data.waag.org/api/asounds/cidata/stations`)
const all = await allResponse.json()
const latestResponse = await fetch(`https://data.waag.org/api/asounds/cidata/recent`)
const latest = await latestResponse.json()
let offlineSensors = []
let unregisteredSensors = []
const data = all.map(sensor => {
let sensorData = latest.find(o => o.id === sensor.id)
const sensorDataReturn = {
id: sensor.id,
name: sensor.id,
source: "cidata",
coordinates: sensor.coordinates.reverse(),
mean: null
}
if(sensorData) {
const dataAge = (new Date() - new Date(sensorData.time))
//console.log(sensor.id, sensorData.timestamp, `${roundBy(dataAge / 1000 / 60 / 60, 2)} uur`)
// 3 hours
if(dataAge < 10800000) {
sensorDataReturn.mean = sensorData.db_avg
} else {
sensorDataReturn.name = sensorDataReturn.name + " (geen recente data)"
}
} else {
offlineSensors.push(sensor.id)
sensorDataReturn.name = sensorDataReturn.name + " (offline)"
}
return sensorDataReturn
})
latest.forEach(sensor => {
const dataAge = (new Date() - new Date(sensor.timestamp))
//console.log(sensor.id, dataAge, `${roundBy(dataAge / 1000 / 60 / 60, 2)} uur`)
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(', '))
return data
} catch (error) {
console.log(error)
}
},
detail: async function getDetail(station, parameter, start, end) {
try {
const stationMeta = {
type: station.id,
name: station.name,
description: ""
}
const response = await fetch(`https://data.waag.org/api/asounds/cidata?granularity=hourly&sensor_id=${station.id}&start=${start}&end=${end}`)
const responseData = await response.json()
const conformedData = responseData.map(d => {
d.timestamp = new Date(d.time).getTime()
delete d.time
d.value = d.db_avg
delete d.db_avg
d.minmax = [d.db_min, d.db_max]
delete d.db_min
delete d.db_max
return d
})
const data = addMissingHours(conformedData)
return { stationMeta, data }
} catch (error) {
console.log(error)
}
}
}
\ No newline at end of file
:root {
--color-loading: #2FB6BC;
--color-true: #2FB6BC;
--heading-weight: 500;
}
body {
font-family: "Maax", sans-serif;
......
export const texts = {
about: {
title: "over deze kaart",
body: "<p>Deze kaart visualiseert data afkomstig van ...</p>"
},
pilotLocations: "Pilot-locaties",
loading: "Bezig met laden...",
loadingError: "Laden mislukt...",
loadingRetry: "Probeer opnieuw",
lastMean: "laatste uurgemiddelde",
lastPeak: "piekwaarde laatste uur",
mean: "gemiddelde",
peak: "piekwaarde",
downloadData: "download data",
startDate: "startdatum",
endDate: "einddatum",
downloadCsv: "download csv",
downloadInfo: "<small><a class='more' href='https://amsterdamsounds.waag.org/data-downloaden/' target='_blank' rel='noopener noreferrer'>meer info over data downloaden en de API</a></small>",
}
data-on-a-map-app @ 71c3de83
Subproject commit 96f16bf26d3d979a319bc5caab394aed04842bad
Subproject commit 71c3de83f1e7a1eebb187a52c3ed46911bbfd0c0
Supports Markdown
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