Merge branch 'idfm-image' into 'idf-mobilite-net'
[feat] generation of a csv file with line/url couple See merge request gla-groupe-3/projet!8
This commit is contained in:
commit
79c5d18187
6 changed files with 101 additions and 5 deletions
|
@ -0,0 +1,55 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package fr.u_paris.gla.project.idfm;
|
||||||
|
|
||||||
|
import fr.u_paris.gla.project.io.ScheduleFormat;
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
import java.text.NumberFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import fr.u_paris.gla.project.io.ImageFormat;
|
||||||
|
import fr.u_paris.gla.project.utils.GPS;
|
||||||
|
|
||||||
|
public final class CSVImageProvider {
|
||||||
|
private static final NumberFormat MINUTES_SECOND_FORMATTER = NumberFormat
|
||||||
|
.getInstance(Locale.ENGLISH);
|
||||||
|
static {
|
||||||
|
MINUTES_SECOND_FORMATTER.setMinimumIntegerDigits(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final String[] line = new String[ImageFormat.NUMBER_COLUMNS];
|
||||||
|
private final Iterator<Transport> current;
|
||||||
|
|
||||||
|
/** Create the stream provider */
|
||||||
|
public CSVImageProvider(Iterator<Transport> traces) {
|
||||||
|
this.current = traces;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Check if next exists */
|
||||||
|
public boolean hasNext() {
|
||||||
|
return this.current.hasNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Get Next element */
|
||||||
|
public String[] next() {
|
||||||
|
if (!this.hasNext()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Transport element = this.current.next();
|
||||||
|
this.line[ImageFormat.LINE_INDEX] = element.name;
|
||||||
|
this.line[ImageFormat.IMAGE_URL_INDEX] = element.image_url;
|
||||||
|
|
||||||
|
return Arrays.copyOf(this.line, this.line.length);
|
||||||
|
}
|
||||||
|
}
|
|
@ -56,6 +56,7 @@ public final class CSVStreamProvider {
|
||||||
|
|
||||||
private String traceId = "";
|
private String traceId = "";
|
||||||
private String traceType = "";
|
private String traceType = "";
|
||||||
|
private String url_image = "";
|
||||||
|
|
||||||
/** Create the stream provider */
|
/** Create the stream provider */
|
||||||
public CSVStreamProvider(Iterator<TraceEntry> traces, Map<String, Transport> t) {
|
public CSVStreamProvider(Iterator<TraceEntry> traces, Map<String, Transport> t) {
|
||||||
|
@ -114,6 +115,7 @@ public final class CSVStreamProvider {
|
||||||
|
|
||||||
this.traceId = trace.id;
|
this.traceId = trace.id;
|
||||||
this.traceType = trace.type;
|
this.traceType = trace.type;
|
||||||
|
this.url_image = trace.url;
|
||||||
this.descriptions.clear();
|
this.descriptions.clear();
|
||||||
this.descriptions.addAll(trace.descriptions);
|
this.descriptions.addAll(trace.descriptions);
|
||||||
|
|
||||||
|
@ -189,9 +191,10 @@ public final class CSVStreamProvider {
|
||||||
String start_p = this.line[NetworkFormat.START_INDEX];
|
String start_p = this.line[NetworkFormat.START_INDEX];
|
||||||
String end_p = this.line[NetworkFormat.STOP_INDEX];
|
String end_p = this.line[NetworkFormat.STOP_INDEX];
|
||||||
// String bifurcation = this.line[NetworkFormat.VARIANT_INDEX];
|
// String bifurcation = this.line[NetworkFormat.VARIANT_INDEX];
|
||||||
|
|
||||||
Transport transp = null;
|
Transport transp = null;
|
||||||
if(!transports.containsKey(traceId)){
|
if(!transports.containsKey(traceId)){
|
||||||
transp = new Transport(nameTransport,traceType);
|
transp = new Transport(nameTransport,traceType, url_image);
|
||||||
transports.put(traceId, transp);
|
transports.put(traceId, transp);
|
||||||
}else{
|
}else{
|
||||||
transp = transports.get(traceId);
|
transp = transports.get(traceId);
|
||||||
|
|
|
@ -45,6 +45,7 @@ public class IDFMNetworkExtractor {
|
||||||
private static final int IDFM_STOPS_NAME_INDEX = 5;
|
private static final int IDFM_STOPS_NAME_INDEX = 5;
|
||||||
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 int IDFM_URL_INDEX = 10;
|
||||||
|
|
||||||
// Magically chosen values
|
// Magically chosen values
|
||||||
/**
|
/**
|
||||||
|
@ -179,6 +180,16 @@ public class IDFMNetworkExtractor {
|
||||||
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]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CSVImageProvider providerimage = new CSVImageProvider(transports.values().iterator());
|
||||||
|
String imageCSV = "image.csv";
|
||||||
|
try {
|
||||||
|
CSVTools.writeCSVToFile(imageCSV, Stream.iterate(providerimage.next(),
|
||||||
|
t -> providerimage.hasNext(), t -> providerimage.next()));
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOGGER.log(Level.SEVERE, e,
|
||||||
|
() -> MessageFormat.format("Could not write in file {0}", imageCSV));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void cleanTraces(Map<String, TraceEntry> traces) {
|
private static void cleanTraces(Map<String, TraceEntry> traces) {
|
||||||
|
@ -244,7 +255,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],line[IDFM_TRACE_TYPE_INDEX]);
|
TraceEntry entry = new TraceEntry(line[IDFM_TRACE_SNAME_INDEX], line[IDFM_TRACE_ID_INDEX],line[IDFM_TRACE_TYPE_INDEX], line[IDFM_URL_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()) {
|
||||||
|
|
|
@ -15,7 +15,7 @@ public final class TraceEntry {
|
||||||
public final String lname;
|
public final String lname;
|
||||||
public final String id;
|
public final String id;
|
||||||
public final String type;
|
public final String type;
|
||||||
|
public final String url;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,11 +29,12 @@ public final class TraceEntry {
|
||||||
*
|
*
|
||||||
* @param lname the name of the line
|
* @param lname the name of the line
|
||||||
*/
|
*/
|
||||||
public TraceEntry(String lname,String ident,String t_type) {
|
public TraceEntry(String lname,String ident,String t_type, String img_url) {
|
||||||
super();
|
super();
|
||||||
this.lname = lname;
|
this.lname = lname;
|
||||||
this.id = ident;
|
this.id = ident;
|
||||||
this.type = t_type;
|
this.type = t_type;
|
||||||
|
this.url = img_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME list of lists are bad practice in direct access...
|
// FIXME list of lists are bad practice in direct access...
|
||||||
|
|
|
@ -17,14 +17,16 @@ public class Transport {
|
||||||
Map<String, Stop> stopsMap = new HashMap<>();
|
Map<String, Stop> stopsMap = new HashMap<>();
|
||||||
public String name;
|
public String name;
|
||||||
public String type;
|
public String type;
|
||||||
|
public String image_url;
|
||||||
|
|
||||||
//All the line descriptions (directions and schedules)
|
//All the line descriptions (directions and schedules)
|
||||||
List <TraceDescription> descriptions = new ArrayList<>();
|
List <TraceDescription> descriptions = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
public Transport(String name,String type){
|
public Transport(String name,String type, String url){
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
this.image_url = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
24
src/main/java/fr/u_paris/gla/project/io/ImageFormat.java
Normal file
24
src/main/java/fr/u_paris/gla/project/io/ImageFormat.java
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package fr.u_paris.gla.project.io;
|
||||||
|
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.time.format.ResolverStyle;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A tool class for the Image format.
|
||||||
|
*/
|
||||||
|
public final class ImageFormat {
|
||||||
|
public static final int NUMBER_COLUMNS = 2;
|
||||||
|
|
||||||
|
public static final int LINE_INDEX = 0;
|
||||||
|
public static final int IMAGE_URL_INDEX = 1;
|
||||||
|
|
||||||
|
/** Hidden constructor for tool class */
|
||||||
|
private ImageFormat() {
|
||||||
|
// Tool class
|
||||||
|
}
|
||||||
|
}
|
Reference in a new issue