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

        CREATE TEMPORARY TABLE RESPONSE_PER_API_PERCENTILE_GEN USING CarbonAnalytics OPTIONS (tableName "ORG_WSO2_ANALYTICS_APIM_RESPONSEPERAPIPERCENTILE",
        schema "api_version string -i, tenantDomain string -i, responsesPerMinPerApiLowerPercentile double",
        primaryKeys "api_version, tenantDomain"
        );

        INSERT INTO TABLE RESPONSE_PER_API_PERCENTILE_GEN
        select api_version, tenantDomain, 
        getpercentileValue(cast(avg(responsesPerMinPerApi) as double), cast(sqrt(avg(cast(responsesPerMinPerApi
        as double)*cast(responsesPerMinPerApi as double))-avg(responsesPerMinPerApi)*avg(responsesPerMinPerApi)) as double), cast(0.05 as double) ) as responsesPerMinPerApiLowerPercentile
        from RESPONSE_PER_API_INFO group by api_version, tenantDomain;
    </Script>
</Analytics>


