1.1 --- a/imiptools/period.py Thu Mar 26 19:15:52 2015 +0100
1.2 +++ b/imiptools/period.py Fri Mar 27 15:09:12 2015 +0100
1.3 @@ -276,11 +276,13 @@
1.4 points.sort()
1.5
1.6 for point, (starting, ending) in points:
1.7 + ending = set(ending)
1.8 + instants = ending.intersection(starting)
1.9
1.10 # Discard all active events ending at or before this start time.
1.11 # Free up the position in the active list.
1.12
1.13 - for t in ending:
1.14 + for t in ending.difference(instants):
1.15 i = active.index(t)
1.16 active[i] = None
1.17
1.18 @@ -301,6 +303,22 @@
1.19
1.20 slots.append((point, active[:]))
1.21
1.22 + # Discard events ending at the same time as they began.
1.23 +
1.24 + if instants:
1.25 + for t in instants:
1.26 + i = active.index(t)
1.27 + active[i] = None
1.28 +
1.29 + # Discard vacant positions from the end of the active list.
1.30 +
1.31 + while active and active[-1] is None:
1.32 + active.pop()
1.33 +
1.34 + # Add another entry for the time point without "instants".
1.35 +
1.36 + slots.append((point, active[:]))
1.37 +
1.38 return slots
1.39
1.40 def add_day_start_points(slots, tzid):
1.41 @@ -405,19 +423,13 @@
1.42 points = [point for point, active in slots]
1.43 spans = {}
1.44
1.45 - for point, active in slots:
1.46 + for _point, active in slots:
1.47 for t in active:
1.48 if t and len(t) >= 2:
1.49 start, end, uid, recurrenceid, summary, organiser, key = get_freebusy_details(t)
1.50
1.51 - try:
1.52 - start_slot = points.index(start)
1.53 - except ValueError:
1.54 - start_slot = 0
1.55 - try:
1.56 - end_slot = points.index(end)
1.57 - except ValueError:
1.58 - end_slot = len(slots)
1.59 + start_slot = bisect_left(points, (start,))
1.60 + end_slot = bisect_left(points, (end,))
1.61 spans[key] = end_slot - start_slot
1.62
1.63 return spans
2.1 --- a/imipweb/calendar.py Thu Mar 26 19:15:52 2015 +0100
2.2 +++ b/imipweb/calendar.py Fri Mar 27 15:09:12 2015 +0100
2.3 @@ -362,25 +362,33 @@
2.4 # Construct a list of time intervals within the day.
2.5
2.6 intervals = []
2.7 +
2.8 + # Convert each partition to a mapping from points to active
2.9 + # periods.
2.10 +
2.11 + partitioned[day] = day_points = {}
2.12 +
2.13 last = None
2.14
2.15 for point, active in day_slots:
2.16 columns = max(columns, len(active))
2.17 if last:
2.18 intervals.append((last, point))
2.19 +
2.20 + # Qualify points in the day with an extra indicator to
2.21 + # handle repeated time points due to instant events.
2.22 +
2.23 + day_points[(point, last == point and 1 or 0)] = active
2.24 +
2.25 last = point
2.26
2.27 if last:
2.28 intervals.append((last, None))
2.29 + day_points[(point, last == point and 1 or 0)] = active
2.30
2.31 if not days.has_key(day):
2.32 days[day] = set()
2.33
2.34 - # Convert each partition to a mapping from points to active
2.35 - # periods.
2.36 -
2.37 - partitioned[day] = dict(day_slots)
2.38 -
2.39 # Record the divisions or intervals within each day.
2.40
2.41 days[day].update(intervals)
2.42 @@ -538,7 +546,12 @@
2.43 intervals = list(intervals)
2.44 intervals.sort()
2.45
2.46 + last = None
2.47 +
2.48 for point, endpoint in intervals:
2.49 + indicator = point == last and 1 or 0
2.50 + last = point
2.51 +
2.52 continuation = point == get_start_of_day(point, tzid)
2.53
2.54 # Some rows contain no period details and are marked as such.
2.55 @@ -547,7 +560,7 @@
2.56 have_active_request = False
2.57
2.58 for slots, group_type in zip(groups, group_types):
2.59 - if slots and slots.get(point):
2.60 + if slots and slots.get((point, indicator)):
2.61 if group_type == "request":
2.62 have_active_request = True
2.63 else:
2.64 @@ -561,13 +574,14 @@
2.65
2.66 page.tr(class_=css)
2.67 page.th(class_="timeslot")
2.68 - self._time_point(point, endpoint)
2.69 + if indicator == 0:
2.70 + self._time_point(point, endpoint)
2.71 page.th.close()
2.72
2.73 # Obtain slots for the time point from each group.
2.74
2.75 for columns, slots, group_type in zip(group_columns, groups, group_types):
2.76 - active = slots and slots.get(point)
2.77 + active = slots and slots.get((point, indicator))
2.78
2.79 # Where no periods exist for the given time interval, generate
2.80 # an empty cell. Where a participant provides no periods at all,