Mercurial > hg > do-we-sing-like-we-speak
comparison processCSV.py @ 0:26494c0d9ffd
Repo Creation
author | DaveM <d.j.moffat@qmul.ac.uk> |
---|---|
date | Wed, 14 Jan 2015 11:39:40 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:26494c0d9ffd |
---|---|
1 | |
2 #!/usr/bin/python | |
3 # | |
4 # processCSV.py: analyse the results and return results breakdown for a given question type | |
5 # | |
6 # Usage: processCSV.py questionType intonationPattern | |
7 # If no intonation pattern or question type is given, then all results are presented. | |
8 # | |
9 # Example: processCSV.py | |
10 # Example: processCSV.py 'Wh' | |
11 # Example: processCSV.py 'Wh' 'F' | |
12 # Possible Questions: 'Echo', 'Wh', 'YN' | |
13 # Possible Intonations: 'RF', 'FR', 'F', 'R', 'H' | |
14 | |
15 | |
16 | |
17 import csv | |
18 import sys | |
19 import matplotlib.pyplot as plt | |
20 import numpy as np | |
21 | |
22 | |
23 if __name__=="__main__": | |
24 #Load Command Line Parameters | |
25 intPattern = None; | |
26 qType = None; | |
27 | |
28 if len(sys.argv) > 2: | |
29 intPattern = [sys.argv[2]] | |
30 else: | |
31 intPattern = ['RF', 'FR', 'F', 'R', 'H'] | |
32 if len(sys.argv) > 1: | |
33 qType = [sys.argv[1]] | |
34 else: | |
35 qType = ['Echo', 'Wh', 'YN'] | |
36 | |
37 #print(intPattern) | |
38 #print(qType) | |
39 | |
40 | |
41 reader = csv.DictReader(open('DataSetSummary.csv')) | |
42 | |
43 result = {} | |
44 for row in reader: | |
45 for column, value in row.iteritems(): | |
46 result.setdefault(column, []).append(value) | |
47 #print result['QType'] | |
48 | |
49 for q in qType: | |
50 qList = [j for j, x in enumerate(result['QType']) if x == q] | |
51 # print "%s count = %d" % (q, len(qList)) | |
52 for i in intPattern: | |
53 iList = [j for j, x in enumerate(result['Intonation']) if x == i] | |
54 count = 0 | |
55 tracks = [] | |
56 if (iList) != None: | |
57 for il in iList: | |
58 if il in qList: | |
59 count +=1 | |
60 tracks.append(il) | |
61 # print (i + ' vs. '+q+'=%d', count) | |
62 # if count > 0: | |
63 print "%s vs. %s = %d" % (q, i, count) | |
64 print tracks | |
65 # for t in tracks: | |
66 # trackName = "T%d/01.csv" % (t) | |
67 # trackReader = csv.reader(open(trackName)) | |
68 # xList = [] | |
69 # yList = [] | |
70 # for r in trackReader: | |
71 ## print "In trackReader" | |
72 ## print(r) | |
73 ## print(r[1]) | |
74 # xList.append(r[0]) | |
75 ## xList = [float(x) for x in xList] | |
76 # yList.append(r[1]) | |
77 ## yList = [float(y) for y in yList] | |
78 # # Apply some smoothing and scaling | |
79 # # Vertical | |
80 # print yList | |
81 # print min(yList) | |
82 # yList = np.subtract(yList, min(yList)) | |
83 # print yList | |
84 # yList = np.divide(yList, max(yList)) | |
85 # print yList | |
86 # # Horizontal | |
87 # xList = np.subtract(xList, min(xList)) | |
88 # xList = np.divide(xList, max(xList)) | |
89 # | |
90 # | |
91 # plt.plot(xList,yList) | |
92 # plt.show() | |
93 | |
94 #result = {} | |
95 #for row in reader: | |
96 # print(row) | |
97 # key = row[1] | |
98 ## if key in result: | |
99 ## # implement your duplicate row handling here | |
100 ## pass | |
101 # result[key] = row[1:] | |
102 #print result |