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 new file mode 100644 index 0000000..afbd983 --- /dev/null +++ b/src/main/java/fr/u_paris/gla/project/idfm/CSVSchedulesProvider.java @@ -0,0 +1,122 @@ +package fr.u_paris.gla.project.idfm; + +import fr.u_paris.gla.project.io.ScheduleFormat; + +import java.text.NumberFormat; +import java.util.*; +public class CSVSchedulesProvider { + 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 currentTransport; + private Iterator currentDescription = Collections.emptyIterator(); + + // private Stop start = null; + // private Stop end = null; + // private boolean hasNext = false; + // private boolean onNext = false; + private int hours_count = 0; + private String last_hour = ""; + + /** + * Create the stream provider + */ + public CSVSchedulesProvider(Iterator transports) { + this.currentTransport = transports; + } + + public boolean hasNext() { + return currentTransport.hasNext() || currentDescription.hasNext(); + } + + private void skipToNext() { + if (hours_count == 2){ + skipToNextDescription(); + hours_count = 0; + }else if(hours_count == 1){ + this.line[ScheduleFormat.TIME_INDEX] = last_hour; + }else if (!this.currentDescription.hasNext()) { + skipToNextTransport(); + } + + } + + private void skipToNextDescription() { + if (this.currentDescription.hasNext()) { + TraceDescription description = this.currentDescription.next(); + hours_count = 0; + // this.start = new Stop(description.from); + // this.end = new Stop(description.to); + this.line[ScheduleFormat.TERMINUS_INDEX] = description.from; + this.line[ScheduleFormat.TRIP_SEQUENCE_INDEX] = description.bifurcation.toString(); + this.line[ScheduleFormat.TIME_INDEX] = description.first; + last_hour = description.last; + // this.onNext = true; + // this.hasNext = true; + }else{ + skipToNextTransport(); + } + } + + private void skipToNextTransport() { + if (this.currentTransport.hasNext()) { + Transport transport = this.currentTransport.next(); + this.line[ScheduleFormat.LINE_INDEX] = transport.name; + // transport.buildBifurcation(); + this.currentDescription = transport.descriptions.iterator(); + skipToNextDescription(); + } else { + // this.onNext = true; + // this.hasNext = false; + } + } + + public String[][] next() { + if (!hasNext()) { + return null; + } + skipToNext(); + hours_count ++; + return new String[][]{Arrays.copyOf(this.line, this.line.length)}; + + // if (!this.currentTransport.hasNext()) { + // return new String[][]{Arrays.copyOf(this.line, this.line.length)}; + // } + // Transport transport = this.currentTransport.next(); + + // // Store all lines for this iteration + // List allLines = new ArrayList<>(); + + // transport.descriptions.forEach(desc -> { + // Arrays.stream(findTimes(desc.first, desc.last)).forEach(time -> { + // String[] newLine = Arrays.copyOf(this.line, this.line.length); + // newLine[ScheduleFormat.LINE_INDEX] = transport.name; + // newLine[ScheduleFormat.TRIP_SEQUENCE_INDEX] = desc.bifurcation.toString(); + // newLine[ScheduleFormat.TERMINUS_INDEX] = desc.to; + // newLine[ScheduleFormat.TIME_INDEX] = time; + // allLines.add(Arrays.copyOf(newLine, newLine.length)); + // }); + // }); + + // return allLines.toArray(new String[0][]); + } + + private String[] findTimes(String start, String last) { + return new String[]{ + start, + last, + }; + } +} \ No newline at end of file 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 df3e2c0..53622c4 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 @@ -119,6 +119,8 @@ public class IDFMNetworkExtractor { // 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"); + System.out.println("****** AFFICHAGE LIGNE ******"); @@ -148,9 +150,23 @@ public class IDFMNetworkExtractor { 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 ************************"); + for (Transport entry : transports.values()) { + entry.buildBifurcation(); + } + 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); + // CSVStreamSchedulesProvider providerschedules = new CSVStreamSchedulesProvider(traces.values().iterator(), transports); + CSVSchedulesProvider providerschedules = new CSVSchedulesProvider(transports.values().iterator()); try { CSVTools.writeCSVToFile(args[1], Stream.iterate(providerschedules.next(), t -> providerschedules.hasNext(), t -> providerschedules.next())); diff --git a/src/main/java/fr/u_paris/gla/project/idfm/Transport.java b/src/main/java/fr/u_paris/gla/project/idfm/Transport.java index a66658f..e16e7e1 100644 --- a/src/main/java/fr/u_paris/gla/project/idfm/Transport.java +++ b/src/main/java/fr/u_paris/gla/project/idfm/Transport.java @@ -35,7 +35,7 @@ public class Transport { } } } - System.out.println("J'en ai trouvé "+found); + // System.out.println("J'en ai trouvé "+found); } public boolean isTerminus(String stop){