diff --git a/src/main/java/lu/jpt/csparqlproject/SimulationContext.java b/src/main/java/lu/jpt/csparqlproject/SimulationContext.java index 56f4cbe..1f337f2 100644 --- a/src/main/java/lu/jpt/csparqlproject/SimulationContext.java +++ b/src/main/java/lu/jpt/csparqlproject/SimulationContext.java @@ -1,6 +1,5 @@ package lu.jpt.csparqlproject; -import java.text.ParseException; import java.util.ArrayList; import java.util.Collection; @@ -156,14 +155,16 @@ public class SimulationContext { // Register all the queries and add result observers! Collection queriesToRegister = new ArrayList(); queriesToRegister.add(RentACarSimulation.getEventsQuery()); + queriesToRegister.add(RentACarSimulation.getAverageDataByCar()); for(String query : queriesToRegister) { String queryName = CsparqlQueryHelper.getQueryName(query); CsparqlQueryResultProxy resultProxy = null; try { resultProxy = this.engine.registerQuery(query, true); - } catch (ParseException e) { + } catch (Exception e) { SimulationContext.logger.error(e.toString()); - SimulationContext.logger.error(e.getStackTrace().toString()); + SimulationContext.logger.error("Could not register query "+queryName); + SimulationContext.logger.error(query); } this.queryResultProxies.add(resultProxy); resultProxy.addObserver(new TextObserverWindow("[ResultProxy] " + queryName)); diff --git a/src/main/java/lu/jpt/csparqlproject/rentacar/Driver.java b/src/main/java/lu/jpt/csparqlproject/rentacar/Driver.java index 7168ce2..85cd1ba 100644 --- a/src/main/java/lu/jpt/csparqlproject/rentacar/Driver.java +++ b/src/main/java/lu/jpt/csparqlproject/rentacar/Driver.java @@ -89,7 +89,7 @@ public class Driver { private void useCar(Car car) { Car.CarState carState = car.getState(); if(carState == Car.CarState.WRECKED) { - // Sad fade :-( + // Sad face :-( return; } switch(carState) { diff --git a/src/main/java/lu/jpt/csparqlproject/rentacar/RentACarSimulation.java b/src/main/java/lu/jpt/csparqlproject/rentacar/RentACarSimulation.java index ae5ecda..a0470bf 100644 --- a/src/main/java/lu/jpt/csparqlproject/rentacar/RentACarSimulation.java +++ b/src/main/java/lu/jpt/csparqlproject/rentacar/RentACarSimulation.java @@ -42,8 +42,8 @@ public class RentACarSimulation implements Runnable { public RentACarSimulation() { this.registerOwnPrefixes(); - int numberOfCars = 1; - int numberOfCustomers = 1; + int numberOfCars = 5; + int numberOfCustomers = 5; // Create a car pool and drivers this.carPool = new CarPool(numberOfCars); this.drivers = new ArrayList(); @@ -188,4 +188,36 @@ public class RentACarSimulation implements Runnable { + " ?driver car:hasPhoneNumber ?driverPhone . " + "}"; } + + public static String getSpeedByCar() { + return "REGISTER QUERY getSpeedByCar AS " + + "PREFIX rdf: " + + "PREFIX f: " + + "PREFIX xsd: " + + "PREFIX car: <"+RentACarSimulation.BASE_ONTOLOGY_IRI+"> " + + "SELECT ?car ?speed " + + "FROM STREAM <"+RentACarSimulation.CAR_STREAM_IRI+"> [RANGE 5s STEP 1s] " + + "WHERE { " + + " ?e rdf:type car:CarStatusEvent . " + + " ?e car:relatedCar ?car . " + + " ?e car:speed ?speed . " + + "}"; + } + + public static String getAverageDataByCar() { + return "REGISTER QUERY getAverageSpeedByCar AS " + + "PREFIX rdf: " + + "PREFIX f: " + + "PREFIX xsd: " + + "PREFIX car: <"+RentACarSimulation.BASE_ONTOLOGY_IRI+"> " + + "SELECT ?car (AVG(?speed) AS ?avgSpeed) (AVG(?rpm) AS ?avgRPM) " + + "FROM STREAM <"+RentACarSimulation.CAR_STREAM_IRI+"> [RANGE 5s STEP 1s] " + + "WHERE { " + + " ?e rdf:type car:CarStatusEvent . " + + " ?e car:relatedCar ?car . " + + " ?e car:motorRPM ?rpm . " + + " ?e car:speed ?speed . " + + "} " + + "GROUP BY (?car) "; + } }