d@0: d@0: #!/usr/bin/python d@0: # d@0: # processCSV.py: analyse the results and return results breakdown for a given question type d@0: # d@0: # Usage: processCSV.py questionType intonationPattern d@0: # If no intonation pattern or question type is given, then all results are presented. d@0: # d@0: # Example: processCSV.py d@0: # Example: processCSV.py 'Wh' d@0: # Example: processCSV.py 'Wh' 'F' d@0: # Possible Questions: 'Echo', 'Wh', 'YN' d@0: # Possible Intonations: 'RF', 'FR', 'F', 'R', 'H' d@0: d@0: d@0: d@0: import csv d@0: import sys d@0: import matplotlib.pyplot as plt d@0: import numpy as np d@0: d@0: d@0: if __name__=="__main__": d@0: #Load Command Line Parameters d@0: intPattern = None; d@0: qType = None; d@0: d@0: if len(sys.argv) > 2: d@0: intPattern = [sys.argv[2]] d@0: else: d@0: intPattern = ['RF', 'FR', 'F', 'R', 'H'] d@0: if len(sys.argv) > 1: d@0: qType = [sys.argv[1]] d@0: else: d@0: qType = ['Echo', 'Wh', 'YN'] d@0: d@0: #print(intPattern) d@0: #print(qType) d@0: d@0: d@0: reader = csv.DictReader(open('DataSetSummary.csv')) d@0: d@0: result = {} d@0: for row in reader: d@0: for column, value in row.iteritems(): d@0: result.setdefault(column, []).append(value) d@0: #print result['QType'] d@0: d@0: for q in qType: d@0: qList = [j for j, x in enumerate(result['QType']) if x == q] d@0: # print "%s count = %d" % (q, len(qList)) d@0: for i in intPattern: d@0: iList = [j for j, x in enumerate(result['Intonation']) if x == i] d@0: count = 0 d@0: tracks = [] d@0: if (iList) != None: d@0: for il in iList: d@0: if il in qList: d@0: count +=1 d@0: tracks.append(il) d@0: # print (i + ' vs. '+q+'=%d', count) d@0: # if count > 0: d@0: print "%s vs. %s = %d" % (q, i, count) d@0: print tracks d@0: # for t in tracks: d@0: # trackName = "T%d/01.csv" % (t) d@0: # trackReader = csv.reader(open(trackName)) d@0: # xList = [] d@0: # yList = [] d@0: # for r in trackReader: d@0: ## print "In trackReader" d@0: ## print(r) d@0: ## print(r[1]) d@0: # xList.append(r[0]) d@0: ## xList = [float(x) for x in xList] d@0: # yList.append(r[1]) d@0: ## yList = [float(y) for y in yList] d@0: # # Apply some smoothing and scaling d@0: # # Vertical d@0: # print yList d@0: # print min(yList) d@0: # yList = np.subtract(yList, min(yList)) d@0: # print yList d@0: # yList = np.divide(yList, max(yList)) d@0: # print yList d@0: # # Horizontal d@0: # xList = np.subtract(xList, min(xList)) d@0: # xList = np.divide(xList, max(xList)) d@0: # d@0: # d@0: # plt.plot(xList,yList) d@0: # plt.show() d@0: d@0: #result = {} d@0: #for row in reader: d@0: # print(row) d@0: # key = row[1] d@0: ## if key in result: d@0: ## # implement your duplicate row handling here d@0: ## pass d@0: # result[key] = row[1:] d@0: #print result