<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Analytics>
    <CronExpression>0 0 12 * * ?</CronExpression>
    <Editable>true</Editable>
    <Name>APIMAnalytics-ResponseTime-ResponseTime-batch1</Name>
    <Script>
                CREATE TEMPORARY TABLE RESPONSE_INFO USING CarbonAnalytics OPTIONS (tableName "ORG_WSO2_APIMGT_STATISTICS_PERMINUTERESPONSE");

        CREATE TEMPORARY TABLE RESPONSE_PER_TIME_PERCENTILE_GEN USING CarbonAnalytics OPTIONS (tableName "ORG_WSO2_ANALYTICS_APIM_RESPONSETIMEPERAPIPERCENTILE",
        schema "api_version string -i, tenantDomain string -i,  responseTimePerApiUpperPercentile double ",
        primaryKeys "api_version, tenantDomain" , mergeSchema "false"
        );

        INSERT INTO TABLE RESPONSE_PER_TIME_PERCENTILE_GEN
        select api_version, tenantDomain,
        getpercentileValue(cast(avg(responseTime) as double), cast(sqrt(avg(cast(responseTime as double)*cast(responseTime as double))-avg(responseTime)*avg(responseTime)) as double),
        cast(0.95 as double) ) as responseTimePerApiUpperPercentile

        from RESPONSE_INFO group by api_version, tenantDomain;

    </Script>
</Analytics>


