Commit 7747dcf1 authored by Sebastian's avatar Sebastian
Browse files

last changes for dokumentation

parent 5d7d894f
......@@ -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() {
String eventString = pi_ID+" | "+ eventName +" | ";
......@@ -271,38 +271,38 @@ public class DataStreamJob {
//----------------------------------------------------------------------------------------------------
// // 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>() {
// @Override
// public boolean filter(Event evt) {
// return evt.getEventName().equals("joystick") && evt.getValues()[0] == 0.1d; //joystick = up
// }
// })
// .followedBy("second").where(new SimpleCondition<Event>() {
// @Override
// public boolean filter(Event evt) throws Exception {
// return evt.getEventName().equals("joystick") && evt.getValues()[0] == 1.0d; //joystick = right
// }
// }).oneOrMore() //one up can match with one or more right events
// .within(Time.seconds(5)) //in the timespan of 5 seconds
// ;
//
// PatternStream<Event> matchStream = CEP.pattern(inputStream, joystickEasyPattern); // apply pattern to Datastream
//
// // Create an outputstream from the matched events
// DataStream<String> outputStream = matchStream.select(new PatternSelectFunction<Event, String>() {
// @Override
// public String select(Map<String, List<Event>> match) throws Exception {
// //System.out.println(match.toString());
//
// // 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)
// Event firstMatchLastElement = match.get("first").get(match.get("first").size() - 1);
// Event secondMatchLastElement = match.get("second").get(match.get("second").size() - 1);
// return "pi_3 | joystick_pattern | " + firstMatchLastElement.getValues()[0] +" , "+ secondMatchLastElement.getValues()[0] + " | " +
// firstMatchLastElement.getTimestamps()[0] +" , "+secondMatchLastElement.getTimestamps()[0] + " | " + getCurrentTimeStr();
// }
// });
// 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>() {
@Override
public boolean filter(Event evt) {
return evt.getEventName().equals("joystick") && evt.getValues()[0] == 0.1d; //joystick = up
}
})
.followedBy("second").where(new SimpleCondition<Event>() {
@Override
public boolean filter(Event evt) throws Exception {
return evt.getEventName().equals("joystick") && evt.getValues()[0] == 1.0d; //joystick = right
}
}).oneOrMore() //one up can match with one or more right events
.within(Time.seconds(5)) //in the timespan of 5 seconds
;
PatternStream<Event> matchStream = CEP.pattern(inputStream, joystickEasyPattern); // apply pattern to Datastream
// Create an outputstream from the matched events
DataStream<String> outputStream = matchStream.select(new PatternSelectFunction<Event, String>() {
@Override
public String select(Map<String, List<Event>> match) throws Exception {
//System.out.println(match.toString());
// 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)
Event firstMatchLastElement = match.get("first").get(match.get("first").size() - 1);
Event secondMatchLastElement = match.get("second").get(match.get("second").size() - 1);
return "pi_3 | joystick_pattern | " + firstMatchLastElement.getValues()[0] +" , "+ secondMatchLastElement.getValues()[0] + " | " +
firstMatchLastElement.getTimestamps()[0] +" , "+secondMatchLastElement.getTimestamps()[0] + " | " + getCurrentTimeStr();
}
});
//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------
......@@ -335,7 +335,7 @@ public class DataStreamJob {
// firstMatchLastElement.getTimestamps()[0] +" , "+secondMatchLastElement.getTimestamps()[0] + " | " + getCurrentTimeStr();
// }
// });
//---------
//--------- Second Pi
// Pattern<Event, ?> helpPattern = Pattern.<Event> begin("first").where(new SimpleCondition<Event>() {
// @Override
// public boolean filter(Event evt) {
......@@ -366,36 +366,36 @@ public class DataStreamJob {
//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------
//Einbruchspattern: 3 Pi's nehmen nacheinander Bewegung war (simuliert durch Gyroskop)
Pattern<Event, ?> firstMotionPattern = Pattern.<Event> begin("first").where(new SimpleCondition<Event>() {
@Override
public boolean filter(Event evt) {
return evt.getPi_ID().equals("pi_3") && evt.getEventName().equals("accelerometer_x") && evt.getValues()[0] < 0.5;
}
})
.followedBy("second").where(new SimpleCondition<Event>() {
@Override
public boolean filter(Event evt) throws Exception {
return evt.getPi_ID().equals("pi_3") && evt.getEventName().equals("accelerometer_x") && evt.getValues()[0] > 0.5;
}
}).within(Time.seconds(3))
;
PatternStream<Event> matchStream = CEP.pattern(inputStream, firstMotionPattern); // apply pattern to Datastream
// Create an outputstream from the matched events
DataStream<String> outputStream = matchStream.select(new PatternSelectFunction<Event, String>() {
@Override
public String select(Map<String, List<Event>> match) throws Exception {
//System.out.println(match.toString());
Event firstMatchLastElement = match.get("first").get(match.get("first").size() - 1);
Event secondMatchLastElement = match.get("second").get(match.get("second").size() - 1);
return "pi_3 | motion1 | " + firstMatchLastElement.getValues()[0] +" , "+ secondMatchLastElement.getValues()[0] + " | " +
firstMatchLastElement.getTimestamps()[0] +" , "+secondMatchLastElement.getTimestamps()[0] + " | " + getCurrentTimeStr();
}
});
//---------
// //Alertpattern: 3 Pi's detect movement one after another
// Pattern<Event, ?> firstMotionPattern = Pattern.<Event> begin("first").where(new SimpleCondition<Event>() {
// @Override
// public boolean filter(Event evt) {
// return evt.getPi_ID().equals("pi_3") && evt.getEventName().equals("accelerometer_x") && evt.getValues()[0] < 0.5;
// }
// })
// .followedBy("second").where(new SimpleCondition<Event>() {
// @Override
// public boolean filter(Event evt) throws Exception {
// return evt.getPi_ID().equals("pi_3") && evt.getEventName().equals("accelerometer_x") && evt.getValues()[0] > 0.5;
// }
// }).within(Time.seconds(3))
// ;
//
// PatternStream<Event> matchStream = CEP.pattern(inputStream, firstMotionPattern); // apply pattern to Datastream
//
// // Create an outputstream from the matched events
// DataStream<String> outputStream = matchStream.select(new PatternSelectFunction<Event, String>() {
// @Override
// public String select(Map<String, List<Event>> match) throws Exception {
// //System.out.println(match.toString());
//
// Event firstMatchLastElement = match.get("first").get(match.get("first").size() - 1);
// Event secondMatchLastElement = match.get("second").get(match.get("second").size() - 1);
// return "pi_3 | motion1 | " + firstMatchLastElement.getValues()[0] +" , "+ secondMatchLastElement.getValues()[0] + " | " +
// firstMatchLastElement.getTimestamps()[0] +" , "+secondMatchLastElement.getTimestamps()[0] + " | " + getCurrentTimeStr();
// }
// });
//--------- Second Pi
// Pattern<Event, ?> secondMotionPattern = Pattern.<Event> begin("first").where(new SimpleCondition<Event>() {
// @Override
// public boolean filter(Event evt) {
......@@ -430,7 +430,7 @@ public class DataStreamJob {
// firstMatchLastElement.getTimestamps()[1] +" , "+ thirdMatchLastElement.getTimestamps()[0] + " | " + getCurrentTimeStr();
// }
// });
//---------
//--------- Third Pi
// Pattern<Event, ?> thirdMotionPattern = Pattern.<Event> begin("first").where(new SimpleCondition<Event>() {
// @Override
// public boolean filter(Event evt) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment