#! /usr/local/bin/python # Tony Pasqualoni / Sept. 20, 2006 import os import sys import re def parse (text): p_values = [] p_values_float = [] p_value_amt = 269 # use 269 if additional tests (e.g. Gorilla) are included, otherwise 229 # minimum and maximum p-values for 95% confidence interval min = 0.0001 max = 0.9999 tag = 'RESULTS OF CRAPS TEST2 for ' p = re.compile( tag + '\S+' ) match = p.search(text) filename = match.group()[len(tag):] print "%30s " % (filename), first = 'All p-values:' last = 'Overall p-value after applying KStest on ' + str(p_value_amt) + ' p-values = ' first_index = text.index (first) + len(first) last_index = text.index (last) overall = text[last_index + len(last):last_index + len(last) + 8] print "%s " % (overall), p_values = text[first_index:last_index].split(',') failed = 0 for i in p_values: if not i.isspace(): i = i.strip() p_values_float.append( float(i) ) if float(i) <= min or float(i) >= max: failed += 1 if not len(p_values_float) == p_value_amt: print "Parse error, illegal list length: " + str(len(p_values_float)) sys.exit() p_values_float.sort() print "%3.6f " % (p_values_float[0]), print "%3.6f " % (p_values_float[len(p_values_float) - 1]), print "%3d of %3d" % (failed,p_value_amt) return (failed,p_value_amt) # ====================================================== results = [] f = open ('result.txt','r') results_file = f.read() if results_file.count('RESULTS OF BIRTHDAY SPACINGS') != results_file.count('Overall p-value'): print "parse-diehard.py: Parse error. Test summaries not equal to amount of tests in results.txt" sys.exit() results = results_file.split('several more times, or new, related tests should be undertaken.') extra = results.pop() if not extra.isspace(): print "* Warning: popped results but it's not whitespace: " print extra[:100] + "..." #sys.exit() # print headers: print print " P-values:" print "Filename: Overall: Low: High: Failures:" print # print p-value data for each data set in Diehard results file and print totals: total_failed = 0 total_p_values = 0 for i in results: (failed_amt,p_value_amt) = parse(i) total_failed += failed_amt total_p_values += p_value_amt print "\nFailed tests: %3d of %3d" % ( total_failed, total_p_values ) print sys.exit()