Code Cleanup

Geolocation Map now scales
This commit is contained in:
Fuzzlemann 2017-07-26 22:27:07 +02:00
parent 2f16beebe4
commit 176d28a535
3 changed files with 953 additions and 951 deletions

View File

@ -6,7 +6,7 @@ import java.util.Map;
/**
* Part responsible for all Geolocation related analysis.
* <p>
* Player location World Chloropleth map.
* Player location World Choropleth map.
* <p>
* Placeholder values can be retrieved using the get method.
* <p>
@ -17,46 +17,44 @@ import java.util.Map;
*/
public class GeolocationPart extends RawData<GeolocationPart> {
private final Map<String, Integer> geolocations;
private final Map<String, Integer> geoLocations;
private final Map<String, String> geoCodes;
public GeolocationPart() {
geolocations = new HashMap<>();
geoLocations = new HashMap<>();
geoCodes = new HashMap<>();
String[] countries = new String[]{"Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antigua and Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas, The", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegovina", "Botswana", "Brazil", "British Virgin Islands", "Brunei", "Bulgaria", "Burkina Faso", "Burma", "Burundi", "Cabo Verde", "Cambodia", "Cameroon", "Canada", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China", "Colombia", "Comoros", "Congo, Democratic Republic of the", "Congo, Republic of the", "Cook Islands", "Costa Rica", "Cote d'Ivoire", "Croatia", "Cuba", "Curacao", "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Falkland Islands (Islas Malvinas)", "Faroe Islands", "Fiji", "Finland", "France", "French Polynesia", "Gabon", "Gambia, The", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guam", "Guatemala", "Guernsey", "Guinea-Bissau", "Guinea", "Guyana", "Haiti", "Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Isle of Man", "Israel", "Italy", "Jamaica", "Japan", "Jersey", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Korea, North", "Korea, South", "Kosovo", "Kuwait", "Kyrgyzstan", "Laos", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", "Macau", "Macedonia", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Mauritania", "Mauritius", "Mexico", "Micronesia, Federated States of", "Moldova", "Monaco", "Mongolia", "Montenegro", "Morocco", "Mozambique", "Namibia", "Nepal", "Netherlands", "New Caledonia", "New Zealand", "Nicaragua", "Nigeria", "Niger", "Niue", "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Poland", "Portugal", "Puerto Rico", "Qatar", "Romania", "Russia", "Rwanda", "Saint Kitts and Nevis", "Saint Lucia", "Saint Martin", "Saint Pierre and Miquelon", "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia", "Seychelles", "Sierra Leone", "Singapore", "Sint Maarten", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "South Sudan", "Spain", "Sri Lanka", "Sudan", "Suriname", "Swaziland", "Sweden", "Switzerland", "Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "Timor-Leste", "Togo", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela", "Vietnam", "Virgin Islands", "West Bank", "Yemen", "Zambia", "Zimbabwe"};
String[] codes = new String[]{"AFG", "ALB", "DZA", "ASM", "AND", "AGO", "AIA", "ATG", "ARG", "ARM", "ABW", "AUS", "AUT", "AZE", "BHM", "BHR", "BGD", "BRB", "BLR", "BEL", "BLZ", "BEN", "BMU", "BTN", "BOL", "BIH", "BWA", "BRA", "VGB", "BRN", "BGR", "BFA", "MMR", "BDI", "CPV", "KHM", "CMR", "CAN", "CYM", "CAF", "TCD", "CHL", "CHN", "COL", "COM", "COD", "COG", "COK", "CRI", "CIV", "HRV", "CUB", "CUW", "CYP", "CZE", "DNK", "DJI", "DMA", "DOM", "ECU", "EGY", "SLV", "GNQ", "ERI", "EST", "ETH", "FLK", "FRO", "FJI", "FIN", "FRA", "PYF", "GAB", "GMB", "GEO", "DEU", "GHA", "GIB", "GRC", "GRL", "GRD", "GUM", "GTM", "GGY", "GNB", "GIN", "GUY", "HTI", "HND", "HKG", "HUN", "ISL", "IND", "IDN", "IRN", "IRQ", "IRL", "IMN", "ISR", "ITA", "JAM", "JPN", "JEY", "JOR", "KAZ", "KEN", "KIR", "KOR", "PRK", "KSV", "KWT", "KGZ", "LAO", "LVA", "LBN", "LSO", "LBR", "LBY", "LIE", "LTU", "LUX", "MAC", "MKD", "MDG", "MWI", "MYS", "MDV", "MLI", "MLT", "MHL", "MRT", "MUS", "MEX", "FSM", "MDA", "MCO", "MNG", "MNE", "MAR", "MOZ", "NAM", "NPL", "NLD", "NCL", "NZL", "NIC", "NGA", "NER", "NIU", "MNP", "NOR", "OMN", "PAK", "PLW", "PAN", "PNG", "PRY", "PER", "PHL", "POL", "PRT", "PRI", "QAT", "ROU", "RUS", "RWA", "KNA", "LCA", "MAF", "SPM", "VCT", "WSM", "SMR", "STP", "SAU", "SEN", "SRB", "SYC", "SLE", "SGP", "SXM", "SVK", "SVN", "SLB", "SOM", "ZAF", "SSD", "ESP", "LKA", "SDN", "SUR", "SWZ", "SWE", "CHE", "SYR", "TWN", "TJK", "TZA", "THA", "TLS", "TGO", "TON", "TTO", "TUN", "TUR", "TKM", "TUV", "UGA", "UKR", "ARE", "GBR", "USA", "URY", "UZB", "VUT", "VEN", "VNM", "VGB", "WBG", "YEM", "ZMB", "ZWE"};
for (int i = 0; i < countries.length; i++) {
String country = countries[i];
geolocations.put(country, 0);
geoCodes.put(country, codes[i]);
String countryCode = codes[i];
geoLocations.put(country, 0);
geoCodes.put(country, countryCode);
}
}
@Override
public void analyse() {
cloroplethMapValues();
choroplethMapValues();
}
private void cloroplethMapValues() {
StringBuilder locations = new StringBuilder();
StringBuilder z = new StringBuilder();
StringBuilder text = new StringBuilder();
locations.append("[");
z.append("[");
text.append("[");
private void choroplethMapValues() {
StringBuilder locations = new StringBuilder("[");
StringBuilder z = new StringBuilder("[");
StringBuilder text = new StringBuilder("[");
int i = 0;
int size = geolocations.size();
for (String c : geolocations.keySet()) {
locations.append("\"").append(c).append("\"");
z.append("\"").append(geolocations.get(c)).append("\"");
text.append("\"");
String code = geoCodes.get(c);
if (code != null) {
text.append(code);
} else {
text.append("UNK");
}
text.append("\"");
int size = geoLocations.size();
for (Map.Entry<String, Integer> entrySet : geoLocations.entrySet()) {
String country = entrySet.getKey();
String code = geoCodes.getOrDefault(country, "UNK");
int amount = entrySet.getValue();
z.append("\"").append(amount).append("\"");
locations.append("\"").append(country).append("\"");
text.append("\"").append(code).append("\"");
if (i < size - 1) {
locations.append(",");
@ -64,16 +62,18 @@ public class GeolocationPart extends RawData<GeolocationPart> {
text.append(",");
}
}
locations.append("]");
z.append("]");
text.append("]");
addValue("geomapz", z.toString());
addValue("geomapcountries", locations.toString());
addValue("geomapcodes", text.toString());
}
public void addGeoloc(String country) {
geolocations.computeIfPresent(country, (computedCountry, amount) -> amount + 1);
geoLocations.computeIfPresent(country, (computedCountry, amount) -> amount + 1);
}
}

View File

@ -93,7 +93,7 @@ public class TPSTable extends Table {
int players = set.getInt(columnPlayers);
double cpuUsage = set.getDouble(columnCPUUsage);
//TODO add new data
data.add(new TPS(date, tps, players, cpuUsage));
data.add(new TPS(date, tps, players, cpuUsage, 0, 0, 0));
}
return data;
} finally {

File diff suppressed because it is too large Load Diff