Weather dashboard https://natronics.org/weather/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

50 lines
1.4 KiB

var d3 = require('d3')
export function readxml(xmldoc) {
let forcast = xmldoc.childNodes[0]
let data = forcast.children[1]
// Time
let times = data.getElementsByTagName('time-layout')[0]
var startTimes = []
for (let time of times.getElementsByTagName('start-valid-time')) {
let date = new Date(time.textContent)
startTimes.push(date)
}
var endTimes = []
for (let time of times.getElementsByTagName('end-valid-time')) {
let date = new Date(time.textContent)
endTimes.push(date)
}
// Temperature
var temperatures = []
for (let temp_type of data.getElementsByTagName('temperature')) {
if (temp_type.attributes.type.nodeValue === 'hourly') {
for (let temp of temp_type.getElementsByTagName('value')) {
let degC = (parseFloat(temp.textContent) - 32) * (5.0/9.0)
temperatures.push(degC)
}
}
}
// Map
let nElements = startTimes.length
var forcastData = []
for (var i = 0; i < nElements; i++) {
let midtimeScale = d3.scaleTime()
.domain([0, 1])
.range([startTimes[i], endTimes[i]])
let midpointTime = midtimeScale(0.5)
forcastData.push({
'date': midpointTime,
'temp': temperatures[i]
})
}
return {
'startTimes': startTimes,
'endTimes': endTimes,
'temperature': forcastData
}
}