Skip to content

Commit

Permalink
fix: error with empty records (#466)
Browse files Browse the repository at this point in the history
* fix: admit empty record in histogram

Signed-off-by: rokamu623 <[email protected]>

* fix: variable name

Signed-off-by: rokamu623 <[email protected]>

* fix: flake8

Signed-off-by: rokamu623 <[email protected]>

* fix: enable legend with empty record

Signed-off-by: rokamu623 <[email protected]>

* fix: mypy

Signed-off-by: rokamu623 <[email protected]>

---------

Signed-off-by: rokamu623 <[email protected]>
  • Loading branch information
rokamu623 authored Jan 31, 2024
1 parent 3d7cf9a commit cd2831f
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/caret_analyze/plot/visualize_lib/bokeh/bokeh.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

from caret_analyze.record import Frequency, Latency, Period, ResponseTime

from numpy import histogram
from numpy import empty, histogram

from .callback_scheduling import BokehCallbackSched
from .message_flow import BokehMessageFlow
Expand Down Expand Up @@ -261,15 +261,20 @@ def histogram(
if data_type in ['period', 'latency', 'response_time']:
data_list = [[_ *10**(-6) for _ in data] for data in data_list]

max_value = max(
max([max_len for max_len in data_list if len(max_len)], key=lambda x: max(x))
)
min_value = min(
min([min_len for min_len in data_list if len(min_len)], key=lambda x: min(x))
)
filled_data_list = [data for data in data_list if len(data)]
if len(filled_data_list) != 0:
max_value = max(max(filled_data_list, key=lambda x: max(x)))
min_value = min(min(filled_data_list, key=lambda x: min(x)))
data_range = (min_value, max_value)
else:
data_range = None

for hist_type, target_object in zip(data_list, target_objects):
hist, bins = histogram(hist_type, 20, (min_value, max_value), density=False)
if len(hist_type) != 0:
hist, bins = histogram(hist_type, 20, data_range, density=False)
else:
hist = empty(0)
bins = empty(0)
quad = plot.quad(top=hist, bottom=0,
left=bins[:-1], right=bins[1:],
line_color='white', alpha=0.5,
Expand Down

0 comments on commit cd2831f

Please sign in to comment.