This repository has been archived by the owner on Jun 5, 2023. It is now read-only.
forked from jmtrivial/crossroads-evaluation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eval-browser.html
329 lines (273 loc) · 13.9 KB
/
eval-browser.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
<!DOCTYPE html>
<html lang="fr-FR" class="no-js">
<head>
<meta charset="UTF-8">
<title>Browser tool</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- bootstrap -->
<link href="node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="node_modules/bootstrap/dist/js/bootstrap.bundle.min.js" ></script>
<!-- bootstrap dark -->
<link rel="stylesheet" href="node_modules/bootstrap-dark/src/bootstrap-dark.css" />
<!-- jquery -->
<script src="node_modules/jquery/dist/jquery.min.js"></script>
<!-- Library Leaflet -->
<link rel="stylesheet" href="node_modules/leaflet/dist/leaflet.css" />
<script src="node_modules/leaflet/dist/leaflet.js"></script>
<script src="js/evaluate-segmentation.js"></script>
<!-- bootstrap table -->
<link href="node_modules/bootstrap-table/dist/bootstrap-table.min.css" rel="stylesheet">
<script src="node_modules/bootstrap-table/dist/bootstrap-table.min.js"></script>
<script>
function is_evaluation_incorrect(ec) {
for(var qid in window.q_json) {
if (ec[qid] != window.q_json[qid]["default"])
return true;
}
return false;
}
function update_buttons() {
var nb_cr = window.crossroads.length;
var nb_cr_eval = 0;
var nb_cr_incorrect = 0;
for(var idc in window.crossroads) {
ec = get_evaluation_crossroad(window.crossroads[idc]);
if (ec != 0) {
nb_cr_eval += 1;
if (is_evaluation_incorrect(ec))
nb_cr_incorrect += 1;
}
}
$("#show-all span").html("(" + nb_cr + ")");
$("#show-evaluated span").html("(" + nb_cr_eval + ")");
$("#show-incorrect span").html("(" + nb_cr_incorrect + ")");
$("#show-correct span").html("(" + (nb_cr_eval - nb_cr_incorrect) + ")");
}
function get_evaluation_crossroad(crossroad) {
for (var idc in crossroad) {
if (crossroad[idc]["type"] == "evaluation")
return crossroad[idc];
}
return 0;
}
function build_data_from_crossroads() {
var result = [];
window.lineFromId = {};
i = 0;
for(var idc in window.crossroads) {
cr_line = {};
eval = get_evaluation_crossroad(window.crossroads[idc]);
fields = Settings.compute_fields(window.crossroads[idc]);
cr_line["evaluated"] = eval != 0;
cr_line["incorrect"] = eval != 0 && is_evaluation_incorrect(eval);
cr_line["crossroad"] = window.crossroads[idc];
if (window.mode == "all" ||
(cr_line["evaluated"] && window.mode == "evaluated") ||
(cr_line["incorrect"] && window.mode == "incorrect") ||
(cr_line["evaluated"] && !cr_line["incorrect"] && window.mode == "correct")) {
for(var qid in window.q_json) {
if (eval == 0 || eval[qid] == window.q_json[qid]["default"])
cr_line[qid] = "-";
else
cr_line[qid] = eval[qid];
}
cr_line["id"] = "" + i;
for(var x in window.cf_json) {
cr_line[x] = fields[x];
}
window.lineFromId[cr_line["id"]] = result.length;
result.push(cr_line);
}
i += 1;
}
return result;
}
function update_crossroads_display() {
data = build_data_from_crossroads();
table = $('#table');
table.bootstrapTable('destroy').bootstrapTable({data: data, onCheck: function(row, element) {select_on_map(row.id);}});
Settings.render_crossroads(data, "crossroads-rendering");
if (window.mode == "all")
$("#crossroads_title span.title").text("All crossroads");
else if (window.mode == "evaluated")
$("#crossroads_title span.title").text("Evaluated crossroads");
else if (window.mode == "incorrect")
$("#crossroads_title span.title").text("Incorrect crossroads");
else if (window.mode == "correct")
$("#crossroads_title span.title").text("Correct crossroads");
}
function display_browser_interface() {
update_crossroads_display();
$("#main-container>div").css("display", "none");
$("#browser").css("display", "block");
}
function build_browser_interface() {
// Create columns
html = '<th scope="row" data-field="id">ID</th>';
html += '<th data-field="state" data-checkbox="true"></th>';
window.q_json = JSON.parse(Settings.question_list);
// Columns from questions
for(var qid in window.q_json) {
html += '<th scope="col" data-sortable="true" data-field="' + qid + '">' + window.q_json[qid]["question"] + '</th>';
}
window.cf_json = JSON.parse(Settings.computed_fields);
// Computed columns
for(var x in window.cf_json) {
html += '<th scope="col" data-sortable="true" data-field="' + x + '">' + window.cf_json[x] + '</th>';
}
$("#table_header").html(html);
}
function set_title() {
$("h1").text(Settings.title_evaluation_browser_page);
document.title = Settings.title_evaluation_browser_page;
}
function set_intro() {
$("#intro").html(Settings.intro_evaluation_browser_page);
}
function select_on_table(cid) {
$('#table').bootstrapTable('uncheckAll');
strCid = "" + cid;
$('#table').bootstrapTable('checkBy', {field: 'id', values: [strCid], onlyCurrentPage: false});
$('#table').bootstrapTable('scrollTo', {value: window.lineFromId[strCid], unit: 'rows'});
}
function select_on_map(cid) {
if (cid in window.crossroads_bounds)
window.map.fitBounds(window.crossroads_bounds[cid]);
}
function registerBounds(cid, bounds) {
window.crossroads_bounds[cid] = bounds;
}
$(document).ready(function () {
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.has('tool')) {
tool = urlParams.get('tool');
}
else {
console.log("cannot identify a tool, select the default one");
tool = "evaluate-segmentation";
}
const script = document.createElement('script');
script.src = 'js/' + tool + '.js';
script.id = 'evaluation-parameters';
document.body.appendChild(script);
script.onerror = function() {
$("#main-container>div").css("display", "none");
$("#error-script").css("display", "block");
}
script.onload = () => {
window.crossroads_bounds = {};
set_title();
set_intro();
build_browser_interface();
$("#inputFile").on("change", function handleFileSelect(evt) {
if (evt == null || evt.target == null || evt.target.files == null || evt.target.files.length == 0) {
console.log("no input file");
return;
}
var file = evt.target.files[0];
if (file.type != "application/json") {
console.log("bad format");
return;
}
const fr = new FileReader();
fr.addEventListener("load", e => {
$("#main-container>div").css("display", "none");
$("#chargement").css("display", "block");
// load data
window.crossroads = JSON.parse(fr.result);
window.mode = "all";
display_browser_interface();
update_buttons();
});
fr.readAsText(file);
window.input_filename = evt.target.files[0].name;
});
$("#show-all").click(function(evt) {
window.mode = "all";
update_crossroads_display();
});
$("#show-evaluated").click(function(evt) {
window.mode = "evaluated";
update_crossroads_display();
});
$("#show-incorrect").click(function(evt) {
window.mode = "incorrect";
update_crossroads_display();
});
$("#show-correct").click(function(evt) {
window.mode = "correct";
update_crossroads_display();
});
$("#osm-external").click(function(evt) {
var center = window.map.getCenter();
var zoom = window.map.getZoom();
console.log(center, zoom);
var osm_url = 'https://www.openstreetmap.org/?zoom=' + zoom + '&mlat=' + center.lat + '&mlon=' + center.lng;
window.open(osm_url, '_blank');
});
}
});
</script>
<style>
#question, #chargement, #browser, #error-script { display: none; }
#crossroads-rendering { height: 400px; width: 100%; background: black;}
</style>
</head>
<body>
<div class="container-xxl" id="main-container">
<h1>Evaluation tool</h1>
<p class="lead" id="intro"></p>
<div id="start">
<div class="position-absolute top-50 start-50 translate-middle fs-1">
<p>Select a <code>json</code> file</p>
<div class="btn btn-primary btn-block" style="width: 100%">
<label style="padding: 0" tkey="chooseFile">Load crossroads</label>
<input type="file" id="inputFile" name="files[]" accept="application/json" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; cursor: pointer; opacity: 0">
</div>
</div>
</div>
<div id="chargement">
<div class="position-absolute top-50 start-50 translate-middle fs-1">Loading data...</div>
</div>
<div id="browser">
<div class="row">
<div class="col">
<button id="show-all" class="btn btn-primary btn-block form-control" type="button">All crossroads <span></span></button>
</div>
<div class="col">
<button id="show-evaluated" class="btn btn-primary btn-block form-control" type="button">Evaluated crossroads <span></span></button>
</div>
<div class="col">
<button id="show-correct" class="btn btn-primary btn-block form-control" type="button">Only correct crossroads <span></span></button>
</div>
<div class="col">
<button id="show-incorrect" class="btn btn-primary btn-block form-control" type="button">Only incorrect crossroads <span></span></button>
</div>
</div>
<div class="card">
<div class="card-body">
<h2 class="card-title" id="crossroads_title"><span class="title"></span> <button id="osm-external" class="button badge bg-secondary">osm</button></h2>
<div id="crossroads-rendering"></div>
</div>
</div>
<div>
<table class="table-dark"
id="table"
data-show-toggle="true"
data-filter="true"
data-height="460"
data-single-select="true"
data-click-to-select="true">
<thead>
<tr id="table_header">
</tr>
</thead>
</table>
</div>
</div>
<div id="error-script">
<div class="position-absolute top-50 start-50 translate-middle fs-1">Error while loading tool</div>
</div>
</div>
</body>
</html>