<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Analytics>
    <Editable>true</Editable>
    <Name>AndroidScreenScript</Name>
    <Script>        CREATE TEMPORARY TABLE AndroidScreenData USING CarbonAnalytics OPTIONS(tableName "IOT_PER_DEVICE_STREAM_ANDROID_SCREEN_STATS", incrementalParams "IOT_PER_DEVICE_STREAM_ANDROID_SCREEN_STATS, DAY");
    
        CREATE TEMPORARY TABLE Android_Screen_Stat_Per_Day USING CarbonAnalytics
        OPTIONS (tableName "Android_Screen_Stat_Per_Day",
        schema "owner STRING -i, deviceId STRING -i, duration LONG -i, year INT -i, month INT -i, day INT -i, timestamp STRING -i",
        primaryKeys "year, month, day, deviceId, owner",
        mergeSchema "false");

        INSERT INTO TABLE Android_Screen_Stat_Per_Day
        SELECT meta_owner as owner, meta_deviceId as deviceId, sum(duration) as duration, year, month, day, getDateStartingTime(year, month, day) as timestamp
        FROM AndroidScreenData
        GROUP BY year, month, day, meta_deviceId, meta_owner ORDER BY timestamp DESC;
        
        INCREMENTAL_TABLE_COMMIT IOT_PER_DEVICE_STREAM_ANDROID_SCREEN_STATS;
    </Script>
    <CronExpression>0 0/5 * * * ?</CronExpression>
</Analytics>
