From 27ee26c96d6b0358a352ab47d9654ab71c6aa280 Mon Sep 17 00:00:00 2001 From: Reinder Kraaij <kraaij@astron.nl> Date: Thu, 16 Nov 2023 00:05:32 +0100 Subject: [PATCH] It's the sunsetting for the world --- .../Timeline/helpers/week.view.helper.js | 25 ++++++++++++------- .../tmss_webapp/src/services/util.service.js | 17 ++++++------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/SAS/TMSS/frontend/tmss_webapp/src/routes/Timeline/helpers/week.view.helper.js b/SAS/TMSS/frontend/tmss_webapp/src/routes/Timeline/helpers/week.view.helper.js index fc3a1eb3826..44a0f50b48b 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/routes/Timeline/helpers/week.view.helper.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/routes/Timeline/helpers/week.view.helper.js @@ -253,20 +253,27 @@ function getSunTimingItem(groupId, groupkey, idPrefix, color, startTime, sunTime export async function getSunTimingItems(startTime, groups, groupkey) { + + let uniqueStations = [...new Set(groups.map(group => group.designatedStation))]; // get all unique Station names. + let stringifiedUniqueStations = uniqueStations.join(","); + let uniqueDates = [...new Set(groups.map(group => moment(group.date).format("YYYY-MM-DD")))]; // get all unique Station dates. + let stringifiedUniqueDates = uniqueDates.join(","); + + + const allstationtimings = await UtilService.getSunTimings(stringifiedUniqueDates,stringifiedUniqueStations); + const sunTimingItems = [] for (const group of groups) { - - const groupDay = moment(group.date); - - const timings = await UtilService.getSunTimings(groupDay.format("YYYY-MM-DD")); - const sunriseStart = moment.utc(timings.sun_rise.start); - const sunriseEnd = moment.utc(timings.sun_rise.end); - const sunsetStart = moment.utc(timings.sun_set.start); - const sunsetEnd = moment.utc(timings.sun_set.end); + const groupDaymoment = groupDay.format("YYYY-MM-DD"); + let timings = allstationtimings?.[group.designatedStation || "CS002"]; + let dateindex = uniqueDates.indexOf(groupDaymoment); + const sunriseStart = moment.utc(timings.sunrise[dateindex].start); + const sunriseEnd = moment.utc(timings.sunrise[dateindex].end); + const sunsetStart = moment.utc(timings.sunset[dateindex].start); + const sunsetEnd = moment.utc(timings.sunset[dateindex].end); const startOfDay = startTime.clone().startOf('day') const endOfDay = startTime.clone().endOf('day') - const nightItemBeforeSunrise = getSunTimingItem(group.id, groupkey, "bef-sunrise", "grey", startOfDay, startOfDay, sunriseStart) const sunriseItem = getSunTimingItem(group.id, groupkey, "sunrise", "#FFF176", startTime, sunriseStart, sunriseEnd) const sunsetItem = getSunTimingItem(group.id, groupkey, "sunset", "#FFB74D", startTime, sunsetStart, sunsetEnd) diff --git a/SAS/TMSS/frontend/tmss_webapp/src/services/util.service.js b/SAS/TMSS/frontend/tmss_webapp/src/services/util.service.js index 03e7c3ef9fc..a56c8b60a6d 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/services/util.service.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/services/util.service.js @@ -59,11 +59,11 @@ const UtilService = { } }, /** Function to fetch sun timings from the backend for single station. */ - getSunTimings: async (timestamp, station) => { + getSunTimings: async (timestamp, stations) => { try { - station = station ? station : "CS002"; - let stationTimestamp = (station ? `${station}-` : "") + timestamp; - let localSunTimeMap = localStorage.getItem('SUN_TIME_MAP'); + stations = stations || "CS002"; + let stationTimestamp = (stations ? `${stations}-` : "") + timestamp; + let localSunTimeMap = localStorage.getItem('SUN_TIME_MAP_V3'); if (localSunTimeMap) { localSunTimeMap = JSON.parse(localSunTimeMap); if (localSunTimeMap[stationTimestamp]) { @@ -72,12 +72,11 @@ const UtilService = { } else { localSunTimeMap = {}; } - const url = `/api/util/sun_rise_and_set?stations=${station ? station : 'CS002'}×tamps=${timestamp}`; + const url = `/api/util/sun_rise_and_set?stations=${stations}×tamps=${timestamp}`; const stationSunTimings = (await axios.get(url)).data; - let sunTimings = { sun_rise: stationSunTimings[station]['sunrise'][0], sun_set: stationSunTimings[station]['sunset'][0] }; - localSunTimeMap[stationTimestamp] = sunTimings; - localStorage.setItem('SUN_TIME_MAP', JSON.stringify(localSunTimeMap)); - return sunTimings; + localSunTimeMap[stationTimestamp] = stationSunTimings; + localStorage.setItem('SUN_TIME_MAP_V3', JSON.stringify(localSunTimeMap)); + return stationSunTimings; } catch (error) { console.error(error); return null; -- GitLab