diff --git a/src/main/java/fr/u_paris/gla/project/idfm/IDFMNetworkExtractor.java b/src/main/java/fr/u_paris/gla/project/idfm/IDFMNetworkExtractor.java index 55e0bc2..7791003 100644 --- a/src/main/java/fr/u_paris/gla/project/idfm/IDFMNetworkExtractor.java +++ b/src/main/java/fr/u_paris/gla/project/idfm/IDFMNetworkExtractor.java @@ -10,6 +10,7 @@ import org.json.JSONException; import org.json.JSONObject; import java.io.IOException; +import java.io.File; import java.text.MessageFormat; import java.util.*; import java.util.Map.Entry; @@ -46,6 +47,10 @@ public class IDFMNetworkExtractor { private static final int IDFM_STOPS_LON_INDEX = 6; private static final int IDFM_STOPS_LAT_INDEX = 7; + private static final String TRACE_FILE_NAME = "trace.csv"; + + private static final String HOURS_FILE_NAME = "hours.csv"; + // Magically chosen values /** * A number of stops on each line @@ -181,6 +186,82 @@ public class IDFMNetworkExtractor { } } + public static boolean checkFileExistence(String filePath) { + File file = new File(filePath); + if (file.exists()) { + LOGGER.severe(filePath+ " already exists."); + return true; + } else { + LOGGER.severe(filePath + " does not exist."); + return false; + } + } + + public static void builFiles() { + + if (checkFileExistence("./"+HOURS_FILE_NAME) && checkFileExistence("./"+TRACE_FILE_NAME)) { + LOGGER.severe("Files already exists."); + return; + } + + Map traces = new HashMap<>(); + try { + CSVTools.readCSVFromURL(TRACE_FILE_URL, + (String[] line) -> addLine(line, traces)); + } catch (IOException e) { + LOGGER.log(Level.SEVERE, "Error while reading the line paths", e); + } + + List stops = new ArrayList<>(traces.size() * GUESS_STOPS_BY_LINE); + try { + CSVTools.readCSVFromURL(STOPS_FILE_URL, + (String[] line) -> addStop(line, traces, stops)); + } catch (IOException e) { + LOGGER.log(Level.SEVERE, "Error while reading the stops", e); + } + + cleanTraces(traces); + + Map transports = new HashMap<>(); + CSVStreamProvider provider = new CSVStreamProvider(traces.values().iterator(), transports); + + // Write into args[0] + try { + CSVTools.writeCSVToFile(TRACE_FILE_NAME, Stream.iterate(provider.next(), + t -> provider.hasNext(), t -> provider.next())); + } catch (IOException e) { + LOGGER.log(Level.SEVERE, e, + () -> MessageFormat.format("Could not write in file {0}", TRACE_FILE_NAME)); + } + + System.out.println("******************Building bifurcations ************************"); + long startTime = System.currentTimeMillis(); + + for (Transport entry : transports.values()) { + entry.buildBifurcationOptimzed(); + } + + long endTime = System.currentTimeMillis(); + long tempsPasse = endTime - startTime; + + long minutes = (tempsPasse / 1000) / 60; + long seconds = (tempsPasse / 1000) % 60; + long milliseconds = tempsPasse % 1000; + + System.out.println("Temps écoulé : " + minutes + " minutess, " + seconds + " secndes et " + milliseconds + " millis"); + + System.out.println("******************Fin Building bifurcations ************************"); + + CSVSchedulesProvider providerschedules = new CSVSchedulesProvider(transports.values().iterator()); + try { + CSVTools.writeCSVToFile(HOURS_FILE_NAME, Stream.iterate(providerschedules.next(), + t -> providerschedules.hasNext(), t -> providerschedules.next())); + } catch (IOException e) { + LOGGER.log(Level.SEVERE, e, + () -> MessageFormat.format("Could not write in file {0}", HOURS_FILE_NAME)); + } + } + private static void cleanTraces(Map traces) { Set toRemove = new HashSet<>(); for (Entry traceEntry : traces.entrySet()) { diff --git a/src/main/java/fr/u_paris/gla/project/itinerary/ItineraryCalculator.java b/src/main/java/fr/u_paris/gla/project/itinerary/ItineraryCalculator.java index 5391c19..fcce253 100644 --- a/src/main/java/fr/u_paris/gla/project/itinerary/ItineraryCalculator.java +++ b/src/main/java/fr/u_paris/gla/project/itinerary/ItineraryCalculator.java @@ -94,7 +94,8 @@ public class ItineraryCalculator { Stop toStop = getOrCreateStop(nodes, tmp, line[IDFM_TRACE_TO_INDEX], line[IDFM_TRACE_TO_GPS_INDEX], line[IDFM_TRACE_ID_INDEX]); String[] timeString = line[IDFM_TRACE_TIME_INDEX].split(":"); - int time = Integer.parseInt(timeString[0]) * 60 + Integer.parseInt(timeString[1]); + String time0WithoutComma = timeString[0].replace(",", ""); + int time = Integer.parseInt(time0WithoutComma) * 60 + Integer.parseInt(timeString[1]); Connection connection = new Connection(toStop, line[IDFM_TRACE_ID_INDEX], Double.parseDouble(line[IDFM_TRACE_DISTANCE_INDEX]), time); @@ -106,6 +107,7 @@ public class ItineraryCalculator { LOGGER.severe("Invalid command line. Target file names are in the main file for now."); return; } + IDFMNetworkExtractor.builFiles(); try { HashSet nodes = new HashSet<>();