Christophe Favergeon | 37b8622 | 2019-07-17 11:49:00 +0200 | [diff] [blame] | 1 | # Process the test results |
| 2 | # Test status (like passed, or failed with error code) |
| 3 | |
| 4 | import argparse |
| 5 | import re |
| 6 | import TestScripts.NewParser as parse |
| 7 | import TestScripts.CodeGen |
| 8 | from collections import deque |
| 9 | import os.path |
| 10 | import numpy as np |
| 11 | import pandas as pd |
| 12 | import statsmodels.api as sm |
| 13 | import statsmodels.formula.api as smf |
| 14 | import csv |
| 15 | import TestScripts.Deprecate as d |
| 16 | |
| 17 | result = [] |
| 18 | commonParams = [] |
| 19 | |
| 20 | def findItem(root,path): |
| 21 | """ Find a node in a tree |
| 22 | |
| 23 | Args: |
| 24 | path (list) : A list of node ID |
| 25 | This list is describing a path in the tree. |
| 26 | By starting from the root and following this path, |
| 27 | we can find the node in the tree. |
| 28 | Raises: |
| 29 | Nothing |
| 30 | Returns: |
| 31 | TreeItem : A node |
| 32 | """ |
| 33 | # The list is converted into a queue. |
| 34 | q = deque(path) |
| 35 | q.popleft() |
| 36 | c = root |
| 37 | while q: |
| 38 | n = q.popleft() |
| 39 | # We get the children based on its ID and continue |
| 40 | c = c[n-1] |
| 41 | return(c) |
| 42 | |
| 43 | |
| 44 | |
| 45 | NORMAL = 1 |
| 46 | INTEST = 2 |
| 47 | TESTPARAM = 3 |
| 48 | |
| 49 | def joinit(iterable, delimiter): |
| 50 | it = iter(iterable) |
| 51 | yield next(it) |
| 52 | for x in it: |
| 53 | yield delimiter |
| 54 | yield x |
| 55 | |
| 56 | def formatProd(a,b): |
| 57 | if a == "Intercept": |
| 58 | return(str(b)) |
| 59 | return("%s * %s" % (a,b)) |
| 60 | |
| 61 | def convert(elem,fullPath): |
| 62 | global commonParams |
| 63 | global result |
| 64 | regressionPath=os.path.join(os.path.dirname(fullPath),"regression.csv") |
| 65 | full=pd.read_csv(fullPath,dtype={'OLDID': str} ,keep_default_na = False) |
| 66 | reg=pd.read_csv(regressionPath,dtype={'OLDID': str} ,keep_default_na = False) |
| 67 | commonParams = list(joinit(elem.params.full,",")) |
| 68 | header = ["OLDID"] + commonParams + ["CYCLES"] |
| 69 | |
| 70 | r=full[header].rename(columns = {"OLDID":"TESTNB"}) |
| 71 | r["TESTNB"] = pd.to_numeric(r["TESTNB"]) |
| 72 | r["PASSED"]=1 |
| 73 | result.append(r) |
| 74 | |
| 75 | |
| 76 | def extractBenchmarks(benchmark,elem): |
| 77 | if not elem.data["deprecated"]: |
| 78 | if elem.params: |
| 79 | benchPath = os.path.join(benchmark,elem.fullPath(),"fullBenchmark.csv") |
| 80 | print("Processing %s" % benchPath) |
| 81 | convert(elem,benchPath) |
| 82 | |
| 83 | for c in elem.children: |
| 84 | extractBenchmarks(benchmark,c) |
| 85 | |
| 86 | |
| 87 | |
| 88 | parser = argparse.ArgumentParser(description='Generate summary benchmarks') |
| 89 | |
| 90 | parser.add_argument('-f', nargs='?',type = str, default=None, help="Test description file path") |
| 91 | parser.add_argument('-b', nargs='?',type = str, default="FullBenchmark", help="Full Benchmark dir path") |
| 92 | parser.add_argument('-e', action='store_true', help="Embedded test") |
| 93 | parser.add_argument('-o', nargs='?',type = str, default="bench.csv", help="Output csv file using old format") |
| 94 | |
| 95 | parser.add_argument('others', nargs=argparse.REMAINDER) |
| 96 | |
| 97 | args = parser.parse_args() |
| 98 | |
| 99 | if args.f is not None: |
| 100 | p = parse.Parser() |
| 101 | # Parse the test description file |
| 102 | root = p.parse(args.f) |
| 103 | d.deprecate(root,args.others) |
| 104 | extractBenchmarks(args.b,root) |
| 105 | finalResult = pd.concat(result) |
| 106 | cols = ['TESTNB'] + commonParams |
| 107 | finalResult=finalResult.sort_values(by=cols) |
| 108 | finalResult.to_csv(args.o,index=False,quoting=csv.QUOTE_NONNUMERIC) |
| 109 | |
| 110 | else: |
| 111 | parser.print_help() |