Skip to content

Commit

Permalink
fix: acccept drop case
Browse files Browse the repository at this point in the history
Signed-off-by: rokamu623 <[email protected]>
  • Loading branch information
rokamu623 committed Jul 28, 2023
1 parent 301b2aa commit a7c5c26
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
16 changes: 10 additions & 6 deletions src/caret_analyze/record/records_service/response_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,21 +240,25 @@ def __init__(
self._start_timestamps: list[int] = []
self._end_timestamps: list[int] = []

for record in records:
if (self._start_column not in record.columns or
self._end_column not in record.columns):
end_ts = None
for record in reversed(records.data):
if self._end_column in record.columns:
end_ts = record.get(self._end_column)
elif end_ts is None:
continue

if self._start_column not in record.columns:
continue
start_ts = record.get(self._start_column)
end_ts = record.get(self._end_column)

if start_ts in self._start_timestamps:
idx = self._start_timestamps.index(start_ts)
if end_ts < self._end_timestamps[idx]:
self._start_timestamps[idx] = start_ts
self._end_timestamps[idx] = end_ts
else:
self._start_timestamps.append(start_ts)
self._end_timestamps.append(end_ts)
self._start_timestamps.insert(0, start_ts)
self._end_timestamps.insert(0, end_ts)

def to_all_records(self) -> RecordsInterface:
records = self._create_empty_records()
Expand Down
10 changes: 6 additions & 4 deletions src/test/record/records_service/test_response_time_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,19 @@ def test_multi_input_single_output_case(self):

def test_drop_case(self):
records_raw = [
{'start': 0, 'middle': 4, 'end': 5},
{'start': 0, 'middle': 4},
{'start': 0, 'middle': 12, 'end': 13}
{'start': 0, 'middle': 4, 'end': 13},
{'start': 1, 'middle': 4},
{'start': 5, 'middle': 12, 'end': 13}
]
columns = [ColumnValue('start'), ColumnValue('end')]
records = create_records(records_raw, columns)

response_time = ResponseTime(records)

expect_raw = [
{'start': 0, 'response_time': 5}
{'start': 0, 'response_time': 13},
{'start': 1, 'response_time': 12},
{'start': 5, 'response_time': 8}
]
result = to_dict(response_time.to_all_records())
assert result == expect_raw

0 comments on commit a7c5c26

Please sign in to comment.