Mercurial > hg > do-we-sing-like-we-speak
view processCSV.py @ 3:475bddaf580c tip
Add report and Presentation
author | Dave Moffat <d.j.moffat@qmul.ac.uk> |
---|---|
date | Wed, 25 Feb 2015 16:07:05 +0000 |
parents | 26494c0d9ffd |
children |
line wrap: on
line source
#!/usr/bin/python # # processCSV.py: analyse the results and return results breakdown for a given question type # # Usage: processCSV.py questionType intonationPattern # If no intonation pattern or question type is given, then all results are presented. # # Example: processCSV.py # Example: processCSV.py 'Wh' # Example: processCSV.py 'Wh' 'F' # Possible Questions: 'Echo', 'Wh', 'YN' # Possible Intonations: 'RF', 'FR', 'F', 'R', 'H' import csv import sys import matplotlib.pyplot as plt import numpy as np if __name__=="__main__": #Load Command Line Parameters intPattern = None; qType = None; if len(sys.argv) > 2: intPattern = [sys.argv[2]] else: intPattern = ['RF', 'FR', 'F', 'R', 'H'] if len(sys.argv) > 1: qType = [sys.argv[1]] else: qType = ['Echo', 'Wh', 'YN'] #print(intPattern) #print(qType) reader = csv.DictReader(open('DataSetSummary.csv')) result = {} for row in reader: for column, value in row.iteritems(): result.setdefault(column, []).append(value) #print result['QType'] for q in qType: qList = [j for j, x in enumerate(result['QType']) if x == q] # print "%s count = %d" % (q, len(qList)) for i in intPattern: iList = [j for j, x in enumerate(result['Intonation']) if x == i] count = 0 tracks = [] if (iList) != None: for il in iList: if il in qList: count +=1 tracks.append(il) # print (i + ' vs. '+q+'=%d', count) # if count > 0: print "%s vs. %s = %d" % (q, i, count) print tracks # for t in tracks: # trackName = "T%d/01.csv" % (t) # trackReader = csv.reader(open(trackName)) # xList = [] # yList = [] # for r in trackReader: ## print "In trackReader" ## print(r) ## print(r[1]) # xList.append(r[0]) ## xList = [float(x) for x in xList] # yList.append(r[1]) ## yList = [float(y) for y in yList] # # Apply some smoothing and scaling # # Vertical # print yList # print min(yList) # yList = np.subtract(yList, min(yList)) # print yList # yList = np.divide(yList, max(yList)) # print yList # # Horizontal # xList = np.subtract(xList, min(xList)) # xList = np.divide(xList, max(xList)) # # # plt.plot(xList,yList) # plt.show() #result = {} #for row in reader: # print(row) # key = row[1] ## if key in result: ## # implement your duplicate row handling here ## pass # result[key] = row[1:] #print result