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

  1. var d3 = require('d3')
  2. export function readxml(xmldoc) {
  3. let forcast = xmldoc.childNodes[0]
  4. let data = forcast.children[1]
  5. // Time
  6. let times = data.getElementsByTagName('time-layout')[0]
  7. var startTimes = []
  8. for (let time of times.getElementsByTagName('start-valid-time')) {
  9. let date = new Date(time.textContent)
  10. startTimes.push(date)
  11. }
  12. var endTimes = []
  13. for (let time of times.getElementsByTagName('end-valid-time')) {
  14. let date = new Date(time.textContent)
  15. endTimes.push(date)
  16. }
  17. // Temperature
  18. var temperatures = []
  19. for (let temp_type of data.getElementsByTagName('temperature')) {
  20. if (temp_type.attributes.type.nodeValue === 'hourly') {
  21. for (let temp of temp_type.getElementsByTagName('value')) {
  22. let degC = (parseFloat(temp.textContent) - 32) * (5.0/9.0)
  23. temperatures.push(degC)
  24. }
  25. }
  26. }
  27. // Map
  28. let nElements = startTimes.length
  29. var forcastData = []
  30. for (var i = 0; i < nElements; i++) {
  31. let midtimeScale = d3.scaleTime()
  32. .domain([0, 1])
  33. .range([startTimes[i], endTimes[i]])
  34. let midpointTime = midtimeScale(0.5)
  35. forcastData.push({
  36. 'date': midpointTime,
  37. 'temp': temperatures[i]
  38. })
  39. }
  40. return {
  41. 'startTimes': startTimes,
  42. 'endTimes': endTimes,
  43. 'temperature': forcastData
  44. }
  45. }