X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=resources%2Ftools%2Fdash%2Fapp%2Fpal%2Ftrending%2Fgraphs.py;h=1eff4aa88981986156cc9ee7410a2728bb24f981;hb=69fd124979890cac21bd0dbc7ef442563f175372;hp=0b4968082fb48a140c863766bd9705ce39279f06;hpb=ae1fe880286d7b0414664bce2b2c7c91c3f543f3;p=csit.git diff --git a/resources/tools/dash/app/pal/trending/graphs.py b/resources/tools/dash/app/pal/trending/graphs.py index 0b4968082f..1eff4aa889 100644 --- a/resources/tools/dash/app/pal/trending/graphs.py +++ b/resources/tools/dash/app/pal/trending/graphs.py @@ -23,17 +23,18 @@ import hdrh.codec from datetime import datetime from ..utils.constants import Constants as C -from ..utils.utils import classify_anomalies - - -def _get_color(idx: int) -> str: - """ - """ - return C.PLOT_COLORS[idx % len(C.PLOT_COLORS)] +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} @@ -47,7 +48,15 @@ def _get_hdrh_latencies(row: pd.Series, name: str) -> dict: 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("-") @@ -90,14 +99,27 @@ 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: - """ + 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 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 color: str + :type norm_factor: float + :returns: Traces (samples, trending line, anomalies) + :rtype: list """ df = df.dropna(subset=[C.VALUE[ttype], ]) if df.empty: return list() - df = df.loc[((df["start_time"] >= start) & (df["start_time"] <= end))] if df.empty: return list() @@ -247,8 +269,21 @@ 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: - """ + 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 normalize: If True, the data is normalized to CPU frquency + Constants.NORM_FREQUENCY. + :type data: pandas.DataFrame + :type sel: dict + :type layout: dict + :type normalize: bool + :returns: Trending graph(s) + :rtype: tuple(plotly.graph_objects.Figure, plotly.graph_objects.Figure) """ if not sel: @@ -272,7 +307,7 @@ def graph_trending(data: pd.DataFrame, sel:dict, layout: dict, else: norm_factor = 1.0 traces = _generate_trending_traces( - itm["testtype"], name, df, start, end, _get_color(idx), norm_factor + itm["testtype"], name, df, get_color(idx), norm_factor ) if traces: if not fig_tput: @@ -281,7 +316,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, get_color(idx), norm_factor ) if traces: if not fig_lat: @@ -297,7 +332,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 @@ -348,7 +390,7 @@ def graph_hdrh_latency(data: dict, layout: dict) -> go.Figure: 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 ),