Build csv added
This commit is contained in:
parent
092ff65355
commit
38f2974bd9
2 changed files with 84 additions and 1 deletions
|
@ -10,6 +10,7 @@ import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.File;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
@ -46,6 +47,10 @@ public class IDFMNetworkExtractor {
|
||||||
private static final int IDFM_STOPS_LON_INDEX = 6;
|
private static final int IDFM_STOPS_LON_INDEX = 6;
|
||||||
private static final int IDFM_STOPS_LAT_INDEX = 7;
|
private static final int IDFM_STOPS_LAT_INDEX = 7;
|
||||||
|
|
||||||
|
private static final String TRACE_FILE_NAME = "trace.csv";
|
||||||
|
|
||||||
|
private static final String HOURS_FILE_NAME = "hours.csv";
|
||||||
|
|
||||||
// Magically chosen values
|
// Magically chosen values
|
||||||
/**
|
/**
|
||||||
* A number of stops on each line
|
* A number of stops on each line
|
||||||
|
@ -181,6 +186,82 @@ public class IDFMNetworkExtractor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean checkFileExistence(String filePath) {
|
||||||
|
File file = new File(filePath);
|
||||||
|
if (file.exists()) {
|
||||||
|
LOGGER.severe(filePath+ " already exists.");
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
LOGGER.severe(filePath + " does not exist.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void builFiles() {
|
||||||
|
|
||||||
|
if (checkFileExistence("./"+HOURS_FILE_NAME) && checkFileExistence("./"+TRACE_FILE_NAME)) {
|
||||||
|
LOGGER.severe("Files already exists.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, TraceEntry> traces = new HashMap<>();
|
||||||
|
try {
|
||||||
|
CSVTools.readCSVFromURL(TRACE_FILE_URL,
|
||||||
|
(String[] line) -> addLine(line, traces));
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOGGER.log(Level.SEVERE, "Error while reading the line paths", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<StopEntry> stops = new ArrayList<>(traces.size() * GUESS_STOPS_BY_LINE);
|
||||||
|
try {
|
||||||
|
CSVTools.readCSVFromURL(STOPS_FILE_URL,
|
||||||
|
(String[] line) -> addStop(line, traces, stops));
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOGGER.log(Level.SEVERE, "Error while reading the stops", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanTraces(traces);
|
||||||
|
|
||||||
|
Map<String, Transport> transports = new HashMap<>();
|
||||||
|
CSVStreamProvider provider = new CSVStreamProvider(traces.values().iterator(), transports);
|
||||||
|
|
||||||
|
// Write into args[0]
|
||||||
|
try {
|
||||||
|
CSVTools.writeCSVToFile(TRACE_FILE_NAME, Stream.iterate(provider.next(),
|
||||||
|
t -> provider.hasNext(), t -> provider.next()));
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOGGER.log(Level.SEVERE, e,
|
||||||
|
() -> MessageFormat.format("Could not write in file {0}", TRACE_FILE_NAME));
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("******************Building bifurcations ************************");
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
|
for (Transport entry : transports.values()) {
|
||||||
|
entry.buildBifurcationOptimzed();
|
||||||
|
}
|
||||||
|
|
||||||
|
long endTime = System.currentTimeMillis();
|
||||||
|
long tempsPasse = endTime - startTime;
|
||||||
|
|
||||||
|
long minutes = (tempsPasse / 1000) / 60;
|
||||||
|
long seconds = (tempsPasse / 1000) % 60;
|
||||||
|
long milliseconds = tempsPasse % 1000;
|
||||||
|
|
||||||
|
System.out.println("Temps écoulé : " + minutes + " minutess, " + seconds + " secndes et " + milliseconds + " millis");
|
||||||
|
|
||||||
|
System.out.println("******************Fin Building bifurcations ************************");
|
||||||
|
|
||||||
|
CSVSchedulesProvider providerschedules = new CSVSchedulesProvider(transports.values().iterator());
|
||||||
|
try {
|
||||||
|
CSVTools.writeCSVToFile(HOURS_FILE_NAME, 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}", HOURS_FILE_NAME));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void cleanTraces(Map<String, TraceEntry> traces) {
|
private static void cleanTraces(Map<String, TraceEntry> traces) {
|
||||||
Set<String> toRemove = new HashSet<>();
|
Set<String> toRemove = new HashSet<>();
|
||||||
for (Entry<String, TraceEntry> traceEntry : traces.entrySet()) {
|
for (Entry<String, TraceEntry> traceEntry : traces.entrySet()) {
|
||||||
|
|
|
@ -94,7 +94,8 @@ public class ItineraryCalculator {
|
||||||
Stop toStop = getOrCreateStop(nodes, tmp, line[IDFM_TRACE_TO_INDEX], line[IDFM_TRACE_TO_GPS_INDEX], line[IDFM_TRACE_ID_INDEX]);
|
Stop toStop = getOrCreateStop(nodes, tmp, line[IDFM_TRACE_TO_INDEX], line[IDFM_TRACE_TO_GPS_INDEX], line[IDFM_TRACE_ID_INDEX]);
|
||||||
|
|
||||||
String[] timeString = line[IDFM_TRACE_TIME_INDEX].split(":");
|
String[] timeString = line[IDFM_TRACE_TIME_INDEX].split(":");
|
||||||
int time = Integer.parseInt(timeString[0]) * 60 + Integer.parseInt(timeString[1]);
|
String time0WithoutComma = timeString[0].replace(",", "");
|
||||||
|
int time = Integer.parseInt(time0WithoutComma) * 60 + Integer.parseInt(timeString[1]);
|
||||||
|
|
||||||
Connection connection = new Connection(toStop, line[IDFM_TRACE_ID_INDEX], Double.parseDouble(line[IDFM_TRACE_DISTANCE_INDEX]), time);
|
Connection connection = new Connection(toStop, line[IDFM_TRACE_ID_INDEX], Double.parseDouble(line[IDFM_TRACE_DISTANCE_INDEX]), time);
|
||||||
|
|
||||||
|
@ -106,6 +107,7 @@ public class ItineraryCalculator {
|
||||||
LOGGER.severe("Invalid command line. Target file names are in the main file for now.");
|
LOGGER.severe("Invalid command line. Target file names are in the main file for now.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
IDFMNetworkExtractor.builFiles();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
HashSet<Stop> nodes = new HashSet<>();
|
HashSet<Stop> nodes = new HashSet<>();
|
||||||
|
|
Reference in a new issue