#7 Store testcase-stats also as JSON
Merged 3 years ago by adamwill. Opened 3 years ago by jskladan.
Unknown source master  into  master

file modified
+9
@@ -30,6 +30,7 @@

  import tempfile

  from collections import defaultdict, OrderedDict

  from operator import attrgetter

+ import json

  

  import relval.user_stats as uss

  import relval.testcase_stats as tcs
@@ -433,6 +434,7 @@

      # identifying the compose from which it comes). Result rows for which

      # all three attributes match are grouped together - they're considered

      # to be results for the same test in different composes.

+     jsondata = {'allcomposes': allcomposes, 'stats': dict()}

      for index, (testtype, pages) in enumerate(allpages.items()):

          print('Processing type [{0}/{1}]: {2}'.format(index + 1,

              len(allpages), testtype))
@@ -456,8 +458,12 @@

              print("Post-processing results...")

              tests = tcs.post_process(tests, allcomposes)

          tcs.print_results_html(testtype, pages, allcomposes, tests, outdir)

+         jsondata['stats'][testtype] = tcs.get_results_data(allcomposes, tests)

  

      tcs.print_summary_html(outdir, allpages)

+     with open(os.path.join(outdir, 'data.json'), 'w') as outfile:

+         json.dump(jsondata, outfile, sort_keys=True, indent=4)

+ 

      if args.out:

          try:

              shutil.rmtree(args.out)
@@ -470,11 +476,14 @@

              print("All output moved to: {0}".format(args.out))

              print("Index page at: {0}".format(os.path.join(args.out,

                                                             "index.html")))

+             print("JSON data at: {0}".format(os.path.join(args.out,

+                                                            "data.json")))

          except (PermissionError, FileExistsError):

              print("Could not write to: {0}! "

                    "Output is at: {1}".format(args.out, outdir))

      else:

          print("HTML Output: " + os.path.join(outdir, "index.html"))

+         print("JSON Output: " + os.path.join(outdir, "data.json"))

          print(outdir)

  

  def report_results(args, site):

file modified
+24
@@ -447,6 +447,30 @@

          template % {'timestamp': datetime.datetime.utcnow(), 'body': body})

      fout.close()

  

+ def get_results_data(allcomposes, tests):

+     """Returns a dictionary containing the testcase-stats, to be used

+     for the JSON formatted output."""

+     data = {}

+     for (name, testcase, section), test in tests.items():

+         # Look ma, no hands!

+         data.setdefault(section, list())

+         if testcase != name:

+             dispname = ' - ' + name

+         else:

+             dispname = ''

+         bitmap = {c: [0, 'n/a'] for c in allcomposes}

+         bitmap.update(test.bitmap)

+ 

+         trow = {

+             'testcase_url': 'https://fedoraproject.org/wiki/%s' % testcase,

+             'testcase_name': '%s%s' % (testcase, dispname),

+             'milestone': test.milestone,

+             'last_tested': test.last_tested,

+             'bitmap': bitmap,

+             }

+         data[section].append(trow)

+     return data

+ 

  def print_summary_html(outdir, allpages):

      """Despite the name, this writes the top-level index.html linking

      to the page for each test type.

Adds JSON-formatted output of testcase-stats on top of the current HTML output. We want to be able to consume the testcase-stats data, and parsing the HTML sounds like a pointless exercise, when one could have the "machine-readable" data at hand.

wat? this seems like you cargo-culted it over from the existing code but then modified it so it does nothing at all...

wat? this seems like you cargo-culted it over from the existing code but then modified it so it does nothing at all...

Gotta sanitize dem inputs :) But yes, you are of course not mistaken, dumb me forgot to delete those lines :( that's what you get for iterative development model :-P (will fix shortly, with any other issues there might be)

Can you change this to {0}? {} is not compatible with Python 2.6, which I still try to stay compatible with.

Also, just printing this here is not quite correct. See how we print something different depending on whether args.out is specified - if args.out is specified, the JSON output will not actually wind up in outdir/data.json as we will move it to args.out/data.json . So please just handle this exactly like index.html - add a line for data.json below each of the two index.html lines.

Much better now. Hopefully.

1 new commit added

  • Fixed to meet common standards!
3 years ago

Pull-Request has been merged by adamwill

3 years ago

Deployed to prod now. Find data here.