From 5528c359d6b65cdd4e96ddce11100409adce576c Mon Sep 17 00:00:00 2001 From: AngeHerman Date: Sat, 6 Apr 2024 10:42:39 +0200 Subject: [PATCH] Cleaning --- .../project/idfm/CSVSchedulesProvider.java | 1 - .../idfm/CSVStreamSchedulesProvider.java | 165 ------------------ .../project/idfm/IDFMNetworkExtractor.java | 67 ++++--- 3 files changed, 30 insertions(+), 203 deletions(-) delete mode 100644 src/main/java/fr/u_paris/gla/project/idfm/CSVStreamSchedulesProvider.java diff --git a/src/main/java/fr/u_paris/gla/project/idfm/CSVSchedulesProvider.java b/src/main/java/fr/u_paris/gla/project/idfm/CSVSchedulesProvider.java index 37a3553..b06035b 100644 --- a/src/main/java/fr/u_paris/gla/project/idfm/CSVSchedulesProvider.java +++ b/src/main/java/fr/u_paris/gla/project/idfm/CSVSchedulesProvider.java @@ -44,7 +44,6 @@ public class CSVSchedulesProvider { private String current_tansport_type = ""; private LocalDateTime currentHour = null; private LocalDateTime lastHour = null; - private int debut = 0; diff --git a/src/main/java/fr/u_paris/gla/project/idfm/CSVStreamSchedulesProvider.java b/src/main/java/fr/u_paris/gla/project/idfm/CSVStreamSchedulesProvider.java deleted file mode 100644 index a718d66..0000000 --- a/src/main/java/fr/u_paris/gla/project/idfm/CSVStreamSchedulesProvider.java +++ /dev/null @@ -1,165 +0,0 @@ -package fr.u_paris.gla.project.idfm; - -import fr.u_paris.gla.project.io.ScheduleFormat; - -import java.text.NumberFormat; -import java.util.*; - -public class CSVStreamSchedulesProvider { - private static final HashMap timings = new HashMap(){{ - put("Bus", new int[]{11, 8, 7}); - put("Funicular", new int[]{15, 25, 20}); - put("Tram", new int[]{6, 7, 8, 9}); - put("Rail", new int[]{10, 11,15,12}); - put("Subway", new int[]{4, 2, 6,3,3,4}); - }}; - private static final NumberFormat MINUTES_SECOND_FORMATTER = NumberFormat - .getInstance(Locale.ENGLISH); - - static { - MINUTES_SECOND_FORMATTER.setMinimumIntegerDigits(2); - } - - private final String[] line = new String[ScheduleFormat.NUMBER_COLUMNS]; - private final Iterator currentTrace; - private Iterator> currentPath = Collections.emptyIterator(); - private Iterator currentSegmentStart = Collections.emptyIterator(); - private Iterator currentSegmentEnd = Collections.emptyIterator(); - Map> lineSegments = new HashMap<>(); - private final Map transports; - - private StopEntry start = null; - private StopEntry end = null; - private boolean hasNext = false; - private boolean onNext = false; - - /** - * Create the stream provider - */ - public CSVStreamSchedulesProvider(Iterator traces, Map t) { - this.currentTrace = traces; - this.transports = t; - } - - public boolean hasNext() { - if (!this.onNext) { - skipToNext(); - } - return this.hasNext; - } - - private void skipToNext() { - if (this.onNext) { - return; - } - while (!this.onNext) { - if (!this.currentSegmentEnd.hasNext()) { - skipToNextCandidatePath(); - } - if (this.onNext) { - return; - } - skipToNextNewSegment(); - } - } - - private void skipToNextNewSegment() { - do { - this.start = this.currentSegmentStart.next(); - this.lineSegments.putIfAbsent(this.start, new HashSet<>()); - this.end = this.currentSegmentEnd.next(); - } while (this.lineSegments.get(this.start).contains(this.end) - && this.currentSegmentEnd.hasNext()); - if (!this.lineSegments.get(this.start).contains(this.end)) { - this.lineSegments.get(this.start).add(this.end); - this.onNext = true; - this.hasNext = true; - } - } - - /** - * Move the reading head of path to the next one that has at least two - * elements - */ - private void skipToNextCandidatePath() { - currentSegmentStart = null; - do { - while (!this.currentPath.hasNext()) { - if (!this.currentTrace.hasNext()) { - this.hasNext = false; - this.onNext = true; - return; - } - TraceEntry trace = this.currentTrace.next(); - this.currentPath = trace.getPaths().iterator(); - } - - List path = this.currentPath.next(); - this.currentSegmentEnd = path.iterator(); - if (this.currentSegmentEnd.hasNext()) { - this.currentSegmentEnd.next(); - this.currentSegmentStart = path.iterator(); - } - } while (currentSegmentStart == null); - } - - public String[][] next() { - if (!this.onNext) { - skipToNext(); - } - this.onNext = false; - - /**/ - - if (!this.currentTrace.hasNext()) { - return new String[][]{Arrays.copyOf(this.line, this.line.length)}; - } - TraceEntry trace = this.currentTrace.next(); - - // Retrieve transports informations - Transport transport = this.transports.get(trace.id); - - // Build bifurcations - transport.buildBifurcation(); - - // Store all lines for this iteration - List allLines = new ArrayList<>(); - - // Iterate over possibilites - transport.descriptions.forEach(desc -> { - // TODO: On doit ajouter toutes les horaires au lieu de mettre que la première - Arrays.stream(findTimes(desc.first, desc.last)).forEach(time -> { - // Create a new line array - String[] newLine = Arrays.copyOf(this.line, this.line.length); - - // Write line name - newLine[ScheduleFormat.LINE_INDEX] = trace.lname; - - // Write bifurcation - newLine[ScheduleFormat.TRIP_SEQUENCE_INDEX] = desc.bifurcation.toString(); - - // Write terminus - newLine[ScheduleFormat.TERMINUS_INDEX] = desc.from; - - // Write time - newLine[ScheduleFormat.TIME_INDEX] = time; - - // Add the new line to the list of lines for this iteration - allLines.add(Arrays.copyOf(newLine, newLine.length)); - }); - - this.lineSegments.clear(); - }); - - - return allLines.toArray(new String[0][]); - } - - private String[] findTimes(String start, String last) { - return new String[]{ - start, - /* TODO: fill with random values each n minutes */ - last, - }; - } -} 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 1ad8fa4..55e0bc2 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 @@ -112,47 +112,47 @@ public class IDFMNetworkExtractor { LOGGER.log(Level.SEVERE, e, () -> MessageFormat.format("Could not write in file {0}", args[1])); }*/ - System.out.println("****** END ******"); - System.out.println(transports.size()); - System.out.println(transports.get("IDFM:C01371").name); - System.out.println(transports.get("IDFM:C02060").name); + // System.out.println("****** END ******"); + // System.out.println(transports.size()); + // System.out.println(transports.get("IDFM:C01371").name); + // System.out.println(transports.get("IDFM:C02060").name); // Transport ligne_1 = transports.get("IDFM:C01371"); - Transport ligne_7 = transports.get("IDFM:C01377"); - Transport rerd = transports.get("IDFM:C01728"); - Transport b54b = transports.get("IDFM:C00940"); + // Transport ligne_7 = transports.get("IDFM:C01377"); + // Transport rerd = transports.get("IDFM:C01728"); + // Transport b54b = transports.get("IDFM:C00940"); - System.out.println("****** AFFICHAGE LIGNE ******"); + // System.out.println("****** AFFICHAGE LIGNE ******"); - Stop maisonBlanche = ligne_7.stopsMap.get("Maison Blanche"); - System.out.println(maisonBlanche.name); + // Stop maisonBlanche = ligne_7.stopsMap.get("Maison Blanche"); + // System.out.println(maisonBlanche.name); - for (BifStop nextEntry : maisonBlanche.connected.values()) { - System.out.println(nextEntry.bifurc+ nextEntry.stop.name); - } - System.out.println("****** AFFICHAGE LIGNE ******"); + // for (BifStop nextEntry : maisonBlanche.connected.values()) { + // System.out.println(nextEntry.bifurc+ nextEntry.stop.name); + // } + // System.out.println("****** AFFICHAGE LIGNE ******"); - Stop corientin = ligne_7.stopsMap.get("Corentin Cariou"); - System.out.println(corientin.name); + // Stop corientin = ligne_7.stopsMap.get("Corentin Cariou"); + // System.out.println(corientin.name); - for (BifStop nextEntry : corientin.connected.values()) { - System.out.println(nextEntry.bifurc+ nextEntry.stop.name); - } - System.out.println("***************************"); + // for (BifStop nextEntry : corientin.connected.values()) { + // System.out.println(nextEntry.bifurc+ nextEntry.stop.name); + // } + // System.out.println("***************************"); // System.out.println("****** AFFICHAGE Description ******"); // System.out.println(traces.get("IDFM:C01377").descriptions); // System.out.println("****** AFFICHAGE Description False ******"); // System.out.println(ligne_7.descriptions); - System.out.println("****************** Build la path ***********************"); - System.out.println(ligne_7.type); - System.out.println(rerd.type); - ligne_7.buildBifurcation(); - rerd.buildBifurcation(); - System.out.println("******************Derniere description ***********************"); - System.out.println(ligne_7.descriptions); - System.out.println("******************Description 54B ************************"); - b54b.buildBifurcation(); - System.out.println(b54b.descriptions); + // System.out.println("****************** Build la path ***********************"); + // System.out.println(ligne_7.type); + // System.out.println(rerd.type); + // ligne_7.buildBifurcation(); + // rerd.buildBifurcation(); + // System.out.println("******************Derniere description ***********************"); + // System.out.println(ligne_7.descriptions); + // System.out.println("******************Description 54B ************************"); + // b54b.buildBifurcation(); + // System.out.println(b54b.descriptions); System.out.println("******************Building bifurcations ************************"); long startTime = System.currentTimeMillis(); @@ -170,14 +170,7 @@ public class IDFMNetworkExtractor { System.out.println("Temps écoulé : " + minutes + " minutess, " + seconds + " secndes et " + milliseconds + " millis"); System.out.println("******************Fin Building bifurcations ************************"); - // System.out.println("Transport size :"+transports.size()); - // System.out.println("Trace size :"+traces.size()); - - - - // Write into args[1] - // CSVStreamSchedulesProvider providerschedules = new CSVStreamSchedulesProvider(traces.values().iterator(), transports); CSVSchedulesProvider providerschedules = new CSVSchedulesProvider(transports.values().iterator()); try { CSVTools.writeCSVToFile(args[1], Stream.iterate(providerschedules.next(),