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

@Plan:description('Find the street name of the location and add to a new stream')

@Import('iot.per.device.stream.android.location:1.0.0')
define stream LocationStream (meta_owner string, meta_deviceId string, meta_timestamp long, latitude double, longitude double);

@Export('iot.per.device.stream.android.location.stats:1.0.0')
define stream LocationStatsStream (meta_owner string, meta_deviceId string, meta_timestamp long, latitude double, longitude double, streetName string, year int, month int, day int, hour int, minute int);

partition with (meta_deviceId of LocationStream)
begin
	from LocationStream
	select meta_owner, meta_deviceId, meta_timestamp, convert(math:round(latitude * 10000), 'double') / 10000.0 as latitude, convert(math:round(longitude * 10000), 'double') / 10000.0 as longitude, "" as streetName, 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 LocationStatsStream;
end;