Schedule provider connected
This commit is contained in:
parent
1e2d4aceb7
commit
51a63e0606
3 changed files with 140 additions and 2 deletions
|
@ -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<String, int[]> timings = new HashMap<String, int[]>(){{
|
||||||
|
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<Transport> currentTransport;
|
||||||
|
private Iterator<TraceDescription> 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<Transport> 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<String[]> 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,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -119,6 +119,8 @@ public class IDFMNetworkExtractor {
|
||||||
// Transport ligne_1 = transports.get("IDFM:C01371");
|
// Transport ligne_1 = transports.get("IDFM:C01371");
|
||||||
Transport ligne_7 = transports.get("IDFM:C01377");
|
Transport ligne_7 = transports.get("IDFM:C01377");
|
||||||
Transport rerd = transports.get("IDFM:C01728");
|
Transport rerd = transports.get("IDFM:C01728");
|
||||||
|
Transport b54b = transports.get("IDFM:C00940");
|
||||||
|
|
||||||
|
|
||||||
System.out.println("****** AFFICHAGE LIGNE ******");
|
System.out.println("****** AFFICHAGE LIGNE ******");
|
||||||
|
|
||||||
|
@ -148,9 +150,23 @@ public class IDFMNetworkExtractor {
|
||||||
rerd.buildBifurcation();
|
rerd.buildBifurcation();
|
||||||
System.out.println("******************Derniere description ***********************");
|
System.out.println("******************Derniere description ***********************");
|
||||||
System.out.println(ligne_7.descriptions);
|
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]
|
// 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 {
|
try {
|
||||||
CSVTools.writeCSVToFile(args[1], Stream.iterate(providerschedules.next(),
|
CSVTools.writeCSVToFile(args[1], Stream.iterate(providerschedules.next(),
|
||||||
t -> providerschedules.hasNext(), t -> providerschedules.next()));
|
t -> providerschedules.hasNext(), t -> providerschedules.next()));
|
||||||
|
|
|
@ -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){
|
public boolean isTerminus(String stop){
|
||||||
|
|
Reference in a new issue