Search in sources :

Example 1 with CSVGymDataReader

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());
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Gym(pokeraidbot.domain.gym.Gym) CSVGymDataReader(pokeraidbot.infrastructure.CSVGymDataReader) FileInputStream(java.io.FileInputStream) LinkedList(java.util.LinkedList)

Example 2 with CSVGymDataReader

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);
        }
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Config(pokeraidbot.infrastructure.jpa.config.Config) CSVGymDataReader(pokeraidbot.infrastructure.CSVGymDataReader)

Example 3 with CSVGymDataReader

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);
}
Also used : Set(java.util.Set) GymRepository(pokeraidbot.domain.gym.GymRepository) HashMap(java.util.HashMap) Config(pokeraidbot.infrastructure.jpa.config.Config) Gym(pokeraidbot.domain.gym.Gym) CSVGymDataReader(pokeraidbot.infrastructure.CSVGymDataReader)

Aggregations

CSVGymDataReader (pokeraidbot.infrastructure.CSVGymDataReader)3 Gym (pokeraidbot.domain.gym.Gym)2 Config (pokeraidbot.infrastructure.jpa.config.Config)2 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 GymRepository (pokeraidbot.domain.gym.GymRepository)1