X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=resources%2Ftools%2Fdash%2Fapp%2Fpal%2Ftrending%2Fgraphs.py;h=06bea25466cf4c123aa7b528dcc0145a7fee7e45;hb=808797d2d913eac7581a4e4cba3fb826ddbff775;hp=895055816635a9d93d76a30ea7889c1ba14976c9;hpb=2f6295d7c63b7e231b0198ee055468b2fc54fa94;p=csit.git diff --git a/resources/tools/dash/app/pal/trending/graphs.py b/resources/tools/dash/app/pal/trending/graphs.py index 8950558166..06bea25466 100644 --- a/resources/tools/dash/app/pal/trending/graphs.py +++ b/resources/tools/dash/app/pal/trending/graphs.py @@ -14,7 +14,6 @@ """ """ -import logging import plotly.graph_objects as go import pandas as pd @@ -22,107 +21,24 @@ import hdrh.histogram import hdrh.codec from datetime import datetime -from numpy import isnan - -from ..jumpavg import classify - - -_NORM_FREQUENCY = 2.0 # [GHz] -_FREQURENCY = { # [GHz] - "2n-aws": 1.000, - "2n-dnv": 2.000, - "2n-clx": 2.300, - "2n-icx": 2.600, - "2n-skx": 2.500, - "2n-tx2": 2.500, - "2n-zn2": 2.900, - "3n-alt": 3.000, - "3n-aws": 1.000, - "3n-dnv": 2.000, - "3n-icx": 2.600, - "3n-skx": 2.500, - "3n-tsh": 2.200 -} - -_ANOMALY_COLOR = { - "regression": 0.0, - "normal": 0.5, - "progression": 1.0 -} -_COLORSCALE_TPUT = [ - [0.00, "red"], - [0.33, "red"], - [0.33, "white"], - [0.66, "white"], - [0.66, "green"], - [1.00, "green"] -] -_TICK_TEXT_TPUT = ["Regression", "Normal", "Progression"] -_COLORSCALE_LAT = [ - [0.00, "green"], - [0.33, "green"], - [0.33, "white"], - [0.66, "white"], - [0.66, "red"], - [1.00, "red"] -] -_TICK_TEXT_LAT = ["Progression", "Normal", "Regression"] -_VALUE = { - "mrr": "result_receive_rate_rate_avg", - "ndr": "result_ndr_lower_rate_value", - "pdr": "result_pdr_lower_rate_value", - "pdr-lat": "result_latency_forward_pdr_50_avg" -} -_UNIT = { - "mrr": "result_receive_rate_rate_unit", - "ndr": "result_ndr_lower_rate_unit", - "pdr": "result_pdr_lower_rate_unit", - "pdr-lat": "result_latency_forward_pdr_50_unit" -} -_LAT_HDRH = ( # Do not change the order - "result_latency_forward_pdr_0_hdrh", - "result_latency_reverse_pdr_0_hdrh", - "result_latency_forward_pdr_10_hdrh", - "result_latency_reverse_pdr_10_hdrh", - "result_latency_forward_pdr_50_hdrh", - "result_latency_reverse_pdr_50_hdrh", - "result_latency_forward_pdr_90_hdrh", - "result_latency_reverse_pdr_90_hdrh", -) -# This value depends on latency stream rate (9001 pps) and duration (5s). -# Keep it slightly higher to ensure rounding errors to not remove tick mark. -PERCENTILE_MAX = 99.999501 - -_GRAPH_LAT_HDRH_DESC = { - "result_latency_forward_pdr_0_hdrh": "No-load.", - "result_latency_reverse_pdr_0_hdrh": "No-load.", - "result_latency_forward_pdr_10_hdrh": "Low-load, 10% PDR.", - "result_latency_reverse_pdr_10_hdrh": "Low-load, 10% PDR.", - "result_latency_forward_pdr_50_hdrh": "Mid-load, 50% PDR.", - "result_latency_reverse_pdr_50_hdrh": "Mid-load, 50% PDR.", - "result_latency_forward_pdr_90_hdrh": "High-load, 90% PDR.", - "result_latency_reverse_pdr_90_hdrh": "High-load, 90% PDR." -} - - -def _get_color(idx: int) -> str: - """ - """ - _COLORS = ( - "#1A1110", "#DA2647", "#214FC6", "#01786F", "#BD8260", "#FFD12A", - "#A6E7FF", "#738276", "#C95A49", "#FC5A8D", "#CEC8EF", "#391285", - "#6F2DA8", "#FF878D", "#45A27D", "#FFD0B9", "#FD5240", "#DB91EF", - "#44D7A8", "#4F86F7", "#84DE02", "#FFCFF1", "#614051" - ) - return _COLORS[idx % len(_COLORS)] + +from ..utils.constants import Constants as C +from ..utils.utils import classify_anomalies, get_color def _get_hdrh_latencies(row: pd.Series, name: str) -> dict: - """ + """Get the HDRH latencies from the test data. + + :param row: A row fron the data frame with test data. + :param name: The test name to be displayed as the graph title. + :type row: pandas.Series + :type name: str + :returns: Dictionary with HDRH latencies. + :rtype: dict """ latencies = {"name": name} - for key in _LAT_HDRH: + for key in C.LAT_HDRH: try: latencies[key] = row[key] except KeyError: @@ -131,58 +47,16 @@ def _get_hdrh_latencies(row: pd.Series, name: str) -> dict: return latencies -def _classify_anomalies(data): - """Process the data and return anomalies and trending values. - - Gather data into groups with average as trend value. - Decorate values within groups to be normal, - the first value of changed average as a regression, or a progression. - - :param data: Full data set with unavailable samples replaced by nan. - :type data: OrderedDict - :returns: Classification and trend values - :rtype: 3-tuple, list of strings, list of floats and list of floats - """ - # NaN means something went wrong. - # Use 0.0 to cause that being reported as a severe regression. - bare_data = [0.0 if isnan(sample) else sample for sample in data.values()] - # TODO: Make BitCountingGroupList a subclass of list again? - group_list = classify(bare_data).group_list - group_list.reverse() # Just to use .pop() for FIFO. - classification = list() - avgs = list() - stdevs = list() - active_group = None - values_left = 0 - avg = 0.0 - stdv = 0.0 - for sample in data.values(): - if isnan(sample): - classification.append("outlier") - avgs.append(sample) - stdevs.append(sample) - continue - if values_left < 1 or active_group is None: - values_left = 0 - while values_left < 1: # Ignore empty groups (should not happen). - active_group = group_list.pop() - values_left = len(active_group.run_list) - avg = active_group.stats.avg - stdv = active_group.stats.stdev - classification.append(active_group.comment) - avgs.append(avg) - stdevs.append(stdv) - values_left -= 1 - continue - classification.append("normal") - avgs.append(avg) - stdevs.append(stdv) - values_left -= 1 - return classification, avgs, stdevs - - def select_trending_data(data: pd.DataFrame, itm:dict) -> pd.DataFrame: - """ + """Select the data for graphs from the provided data frame. + + :param data: Data frame with data for graphs. + :param itm: Item (in this case job name) which data will be selected from + the input data frame. + :type data: pandas.DataFrame + :type itm: str + :returns: A data frame with selected data. + :rtype: pandas.DataFrame """ phy = itm["phy"].split("-") @@ -226,10 +100,28 @@ def select_trending_data(data: pd.DataFrame, itm:dict) -> pd.DataFrame: def _generate_trending_traces(ttype: str, name: str, df: pd.DataFrame, start: datetime, end: datetime, color: str, norm_factor: float) -> list: - """ + """Generate the trending traces for the trending graph. + + :param ttype: Test type (MRR, NDR, PDR). + :param name: The test name to be displayed as the graph title. + :param df: Data frame with test data. + :param start: The date (and time) when the selected data starts. + :param end: The date (and time) when the selected data ends. + :param color: The color of the trace (samples and trend line). + :param norm_factor: The factor used for normalization of the results to CPU + frequency set to Constants.NORM_FREQUENCY. + :type ttype: str + :type name: str + :type df: pandas.DataFrame + :type start: datetime.datetime + :type end: datetime.datetime + :type color: str + :type norm_factor: float + :returns: Traces (samples, trending line, anomalies) + :rtype: list """ - df = df.dropna(subset=[_VALUE[ttype], ]) + df = df.dropna(subset=[C.VALUE[ttype], ]) if df.empty: return list() df = df.loc[((df["start_time"] >= start) & (df["start_time"] <= end))] @@ -238,11 +130,11 @@ def _generate_trending_traces(ttype: str, name: str, df: pd.DataFrame, x_axis = df["start_time"].tolist() if ttype == "pdr-lat": - y_data = [(itm / norm_factor) for itm in df[_VALUE[ttype]].tolist()] + y_data = [(itm / norm_factor) for itm in df[C.VALUE[ttype]].tolist()] else: - y_data = [(itm * norm_factor) for itm in df[_VALUE[ttype]].tolist()] + y_data = [(itm * norm_factor) for itm in df[C.VALUE[ttype]].tolist()] - anomalies, trend_avg, trend_stdev = _classify_anomalies( + anomalies, trend_avg, trend_stdev = classify_anomalies( {k: v for k, v in zip(x_axis, y_data)} ) @@ -252,7 +144,7 @@ def _generate_trending_traces(ttype: str, name: str, df: pd.DataFrame, d_type = "trex" if row["dut_type"] == "none" else row["dut_type"] hover_itm = ( f"date: {row['start_time'].strftime('%Y-%m-%d %H:%M:%S')}
" - f" [{row[_UNIT[ttype]]}]: {y_data[idx]:,.0f}
" + f" [{row[C.UNIT[ttype]]}]: {y_data[idx]:,.0f}
" f"" f"{d_type}-ref: {row['dut_version']}
" f"csit-ref: {row['job']}/{row['build']}
" @@ -330,7 +222,7 @@ def _generate_trending_traces(ttype: str, name: str, df: pd.DataFrame, if anomaly in ("regression", "progression"): anomaly_x.append(x_axis[idx]) anomaly_y.append(trend_avg[idx]) - anomaly_color.append(_ANOMALY_COLOR[anomaly]) + anomaly_color.append(C.ANOMALY_COLOR[anomaly]) hover_itm = ( f"date: {x_axis[idx].strftime('%Y-%m-%d %H:%M:%S')}
" f"trend [pps]: {trend_avg[idx]:,.0f}
" @@ -354,8 +246,8 @@ def _generate_trending_traces(ttype: str, name: str, df: pd.DataFrame, "size": 15, "symbol": "circle-open", "color": anomaly_color, - "colorscale": _COLORSCALE_LAT \ - if ttype == "pdr-lat" else _COLORSCALE_TPUT, + "colorscale": C.COLORSCALE_LAT \ + if ttype == "pdr-lat" else C.COLORSCALE_TPUT, "showscale": True, "line": { "width": 2 @@ -367,8 +259,8 @@ def _generate_trending_traces(ttype: str, name: str, df: pd.DataFrame, "titleside": "right", "tickmode": "array", "tickvals": [0.167, 0.500, 0.833], - "ticktext": _TICK_TEXT_LAT \ - if ttype == "pdr-lat" else _TICK_TEXT_TPUT, + "ticktext": C.TICK_TEXT_LAT \ + if ttype == "pdr-lat" else C.TICK_TEXT_TPUT, "ticks": "", "ticklen": 0, "tickangle": -90, @@ -383,7 +275,24 @@ def _generate_trending_traces(ttype: str, name: str, df: pd.DataFrame, def graph_trending(data: pd.DataFrame, sel:dict, layout: dict, start: datetime, end: datetime, normalize: bool) -> tuple: - """ + """Generate the trending graph(s) - MRR, NDR, PDR and for PDR also Latences + (result_latency_forward_pdr_50_avg). + + :param data: Data frame with test results. + :param sel: Selected tests. + :param layout: Layout of plot.ly graph. + :param start: The date (and time) when the selected data starts. + :param end: The date (and time) when the selected data ends. + :param normalize: If True, the data is normalized to CPU frquency + Constants.NORM_FREQUENCY. + :type data: pandas.DataFrame + :type sel: dict + :type layout: dict + :type start: datetime.datetime + :type end: datetype.datetype + :type normalize: bool + :returns: Trending graph(s) + :rtype: tuple(plotly.graph_objects.Figure, plotly.graph_objects.Figure) """ if not sel: @@ -402,12 +311,12 @@ def graph_trending(data: pd.DataFrame, sel:dict, layout: dict, if normalize: phy = itm["phy"].split("-") topo_arch = f"{phy[0]}-{phy[1]}" if len(phy) == 4 else str() - norm_factor = (_NORM_FREQUENCY / _FREQURENCY[topo_arch]) \ + norm_factor = (C.NORM_FREQUENCY / C.FREQUENCY[topo_arch]) \ if topo_arch else 1.0 else: norm_factor = 1.0 traces = _generate_trending_traces( - itm["testtype"], name, df, start, end, _get_color(idx), norm_factor + itm["testtype"], name, df, start, end, get_color(idx), norm_factor ) if traces: if not fig_tput: @@ -416,7 +325,7 @@ def graph_trending(data: pd.DataFrame, sel:dict, layout: dict, if itm["testtype"] == "pdr": traces = _generate_trending_traces( - "pdr-lat", name, df, start, end, _get_color(idx), norm_factor + "pdr-lat", name, df, start, end, get_color(idx), norm_factor ) if traces: if not fig_lat: @@ -432,7 +341,14 @@ def graph_trending(data: pd.DataFrame, sel:dict, layout: dict, def graph_hdrh_latency(data: dict, layout: dict) -> go.Figure: - """ + """Generate HDR Latency histogram graphs. + + :param data: HDRH data. + :param layout: Layout of plot.ly graph. + :type data: dict + :type layout: dict + :returns: HDR latency Histogram. + :rtype: plotly.graph_objects.Figure """ fig = None @@ -453,11 +369,11 @@ def graph_hdrh_latency(data: dict, layout: dict) -> go.Figure: # For 100%, we cut that down to "x_perc" to avoid # infinity. percentile = item.percentile_level_iterated_to - x_perc = min(percentile, PERCENTILE_MAX) + x_perc = min(percentile, C.PERCENTILE_MAX) xaxis.append(previous_x) yaxis.append(item.value_iterated_to) hovertext.append( - f"{_GRAPH_LAT_HDRH_DESC[lat_name]}
" + f"{C.GRAPH_LAT_HDRH_DESC[lat_name]}
" f"Direction: {('W-E', 'E-W')[idx % 2]}
" f"Percentile: {prev_perc:.5f}-{percentile:.5f}%
" f"Latency: {item.value_iterated_to}uSec" @@ -466,7 +382,7 @@ def graph_hdrh_latency(data: dict, layout: dict) -> go.Figure: xaxis.append(next_x) yaxis.append(item.value_iterated_to) hovertext.append( - f"{_GRAPH_LAT_HDRH_DESC[lat_name]}
" + f"{C.GRAPH_LAT_HDRH_DESC[lat_name]}
" f"Direction: {('W-E', 'E-W')[idx % 2]}
" f"Percentile: {prev_perc:.5f}-{percentile:.5f}%
" f"Latency: {item.value_iterated_to}uSec" @@ -478,12 +394,12 @@ def graph_hdrh_latency(data: dict, layout: dict) -> go.Figure: go.Scatter( x=xaxis, y=yaxis, - name=_GRAPH_LAT_HDRH_DESC[lat_name], + name=C.GRAPH_LAT_HDRH_DESC[lat_name], mode="lines", - legendgroup=_GRAPH_LAT_HDRH_DESC[lat_name], + legendgroup=C.GRAPH_LAT_HDRH_DESC[lat_name], showlegend=bool(idx % 2), line=dict( - color=_get_color(int(idx/2)), + color=get_color(int(idx/2)), dash="solid", width=1 if idx % 2 else 2 ),