recuperation de certain mise à jour depuis la branche idf-mobili...
This commit is contained in:
Abdoulbasti 2024-03-14 02:19:25 +01:00
commit d9a5f3a17f
2 changed files with 17 additions and 22 deletions

View file

@ -4,7 +4,6 @@ import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
import fr.u_paris.gla.project.io.ScheduleFormat; import fr.u_paris.gla.project.io.ScheduleFormat;
import java.text.MessageFormat;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -14,27 +13,12 @@ import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import fr.u_paris.gla.project.utils.GPS;
public class CSVStreamSchedulesProvider { public class CSVStreamSchedulesProvider {
/*
* private static final NumberFormat GPS_FORMATTER = ScheduleFormat
* .getGPSFormatter();
*/
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);
} }
/** Number of seconds in a minute. */
private static final int SECONDS_IN_MINUTES = 60;
private static final long SECONDS_IN_HOURS = 3_600;
// Magically chosen values
/** Maximal speed in km/h */
private static final double MAX_SPEED = 5;
/** Distance to reach maximal speed in km */
private static final double TWO_ACCELERATION_DISTANCE = 0.2;
private String[] line = new String[ScheduleFormat.NUMBER_COLUMNS]; private String[] line = new String[ScheduleFormat.NUMBER_COLUMNS];
@ -106,8 +90,15 @@ public class CSVStreamSchedulesProvider {
} }
TraceEntry trace = this.currentTrace.next(); TraceEntry trace = this.currentTrace.next();
this.currentPath = trace.getPaths().iterator(); this.currentPath = trace.getPaths().iterator();
this.line[ScheduleFormat.LINE_INDEX] = trace.lname; this.line[ScheduleFormat.LINE_INDEX] = trace.lname;
this.line[ScheduleFormat.TERMINUS_INDEX] = trace.getTerminus().get(0);
// Write terminus
List<String> terminus = trace.getTerminus();
if (!terminus.isEmpty()) {
this.line[ScheduleFormat.TERMINUS_INDEX] = terminus.get(0);
}
this.lineSegments.clear(); this.lineSegments.clear();
} }
List<StopEntry> path = this.currentPath.next(); List<StopEntry> path = this.currentPath.next();

View file

@ -60,7 +60,8 @@ 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 the arguments (expected one for the destination file) * @param args
* the arguments (expected one for the destination file)
*/ */
public static void main(String[] args) { public static void main(String[] args) {
@ -89,6 +90,7 @@ public class IDFMNetworkExtractor {
CSVStreamProvider provider = new CSVStreamProvider(traces.values().iterator()); CSVStreamProvider provider = new CSVStreamProvider(traces.values().iterator());
// Write into args[0]
try { try {
CSVTools.writeCSVToFile(args[0], Stream.iterate(provider.next(), CSVTools.writeCSVToFile(args[0], Stream.iterate(provider.next(),
t -> provider.hasNext(), t -> provider.next())); t -> provider.hasNext(), t -> provider.next()));
@ -103,6 +105,7 @@ public class IDFMNetworkExtractor {
tmp.getTerminus() tmp.getTerminus()
.forEach(m -> LOGGER.log(Level.INFO, m)); .forEach(m -> LOGGER.log(Level.INFO, m));
// 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()));
@ -153,6 +156,8 @@ public class IDFMNetworkExtractor {
Double.parseDouble(line[IDFM_STOPS_LON_INDEX]), Double.parseDouble(line[IDFM_STOPS_LON_INDEX]),
Double.parseDouble(line[IDFM_STOPS_LAT_INDEX])); Double.parseDouble(line[IDFM_STOPS_LAT_INDEX]));
String rid = line[IDFM_STOPS_RID_INDEX]; String rid = line[IDFM_STOPS_RID_INDEX];
// Add terminus to the traces
if (traces.keySet().contains(rid)) { if (traces.keySet().contains(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));
} }
@ -215,14 +220,13 @@ public class IDFMNetworkExtractor {
return all; return all;
} }
private static List<String> extractTerminus(String pathsJSON) { private static List<String> extractTerminus(String JSON) {
List<String> all = new ArrayList<>(); List<String> all = new ArrayList<>();
try { try {
JSONArray schedules = new JSONArray(pathsJSON); JSONArray schedules = new JSONArray(JSON);
for (int i = 0; i < schedules.length(); i++) { for (int i = 0; i < schedules.length(); i++) {
JSONObject stop = schedules.getJSONObject(i); JSONObject stop = schedules.getJSONObject(i);
String terminus = stop.getString("from"); String terminus = stop.getString("from");
all.add(terminus); all.add(terminus);
} }
} catch ( } catch (
@ -230,7 +234,7 @@ public class IDFMNetworkExtractor {
JSONException e) { JSONException e) {
// Ignoring invalid element! // Ignoring invalid element!
LOGGER.log(Level.FINE, e, LOGGER.log(Level.FINE, e,
() -> MessageFormat.format("Invalid json element {0}", pathsJSON)); //$NON-NLS-1$ () -> MessageFormat.format("Invalid json element {0}", JSON)); //$NON-NLS-1$
} }
return all; return all;