-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplot_TM_CIESS.html
More file actions
306 lines (211 loc) · 6.99 KB
/
plot_TM_CIESS.html
File metadata and controls
306 lines (211 loc) · 6.99 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
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Test TM-Chart</title>
<script type="text/javascript" src="js/plot.js"></script>
<script src="js/jquery-2.1.1.js"></script>
<script src="js/jquery.csv-0.71.js"></script>
<script src="js/classes.js"></script>
<style type="text/css">
body {
background-color: #b0c4de;
}
#global {
margin-left: auto;
margin-right: auto;
width:1100px;
background-color:white;
}
#showresult {
width:98%;
height: 300px;
}
</style>
</head>
<body>
<div id="global">
<center>
<h1>TM-chart visualization</h1>
</center>
<div id="glass" align="right">
<table>
<tr>
<td><input type="image" id="glass_up" src="html/images/loupe_up.jpg" style="width:50px" onClick="glass_up();"/></td>
<td><input type="image" id="glass_down" src="html/images/loupe_down.jpg" style="width:50px" onClick="glass_down();"/></td>
</tr>
</table>
</div>
<center>
<input type="file" id="files_input" multiple/>
<svg id="svgzone" xmlns="http://www.w3.org/2000/svg">
</svg>
</center>
</div>
<script>
function glass_up(){
console.log("scale_plotTM : ",scale_plotTM);
$("svg").empty();
scale_plotTM+=0.1;
console.log("Magnifing glass up. scale_plotTM : ",scale_plotTM);
plotlegend()
plotTMarray(svg,shift_x,shift_y,corpus,scale_plotTM,xmax);
}
function glass_down(){
console.log("scale_plotTM : ",scale_plotTM);
$("svg").empty();
if (scale_plotTM>0.1) {scale_plotTM-=0.1;}
console.log("Magnifing glass down. scale_plotTM : ",scale_plotTM);
plotlegend()
plotTMarray(svg,shift_x,shift_y,corpus,scale_plotTM,xmax);
}
function getcolumn(array,numcolumn){
// Otput a specific float column from an array of string
out=[];
for (var i=0; i < array.length; i++) {
out.push(parseFloat(array[i][numcolumn]));
}
return out;
}
percent = function (values,thres){
// Return the % of the length of an sorted array which is superior to a specified value thres
var i=0;
while (values[i]>=thres) {i++;}
return (100*i/values.length);
}
makeColorFromSteps = function(filters){
// From a step array (values between 0 and 1) return an array of values between 0 and 100
var confidence= new Array(filters.length);
for(var i=0; i < confidence.length; i++)
{
confidence[i]= Math.round(filters[i]*100);
}
return confidence;
}
function openFiles(evt) {
var file_read=0;
var numberOfFile=0;
var files = evt.target.files; // FileList object
numberOfFile=files.length;
console.log('Number of files : ' + numberOfFile);
for (var i = 0; i < numberOfFile; i++) {
var file=files[i];
reader = new FileReader();
//console.log('Reading file : ' + file.name);
reader.onloadend = function() {
file_read++;
if (file_read==numberOfFile){
console.log('Reading finish');
console.log(corpus);
add_audio(corpus);
plotlegend();
plotTMarray(svg,shift_x,shift_y,corpus,scale_plotTM,xmax);
}
}
reader.onload = (function(f) {
return function(e) {
console.log('----------------------------');
console.log('f.name', f.name);
var recording;
var source;
var filter;
[recording,source,filter]=getNamesFromFilename(f.name, '--', '.txt')
var data = $.csv.toArrays(e.target.result,{separator:'\t'});
var duration=data[data.length-1][0];
if (!recording.duration===false && recording.duration!=duration){
console.log("Warning, duration source \"" + source.sourceName + "\" is not the same of the other source durations in the file " + recording.recordingName)
}
recording.duration=duration;
var values=getcolumn(data,1);
values.sort();
values.reverse();
source.data=values;
source.percentOfDuration=percent(values,filter.threshold);
source.filter=filter;
source.fileName=f.name;
source.makeHeigths();
// console.log('recording.recordingName', recording.recordingName);
// console.log('source.sourceName', source.sourceName);
// console.log('source.data', source.data);
// console.log('source.percentOfDuration', source.percentOfDuration);
// console.log('filter.filterName', filter.filterName);
console.log('source.heights', source.heights);
};
})(file);
reader.readAsText(file);
}
}
function getNamesFromFilename(filename, delimiteur, extension){
var recordingName = filename.slice(0,filename.search(delimiteur));
var sourceName = filename.slice(filename.search(delimiteur)+delimiteur.length, filename.search(extension));
var source=new Source(sourceName);
if (typeof(corpus.getFilter(sourceName)) == 'undefined') // Check is the filter is well defined in the corpus
{ throw new Error("Filter name \"" + sourceName + "\" not known") }
else { var filter=corpus.getFilter(sourceName); }
if (typeof(corpus.getRecording(recordingName)) == 'undefined')
{ // The recording is not in the corpus. We create a new recording and add the source to the recording
var recording = new Recording(recordingName);
corpus.addRecording(recording);
recording.addSource(source);
}
else
{ // The recording is already is the corpus. We add the source to the recording
var recording = corpus.getRecording(recordingName);
recording.addSource(source);
}
return [recording,source,filter];
}
function add_audio(corpus)
// the audio file is added from the same directory for each files..
{
for (var i=0; i<corpus.recordings.length; i++){
var file=corpus.recordings[i].recordingName;
//console.log(file);
corpus.recordings[i].audioFile="audio/" + file + ".wav"
}
}
function plotlegend(){
var origin_x=290;
var origin_y=47;
var scale=3;
plotlegendbar3plot(svg,corpus,origin_x,origin_y,scale);
}
// Beginning of the main program
var audio = new Audio();
audio.onplay = function() {
console.log("playing : " +audio.src)
};
var svg = document.getElementById('svgzone');
var corpus = new Corpus("moncorpus" );
var filter1 = new Filter("footstep");
var filter2 = new Filter("horn");
var filter3 = new Filter("motor");
corpus.addFilter(filter1);
corpus.addFilter(filter2);
corpus.addFilter(filter3);
filter1.threshold=0.4;
filter2.threshold=0.2;
filter3.threshold=0.3;
filter1.numberOfStep=3;
filter2.numberOfStep=3;
filter3.numberOfStep=3;
filter1.color=230; // Hue of hsl color
filter2.color=130;
filter3.color=50;
filter1.makeSteps();
filter2.makeSteps();
filter3.makeSteps();
// SVG size
svg.setAttribute("width", "1100");
svg.setAttribute("height", "2400");
// shift to plot TM-chart
var shift_y=120;
var shift_x=50;
var scale_plotTM=0.4;
var xmax= document.getElementById('svgzone').getAttributeNS(null, 'width');
console.log(corpus);
files_input.addEventListener("change", openFiles, false);
console.log(corpus);
</script>
</body>
</html>