debut export csv
This commit is contained in:
parent
503b5ce35a
commit
c1c69963c8
3 changed files with 97 additions and 78 deletions
|
@ -1,44 +1,36 @@
|
||||||
package fr.u_paris.gla.project.idfm;
|
package fr.u_paris.gla.project.idfm;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import fr.u_paris.gla.project.io.ScheduleFormat;
|
import fr.u_paris.gla.project.io.ScheduleFormat;
|
||||||
|
|
||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
import java.util.Collections;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class CSVStreamSchedulesProvider {
|
public class CSVStreamSchedulesProvider {
|
||||||
private static final NumberFormat MINUTES_SECOND_FORMATTER = NumberFormat
|
private static final NumberFormat MINUTES_SECOND_FORMATTER = NumberFormat
|
||||||
.getInstance(Locale.ENGLISH);
|
.getInstance(Locale.ENGLISH);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
MINUTES_SECOND_FORMATTER.setMinimumIntegerDigits(2);
|
MINUTES_SECOND_FORMATTER.setMinimumIntegerDigits(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String[] line = new String[ScheduleFormat.NUMBER_COLUMNS];
|
private final String[] line = new String[ScheduleFormat.NUMBER_COLUMNS];
|
||||||
|
private final Iterator<TraceEntry> currentTrace;
|
||||||
private Iterator<TraceEntry> currentTrace;
|
private final Map<String, Transport> transports;
|
||||||
|
Map<StopEntry, Set<StopEntry>> lineSegments = new HashMap<>();
|
||||||
private Iterator<List<StopEntry>> currentPath = Collections.emptyIterator();
|
private Iterator<List<StopEntry>> currentPath = Collections.emptyIterator();
|
||||||
private Iterator<StopEntry> currentSegmentStart = Collections.emptyIterator();
|
private Iterator<StopEntry> currentSegmentStart = Collections.emptyIterator();
|
||||||
private Iterator<StopEntry> currentSegmentEnd = Collections.emptyIterator();
|
private Iterator<StopEntry> currentSegmentEnd = Collections.emptyIterator();
|
||||||
Map<StopEntry, Set<StopEntry>> lineSegments = new HashMap<>();
|
|
||||||
|
|
||||||
|
|
||||||
private StopEntry start = null;
|
private StopEntry start = null;
|
||||||
private StopEntry end = null;
|
private StopEntry end = null;
|
||||||
|
|
||||||
private boolean hasNext = false;
|
private boolean hasNext = false;
|
||||||
private boolean onNext = false;
|
private boolean onNext = false;
|
||||||
|
|
||||||
/** Create the stream provider */
|
/**
|
||||||
public CSVStreamSchedulesProvider(Iterator<TraceEntry> traces) {
|
* Create the stream provider
|
||||||
|
*/
|
||||||
|
public CSVStreamSchedulesProvider(Iterator<TraceEntry> traces, Map<String, Transport> t) {
|
||||||
this.currentTrace = traces;
|
this.currentTrace = traces;
|
||||||
|
this.transports = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
|
@ -93,15 +85,34 @@ public class CSVStreamSchedulesProvider {
|
||||||
TraceEntry trace = this.currentTrace.next();
|
TraceEntry trace = this.currentTrace.next();
|
||||||
this.currentPath = trace.getPaths().iterator();
|
this.currentPath = trace.getPaths().iterator();
|
||||||
|
|
||||||
|
// Retrieve transports informations
|
||||||
|
Transport transport = this.transports.get(trace.id);
|
||||||
|
|
||||||
|
// Build bifurcations
|
||||||
|
transport.buildBifurcation();
|
||||||
|
|
||||||
|
// Iterate over possibilites
|
||||||
|
transport.descriptions.forEach(desc -> {
|
||||||
|
// TODO: On doit ajouter toutes les horaires au lieu de mettre que la première
|
||||||
|
Arrays.stream(new String[]{desc.first}).forEach(time -> {
|
||||||
|
// Write line name
|
||||||
this.line[ScheduleFormat.LINE_INDEX] = trace.lname;
|
this.line[ScheduleFormat.LINE_INDEX] = trace.lname;
|
||||||
|
|
||||||
|
// Write bifurcation
|
||||||
|
this.line[ScheduleFormat.TRIP_SEQUENCE_INDEX] = desc.bifurcation.toString();
|
||||||
|
|
||||||
// Write terminus
|
// Write terminus
|
||||||
List<String> terminus = trace.getTerminus();
|
this.line[ScheduleFormat.TERMINUS_INDEX] = desc.from;
|
||||||
if (!terminus.isEmpty()) {
|
|
||||||
this.line[ScheduleFormat.TERMINUS_INDEX] = terminus.get(0);
|
// Write time TODO: Pourquoi ça marche pas ??
|
||||||
}
|
this.line[ScheduleFormat.TIME_INDEX] = time;
|
||||||
|
|
||||||
|
// Test
|
||||||
|
// System.out.println("TEST CSV: " + Arrays.toString(this.line));
|
||||||
|
|
||||||
this.lineSegments.clear();
|
this.lineSegments.clear();
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
List<StopEntry> path = this.currentPath.next();
|
List<StopEntry> path = this.currentPath.next();
|
||||||
this.currentSegmentEnd = path.iterator();
|
this.currentSegmentEnd = path.iterator();
|
||||||
|
|
|
@ -3,25 +3,19 @@
|
||||||
*/
|
*/
|
||||||
package fr.u_paris.gla.project.idfm;
|
package fr.u_paris.gla.project.idfm;
|
||||||
|
|
||||||
import java.io.IOException;
|
import fr.u_paris.gla.project.utils.CSVTools;
|
||||||
import java.text.MessageFormat;
|
import fr.u_paris.gla.project.utils.GPS;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import fr.u_paris.gla.project.utils.CSVTools;
|
import java.io.IOException;
|
||||||
import fr.u_paris.gla.project.utils.GPS;
|
import java.text.MessageFormat;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Code of an extractor for the data from IDF mobilite.
|
* Code of an extractor for the data from IDF mobilite.
|
||||||
|
@ -30,7 +24,9 @@ import fr.u_paris.gla.project.utils.GPS;
|
||||||
*/
|
*/
|
||||||
public class IDFMNetworkExtractor {
|
public class IDFMNetworkExtractor {
|
||||||
|
|
||||||
/** The logger for information on the process */
|
/**
|
||||||
|
* The logger for information on the process
|
||||||
|
*/
|
||||||
private static final Logger LOGGER = Logger
|
private static final Logger LOGGER = Logger
|
||||||
.getLogger(IDFMNetworkExtractor.class.getName());
|
.getLogger(IDFMNetworkExtractor.class.getName());
|
||||||
|
|
||||||
|
@ -50,7 +46,9 @@ public class IDFMNetworkExtractor {
|
||||||
private static final int IDFM_STOPS_LAT_INDEX = 7;
|
private static final int IDFM_STOPS_LAT_INDEX = 7;
|
||||||
|
|
||||||
// Magically chosen values
|
// Magically chosen values
|
||||||
/** A number of stops on each line */
|
/**
|
||||||
|
* A number of stops on each line
|
||||||
|
*/
|
||||||
private static final int GUESS_STOPS_BY_LINE = 5;
|
private static final int GUESS_STOPS_BY_LINE = 5;
|
||||||
|
|
||||||
// Well named constants
|
// Well named constants
|
||||||
|
@ -60,8 +58,7 @@ public class IDFMNetworkExtractor {
|
||||||
* Main entry point for the extractor of IDF mobilite data into a network as
|
* Main entry point for the extractor of IDF mobilite data into a network as
|
||||||
* defined by this application.
|
* defined by this application.
|
||||||
*
|
*
|
||||||
* @param args
|
* @param args the arguments (expected one for the destination file)
|
||||||
* the arguments (expected one for the destination file)
|
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
@ -89,7 +86,7 @@ public class IDFMNetworkExtractor {
|
||||||
cleanTraces(traces);
|
cleanTraces(traces);
|
||||||
|
|
||||||
Map<String, Transport> transports = new HashMap<>();
|
Map<String, Transport> transports = new HashMap<>();
|
||||||
CSVStreamProvider provider = new CSVStreamProvider(traces.values().iterator(),transports);
|
CSVStreamProvider provider = new CSVStreamProvider(traces.values().iterator(), transports);
|
||||||
|
|
||||||
// Write into args[0]
|
// Write into args[0]
|
||||||
try {
|
try {
|
||||||
|
@ -100,20 +97,20 @@ public class IDFMNetworkExtractor {
|
||||||
() -> MessageFormat.format("Could not write in file {0}", args[0]));
|
() -> 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();
|
// TraceEntry tmp = traces.values().iterator().next();
|
||||||
// tmp.getTerminus()
|
// tmp.getTerminus()
|
||||||
// .forEach(m -> LOGGER.log(Level.INFO, m));
|
// .forEach(m -> LOGGER.log(Level.INFO, m));
|
||||||
|
|
||||||
// Write into args[1]
|
// Write into args[1]
|
||||||
// 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()));
|
||||||
// } catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// 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);
|
||||||
|
@ -141,6 +138,15 @@ public class IDFMNetworkExtractor {
|
||||||
System.out.println("******************Derniere description ***********************");
|
System.out.println("******************Derniere description ***********************");
|
||||||
System.out.println(rerd.descriptions);
|
System.out.println(rerd.descriptions);
|
||||||
|
|
||||||
|
// Write into args[1]
|
||||||
|
CSVStreamSchedulesProvider providerschedules = new CSVStreamSchedulesProvider(traces.values().iterator(), transports);
|
||||||
|
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]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void cleanTraces(Map<String, TraceEntry> traces) {
|
private static void cleanTraces(Map<String, TraceEntry> traces) {
|
||||||
|
@ -158,15 +164,16 @@ public class IDFMNetworkExtractor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @param path */
|
/**
|
||||||
|
* @param path
|
||||||
|
*/
|
||||||
private static boolean cleanLine(List<List<StopEntry>> stops) {
|
private static boolean cleanLine(List<List<StopEntry>> stops) {
|
||||||
for (List<StopEntry> path : stops) {
|
for (List<StopEntry> path : stops) {
|
||||||
for (int i = 0; i < path.size(); i++) {
|
for (int i = 0; i < path.size(); i++) {
|
||||||
StopEntry stop = path.get(i);
|
StopEntry stop = path.get(i);
|
||||||
if (!(stop instanceof UnidentifiedStopEntry)) {
|
if (!(stop instanceof UnidentifiedStopEntry unidentified)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
UnidentifiedStopEntry unidentified = (UnidentifiedStopEntry) stop;
|
|
||||||
StopEntry stopResolution = unidentified.resolve();
|
StopEntry stopResolution = unidentified.resolve();
|
||||||
if (stopResolution == null) {
|
if (stopResolution == null) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -185,9 +192,9 @@ public class IDFMNetworkExtractor {
|
||||||
String rid = line[IDFM_STOPS_RID_INDEX];
|
String rid = line[IDFM_STOPS_RID_INDEX];
|
||||||
|
|
||||||
//Add traces description if it's empty
|
//Add traces description if it's empty
|
||||||
if (traces.keySet().contains(rid)) {
|
if (traces.containsKey(rid)) {
|
||||||
TraceEntry tmp = traces.get(rid);
|
TraceEntry tmp = traces.get(rid);
|
||||||
if (tmp.isDescriptionEmpty()){
|
if (tmp.isDescriptionEmpty()) {
|
||||||
List<TraceDescription> descriptions = extractDescription(line[IDFM_STOPS_SCHEDULES_INDEX]);
|
List<TraceDescription> descriptions = extractDescription(line[IDFM_STOPS_SCHEDULES_INDEX]);
|
||||||
tmp.addDescriptions(descriptions);
|
tmp.addDescriptions(descriptions);
|
||||||
}
|
}
|
||||||
|
@ -195,7 +202,7 @@ public class IDFMNetworkExtractor {
|
||||||
|
|
||||||
|
|
||||||
// Add terminus to the traces
|
// Add terminus to the traces
|
||||||
if (traces.keySet().contains(rid)) {
|
if (traces.containsKey(rid)) {
|
||||||
extractTerminus(line[IDFM_STOPS_SCHEDULES_INDEX]).forEach(t -> traces.get(rid).addTerminus(t));
|
extractTerminus(line[IDFM_STOPS_SCHEDULES_INDEX]).forEach(t -> traces.get(rid).addTerminus(t));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,7 +212,7 @@ public class IDFMNetworkExtractor {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addLine(String[] line, Map<String, TraceEntry> traces) {
|
private static void addLine(String[] line, Map<String, TraceEntry> traces) {
|
||||||
TraceEntry entry = new TraceEntry(line[IDFM_TRACE_SNAME_INDEX],line[IDFM_TRACE_ID_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]);
|
List<List<StopEntry>> buildPaths = buildPaths(line[IDFM_TRACE_SHAPE_INDEX]);
|
||||||
entry.getPaths().addAll(buildPaths);
|
entry.getPaths().addAll(buildPaths);
|
||||||
if (buildPaths.isEmpty()) {
|
if (buildPaths.isEmpty()) {
|
||||||
|
|
|
@ -25,13 +25,14 @@ public class Transport {
|
||||||
|
|
||||||
Stop debut = stopsMap.get(d.from);
|
Stop debut = stopsMap.get(d.from);
|
||||||
Stop fin = stopsMap.get(d.to);
|
Stop fin = stopsMap.get(d.to);
|
||||||
|
if (debut != null && fin != null) {
|
||||||
SimpleEntry<Boolean,List<Integer> > sol = roadToLast(debut.name, debut.name, fin.name, new ArrayList<String>(), new ArrayList<Integer>());
|
SimpleEntry<Boolean, List<Integer>> sol = roadToLast(debut.name, debut.name, fin.name, new ArrayList<String>(), new ArrayList<Integer>());
|
||||||
if(sol.getKey()){
|
if (sol.getKey()) {
|
||||||
found ++;
|
found++;
|
||||||
d.bifurcation = sol.getValue();
|
d.bifurcation = sol.getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
System.out.println("J'en ai trouvé "+found);
|
System.out.println("J'en ai trouvé "+found);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue