-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: response time timeseries (#322)
* diff_node_names Signed-off-by: yu-taro- <[email protected]> * 20230130 Signed-off-by: yu-taro- <[email protected]> * diff_node_names 20230205 * re Signed-off-by: yu-taro- <[email protected]> * class Diff Signed-off-by: yu-taro- <[email protected]> * 20230205 Signed-off-by: yu-taro- <[email protected]> * refactor(arcitecture), test(test_arcitecture) / Naming conventions were changed and mock tests were added and modified because of the points raised Signed-off-by: yu-taro- <[email protected]> * a Signed-off-by: yu-taro- <[email protected]> * conflict fix2 Signed-off-by: yu-taro- <[email protected]> * feat: make response time time series plot func Signed-off-by: taro-yu <[email protected]> * fix: conflict Signed-off-by: taro-yu <[email protected]> * fix: changed to use new record api Signed-off-by: taro-yu <[email protected]> * fix: changed to use new record api Signed-off-by: taro-yu <[email protected]> * fix: pytest errors Signed-off-by: taro-yu <[email protected]> * docs: add some description Signed-off-by: taro-yu <[email protected]> * docs: add some description Signed-off-by: taro-yu <[email protected]> * fix: argument error Signed-off-by: taro-yu <[email protected]> * feat: add hover info Signed-off-by: taro-yu <[email protected]> * docs: fix a comment Signed-off-by: taro-yu <[email protected]> * docs: added CARET_doc and fixed spell-ceheck-errors Signed-off-by: taro-yu <[email protected]> * docs: fixed spell-check-error Signed-off-by: taro-yu <[email protected]> * fix: mypy errors Signed-off-by: taro-yu <[email protected]> * fix: mypy errors Signed-off-by: taro-yu <[email protected]> * fix: mypy errors Signed-off-by: taro-yu <[email protected]> * fix: mypy errors and add some docs Signed-off-by: taro-yu <[email protected]> * fix: pytest errors Signed-off-by: taro-yu <[email protected]> * fix: mypy errors Signed-off-by: taro-yu <[email protected]> * docs remove some docs Signed-off-by: taro-yu <[email protected]> * feat: change hover info Signed-off-by: taro-yu <[email protected]> --------- Signed-off-by: yu-taro- <[email protected]> Signed-off-by: taro-yu <[email protected]> Co-authored-by: taro-yu <[email protected]>
- Loading branch information
Showing
9 changed files
with
210 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
src/caret_analyze/plot/timeseries/response_time_timeseries.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# Copyright 2021 Research Institute of Systems Planning, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from __future__ import annotations | ||
|
||
from collections.abc import Sequence | ||
|
||
import pandas as pd | ||
|
||
from ..metrics_base import MetricsBase | ||
from ...record import RecordsInterface, ResponseTime | ||
from ...runtime import Path | ||
|
||
|
||
class ResponseTimeTimeSeries(MetricsBase): | ||
"""Class that provides latency timeseries data.""" | ||
|
||
def __init__( | ||
self, | ||
target_objects: Sequence[Path], | ||
case: str | ||
) -> None: | ||
super().__init__(target_objects) | ||
self._case = case | ||
|
||
def to_dataframe(self, xaxis_type: str = 'system_time') -> pd.DataFrame: | ||
""" | ||
Get Response time timeseries data for each object in pandas DataFrame format. | ||
Parameters | ||
---------- | ||
xaxis_type : str | ||
Type of time for timestamp. | ||
"system_time", "index", or "sim_time" can be specified. | ||
The default is "system_time". | ||
Returns | ||
------- | ||
pd.DataFrame | ||
Multi-column Response time DataFrame. | ||
Notes | ||
----- | ||
xaxis_type "system_time" and "index" return the same DataFrame. | ||
""" | ||
timeseries_records_list = self.to_timeseries_records_list(xaxis_type) | ||
all_df = pd.DataFrame() | ||
for to, response_records in zip(self._target_objects, timeseries_records_list): | ||
response_df = response_records.to_dataframe() | ||
response_df[response_df.columns[-1]] *= 10**(-6) | ||
response_df.rename( | ||
columns={ | ||
response_df.columns[0]: 'path_start_timestamp [ns]', | ||
response_df.columns[1]: 'response_time [ms]', | ||
}, | ||
inplace=True | ||
) | ||
# TODO: Multi-column DataFrame are difficult for users to handle, | ||
# so it should be a single-column DataFrame. | ||
response_df = self._add_top_level_column(response_df, to) | ||
all_df = pd.concat([all_df, response_df], axis=1) | ||
|
||
return all_df.sort_index(level=0, axis=1, sort_remaining=False) | ||
|
||
def to_timeseries_records_list( | ||
self, | ||
xaxis_type: str = 'system_time' | ||
) -> list[RecordsInterface]: | ||
""" | ||
Get Response time records list of all target objects. | ||
Parameters | ||
---------- | ||
xaxis_type : str | ||
Type of time for timestamp. | ||
"system_time", "index", or "sim_time" can be specified. | ||
The default is "system_time". | ||
Returns | ||
------- | ||
list[RecordsInterface] | ||
Response time records list of all target objects. | ||
""" | ||
timeseries_records_list: list[RecordsInterface] = [ | ||
_.to_records() for _ in self._target_objects | ||
] | ||
|
||
if xaxis_type == 'sim_time': | ||
timeseries_records_list = \ | ||
self._convert_timeseries_records_to_sim_time(timeseries_records_list) | ||
|
||
response_timeseries_list: list[RecordsInterface] = [] | ||
for records in timeseries_records_list: | ||
response = ResponseTime(records) | ||
if self._case == 'best': | ||
response_timeseries_list.append(response.to_best_case_records()) | ||
elif self._case == 'worst': | ||
response_timeseries_list.append(response.to_worst_case_records()) | ||
elif self._case == 'all': | ||
response_timeseries_list.append(response.to_all_records()) | ||
|
||
return response_timeseries_list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.