Skip to content

Commit

Permalink
fix: response time stacked bar option name
Browse files Browse the repository at this point in the history
Signed-off-by: rokamu623 <[email protected]>
  • Loading branch information
rokamu623 committed Sep 25, 2023
1 parent 22efb03 commit 3957db1
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/caret_analyze/plot/plot_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def create_response_time_stacked_bar_plot(
supported metrics: [latency]
case : str, optional
Response time calculation method, worst by default.
supported case: [best/worst].
supported case: [all/best/worst/worst-with-external-latency].
Returns
-------
Expand Down
15 changes: 9 additions & 6 deletions src/caret_analyze/plot/stacked_bar/latency_stacked_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,17 @@ def _get_response_time_record(
response_time = ResponseTime(target_object.to_records(),
columns=target_object.column_names)
# include timestamp of response time (best, worst)
if self._case == 'best':
return response_time.to_best_case_stacked_bar()
if self._case == 'worst-in-input':
return response_time.to_worst_in_input_case_stacked_bar()
if self._case == 'all':
return response_time.to_all_stacked_bar()

return response_time.to_stacked_bar()
elif self._case == 'best':
return response_time.to_best_case_stacked_bar()
elif self._case == 'worst':
return response_time.to_worst_case_stacked_bar()
elif self._case == 'worst-with-external-latency':
return response_time.to_worst_with_external_latency_stacked_bar()
else:
raise ValueError('optional argument "case" must be following: \
"all", "best", "worst", "worst-with-external-latency".')

@property
def target_objects(self) -> Path:
Expand Down
40 changes: 17 additions & 23 deletions src/caret_analyze/record/records_service/response_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,33 +522,32 @@ def to_worst_with_external_latency_case_records(self) -> RecordsInterface:
"""
return self._timeseries.to_worst_with_external_latency()

def to_stacked_bar(self) -> RecordsInterface:
def to_all_stacked_bar(self) -> RecordsInterface:
"""
Calculate records for stacked bar.
Returns
-------
RecordsInterface
The best and worst cases are separated into separate columns.
Records of the all response time.
Columns
- {columns[0]}_min
- {columns[0]}_max
- {columns[0]}
- {columns[1]}
- {...}
- {columns[n-1]}
"""
return self._records.to_range_records()
return self._response_map_all.to_all_stacked_bar()

def to_best_case_stacked_bar(self) -> RecordsInterface:
def to_worst_case_stacked_bar(self) -> RecordsInterface:
"""
Calculate records for stacked bar.
Returns
-------
RecordsInterface
Records of the best cases response time.
Records of the worst-with-external-latency cases response time.
Columns
- {columns[0]}
Expand All @@ -557,16 +556,16 @@ def to_best_case_stacked_bar(self) -> RecordsInterface:
- {columns[n-1]}
"""
return self._records.to_range_records('best')
return self._response_map_all.to_worst_stacked_bar()

def to_all_stacked_bar(self) -> RecordsInterface:
def to_best_case_stacked_bar(self) -> RecordsInterface:
"""
Calculate records for stacked bar.
Returns
-------
RecordsInterface
Records of the all response time.
Records of the best cases response time.
Columns
- {columns[0]}
Expand All @@ -575,31 +574,26 @@ def to_all_stacked_bar(self) -> RecordsInterface:
- {columns[n-1]}
"""
return self._response_map_all.to_all_stacked_bar()
return self._records.to_range_records('best')

def to_worst_in_input_case_stacked_bar(self) -> RecordsInterface:
def to_worst_with_external_latency_stacked_bar(self) -> RecordsInterface:
"""
Calculate records for stacked bar.
Returns
-------
RecordsInterface
Records of the worst-in-input cases response time.
The best and worst cases are separated into separate columns.
Columns
- {columns[0]}
- {columns[0]}_min
- {columns[0]}_max
- {columns[1]}
- {...}
- {columns[n-1]}
"""
return self._response_map_all.to_worst_stacked_bar()

def to_worst_case_stacked_bar(self) -> RecordsInterface:
# NOTE:
# We think this function is unnecessary.
# If necessary, please contact us.
raise NotImplementedError()
return self._records.to_range_records('worst-with-external-latency')

def to_best_case_timeseries(self) -> tuple[np.ndarray, np.ndarray]:
warn('This API will be moved to the Plot package in the near future.', DeprecationWarning)
Expand Down Expand Up @@ -719,15 +713,15 @@ def __init__(

def to_range_records(
self,
case: str = 'worst',
case: str = 'worst-with-external-latency',
) -> RecordsInterface:
"""
Calculate response time records.
Returns
-------
RecordsInterface
The best and worst cases are separated into separate columns.
The best and worst-with-external-latency cases are separated into separate columns.
Columns
- {columns[0]}_min
- {columns[0]}_max
Expand Down
16 changes: 8 additions & 8 deletions src/test/record/records_service/test_response_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_empty_flow_case(self):
response = ResponseTime(records)

expect_raw = []
result = to_dict(response.to_stacked_bar())
result = to_dict(response.to_worst_with_external_latency_stacked_bar())
assert result == expect_raw

def test_single_flow_case(self):
Expand All @@ -65,7 +65,7 @@ def test_single_flow_case(self):

expect_raw = [
]
result = to_dict(response.to_stacked_bar())
result = to_dict(response.to_worst_with_external_latency_stacked_bar())
assert result == expect_raw

def test_double_flow_case(self):
Expand All @@ -81,7 +81,7 @@ def test_double_flow_case(self):
expect_raw = [
{'start_min': 0, 'start_max': 2, 'end': 3},
]
result = to_dict(response.to_stacked_bar())
result = to_dict(response.to_worst_with_external_latency_stacked_bar())
assert result == expect_raw

expect_raw = [
Expand All @@ -107,7 +107,7 @@ def test_cross_flow_case(self):
{'start_min': 0, 'start_max': 3, 'end': 4},
{'start_min': 3, 'start_max': 6, 'end': 6},
]
result = to_dict(response.to_stacked_bar())
result = to_dict(response.to_worst_with_external_latency_stacked_bar())
assert result == expect_raw

expect_raw = [
Expand All @@ -132,7 +132,7 @@ def test_triple_flow_case(self):
{'start_min': 0, 'start_max': 2, 'end': 3},
{'start_min': 2, 'start_max': 10, 'end': 11},
]
result = to_dict(response.to_stacked_bar())
result = to_dict(response.to_worst_with_external_latency_stacked_bar())
assert result == expect_raw

expect_raw = [
Expand All @@ -156,7 +156,7 @@ def test_double_flow_cross_case(self):
expect_raw = [
{'start_min': 0, 'start_max': 2, 'end': 3},
]
result = to_dict(response.to_stacked_bar())
result = to_dict(response.to_worst_with_external_latency_stacked_bar())
assert result == expect_raw

def test_drop_case(self):
Expand All @@ -174,7 +174,7 @@ def test_drop_case(self):
expect_raw = [
{'start_min': 2, 'start_max': 3, 'end': 4},
]
result = to_dict(response.to_stacked_bar())
result = to_dict(response.to_worst_with_external_latency_stacked_bar())
assert result == expect_raw


Expand Down Expand Up @@ -581,7 +581,7 @@ def test_to_response_records(self):
columns=self.column_names
)

records = response.to_stacked_bar()
records = response.to_worst_with_external_latency_stacked_bar()

expect = [
# flow 1 input ~ flow 7 output
Expand Down
8 changes: 4 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 @@ -238,7 +238,7 @@ def test_empty_case(self):
response_time = ResponseTime(records, columns=self.column_names)

expect_raw = []
result = to_dict(response_time.to_worst_in_input_case_stacked_bar())
result = to_dict(response_time.to_worst_case_stacked_bar())
assert result == expect_raw

def test_single_case(self):
Expand All @@ -256,7 +256,7 @@ def test_single_case(self):
{'start': 4, 'middle0': 5, 'middle1': 7, 'end': 8},
{'start': 6, 'middle0': 7, 'middle1': 8, 'end': 9}
]
result = to_dict(response_time.to_worst_in_input_case_stacked_bar())
result = to_dict(response_time.to_worst_case_stacked_bar())
assert result == expect_raw

def test_multi_case(self):
Expand All @@ -274,7 +274,7 @@ def test_multi_case(self):
{'start': 0, 'middle0': 1, 'middle1': 3, 'end': 4},
{'start': 2, 'middle0': 3, 'middle1': 5, 'end': 6},
]
result = to_dict(response_time.to_worst_in_input_case_stacked_bar())
result = to_dict(response_time.to_worst_case_stacked_bar())
assert result == expect_raw

def test_drop_case(self):
Expand All @@ -292,5 +292,5 @@ def test_drop_case(self):
{'start': 0, 'middle0': 1, 'middle1': 3, 'end': 4},
{'start': 2, 'middle0': 3, 'middle1': 4, 'end': 6},
]
result = to_dict(response_time.to_worst_in_input_case_stacked_bar())
result = to_dict(response_time.to_worst_case_stacked_bar())
assert result == expect_raw

0 comments on commit 3957db1

Please sign in to comment.