Skip to content
Snippets Groups Projects
Commit 7747dcf1 authored by Sebastian's avatar Sebastian
Browse files

last changes for dokumentation

parent 5d7d894f
Branches main
No related tags found
No related merge requests found
...@@ -167,7 +167,7 @@ public class DataStreamJob { ...@@ -167,7 +167,7 @@ public class DataStreamJob {
} }
} }
// Implemented toString() so generic print()-method can be called on Event-type // Implemented toString() so generic print() can be called on Event-type
public String toString() { public String toString() {
String eventString = pi_ID+" | "+ eventName +" | "; String eventString = pi_ID+" | "+ eventName +" | ";
...@@ -271,38 +271,38 @@ public class DataStreamJob { ...@@ -271,38 +271,38 @@ public class DataStreamJob {
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
// // Simple pattern for sensehat joystick: up then (one or more) right (in the timespan of 5 seconds) // Simple pattern for sensehat joystick: up then (one or more) right (in the timespan of 5 seconds)
// Pattern<Event, ?> joystickEasyPattern = Pattern.<Event> begin("first").where(new SimpleCondition<Event>() { Pattern<Event, ?> joystickEasyPattern = Pattern.<Event> begin("first").where(new SimpleCondition<Event>() {
// @Override @Override
// public boolean filter(Event evt) { public boolean filter(Event evt) {
// return evt.getEventName().equals("joystick") && evt.getValues()[0] == 0.1d; //joystick = up return evt.getEventName().equals("joystick") && evt.getValues()[0] == 0.1d; //joystick = up
// } }
// }) })
// .followedBy("second").where(new SimpleCondition<Event>() { .followedBy("second").where(new SimpleCondition<Event>() {
// @Override @Override
// public boolean filter(Event evt) throws Exception { public boolean filter(Event evt) throws Exception {
// return evt.getEventName().equals("joystick") && evt.getValues()[0] == 1.0d; //joystick = right return evt.getEventName().equals("joystick") && evt.getValues()[0] == 1.0d; //joystick = right
// } }
// }).oneOrMore() //one up can match with one or more right events }).oneOrMore() //one up can match with one or more right events
// .within(Time.seconds(5)) //in the timespan of 5 seconds .within(Time.seconds(5)) //in the timespan of 5 seconds
// ; ;
//
// PatternStream<Event> matchStream = CEP.pattern(inputStream, joystickEasyPattern); // apply pattern to Datastream PatternStream<Event> matchStream = CEP.pattern(inputStream, joystickEasyPattern); // apply pattern to Datastream
//
// // Create an outputstream from the matched events // Create an outputstream from the matched events
// DataStream<String> outputStream = matchStream.select(new PatternSelectFunction<Event, String>() { DataStream<String> outputStream = matchStream.select(new PatternSelectFunction<Event, String>() {
// @Override @Override
// public String select(Map<String, List<Event>> match) throws Exception { public String select(Map<String, List<Event>> match) throws Exception {
// //System.out.println(match.toString()); //System.out.println(match.toString());
//
// // Since output gets invoked with every match, we need to filter matched events // Since output gets invoked with every match, we need to filter matched events
// // Matched events are saved in a list and each further eventmatch B to an event A is getting appended to the second list (so with every invoke take the last elements of the lists) // Matched events are saved in a list and each further eventmatch B to an event A is getting appended to the second list (so with every invoke take the last elements of the lists)
// Event firstMatchLastElement = match.get("first").get(match.get("first").size() - 1); Event firstMatchLastElement = match.get("first").get(match.get("first").size() - 1);
// Event secondMatchLastElement = match.get("second").get(match.get("second").size() - 1); Event secondMatchLastElement = match.get("second").get(match.get("second").size() - 1);
// return "pi_3 | joystick_pattern | " + firstMatchLastElement.getValues()[0] +" , "+ secondMatchLastElement.getValues()[0] + " | " + return "pi_3 | joystick_pattern | " + firstMatchLastElement.getValues()[0] +" , "+ secondMatchLastElement.getValues()[0] + " | " +
// firstMatchLastElement.getTimestamps()[0] +" , "+secondMatchLastElement.getTimestamps()[0] + " | " + getCurrentTimeStr(); firstMatchLastElement.getTimestamps()[0] +" , "+secondMatchLastElement.getTimestamps()[0] + " | " + getCurrentTimeStr();
// } }
// }); });
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
...@@ -335,7 +335,7 @@ public class DataStreamJob { ...@@ -335,7 +335,7 @@ public class DataStreamJob {
// firstMatchLastElement.getTimestamps()[0] +" , "+secondMatchLastElement.getTimestamps()[0] + " | " + getCurrentTimeStr(); // firstMatchLastElement.getTimestamps()[0] +" , "+secondMatchLastElement.getTimestamps()[0] + " | " + getCurrentTimeStr();
// } // }
// }); // });
//--------- //--------- Second Pi
// Pattern<Event, ?> helpPattern = Pattern.<Event> begin("first").where(new SimpleCondition<Event>() { // Pattern<Event, ?> helpPattern = Pattern.<Event> begin("first").where(new SimpleCondition<Event>() {
// @Override // @Override
// public boolean filter(Event evt) { // public boolean filter(Event evt) {
...@@ -366,36 +366,36 @@ public class DataStreamJob { ...@@ -366,36 +366,36 @@ public class DataStreamJob {
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
//Einbruchspattern: 3 Pi's nehmen nacheinander Bewegung war (simuliert durch Gyroskop) // //Alertpattern: 3 Pi's detect movement one after another
Pattern<Event, ?> firstMotionPattern = Pattern.<Event> begin("first").where(new SimpleCondition<Event>() { // Pattern<Event, ?> firstMotionPattern = Pattern.<Event> begin("first").where(new SimpleCondition<Event>() {
@Override // @Override
public boolean filter(Event evt) { // public boolean filter(Event evt) {
return evt.getPi_ID().equals("pi_3") && evt.getEventName().equals("accelerometer_x") && evt.getValues()[0] < 0.5; // return evt.getPi_ID().equals("pi_3") && evt.getEventName().equals("accelerometer_x") && evt.getValues()[0] < 0.5;
} // }
}) // })
.followedBy("second").where(new SimpleCondition<Event>() { // .followedBy("second").where(new SimpleCondition<Event>() {
@Override // @Override
public boolean filter(Event evt) throws Exception { // public boolean filter(Event evt) throws Exception {
return evt.getPi_ID().equals("pi_3") && evt.getEventName().equals("accelerometer_x") && evt.getValues()[0] > 0.5; // return evt.getPi_ID().equals("pi_3") && evt.getEventName().equals("accelerometer_x") && evt.getValues()[0] > 0.5;
} // }
}).within(Time.seconds(3)) // }).within(Time.seconds(3))
; // ;
//
PatternStream<Event> matchStream = CEP.pattern(inputStream, firstMotionPattern); // apply pattern to Datastream // PatternStream<Event> matchStream = CEP.pattern(inputStream, firstMotionPattern); // apply pattern to Datastream
//
// Create an outputstream from the matched events // // Create an outputstream from the matched events
DataStream<String> outputStream = matchStream.select(new PatternSelectFunction<Event, String>() { // DataStream<String> outputStream = matchStream.select(new PatternSelectFunction<Event, String>() {
@Override // @Override
public String select(Map<String, List<Event>> match) throws Exception { // public String select(Map<String, List<Event>> match) throws Exception {
//System.out.println(match.toString()); // //System.out.println(match.toString());
//
Event firstMatchLastElement = match.get("first").get(match.get("first").size() - 1); // Event firstMatchLastElement = match.get("first").get(match.get("first").size() - 1);
Event secondMatchLastElement = match.get("second").get(match.get("second").size() - 1); // Event secondMatchLastElement = match.get("second").get(match.get("second").size() - 1);
return "pi_3 | motion1 | " + firstMatchLastElement.getValues()[0] +" , "+ secondMatchLastElement.getValues()[0] + " | " + // return "pi_3 | motion1 | " + firstMatchLastElement.getValues()[0] +" , "+ secondMatchLastElement.getValues()[0] + " | " +
firstMatchLastElement.getTimestamps()[0] +" , "+secondMatchLastElement.getTimestamps()[0] + " | " + getCurrentTimeStr(); // firstMatchLastElement.getTimestamps()[0] +" , "+secondMatchLastElement.getTimestamps()[0] + " | " + getCurrentTimeStr();
} // }
}); // });
//--------- //--------- Second Pi
// Pattern<Event, ?> secondMotionPattern = Pattern.<Event> begin("first").where(new SimpleCondition<Event>() { // Pattern<Event, ?> secondMotionPattern = Pattern.<Event> begin("first").where(new SimpleCondition<Event>() {
// @Override // @Override
// public boolean filter(Event evt) { // public boolean filter(Event evt) {
...@@ -430,7 +430,7 @@ public class DataStreamJob { ...@@ -430,7 +430,7 @@ public class DataStreamJob {
// firstMatchLastElement.getTimestamps()[1] +" , "+ thirdMatchLastElement.getTimestamps()[0] + " | " + getCurrentTimeStr(); // firstMatchLastElement.getTimestamps()[1] +" , "+ thirdMatchLastElement.getTimestamps()[0] + " | " + getCurrentTimeStr();
// } // }
// }); // });
//--------- //--------- Third Pi
// Pattern<Event, ?> thirdMotionPattern = Pattern.<Event> begin("first").where(new SimpleCondition<Event>() { // Pattern<Event, ?> thirdMotionPattern = Pattern.<Event> begin("first").where(new SimpleCondition<Event>() {
// @Override // @Override
// public boolean filter(Event evt) { // public boolean filter(Event evt) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment