-
Notifications
You must be signed in to change notification settings - Fork 2
/
poland.html
370 lines (330 loc) · 14.6 KB
/
poland.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
<!DOCTYPE html>
<html>
<head>
<title>QONQR Poland zone map</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<script src="https://rawcdn.githack.com/robertleeplummerjr/Leaflet.glify/466c3696d9f67b7833089c15317ae9b6d7e5a30f/dist/glify-browser.js"></script>
<script src="https://unpkg.com/[email protected]/leaflet-providers.js"></script>
<script src="https://unpkg.com/[email protected]/dist/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/4.3.7/papaparse.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/spin.js/2.3.2/spin.min.js"></script>
<script src="https://unpkg.com/[email protected]/leaflet.spin.min.js"></script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-164777450-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'UA-164777450-1');
</script>
<style>
body,
html,
#map {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.legend {
color: white;
padding: 10px;
background-color: rgba(0, 0, 0, 0.8);
border-radius: 5px;
}
.uncaptured {
color: orange;
}
.legion {
color: red;
}
.swarm {
color: green;
}
.faceless {
color: purple;
}
.uncapturedBG {
background-color: orange;
}
.legionBG {
background-color: red;
}
.swarmBG {
background-color: green;
}
.facelessBG {
background-color: purple;
}
.link {
text-decoration: underline;
cursor: pointer;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
const zoneControlState = {
0: "uncaptured",
1: "legion",
2: "swarm",
3: "faceless"
}
const colours = {
0: { r: 1, g: 0.647, b: 0 },
1: { r: 1, g: 0, b: 0 },
2: { r: 0, g: 1, b: 0 },
3: { r: 0.5, g: 0, b: 0.5 }
}
var map = L.map('map', {
center: [15, 30],
zoom: 3,
maxBounds: [[-90, -360], [90, 360]],
worldCopyJump: true
});
map.locate({
setView: true,
maxZoom: 5
}).on("locationfound", function (e) {
L.circle([e.latitude, e.longitude], { color: "cyan", radius: e.accuracy }).bindTooltip("You").addTo(map);
var range_km = 1609.34;
if (new Date().getUTCDay() == 1) { // Monday
var week = Math.floor(new Date().getUTCDate() / 7);
if (week == 1) {
range_km = 4828.032;
} else if (week == 2) {
range_km = 9656.064;
} else if (week >= 3) {
range_km = 20116.8;
}
}
L.circle([e.latitude, e.longitude], { color: "cyan", fillOpacity: 0, weight: .5, radius: range_km * 1000, interactive: false }).addTo(map);
});
var baseMaps = {
"OSM": L.tileLayer.provider("OpenStreetMap.Mapnik"),
"OSM Grayscale": L.tileLayer.provider("OpenStreetMap.BlackAndWhite"),
"CartoDB Positron": L.tileLayer.provider('CartoDB.Positron'),
"CartoDB Dark Matter": L.tileLayer.provider("CartoDB.DarkMatter").addTo(map),
"ESRI WorldImagery": L.tileLayer.provider("Esri.WorldImagery"),
"Google Hybrid": L.tileLayer('http://{s}.google.com/vt/lyrs=s,h&x={x}&y={y}&z={z}', {
maxZoom: 20,
subdomains: ['mt0', 'mt1', 'mt2', 'mt3']
}),
"Wikimedia": L.tileLayer.provider("Wikimedia")
}
var uncaptured = L.layerGroup().addTo(map);
var legion = L.layerGroup().addTo(map);
var swarm = L.layerGroup().addTo(map);
var faceless = L.layerGroup().addTo(map);
var overlays = {
"Uncaptured": uncaptured,
"Legion": legion,
"Swarm": swarm,
"Faceless": faceless,
}
L.control.layers(baseMaps, overlays).addTo(map);
var layers = Object.keys(overlays);
window.teamfilter = [0, 1, 2, 3];
map.on("overlayadd", function (e) {
layers.push(e.name);
var indices = layers.map(e => Object.keys(overlays).indexOf(e));
window.teamfilter = indices;
createPointsLayer();
}).on("overlayremove", function (e) {
layers.splice(layers.indexOf(e.name), 1);
var indices = layers.map(e => Object.keys(overlays).indexOf(e));
window.teamfilter = indices;
createPointsLayer();
});
function clamp(num) {
var min = 10;
var max = 50;
return num <= min ? min : num >= max ? max : num;
}
function formatDelta(delta) {
if (!delta) {
return "";
} else if (delta >= 0) {
delta = "+" + delta.toLocaleString();
}
return " (" + delta.toLocaleString() + ")";
}
function buildDescString(d) {
var className = zoneControlState[d.ZoneControlState]
var desc = "<b class='" + className + "'>" + d.Description + "</b>" +
"<br>Zone ID: " + d.ZoneId +
"<br>Captured: " + d.DateCapturedUtc.slice(0, 19) +
"<br>Last updated: " + d.LastUpdateDateUtc.slice(0, 19) +
"<div class='legion'>Legion: " + d.LegionCount.toLocaleString() + formatDelta(d.LegionDelta) +
"</div><div class='swarm'>Swarm: " + d.SwarmCount.toLocaleString() + formatDelta(d.SwarmDelta) +
"</div><div class='faceless'>Faceless: " + d.FacelessCount.toLocaleString() + formatDelta(d.FacelessDelta) + "</div>";
return desc;
}
function createPointsLayer() {
console.log(window.data.length);
if (window.countfilter == "contested") {
var data = window.data.filter(function(e) {
if (e.ZoneControlState == 0) return false; // Uncaptured zones are by definition uncontested
// A Legion held zone, where the total bot count is equal to the legion bot count, is uncontested
if (e.ZoneControlState == 1 && e.TotalCount == e.LegionCount) return false;
if (e.ZoneControlState == 2 && e.TotalCount == e.SwarmCount) return false;
if (e.ZoneControlState == 3 && e.TotalCount == e.FacelessCount) return false;
return new Date(e.LastUpdateDateUtc.replace(" ", "T") + "Z") > window.timefilter && window.teamfilter.includes(e.ZoneControlState)
});
console.log(data);
} else if (window.countfilter == "colocated") {
var data = window.data.filter(e => e.colocated &&
new Date(e.LastUpdateDateUtc.replace(" ", "T") + "Z") > window.timefilter &&
window.teamfilter.includes(e.ZoneControlState)
)
} else {
var data = window.data.filter(e => e.TotalCount >= window.countfilter &&
new Date(e.LastUpdateDateUtc.replace(" ", "T") + "Z") > window.timefilter &&
window.teamfilter.includes(e.ZoneControlState)
)
}
console.log(data.length);
var points = data.map(e => [e.Latitude, e.Longitude]);
if (window.pointsLayer) window.pointsLayer.remove()
window.pointsLayer = L.glify.points({
map: map,
size: function (i, e) {
return clamp(data[i].TotalCount / 1E6);
},
color: function (i, e) {
return colours[data[i].ZoneControlState]
},
click: function (e, feature) {
var i = points.indexOf(feature);
L.popup()
.setLatLng(e.latlng)
.setContent(buildDescString(data[i]))
.openOn(map);
},
data: points
});
updateStats(data);
}
function updateStats(data) {
var totalLegion = 0, totalSwarm = 0, totalFaceless = 0;
for (var d of data) {
totalLegion += d.LegionCount;
totalSwarm += d.SwarmCount;
totalFaceless += d.FacelessCount;
}
$("#stats").html("<div class='legion'>Total Legion bots:" + totalLegion.toLocaleString() +
"</div><div class='swarm'>Total Swarm bots: " + totalSwarm.toLocaleString() +
"</div><div class='faceless'>Total Faceless bots: " + totalFaceless.toLocaleString() +
"</div><div>Total zones: " + data.length.toLocaleString() + "</div><div id='top10'>Top 10 zones:</div>");
var sorted_data = data.filter(e => e.TotalDelta != undefined).sort((a, b) => a.TotalDelta < b.TotalDelta ? 1 : -1);
var top10 = sorted_data.slice(0, 10);
for (var i in top10) {
var d = top10[i];
var className = zoneControlState[d.ZoneControlState];
var country = countries[d.CountryId].Description;
var region = regions[d.RegionId].description;
$("#top10").append("<div onclick='map.flyTo([" + d.Latitude + "," + d.Longitude + "], 12)' class='link " +
className + "'>" + d.Description + ", " + region + ", " + country + "</div>")
}
}
var baseUrl = "https://raw.githubusercontent.com/neon-ninja/QONQR_zonedata/master/data/";
map.spin(true, { color: "white" });
Papa.parse(baseUrl + "Countries.csv", {
download: true,
header: true,
dynamicTyping: true,
complete: function (countries) {
window.countries = {}
for (var i in countries.data) {
var c = countries.data[i];
window.countries[c.countryid] = c;
}
Papa.parse(baseUrl + "Regions.csv", {
download: true,
header: true,
dynamicTyping: true,
complete: function (regions) {
window.regions = {}
for (var i in regions.data) {
var r = regions.data[i];
window.regions[r.regionid] = r;
}
Papa.parse(baseUrl + "poland.csv", {
download: true,
header: true,
dynamicTyping: true,
skipEmptyLines: true,
complete: function (csv) {
window.data = csv.data;
var pointLookup = {}
for (var d of window.data) {
var p = [d.Latitude, d.Longitude]
if (!pointLookup[p]) {
pointLookup[p] = d;
} else {
pointLookup[p].colocated = true;
pointLookup[p] = d;
d.Longitude += .001;
d.colocated = true;
}
}
createPointsLayer();
map.spin(false);
}
});
}
});
}
});
var legend = L.control({ position: 'bottomright' });
function statsToggle() {
$("#stats").toggle();
}
legend.onAdd = function (map) {
var div = L.DomUtil.create('div', 'info legend');
div.innerHTML += `Shows zones with activity <select id="filtertime">
<option>since 2020-03-16</option>
<option value="month">in the past month</option>
<option value="week">in the past week</option>
<option value="day">in the past day</option>
</select><br>
<select id='filter'>
<option value=0>Show all zones</option>
<option value=10000>Show zones > 10K</option>
<option value=100000>Show zones > 100K</option>
<option value=1000000>Show zones > 1M</option>
<option value=10000000>Show zones > 10M</option>
<option value=contested>Show contested zones</option>
<option value=colocated>Show colocated zones</option>
</select><br>
<a id='statsButton' class='link' onclick='statsToggle()'>Show/hide stats</a><div id='stats' style='display:none'></div>
<a href='https://github.com/neon-ninja/QONQR'>GitHub</a>`;
L.DomEvent.disableClickPropagation(div);
return div;
};
legend.addTo(map);
window.countfilter = 0;
window.timefilter = new Date(0);
$("#filter").change(function () {
window.countfilter = this.value;
createPointsLayer();
})
$("#filtertime").change(function () {
var date = new Date();
var timefilter = new Date(0);
if (this.value == "month") {
timefilter = Date.UTC(date.getUTCFullYear(), date.getUTCMonth() - 1, date.getUTCDate());
} else if (this.value == "week") {
timefilter = Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate() - 7);
} else if (this.value == "day") {
timefilter = Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate() - 1);
}
window.timefilter = timefilter;
createPointsLayer();
})
</script>
</body>
</html>