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

@Plan:description('Find the battery status of the android device.')


@Import('iot.per.device.stream.android.battery:1.0.0')
define stream BatteryStream (meta_owner string, meta_deviceId string, meta_timestamp long, level int, state string, status int, temperature int);


@Export('iot.per.device.stream.android.battery.stats:1.0.0')
define stream BatteryStatsStream (meta_owner string, meta_deviceId string, meta_timestamp long, level int, state
string, status int, temperature int, year int, month int, day int, hour int, minute int);

partition with (meta_deviceId of BatteryStream)
begin
    from BatteryStream
    select meta_owner, meta_deviceId, meta_timestamp, level, state, status, temperature, time:extract(preState.meta_timestamp, 'year') as year, time:extract(preState.meta_timestamp, 'month') as month, time:extract(preState.meta_timestamp, 'day') as day, time:extract(preState.meta_timestamp, 'hour') as hour, time:extract(preState.meta_timestamp, 'minute') as minute
    insert into BatteryStatsStream;
end;