-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessCleanedData.py
More file actions
101 lines (88 loc) · 2.5 KB
/
processCleanedData.py
File metadata and controls
101 lines (88 loc) · 2.5 KB
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
# -*- coding: utf-8 -*-
"""
Created on Sat Sep 24 23:41:16 2011
@author: antoanne
"""
import plots as plots
from plot import plot, subplot, title, ylabel, xlabel, grid,
from BeautifulSoup import BeautifulStoneSoup
from sqlite3 import dbapi2 as sqlite
import re, sys
import mingus.core.notes as notes
from mingus.containers.Note import Note
PATH = "/home/antoanne/Dropbox/Work-2011/Mestrado/Modelagem/musica/data/"
FILE = "www.cifraclub.com.br_%s.cleaned"
letras = map(chr, range(65, 91))
#letras = map(chr, range(65, 66))
acords = {}
tons = {}
def acumulaTons(d, tons):
if (d['tom'] != ""):
try:
if (notes.is_valid_note(d['tom'])):
if (d['tom'] in tons.keys()):
tons[d['tom']] += 1
else:
tons[d['tom']] = 1
except:
pass
def acumulaAcordes(d, acords):
if (len(d['cifra']) > 0):
for c in d['cifra']:
if (str(c) in acords.keys()):
acords[str(c)] += 1
else:
acords[str(c)] = 1
def wordleFile(fileName, d):
f = open(PATH+fileName +'.wordle','w')
for a in d:
try:
f.write("%s:%d\r\n" % (a,d[a]))
except:
pass
f.close()
def readFromDictFile(fileName, tons, acords):
f = open(PATH+fileName +'.dictFile','r')
for line in f:
try:
acumulaTons(eval(line), tons)
acumulaAcordes(eval(line), acords)
except:
print "ERROR on " + line
f.close()
for l in letras:
print "lendo %s..." % l
try:
readFromDictFile(FILE % l, tons, acords)
except:
pass
def reverse_numeric(x, y):
return y - x
def acordesMaisTocados(acords):
l=sorted([acords[x] for x in acords], cmp=reverse_numeric)
mais = {}
p = .02
for x in acords:
if (acords[x] >= min(l[:int(len(l)*p)])):
print x, min(l[:int(len(l)*p)])
mais[x] = acords[x]
return mais
def plotRepeticoes():
p = .02
l=sorted([acords[x] for x in acords], cmp=reverse_numeric)
subplot(211)
title(unicode('Repetições dos acordes'))
ylabel(unicode('repetições'))
xlabel('acordes')
grid(True)
plot(l)
subplot(212)
title(unicode('\n1% das repetições'))
ylabel(unicode('repetições'))
xlabel('acordes')
plot(l[:int(len(l)*p)])
plotRepeticoes()
wordleFile('maisTocados',acordesMaisTocados(acords))
#wordleFile('acordes', acords)
#plots.constructQTDPlot(tons)
#plots.constructQTDPlot(acords)