bug fix: score calculation based on build_tag
[releng.git] / utils / test / reporting / reporting / utils / reporting_utils.py
index 6c0d5a2..58a0c62 100644 (file)
@@ -6,7 +6,6 @@
 #
 # http://www.apache.org/licenses/LICENSE-2.0
 #
-from urllib2 import Request, urlopen, URLError
 import logging
 import json
 import os
@@ -14,6 +13,8 @@ import requests
 import pdfkit
 import yaml
 
+from urllib2 import Request, urlopen, URLError
+
 
 # ----------------------------------------------------------
 #
@@ -113,7 +114,8 @@ def getScenarios(project, case, installer, version):
     """
     Get the list of Scenarios
     """
-
+    test_results = None
+    scenario_results = None
     period = get_config('general.period')
     url_base = get_config('testapi.url')
 
@@ -186,7 +188,6 @@ def getScenarioStats(scenario_results):
 def getScenarioStatus(installer, version):
     """
     Get the status of a scenariofor Yardstick
-    they used criteria SUCCESS (default: PASS)
     """
     period = get_config('general.period')
     url_base = get_config('testapi.url')
@@ -228,7 +229,7 @@ def getScenarioStatus(installer, version):
                 # scenario_results[k] = v[:LASTEST_TESTS]
                 s_list = []
                 for element in scen_v:
-                    if element['criteria'] == 'SUCCESS':
+                    if element['criteria'] == 'PASS':
                         s_list.append(1)
                     else:
                         s_list.append(0)
@@ -285,7 +286,7 @@ def getNbtestOk(results):
     return nb_test_ok
 
 
-def getResult(testCase, installer, scenario, version):
+def getCaseScore(testCase, installer, scenario, version):
     """
     Get Result  for a given Functest Testcase
     """
@@ -344,6 +345,41 @@ def getResult(testCase, installer, scenario, version):
     return test_result_indicator
 
 
+def getCaseScoreFromBuildTag(testCase, s_results):
+    """
+    Get Results for a given Functest Testcase with arch filtering
+    """
+    url_base = get_config('testapi.url')
+    nb_tests = get_config('general.nb_iteration_tests_success_criteria')
+    test_result_indicator = 0
+    # architecture is not a result field...so we cannot use getResult as it is
+    res_matrix = []
+    try:
+        for s_result in s_results:
+            build_tag = s_result['build_tag']
+            d = s_result['start_date']
+            res_matrix.append({'date': d,
+                               'build_tag': build_tag})
+        # sort res_matrix
+        filter_res_matrix = sorted(res_matrix, key=lambda k: k['date'],
+                                   reverse=True)[:nb_tests]
+        for my_res in filter_res_matrix:
+            url = ("http://" + url_base + "?case=" + testCase +
+                   "&build_tag=" + my_res['build_tag'])
+            request = Request(url)
+            response = urlopen(request)
+            k = response.read()
+            results = json.loads(k)
+            if "PASS" in results['results'][0]['criteria']:
+                test_result_indicator += 1
+    except:
+        print "No results found for this case"
+    if test_result_indicator > 2:
+        test_result_indicator = test_result_indicator - 1
+
+    return test_result_indicator
+
+
 def getJenkinsUrl(build_tag):
     """
     Get Jenkins url_base corespoding to the last test CI run