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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
|
||||
import fr.u_paris.gla.project.io.ScheduleFormat;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
public class CSVStreamSchedulesProvider {
|
||||
private static final NumberFormat MINUTES_SECOND_FORMATTER = NumberFormat
|
||||
.getInstance(Locale.ENGLISH);
|
||||
|
||||
static {
|
||||
MINUTES_SECOND_FORMATTER.setMinimumIntegerDigits(2);
|
||||
}
|
||||
|
||||
private String[] line = new String[ScheduleFormat.NUMBER_COLUMNS];
|
||||
|
||||
private Iterator<TraceEntry> currentTrace;
|
||||
private final String[] line = new String[ScheduleFormat.NUMBER_COLUMNS];
|
||||
private final 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<StopEntry> currentSegmentStart = Collections.emptyIterator();
|
||||
private Iterator<StopEntry> currentSegmentEnd = Collections.emptyIterator();
|
||||
Map<StopEntry, Set<StopEntry>> lineSegments = new HashMap<>();
|
||||
|
||||
|
||||
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) {
|
||||
/**
|
||||
* Create the stream provider
|
||||
*/
|
||||
public CSVStreamSchedulesProvider(Iterator<TraceEntry> traces, Map<String, Transport> t) {
|
||||
this.currentTrace = traces;
|
||||
this.transports = t;
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
|
@ -93,15 +85,34 @@ public class CSVStreamSchedulesProvider {
|
|||
TraceEntry trace = this.currentTrace.next();
|
||||
this.currentPath = trace.getPaths().iterator();
|
||||
|
||||
this.line[ScheduleFormat.LINE_INDEX] = trace.lname;
|
||||
// Retrieve transports informations
|
||||
Transport transport = this.transports.get(trace.id);
|
||||
|
||||
// Write terminus
|
||||
List<String> terminus = trace.getTerminus();
|
||||
if (!terminus.isEmpty()) {
|
||||
this.line[ScheduleFormat.TERMINUS_INDEX] = terminus.get(0);
|
||||
}
|
||||
// Build bifurcations
|
||||
transport.buildBifurcation();
|
||||
|
||||
this.lineSegments.clear();
|
||||
// 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;
|
||||
|
||||
// Write bifurcation
|
||||
this.line[ScheduleFormat.TRIP_SEQUENCE_INDEX] = desc.bifurcation.toString();
|
||||
|
||||
// Write terminus
|
||||
this.line[ScheduleFormat.TERMINUS_INDEX] = desc.from;
|
||||
|
||||
// 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();
|
||||
});
|
||||
});
|
||||
}
|
||||
List<StopEntry> path = this.currentPath.next();
|
||||
this.currentSegmentEnd = path.iterator();
|
||||
|
|
|
@ -3,25 +3,19 @@
|
|||
*/
|
||||
package fr.u_paris.gla.project.idfm;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.MessageFormat;
|
||||
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 fr.u_paris.gla.project.utils.CSVTools;
|
||||
import fr.u_paris.gla.project.utils.GPS;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import fr.u_paris.gla.project.utils.CSVTools;
|
||||
import fr.u_paris.gla.project.utils.GPS;
|
||||
import java.io.IOException;
|
||||
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.
|
||||
|
@ -30,7 +24,9 @@ import fr.u_paris.gla.project.utils.GPS;
|
|||
*/
|
||||
public class IDFMNetworkExtractor {
|
||||
|
||||
/** The logger for information on the process */
|
||||
/**
|
||||
* The logger for information on the process
|
||||
*/
|
||||
private static final Logger LOGGER = Logger
|
||||
.getLogger(IDFMNetworkExtractor.class.getName());
|
||||
|
||||
|
@ -50,7 +46,9 @@ public class IDFMNetworkExtractor {
|
|||
private static final int IDFM_STOPS_LAT_INDEX = 7;
|
||||
|
||||
// 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;
|
||||
|
||||
// Well named constants
|
||||
|
@ -60,8 +58,7 @@ public class IDFMNetworkExtractor {
|
|||
* Main entry point for the extractor of IDF mobilite data into a network as
|
||||
* defined by this application.
|
||||
*
|
||||
* @param args
|
||||
* the arguments (expected one for the destination file)
|
||||
* @param args the arguments (expected one for the destination file)
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
@ -89,7 +86,7 @@ public class IDFMNetworkExtractor {
|
|||
cleanTraces(traces);
|
||||
|
||||
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]
|
||||
try {
|
||||
|
@ -100,20 +97,20 @@ 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));
|
||||
|
||||
// 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);
|
||||
|
@ -141,6 +138,15 @@ public class IDFMNetworkExtractor {
|
|||
System.out.println("******************Derniere description ***********************");
|
||||
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) {
|
||||
|
@ -158,15 +164,16 @@ public class IDFMNetworkExtractor {
|
|||
}
|
||||
}
|
||||
|
||||
/** @param path */
|
||||
/**
|
||||
* @param path
|
||||
*/
|
||||
private static boolean cleanLine(List<List<StopEntry>> stops) {
|
||||
for (List<StopEntry> path : stops) {
|
||||
for (int i = 0; i < path.size(); i++) {
|
||||
StopEntry stop = path.get(i);
|
||||
if (!(stop instanceof UnidentifiedStopEntry)) {
|
||||
if (!(stop instanceof UnidentifiedStopEntry unidentified)) {
|
||||
continue;
|
||||
}
|
||||
UnidentifiedStopEntry unidentified = (UnidentifiedStopEntry) stop;
|
||||
StopEntry stopResolution = unidentified.resolve();
|
||||
if (stopResolution == null) {
|
||||
return false;
|
||||
|
@ -178,24 +185,24 @@ public class IDFMNetworkExtractor {
|
|||
}
|
||||
|
||||
private static void addStop(String[] line, Map<String, TraceEntry> traces,
|
||||
List<StopEntry> stops) {
|
||||
List<StopEntry> stops) {
|
||||
StopEntry entry = new StopEntry(line[IDFM_STOPS_NAME_INDEX],
|
||||
Double.parseDouble(line[IDFM_STOPS_LON_INDEX]),
|
||||
Double.parseDouble(line[IDFM_STOPS_LAT_INDEX]));
|
||||
String rid = line[IDFM_STOPS_RID_INDEX];
|
||||
|
||||
|
||||
//Add traces description if it's empty
|
||||
if (traces.keySet().contains(rid)) {
|
||||
if (traces.containsKey(rid)) {
|
||||
TraceEntry tmp = traces.get(rid);
|
||||
if (tmp.isDescriptionEmpty()){
|
||||
if (tmp.isDescriptionEmpty()) {
|
||||
List<TraceDescription> descriptions = extractDescription(line[IDFM_STOPS_SCHEDULES_INDEX]);
|
||||
tmp.addDescriptions(descriptions);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 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));
|
||||
}
|
||||
|
||||
|
@ -205,7 +212,7 @@ public class IDFMNetworkExtractor {
|
|||
}
|
||||
|
||||
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]);
|
||||
entry.getPaths().addAll(buildPaths);
|
||||
if (buildPaths.isEmpty()) {
|
||||
|
@ -221,8 +228,8 @@ public class IDFMNetworkExtractor {
|
|||
for (StopEntry stopEntry : path) {
|
||||
if (stopEntry instanceof UnidentifiedStopEntry unidentified
|
||||
&& GPS.distance(entry.latitude, entry.longitude,
|
||||
stopEntry.latitude,
|
||||
stopEntry.longitude) < QUARTER_KILOMETER) {
|
||||
stopEntry.latitude,
|
||||
stopEntry.longitude) < QUARTER_KILOMETER) {
|
||||
unidentified.addCandidate(entry);
|
||||
}
|
||||
}
|
||||
|
@ -268,7 +275,7 @@ public class IDFMNetworkExtractor {
|
|||
}
|
||||
} catch (
|
||||
|
||||
JSONException e) {
|
||||
JSONException e) {
|
||||
// Ignoring invalid element!
|
||||
LOGGER.log(Level.FINE, e,
|
||||
() -> MessageFormat.format("Invalid json element {0}", JSON)); //$NON-NLS-1$
|
||||
|
@ -289,7 +296,7 @@ public class IDFMNetworkExtractor {
|
|||
String last = stop.getString("last");
|
||||
//We skip the lines where from equals to
|
||||
// if(from.compareTo(to) != 0){
|
||||
all.add(new TraceDescription(from, to, first, last));
|
||||
all.add(new TraceDescription(from, to, first, last));
|
||||
// }
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
|
|
|
@ -25,11 +25,12 @@ public class Transport {
|
|||
|
||||
Stop debut = stopsMap.get(d.from);
|
||||
Stop fin = stopsMap.get(d.to);
|
||||
|
||||
SimpleEntry<Boolean,List<Integer> > sol = roadToLast(debut.name, debut.name, fin.name, new ArrayList<String>(), new ArrayList<Integer>());
|
||||
if(sol.getKey()){
|
||||
found ++;
|
||||
d.bifurcation = sol.getValue();
|
||||
if (debut != null && fin != null) {
|
||||
SimpleEntry<Boolean, List<Integer>> sol = roadToLast(debut.name, debut.name, fin.name, new ArrayList<String>(), new ArrayList<Integer>());
|
||||
if (sol.getKey()) {
|
||||
found++;
|
||||
d.bifurcation = sol.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("J'en ai trouvé "+found);
|
||||
|
@ -55,7 +56,7 @@ public class Transport {
|
|||
}
|
||||
List<String> visitedCopy = new ArrayList<>(alreadyVisited);
|
||||
visitedCopy.add(currentStop);
|
||||
|
||||
|
||||
Stop current = stopsMap.get(currentStop);
|
||||
int i = 1;
|
||||
List <SimpleEntry<Boolean,List<Integer>> > solutions = new ArrayList<>();
|
||||
|
@ -80,7 +81,7 @@ public class Transport {
|
|||
}
|
||||
return new SimpleEntry<>(trouve,bifSol) ;
|
||||
}
|
||||
|
||||
|
||||
public void addStop(String start,String end,String bifurcation){
|
||||
Stop start_stop;
|
||||
Stop end_stop;
|
||||
|
@ -100,10 +101,10 @@ public class Transport {
|
|||
start_stop.connected.add( end_stop);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param stopsMap
|
||||
* @param start
|
||||
* @param end
|
||||
|
|
Reference in a new issue