Skip to content

Commit

Permalink
Merge branch 'expo' of github.com:lucashicks1/lambda-deco3801 into expo
Browse files Browse the repository at this point in the history
  • Loading branch information
lucashicks1 committed Oct 25, 2023
2 parents bc2c999 + 83e27f5 commit 44c8643
Show file tree
Hide file tree
Showing 8 changed files with 855 additions and 501 deletions.
2 changes: 1 addition & 1 deletion ui-display/frontend-app/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ function App() {
<div className="Grass-box">
<div className="Names-box">
<h1> Timmy </h1>
<h1> Jimmy </h1>
<h1> Kimmy </h1>
<h1> Jimmy </h1>
<h1> Timmy Jr </h1>
</div>
<div className="Names-box">
Expand Down
120 changes: 88 additions & 32 deletions ui-display/frontend-app/src/components/widgets/SuggestedTimeWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,17 @@ export default function SuggestedTimeWidget() {
}

const [suggestedTime, setSuggestedTime] = useState("");
const [timeDelta, setTimeDelta] = useState(0);
const [upcomingEvent, setUpcomingEvent] = useState(null);
const [loading, setLoading] = useState(true);
const [nearEnd, setNearEnd] = useState(false);
const baseURL = 'https://localhost:8000/display/';


useEffect(() => {
const interval = setInterval(()=>{
fetchData();
//fetchTime();
},50000);
fetchEvents();
},5000);
/* DEFAULT BEHAVIOUR: GET SINGLE RECOMMENDATION OF NEXT NEAREST TIME */
const fetchData = async () => {
console.log('data fetched');
Expand All @@ -59,51 +60,91 @@ export default function SuggestedTimeWidget() {
console.log(dayName);
console.log(Constants.DAY_POSITIONS[dayName]);
console.log("today:", currentToTimeSlotNum());



const timeSlots = timeSlotsAllWeek.filter(timeSlot =>
(Constants.DAY_POSITIONS[timeSlot.day] > Constants.DAY_POSITIONS[dayName])
|| (Constants.DAY_POSITIONS[timeSlot.day] === Constants.DAY_POSITIONS[dayName]
&& timeSlot.slot_num > currentToTimeSlotNum()));
console.log(timeSlots);

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];
if (timeSlots && timeSlots.length > 0) {

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 {
console.log("no consecutive times found :(");
break;
consecutiveSlots = 0;
if (numberChecked < timeSlots.length) {
currentSlot = timeSlots[++numberChecked];
if (!currentSlot) {
recommendation = null;
setNearEnd(true);
break;
}

} else {
console.log("no consecutive times found :(");
setNearEnd(true);
break;
}
}
}

} else {
setNearEnd(true);
}

//console.log(recommendation);

if (recommendation) {
if (timeSlots && recommendation) {
setSuggestedTime(dayAndTimeToDate(recommendation['day'],
recommendation['time']));
setLoading(false);
}
}
};
const fetchEvents = async () => {
const response = await fetch("http://localhost:8000/display/family-timeslots");
const data = await response.json();
if (data && data.body) {
const timeSlotsAllWeek = Array.from(data.body);
console.log("events:", timeSlotsAllWeek);
// filter out any days already passed
// TODO what do we do when the week is nearly over?
const trueNow = new Date();
const dayName = Constants.DAYS[addSeconds(trueNow, Constants.TIME_DELTA).getDay()];

const timeSlots = timeSlotsAllWeek.filter(timeSlot =>
(Constants.DAY_POSITIONS[timeSlot.day] > Constants.DAY_POSITIONS[dayName])
|| (Constants.DAY_POSITIONS[timeSlot.day] === Constants.DAY_POSITIONS[dayName]
&& timeSlot.slot_num > currentToTimeSlotNum()));
console.log("events filtered", timeSlots);

if (timeSlots && timeSlots.length > 0) {
console.log("upcoming", timeSlots[0]);
setUpcomingEvent(timeSlots[0]);
} else {
console.log("no upcoming events");
setUpcomingEvent(null);
}

}
Expand All @@ -121,7 +162,22 @@ export default function SuggestedTimeWidget() {
<p>Oops! Check back in a sec.</p> :
<>
<h1>Suggested Time 🪩</h1>
<h3>Everybody is next free {suggestedTime}.</h3>
{nearEnd ?
<p>Oops! No more times this week suit everybody.
Maybe try again next week!
</p>
:
<>
<h3>Everybody is next free {suggestedTime}.</h3>
{upcomingEvent ?
<p> And good news! 🥳 You've got
{(upcomingEvent.data && upcomingEvent.data.length > 1) ? ` ${upcomingEvent.data} ` : " something "}
coming up {dayAndTimeToDate(upcomingEvent['day'], upcomingEvent['time'])} 💗
</p>
:
<p>Maybe pencil something in!</p>}
</>
}
</>
}
</header>
Expand Down
19 changes: 19 additions & 0 deletions ui-display/frontend-app/src/components/widgets/Widgets.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,25 @@
color: var(--darkgrey);
}

.SuggestedTime-box h3, p {
padding: 0;
margin: 0;
}
.SuggestedTime-box h3 {
padding-bottom: 0.1em;
font-size: 1em;
}

.SuggestedTime-box h1 {
margin-top: 0.2em;
font-size: 1.75em;
}

.SuggestedTime-box p {
font-size: 0.75em;
margin-bottom: 0.5em;
}

.Weather-box {
font-family: Nightingale;
font-size: 30px;
Expand Down
53 changes: 25 additions & 28 deletions vision/make_availabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,44 @@
'Timmy_Jr': [],
}
timmy_time_slots = {
'monday': [0, 1, 2, 3, 4, 5, 6, 7],
'tuesday': [0, 1, 2, 3, 4, 5, 6, 7],
'wednesday': [0, 1, 2, 3, 4, 5, 6, 7],
'thursday': [0, 1, 2, 3, 4, 5, 6, 7],
'friday': [0, 1, 2, 3, 4, 5, 6, 7],
'saturday': [0, 1, 2, 3, 4, 5, 6, 7],
'sunday': [0, 1, 2, 3, 4, 5, 6, 7],
'monday': [8, 9, 10, 11, 12, 13, 14, 15, 20, 21, 22, 23, 24, 25],
'tuesday': [8, 9, 10, 11, 12, 13, 14, 15, 20, 21, 22, 23, 24, 25, 28, 29, 30, 31, 32, 33],
'wednesday': [8, 9, 10, 11, 12, 13, 14, 15, 18],
'thursday': [8, 9, 10, 11, 12, 13, 14, 15],
'friday': [8, 9, 10, 11, 12, 13, 14, 15, 20, 21, 22, 23, 24, 25],
'saturday': [12, 13, 14, 15],
}
timmj_time_slots = {
'monday': [0, 1, 2, 3, 4, 5, 6, 7],
'tuesday': [0, 1, 2, 3, 4, 5, 6, 7],
'wednesday': [0, 1, 2, 3, 4, 5, 6, 7],
'thursday': [0, 1, 2, 3, 4, 5, 6, 7],
'friday': [0, 1, 2, 3, 4, 5, 6, 7],
'saturday': [0, 1, 2, 3, 4, 5, 6, 7],
'sunday': [0, 1, 2, 3, 4, 5, 6, 7],
'monday': [24, 25, 26, 27, 28, 29],
'wednesday': [22, 23, 24, 25, 26],
'thursday': [24, 25, 26, 27, 28, 29, 30, 31, 32, 33],
'saturday': [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33],
'sunday': [22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33],
}
jimmy_time_slots = {
'monday': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
'tuesday': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
'wednesday': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
'monday': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 16, 17, 18, 19, 20, 21, 22],
'tuesday': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 16, 17, 18, 19],
'wednesday': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 19, 20, 21, 24, 25, 26, 27, 28],
'thursday': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
'friday': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
'saturday': [0, 1, 2, 3, 4, 5, 6, 7],
'sunday': [0, 1, 2, 3, 4, 5, 6, 7],
'friday': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 15, 16, 17, 18, 19],
'saturday': [18, 19, 20, 21, 22, 23, 24, 25, 26, 27],
'sunday': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
}
kimmy_time_slots = {
'monday': [0, 1, 2, 3, 4, 5, 6, 7],
'tuesday': [0, 1, 2, 3, 4, 5, 6, 7],
'wednesday': [0, 1, 2, 3, 4, 5, 6, 7],
'thursday': [0, 1, 2, 3, 4, 5, 6, 7],
'friday': [0, 1, 2, 3, 4, 5, 6, 7],
'saturday': [0, 1, 2, 3, 4, 5, 6, 7],
'sunday': [0, 1, 2, 3, 4, 5, 6, 7],
'monday': [10, 11, 12, 13, 15, 16, 17, 18, 27, 30, 31, 32, 33],
'tuesday': [16, 24, 25, 26, 27],
'wednesday': [16, 17, 20, 21, 22, 23],
'thursday': [16, 17, 18, 19, 20, 21, 22, 23, 24],
'friday': [18, 19, 20, 21, 22, 23, 24, 25, 26, 27],
'saturday': [0, 1, 2, 3, 4, 5, 14, 15, 16],
'sunday': [16, 17, 18, 19],
}


def make_json(person):
result = []
for day in person:
for time in day:
for time in person.get(day):
result.append(
{'day': day, 'time_slot': time, 'data': '', 'colour': 'black'}
)
Expand Down
Loading

0 comments on commit 44c8643

Please sign in to comment.