From 896e6cbaa15fb5fe46697839f340332fe46e10dc Mon Sep 17 00:00:00 2001 From: Daniel Bosk Date: Tue, 13 Aug 2024 17:09:50 +0200 Subject: [PATCH 1/2] Adds detection script for double bookings --- src/nytid/cli/init.nw | 87 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 84 insertions(+), 3 deletions(-) diff --git a/src/nytid/cli/init.nw b/src/nytid/cli/init.nw index 44eff31..0541c20 100644 --- a/src/nytid/cli/init.nw +++ b/src/nytid/cli/init.nw @@ -1341,9 +1341,90 @@ make_regex() { } @ -% courses Manage courses -% mine Manage my courses -% registry Manage course registers +\subsection{Detecting double bookings} + +Sometimes the TAs book themselves for two events at the same time but in +different courses. +This is easily done, but really bad. +We'll now add a small script to detect this and notify the concerned TA. +We can run this check daily. + +The idea is this: +We check the TA's schedule and look for the same start time occurring more than +once. +Then we notify the TA about these times. +<>= +### Detect double booking ### + +<> + +for user in $(nytid hr users ""); do + <> + <> + if <<[[schedule]] has double bookings>>; then + <> \ + | notify_doublebooking ${user} + fi +done +@ + +We need the schedule for [[user]]. +We want to look ahead, so we change the end date to one year ahead instead of +one week ahead (the default). +Since we don't give any course, we get [[user]]'s schedule for all courses that +we manage (in the [[mine]] register). +<>= +schedule=$(nytid schedule show --user ${user} \ + --end $(date +%Y-%m-%d -d "next year")) +@ + +To test if a schedule has double bookings, we can check for the same start time +(first column) occurring in more than once line. +We must also remove the empty lines that will be part of the output. +<>= +doublebooked=$(echo "${schedule}" | cut -f 1 | sort | uniq -d | grep -v "^$") +@ + +To check if we got a match, we check that the [[doublebooked]] contains more +than one character. +The reason for this test is that, if we don't have any match, we'll still get a +newline character. +<<[[schedule]] has double bookings>>= +[[ $(echo "${doublebooked}" | wc -c) -gt 1 ]] +@ + +To extract the double booked events, not just the times, we can grep for those +times. +<>= +echo "${schedule}" | grep -f <(echo "${doublebooked}") +@ + +The function~[[notify_doublebooking]] simply sends an email to [[user]] with +the times that are double booked. +The username (from which the mail is constructed) is the only argument and the +double booked events are read from standard input. +<>= +notify_doublebooking() { + user="$1" + events=$(cat) + echo " +<> +" | mutt -s "dubbelbokningar i arbetsschemat" ${user}@kth.se +} +@ + +The message is simply a short message and then ending with the double booked +events. +<>= +Hej, hej! + +Det ser ut som att du har dubbelbokat dig i ditt schema. Se listan nedan och +åtgärda så snart som möjligt. + + Daniel + +${events} +@ \section{Future usage: design plans} From 06805720ec0a9b758475b4ea549adf3f26458c8e Mon Sep 17 00:00:00 2001 From: Daniel Bosk Date: Tue, 13 Aug 2024 18:58:00 +0200 Subject: [PATCH 2/2] Improves double booking message --- src/nytid/cli/init.nw | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/nytid/cli/init.nw b/src/nytid/cli/init.nw index 0541c20..6a6a341 100644 --- a/src/nytid/cli/init.nw +++ b/src/nytid/cli/init.nw @@ -1419,7 +1419,8 @@ events. Hej, hej! Det ser ut som att du har dubbelbokat dig i ditt schema. Se listan nedan och -åtgärda så snart som möjligt. +åtgärda så snart som möjligt: boka av dig från det pass ligger bäst till med +antal assar. Daniel