From 95ded9f36678c9a7fb8e1471ada07f7781cd18f0 Mon Sep 17 00:00:00 2001 From: alilaherty Date: Wed, 25 Oct 2023 13:38:20 +1000 Subject: [PATCH] 90 minute minimum --- .../components/widgets/SuggestedTimeWidget.js | 57 +++++++++++++------ 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/ui-display/frontend-app/src/components/widgets/SuggestedTimeWidget.js b/ui-display/frontend-app/src/components/widgets/SuggestedTimeWidget.js index de998ad..d42e0cb 100644 --- a/ui-display/frontend-app/src/components/widgets/SuggestedTimeWidget.js +++ b/ui-display/frontend-app/src/components/widgets/SuggestedTimeWidget.js @@ -44,7 +44,7 @@ export default function SuggestedTimeWidget() { const interval = setInterval(()=>{ fetchData(); //fetchTime(); - },5000); + },50000); /* DEFAULT BEHAVIOUR: GET SINGLE RECOMMENDATION OF NEXT NEAREST TIME */ const fetchData = async () => { console.log('data fetched'); @@ -64,25 +64,50 @@ export default function SuggestedTimeWidget() { (Constants.DAY_POSITIONS[timeSlot.day] > Constants.DAY_POSITIONS[dayName]) || (Constants.DAY_POSITIONS[timeSlot.day] === Constants.DAY_POSITIONS[dayName] && timeSlot.slot_num > currentToTimeSlotNum())); - setSuggestedTime(dayAndTimeToDate(timeSlots[0]['day'], - timeSlots[0]['time'])); - setLoading(false); - } - }; + console.log(timeSlots); - /* - const fetchTime = async () => { - const time = await fetch("../../../time_change.txt"); - const data = time; + let recommendation = timeSlots[0]; + let recommendations = []; + let currentSlot = timeSlots[0]; + let numberChecked = 0; + //console.log("recommendation", recommendations) + + let consecutiveSlots = 0; + while (consecutiveSlots < 3) { + //console.log("day", Constants.DAY_POSITIONS[currentSlot.day]); + const nextSlot = timeSlots.filter(timeSlot => + (Constants.DAY_POSITIONS[timeSlot.day] === Constants.DAY_POSITIONS[currentSlot.day]) && (timeSlot.slot_num === currentSlot.slot_num + 1) + ); + //console.log("nextSlot", nextSlot); + if (nextSlot && nextSlot.length > 0) { + console.log("next", nextSlot); + //recommendations.push(currentSlot); + if (consecutiveSlots == 0) { + recommendation = currentSlot; + } + currentSlot = nextSlot[0]; + consecutiveSlots++; + } else { + consecutiveSlots = 0; + if (numberChecked < timeSlots.length) { + currentSlot = timeSlots[++numberChecked]; + } else { + console.log("no consecutive times found :("); + break; + } + } + } - if (data) { - const delta = data.text(); - console.log("delta", delta); - setTimeDelta(delta); - } + //console.log(recommendation); - }*/ + if (recommendation) { + setSuggestedTime(dayAndTimeToDate(recommendation['day'], + recommendation['time'])); + setLoading(false); + } + } + }; return () => clearInterval(interval); //fetchData();