[feat] generation of a csv file with line/url

This commit is contained in:
Mylloon 2024-04-11 23:03:07 +02:00
parent f528d9f0c0
commit ef61b8daff
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
6 changed files with 101 additions and 5 deletions

View file

@ -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);
}
}

View file

@ -56,6 +56,7 @@ public final class CSVStreamProvider {
private String traceId = "";
private String traceType = "";
private String url_image = "";
/** Create the stream provider */
public CSVStreamProvider(Iterator<TraceEntry> traces, Map<String, Transport> t) {
@ -114,6 +115,7 @@ public final class CSVStreamProvider {
this.traceId = trace.id;
this.traceType = trace.type;
this.url_image = trace.url;
this.descriptions.clear();
this.descriptions.addAll(trace.descriptions);
@ -189,9 +191,10 @@ public final class CSVStreamProvider {
String start_p = this.line[NetworkFormat.START_INDEX];
String end_p = this.line[NetworkFormat.STOP_INDEX];
// String bifurcation = this.line[NetworkFormat.VARIANT_INDEX];
Transport transp = null;
if(!transports.containsKey(traceId)){
transp = new Transport(nameTransport,traceType);
transp = new Transport(nameTransport,traceType, url_image);
transports.put(traceId, transp);
}else{
transp = transports.get(traceId);

View file

@ -45,6 +45,7 @@ public class IDFMNetworkExtractor {
private static final int IDFM_STOPS_NAME_INDEX = 5;
private static final int IDFM_STOPS_LON_INDEX = 6;
private static final int IDFM_STOPS_LAT_INDEX = 7;
public static final int IDFM_URL_INDEX = 10;
// Magically chosen values
/**
@ -179,6 +180,16 @@ public class IDFMNetworkExtractor {
LOGGER.log(Level.SEVERE, e,
() -> 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) {
@ -244,7 +255,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],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]);
entry.getPaths().addAll(buildPaths);
if (buildPaths.isEmpty()) {

View file

@ -15,7 +15,7 @@ public final class TraceEntry {
public final String lname;
public final String id;
public final String type;
public final String url;
@ -29,11 +29,12 @@ public final class TraceEntry {
*
* @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();
this.lname = lname;
this.id = ident;
this.type = t_type;
this.url = img_url;
}
// FIXME list of lists are bad practice in direct access...

View file

@ -17,14 +17,16 @@ public class Transport {
Map<String, Stop> stopsMap = new HashMap<>();
public String name;
public String type;
public String image_url;
//All the line descriptions (directions and schedules)
List <TraceDescription> descriptions = new ArrayList<>();
public Transport(String name,String type){
public Transport(String name,String type, String url){
this.name = name;
this.type = type;
this.image_url = url;
}

View 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
}
}