use of pokeraidbot.infrastructure.CSVGymDataReader in project pokeraidbot by magnusmickelsson.
the class GymDataImportTool method reportDiffBetweenOldAndNewFileIfExists.
private static void reportDiffBetweenOldAndNewFileIfExists(String location) {
try {
CSVGymDataReader oldGymDataReader = new CSVGymDataReader("/gyms_" + location + ".csv");
InputStream exStream = GymDataImportTool.class.getResourceAsStream("/gyms_" + location + ".csv.ex.txt");
CSVGymDataReader newGymDataReader;
if (exStream != null) {
newGymDataReader = new CSVGymDataReader(new FileInputStream("target/" + location + ".csv"), exStream);
} else {
newGymDataReader = new CSVGymDataReader(new FileInputStream("target/" + location + ".csv"));
}
final Set<Gym> oldGyms = oldGymDataReader.readAll();
final Set<Gym> newGyms = newGymDataReader.readAll();
int sameCount = 0;
LinkedList<String> report = new LinkedList<>();
LinkedList<String> focusReport = new LinkedList<>();
for (Gym newGym : newGyms) {
if (!oldGyms.contains(newGym)) {
boolean weird = false;
for (Gym oldGym : oldGyms) {
if (oldGym.getX().equals(newGym.getX()) && oldGym.getY().equals(newGym.getY())) {
focusReport.add("New name for old gym? Old: " + oldGym + " - New: " + newGym);
weird = true;
} else if (oldGym.getId().equals(newGym.getId())) {
focusReport.add("Reused ID for old gym? Old: " + oldGym + " - New: " + newGym);
weird = true;
} else if (oldGym.getName().trim().equalsIgnoreCase(newGym.getName().trim())) {
focusReport.add("Potential duplicate. Old: " + oldGym + " - New: " + newGym);
weird = true;
}
}
if (!weird) {
focusReport.add("New gym: " + newGym);
}
} else {
sameCount++;
}
}
for (Gym oldGym : oldGyms) {
boolean weird = false;
if (!newGyms.contains(oldGym)) {
for (Gym newGym : newGyms) {
if (oldGym.getX().equals(newGym.getX()) && oldGym.getY().equals(newGym.getY())) {
LOGGER.debug("OLD: New name for old gym? Old: " + oldGym + " - New: " + newGym);
weird = true;
} else if (oldGym.getId().equals(newGym.getId())) {
LOGGER.debug("OLD: Reused ID for old gym? Old: " + oldGym + " - New: " + newGym);
weird = true;
} else if (oldGym.getName().equalsIgnoreCase(newGym.getName())) {
LOGGER.debug("OLD: Potential duplicate. Old: " + oldGym + " - New: " + newGym);
weird = true;
}
}
if (!weird) {
report.add("Removed gym: " + oldGym);
}
} else {
report.add("Exists in old and new: " + oldGym);
}
}
for (String r : report) {
System.out.println(r);
}
for (String r : focusReport) {
System.out.println(r);
}
System.out.println("\nREPORT:\n\nOld gyms: " + oldGyms.size() + ", new gyms: " + newGyms.size() + ", diff: " + (newGyms.size() - oldGyms.size()) + ", same in both: " + sameCount);
} catch (Throwable t) {
System.out.printf("Could not perform a diff between old gym file and new one: " + t.getMessage());
}
}
use of pokeraidbot.infrastructure.CSVGymDataReader in project pokeraidbot by magnusmickelsson.
the class GymRepository method reloadGymData.
public void reloadGymData() {
if (serverConfigRepository != null) {
Map<String, Config> configMap = serverConfigRepository.getAllConfig();
Map<String, Set<Gym>> gymsPerRegion = new HashMap<>();
LOGGER.info("Config has following servers: " + configMap.keySet());
for (String server : configMap.keySet()) {
final Config config = serverConfigRepository.getConfigForServer(server);
final String region = config.getRegion();
final Set<Gym> existingGyms = gymsPerRegion.get(region);
if (existingGyms == null) {
try {
final Set<Gym> gymsInRegion = new CSVGymDataReader("/gyms_" + region + ".csv").readAll();
gymsPerRegion.put(region, gymsInRegion);
LOGGER.info("Loaded " + gymsInRegion.size() + " gyms for region " + region + ".");
} catch (Throwable t) {
LOGGER.warn("Could not load data for region " + region + ", skipping.");
}
}
}
for (String region : gymsPerRegion.keySet()) {
Set<Gym> gymsForRegion = gymsPerRegion.get(region);
this.gymsPerRegion.put(region, gymsForRegion);
}
}
}
use of pokeraidbot.infrastructure.CSVGymDataReader in project pokeraidbot by magnusmickelsson.
the class TestServerMain method getGymRepositoryForConfig.
public static GymRepository getGymRepositoryForConfig(LocaleService localeService, ServerConfigRepository serverConfigRepository) {
Map<String, Set<Gym>> gymsPerRegion = new HashMap<>();
final Map<String, Config> configMap = serverConfigRepository.getAllConfig();
System.out.println("Config has following servers: " + configMap.keySet());
for (String server : configMap.keySet()) {
final Config config = serverConfigRepository.getConfigForServer(server);
final String region = config.getRegion();
if (!gymsPerRegion.containsKey(region)) {
final Set<Gym> gymsInRegion = new CSVGymDataReader("/gyms_" + region + ".csv").readAll();
gymsPerRegion.put(region, gymsInRegion);
System.out.println("Loaded " + gymsInRegion.size() + " gyms for server " + server + ".");
}
}
return new GymRepository(gymsPerRegion, localeService);
}
Aggregations