This commit is contained in:
AngeHerman 2024-04-06 10:42:39 +02:00
parent e97a517f1f
commit 5528c359d6
3 changed files with 30 additions and 203 deletions

View file

@ -44,7 +44,6 @@ public class CSVSchedulesProvider {
private String current_tansport_type = ""; private String current_tansport_type = "";
private LocalDateTime currentHour = null; private LocalDateTime currentHour = null;
private LocalDateTime lastHour = null; private LocalDateTime lastHour = null;
private int debut = 0;

View file

@ -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<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<TraceEntry> currentTrace;
private Iterator<List<StopEntry>> currentPath = Collections.emptyIterator();
private Iterator<StopEntry> currentSegmentStart = Collections.emptyIterator();
private Iterator<StopEntry> currentSegmentEnd = Collections.emptyIterator();
Map<StopEntry, Set<StopEntry>> lineSegments = new HashMap<>();
private final Map<String, Transport> transports;
private StopEntry start = null;
private StopEntry end = null;
private boolean hasNext = false;
private boolean onNext = false;
/**
* Create the stream provider
*/
public CSVStreamSchedulesProvider(Iterator<TraceEntry> traces, Map<String, Transport> 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<StopEntry> 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<String[]> 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,
};
}
}

View file

@ -112,47 +112,47 @@ public class IDFMNetworkExtractor {
LOGGER.log(Level.SEVERE, e, LOGGER.log(Level.SEVERE, e,
() -> MessageFormat.format("Could not write in file {0}", args[1])); () -> MessageFormat.format("Could not write in file {0}", args[1]));
}*/ }*/
System.out.println("****** END ******"); // System.out.println("****** END ******");
System.out.println(transports.size()); // System.out.println(transports.size());
System.out.println(transports.get("IDFM:C01371").name); // System.out.println(transports.get("IDFM:C01371").name);
System.out.println(transports.get("IDFM:C02060").name); // System.out.println(transports.get("IDFM:C02060").name);
// 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"); // Transport b54b = transports.get("IDFM:C00940");
System.out.println("****** AFFICHAGE LIGNE ******"); // System.out.println("****** AFFICHAGE LIGNE ******");
Stop maisonBlanche = ligne_7.stopsMap.get("Maison Blanche"); // Stop maisonBlanche = ligne_7.stopsMap.get("Maison Blanche");
System.out.println(maisonBlanche.name); // System.out.println(maisonBlanche.name);
for (BifStop nextEntry : maisonBlanche.connected.values()) { // for (BifStop nextEntry : maisonBlanche.connected.values()) {
System.out.println(nextEntry.bifurc+ nextEntry.stop.name); // System.out.println(nextEntry.bifurc+ nextEntry.stop.name);
} // }
System.out.println("****** AFFICHAGE LIGNE ******"); // System.out.println("****** AFFICHAGE LIGNE ******");
Stop corientin = ligne_7.stopsMap.get("Corentin Cariou"); // Stop corientin = ligne_7.stopsMap.get("Corentin Cariou");
System.out.println(corientin.name); // System.out.println(corientin.name);
for (BifStop nextEntry : corientin.connected.values()) { // for (BifStop nextEntry : corientin.connected.values()) {
System.out.println(nextEntry.bifurc+ nextEntry.stop.name); // System.out.println(nextEntry.bifurc+ nextEntry.stop.name);
} // }
System.out.println("***************************"); // System.out.println("***************************");
// System.out.println("****** AFFICHAGE Description ******"); // System.out.println("****** AFFICHAGE Description ******");
// System.out.println(traces.get("IDFM:C01377").descriptions); // System.out.println(traces.get("IDFM:C01377").descriptions);
// System.out.println("****** AFFICHAGE Description False ******"); // System.out.println("****** AFFICHAGE Description False ******");
// System.out.println(ligne_7.descriptions); // System.out.println(ligne_7.descriptions);
System.out.println("****************** Build la path ***********************"); // System.out.println("****************** Build la path ***********************");
System.out.println(ligne_7.type); // System.out.println(ligne_7.type);
System.out.println(rerd.type); // System.out.println(rerd.type);
ligne_7.buildBifurcation(); // ligne_7.buildBifurcation();
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 ************************"); // System.out.println("******************Description 54B ************************");
b54b.buildBifurcation(); // b54b.buildBifurcation();
System.out.println(b54b.descriptions); // System.out.println(b54b.descriptions);
System.out.println("******************Building bifurcations ************************"); System.out.println("******************Building bifurcations ************************");
long startTime = System.currentTimeMillis(); 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("Temps écoulé : " + minutes + " minutess, " + seconds + " secndes et " + milliseconds + " millis");
System.out.println("******************Fin Building bifurcations ************************"); 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()); 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(),