double-booking with recurrent events

Bug #117817 reported by sainrat
2
Affects Status Importance Assigned to Milestone
SchoolTool
Confirmed
Wishlist
Justas Sadzevičius

Bug Description

In 0.11.4, If you create a recurring event and book a resource, double booking is detected only on the first occurence of the event not on later occurences. Tested only on weekly events but I believe it's the same everywhere.
I believe the error is in schoolbell/app/browser/cal.py in GetConflictingEvents.

Revision history for this message
sainrat (sainrat) wrote :

    def getConflictingEvents(self, resource):
        """Return a list of events that would conflict when booking resource."""
        events = []
        if not canAccess(resource.calendar, "expand"):
            return events
           if self.context.recurrence:
          totest = []
          for d in self.context.recurrence.apply(self.context):
              totest.append(datetime(d.year, d.month, d.day, self.context.dtstart.hour, self.context.dtstart.minute, self.context.dtstart.second, self.context.dtstart.microsecond, self.context.dtstart.tzinfo))
        else:
          totest = [self.context.dtstart]
        for d in totest:
          for event in resource.calendar.expand(d,d + self.context.duration):
            if event != self.context:
                  events.append(EventForBookingDisplay(event))
        return events

Changed in schooltool:
assignee: nobody → ignas
Revision history for this message
Ignas Mikalajūnas (ignas) wrote :

Yes we only test for intersection with first event in the chain. The heuristics could be improved i guess, but implementing a system that would find whether there is a possible intersection between 2 infinitely recurring events is very difficult and not very feasible so i am marking this as a "Wishlist".

If you want to you can try and come up with some kind of clever algorithm, i will gladly accept patches that fix this problem.

As for your current code:

    def getConflictingEvents(self, resource):
        """Return a list of events that would conflict when booking resource."""
        events = []
        if not canAccess(resource.calendar, "expand"):
            return events
        if self.context.recurrence:
          totest = []
          # this loop is infinite when you have an infinite recurrence rule
          for d in self.context.recurrence.apply(self.context):
              totest.append(datetime(d.year, d.month, d.day, self.context.dtstart.hour, self.context.dtstart.minute, self.context.dtstart.second, self.context.dtstart.microsecond, self.context.dtstart.tzinfo))
        else:
          totest = [self.context.dtstart]
        for d in totest:
          # expanding each of the events let's say 300 times (because we have a daily recurring event for a year)
          for event in resource.calendar.expand(d,d + self.context.duration):
            # for every one of like 100 events in the resource calendar
            # and we show at least 10 resources
            # i am afraid this would be too slow :(
            if event != self.context:
                  events.append(EventForBookingDisplay(event))
        return events

Changed in schooltool:
importance: Undecided → Wishlist
status: Unconfirmed → Confirmed
tags: added: calendar resources
Changed in schooltool:
assignee: Ignas Mikalajūnas (ignas) → Justas Sadzevičius (justas-pov)
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.