aboutsummaryrefslogtreecommitdiffstats
path: root/resources/tools/presentation/generator_cpta.py
blob: db64d5ffae59ee816d28ec9436e8c7711f0861a0 (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
3
# Copyright (c) 2020 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.

"""Constants used in CSIT.

"Constant" means a value that keeps its value since initialization. The value
does not need to be hard coded here, but can be read from environment variables.
"""


import os


def get_str_from_env(env_var_names, default_value):
    """Attempt to read string from environment variable, return that or default.

    If environment variable exists, but is empty (and default is not),
    empty string is returned.

    Several environment variable names are examined, as CSIT currently supports
    a mix of naming conventions.
    Here "several" means there are hard coded prefixes to try,
    and env_var_names itself can be single name, or a list or a tuple of names.

    :param env_var_names: Base names of environment variable to attempt to read.
    :param default_value: Value to return if the env var does not exist.
    :type env_var_names: str, or list of str, or tuple of str
    :type default_value: str
    :returns: The value read, or default value.
    :rtype: str
    """
    prefixes = (u"FDIO_CSIT_", u"CSIT_"
@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.highlight .ld { color: #e6db74 } /* Literal.Date */
.highlight .m { color: #ae81ff } /* Literal.Number */
.highlight .s { color: #e6db74 } /* Literal.String */
.highlight .na { color: #a6e22e } /* Name.Attribute */
.highlight .nb { color: #f8f8f2 } /* Name.Builtin */
.highlight .nc { color: #a6e22e } /* Name.Class */
.highlight .no { color: #66d9ef } /* Name.Constant */
.highlight .nd { color: #a6e22e } /* Name.Decorator */
.highlight .ni { color: #f8f8f2 } /* Name.Entity */
.highlight .ne { color: #a6e22e } /* Name.Exception */
.highlight .nf { color: #a6e22e } /* Name.Function */
.highlight .nl { color: #f8f8f2 } /* Name.Label */
.highlight .nn { color: #f8f8f2 } /* Name.Namespace */
.highlight .nx { color: #a6e22e } /* Name.Other */
.highlight .py { color: #f8f8f2 } /* Name.Property */
.highlight .nt { color: #f92672 } /* Name.Tag */
.highlight .nv { color: #f8f8f2 } /* Name.Variable */
.highlight .ow { color: #f92672 } /* Operator.Word */
.highlight .w { color: #f8f8f2 } /* Text.Whitespace */
.highlight .mb { color: #ae81ff } /* Literal.Number.Bin */
.highlight .mf { color: #ae81ff } /* Literal.Number.Float */
.highlight .mh { color: #ae81ff } /* Literal.Number.Hex */
.highlight .mi { color: #ae81ff } /* Literal.Number.Integer */
.highlight .mo { color: #ae81ff } /* Literal.Number.Oct */
.highlight .sa { color: #e6db74 } /* Literal.String.Affix */
.highlight .sb { color: #e6db74 } /* Literal.String.Backtick */
.highlight .sc { color: #e6db74 } /* Literal.String.Char */
.highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */
.highlight .sd { color: #e6db74 } /* Literal.String.Doc */
.highlight .s2 { color: #e6db74 } /* Literal.String.Double */
.highlight .se { color: #ae81ff } /* Literal.String.Escape */
.highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */
.highlight .si { color: #e6db74 } /* Literal.String.Interpol */
.highlight .sx { color: #e6db74 } /* Literal.String.Other */
.highlight .sr { color: #e6db74 } /* Literal.String.Regex */
.highlight .s1 { color: #e6db74 } /* Literal.String.Single */
.highlight .ss { color: #e6db74 } /* Literal.String.Symbol */
.highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #a6e22e } /* Name.Function.Magic */
.highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */
.highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */
.highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */
.highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */
.highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */
}
@media (prefers-color-scheme: light) {
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
}
# Copyright (c) 2021 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.

"""Generation of Continuous Performance Trending and Analysis.
"""

import re
import logging
import csv

from collections import OrderedDict
from datetime import datetime
from copy import deepcopy

import prettytable
import plotly.offline as ploff
import plotly.graph_objs as plgo
import plotly.exceptions as plerr

from pal_utils import archive_input_data, execute_command, classify_anomalies


# Command to build the html format of the report
HTML_BUILDER = u'sphinx-build -v -c sphinx_conf/trending -a ' \
               u'-b html -E ' \
               u'-t html ' \
               u'-D version="{date}" ' \
               u'{working_dir} ' \
               u'{build_dir}/'

# .css file for the html format of the report
THEME_OVERRIDES = u"""/* override table width restrictions */
.wy-nav-content {
    max-width: 1200px !important;
}
.rst-content blockquote {
    margin-left: 0px;
    line-height: 18px;
    margin-bottom: 0px;
}
.wy-menu-vertical a {
    display: inline-block;
    line-height: 18px;
    padding: 0 2em;
    display: block;
    position: relative;
    font-size: 90%;
    color: #d9d9d9
}
.wy-menu-vertical li.current a {
    color: gray;
    border-right: solid 1px #c9c9c9;
    padding: 0 3em;
}
.wy-menu-vertical li.toctree-l2.current > a {
    background: #c9c9c9;
    padding: 0 3em;
}
.wy-menu-vertical li.toctree-l2.current li.toctree-l3 > a {
    display: block;
    background: #c9c9c9;
    padding: 0 4em;
}
.wy-menu-vertical li.toctree-l3.current li.toctree-l4 > a {
    display: block;
    background: #bdbdbd;
    padding: 0 5em;
}
.wy-menu-vertical li.on a, .wy-menu-vertical li.current > a {
    color: #404040;
    padding: 0 2em;
    font-weight: bold;
    position: relative;
    background: #fcfcfc;
    border: none;
        border-top-width: medium;
        border-bottom-width: medium;
        border-top-style: none;
        border-bottom-style: none;
        border-top-color: currentcolor;
        border-bottom-color: currentcolor;
    padding-left: 2em -4px;
}
"""

COLORS = (
    u"#1A1110",
    u"#DA2647",
    u"#214FC6",
    u"#01786F",
    u"#BD8260",
    u"#FFD12A",
    u"#A6E7FF",
    u"#738276",
    u"#C95A49",
    u"#FC5A8D",
    u"#CEC8EF",
    u"#391285",
    u"#6F2DA8",
    u"#FF878D",
    u"#45A27D",
    u"#FFD0B9",
    u"#FD5240",
    u"#DB91EF",
    u"#44D7A8",
    u"#4F86F7",
    u"#84DE02",
    u"#FFCFF1",
    u"#614051"
)


def generate_cpta(spec, data):
    """Generate all formats and versions of the Continuous Performance Trending
    and Analysis.

    :param spec: Specification read from the specification file.
    :param data: Full data set.
    :type spec: Specification
    :type data: InputData
    """

    logging.info(u"Generating the Continuous Performance Trending and Analysis "
                 u"...")

    ret_code = _generate_all_charts(spec, data)

    cmd = HTML_BUILDER.format(
        date=datetime.utcnow().strftime(u'%Y-%m-%d %H:%M UTC'),
        working_dir=spec.environment[u'paths'][u'DIR[WORKING,SRC]'],
        build_dir=spec.environment[u'paths'][u'DIR[BUILD,HTML]'])
    execute_command(cmd)

    with open(spec.environment[u'paths'][u'DIR[CSS_PATCH_FILE]'], u'w') as \
            css_file:
        css_file.write(THEME_OVERRIDES)

    with open(spec.environment[u'paths'][u'DIR[CSS_PATCH_FILE2]'], u'w') as \
            css_file:
        css_file.write(THEME_OVERRIDES)

    if spec.environment.get(u"archive-inputs", False):
        archive_input_data(spec)

    logging.info(u"Done.")

    return ret_code


def _generate_trending_traces(in_data, job_name, build_info,
                              name=u"", color=u"", incl_tests=u"mrr"):
    """Generate the trending traces:
     - samples,
     - outliers, regress, progress
     - average of normal samples (trending line)

    :param in_data: Full data set.
    :param job_name: The name of job which generated the data.
    :param build_info: Information about the builds.
    :param name: Name of the plot
    :param color: Name of the color for the plot.
    :param incl_tests: Included tests, accepted values: mrr, ndr, pdr
    :type in_data: OrderedDict
    :type job_name: str
    :type build_info: dict
    :type name: str
    :type color: str
    :type incl_tests: str
    :returns: Generated traces (list) and the evaluated result.
    :rtype: tuple(traces, result)
    """

    if incl_tests not in (u"mrr", u"ndr", u"pdr"):
        return list(), None

    data_x = list(in_data.keys())
    data_y_pps = list()
    data_y_mpps = list()
    data_y_stdev = list()
    for item in in_data.values():
        data_y_pps.append(float(item[u"receive-rate"]))
        data_y_stdev.append(float(item[u"receive-stdev"]) / 1e6)
        data_y_mpps.append(float(item[u"receive-rate"]) / 1e6)

    hover_text = list()
    xaxis = list()
    for index, key in enumerate(data_x):
        str_key = str(key)
        date = build_info[job_name][str_key][0]
        hover_str = (u"date: {date}<br>"
                     u"{property} [Mpps]: {value:.3f}<br>"
                     u"<stdev>"
                     u"{sut}-ref: {build}<br>"
                     u"csit-ref: {test}-{period}-build-{build_nr}<br>"
                     u"testbed: {testbed}")
        if incl_tests == u"mrr":
            hover_str = hover_str.replace(
                u"<stdev>", f"stdev [Mpps]: {data_y_stdev[index]:.3f}<br>"
            )
        else:
            hover_str = hover_str.replace(u"<stdev>", u"")
        if u"-cps" in name:
            hover_str = hover_str.replace(u"[Mpps]", u"[Mcps]")
        if u"dpdk" in job_name:
            hover_text.append(hover_str.format(
                date=date,
                property=u"average" if incl_tests == u"mrr" else u"throughput",
                value=data_y_mpps[index],
                sut=u"dpdk",
                build=build_info[job_name][str_key][1].rsplit(u'~', 1)[0],
                test=incl_tests,
                period=u"weekly",
                build_nr=str_key,
                testbed=build_info[job_name][str_key][2]))
        elif u"vpp" in job_name:
            hover_str = hover_str.format(
                date=date,
                property=u"average" if incl_tests == u"mrr" else u"throughput",
                value=data_y_mpps[index],
                sut=u"vpp",
                build=build_info[job_name][str_key][1].rsplit(u'~', 1)[0],
                test=incl_tests,
                period=u"daily" if incl_tests == u"mrr" else u"weekly",
                build_nr=str_key,
                testbed=build_info[job_name][str_key][2])
            if u"-cps" in name:
                hover_str = hover_str.replace(u"throughput", u"connection rate")
            hover_text.append(hover_str)

        xaxis.append(datetime(int(date[0:4]), int(date[4:6]), int(date[6:8]),
                              int(date[9:11]), int(date[12:])))

    data_pd = OrderedDict()
    for key, value in zip(xaxis, data_y_pps):
        data_pd[key] = value

    anomaly_classification, avgs_pps, stdevs_pps = classify_anomalies(data_pd)
    avgs_mpps = [avg_pps / 1e6 for avg_pps in avgs_pps]
    stdevs_mpps = [stdev_pps / 1e6 for stdev_pps in stdevs_pps]

    anomalies = OrderedDict()
    anomalies_colors = list()
    anomalies_avgs = list()
    anomaly_color = {
        u"regression": 0.0,
        u"normal": 0.5,
        u"progression": 1.0
    }
    if anomaly_classification:
        for index, (key, value) in enumerate(data_pd.items()):
            if anomaly_classification[index] in (u"regression", u"progression"):
                anomalies[key] = value / 1e6
                anomalies_colors.append(
                    anomaly_color[anomaly_classification[index]])
                anomalies_avgs.append(avgs_mpps[index])
        anomalies_colors.extend([0.0, 0.5, 1.0])

    # Create traces

    trace_samples = plgo.Scatter(
        x=xaxis,
        y=data_y_mpps,
        mode=u"markers",
        line={
            u"width": 1
        },
        showlegend=True,
        legendgroup=name,
        name=f"{name}",
        marker={
            u"size": 5,
            u"color": color,
            u"symbol": u"circle",
        },
        text=hover_text,
        hoverinfo=u"text+name"
    )
    traces = [trace_samples, ]

    trend_hover_text = list()
    for idx in range(len(data_x)):
        trend_hover_str = (
            f"trend [Mpps]: {avgs_mpps[idx]:.3f}<br>"
            f"stdev [Mpps]: {stdevs_mpps[idx]:.3f}"
        )
        trend_hover_text.append(trend_hover_str)

    trace_trend = plgo.Scatter(
        x=xaxis,
        y=avgs_mpps,
        mode=u"lines",
        line={
            u"shape": u"linear",
            u"width": 1,
            u"color": color,
        },
        showlegend=False,
        legendgroup=name,
        name=f"{name}",
        text=trend_hover_text,
        hoverinfo=u"text+name"
    )
    traces.append(trace_trend)

    trace_anomalies = plgo.Scatter(
        x=list(anomalies.keys()),
        y=anomalies_avgs,
        mode=u"markers",
        hoverinfo=u"none",
        showlegend=False,
        legendgroup=name,
        name=f"{name}-anomalies",
        marker={
            u"size": 15,
            u"symbol": u"circle-open",
            u"color": anomalies_colors,
            u"colorscale": [
                [0.00, u"red"],
                [0.33, u"red"],
                [0.33, u"white"],
                [0.66, u"white"],
                [0.66, u"green"],
                [1.00, u"green"]
            ],
            u"showscale": True,
            u"line": {
                u"width": 2
            },
            u"colorbar": {
                u"y": 0.5,
                u"len": 0.8,
                u"title": u"Circles Marking Data Classification",
                u"titleside": u"right",
                u"titlefont": {
                    u"size": 14
                },
                u"tickmode": u"array",
                u"tickvals": [0.167, 0.500, 0.833],
                u"ticktext": [u"Regression", u"Normal", u"Progression"],
                u"ticks": u"",
                u"ticklen": 0,
                u"tickangle": -90,
                u"thickness": 10
            }
        }
    )
    traces.append(trace_anomalies)

    if anomaly_classification:
        return traces, anomaly_classification[-1]

    return traces, None


def _generate_all_charts(spec, input_data):
    """Generate all charts specified in the specification file.

    :param spec: Specification.
    :param input_data: Full data set.
    :type spec: Specification
    :type input_data: InputData
    """

    def _generate_chart(graph):
        """Generates the chart.

        :param graph: The graph to be generated
        :type graph: dict
        :returns: Dictionary with the job name, csv table with results and
            list of tests classification results.
        :rtype: dict
        """

        logging.info(f"  Generating the chart {graph.get(u'title', u'')} ...")

        job_name = list(graph[u"data"].keys())[0]

        # Transform the data
        logging.info(
            f"    Creating the data set for the {graph.get(u'type', u'')} "
            f"{graph.get(u'title', u'')}."
        )

        data = input_data.filter_tests_by_name(
            graph,
            params=[u"type", u"result", u"throughput", u"tags"],
            continue_on_error=True
        )

        if data is None or data.empty:
            logging.error(u"No data.")
            return dict()

        return_lst = list()

        for ttype in graph.get(u"test-type", (u"mrr", )):
            for core in graph.get(u"core", tuple()):
                csv_tbl = list()
                res = dict()
                chart_data = dict()
                chart_tags = dict()
                for item in graph.get(u"include", tuple()):
                    reg_ex = re.compile(str(item.format(core=core)).lower())
                    for job, job_data in data.items():
                        if job != job_name:
                            continue
                        for index, bld in job_data.items():
                            for test_id, test in bld.items():
                                if not re.match(reg_ex, str(test_id).lower()):
                                    continue
                                if chart_data.get(test_id, None) is None:
                                    chart_data[test_id] = OrderedDict()
                                try:
                                    if ttype == u"mrr":
                                        rate = test[u"result"][u"receive-rate"]
                                        stdev = \
                                            test[u"result"][u"receive-stdev"]
                                    elif ttype == u"ndr":
                                        rate = \
                                            test["throughput"][u"NDR"][u"LOWER"]
                                        stdev = float(u"nan")
                                    elif ttype == u"pdr":
                                        rate = \
                                            test["throughput"][u"PDR"][u"LOWER"]
                                        stdev = float(u"nan")
                                    else:
                                        continue
                                    chart_data[test_id][int(index)] = {
                                        u"receive-rate": rate,
                                        u"receive-stdev": stdev
                                    }
                                    chart_tags[test_id] = \
                                        test.get(u"tags", None)
                                except (KeyError, TypeError):
                                    pass

                # Add items to the csv table:
                for tst_name, tst_data in chart_data.items():
                    tst_lst = list()
                    for bld in builds_dict[job_name]:
                        itm = tst_data.get(int(bld), dict())
                        # CSIT-1180: Itm will be list, compute stats.
                        try:
                            tst_lst.append(str(itm.get(u"receive-rate", u"")))
                        except AttributeError:
                            tst_lst.append(u"")
                    csv_tbl.append(f"{tst_name}," + u",".join(tst_lst) + u'\n')

                # Generate traces:
                traces = list()
                index = 0
                groups = graph.get(u"groups", None)
                visibility = list()

                if groups:
                    for group in groups:
                        visible = list()
                        for tag in group:
                            for tst_name, test_data in chart_data.items():
                                if not test_data:
                                    logging.warning(
                                        f"No data for the test {tst_name}"
                                    )
                                    continue
                                if tag not in chart_tags[tst_name]:
                                    continue
                                try:
                                    trace, rslt = _generate_trending_traces(
                                        test_data,
                                        job_name=job_name,
                                        build_info=build_info,
                                        name=u'-'.join(tst_name.split(u'.')[-1].
                                                       split(u'-')[2:-1]),
                                        color=COLORS[index],
                                        incl_tests=ttype
                                    )
                                except IndexError:
                                    logging.error(f"Out of colors: index: "
                                                  f"{index}, test: {tst_name}")
                                    index += 1
                                    continue
                                traces.extend(trace)
                                visible.extend(
                                    [True for _ in range(len(trace))]
                                )
                                res[tst_name] = rslt
                                index += 1
                                break
                        visibility.append(visible)
                else:
                    for tst_name, test_data in chart_data.items():
                        if not test_data:
                            logging.warning(f"No data for the test {tst_name}")
                            continue
                        try:
                            trace, rslt = _generate_trending_traces(
                                test_data,
                                job_name=job_name,
                                build_info=build_info,
                                name=u'-'.join(
                                    tst_name.split(u'.')[-1].split(u'-')[2:-1]),
                                color=COLORS[index],
                                incl_tests=ttype
                            )
                        except IndexError:
                            logging.error(
                                f"Out of colors: index: "
                                f"{index}, test: {tst_name}"
                            )
                            index += 1
                            continue
                        traces.extend(trace)
                        res[tst_name] = rslt
                        index += 1

                if traces:
                    # Generate the chart:
                    try:
                        layout = deepcopy(graph[u"layout"])
                    except KeyError as err:
                        logging.error(u"Finished with error: No layout defined")
                        logging.error(repr(err))
                        return dict()
                    if groups:
                        show = list()
                        for i in range(len(visibility)):
                            visible = list()
                            for vis_idx, _ in enumerate(visibility):
                                for _ in range(len(visibility[vis_idx])):
                                    visible.append(i == vis_idx)
                            show.append(visible)

                        buttons = list()
                        buttons.append(dict(
                            label=u"All",
                            method=u"update",
                            args=[{u"visible":
                                       [True for _ in range(len(show[0]))]}, ]
                        ))
                        for i in range(len(groups)):
                            try:
                                label = graph[u"group-names"][i]
                            except (IndexError, KeyError):
                                label = f"Group {i + 1}"
                            buttons.append(dict(
                                label=label,
                                method=u"update",
                                args=[{u"visible": show[i]}, ]
                            ))

                        layout[u"updatemenus"] = list([
                            dict(
                                active=0,
                                type=u"dropdown",
                                direction=u"down",
                                xanchor=u"left",
                                yanchor=u"bottom",
                                x=-0.12,
                                y=1.0,
                                buttons=buttons
                            )
                        ])

                    name_file = (
                        f"{spec.cpta[u'output-file']}/"
                        f"{graph[u'output-file-name']}.html"
                    )
                    name_file = name_file.format(core=core, test_type=ttype)

                    logging.info(f"    Writing the file {name_file}")
                    plpl = plgo.Figure(data=traces, layout=layout)
                    try:
                        ploff.plot(
                            plpl,
                            show_link=False,
                            auto_open=False,
                            filename=name_file
                        )
                    except plerr.PlotlyEmptyDataError:
                        logging.warning(u"No data for the plot. Skipped.")

                return_lst.append(
                    {
                        u"job_name": job_name,
                        u"csv_table": csv_tbl,
                        u"results": res
                    }
                )

        return return_lst

    builds_dict = dict()
    for job, builds in spec.input.items():
        if builds_dict.get(job, None) is None:
            builds_dict[job] = list()
        for build in builds:
            if build[u"status"] not in (u"failed", u"not found", u"removed",
                                        None):
                builds_dict[job].append(str(build[u"build"]))

    # Create "build ID": "date" dict:
    build_info = dict()
    tb_tbl = spec.environment.get(u"testbeds", None)
    for job_name, job_data in builds_dict.items():
        if build_info.get(job_name, None) is None:
            build_info[job_name] = OrderedDict()
        for build in job_data:
            testbed = u""
            tb_ip = input_data.metadata(job_name, build).get(u"testbed", u"")
            if tb_ip and tb_tbl:
                testbed = tb_tbl.get(tb_ip, u"")
            build_info[job_name][build] = (
                input_data.metadata(job_name, build).get(u"generated", u""),
                input_data.metadata(job_name, build).get(u"version", u""),
                testbed
            )

    anomaly_classifications = dict()

    # Create the table header:
    csv_tables = dict()
    for job_name in builds_dict:
        if csv_tables.get(job_name, None) is None:
            csv_tables[job_name] = list()
        header = f"Build Number:,{u','.join(builds_dict[job_name])}\n"
        csv_tables[job_name].append(header)
        build_dates = [x[0] for x in build_info[job_name].values()]
        header = f"Build Date:,{u','.join(build_dates)}\n"
        csv_tables[job_name].append(header)
        versions = [x[1] for x in build_info[job_name].values()]
        header = f"Version:,{u','.join(versions)}\n"
        csv_tables[job_name].append(header)

    for chart in spec.cpta[u"plots"]:
        results = _generate_chart(chart)
        if not results:
            continue

        for result in results:
            csv_tables[result[u"job_name"]].extend(result[u"csv_table"])

            if anomaly_classifications.get(result[u"job_name"], None) is None:
                anomaly_classifications[result[u"job_name"]] = dict()
            anomaly_classifications[result[u"job_name"]].\
                update(result[u"results"])

    # Write the tables:
    for job_name, csv_table in csv_tables.items():
        file_name = f"{spec.cpta[u'output-file']}/{job_name}-trending"
        with open(f"{file_name}.csv", u"wt") as file_handler:
            file_handler.writelines(csv_table)

        txt_table = None
        with open(f"{file_name}.csv", u"rt") as csv_file:
            csv_content = csv.reader(csv_file, delimiter=u',', quotechar=u'"')
            line_nr = 0
            for row in csv_content:
                if txt_table is None:
                    txt_table = prettytable.PrettyTable(row)
                else:
                    if line_nr > 1:
                        for idx, item in enumerate(row):
                            try:
                                row[idx] = str(round(float(item) / 1000000, 2))
                            except ValueError:
                                pass
                    try:
                        txt_table.add_row(row)
                    # PrettyTable raises Exception
                    except Exception as err:
                        logging.warning(
                            f"Error occurred while generating TXT table:\n{err}"
                        )
                line_nr += 1
            txt_table.align[u"Build Number:"] = u"l"
        with open(f"{file_name}.txt", u"wt") as txt_file:
            txt_file.write(str(txt_table))

    # Evaluate result:
    if anomaly_classifications:
        result = u"PASS"
        for job_name, job_data in anomaly_classifications.items():
            file_name = \
                f"{spec.cpta[u'output-file']}/regressions-{job_name}.txt"
            with open(file_name, u'w') as txt_file:
                for test_name, classification in job_data.items():
                    if classification == u"regression":
                        txt_file.write(test_name + u'\n')
                    if classification in (u"regression", u"outlier"):
                        result = u"FAIL"
            file_name = \
                f"{spec.cpta[u'output-file']}/progressions-{job_name}.txt"
            with open(file_name, u'w') as txt_file:
                for test_name, classification in job_data.items():
                    if classification == u"progression":
                        txt_file.write(test_name + u'\n')
    else:
        result = u"FAIL"

    logging.info(f"Partial results: {anomaly_classifications}")
    logging.info(f"Result: {result}")

    return result