From 2f2fd53006e315c8d1920999d2009cede66bb8c7 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Sun, 9 Oct 2016 19:09:03 +0200 Subject: [PATCH] [TASK] Generic commit. --- .../jpt/csparqlproject/SimulationContext.java | 1 + .../lu/jpt/csparqlproject/rentacar/Car.java | 4 +- .../rentacar/RentACarSimulation.java | 61 ++++++++++++++++--- 3 files changed, 54 insertions(+), 12 deletions(-) diff --git a/src/main/java/lu/jpt/csparqlproject/SimulationContext.java b/src/main/java/lu/jpt/csparqlproject/SimulationContext.java index ccd18c8..9d6d0fa 100644 --- a/src/main/java/lu/jpt/csparqlproject/SimulationContext.java +++ b/src/main/java/lu/jpt/csparqlproject/SimulationContext.java @@ -169,6 +169,7 @@ public class SimulationContext { queriesToRegister.add(simulation.getCarTakenEventsQuery()); queriesToRegister.add(simulation.getCarReturnedEventsQuery()); queriesToRegister.add(simulation.getWearEvents()); + queriesToRegister.add(simulation.getLockedMovingCars()); // Now register each query appropriately! for(QueryContainer queryContainer : queriesToRegister) { CsparqlQueryResultProxy resultProxy = null; diff --git a/src/main/java/lu/jpt/csparqlproject/rentacar/Car.java b/src/main/java/lu/jpt/csparqlproject/rentacar/Car.java index 3cf7f6b..b8edda7 100644 --- a/src/main/java/lu/jpt/csparqlproject/rentacar/Car.java +++ b/src/main/java/lu/jpt/csparqlproject/rentacar/Car.java @@ -237,7 +237,7 @@ public class Car { this.speed += RandomHelper.getRandomNumberWithin(5, 20); if(this.isCurrentActionHard) { this.speed += 40; - this.motorRpm += RandomHelper.getRandomNumberWithin(100, 350 + rpmBonus); + this.motorRpm += RandomHelper.getRandomNumberWithin(1000, 2000 + rpmBonus); } break; case BRAKING: @@ -246,7 +246,7 @@ public class Car { this.speed -= RandomHelper.getRandomNumberWithin(5, 20); if(this.isCurrentActionHard) { this.speed -= 40; - this.motorRpm -= RandomHelper.getRandomNumberWithin(100, 350 + rpmBonus); + this.motorRpm -= RandomHelper.getRandomNumberWithin(1000, 2000 + rpmBonus); } if(this.speed < 0) this.speed = 0; if(this.motorRpm < 0) this.motorRpm = Car.MIN_RPM[this.CAR_TYPE]; diff --git a/src/main/java/lu/jpt/csparqlproject/rentacar/RentACarSimulation.java b/src/main/java/lu/jpt/csparqlproject/rentacar/RentACarSimulation.java index 76449ff..870b4c5 100644 --- a/src/main/java/lu/jpt/csparqlproject/rentacar/RentACarSimulation.java +++ b/src/main/java/lu/jpt/csparqlproject/rentacar/RentACarSimulation.java @@ -338,7 +338,7 @@ public class RentACarSimulation implements Runnable { + " [] rdf:type car:CarBrakeWearEvent " + " ; car:relatedCar ?car . " + "} " - + "FROM STREAM <"+RentACarSimulation.BASE_STREAM_IRI+"/getStronglyBrakingCars> [RANGE 2s STEP 1s] " + + "FROM STREAM <"+RentACarSimulation.BASE_STREAM_IRI+"/getStronglyBrakingCars> [RANGE 3s STEP 1s] " + "WHERE { " + " ?e rdf:type car:CarStrongBrakingEvent . " + " ?e car:relatedCar ?car . " @@ -497,30 +497,71 @@ public class RentACarSimulation implements Runnable { /** * 5) Query to report all WearEvents using enabled inference. + * Also returns the responsible driver if available */ public QueryContainer getWearEvents() { String query = "REGISTER QUERY getWearEvents AS " + "PREFIX rdf: " + + "PREFIX rdfs: " + "PREFIX f: " + "PREFIX xsd: " + "PREFIX car: <"+RentACarSimulation.BASE_ONTOLOGY_IRI+"> " - + "SELECT ?e ?car ?types " - + "FROM STREAM <"+RentACarSimulation.BASE_STREAM_IRI+"/getEngineWear> [RANGE 5s STEP 1s] " - + "FROM STREAM <"+RentACarSimulation.BASE_STREAM_IRI+"/getBrakeWear> [RANGE 5s STEP 1s] " - + "FROM STREAM <"+RentACarSimulation.BASE_STREAM_IRI+"/getHandbrakeWear> [RANGE 5s STEP 1s] " - + "FROM STREAM <"+RentACarSimulation.BASE_STREAM_IRI+"/getTireWear> [RANGE 5s STEP 1s] " + + "SELECT ?e ?type ?car ?driverName ?driverPhone " + + "FROM STREAM <"+RentACarSimulation.BASE_STREAM_IRI+"/getEngineWear> [RANGE 1s TUMBLING] " + + "FROM STREAM <"+RentACarSimulation.BASE_STREAM_IRI+"/getBrakeWear> [RANGE 1s TUMBLING] " + + "FROM STREAM <"+RentACarSimulation.BASE_STREAM_IRI+"/getHandbrakeWear> [RANGE 1s TUMBLING] " + + "FROM STREAM <"+RentACarSimulation.BASE_STREAM_IRI+"/getTireWear> [RANGE 1s TUMBLING] " + + "FROM <"+RentACarSimulation.DOMAIN_KNOWLEDGE_GRAPH_IRI+"> " + "WHERE { " + " ?e rdf:type car:CarWearEvent . " - + " ?e rdf:type ?types . " - + " ?e car:relatedCar ?car " + + " ?e rdf:type ?type . " + + " ?e car:relatedCar ?car . " + + " OPTIONAL { " + + " ?car car:isDrivenBy ?driver . " + + " ?driver car:hasName ?driverName . " + + " ?driver car:hasPhoneNumber ?driverPhone . " + + " } " + "}"; - QueryContainer queryContainer = new QueryContainer("getWearEvents", query, true); + QueryContainer queryContainer = new QueryContainer("getWearEvents", query, false); queryContainer.useObserverWindow(); RentACarSimulation.setUpReasoningOnQueryContainer(queryContainer); return queryContainer; } - ////////////////////////////////////////////////////////////// + /** + * 6) Query to report locked cars that move due to forgotten handbrake + */ + public QueryContainer getLockedMovingCars() { + String query = "REGISTER QUERY getLockedMovingCars AS " + + "PREFIX rdf: " + + "PREFIX f: " + + "PREFIX xsd: " + + "PREFIX car: <"+RentACarSimulation.BASE_ONTOLOGY_IRI+"> " + + "SELECT ?car " + + "FROM STREAM <"+RentACarSimulation.CAR_STREAM_IRI+"> [RANGE 15s STEP 1s] " + + "WHERE { " + + " ?standingEvent rdf:type car:CarStatusEvent . " + + " ?standingEvent car:speed ?zeroSpeed . " + + " ?standingEvent car:handbrakeEngaged ?handbrake . " + + " ?standingEvent car:locked ?locked . " + + " ?rollingEvent rdf:type car:CarStatusEvent . " + + " ?rollingEvent car:speed ?speed . " + + " ?rollingEvent car:handbrakeEngaged ?handbrake . " + + " ?rollingEvent car:locked ?locked . " + + " FILTER(?zeroSpeed = 0) " + + " FILTER(?locked) " + + " FILTER(!?handbrake)" + + " FILTER(f:timestamp(?standingEvent,rdf:type,car:CarStatusEvent) < f:timestamp(?rollingEvent,rdf:type,car:CarStatusEvent)) " + + "}"; + QueryContainer queryContainer = new QueryContainer("getLockedMovingCars", query, true); + queryContainer.useObserverWindow(); + RentACarSimulation.setUpReasoningOnQueryContainer(queryContainer); + return queryContainer; + } + + ///////////////////////////////////// UNUSED QUERIES BELOW THIS LINE ///////////////////////////////////// + ///////////////////////////////////// UNUSED QUERIES BELOW THIS LINE ///////////////////////////////////// + ///////////////////////////////////// UNUSED QUERIES BELOW THIS LINE ///////////////////////////////////// public QueryContainer getEventsQuery() { String query = "REGISTER QUERY getCarStatusEvents AS "