forked from SteveHodge/ed-systems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecksystems.html
122 lines (109 loc) · 3.41 KB
/
checksystems.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ED Systems.json Sanity Check</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="trilateration.js"></script>
<style>
pre {outline: 1px solid #ccc; padding: 5px; margin: 5px; }
.string { color: green; }
.number { color: darkorange; }
.boolean { color: blue; }
.null { color: magenta; }
.key { color: red; }
</style>
<script>
var systems = null;
var output = [];
$(document).ready(function () {
$.getJSON('systems.json', function(data) {
systems = data;
logAppend('Loaded systems.json\n');
process();
});
$("#json-output").click(selectAll);
});
function logAppend(str) {
$('#log-output').text(function(i, old) {
return old + str;
});
}
function displayName(s) {
return s.name + ' (' + s.region + (s.calculated ? '' : ' ref') + ')';
}
function process() {
logAppend('Processing...\n');
var dupenames = 0, dupecoords = 0;
var baddists = 0;
var regions = {};
// find duplicate names
// count regions
var names = {};
for (i = 0; i < systems.length; i++) {
var r = systems[i].region + (systems[i].calculated ? '' : ' (ref)');
if (r in regions) {
regions[r]++;
} else {
regions[r] = 1;
}
var key = systems[i].name.trim().toLowerCase();
if (key in names) {
logAppend('Duplicate system: '+displayName(systems[i]));
if (systems[i].x == names[key].x && systems[i].y == names[key].y && systems[i].z == names[key].z) {
logAppend(' and ('+names[key].region+') - coordinates identical\n');
} else {
logAppend(' '+vectorToString(systems[i])+' and ('+names[key].region+') '+vectorToString(names[key])+'\n');
}
dupenames++;
} else {
names[systems[i].name.trim().toLowerCase()] = systems[i];
}
}
// find duplicate coordinates
var coords = {};
for (i = 0; i < systems.length; i++) {
var coords = '[' + systems[i].x + ', ' + systems[i].y + ', ' + systems[i].z + ']';
if (coords in names) {
logAppend('Duplicate coordinates: '+displayName(systems[i]) + ' and ' + displayName(names[coords])+'\n');
dupecoords++;
} else {
names[coords] = systems[i];
}
}
// check distances exist
$.each(systems, function() {
if (this.distances) {
for (var i = 0; i < this.distances.length; i++) {
if (!(this.distances[i].system.trim().toLowerCase() in names)) {
logAppend(this.name+': distance to non-existant system '+this.distances[i].system+'\n');
baddists++;
output.push({
system1: this.name,
system2: this.distances[i].system,
distance: this.distances[i].distance
});
}
}
}
});
logAppend('\n\nTotal systems: '+systems.length+'\n');
logAppend('Duplicated names: '+dupenames+'\n');
logAppend('Duplicated coordinates: '+dupecoords+'\n');
logAppend('Bad distances: '+baddists+'\n');
logAppend('\nRegions:\n');
$.each(Object.keys(regions).sort(), function() {
logAppend(' '+this+': '+regions[this]+'\n');
});
$('#json-output').text(JSON.stringify(output, null, 2));
}
</script>
</head>
<body class="ui-widget" style="font-size:100%">
<pre id="log-output" style="height:45vh; overflow:auto"></pre>
<pre id="json-output" style="height:45vh; overflow:auto"></pre>
</body>
</html>