-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
431 lines (394 loc) · 18.4 KB
/
index.html
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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
<html xmlns:aad="http://www.w3.org/1999/xhtml">
<head>
<link href="css/ui-lightness/jquery-ui-1.8.21.custom.css" rel="stylesheet" type="text/css" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<title>INFLAB01</title>
</head>
<body>
<div id="wrapper">
<div id="content" class="clearfix">
<div id="left">
<div id="mapArea"></div>
</div>
<div id="right">
<div id="debug"></div>
<div id="controllers-analyser">
<h2>Analyse</h2>
<div class="controller">
<div class="label">Pearsons nauwkeurigheid:</div>
<div id="raster-size-val" class="value">10</div>
<div class="slider" id="raster-size"></div>
</div>
<div class="controller">
<div class="label">Zonegrootte:</div>
<div id="zones-val" class="value">7</div>
<div class="slider" id="zones"></div>
</div>
<div class="controller">
<div class="label">Correlatie bereik:</div>
<div id="min-correlation-val" class="value-left">0.5</div>
<div class="dash">-</div>
<div id="max-correlation-val" class="value-right">0.9</div>
<div class="slider" id="correlation-range"></div>
</div>
<div class="collection-selector">
Datasets en attributen:
<div>
<select id="collections1" class="collections"><option value="">-</option></select>
<select id="attributes1-1" class="attributes collections1"><option value="">-</option></select>
<select id="attributes1-2" class="attributes collections1"><option value="">-</option></select>
<select id="attributes1-3" class="attributes collections1"><option value="">-</option></select>
<select id="attributes1-4" class="attributes collections1"><option value="">-</option></select>
<select id="attributes1-5" class="attributes collections1"><option value="">-</option></select>
</div>
<div>
<select id="collections2" class="collections"><option value="">-</option></select>
<select id="attributes2-1" class="attributes collections2"><option value="">-</option></select>
<select id="attributes2-2" class="attributes collections2"><option value="">-</option></select>
<select id="attributes2-3" class="attributes collections2"><option value="">-</option></select>
<select id="attributes2-4" class="attributes collections2"><option value="">-</option></select>
<select id="attributes2-5" class="attributes collections2"><option value="">-</option></select>
</div>
<div>
<select id="collections3" class="collections"><option value="">-</option></select>
<select id="attributes3-1" class="attributes collections3"><option value="">-</option></select>
<select id="attributes3-2" class="attributes collections3"><option value="">-</option></select>
<select id="attributes3-3" class="attributes collections3"><option value="">-</option></select>
<select id="attributes3-4" class="attributes collections3"><option value="">-</option></select>
<select id="attributes3-5" class="attributes collections3"><option value="">-</option></select>
</div>
</div>
<div>
<input type="button" id="start-analyzer" value="Analyseer">
<input type="button" id="reset-analyzer" value="Reset map">
</div>
<div id="associations-results"></div>
</div>
<div id="upload" class="clearfix">
<h2>Nieuwe set uploaden</h2>
<form enctype="multipart/form-data" action="scripts/upload-file.py" method="post">
<div><label>Collectie naam:</label><input type="text" name="collection"></div>
<div><label>Shp bestand:</label> <input type="file" name="shp"></div>
<div><label>Dbf bestand:</label> <input type="file" name="dbf"></div>
<div style="padding-top: 40px;"><input type=submit value="Uploaden"></div>
</form>
</div>
</div>
</div><!-- content -->
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
<script src="//ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.1/jquery.dataTables.min.js"></script>
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script src="js/common.js"></script>
<script type="text/javascript">
var map;
var grid = Grid;
grid.columns = 7;
grid.rows = 7;
var corrMin = 0.5;
var corrMax = 0.9;
var data;
// --------------------- for testing purposes only !!! ------------------------------------------------
var firstload = true;
// ----------------------------- end testing ----------------------------------------------------------
window.onload = function(){
$(function() {
$( "#raster-size" ).slider({
value:10,
min: 3,
max: 50,
step: 1,
slide: function(event, ui){
$( "#raster-size-val" ).html( ui.value );
}
});
$( "#correlation-range" ).slider({
range: true,
values: [ 0.5, 0.9 ],
min: 0.0,
max: 1.0,
step: 0.1,
slide: function(event, ui){
$( "#min-correlation-val" ).html( ui.values[0]);
$( "#max-correlation-val" ).html( ui.values[1]);
}
});
$( "#zones" ).slider({
value:7,
min: 3,
max: 50,
step: 1,
slide: function(event, ui){
$( "#zones-val" ).html( ui.value );
grid.columns = ui.value;
grid.rows = ui.value;
}
});
});
// alert($("#correlation-range").slider("values"));
var my_resolution = 100;
var my_radius = 10;
var my_opacity = 70;
var myLatlng = new google.maps.LatLng(51.9209866008, 4.47188401315);
var myOptions = {
zoom: 15,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
disableDefaultUI: false,
scrollwheel: true,
draggable: true,
navigationControl: true,
mapTypeControl: false,
scaleControl: true,
disableDoubleClickZoom: false
};
map = new google.maps.Map(document.getElementById("mapArea"), myOptions);
// $("#mapArea").css('position', 'fixed');
grid.map = map;
var clearSelect = function(selectElement){
$("."+($(selectElement).attr('id'))).find('option')
.remove()
.end()
.append('<option value="">-</option>')
.val('whatever');
};
// Adds an function to the analyze button to do something real.
$("#start-analyzer").click(function() {
grid.removeGrid();
// The request url.
var url = "scripts/analyze.py?bounds=" + map.getBounds() + "";
// We store what data sets and attributes are selected
var dataSets = [];
var setAttributen = []; // Stores arrays with attributes
// Check each data set select-field.
$(".collection-selector").find(".collections option:selected").each(function(i, v){
// Check if the value of a data set is not equal to '-'.
if($(this).text() != "-") {
// Check if the set is not selected before
if(jQuery.inArray($(this).text(), dataSets) == -1) {
var selector = ".attributes." + $(this).parent().attr("id") + " option:selected";
var attributes = []; // For a single data set
// Store each selected attribute
$(selector).each(function(j, w) {
if($(this).text() != "-") {
if(jQuery.inArray($(this).text(), attributes) == -1) {
attributes.push($(this).text());
}
}
});
// Store the data set and it attributes only if at least one attributes was selected, .
if($(attributes).size() > 0) {
dataSets.push($(this).text());
setAttributen.push(attributes);
}
}
}
});
// Kijk of er een geldige selectie van data sets (en attributen) is.
if($(dataSets).size() > 0) {
// Generate data set call
var setCall = "{"
$.each(dataSets, function(index, value) {
var attrCal = "[";
$.each(setAttributen[index], function (index, value) {
if(index != 0) {
attrCal += ", ";
}
attrCal += "\"" + value + "\"";
});
attrCal += "]";
if(index != 0) {
setCall += ", "
}
setCall += "\"" + value + "\": " + attrCal;
});
setCall += "}";
url += "&sets=" + setCall;
url += "&zones=" + $("#zones-val").html();
// Generate rasterSize option
url += "&rasterSize=" + $("#raster-size-val").html();
// Generate threshold option
url += "&threshold=" + $("#min-correlation-val").html();
$("#associations-results").html( '<img src="img/loading.gif" alt="loading">' );
$.ajax({ url: url }).done(
function( response ) {
data = response;
var result = "<table id=\"correlation_results_table\" cellspacing='15px'><thead><th>#</th><th>Serie 1</th><th>Serie 2</th><th>Correlatie</th><th>Actie</th></thead><tbody>";
var zvc = null;
$.each(data, function(key, item){
var rgb = hsvToRgb(((item["pearsons"]+1.0)*60), 100, 100);
result += "<tr><td>" +
"Set: <br>" +
"Attribuut: <br>" +
"Waarde: <br>" +
"Met deze waarde: <br>" +
"Totaal: " +
"</td>" +
"<td>" +
item["set_a"]["set"]+"<br>" +
item["set_a"]["attribute"]+"<br>" +
item["set_a"]["value"] +"<br>" +
item["set_a"]["amount-value"] +"<br>" +
item["set_a"]["amount-total"] +
"</td>" +
"<td>" +
item["set_b"]["set"]+"<br>" +
item["set_b"]["attribute"]+"<br>" +
item["set_b"]["value"] +"<br>" +
item["set_b"]["amount-value"] +"<br>" +
item["set_b"]["amount-total"] +
"</td>" +
// "<td>"+item["pearsons"]+"</td>" +
"<td style=\"background-color: rgb(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + ");\">"+item["pearsons"]+"</td>" +
"<td><input type='button' id='start-detail' value='Details' onclick='showDetails(\""+key+"\");'></td></tr>";
});
zvc = countAvgDeviationViolation(data);
result += "</tbody></table>";
$("#associations-results").html( result );
var corrResultsTable = $("#correlation_results_table").dataTable({
"aaSorting": [[ 3, "desc" ]],
"aoColumnDefs": [
{ 'bSortable': false, 'aTargets': [ 0, 1, 2, 4 ] }
],
"bFilter": true
});
$.fn.dataTableExt.afnFiltering.push(
function( oSettings, aData, iDataIndex ) {
var iMin = corrMin;
var iMax = corrMax;
var pearson = Math.abs(aData[3]);
// Math.abs(item["pearsons"])
if ( iMin <= pearson && pearson <= iMax ) {
return true;
}
return false;
}
);
corrResultsTable.fnDraw(true);
$( "#correlation-range" ).slider({
slide: function(event, ui){
$( "#min-correlation-val" ).html( ui.values[0]);
$( "#max-correlation-val" ).html( ui.values[1]);
corrMin = ui.values[0];
corrMax = ui.values[1];
corrResultsTable.fnDraw(true);
}
});
grid.buildGrid();
for (var j = 0; j < zvc.length; j++){
if(zvc[j] > 3){
grid.tiles[j].fillOpacity = 0.5;
}
}
});
} else {
$("#associations-results").html("Geen geldige selectie van data set(s) en attributen.");
}
});
$("#reset-analyzer").click(function() {
grid.removeGrid();
$("#associations-results").html('');
});
$.ajax({ url: "scripts/find_collections.py" }).done(
function( msg ) {
var options = $("select.collections");
var coll_array = eval(msg);
for (var i = 0; i < coll_array.length; i++) {
options.append($("<option />").val(coll_array[i]).text(coll_array[i]));
}
$(".collections").change(function(){
if ($(this).val() != ""){
var selector = this;
var set = $("option:selected", this).text();
$.ajax({ url: "scripts/load_attributes.py?set="+set }).done(
function( response ){
var att_array = eval(response);
if (att_array == undefined ){
clearSelect(selector);
} else {
clearSelect(selector);
var selects = $("."+($(selector).attr("id")));
for (var i = 0; i < att_array.length; i++) {
selects.append($("<option />").val(att_array[i]).text(att_array[i]));
}
}
// --------------------- for testing purposes only !!! ------------------------------------------------
if (firstload){
$('#attributes1-1 :nth-child(15)').attr('selected', 'selected');
$('#attributes1-2 :nth-child(27)').attr('selected', 'selected');
firstload = false;
}
// ----------------------------- end testing ----------------------------------------------------------
}
);
} else {
clearSelect(this);
}
});
// --------------------- for testing purposes only !!! ------------------------------------------------
$('#collections1 :nth-child(6)').attr('selected', 'selected');
$('#collections1 :nth-child(6)').change();
// $( "#zones" ).slider.slide();
// ----------------------------- end testing ----------------------------------------------------------
});
};
function showDetails(combKey){
var pearson = data[combKey]["pearsons"];
var sub = data[combKey]["sub"];
var dev = data[combKey]["avg_deviation"];
var diff = [];
for (var field in sub){
if (sub[field] == "X"){
diff.push("X");
} else {
diff.push(sub[field]-pearson);
}
}
for (var i in diff){
var my_rectOpt;
// if diff is either X, or within standard deviation
if (diff[i] == "X") {
my_rectOpt = {
fillColor: "#000000",
fillOpacity: 0.2
};
} else {
if (diff[i] > dev){
my_rectOpt = {
fillColor: "#00FF00",
fillOpacity: 0.5
};
} else if (diff[i] < -dev){
my_rectOpt = {
fillColor: "#FF0000",
fillOpacity: 0.5
};
} else {
my_rectOpt = {
fillOpacity: 0.0
};
}
}
var result = "<p>"
result += "Algemene correlatie: "+round(pearson, 3)+"<br>";
result += "Gemiddelde afwijking: +/-"+round(dev, 3)+"<br>";
result += "Locale correlatie: "+round(sub[i], 3)+"<br>";
result += "</p>";
grid.addGridTileListener(grid.tiles[i], result);
grid.tiles[i].setOptions(my_rectOpt);
}
}
function round(num, dec) {
var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
return result;
}
function color(pearson) {
// -1 , 0, 1 = 2
0 = -1
1 = 120
(pearson + 1) * 120
}
</script>
</body>
</html>