From 2585c3552a15aad7f0f731406550233cce5b6e0a Mon Sep 17 00:00:00 2001 From: Mylloon Date: Mon, 11 Mar 2024 16:13:29 +0100 Subject: [PATCH] do not crash --- .../idfm/CSVStreamSchedulesProvider.java | 25 ++++++------------- .../project/idfm/IDFMNetworkExtractor.java | 14 +++++++---- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/src/main/java/fr/u_paris/gla/project/idfm/CSVStreamSchedulesProvider.java b/src/main/java/fr/u_paris/gla/project/idfm/CSVStreamSchedulesProvider.java index a5c91eb..d45493a 100644 --- a/src/main/java/fr/u_paris/gla/project/idfm/CSVStreamSchedulesProvider.java +++ b/src/main/java/fr/u_paris/gla/project/idfm/CSVStreamSchedulesProvider.java @@ -4,7 +4,6 @@ import java.util.Arrays; import java.util.Iterator; import fr.u_paris.gla.project.io.ScheduleFormat; -import java.text.MessageFormat; import java.text.NumberFormat; import java.util.Collections; import java.util.HashMap; @@ -14,27 +13,12 @@ import java.util.Locale; import java.util.Map; import java.util.Set; -import fr.u_paris.gla.project.utils.GPS; - public class CSVStreamSchedulesProvider { - - /* - * private static final NumberFormat GPS_FORMATTER = ScheduleFormat - * .getGPSFormatter(); - */ private static final NumberFormat MINUTES_SECOND_FORMATTER = NumberFormat .getInstance(Locale.ENGLISH); static { 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]; @@ -106,8 +90,15 @@ public class CSVStreamSchedulesProvider { } TraceEntry trace = this.currentTrace.next(); this.currentPath = trace.getPaths().iterator(); + this.line[ScheduleFormat.LINE_INDEX] = trace.lname; - this.line[ScheduleFormat.TERMINUS_INDEX] = trace.getTerminus().get(0); + + // Write terminus + List terminus = trace.getTerminus(); + if (!terminus.isEmpty()) { + this.line[ScheduleFormat.TERMINUS_INDEX] = terminus.get(0); + } + this.lineSegments.clear(); } List path = this.currentPath.next(); diff --git a/src/main/java/fr/u_paris/gla/project/idfm/IDFMNetworkExtractor.java b/src/main/java/fr/u_paris/gla/project/idfm/IDFMNetworkExtractor.java index 71d08f5..c8c2e2e 100644 --- a/src/main/java/fr/u_paris/gla/project/idfm/IDFMNetworkExtractor.java +++ b/src/main/java/fr/u_paris/gla/project/idfm/IDFMNetworkExtractor.java @@ -60,7 +60,8 @@ 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,6 +90,7 @@ public class IDFMNetworkExtractor { CSVStreamProvider provider = new CSVStreamProvider(traces.values().iterator()); + // Write into args[0] try { CSVTools.writeCSVToFile(args[0], Stream.iterate(provider.next(), t -> provider.hasNext(), t -> provider.next())); @@ -103,6 +105,7 @@ public class IDFMNetworkExtractor { 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())); @@ -153,6 +156,8 @@ public class IDFMNetworkExtractor { Double.parseDouble(line[IDFM_STOPS_LON_INDEX]), Double.parseDouble(line[IDFM_STOPS_LAT_INDEX])); String rid = line[IDFM_STOPS_RID_INDEX]; + + // Add terminus to the traces if (traces.keySet().contains(rid)) { extractTerminus(line[IDFM_STOPS_SCHEDULES_INDEX]).forEach(t -> traces.get(rid).addTerminus(t)); } @@ -215,14 +220,13 @@ public class IDFMNetworkExtractor { return all; } - private static List extractTerminus(String pathsJSON) { + private static List extractTerminus(String JSON) { List all = new ArrayList<>(); try { - JSONArray schedules = new JSONArray(pathsJSON); + JSONArray schedules = new JSONArray(JSON); for (int i = 0; i < schedules.length(); i++) { JSONObject stop = schedules.getJSONObject(i); String terminus = stop.getString("from"); - all.add(terminus); } } catch ( @@ -230,7 +234,7 @@ public class IDFMNetworkExtractor { JSONException e) { // Ignoring invalid element! 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;