Objetct Transport and Stop filled
This commit is contained in:
parent
2585c3552a
commit
16c875bb68
8 changed files with 153529 additions and 16 deletions
|
@ -25,3 +25,4 @@ L'option de lancement `--info` causera l'affichage dans la console d'information
|
|||
|
||||
L'option de lancement `--gui` causera l'ouverture d'une fenêtre affichant le logo de l'Université de Paris.
|
||||
|
||||
mvn verify && java -jar target/project-2024.1.0.0-SNAPSHOT.jar prof.csv nous.csv
|
||||
|
|
|
@ -42,6 +42,8 @@ public final class CSVStreamProvider {
|
|||
private Iterator<StopEntry> currentSegmentStart = Collections.emptyIterator();
|
||||
private Iterator<StopEntry> currentSegmentEnd = Collections.emptyIterator();
|
||||
Map<StopEntry, Set<StopEntry>> lineSegments = new HashMap<>();
|
||||
// The transport id with its value
|
||||
private Map<String, Transport> transports;
|
||||
|
||||
private StopEntry start = null;
|
||||
private StopEntry end = null;
|
||||
|
@ -49,9 +51,11 @@ public final class CSVStreamProvider {
|
|||
private boolean hasNext = false;
|
||||
private boolean onNext = false;
|
||||
|
||||
private String id = "";
|
||||
/** Create the stream provider */
|
||||
public CSVStreamProvider(Iterator<TraceEntry> traces) {
|
||||
public CSVStreamProvider(Iterator<TraceEntry> traces, Map<String, Transport> t) {
|
||||
this.currentTrace = traces;
|
||||
transports = t;
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
|
@ -102,6 +106,7 @@ public final class CSVStreamProvider {
|
|||
return;
|
||||
}
|
||||
TraceEntry trace = this.currentTrace.next();
|
||||
id = trace.id;
|
||||
this.currentPath = trace.getPaths().iterator();
|
||||
this.line[NetworkFormat.LINE_INDEX] = trace.lname;
|
||||
this.lineSegments.clear();
|
||||
|
@ -131,7 +136,7 @@ public final class CSVStreamProvider {
|
|||
(long) Math.ceil(distanceToTime(distance) * SECONDS_IN_HOURS));
|
||||
this.line[NetworkFormat.VARIANT_INDEX] = Integer
|
||||
.toString(this.lineSegments.get(this.start).size() - 1);
|
||||
|
||||
fillTransports();
|
||||
return Arrays.copyOf(this.line, this.line.length);
|
||||
}
|
||||
|
||||
|
@ -165,4 +170,20 @@ public final class CSVStreamProvider {
|
|||
+ Math.pow(Math.min(distance, TWO_ACCELERATION_DISTANCE) / MAX_SPEED, 2);
|
||||
}
|
||||
|
||||
private void fillTransports() {
|
||||
String nameTransport = this.line[NetworkFormat.LINE_INDEX];
|
||||
String start_p = this.line[NetworkFormat.START_INDEX];
|
||||
String end_p = this.line[NetworkFormat.STOP_INDEX];
|
||||
String bifurcation = this.line[NetworkFormat.VARIANT_INDEX];
|
||||
Transport transp = null;
|
||||
if(!transports.containsKey(id)){
|
||||
transp = new Transport(nameTransport);
|
||||
transports.put(id, transp);
|
||||
}else{
|
||||
transp = transports.get(id);
|
||||
}
|
||||
transp.addStop(start_p, end_p, bifurcation);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -88,7 +88,8 @@ public class IDFMNetworkExtractor {
|
|||
|
||||
cleanTraces(traces);
|
||||
|
||||
CSVStreamProvider provider = new CSVStreamProvider(traces.values().iterator());
|
||||
Map<String, Transport> transports = new HashMap<>();
|
||||
CSVStreamProvider provider = new CSVStreamProvider(traces.values().iterator(),transports);
|
||||
|
||||
// Write into args[0]
|
||||
try {
|
||||
|
@ -99,20 +100,38 @@ public class IDFMNetworkExtractor {
|
|||
() -> MessageFormat.format("Could not write in file {0}", args[0]));
|
||||
}
|
||||
|
||||
CSVStreamSchedulesProvider providerschedules = new CSVStreamSchedulesProvider(traces.values().iterator());
|
||||
// CSVStreamSchedulesProvider providerschedules = new CSVStreamSchedulesProvider(traces.values().iterator());
|
||||
|
||||
TraceEntry tmp = traces.values().iterator().next();
|
||||
tmp.getTerminus()
|
||||
.forEach(m -> LOGGER.log(Level.INFO, m));
|
||||
// TraceEntry tmp = traces.values().iterator().next();
|
||||
// tmp.getTerminus()
|
||||
// .forEach(m -> LOGGER.log(Level.INFO, m));
|
||||
|
||||
// Write into args[1]
|
||||
try {
|
||||
CSVTools.writeCSVToFile(args[1], 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}", args[1]));
|
||||
// try {
|
||||
// CSVTools.writeCSVToFile(args[1], 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}", 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);
|
||||
// Transport ligne_1 = transports.get("IDFM:C01371");
|
||||
Transport ligne_7 = transports.get("IDFM:C01377");
|
||||
System.out.println("****** AFFICHAGE LIGNE ******");
|
||||
|
||||
Stop maisonBlanche = ligne_7.stopsMap.get("Maison Blanche");
|
||||
System.out.println(maisonBlanche.name);
|
||||
|
||||
for (Stop nextEntry : maisonBlanche.connected) {
|
||||
System.out.println(nextEntry.name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static void cleanTraces(Map<String, TraceEntry> traces) {
|
||||
|
@ -125,7 +144,6 @@ public class IDFMNetworkExtractor {
|
|||
toRemove.add(traceEntry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
for (String string : toRemove) {
|
||||
traces.remove(string);
|
||||
}
|
||||
|
@ -168,7 +186,7 @@ public class IDFMNetworkExtractor {
|
|||
}
|
||||
|
||||
private static void addLine(String[] line, Map<String, TraceEntry> traces) {
|
||||
TraceEntry entry = new TraceEntry(line[IDFM_TRACE_SNAME_INDEX]);
|
||||
TraceEntry entry = new TraceEntry(line[IDFM_TRACE_SNAME_INDEX],line[IDFM_TRACE_ID_INDEX]);
|
||||
List<List<StopEntry>> buildPaths = buildPaths(line[IDFM_TRACE_SHAPE_INDEX]);
|
||||
entry.getPaths().addAll(buildPaths);
|
||||
if (buildPaths.isEmpty()) {
|
||||
|
|
19
src/main/java/fr/u_paris/gla/project/idfm/Stop.java
Normal file
19
src/main/java/fr/u_paris/gla/project/idfm/Stop.java
Normal file
|
@ -0,0 +1,19 @@
|
|||
package fr.u_paris.gla.project.idfm;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
|
||||
public class Stop {
|
||||
Map<String, Stop> next = new HashMap<>();
|
||||
Map<String, Stop> previous = new HashMap<>();
|
||||
List<Stop> connected = new ArrayList<>();
|
||||
|
||||
public String name;
|
||||
|
||||
public Stop(String n){
|
||||
name = n;
|
||||
}
|
||||
}
|
|
@ -13,18 +13,22 @@ import java.util.List;
|
|||
*/
|
||||
public final class TraceEntry {
|
||||
public final String lname;
|
||||
public final String id;
|
||||
|
||||
|
||||
private List<String> terminus = new ArrayList<>();
|
||||
private List<List<StopEntry>> paths = new ArrayList<>();
|
||||
|
||||
|
||||
/**
|
||||
* Create a transport line.
|
||||
*
|
||||
* @param lname the name of the line
|
||||
*/
|
||||
public TraceEntry(String lname) {
|
||||
public TraceEntry(String lname,String ident) {
|
||||
super();
|
||||
this.lname = lname;
|
||||
this.id = ident;
|
||||
}
|
||||
|
||||
// FIXME list of lists are bad practice in direct access...
|
||||
|
|
129
src/main/java/fr/u_paris/gla/project/idfm/Transport.java
Normal file
129
src/main/java/fr/u_paris/gla/project/idfm/Transport.java
Normal file
|
@ -0,0 +1,129 @@
|
|||
package fr.u_paris.gla.project.idfm;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
|
||||
public class Transport {
|
||||
Map<String, Stop> stopsMap = new LinkedHashMap<>();
|
||||
public String name;
|
||||
private boolean goingNext = true;
|
||||
|
||||
public Transport(String n){
|
||||
name = n;
|
||||
}
|
||||
|
||||
public void addStop(String start,String end,String bifurcation){
|
||||
// String saveLastEndStop = lastStop;
|
||||
// if(stopsMap.size() == 0){
|
||||
// stopsMap.put(start, new Stop(start));
|
||||
Stop start_stop;
|
||||
Stop end_stop;
|
||||
if (!stopsMap.containsKey(start)){
|
||||
start_stop = new Stop(start);
|
||||
stopsMap.put(start, start_stop);
|
||||
}else{
|
||||
start_stop = stopsMap.get(start);
|
||||
}
|
||||
|
||||
if (!stopsMap.containsKey(end)){
|
||||
end_stop = new Stop(end);
|
||||
stopsMap.put(end, end_stop);
|
||||
}else{
|
||||
end_stop = stopsMap.get(end);
|
||||
}
|
||||
start_stop.connected.add( end_stop);
|
||||
if(start.equals("Maison Blanche") && end.equals("Tolbiac")){
|
||||
System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
|
||||
for (Stop nextEntry : start_stop.connected) {
|
||||
System.out.println(nextEntry.name);
|
||||
}
|
||||
|
||||
}
|
||||
if(start.equals("Tolbiac") && end.equals("Maison Blanche")){
|
||||
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
|
||||
|
||||
}
|
||||
// if(stopsMap.size() == 0){
|
||||
// start_stop.next.put(bifurcation, end_stop);
|
||||
// }else{
|
||||
// if(goingNext){
|
||||
// if(start.equals("Porte Maillot") && end.equals("Les Sablons")){
|
||||
// System.out.println("<<<<<<<<<<<<<<<Arrivé au probleme<<<<<<<<<<<<<<<<<<");
|
||||
// System.out.println(startBeforeEnd(end, start));
|
||||
// System.out.println(startBeforeEnd(start, end));
|
||||
// System.out.println(end_stop.next.containsValue(start_stop));
|
||||
// for (Map.Entry<String, Stop> nextEntry : end_stop.next.entrySet()) {
|
||||
// System.out.println(nextEntry.getKey() + ": " + nextEntry.getValue().name);
|
||||
// }
|
||||
|
||||
// }
|
||||
// if( startBeforeEnd(start, end)){
|
||||
// start_stop.next.put(bifurcation, end_stop);
|
||||
// }else{
|
||||
// if(end_stop.next.containsValue(start_stop)){
|
||||
// goingNext = false;
|
||||
// start_stop.previous.put(bifurcation, end_stop);
|
||||
// }else{ //Probleme de la zone artisanale (ligne 20 du bus 56)
|
||||
// start_stop.next.put(bifurcation, end_stop);
|
||||
// }
|
||||
|
||||
// }
|
||||
// }else{
|
||||
// start_stop.previous.put(bifurcation, end_stop);
|
||||
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param stopsMap
|
||||
* @param start
|
||||
* @param end
|
||||
* @return true if the start stop has been added before the end stop
|
||||
*/
|
||||
public boolean startBeforeEnd( String start, String end) {
|
||||
for (String key : stopsMap.keySet()) {
|
||||
if (key.equals(start)) {
|
||||
return true;
|
||||
}
|
||||
if (key.equals(end)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void printAllNextStops() {
|
||||
System.out.println("Affichage des couples (stop, next du stop):");
|
||||
for (Map.Entry<String, Stop> entry : stopsMap.entrySet()) {
|
||||
Stop stop = entry.getValue();
|
||||
System.out.println("Stop: " + stop.name);
|
||||
System.out.println("Next:");
|
||||
for (Map.Entry<String, Stop> nextEntry : stop.next.entrySet()) {
|
||||
System.out.println(nextEntry.getKey() + ": " + nextEntry.getValue().name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Méthode pour afficher tous les couples (stop, previous du stop)
|
||||
public void printAllPreviousStops() {
|
||||
System.out.println("Affichage des couples (stop, previous du stop):");
|
||||
for (Map.Entry<String, Stop> entry : stopsMap.entrySet()) {
|
||||
Stop stop = entry.getValue();
|
||||
System.out.println("Stop: " + stop.name);
|
||||
System.out.println("Previous:");
|
||||
for (Map.Entry<String, Stop> prevEntry : stop.previous.entrySet()) {
|
||||
System.out.println(prevEntry.getKey() + ": " + prevEntry.getValue().name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in a new issue