-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsysinfo.html
415 lines (355 loc) · 12.7 KB
/
sysinfo.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ED System Info</title>
<link href="external/jquery-ui.css" rel="stylesheet">
<link href="trilateration.css" rel="stylesheet">
<script src="external/jquery-2.1.1.js"></script>
<script src="external/stupidtable.min.js"></script>
<script src="external/jquery-ui.js"></script>
<script src="trilateration.js"></script>
<script src="tgc.js"></script>
<script src="ed-systems.js"></script>
<script>
var currentSystem = null;
var systemData;
function systemAutoComplete(req, res) {
var options = [];
var term = req.term.toLowerCase();
if (term.length > 2) {
$.each(systemsMap, function(key, val) {
if (key.indexOf(term) > -1) {
options.push(val.name);
}
});
}
res(options);
}
$(document).ready(function () {
EDSM.fetch(function() {
$('#search-go').prop('disabled', false);
});
$('#search-name').autocomplete({source: systemAutoComplete});
// setup sorting on the distance table
$('#distances').stupidtable({'optfloat': sortOptionalFloat})
.bind('aftertablesort', postSortDistances)
.bind('beforetablesort', preSortDistances);
$('#local-systems').stupidtable().bind('aftertablesort', updateSortArrow);
// add the event handlers
$('#search-go').click(function() {
showSystem();
});
$('#refresh-edsm').click(function() {
$('#refresh-edsm').prop('disabled', true);
EDSM.update(function() {
$('#refresh-edsm').prop('disabled', false);
showSystem();
});
});
// $("#distances input").change(updateCoords);
// $('input.system-name').change(checkEmptyRow);
// addSystemRow();
// $("#tgc-button").attr('disabled',true);
// $("#done-button").attr('disabled',true);
});
function showSystem() {
currentSystem = systemsMap[nameKey($('#search-name').val())] || null;
var info = '';
if (currentSystem) {
info += 'Coordinates: '+vectorToString(currentSystem)+'<br>';
info += 'Contributed by: '+currentSystem.contributor+' on '+currentSystem.contributed+'<br>';
info += 'CR: '+currentSystem.cr+'<br>';
}
$('#system-info').html(info);
updateLocalSystems(currentSystem);
updateTrilateration();
}
function logAppend(str) {
$('#log-output').text(function(i, old) {
return old + str;
});
}
// setup sort values for the system column
function preSortDistances(event, data) {
$('#distances td').has('input.system-name').each(function() {
$(this).data('sort-value', $(this).find('input.system-name').val());
});
}
// update the arrows and force any blank systems to the bottom
function postSortDistances(event, data) {
var th = $(this).find("th");
th.find(".arrow").remove();
var arrow = data.direction === "asc" ? "\u2191" : "\u2193";
th.eq(data.column).append('<span class="arrow">' + arrow +'</span>');
// Move all top row blanks to the bottom.
var rowsObjs = $(this).find("tbody tr");
var rows = rowsObjs.slice(0);
var numBlank = 0;
$(rows).children("td:nth-child(1)").each(function(){
if($(this).find('input.system-name').val() === "")
numBlank++;
else
return false;
});
for(j=0; j<numBlank; j++){
var tmp = rows[0];
for(i=0; i<rows.length-1; i++){
rows[i] = rows[i+1];
}
rows[rows.length-1] = tmp;
}
$(this).children("tbody").append($(rows));
}
function checkEmptyRow() {
var empty = false;
$('input.system-name').each(function() {
if (!this.value || this.value.length === 0) {
empty = true
return false;
}
});
if (!empty) addSystemRow();
}
function addSystemRow() {
var tr = $('<tr><td><input class="system-name"></td><td/><td/><td/><td><input class="distance" size="8"></td><td/><td/><td/><td/></tr>')
.appendTo('#distances tbody');
tr.find('input').change(updateCoords);
tr.find('input.system-name')
.change(checkEmptyRow)
.autocomplete({source: systemAutoComplete});
return tr;
}
function updateTrilateration() {
$('#distances tbody').empty();
$('#output').html('');
if (currentSystem != null && 'distances' in currentSystem) {
$.each(currentSystem.distances, function() {
var $tr = addSystemRow();
$tr.find('input.system-name').val(this.system);
$tr.find('input.distance').val(this.distance);
$tr.children("td:nth-child(8)").text(this.created);
$tr.children("td:nth-child(9)").text(this.creator);
});
updateCoords();
}
checkEmptyRow();
}
function updateCoords() {
var dists = [];
// hook the reference systems up to the data
$("#distances input.system-name").each(function() {
var n = nameKey(this.value);
if (n.length > 0) {
var $tr = $(this).parentsUntil('table','tr');
$tr.attr('system', n);
if (n in systemsMap) {
var s = systemsMap[n];
if (s.name !== this.value) $(this).val(s.name); // update name if the capitalisation is different
// update coords:
$tr.children("td:nth-child(2)").text(s.x);
$tr.children("td:nth-child(3)").text(s.y);
$tr.children("td:nth-child(4)").text(s.z);
}
}
});
// get the distances
$("#distances tr[system]").each(function() {
var inp = $(this).find("input.distance");
var dist = inp.val();
var nameKey = this.getAttribute('system');
var system = systemsMap[nameKey];
var d = parseFloat(dist);
if (isNaN(d)) {
inp.val("");
} else if (system !== undefined) {
if (d != (dist+0)) inp.val(d); // parseFloat will parse anything starting with a valid float, so if that doesn't match the input then update the field
if (system.x != null) dists.push({name: system.name, distance: d, x: system.x, y: system.y, z: system.z});
}
});
// reset the calculated distances and errors.
$("#distances tr:has(input.system-name) td:nth-child(6)").text("").next().text("");
$("#output").html("");
if (dists.length > 24) dists.sort(function(a, b) {return a.distance - b.distance});
var index = 0;
var trilat = new Trilateration();
var goodDists = 0; // number of distances that match (reset if the best changes)
var badDists = 0; // number of distances that don't match (reset if the best changes)
var currentBest = null;
setTimeout(doDistance, 20);
function doDistance() {
if (index >= dists.length) return;
if (index > 24) return; // bail out before it gets too slow
$("#output").html('Calculating coordinates with '+(index+1)+' distances...<br>');
trilat.addDistance(dists[index]);
if (trilat.best && trilat.best.length === 1) {
// single candidate
if (currentBest == null || trilat.best[0].x !== currentBest.x || trilat.best[0].y !== currentBest.y || trilat.best[0].z !== currentBest.z) {
currentBest = trilat.best[0];
//console.log('new best '+vectorToString(currentBest)+' after dist '+index);
goodDists = 0;
badDists = 0;
$("#distances tr[system]").each(function() {
var enteredDist = $(this).find("input.distance").val();
if (enteredDist.length > 0) {
var nameKey = this.getAttribute('system');
if (!(nameKey in systemsMap)) {
$(this).children("td:nth-child(6)").text("")
.next().html('<span class="ui-icon ui-icon-alert inline-alert"></span>Unknown system');
return;
}
var sys = systemsMap[nameKey];
var status;
if (sys.x != null) {
var calcDist = eddist(sys, trilat.best[0]);
if (enteredDist - calcDist !== 0) {
status = '<span class="ui-icon ui-icon-alert inline-alert"></span>Bad Distance';
badDists++;
} else {
status = '<span class="ui-icon ui-icon-check inline-check"></span>Ok';
goodDists++;
}
} else {
status = 'No coords';
}
if (!sys.calculated) status += " (ref)";
$(this).children("td:nth-child(6)").text(sys.x == null ? '' : calcDist.toFixed(2)).next().html(status);
}
});
updateLocalSystems(trilat.best[0]);
}
$("#output").append("Coordinates: "+vectorToString(trilat.best[0])
+"<br/>Better than next candidate(s) by "+(trilat.bestCount - trilat.nextBest)+" distances"
+"<br/>Matching distances: "+goodDists
+"<br/>Inconsistent distances: "+badDists);
//$('#output').append('<br/>Regions Searched:').append(getRegionTable(trilat)).append('<br/>');
} else if (dists.length > 0) {
$("#output").append("Coordinates: found "+(trilat.best ? trilat.best.length : 'no')+" potential candidates");
//$('#output').append('<br/>Regions Searched:').append(getRegionTable(trilat)).append('<br/>');
if (null !== currentBest) {
//console.log('no best after dist '+index);
currentBest = null;
updateLocalSystems(null);
}
}
index++;
setTimeout(doDistance, 20);
}
}
function getRegionTable(trilat) {
var table = document.createElement('table');
var row = document.createElement('tr');
$('<th data-sort="string">Corner 1</th>').appendTo(row);
$('<th data-sort="string">Corner 2</th>').appendTo(row);
$('<th data-sort="int">Volume</th>').appendTo(row);
$('<th data-sort="int">Best Candidates</th>').appendTo(row);
$('<th data-sort="int">Region Best</th>').appendTo(row);
$('<th data-sort="int"># Region Best</th>').appendTo(row);
$('<th data-sort="int">Region 2nd</th>').appendTo(row);
$('<thead/>').append(row).appendTo(table);
var tbody = document.createElement('tbody');
table.appendChild(tbody);
$.each(trilat.regions, function() {
var best = 0;
for (var i = 0; i < trilat.best.length; i++) {
if (this.contains(trilat.best[i])) best++;
}
row = document.createElement('tr');
$('<td>').text('['+this.minx+', '+this.miny+', '+this.minz+']').appendTo(row);
$('<td>').text('['+this.maxx+', '+this.maxy+', '+this.maxz+']').appendTo(row);
$('<td>').text(this.volume()).appendTo(row);
$('<td>').text(best).appendTo(row);
$('<td>').text(this.bestCount).appendTo(row);
$('<td>').text(this.best.length).appendTo(row);
$('<td>').text(this.nextBest).appendTo(row);
tbody.appendChild(row);
});
$(table).stupidtable().bind('aftertablesort', updateSortArrow);
return table;
}
function updateLocalSystems(coords) {
$('#local-systems tbody').empty();
if (coords == null || coords.x == null) return;
var locals = [];
$.each(systemsMap, function(key, val) {
if (val === coords) return;
if (val.x == null) return;
locals.push({system:val.name, distance:eddist(val, coords)});
});
// add any entered distances to un-located systems
$('#distances tr[system]').each(function() {
var system = systemsMap[this.getAttribute('system')];
if (system !== undefined && system.x != null) return;
var name = system ? system.name : $(this).find('input.system-name').val();
var d = parseFloat($(this).find('input.distance').val());
if (!isNaN(d)) {
locals.push({system: name, distance: d});
}
});
locals.sort(function(a,b) {return a.distance-b.distance;});
for (i = 0; i < locals.length && locals[i].distance < 20; i++) {
$('<tr>')
.attr('system', nameKey(locals[i].system))
.click(selectSystem)
.append($('<td>').text(locals[i].system))
.append($('<td>').text((locals[i].distance).toFixed(2)))
.appendTo('#local-systems tbody');
}
}
function selectSystem() {
var key = $(this).attr('system');
console.log(key);
var sys = systemsMap[key];
if (!sys) return;
$('#search-name').val(sys.name);
$('#search-go').click();
}
</script>
</head>
<body>
<div class="ui-widget">
<label for="search-name">Name: </label>
<input id="search-name" size="30"/>
<button id="search-go" disabled>Go</button>
<button id="refresh-edsm" style="float: right">EDSM Refresh</button>
<div id="not-found-warning" class="ui-state-error ui-corner-all" style="margin: 0.5em; display:none">
<p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
Can't find a system with that name!</p>
</div>
<div id="system-info"></div>
<div style="float:right">
<h3>Nearby Systems</h3>
<table id="local-systems">
<thead>
<tr>
<th data-sort="string-ins">System</th>
<th data-sort="optfloat">Distance</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<h3>Trilateration</h3>
<div id="output"></div>
<table id="distances">
<thead>
<tr>
<th data-sort="string-ins">System</th>
<th data-sort="float">X</th>
<th data-sort="float">Y</th>
<th data-sort="float">Z</th>
<th data-sort="optfloat">Distance</th>
<th data-sort="optfloat">Calculated</th>
<th data-sort="string-ins" style="width:12em">Status</th>
<th data-sort="string-ins">Date</th>
<th data-sort="string-ins">Cmdr</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<pre id="log-output" style="height: 180px; overflow: auto; float: clear"></pre>
</div>
</body>
</html>