Skip to content

Instantly share code, notes, and snippets.

@skatenerd
Last active January 29, 2021 14:47
Show Gist options
  • Save skatenerd/5605effdeaecd806fc431102d814a76c to your computer and use it in GitHub Desktop.
Save skatenerd/5605effdeaecd806fc431102d814a76c to your computer and use it in GitHub Desktop.
whenisgood pairs
JSON.stringify(Object.keys(respondents).map(function(k) { return respondents[k]}))
import json
import functools
import itertools
import datetime
def format(ts):
return (ts + datetime.timedelta(hours=5)).strftime("%a at %I:%M%p")
def get_respondents():
def postprocess(r):
return {
'name': r['name'],
'available_times': [datetime.datetime.fromtimestamp(int(x)/1000) for x in r.get('myCanDos', [])]
}
with open('respondents.json') as f:
raw = json.load(f)
return [postprocess(x) for x in raw]
def all_possible_times(respondents):
list_of_lists = [r['available_times'] for r in respondents]
return set(itertools.chain(*list_of_lists))
def pairs(items):
for x in items:
for y in items:
if y > x:
yield(x,y)
def winners_for_time(respondents, timestamp):
return set(x['name'] for x in respondents if timestamp in x['available_times'])
def all_unique_attendees(per_meeting):
return functools.reduce(lambda x,y: x.union(y), per_meeting)
def score_attendance(times_to_attendees):
attendees_for_each_meeting = times_to_attendees.values()
people_who_ever_get_to_come = all_unique_attendees(attendees_for_each_meeting)
total_attendances = sum(len(x) for x in attendees_for_each_meeting)
return (len(people_who_ever_get_to_come), total_attendances)
def go():
respondents = get_respondents()
all_names = set(x['name'] for x in respondents)
results = [dict((time, winners_for_time(respondents, time)) for time in pair) for pair in pairs(all_possible_times(respondents))]
by_score = sorted(results, key=lambda x: score_attendance(x), reverse=True)
#with_missing = [(time, all_names - all_unique_attendees(attendees_per_meeting)) for (time, attendees_per_meeting) in by_score]
for times_to_attendees in by_score[:20]:
first, second = times_to_attendees.keys()
print(", AND ".join(format(x) for x in times_to_attendees))
print("MISSING:")
for time, attendees in times_to_attendees.items():
print(f" MISSES: {format(time)}: {all_names - attendees}")
print(f" MISSES: ALL: {all_names - all_unique_attendees(times_to_attendees.values())}")
print("")
print("")
go()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment