mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-14 12:11:23 +01:00
[#942] Reproduced & fixed WorldMap error
Error was caused by two different unknown geolocations ("Local Machine", "Not Known") mapping to null due to missing Geo code (eg. 'FIN')
This commit is contained in:
parent
0f32c030e6
commit
a235bda099
@ -23,7 +23,6 @@ import org.apache.commons.text.TextStringBuilder;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* World Map that uses iso-a3 specification of Country codes.
|
||||
@ -59,8 +58,19 @@ public class WorldMap implements HighChart {
|
||||
|
||||
private Map<String, Integer> toGeoCodeCounts(Map<String, Integer> geolocationCounts) {
|
||||
Map<String, String> geoCodes = getGeoCodes();
|
||||
return geolocationCounts.entrySet().stream()
|
||||
.collect(Collectors.toMap(entry -> geoCodes.get(entry.getKey().toLowerCase()), Map.Entry::getValue));
|
||||
Map<String, Integer> geoCodeCounts = new HashMap<>();
|
||||
|
||||
for (Map.Entry<String, Integer> entry : geolocationCounts.entrySet()) {
|
||||
String geolocation = entry.getKey().toLowerCase();
|
||||
String geoCode = geoCodes.get(geolocation);
|
||||
if (geoCode == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
geoCodeCounts.put(geoCode, entry.getValue());
|
||||
}
|
||||
|
||||
return geoCodeCounts;
|
||||
}
|
||||
|
||||
private Map<String, Integer> toGeoCodeCounts(List<String> geoLocations) {
|
||||
|
@ -75,6 +75,9 @@ public class MySQLTest extends CommonDBTest {
|
||||
UUID firstUuid = UUID.randomUUID();
|
||||
UUID secondUuid = UUID.randomUUID();
|
||||
UUID thirdUuid = UUID.randomUUID();
|
||||
UUID fourthUuid = UUID.randomUUID();
|
||||
UUID fifthUuid = UUID.randomUUID();
|
||||
UUID sixthUuid = UUID.randomUUID();
|
||||
|
||||
db.executeTransaction(new PlayerRegisterTransaction(firstUuid, () -> 0L, ""));
|
||||
db.executeTransaction(new PlayerRegisterTransaction(secondUuid, () -> 0L, ""));
|
||||
@ -84,6 +87,9 @@ public class MySQLTest extends CommonDBTest {
|
||||
saveGeoInfo(firstUuid, new GeoInfo("-", "Finland", 5, "3"));
|
||||
saveGeoInfo(secondUuid, new GeoInfo("-", "Sweden", 0, "3"));
|
||||
saveGeoInfo(thirdUuid, new GeoInfo("-", "Denmark", 0, "3"));
|
||||
saveGeoInfo(fourthUuid, new GeoInfo("-", "Denmark", 0, "3"));
|
||||
saveGeoInfo(fifthUuid, new GeoInfo("-", "Not Known", 0, "3"));
|
||||
saveGeoInfo(sixthUuid, new GeoInfo("-", "Local Machine", 0, "3"));
|
||||
|
||||
Map<String, Integer> got = db.query(ServerAggregateQueries.networkGeolocationCounts());
|
||||
|
||||
@ -91,7 +97,9 @@ public class MySQLTest extends CommonDBTest {
|
||||
// first user has a more recent connection from Finland so their country should be counted as Finland.
|
||||
expected.put("Finland", 1);
|
||||
expected.put("Sweden", 1);
|
||||
expected.put("Denmark", 1);
|
||||
expected.put("Not Known", 1);
|
||||
expected.put("Local Machine", 1);
|
||||
expected.put("Denmark", 2);
|
||||
|
||||
assertEquals(expected, got);
|
||||
}
|
||||
|
@ -92,6 +92,9 @@ public class SQLiteTest extends CommonDBTest {
|
||||
UUID firstUuid = UUID.randomUUID();
|
||||
UUID secondUuid = UUID.randomUUID();
|
||||
UUID thirdUuid = UUID.randomUUID();
|
||||
UUID fourthUuid = UUID.randomUUID();
|
||||
UUID fifthUuid = UUID.randomUUID();
|
||||
UUID sixthUuid = UUID.randomUUID();
|
||||
|
||||
db.executeTransaction(new PlayerRegisterTransaction(firstUuid, () -> 0L, ""));
|
||||
db.executeTransaction(new PlayerRegisterTransaction(secondUuid, () -> 0L, ""));
|
||||
@ -101,6 +104,9 @@ public class SQLiteTest extends CommonDBTest {
|
||||
saveGeoInfo(firstUuid, new GeoInfo("-", "Finland", 5, "3"));
|
||||
saveGeoInfo(secondUuid, new GeoInfo("-", "Sweden", 0, "3"));
|
||||
saveGeoInfo(thirdUuid, new GeoInfo("-", "Denmark", 0, "3"));
|
||||
saveGeoInfo(fourthUuid, new GeoInfo("-", "Denmark", 0, "3"));
|
||||
saveGeoInfo(fifthUuid, new GeoInfo("-", "Not Known", 0, "3"));
|
||||
saveGeoInfo(sixthUuid, new GeoInfo("-", "Local Machine", 0, "3"));
|
||||
|
||||
Map<String, Integer> got = db.query(ServerAggregateQueries.networkGeolocationCounts());
|
||||
|
||||
@ -108,7 +114,9 @@ public class SQLiteTest extends CommonDBTest {
|
||||
// first user has a more recent connection from Finland so their country should be counted as Finland.
|
||||
expected.put("Finland", 1);
|
||||
expected.put("Sweden", 1);
|
||||
expected.put("Denmark", 1);
|
||||
expected.put("Not Known", 1);
|
||||
expected.put("Local Machine", 1);
|
||||
expected.put("Denmark", 2);
|
||||
|
||||
assertEquals(expected, got);
|
||||
}
|
||||
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan.utilities.html.graphs.special;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.platform.runner.JUnitPlatform;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Test against exceptions due to unnamed geolocations.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@RunWith(JUnitPlatform.class)
|
||||
class WorldMapTest {
|
||||
|
||||
@Test
|
||||
void toGeolocationCountsCausesNoException() {
|
||||
Map<String, Integer> geolocations = new HashMap<>();
|
||||
geolocations.put("Finland", 1);
|
||||
geolocations.put("Sweden", 1);
|
||||
geolocations.put("Not Known", 1);
|
||||
geolocations.put("Local Machine", 1);
|
||||
geolocations.put("Denmark", 2);
|
||||
|
||||
String expected = "[{'code':'SWE','value':1},{'code':'DNK','value':2},{'code':'FIN','value':1}]";
|
||||
String result = new WorldMap(geolocations).toHighChartsSeries();
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user