convertToOld.py 3.1 KB

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