-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvis_structure.html
More file actions
234 lines (193 loc) · 8.16 KB
/
vis_structure.html
File metadata and controls
234 lines (193 loc) · 8.16 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
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
<!DOCTYPE html>
<meta charset="utf-8">
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<style>
</style>
<body>
<div class="" id="nav-placeholder">
</div>
<div class="container">
<div class="row">
<div class="col-md-12">
<h1>Structural Variation</h1>
<p>Most modern music can be described as a composition of common parts: chorus, verse, intro or outro, bridge, solo, etc. Songs with more unique parts are clearly more complex than songs with fewer unique parts.</p>
</div>
</div>
<div class="row">
<h2>Total number of sections</h2>
<p>The total number of sections shows how many sections there are including repeats (i.e., if the chorus is played four times, that counts as four sections). We can see that the total number of sections has stayed fairly stagnant over the years, with the median being around 7-8 for all five decades.</p>
</div>
<div class="row"><div class="col-md-12" id="totalSectionsChart"></div></div>
<div class="row">
<h2>Number of unique sections</h2>
<p>Next, we look at the number of unique sections. The "typical" song will have three unique sections — verse, chorus, and bridge — possibly with an intro and/or outro. The number of unique sections has remained about the same, although the 2010's actually boasted a slightly higher number of unique sections (5, versus 4 for the previous decades). </p>
</div>
<div class="row"><div class="col-md-12" id="uniqueSectionsChart"></div></div>
<div class="row">
<div class="col-sm-12">
<p><h1>Conclusions</h1></p>
<p>Looking purely at mathematical measures of structural variation, it appears as though overall complexity has remained the same across the last 50 years.</p>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script src="https://d3js.org/d3.v5.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
<script>
// https://snippets.bentasker.co.uk/page-1907020841-Calculating-Mean,-Median,-Mode,-Range-and-Percentiles-with-Javascript-Javascript.html
function calcAverage(arr){
var a = arr.slice();
if (a.length){
sum = sumArr(a);
avg = sum / a.length;
return avg;
}
return false;
}
function calcMax(arr){
return Math.max(...arr);
}
function calcMedian(arr){
var a = arr.slice();
hf = Math.floor(a.length/2);
arr = sortArr(a);
if (a.length % 2){
return arr[hf];
}else{
return (parseFloat(arr[hf-1]) + parseFloat(arr[hf])) / 2.0;
}
}
function calcMin(arr){
return Math.min(...arr);
}
function calcMode(arr){
var ary = arr.slice();
t = ary.sort(function(a,b){
ary.filter(function(val){
val===a
}).length - ary.filter(function(val){
val===b
}).length});
return t.pop();
}
function calcQuartile(arr,q){
var a = arr.slice();
// Turn q into a decimal (e.g. 95 becomes 0.95)
q = q/100;
// Sort the array into ascending order
data = sortArr(a);
// Work out the position in the array of the percentile point
var p = ((data.length) - 1) * q;
var b = Math.floor(p);
// Work out what we rounded off (if anything)
var remainder = p - b;
// See whether that data exists directly
if (data[b+1]!==undefined){
return parseFloat(data[b]) + remainder * (parseFloat(data[b+1]) - parseFloat(data[b]));
}else{
return parseFloat(data[b]);
}
}
function calcRange(arr){
mx = calcMax(arr);
mn = calcMin(arr);
return mx-mn;
}
function sumArr(arr){
var a = arr.slice();
return a.reduce(function(a, b) { return parseFloat(a) + parseFloat(b); });
}
function sortArr(arr){
var ary = arr.slice();
ary.sort(function(a,b){ return parseFloat(a) - parseFloat(b);});
return ary;
}
function fiveNumberSummary(data){
return([calcMin(data), calcQuartile(data, 25), calcMedian(data), calcQuartile(data,75), calcMax(data)])
}Promise.all([
d3.csv("https://raw.githubusercontent.com/morganoneka/UltimateGuitarAnalysis/main/Output/SongStructure/1970_distribution_stats.csv"),
d3.csv("https://raw.githubusercontent.com/morganoneka/UltimateGuitarAnalysis/main/Output/SongStructure/1980_distribution_stats.csv"),
d3.csv("https://raw.githubusercontent.com/morganoneka/UltimateGuitarAnalysis/main/Output/SongStructure/1990_distribution_stats.csv"),
d3.csv("https://raw.githubusercontent.com/morganoneka/UltimateGuitarAnalysis/main/Output/SongStructure/2000_distribution_stats.csv"),
d3.csv("https://raw.githubusercontent.com/morganoneka/UltimateGuitarAnalysis/main/Output/SongStructure/2010_distribution_stats.csv")
]).then(function(files) {
// files[0] will contain file1.csv
// files[1] will contain file2.csv
console.log(files[0]);
totalSections(files);
uniqueSections(files);
}).catch(function(err) {
// handle error here
console.log(err)
})
function totalSections(files){
data = [
{x:'1970s', y:fiveNumberSummary(files[0].map(a => parseInt(a.total_num_sections)))},
{x:'1980s', y:fiveNumberSummary(files[1].map(a => parseInt(a.total_num_sections)))},
{x:'1990s', y:fiveNumberSummary(files[2].map(a => parseInt(a.total_num_sections)))},
{x:'2000s', y:fiveNumberSummary(files[3].map(a => parseInt(a.total_num_sections)))},
{x:'2010s', y:fiveNumberSummary(files[4].map(a => parseInt(a.total_num_sections)))}];
var options = {
series: [{type:'boxPlot', data:data}],
chart: {
type: 'boxPlot',
height: 350
},
title: {
text: 'Total Number of Sections',
align: 'left'
},
plotOptions: {
boxPlot: {
colors: {
upper: '#fcba03',
lower: '#5d88fc'
}
}
}
};
var chart = new ApexCharts(document.querySelector("#totalSectionsChart"), options);
chart.render();
}
function uniqueSections(files){
data = [
{x:'1970s', y:fiveNumberSummary(files[0].map(a => parseInt(a.num_unique_sections)))},
{x:'1980s', y:fiveNumberSummary(files[1].map(a => parseInt(a.num_unique_sections)))},
{x:'1990s', y:fiveNumberSummary(files[2].map(a => parseInt(a.num_unique_sections)))},
{x:'2000s', y:fiveNumberSummary(files[3].map(a => parseInt(a.num_unique_sections)))},
{x:'2010s', y:fiveNumberSummary(files[4].map(a => parseInt(a.num_unique_sections)))}];
var options = {
series: [{type:'boxPlot', data:data}],
chart: {
type: 'boxPlot',
height: 350
},
title: {
text: 'Number of Unique Sections',
align: 'left'
},
plotOptions: {
boxPlot: {
colors: {
upper: '#fcba03',
lower: '#5d88fc'
}
}
}
};
var chart = new ApexCharts(document.querySelector("#uniqueSectionsChart"), options);
chart.render();
}
</script>
<script>
$(function(){
$("#nav-placeholder").load("nav.html");
});
</script>
</body>