# HG changeset patch # User Paul Boddie # Date 1427474105 -3600 # Node ID 33dfed39e49621ad0d125a9d97b8cd1a6e489d30 # Parent 3c8e6e1fe1388b41b68817f2df1562cfb75729d8 Introduced repeated time points at the start of the slot definition process, exposing original and repeated points as an indicator in the different period functions. diff -r 3c8e6e1fe138 -r 33dfed39e496 imiptools/period.py --- a/imiptools/period.py Fri Mar 27 17:28:50 2015 +0100 +++ b/imiptools/period.py Fri Mar 27 17:35:05 2015 +0100 @@ -259,14 +259,20 @@ return scale +POINT, REPEATED = 0, 1 + def get_slots(scale): """ Return an ordered list of time slots from the given 'scale'. - Each slot is a tuple containing a point in time for the start of the slot, - together with a list of parallel event tuples, each tuple containing the - original details of an event. + Each slot is a tuple containing details of a point in time for the start of + the slot, together with a list of parallel event tuples, each tuple + containing the original details of an event. + + Each point in time is described as a tuple containing the actual time point + plus an indicator (0 as POINT or 1 as REPEATED), with REPEATED being used to + indicate repeated points used for the end of "instant" events. """ slots = [] @@ -301,7 +307,9 @@ while active and active[-1] is None: active.pop() - slots.append((point, active[:])) + # Add an entry for the time point before "instants". + + slots.append(((point, POINT), active[:])) # Discard events ending at the same time as they began. @@ -315,9 +323,9 @@ while active and active[-1] is None: active.pop() - # Add another entry for the time point without "instants". + # Add another entry for the time point after "instants". - slots.append((point, active[:])) + slots.append(((point, REPEATED), active[:])) return slots @@ -333,7 +341,7 @@ current_date = None previously_active = [] - for point, active in slots: + for (point, indicator), active in slots: start_of_day = get_start_of_day(point, tzid) this_date = point.date() @@ -347,7 +355,7 @@ if current_date: current_date += timedelta(1) while current_date < this_date: - new_slots.append((get_start_of_day(current_date, tzid), previously_active)) + new_slots.append(((get_start_of_day(current_date, tzid), POINT), previously_active)) current_date += timedelta(1) else: current_date = this_date @@ -355,7 +363,7 @@ # Add any continuing periods. if point != start_of_day: - new_slots.append((start_of_day, previously_active)) + new_slots.append(((start_of_day, POINT), previously_active)) # Add the currently active periods at this point in time. @@ -375,7 +383,7 @@ new_slots = [] for point in points: - i = bisect_left(slots, (point,)) + i = bisect_left(slots, (point,)) # slots is [(point, active)...] if i < len(slots) and slots[i][0] == point: continue @@ -392,11 +400,11 @@ d = {} - for point, value in slots: + for (point, indicator), value in slots: day = point.date() if not d.has_key(day): d[day] = [] - d[day].append((point, value)) + d[day].append(((point, indicator), value)) return d @@ -412,7 +420,7 @@ if last_day: empty_day = last_day + timedelta(1) while empty_day < day: - days[empty_day] = [(get_start_of_day(empty_day, tzid), None)] + days[empty_day] = [((get_start_of_day(empty_day, tzid), POINT), None)] empty_day += timedelta(1) last_day = day @@ -420,7 +428,7 @@ "Inspect the given 'slots', returning a mapping of event uids to spans." - points = [point for point, active in slots] + all_point_details = [point_details for point_details, active in slots] spans = {} for _point, active in slots: @@ -428,8 +436,8 @@ if t and len(t) >= 2: start, end, uid, recurrenceid, summary, organiser, key = get_freebusy_details(t) - start_slot = bisect_left(points, (start,)) - end_slot = bisect_left(points, (end,)) + start_slot = bisect_left(all_point_details, (start,)) + end_slot = bisect_left(all_point_details, (end,)) spans[key] = end_slot - start_slot return spans diff -r 3c8e6e1fe138 -r 33dfed39e496 imipweb/calendar.py --- a/imipweb/calendar.py Fri Mar 27 17:28:50 2015 +0100 +++ b/imipweb/calendar.py Fri Mar 27 17:35:05 2015 +0100 @@ -27,7 +27,8 @@ to_timezone from imiptools.period import add_day_start_points, add_empty_days, add_slots, \ convert_periods, get_freebusy_details, \ - get_scale, get_slots, get_spans, partition_by_day + get_scale, get_slots, get_spans, partition_by_day, \ + POINT from imipweb.resource import Resource class CalendarPage(Resource): @@ -334,7 +335,7 @@ # Record the slots and all time points employed. groups.append(slots) - all_points.update([point for point, active in slots]) + all_points.update([point_details for point_details, active in slots]) # Partition the groups into days. @@ -370,18 +371,15 @@ last = None - for point, active in day_slots: + for point_details, active in day_slots: + point, indicator = point_details columns = max(columns, len(active)) - - # Qualify points in the day with an extra indicator to - # handle repeated time points due to instant events. - - day_points[(point, last == point and 1 or 0)] = active + day_points[point_details] = active if last: intervals.append((last, point)) - last = point + last = point_details if last: intervals.append((last, None)) @@ -548,10 +546,7 @@ last = None - for point, endpoint in intervals: - indicator = point == last and 1 or 0 - last = point - + for (point, indicator), endpoint in intervals: continuation = point == get_start_of_day(point, tzid) # Some rows contain no period details and are marked as such. @@ -577,7 +572,7 @@ page.tr(class_=css) page.th(class_="timeslot") - if indicator == 0: + if indicator == POINT: self._time_point(point, endpoint) page.th.close()