Exemple #1
0
    def _getBookingsBetweenTimestamps(self, fromDate, toDate,
                                      tz = 'UTC', conferenceId = None, categoryId = None, dateFormat = None):
        bookings = []
        nBookings = 0

        date = None
        bookingsForDate = None

        for timestamp, s in self._tree.iteritems(fromDate, toDate):
            currentDate = unixTimeToDatetime(timestamp, tz).date()

            if date != currentDate:
                if date is not None and bookingsForDate:
                    bookings.append((datetime.strftime(date, dateFormat), bookingsForDate))
                    nBookings += len(bookingsForDate)
                date = currentDate
                bookingsForDate = []

            if conferenceId:
                for booking in s:
                    if booking.getConference().getId() == conferenceId:
                        bookingsForDate.append(booking)
            elif categoryId:
                cc = CategoryChecker(categoryId)
                for booking in s:
                    if cc.check(booking.getConference()):
                        bookingsForDate.append(booking)
            else:
                bookingsForDate.extend(s)

        if date is not None and bookingsForDate:
            bookings.append((datetime.strftime(date, dateFormat), bookingsForDate))
            nBookings += len(bookingsForDate)

        return bookings, nBookings
Exemple #2
0
    def _getBookingsGroupedByStartDate(self,
                                       fromTitle=None,
                                       toTitle=None,
                                       conferenceId=None,
                                       categoryId=None,
                                       tz=None,
                                       dateFormat=None):
        """
        Differs from getBookings by returning a list of bookings grouped by
        the conference start date.
        """

        if fromTitle:
            fromTitle = fromTitle.lower()
        if toTitle:
            toTitle = toTitle.lower()

        bookings = []
        nBookings = 0
        currentDate = None
        bookingsForDate = None

        for timestamp, pair in self._tree.iteritems(fromTitle, toTitle):
            ts = float(timestamp.split('_')[0])
            tsDate = unixTimeToDatetime(ts, tz).date()
            __, bset = pair  # the set of bookings associated with the event.

            if currentDate != tsDate:
                # if we're already at the next timestamp, apped what we have
                if currentDate is not None and bookingsForDate:
                    bookings.append(
                        (datetime.strftime(currentDate,
                                           dateFormat), bookingsForDate))
                    nBookings += len(bookingsForDate)
                currentDate = tsDate
                bookingsForDate = []

            # check filtering criteria
            if conferenceId:
                for booking in bset:
                    if booking.getConference().getId() == conferenceId:
                        bookingsForDate.append(booking)
            elif categoryId:
                cc = CategoryChecker(categoryId)
                for booking in bset:
                    if cc.check(booking.getConference()):
                        bookingsForDate.append(booking)
            else:
                bookingsForDate.extend(bset)

        if currentDate is not None and bookingsForDate:
            bookings.append((datetime.strftime(currentDate,
                                               dateFormat), bookingsForDate))
            nBookings += len(bookingsForDate)

        return bookings, nBookings
Exemple #3
0
    def _getBookingsGroupedByStartDate(self, fromTitle = None, toTitle = None,
                                       conferenceId = None, categoryId = None,
                                       tz = None, dateFormat = None):
        """
        Differs from getBookings by returning a list of bookings grouped by
        the conference start date.
        """

        if fromTitle:
            fromTitle = fromTitle.lower()
        if toTitle:
            toTitle = toTitle.lower()

        bookings = []
        nBookings = 0
        currentDate = None
        bookingsForDate = None

        for timestamp, pair in self._tree.iteritems(fromTitle, toTitle):
            ts = float(timestamp.split('_')[0])
            tsDate = unixTimeToDatetime(ts, tz).date()
            __, bset = pair  # the set of bookings associated with the event.

            if currentDate != tsDate:
                # if we're already at the next timestamp, apped what we have
                if currentDate is not None and bookingsForDate:
                    bookings.append((datetime.strftime(currentDate, dateFormat),
                                     bookingsForDate))
                    nBookings += len(bookingsForDate)
                currentDate = tsDate
                bookingsForDate = []

            # check filtering criteria
            if conferenceId:
                for booking in bset:
                    if booking.getConference().getId() == conferenceId:
                        bookingsForDate.append(booking)
            elif categoryId:
                cc = CategoryChecker(categoryId)
                for booking in bset:
                    if cc.check(booking.getConference()):
                        bookingsForDate.append(booking)
            else:
                bookingsForDate.extend(bset)

        if currentDate is not None and bookingsForDate:
            bookings.append((datetime.strftime(currentDate, dateFormat),
                             bookingsForDate))
            nBookings += len(bookingsForDate)

        return bookings, nBookings
Exemple #4
0
    def _getBookingsBetweenTimestamps(self,
                                      fromDate,
                                      toDate,
                                      tz='UTC',
                                      conferenceId=None,
                                      categoryId=None,
                                      dateFormat=None):
        bookings = []
        nBookings = 0

        date = None
        bookingsForDate = None

        for timestamp, s in self._tree.iteritems(fromDate, toDate):
            currentDate = unixTimeToDatetime(timestamp, tz).date()

            if date != currentDate:
                if date is not None and bookingsForDate:
                    bookings.append(
                        (datetime.strftime(date, dateFormat), bookingsForDate))
                    nBookings += len(bookingsForDate)
                date = currentDate
                bookingsForDate = []

            if conferenceId:
                for booking in s:
                    if booking.getConference().getId() == conferenceId:
                        bookingsForDate.append(booking)
            elif categoryId:
                cc = CategoryChecker(categoryId)
                for booking in s:
                    if cc.check(booking.getConference()):
                        bookingsForDate.append(booking)
            else:
                bookingsForDate.extend(s)

        if date is not None and bookingsForDate:
            bookings.append((datetime.strftime(date,
                                               dateFormat), bookingsForDate))
            nBookings += len(bookingsForDate)

        return bookings, nBookings
Exemple #5
0
 def _keyToDate(cls, key):
     if key:
         return unixTimeToDatetime(key)
     else:
         return None
Exemple #6
0
 def _keyToDate(cls, key):
     if key:
         return unixTimeToDatetime(key)
     else:
         return None