diff --git a/src/algo/graph/Graph.java b/src/algo/graph/Graph.java index ba310fa..0c37c5a 100755 --- a/src/algo/graph/Graph.java +++ b/src/algo/graph/Graph.java @@ -249,7 +249,7 @@ public static void main(String[] args) Graph g = parse.getGraph(); List chemin = g.Dijkstra(g.node,"La Courneuve-8-Mai-1945","Buttes-Chaumont","TOUS"); - + //List chemin = g.Dijkstra(g.node,"Jourdain","Buttes-Chaumont","TOUS"); String ligne = ""; for(int i = chemin.size()-1 ; i >= 0 ; i--) { diff --git a/src/algo/graph/parsing/Parse.java b/src/algo/graph/parsing/Parse.java index 817b388..8908db6 100755 --- a/src/algo/graph/parsing/Parse.java +++ b/src/algo/graph/parsing/Parse.java @@ -1,10 +1,20 @@ package algo.graph.parsing; +import hibernateLocal.HibernateSession; + import java.io.BufferedReader; import java.io.FileInputStream; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; +import java.util.Collection; + +import org.onebusaway.gtfs.model.Route; +import org.onebusaway.gtfs.model.Stop; +import org.onebusaway.gtfs.model.StopTime; +import org.onebusaway.gtfs.model.Trip; +import org.onebusaway.gtfs.services.GtfsMutableRelationalDao; +import org.onebusaway.gtfs.services.HibernateGtfsFactory; import algo.graph.Graph; @@ -23,40 +33,49 @@ public Parse() } + public String getTransportation(int type){ + if(type == 1) + return "METRO"; + else if(type == 2) + return "RER"; + else if(type == 3) + return "BUS"; + else if (type == 0) + return "TRAM"; + else + return "NONE"; + + + } public Graph getGraph() { // Cr�ation du Graph a retourner try { - // Chargement du fichier permettant de r�cup�rer toutes les routes du r�seaux RATP/SNCF - String fichierRoutes ="routes.txt"; - InputStream ips = new FileInputStream(fichierRoutes); - InputStreamReader ipsr = new InputStreamReader(ips); - BufferedReader br = new BufferedReader(ipsr); - String ligneRoutes; - String numTrips_ID = ""; - - br.readLine(); - String modeTransport = ""; - - while ((ligneRoutes = br.readLine()) != null) - { - String [] splitRoutes = ligneRoutes.split(","); - - if(splitRoutes[2].contains("T")) - modeTransport = "TRAM"; - - if(splitRoutes[2].equals("A") || splitRoutes[2].equals("B")) - modeTransport = "RER"; - - else - modeTransport = "METRO"; - - // Traitement mode de transport - routes.add(new Routes(splitRoutes[0],splitRoutes[2],modeTransport)); - } - br.close(); - + + HibernateSession hyber = new HibernateSession(); + HibernateGtfsFactory factory = hyber.createHibernateGtfsFactory(); + GtfsMutableRelationalDao dao = factory.getDao(); + + /** fill routes **/ + Collection routesDB = dao.getAllRoutes(); + for( Route route: routesDB){ + routes.add(new Routes(route.getId().getId(), route.getShortName(),getTransportation(route.getType()))); + } + + /** fill stops **/ + Collection stopsDB = dao.getAllStops(); + for( Stop stop: stopsDB){ + + stops.add(new Stops(stop.getId().getId(), stop.getName(), + Double.toString(stop.getLat()), Double.toString(stop.getLon()), stop.getParentStation())); + //StopTime stopTime = dao.getStopTimeForId(Integer.parseInt(stop.getId().getId())); + //stop_times.add( new StopTimes(stopTime.getTrip().getId().getId(), + // stopTime.getStop().getId().getId(),Integer.toString( stopTime.getArrivalTime()))); + + } + + // Chargement du fichier permettant de r�cup�rer les correspondances et les d�lais entre les stations String fichierStop_Times = "stop_times.txt"; InputStream ipsStop_Times = new FileInputStream(fichierStop_Times); @@ -73,37 +92,27 @@ public Graph getGraph() brStop_Times.close(); - // Parcourt du fichier permettant de recup�rer les chemins des diff�rentes lignes du reseau - String fichierTrips = "trips.txt"; - InputStream ipsTrips = new FileInputStream(fichierTrips); - InputStreamReader ipsrTrips = new InputStreamReader(ipsTrips); - BufferedReader brTrips = new BufferedReader(ipsrTrips); - - String ligneTrips; - brTrips.readLine(); - while ((ligneTrips = brTrips.readLine()) != null) - { - String [] splitTrips = ligneTrips.split(","); - trips.add(new Trips(splitTrips[0],splitTrips[2])); - } - brTrips.close(); + /*** fill stop times *****/ + /* fill stops + Collection stopTimesDB = dao.getAllStopTimes(); + for( StopTime stopTime: stopTimesDB){ + + stop_times.add( new StopTimes(stopTime.getTrip().getId().getId(), + stopTime.getStop().getId().getId(),Integer.toString( stopTime.getDepartureTime()))); + + } + */ + + + /* fill trips **/ + Collection tripsDB = dao.getAllTrips(); + for( Trip trip: tripsDB){ + trips.add(new Trips(trip.getRoute().getId().getId(), trip.getId().getId())); + + } - // Parcourt du fichier permettant de recup�rer les chemins des diff�rentes lignes du reseau - String fichierStops = "stops.txt"; - InputStream ipsStops = new FileInputStream(fichierStops); - InputStreamReader ipsrStops = new InputStreamReader(ipsStops); - BufferedReader brStops = new BufferedReader(ipsrStops); - - String ligneStops; - brStops.readLine(); - while ((ligneStops = brStops.readLine()) != null) - { - String [] splitStops = ligneStops.split(","); - stops.add(new Stops(splitStops[0],splitStops[2],splitStops[3],splitStops[4],splitStops[7])); - } - brStops.close(); - + String fichierGeo= "geo.csv"; InputStream ipsGeo = new FileInputStream(fichierGeo); diff --git a/src/hibernateLocal/HibernateSession.java b/src/hibernateLocal/HibernateSession.java new file mode 100644 index 0000000..ac08c3d --- /dev/null +++ b/src/hibernateLocal/HibernateSession.java @@ -0,0 +1,41 @@ +package hibernateLocal; + +import java.io.File; + +import org.hibernate.SessionFactory; +import org.hibernate.cfg.Configuration; +import org.onebusaway.gtfs.services.HibernateGtfsFactory; + +public class HibernateSession { + private static final String KEY_CLASSPATH = "classpath:"; + + private static final String KEY_FILE = "file:"; + + + protected String resource = null; + + public HibernateSession() { + super(); + this.resource = "file:src/hibernateLocal/hibernate-configuration.xml"; + } + + public HibernateGtfsFactory createHibernateGtfsFactory() { + + Configuration config = new Configuration(); + + + if (resource.startsWith(KEY_CLASSPATH)) { + resource = resource.substring(KEY_CLASSPATH.length()); + config = config.configure(resource); + } else if (resource.startsWith(KEY_FILE)) { + resource = resource.substring(KEY_FILE.length()); + config = config.configure(new File(resource)); + } else { + config = config.configure(new File(resource)); + } + + SessionFactory sessionFactory = config.buildSessionFactory(); + return new HibernateGtfsFactory(sessionFactory); + } + +} diff --git a/src/hibernate_handling/TestLoading.java b/src/hibernateLocal/TestLoading.java similarity index 99% rename from src/hibernate_handling/TestLoading.java rename to src/hibernateLocal/TestLoading.java index 60e8908..b22e448 100644 --- a/src/hibernate_handling/TestLoading.java +++ b/src/hibernateLocal/TestLoading.java @@ -1,4 +1,4 @@ -package hibernate_handling; +package hibernateLocal; import java.io.File; diff --git a/src/hibernateLocal/TestReading.java b/src/hibernateLocal/TestReading.java new file mode 100644 index 0000000..de3776d --- /dev/null +++ b/src/hibernateLocal/TestReading.java @@ -0,0 +1,250 @@ +package hibernateLocal; + + +import java.io.File; +import java.io.IOException; +import java.math.BigDecimal; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import org.hibernate.SessionFactory; +import org.hibernate.cfg.Configuration; +import org.onebusaway.gtfs.model.AgencyAndId; +import org.onebusaway.gtfs.model.Pathway; +import org.onebusaway.gtfs.model.Route; +import org.onebusaway.gtfs.model.Stop; +import org.onebusaway.gtfs.model.StopTime; +import org.onebusaway.gtfs.model.Transfer; +import org.onebusaway.gtfs.model.Trip; +import org.onebusaway.gtfs.model.calendar.ServiceDate; +import org.onebusaway.gtfs.serialization.GtfsReader; +import org.onebusaway.gtfs.services.GtfsDao; +import org.onebusaway.gtfs.services.GtfsMutableRelationalDao; +import org.onebusaway.gtfs.services.HibernateGtfsFactory; +import org.onebusaway.gtfs.services.calendar.CalendarService; + +import algo.graph.parsing.StopTimes; + + + + + + +public class TestReading { + + + private static final String KEY_CLASSPATH = "classpath:"; + + private static final String KEY_FILE = "file:"; + + @SuppressWarnings("null") + public static void main(String[] args) throws IOException { + /* + if (!(args.length == 1 || args.length == 2)) { + System.err.println("usage: gtfsPath [hibernate-config.xml]"); + System.exit(-1); + } + */ + + + //String gtfsFiles = "src/ressources/"; + //if (args.length == 2) + //resource = args[1]; + + HibernateSession hyber = new HibernateSession(); + HibernateGtfsFactory factory = hyber.createHibernateGtfsFactory(); + GtfsMutableRelationalDao dao = factory.getDao(); + + Collection stops = dao.getAllStops(); + //Collection timeList = null ; + + + try{ + for(Stop stop : stops ){ + + //System.out.println(stop.getId()); + //System.out.println(stop.getId().getId()); + //System.out.println(stop.getId().getAgencyId()); + //for(Stop stop2 : stops ){ + //boolean b = timeList.add( dao.getStopTimeForId( Integer.parseInt(stop.getId().getAgencyId()))) ; + //System.out.println("bool check " + b); + System.out.println("stop times are: "+dao.getStopTimeForId(Integer.parseInt(stop.getId().getId()))); + //System.out.println("--------------------------------------------------------"); + //System.out.println( stop.getName()+" <---------> " + //+(dao.getStopTimeForId(Integer.parseInt(stop.getId().getId()))).getStop().getName()); + // int stopId = stop.getId().toString() + + //if( Integer.parseInt(stop2.getId().getId()) == Integer.parseInt(stop.getId().getId())+2){ + // System.out.println(stop.getName()+ " <---------------> "+ stop2.getName()); + // break; + //} + //} + } + }catch( Exception e){ + + } + + + + //GtfsReader reader = new GtfsReader(); + // reader.setInputLocation(new File(gtfsFiles)); + + + + //reader.setEntityStore(dao); + //reader.run(); + + /* + Collection trips = dao.getAllTrips(); + Collection stops = null; + int i = 0; + + try{ + for(Trip trip : trips ){ + if( trip.getRoute().getType() == 1){ + //System.out.println( dao.getStopTimeForId(Integer.parseInt(trip.getId().getId())).getStop().getName()); + //System.out.println(dao.getStopTimeForId(Integer.parseInt(trip.getId().getId())).getStop().getName()); + //System.out.println(trip.getId().getAgencyId()); + i++; + //System.out.println((dao.getStopTimesForTrip(trip)).get(2).getStop().getName()); + + + System.out.println(i); + + } + //System.out.println(trip); + } + //System.out.println("taille"+stops.size()); + } + catch( Exception e){ + System.out.println(e.toString()); + } + */ + + + /* + + + Collection trips = dao.getAllTrips(); + + try{ + for(Trip trip : trips ){ + //if( trip.getRoute().getType() == 1){ + //System.out.println( dao.getStopTimeForId(Integer.parseInt(trip.getId().getId())).getStop().getName()); + //} + System.out.println(trip); + } + } + catch( Exception e){ + + } + // check if the station is a subway or something else + Collection routes = dao.getAllRoutes(); + + int i = 0; + try{ + for( Route route : routes ){ + + + if( route.getType() == 1) + { + i++; + System.out.println( " This is a subway" + " and the iteration is: "+i); + + } + + } + }catch( Exception e){ + + } + // check the pathways + Collection paths = dao.getAllPathways(); + + try{ + for( Pathway path : paths ){ + + System.out.println(path.toString()); + + + } + }catch( Exception e){ + + } + + + + Collection trips = dao.getAllTrips(); + + try{ + for(Trip trip : trips ){ + + System.out.println(Integer.parseInt((trip.getRoute().getId().getAgencyId()))); + + } + }catch( Exception e){ + + } + + + + try{ + //System.out.println( timeList.get(0).getArrivalTime()); + for(StopTime time : timeList ){ + System.out.println( "this is stop time"+time.getArrivalTime()); + } + }catch( Exception e){ + + } + + + + for (Stop stop : stops) + System.out.println(stop.getName()); + + for(Trip trip : trips) + System.out.println(trip.getRoute()); + */ + + } + + /* + + CalendarService calendarService = factory.getCalendarService(); + Set serviceIds = calendarService.getServiceIds(); + + for (AgencyAndId serviceId : serviceIds) { + Set dates = calendarService.getServiceDatesForServiceId(serviceId); + ServiceDate from = null; + ServiceDate to = null; + for (ServiceDate date : dates) { + from = min(from, date); + to = max(to, date); + } + + System.out.println("serviceId=" + serviceId + " from=" + from + " to=" + + to); + } + } + + private static ServiceDate min(ServiceDate a, ServiceDate b) { + if (a == null) + return b; + if (b == null) + return a; + return a.compareTo(b) <= 0 ? a : b; + } + + private static ServiceDate max(ServiceDate a, ServiceDate b) { + if (a == null) + return b; + if (b == null) + return a; + return a.compareTo(b) <= 0 ? b : a; + } +*/ + + + +} diff --git a/src/hibernate_handling/hibernate-configuration.xml b/src/hibernateLocal/hibernate-configuration.xml similarity index 100% rename from src/hibernate_handling/hibernate-configuration.xml rename to src/hibernateLocal/hibernate-configuration.xml diff --git a/src/hibernate_handling/TestReading.java b/src/hibernate_handling/TestReading.java deleted file mode 100644 index 8cc2f05..0000000 --- a/src/hibernate_handling/TestReading.java +++ /dev/null @@ -1,151 +0,0 @@ -package hibernate_handling; - - -import java.io.File; -import java.io.IOException; -import java.math.BigDecimal; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import org.hibernate.SessionFactory; -import org.hibernate.cfg.Configuration; -import org.onebusaway.gtfs.model.AgencyAndId; -import org.onebusaway.gtfs.model.Stop; -import org.onebusaway.gtfs.model.StopTime; -import org.onebusaway.gtfs.model.Trip; -import org.onebusaway.gtfs.model.calendar.ServiceDate; -import org.onebusaway.gtfs.serialization.GtfsReader; -import org.onebusaway.gtfs.services.GtfsMutableRelationalDao; -import org.onebusaway.gtfs.services.HibernateGtfsFactory; -import org.onebusaway.gtfs.services.calendar.CalendarService; - -import algo.graph.parsing.StopTimes; - - - - - - -public class TestReading { - - - private static final String KEY_CLASSPATH = "classpath:"; - - private static final String KEY_FILE = "file:"; - - @SuppressWarnings("null") - public static void main(String[] args) throws IOException { - /* - if (!(args.length == 1 || args.length == 2)) { - System.err.println("usage: gtfsPath [hibernate-config.xml]"); - System.exit(-1); - } - */ - //String resource = "classpath:org/onebusaway/gtfs/examples/hibernate-configuration-examples.xml"; - String resource = "file:src/hibernate_handling/hibernate-configuration.xml"; - //String gtfsFiles = "src/ressources/"; - //if (args.length == 2) - //resource = args[1]; - - HibernateGtfsFactory factory = createHibernateGtfsFactory(resource); - - GtfsReader reader = new GtfsReader(); - // reader.setInputLocation(new File(gtfsFiles)); - - GtfsMutableRelationalDao dao = factory.getDao(); - reader.setEntityStore(dao); - //reader.run(); - - Collection stops = dao.getAllStops(); - Collection trips = dao.getAllTrips(); - - - - List timeList = null ; - - - try{ - for(Stop stop : stops ){ - System.out.println(dao.getStopTimeForId(Integer.parseInt(stop.getId().getId()))+" "+ stop.getName()); - } - }catch( Exception e){ - - } - try{ - System.out.println( timeList.get(0).getArrivalTime()); - for(StopTime time : timeList ){ - System.out.println( time.getArrivalTime()); - } - }catch( Exception e){ - - } - - /* - for (Stop stop : stops) - System.out.println(stop.getName()); - - for(Trip trip : trips) - System.out.println(trip.getRoute()); - */ - - } - - /* - - CalendarService calendarService = factory.getCalendarService(); - Set serviceIds = calendarService.getServiceIds(); - - for (AgencyAndId serviceId : serviceIds) { - Set dates = calendarService.getServiceDatesForServiceId(serviceId); - ServiceDate from = null; - ServiceDate to = null; - for (ServiceDate date : dates) { - from = min(from, date); - to = max(to, date); - } - - System.out.println("serviceId=" + serviceId + " from=" + from + " to=" - + to); - } - } - - private static ServiceDate min(ServiceDate a, ServiceDate b) { - if (a == null) - return b; - if (b == null) - return a; - return a.compareTo(b) <= 0 ? a : b; - } - - private static ServiceDate max(ServiceDate a, ServiceDate b) { - if (a == null) - return b; - if (b == null) - return a; - return a.compareTo(b) <= 0 ? b : a; - } -*/ - - private static HibernateGtfsFactory createHibernateGtfsFactory(String resource) { - - Configuration config = new Configuration(); - - if (resource.startsWith(KEY_CLASSPATH)) { - resource = resource.substring(KEY_CLASSPATH.length()); - config = config.configure(resource); - } else if (resource.startsWith(KEY_FILE)) { - resource = resource.substring(KEY_FILE.length()); - config = config.configure(new File(resource)); - } else { - config = config.configure(new File(resource)); - } - - SessionFactory sessionFactory = config.buildSessionFactory(); - return new HibernateGtfsFactory(sessionFactory); - } - - - -} diff --git a/target/classes/META-INF/maven/Graph/Graph/pom.properties b/target/classes/META-INF/maven/Graph/Graph/pom.properties index 836553d..16753ea 100644 --- a/target/classes/META-INF/maven/Graph/Graph/pom.properties +++ b/target/classes/META-INF/maven/Graph/Graph/pom.properties @@ -1,5 +1,5 @@ #Generated by Maven Integration for Eclipse -#Wed Nov 27 02:12:03 CET 2013 +#Sat Nov 30 21:07:44 CET 2013 version=0.0.1-SNAPSHOT groupId=Graph m2e.projectName=Graph diff --git a/target/classes/algo/graph/parsing/Parse.class b/target/classes/algo/graph/parsing/Parse.class index df66e39..f5981dd 100644 Binary files a/target/classes/algo/graph/parsing/Parse.class and b/target/classes/algo/graph/parsing/Parse.class differ diff --git a/target/classes/hibernateLocal/HibernateSession.class b/target/classes/hibernateLocal/HibernateSession.class new file mode 100644 index 0000000..bf09fa1 Binary files /dev/null and b/target/classes/hibernateLocal/HibernateSession.class differ diff --git a/target/classes/hibernate_handling/TestLoading.class b/target/classes/hibernateLocal/TestLoading.class similarity index 94% rename from target/classes/hibernate_handling/TestLoading.class rename to target/classes/hibernateLocal/TestLoading.class index 18bc3ae..3c2ce31 100644 Binary files a/target/classes/hibernate_handling/TestLoading.class and b/target/classes/hibernateLocal/TestLoading.class differ diff --git a/target/classes/hibernateLocal/TestReading.class b/target/classes/hibernateLocal/TestReading.class new file mode 100644 index 0000000..7d71d57 Binary files /dev/null and b/target/classes/hibernateLocal/TestReading.class differ diff --git a/target/classes/hibernate_handling/hibernate-configuration.xml b/target/classes/hibernateLocal/hibernate-configuration.xml similarity index 100% rename from target/classes/hibernate_handling/hibernate-configuration.xml rename to target/classes/hibernateLocal/hibernate-configuration.xml diff --git a/target/classes/hibernate_handling/TestReading.class b/target/classes/hibernate_handling/TestReading.class deleted file mode 100644 index 51e6a7d..0000000 Binary files a/target/classes/hibernate_handling/TestReading.class and /dev/null differ diff --git a/target/classes/test.html b/target/classes/test.html index 3084146..a6e2d0b 100644 --- a/target/classes/test.html +++ b/target/classes/test.html @@ -1 +1 @@ -
\ No newline at end of file +
\ No newline at end of file diff --git a/target/classes/test1.html b/target/classes/test1.html index 916450f..50b963e 100644 --- a/target/classes/test1.html +++ b/target/classes/test1.html @@ -1 +1 @@ - \ No newline at end of file +
depuis La Courneuve-8-Mai-1945
jusqu'a Louis Blanc
20h29
20h39
12min
depuis Louis Blanc
jusqu'a Buttes-Chaumont
20h39
20h43
4min
\ No newline at end of file
depuis La Courneuve-8-Mai-1945
jusqu'a Louis Blanc
20h31
20h41
12min
depuis Louis Blanc
jusqu'a Buttes-Chaumont
20h41
20h45
4min