resultsAggregatorScript.py 5.39 KB
Newer Older
Alan White committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
import os, csv

msgStatsHeader = ""
planStatsHeader = ""
stepStatsHeader = ""

msgStats = {}
stepStats = {}
planStats = {}


def traverse(root):
    for dirName, subDirList, fileList in os.walk(root):
        print('Found directory %s' % dirName)
        if len(fileList) > 0:
            handleExperiments(root, dirName, fileList)
    summaryDir = root + '/'
    displayStepStats(summaryDir)
    displayPlanStats(summaryDir)
    displayMsgStats(summaryDir)

def displayMsgStats(summaryDir):
    f = open(summaryDir+'msgStatSummary.csv', 'w')
    global msgStats
    global msgStatsHeader
    msgKeys = sorted(msgStats.keys())
    f.write(msgStatsHeader)
    for key in msgKeys:
        lines  = msgStats[key].keys()
        for lineSet in lines:
            for entry in msgStats[key][lineSet]:
                f.write("\n" + key + ", " + entry);
            f.write('\nAverage\nst.dev\np-value\n')
    f.close()

def displayPlanStats(summaryDir):
    f = open(summaryDir+'planStatSummary.csv', 'w')
    global planStats
    global planStatsHeader
    planKeys = sorted(planStats.keys())
    f.write(planStatsHeader)
    for key in planKeys:
        lines  = planStats[key].keys()
        for lineSet in lines:
            for entry in planStats[key][lineSet]:
                f.write("\n" + key + ", " + entry);
            f.write('\nAverage\nst.dev\np-value\n')
    f.close()

def displayStepStats(summaryDir):
    f = open(summaryDir+'stepStatSummary.csv', 'w')
    global stepStats
    global stepStatsHeader
    stepKeys = sorted(stepStats.keys())
    f.write(stepStatsHeader)
    for key in stepKeys:
        lines  = stepStats[key].keys()
        for lineSet in lines:
            for entry in stepStats[key][lineSet]:
                f.write("\n" + key + ", " + entry);
            f.write('\nAverage\nst.dev\np-value\n')
    f.close()

def handleExperiments(root, dirName, fileList):
    config, system, experimentNumber = experimentInfo(dirName.split('/'))
    msgSummary = []
    planSummary = []
    stepSummary = []
    for file in fileList:
        msgSummaryEntry, planSummaryEntry, stepSummaryEntry = handle(system, experimentNumber, dirName, file)
        if(len(msgSummaryEntry)>0):
            msgSummary.append(system + msgSummaryEntry)
        if(len(planSummaryEntry)>0):
            planSummary.append(system + planSummaryEntry)
        if(len(stepSummaryEntry)>0):
            stepSummary.append(system + stepSummaryEntry)
        addToDictionary(config, system, stepSummaryEntry, planSummaryEntry, msgSummaryEntry)

def experimentInfo(split):
    experimentNumber = split[len(split)-1]
    system = split[len(split)-2]
    config = split[len(split)-3]
    return config, system, experimentNumber

def handle(system, experimentNumber, dirName, file):
    msgSummaryEntry = ""
    planSummaryEntry = ""
    stepSummaryEntry = ""
    if file == "msgStats.txt":
        msgSummaryEntry = handleMsgStats(system, experimentNumber, dirName + "/" + file)
    elif file == "planStats.txt":
        planSummaryEntry = handlePlanStats(system, experimentNumber, dirName + "/" + file)
    elif file == "stepStats.txt":
        stepSummaryEntry = handleStepStats(system, experimentNumber, dirName + "/" + file)
    return msgSummaryEntry, planSummaryEntry, stepSummaryEntry

def handleMsgStats(system, experimentNumber, file):
    global msgStatsHeader
    statsFile = open(str(file))
    msgStatsHeader = updateHeader(msgStatsHeader, statsFile)
    summary = lastLine(statsFile)
    statsFile.close()
    return system + ", " + experimentNumber + ", " + summary

def handlePlanStats(system, experimentNumber, file):
    global planStatsHeader
    statsFile = open(str(file))
    planStatsHeader = updateHeader(planStatsHeader, statsFile)
    summary = lastLine(statsFile)
    statsFile.close()
    return system + ", " + experimentNumber + ", " + summary

def handleStepStats(system, experimentNumber, file):
    global stepStatsHeader
    statsFile = open(str(file))
    stepStatsHeader = updateHeader(stepStatsHeader, statsFile)
    summary = lastLine(statsFile)
    statsFile.close()
    return system + ", " + experimentNumber + ", " + summary

def updateHeader(header, statsFile):
    if(len(header)==0):
        return "nDebil, System, Run, " + statsFile.readline().rstrip('\n')
    else:
        return header

def lastLine(file):
    for line in file:
        pass
    return line.rstrip('\n')

def addToDictionary(config, system, stepSummaryEntry, planSummaryEntry, msgSummaryEntry):
    global msgStats
    global stepStats
    global planStats
    if(len(msgSummaryEntry)>0):
        msgStatsForApproach = msgStats.get(config, {})
        msgStatsSet = msgStatsForApproach.get(system, [])
        msgStatsSet.append(msgSummaryEntry)
        msgStatsForApproach[system] = msgStatsSet
        msgStats[config] = msgStatsForApproach
    if(len(planSummaryEntry)>0):
        planStatsForApproach = planStats.get(config, {})
        planStatsSet = planStatsForApproach.get(system, [])
        planStatsSet.append(planSummaryEntry)
        planStatsForApproach[system] = planStatsSet
        planStats[config] = planStatsForApproach
    if(len(stepSummaryEntry)>0):
        stepStatsForApproach = stepStats.get(config, {})
        stepStatsSet = stepStatsForApproach.get(system, [])
        stepStatsSet.append(stepSummaryEntry)
        stepStatsForApproach[system] = stepStatsSet
        stepStats[config] = stepStatsForApproach


if __name__=="__main__":
    import sys
    traverse(sys.argv[1])