********************************************************** @Name('Crash') context SegmentedByMotorbikeId insert into Crash select current_timestamp() as timestamp, a2.motorbikeId as motorbikeId, a2.location as location, a1.speed as speed_a1, a2.speed as speed_a2 from pattern [every a1 = MotorbikeEvent(a1.speed >= 50) -> a2 = MotorbikeEvent(a2.speed = 0) where timer:within(3 milliseconds)]; ********************************************************** @Name('BlowOutTire') context SegmentedByMotorbikeId insert into BlowOutTire select current_timestamp() as timestamp, a2.motorbikeId as motorbikeId, a1.location as location_a1, a1.tirePressure1 as tirePressure1_a1, a1.tirePressure2 as tirePressure2_a1, a2.location as location_a2, a2.tirePressure1 as tirePressure1_a2, a2.tirePressure2 as tirePressure2_a2 from pattern [(every a1 = MotorbikeEvent(a1.tirePressure1 >= 2.0) -> a2 = MotorbikeEvent(a2.tirePressure1 <= 1.2) where timer:within(5 milliseconds)) or (every a1 = MotorbikeEvent(a1.tirePressure2 >= 2.0) -> a2 = MotorbikeEvent(a2.tirePressure2 <= 1.2) where timer:within(5 milliseconds))]; ********************************************************** @Name('DriverLeftSeat') context SegmentedByMotorbikeId insert into DriverLeftSeat select current_timestamp() as timestamp, a2.motorbikeId as motorbikeId, a2.location as location, a1.seat as seat_a1, a2.seat as seat_a2 from pattern [every a1 = MotorbikeEvent(a1.seat = true) -> a2 = MotorbikeEvent(a2.seat = false)]; ********************************************************** @Name('GhostRider') insert into GhostRider select e.timestamp as timestamp, e.motorbikeId as motorbikeId from pattern [every e = MotorbikeEvent(e.seat = false and e.speed>0)]; ********************************************************** @Name('DangerousLocation') insert into DangerousLocation select current_timestamp() as timestamp, a1.location as location from pattern [every a1 = Crash(a1.location = 'Cadiz')].win:length_batch(100) group by a1.location; ********************************************************** @Name('OccupantThrownAccident') insert into OccupantThrownAccident select current_timestamp() as timestamp, a3.motorbikeId as motorbikeId, a3.location as location from pattern [every-distinct(a1.motorbikeId, a1.timestamp) a1 = BlowOutTire -> (a2 = Crash(a1.motorbikeId = a2.motorbikeId) -> a3 = DriverLeftSeat(a1.motorbikeId = a3.motorbikeId)) where timer:within(3 milliseconds)]; ********************************************************** @Name('AccidentsReport') select current_timestamp() as timestamp, a1.location as location, count(*) as count from pattern [every a1 = OccupantThrownAccident].win:time_batch(86400 milliseconds) group by a1.location;