@Plan:name('Android-Proximity-ExecutionPlan')

@Plan:description('Process proximity changes.')

@Import('org.wso2.iot.android.proximity:1.0.0')
define stream ProximityStream (meta_owner string, meta_deviceId string, meta_timestamp long, proximity float);

@Export('org.wso2.iot.android.proximity.stats:1.0.0')
define stream ProximityStatsStream (meta_owner string, meta_deviceId string, meta_timestamp long, proximity float, year int,
month int, day int, hour int, minute int);

partition with (meta_deviceId of ProximityStream)
begin
    from ProximityStream
    select meta_owner, meta_deviceId, meta_timestamp, proximity, time:extract
    (meta_timestamp, 'year') as year, time:extract(meta_timestamp, 'month') as month, time:extract(meta_timestamp, 'day') as day, time:extract(meta_timestamp, 'hour') as hour, time:extract(meta_timestamp, 'minute') as minute
    insert into ProximityStatsStream;
end;