From 88f2a7549ca1a208760fa55e708bc1f6d8414b91 Mon Sep 17 00:00:00 2001 From: Tor-Einar Skog <tor-einar.skog@nibio.no> Date: Tue, 27 Feb 2024 13:19:19 +0100 Subject: [PATCH] Add filter criteria to weather datasource --- ipmd/static/ipmd/js/ipmdlib.js | 23 ++ ipmd/templates/ipmd/saddlegallmidgeform.html | 361 +------------------ 2 files changed, 24 insertions(+), 360 deletions(-) diff --git a/ipmd/static/ipmd/js/ipmdlib.js b/ipmd/static/ipmd/js/ipmdlib.js index 3445c6d7..30859cd2 100644 --- a/ipmd/static/ipmd/js/ipmdlib.js +++ b/ipmd/static/ipmd/js/ipmdlib.js @@ -104,6 +104,29 @@ async function getWeatherDatasources() return await response.json(); } +/** + * TODO Add more filtering than just authenticationType + * @param {String} filterCriteria {"authenticationType": ["NONE", "CREDENTIALS", "BEARER_TOKEN"]} + */ +async function getFilteredWeatherDatasources(filterCriteria) +{ + let allWeatherDatasources = await getWeatherDatasources(); + let filteredWeatherDatasources = allWeatherDatasources; + let authenticationType = filterCriteria["authenticationType"]; + if(authenticationType != undefined) + { + filteredWeatherDatasources = []; + for(let i=0;i< allWeatherDatasources.length; i++) + { + if(allWeatherDatasources[i].authentication_type == authenticationType || (allWeatherDatasources[i].authentication_type == undefined && authenticationType == "NONE")) + { + filteredWeatherDatasources.push(allWeatherDatasources[i]) + } + } + } + return filteredWeatherDatasources; +} + /** * * @param {String} weatherDatasource diff --git a/ipmd/templates/ipmd/saddlegallmidgeform.html b/ipmd/templates/ipmd/saddlegallmidgeform.html index 023edf43..077d49f2 100644 --- a/ipmd/templates/ipmd/saddlegallmidgeform.html +++ b/ipmd/templates/ipmd/saddlegallmidgeform.html @@ -138,7 +138,7 @@ parameterInfo.style.display = "block"; // Pull weather data sources from web service, render lists (historic and forecast sources, some are both) - weatherDatasources = await getWeatherDatasources(); + weatherDatasources = await getFilteredWeatherDatasources({"authenticationType":"NONE"}); //console.info(weatherDatasources); weatherDatasources.sort((a, b) => { return (a.name < b.name) ? -1 : (a.name > b.name) ? 1 : 0; @@ -586,364 +586,5 @@ renderWeatherData(weatherData, document.getElementById("weatherData"), "table table-striped") } - - - // Mock result!!! Waiting for ADAS to fix CORS issue - const mockResult={ - "timeStart": "2023-06-30T22:00:00+00:00", - "timeEnd": "2023-08-10T22:00:00+00:00", - "interval": 86400, - "resultParameters": [ - "Cumulative_DayDegrees", - "StartOfEmergenceThreshold", - "FirstThreshold", - "SecondThreshold", - "ThirdThreshold" - ], - "locationResult": [ - { - "longitude": 10.62687, - "latitude": 62.10944, - "altitude": 478.0, - "data": [ - [ - 12.957083333333332, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 26.471249999999998, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 38.164583333333333, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 50.12833333333333, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 63.424166666666665, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 76.315416666666664, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 90.9525, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 106.4175, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 124.07208333333334, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 143.23041666666666, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 158.54916666666665, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 173.02458333333331, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 186.06041666666664, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 198.31124999999997, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 210.43499999999997, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 224.8820833333333, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 239.05541666666665, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 251.71874999999997, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 263.06991666666664, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 274.32391666666666, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 284.68975, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 296.90266666666668, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 309.94766666666669, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 322.764, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 334.34983333333332, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 346.98191666666668, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 359.79066666666665, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 372.52816666666666, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 386.75358333333332, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 402.21066666666667, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 416.82858333333331, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 428.63025, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 442.98983333333331, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 456.554, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 470.31691666666666, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 483.14233333333334, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 497.56275, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 508.33566666666667, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 521.79775, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 533.56191666666666, - 500.0, - 750.47, - 1023.93, - 1500.0 - ], - [ - 545.3566992753623, - 500.0, - 750.47, - 1023.93, - 1500.0 - ] - ], - "warningStatus": [ - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 4, - 4, - 4, - 4 - ], - "width": 5, - "length": 41 - } - ], - "message": "Start of cumulative emergence: 07/08/2023 .", - "messageType": 0 - }; - </script> {% endblock %} \ No newline at end of file -- GitLab