-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtaught_questions.py
349 lines (278 loc) · 9.98 KB
/
taught_questions.py
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
# -*- coding: utf-8 -*-
from __future__ import print_function, absolute_import, division
#from pprint import pprint as print
import bali, itertools
fp = bali.FileParser()
class PercentList(list):
'''
A list where each element is a tuple of (percent, weight), that
can calculate certain things...
'''
def num(self):
'''
return the numerator of the weighted mean
'''
tot = 0
for percent, weight in self:
tot += percent * weight
return tot
def denom(self):
'''
return the total amount of weight in the list
'''
tot = 0
for unused_percent, weight in self:
tot += weight
return tot
def weighedTotalPercentage(self):
'''
return num/denom...
'''
denom = self.denom()
if denom == 0:
raise ZeroDivisionError("There are no matching strokes in this list")
return self.num()/denom
'''
What percentage of Lanang is on the beat with nothing changed?
'''
def percentOnBeatLanangEDouble():
'''
Returns a PercentList for a lanang peng for every pattern, at beat level double
>>> import bali, taught_questions
>>> percentList = taught_questions.percentOnBeatLanangEDouble()
>>> len(percentList)
41
>>> percentList[1][0]
85.7...
>>> percentList[-1][0]
66.6...
>>> percentList.weighedTotalPercentage()
56.8...
'''
lanangPatterns = fp.separatePatternsByDrum()[0]
percents = PercentList()
for pattern in lanangPatterns:
percent = pattern.percentOnBeat('e')
weight = pattern.beatsInPattern('e')
percents.append((percent, weight))
return percents
'''
Testing that peng strokes occur on the beat in lanang and kom strokes occur off
the beat in wadon, after removing all double strokes.
'''
def percentOnBeatLanangEDoubleSingle():
'''
Returns PercentList for on-beats for peng strokes for all lanang patterns,
at beat level double
Only looks at single strokes
>>> import bali, taught_questions
>>> percentList = taught_questions.percentOnBeatLanangEDoubleSingle()
>>> percentList[1][0]
100.0
>>> percentList[4][0]
100.0
>>> percentList.weighedTotalPercentage()
68.7...
>>> percentList.denom()
96.0
'''
lanangPatterns = fp.separatePatternsByDrum()[0]
percents = PercentList()
for pattern in lanangPatterns:
pattern = pattern.removeConsecutiveStrokes('e', True, True)
percent = pattern.percentOnBeat('e', bali.BeatLevel.double)
weight = pattern.beatsInPattern('e')
percents.append((percent, weight))
return percents
def percentOffBeatWadonODoubleSingle():
'''
Returns PercentList for off-beats for kom strokes for all wadon patterns,
at beat level double
Only looks at single strokes
>>> import bali, taught_questions
>>> percentList = taught_questions.percentOffBeatWadonODoubleSingle()
>>> percentList[1][0]
100.0
>>> percentList[5][0]
75.0
>>> percentList.weighedTotalPercentage()
90.7...
>>> percentList.denom()
65
'''
wadonPatterns = fp.separatePatternsByDrum()[1]
percents = PercentList()
for pattern in wadonPatterns:
pattern = pattern.removeConsecutiveStrokes('o', True, True)
percent = pattern.percentOnBeat('o', bali.BeatLevel.double)
weight = pattern.beatsInPattern('o')
percents.append((100 - percent, weight))
return percents
'''
Testing that lanang peng strokes are off the beat and wadon kom strokes are on the
beat when single and the first of all double strokes are removed, at beat level guntang
'''
def percentOffBeatLanangEGuntangSecondDouble():
'''
Returns PercentList for off-beats for a peng for all lanang patterns, at beat level guntang,
after removing single strokes and then first of consecutive strokes
>>> import bali, taught_questions
>>> percentList = taught_questions.percentOffBeatLanangEGuntangSecondDouble()
>>> percentList[1][0]
0.0
>>> percentList[4][0]
100.0
>>> percentList.weighedTotalPercentage()
75.9...
>>> percentList.denom()
83.0
'''
lanangPatterns = fp.separatePatternsByDrum()[0]
percents = PercentList()
for pattern in lanangPatterns:
pattern = pattern.removeSingleStrokes('e')
pattern = pattern.removeConsecutiveStrokes('e')
percent = pattern.percentOnBeat('e', bali.BeatLevel.guntang)
weight = pattern.beatsInPattern('e')
percents.append((100 - percent, weight))
return percents
def percentOnBeatWadonOGuntangSecondDouble():
'''
Returns PercentList for on-beats for a kom for all wadon pattern, at beat level guntang,
after removing all single strokes and the first of all double strokes
>>> import bali, taught_questions
>>> percentList = taught_questions.percentOnBeatWadonOGuntangSecondDouble()
>>> percentList[8][0]
100.0
>>> percentList[-1][0]
50.0
>>> percentList.weighedTotalPercentage()
62.0...
>>> percentList.denom()
29.0
'''
wadonPatterns = fp.separatePatternsByDrum()[1]
percents = PercentList()
for pattern in wadonPatterns:
pattern = pattern.removeSingleStrokes('o')
pattern = pattern.removeConsecutiveStrokes('o')
percent = pattern.percentOnBeat('o', bali.BeatLevel.guntang)
weight = pattern.beatsInPattern('o')
percents.append((percent, weight))
return percents
'''
Dag and tut strokes
Normally, lanang tuts are off the beat and wadon dags are on the beat.
Wadon breaks the rules more, so we are testing in which beat subdivisions
and part of the gong cycle the rules are broken more
'''
def percentOffBeatLanangTGuntang():
'''
Returns PercentList for off-beats for a lanang tut strokes for all lanang patterns,
at beat level guntang.
Gives us what percent tut strokes land on beat subdivisions 1 and 3 as opposed to
2 and 4
>>> import bali, taught_questions
>>> percentList = taught_questions.percentOffBeatLanangTGuntang()
>>> percentList[1][0]
100.0
>>> percentList[-1][0]
100.0
>>> percentList.weighedTotalPercentage()
97.2...
>>> percentList.denom()
111.0
'''
lanangPatterns = fp.separatePatternsByDrum()[0]
percents = PercentList()
for pattern in lanangPatterns:
percent = pattern.percentOnBeat('T', bali.BeatLevel.guntang)
weight = pattern.beatsInPattern('T')
percents.append((100 - percent, weight))
return percents
def percentOnBeatWadonDGuntang():
'''
Returns PercentList for on-beats for dag strokes for all wadon patterns,
at beat level guntang.
First of all double strokes removed.
Gives us what percent dag strokes land on beat subdivisions 2 and 4 as opposed to
1 and 3
>>> import bali, taught_questions
>>> percentList = taught_questions.percentOnBeatWadonDGuntang()
>>> percentList[4][0]
33.3...
>>> percentList[-3][0]
50.0
>>> percentList.weighedTotalPercentage()
26.0
>>> percentList.denom()
50.0
Great confirmation of a null hypothesis: 25%
'''
wadonPatterns = fp.separatePatternsByDrum()[1]
percents = PercentList()
for pattern in wadonPatterns:
pattern = pattern.removeConsecutiveStrokes('Dd')
percent = pattern.percentOnBeat('D', bali.BeatLevel.guntang)
weight = pattern.beatsInPattern('D')
percents.append((percent, weight))
return percents
def whenLanangOffTList(beatDivision='first'):
'''
Returns distribution of which half of the gong lanang tuts land in
when they're on the first or third division of the beat
In dictionary form.
>>> import bali, taught_questions
Testing when beatDivision is first
>>> taught_questions.whenLanangOffTList()['first half']
5
>>> taught_questions.whenLanangOffTList()['second half']
20
Testing when beatDivision is third
>>> taught_questions.whenLanangOffTList('third')['first half']
27
>>> taught_questions.whenLanangOffTList('third')['second half']
51
'''
lanangPatterns = fp.separatePatternsByDrum()[0]
dist = {'first half': 0, 'second half': 0}
if beatDivision == 'first':
for pattern in lanangPatterns:
dist['first half'] += pattern.whenLanangOffT()['first half']
dist['second half'] += pattern.whenLanangOffT()['second half']
elif beatDivision == 'third':
for pattern in lanangPatterns:
dist['first half'] += pattern.whenLanangOffT('third')['first half']
dist['second half'] += pattern.whenLanangOffT('third')['second half']
return dist
def whenWadonOffDList(beatDivision='first'):
'''
Returns distribution of which half of the gong wadon dags land in
when they're on the first or third division of the beat.
In dictionary form.
>>> import bali, taught_questions
Testing when beatDivision is first
>>> taught_questions.whenWadonOffDList()['first half']
17
>>> taught_questions.whenWadonOffDList()['second half']
11
Testing when beatDivision is third
>>> taught_questions.whenWadonOffDList('third')['first half']
6
>>> taught_questions.whenWadonOffDList('third')['second half']
1
'''
wadonPatterns = fp.separatePatternsByDrum()[1]
dist = {'first half': 0, 'second half': 0}
if beatDivision == 'first':
for pattern in wadonPatterns:
dist['first half'] += pattern.whenWadonOffD()['first half']
dist['second half'] += pattern.whenWadonOffD()['second half']
elif beatDivision == 'third':
for pattern in wadonPatterns:
dist['first half'] += pattern.whenWadonOffD('third')['first half']
dist['second half'] += pattern.whenWadonOffD('third')['second half']
return dist
if __name__ == '__main__':
import music21
music21.mainTest()