From 612b4019473249dfe726f6230e5d6cfdc374b976 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Fri, 8 Jul 2016 12:12:20 +0200 Subject: [PATCH] [TASK] Begin implementing a query to detect breaking down cars. --- src/main/java/lu/jpt/csparqltest/Main.java | 47 +++++++++++++++++----- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/src/main/java/lu/jpt/csparqltest/Main.java b/src/main/java/lu/jpt/csparqltest/Main.java index da9b256..39525cc 100644 --- a/src/main/java/lu/jpt/csparqltest/Main.java +++ b/src/main/java/lu/jpt/csparqltest/Main.java @@ -18,7 +18,10 @@ public class Main { private static Logger logger = LoggerFactory.getLogger(Main.class); public static void main(String[] args) { - System.out.println("Hallo!"); + // Determines the time the engine will be run for + final long millisecondsToRun = 50 * 1000; + + // Load configuration for log4j try { PropertyConfigurator.configure("./src/main/resources/log4j.properties"); } catch(Throwable t) { @@ -28,8 +31,10 @@ public class Main { // Instantiate and initialize engine CsparqlEngine engine = new CsparqlEngineImpl(); engine.initialize(true); - logger.debug("CWD: " + System.getProperty("user.dir")); - logger.debug("Engine from: " + engine.getClass().getProtectionDomain().getCodeSource()); + + // Debugging: Needed to verify which engine is being used + //logger.debug("CWD: " + System.getProperty("user.dir")); + //logger.debug("Engine from: " + engine.getClass().getProtectionDomain().getCodeSource()); // Create and register stream generator at specific URI RdfStream carStreamGenerator = new CarStreamGenerator("http://myexample.org/cars"); @@ -40,7 +45,7 @@ public class Main { t.start(); // Now build a query to run - interchangeable - String query = Main.getAcceleratingCarsQuery(); + String query = Main.getBreakingDownCarsQuery(); // Create a result proxy by registering the query at the engine CsparqlQueryResultProxy resultProxy = null; @@ -53,9 +58,9 @@ public class Main { // Add ConsoleFormatter as observer so it gets notified of every query result resultProxy.addObserver(new ConsoleFormatter()); - // Let it all run for a couple of seconds (3 min, 20 seconds) + // Let it all run for some time try { - Thread.sleep(20000); + Thread.sleep(millisecondsToRun); } catch (InterruptedException e) { logger.error(e.getMessage(), e); } @@ -86,7 +91,7 @@ public class Main { } private static String getIncreasingTemperatureQuery() { - return "REGISTER QUERY getIncreasingTemperature AS " + return "REGISTER QUERY IncreasingTemperature AS " + "PREFIX f: " + "PREFIX xsd: " + "PREFIX cars: " @@ -99,13 +104,13 @@ public class Main { + " ?e2 cars:carID ?car . " + " ?e2 cars:currentSpeed ?speed2 . " + " ?e2 cars:currentTemperature ?temp2 . " - + " FILTER(f:timestamp(?e1,cars:carID,?car) > f:timestamp(?e2,cars:carID,?car)) " + + " FILTER(f:timestamp(?e1,cars:carID,?car) < f:timestamp(?e2,cars:carID,?car)) " + " FILTER(?temp1 < ?temp2) " + "}"; } private static String getAcceleratingCarsQuery() { - return "REGISTER QUERY getAcceleratingCars AS " + return "REGISTER QUERY AcceleratingCars AS " + "PREFIX f: " + "PREFIX xsd: " + "PREFIX cars: " @@ -118,9 +123,31 @@ public class Main { + " ?e2 cars:carID ?car . " + " ?e2 cars:currentSpeed ?speed2 . " + " ?e2 cars:currentTemperature ?temp2 . " - + " FILTER(f:timestamp(?e1,cars:carID,?car) > f:timestamp(?e2,cars:carID,?car)) " + + " FILTER(f:timestamp(?e1,cars:carID,?car) < f:timestamp(?e2,cars:carID,?car)) " + " FILTER(?speed1 < ?speed2) " + "}"; } + private static String getBreakingDownCarsQuery() { + return "REGISTER QUERY BreakingDownCars AS " + + "PREFIX f: " + + "PREFIX xsd: " + + "PREFIX cars: " + + "SELECT ?car (?speed2 - ?speed1 AS ?deltaspeed) (?temp2 - ?temp1 AS ?deltatemp) ?speed2 ?temp2 " + + "FROM STREAM [RANGE 5s STEP 1s] " + + "WHERE { " + + " ?e1 cars:carID ?car ; " + + " cars:currentSpeed ?speed1 ; " + + " cars:currentTemperature ?temp1 . " + + " ?e2 cars:carID ?car ; " + + " cars:currentSpeed ?speed2 ; " + + " cars:currentTemperature ?temp2 . " + + " FILTER(f:timestamp(?e1,cars:carID,?car) < f:timestamp(?e2,cars:carID,?car)) " + + " FILTER(f:timestamp(?e2,cars:carID,?car) - f:timestamp(?e1,cars:carID,?car) < 1800) " + + " FILTER(?speed1 > ?speed2) " + + " FILTER(?temp2 > ?temp1) " + + " FILTER(?temp2 > 90) " + + "}"; + } + }