trending: hotfix failing trending emails 56/34756/4
authorViliam Luc <vluc@cisco.com>
Thu, 16 Dec 2021 08:22:43 +0000 (09:22 +0100)
committerViliam Luc <vluc@cisco.com>
Fri, 17 Dec 2021 10:17:23 +0000 (11:17 +0100)
Legend was showing for each job_name. When trying to fix it
we broke the cpta with I/O operation. This fixes legend
positioning and I/O operation error.

Signed-off-by: Viliam Luc <vluc@cisco.com>
Change-Id: I809daa3eabe6a728e5e183630fc7c6615dfef8bf

resources/tools/presentation/generator_alerts.py
resources/tools/presentation/generator_cpta.py

index 9a0a03a..d22e7aa 100644 (file)
@@ -375,6 +375,30 @@ class Alerting:
             )
 
         text = u""
+
+        legend = (f"Legend:\n[ Last trend in Mpps | number of runs for "
+                  f"last trend |")
+
+        out_file = (
+            f"{self.configs[alert[u'way']][u'output-dir']}/"
+            f"trending-regressions.txt"
+        )
+        try:
+            with open(out_file, u'w') as reg_file:
+                reg_file.write(f"{legend} regressions ]")
+        except IOError:
+            logging.error(f"Not possible to write the file {out_file}.txt.")
+
+        out_file = (
+            f"{self.configs[alert[u'way']][u'output-dir']}/"
+            f"trending-progressions.txt"
+        )
+        try:
+            with open(out_file, u'w') as reg_file:
+                reg_file.write(f"{legend} progressions ]")
+        except IOError:
+            logging.error(f"Not possible to write the file {out_file}.txt.")
+
         for idx, test_set in enumerate(alert.get(u"include", list())):
             test_set_short = u""
             device = u""
index 923d56b..1a2dbaa 100644 (file)
@@ -838,8 +838,6 @@ def _generate_all_charts(spec, input_data):
 
     # Evaluate result:
     if anomaly_classifications:
-        legend_str = (f"Legend:\n[ Last trend in Mpps/Mcps | number of runs for"
-                      f" last trend | ")
         result = u"PASS"
         for job_name, job_data in anomaly_classifications.items():
             data = []
@@ -877,9 +875,6 @@ def _generate_all_charts(spec, input_data):
 
                     if classification in (u"regression", u"outlier"):
                         result = u"FAIL"
-
-            txt_file.write(f"\n{legend_str}regression in percentage ]")
-
             file_name = \
                 f"{spec.cpta[u'output-file']}/progressions-{job_name}.txt"
             with open(file_name, u'w') as txt_file:
@@ -904,8 +899,6 @@ def _generate_all_charts(spec, input_data):
                                 ltc = line.split("|")[4]
                                 txt_file.write(f"{tst_name} [ {trend}M | "
                                                f"#{number} | {ltc}% ]\n")
-
-            txt_file.write(f"\n{legend_str}progression in percentage ]")
     else:
         result = u"FAIL"