From a7c5c2648f1afd7655162dfe05a2cb80e56016e4 Mon Sep 17 00:00:00 2001 From: rokamu623 Date: Fri, 28 Jul 2023 14:53:15 +0900 Subject: [PATCH] fix: acccept drop case Signed-off-by: rokamu623 --- .../record/records_service/response_time.py | 16 ++++++++++------ .../records_service/test_response_time_all.py | 10 ++++++---- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/caret_analyze/record/records_service/response_time.py b/src/caret_analyze/record/records_service/response_time.py index 25c3de1ec..309d3484f 100644 --- a/src/caret_analyze/record/records_service/response_time.py +++ b/src/caret_analyze/record/records_service/response_time.py @@ -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() diff --git a/src/test/record/records_service/test_response_time_all.py b/src/test/record/records_service/test_response_time_all.py index ea5759ed4..5614066bf 100644 --- a/src/test/record/records_service/test_response_time_all.py +++ b/src/test/record/records_service/test_response_time_all.py @@ -122,9 +122,9 @@ 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) @@ -132,7 +132,9 @@ def test_drop_case(self): 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