aboutsummaryrefslogtreecommitdiffstats
path: root/resources/tools/dash/app/pal/trending/graphs.py
blob: a20ce8efd4120eeed97c1bc3ed250a5abf05381a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# Copyright (c) 2022 Cisco and/or its affiliates.
# 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.

"""
"""


import plotly.graph_objects as go
import pandas as pd
import re

from datetime import datetime

from dash import no_update


def trending_tput(data: pd.DataFrame, sel:dict, layout: dict, start: datetime,
    end: datetime):
    """
    """

    if not sel:
        return no_update, no_update

    def _generate_trace(ttype: str, name: str, df: pd.DataFrame,
        start: datetime, end: datetime):

        value = {
            "mrr": "result_receive_rate_rate_avg",
            "ndr": "result_ndr_lower_rate_value",
            "pdr": "result_pdr_lower_rate_value"
        }
        unit = {
            "mrr": "result_receive_rate_rate_unit",
            "ndr": "result_ndr_lower_rate_unit",
            "pdr": "result_pdr_lower_rate_unit"
        }

        x_axis = [
            d for d in df["start_time"] if d >= start and d <= end
        ]
        hover_txt = list()
        for _, row in df.iterrows():
            hover_itm = (
                f"date: "
                f"{row['start_time'].strftime('%d-%m-%Y %H:%M:%S')}<br>"
                f"average [{row[unit[ttype]]}]: "
                f"{row[value[ttype]]}<br>"
                f"{row['dut_type']}-ref: {row['dut_version']}<br>"
                f"csit-ref: {row['job']}/{row['build']}"
            )
            if ttype == "mrr":
                stdev = (
                    f"stdev [{row['result_receive_rate_rate_unit']}]: "
                    f"{row['result_receive_rate_rate_stdev']}<br>"
                )
            else:
                stdev = ""
            hover_itm = hover_itm.replace("<stdev>", stdev)
            hover_txt.append(hover_itm)

        return go.Scatter(
            x=x_axis,
            y=df[value[ttype]],
            name=name,
            mode="markers+lines",
            text=hover_txt,
            hoverinfo=u"text+name"
        )

    # Generate graph:
    fig = go.Figure()
    for itm in sel:
        phy = itm["phy"].split("-")
        if len(phy) == 4:
            topo, arch, nic, drv = phy
            if drv in ("dpdk", "ixgbe"):
                drv = ""
            else:
                drv += "-"
        else:
            continue
        cadence = \
            "weekly" if (arch == "aws" or itm["testtype"] != "mrr") else "daily"
        sel_topo_arch = (
            f"csit-vpp-perf-"
            f"{itm['testtype'] if itm['testtype'] == 'mrr' else 'ndrpdr'}-"
            f"{cadence}-master-{topo}-{arch}"
        )
        df_sel = data.loc[(data["job"] == sel_topo_arch)]
        regex = (
            f"^.*{nic}.*\.{itm['framesize']}-{itm['core']}-{drv}{itm['test']}-"
            f"{'mrr' if itm['testtype'] == 'mrr' else 'ndrpdr'}$"
        )
        df = df_sel.loc[
            df_sel["test_id"].apply(
                lambda x: True if re.search(regex, x) else False
            )
        ].sort_values(by="start_time", ignore_index=True)
        name = (
            f"{itm['phy']}-{itm['framesize']}-{itm['core']}-"
            f"{itm['test']}-{itm['testtype']}"
        )
        fig.add_trace(_generate_trace(itm['testtype'], name, df, start, end))

    style={
        "vertical-align": "top",
        "display": "inline-block",
        "width": "80%",
        "padding": "5px"
    }

    layout = layout.get("plot-trending", dict())
    fig.update_layout(layout)

    return fig, style