Ejemplo n.º 1
0
    def post(self):
        # array of time strings: "08:00 AM"
        bannedTimes = json.loads(self.request.get('bannedTimes'))
        # array of all bannedDays checkboxes (booleans)
        bannedDays = json.loads(self.request.get('bannedDays'))

        badIvals = []
        # each 2 time strings corresponds to 5 bannedDays checkboxes
        for dayBools, times in zip(misc.iterGroups(bannedDays, 5), misc.iterGroups(bannedTimes, 2)):
            badIvals += parseJSInterval(times, dayBools)

        subCodes = json.loads(self.request.get('subCodes'))
        nums = json.loads(self.request.get('nums'))
        curCRNs = json.loads(self.request.get('curCRNs'))

        classes = [t + (year, season) for t in zip(subCodes, nums)]

        try:
            clsToSections = courses.planSchedule(classes, badIvals, curCRNs)
        except:
            self.response.out.write(json.dumps({}))
        else:
            for cls, sections in clsToSections.items():
                clsToSections[cls[0] + ' ' + str(cls[1])] = sections
                del clsToSections[cls]

                for sec in sections:
                    sec['Intervals'] = [courses.reprInterval(i) for i in sec['Intervals']]

            self.response.out.write(json.dumps(clsToSections))
Ejemplo n.º 2
0
def strToIntervals(s):
    """
    Given a string of days and time intervals in the following format, return a
    list of 5-tuples: (day index, start hour, start min, end hour, end min).

    >>> strToIntervals('MTW 10 10:50 11:00 11:50')
    [(0, 10, 0, 10, 50), (0, 11, 0, 11, 50), (1, 10, 0, 10, 50), (1, 11, 0, 11, 50), (2, 10, 0, 10, 50), (2, 11, 0, 11, 50)]
    """

    def getTimeTup(s):
        return tuple(int(t) for t in s.split(":")) if ":" in s else (int(s), 0)

    parts = s.lower().split()
    days = parts[0]
    timeIntervals = misc.iterGroups(parts[1:], 2)

    ivals = []
    for day, (startTime, endTime) in itertools.product(days, timeIntervals):
        ivals.append((DAYS.index(day.lower()),) + getTimeTup(startTime) + getTimeTup(endTime))
    return ivals