Created
August 29, 2024 02:27
-
-
Save Kenny2github/b92b9fb588f8a05b314417db00cf6571 to your computer and use it in GitHub Desktop.
Find out the timeslot of a when2meet that maximizes the number of stakeholder groups represented.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Find out the timeslot of a when2meet that maximizes | |
* the number of stakeholder groups represented. | |
* | |
* Usage: | |
* 1. Open the when2meet to see the names of those | |
* that have filled it out. | |
* 2. Change the values below to suit your situation. | |
* 3. Open developer tools on your browser (search up | |
* how to do this) and navigate to its console. | |
* 4. Copy and paste the whole script (with your modifications) | |
* into the console and press Enter/Return. | |
* 5. The output will be the times that begin the best timeslots. | |
*/ | |
(() => { | |
/** | |
* Replace 2023-07-15 with the earliest day | |
* the meeting can be on, in YYYY-MM-DD format. | |
*/ | |
const EARLIEST_DAY = '2023-07-15'; | |
/** | |
* Replace the dates below with dates on which | |
* the meeting cannot be scheduled, in the same format. | |
*/ | |
const DISABLED_DAYS = [ | |
'2023-07-16', | |
'2023-07-17', | |
]; | |
/** | |
* Replace the names below with the following format: | |
* ['GROUP', ['MEMBER1', 'MEMBER2', ...]], | |
* where GROUP is the name of each stakeholder group | |
* and MEMBERn are the names of the members of the group, | |
* EXACTLY AS THEY ARE WRITTEN IN THE WHEN2MEET. | |
*/ | |
const GROUPS = new Map([ | |
['AAB', ['Name 1', 'Name 2', 'Name 3', 'Name 4', 'Name 5', 'Name 6', 'Name 7']], | |
['Admissions', ['Name']], | |
['IDEA', ['Name 1', 'Name 2', 'Name 3', 'Name 4', 'Name 5', 'Name 6']], | |
['TMRC', ['Name 1', 'Name 2']], | |
['SAC', ['Name 1', 'Name 2']], | |
['UAC', ['Name 1', 'Name 2', 'Name 3', 'Name 4']], | |
['UCC', ['Name 1', 'Name 2', 'Name 3']], | |
]); | |
/** | |
* If needed, set this to the number of members of each group that | |
* must be present for the group to be considered represented. | |
*/ | |
const MIN_MEMBERS = 1; | |
// The rest is magic! :D | |
const tzE = document.getElementById("ParticipantTimeZone"); | |
const timezone = tzE[tzE.selectedIndex].value; | |
const IDMap = new Map(PeopleIDs.map((id, i) => [id, PeopleNames[i].trim()])); | |
let maxRepresented = 0, bestSlots = []; | |
for (let slot = 0; slot < TimeOfSlot.length; ++slot) { | |
const date = moment.tz(new Date(TimeOfSlot[slot] * 1000), timezone); | |
// skip dates that are too early | |
if (date.format('YYYY-MM-DD') < EARLIEST_DAY) continue; | |
// skip dates that are not allowed | |
if (DISABLED_DAYS.includes(date.format('YYYY-MM-DD'))) continue; | |
const groups = [...GROUPS.entries()] | |
.map(([name, members]) => ( | |
AvailableAtSlot[slot] | |
.map(id => IDMap.get(id)) | |
.filter(member => members.includes(member)) | |
.length | |
>= MIN_MEMBERS | |
) ? name : null) | |
.filter(group => group); | |
const represented = groups.length; | |
if (represented > maxRepresented) { | |
maxRepresented = represented; | |
bestSlots = []; // pushed in next if-clause | |
} | |
if (represented >= maxRepresented) { | |
bestSlots.push(`${date.format('YYYY-MM-DD HH:mm')} - ${groups.join(', ')}`); | |
} | |
} | |
console.log(bestSlots.join('\n')); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment