def create_conference(schedule: Schedule): conference = schedule.conference() input = { 'conference': { 'acronym': conference['acronym'], 'title': conference['title'], 'startDate': conference['start'], 'endDate': conference['end'], 'daysUsingId': { 'create': [{ 'index': day['index'], 'startDate': day['day_start'], 'endDate': day['day_end'] } for day in schedule.days()] }, 'roomsUsingId': { 'create': [{ 'name': room, } for room in schedule.rooms()] } } } #print(json.dumps(input, indent=2)) try: result = client.execute(gql(''' mutation createConferenceAndDaysAndRooms($input: CreateConferenceInput!) { createConference(input: $input) { conference { id rooms { nodes { guid name } } } } } '''), variable_values={'input': input}) return result['createConference'] except TransportQueryError as e: # raise exception, error is not 'conference already exists' if 'duplicate key value violates unique constraint "conferences_acronym_key"' != e.errors[ 0]['message']: raise e # conference already exists, so try to get required infos result = client.execute( gql(''' query getConferenceAndRooms($acronym: String!) { conference: conferenceByAcronym(acronym: $acronym) { id rooms { nodes { guid name } } } } '''), variable_values={'acronym': conference['acronym']}) return result
def calculateSchedule(globalDays: [Day], tasks: [Task], currentSchedule: Schedule, start: arrow.Arrow, debug=False) -> Schedule: currentTime = util.smoothCurrentArrow() if start < currentTime: raise Exception("Cannot calculate a schedule for the past") days = currentSchedule.days() oldDays = [day.copy() for day in days if day.date <= start.date() ] # Contains all days PRIOR to start date (last is popped off) oldTimeSlots = [] if oldDays: # On initial creation, there are no old days lastDay = oldDays.pop( ) # This day is changed after the current timeslot and kept the same before. splitTime = Time(start.hour, start.minute) for ts in lastDay.timeSlots: if ts.endTime > splitTime and ts.startTime < splitTime: # Update start time to be the end of the current timeslot # Update Arrow object only if it isn't before the smoothCurrentArrow() splitArrow = arrow.Arrow(start.year, start.month, start.day, hour=ts.endTime.hours, minute=ts.endTime.minutes) if splitArrow >= currentTime: start = splitArrow splitTime = Time(start.hour, start.minute) if ts.startTime < splitTime and ts.taskOrAppointment is not None: oldTimeSlots.append(ts) startIndex = None for i, day in enumerate(globalDays): if day.date == start.date(): startIndex = i break else: raise Exception("Error in schedule_alg 555255GGG") newDays = [day.copy() for day in globalDays[startIndex:]] # Remove TimeSlots prior to start firstNewDay = newDays[0] oldTimeSlotsToRemove = [] for ts in firstNewDay.timeSlots: if ts.startTime < splitTime: oldTimeSlotsToRemove.append(ts) for otstr in oldTimeSlotsToRemove: firstNewDay.timeSlots.remove(otstr) for oldTimeSlot in oldTimeSlots: firstNewDay.addTimeSlot(oldTimeSlot) lastWorkConfirmed = currentSchedule.lastWorkConfirmed if lastWorkConfirmed is None: lastWorkConfirmed = start.clone() # Creates a clean copy of the tasks and days, so that no evil mutation occurs newDays = sorted(newDays, key=lambda d: d.date) tmpTasks = sorted([task.copy() for task in tasks], key=lambda t: t.deadline) if isSolvable(tasks, newDays, start, useMinimum=False): happySchedule = calculateHappySchedule( tmpTasks, newDays, lastWorkConfirmed, start, debug=debug ) # Adds the history (previous schedule) to the newly calculated schedule happySchedule.addHistory(oldDays) return happySchedule elif isSolvable(tasks, newDays, start, useMinimum=True): riskySchedule = calculateSadSchedule(tmpTasks, newDays, lastWorkConfirmed, start, debug=debug) riskySchedule.addHistory(oldDays) return riskySchedule #return calculateRiskySchedule(tmpTasks, newDays, created=start) else: sadSchedule = calculateSadSchedule(tmpTasks, newDays, lastWorkConfirmed, start, debug=debug) sadSchedule.addHistory(oldDays) return sadSchedule