Skip to content

Commit b4e60f8

Browse files
committed
feat: add is_same_result parameter to find_rectangles
1 parent 405f3de commit b4e60f8

File tree

3 files changed

+34
-22
lines changed

3 files changed

+34
-22
lines changed

execution_engine/task/process/rectangle.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ def find_overlapping_personal_windows(
775775

776776
return result
777777

778-
def find_rectangles(data: list[PersonIntervals], interval_constructor: Callable) -> PersonIntervals:
778+
def find_rectangles(data: list[PersonIntervals], interval_constructor: Callable, is_same_result = None) -> PersonIntervals:
779779
# TODO(jmoringe): can this use _process_interval?
780780
if len(data) == 0:
781781
return {}
@@ -784,5 +784,5 @@ def find_rectangles(data: list[PersonIntervals], interval_constructor: Callable)
784784
for track in data:
785785
keys |= track.keys()
786786
return {key: _impl.find_rectangles([ intervals.get(key, []) for intervals in data ],
787-
interval_constructor)
787+
interval_constructor, is_same_result=is_same_result)
788788
for key in keys}

execution_engine/task/process/rectangle_cython.pyx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,20 @@ def union_interval_lists(
329329
330330
IntervalConstructor = Callable[[int, int, typing.List[AnyInterval]], AnyInterval]
331331
332+
def default_is_same_result(interval_constructor):
333+
def is_same_result(active_intervals1, active_intervals2):
334+
# When we have to decide whether to extend a result interval
335+
# or start a new one, we compare the state for the existing
336+
# result interval with the new state. The states are derived
337+
# from the respective lists of active intervals by calling
338+
# interval_constructor (with fake points in time) .
339+
return (interval_constructor(0, 0, active_intervals1)
340+
== interval_constructor(0, 0, active_intervals2))
341+
return is_same_result
342+
332343
def find_rectangles(all_intervals: list[list[AnyInterval]],
333-
interval_constructor: IntervalConstructor) \
344+
interval_constructor: IntervalConstructor,
345+
is_same_result = None) \
334346
-> list[AnyInterval]:
335347
"""For multiple parallel "tracks" of intervals, identify temporal
336348
intervals in which no change occurs on any "track". For each such
@@ -356,6 +368,9 @@ def find_rectangles(all_intervals: list[list[AnyInterval]],
356368
that adjacent intervals (i.e. without gaps between them)
357369
have different "payloads".
358370
"""
371+
if is_same_result is None:
372+
is_same_result = default_is_same_result(interval_constructor)
373+
359374
# Convert all intervals into a single list of events sorted by
360375
# time. Multiple events at the same point in time can be problem
361376
# here: If an interval open event and an interval close event on
@@ -396,15 +411,6 @@ def find_rectangles(all_intervals: list[list[AnyInterval]],
396411
result.append(interval)
397412
previous_end = end
398413
399-
def is_same_result(active_intervals1, active_intervals2):
400-
# When we have to decide whether to extend a result interval
401-
# or start a new one, we compare the state for the existing
402-
# result interval with the new state. The states are derived
403-
# from the respective lists of active intervals by calling
404-
# interval_constructor (with fake points in time) .
405-
return (interval_constructor(0,0,active_intervals1)
406-
== interval_constructor(0,0,active_intervals2))
407-
408414
active_intervals = [None] * track_count
409415
def process_events_for_point_in_time(index, point_time):
410416
high_time = point_time

execution_engine/task/process/rectangle_python.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,20 @@ def union_interval_lists(left: list[Interval], right: list[Interval]) -> list[In
323323

324324
IntervalConstructor = Callable[[int, int, typing.List[AnyInterval]], AnyInterval]
325325

326+
def default_is_same_result(interval_constructor):
327+
def is_same_result(active_intervals1, active_intervals2):
328+
# When we have to decide whether to extend a result interval
329+
# or start a new one, we compare the state for the existing
330+
# result interval with the new state. The states are derived
331+
# from the respective lists of active intervals by calling
332+
# interval_constructor (with fake points in time) .
333+
return (interval_constructor(0, 0, active_intervals1)
334+
== interval_constructor(0, 0, active_intervals2))
335+
return is_same_result
336+
326337
def find_rectangles(all_intervals: list[list[AnyInterval]],
327-
interval_constructor: IntervalConstructor) \
338+
interval_constructor: IntervalConstructor,
339+
is_same_result = None) \
328340
-> list[AnyInterval]:
329341
"""For multiple parallel "tracks" of intervals, identify temporal
330342
intervals in which no change occurs on any "track". For each such
@@ -350,6 +362,9 @@ def find_rectangles(all_intervals: list[list[AnyInterval]],
350362
that adjacent intervals (i.e. without gaps between them)
351363
have different "payloads".
352364
"""
365+
if is_same_result is None:
366+
is_same_result = default_is_same_result(interval_constructor)
367+
353368
# Convert all intervals into a single list of events sorted by
354369
# time. Multiple events at the same point in time can be problem
355370
# here: If an interval open event and an interval close event on
@@ -390,15 +405,6 @@ def add_segment(start, end, original_intervals):
390405
result.append(interval)
391406
previous_end = end
392407

393-
def is_same_result(active_intervals1, active_intervals2):
394-
# When we have to decide whether to extend a result interval
395-
# or start a new one, we compare the state for the existing
396-
# result interval with the new state. The states are derived
397-
# from the respective lists of active intervals by calling
398-
# interval_constructor (with fake points in time) .
399-
return (interval_constructor(0,0,active_intervals1)
400-
== interval_constructor(0,0,active_intervals2))
401-
402408
active_intervals = [None] * track_count
403409
def process_events_for_point_in_time(index, point_time):
404410
high_time = point_time

0 commit comments

Comments
 (0)