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


        CREATE TEMPORARY TABLE RESPONSE_PERCENTILE_GEN USING CarbonAnalytics OPTIONS (tableName "ORG_WSO2_ANALYTICS_APIM_RESPONSEPERCENTILE",
        schema "api_version string, tenantDomain string, resourceTemplate string, method string, responsePercentile double, backendPercentile double ",
        primaryKeys "api_version,tenantDomain,resourceTemplate,method"
        );


        INSERT OVERWRITE TABLE RESPONSE_PERCENTILE_GEN
        select api_version, tenantDomain, resourceTemplate, method,
        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 responsePercentile,
        getpercentileValue(cast(avg(backendTime) as double), cast(sqrt(avg(cast(backendTime as double)*cast(backendTime as double))-avg(backendTime)*avg(backendTime)) as double), cast(0.95 as double) ) as backendPercentile
        from RESPONSE_INFO group by api_version, tenantDomain, resourceTemplate, method;

    </Script>
</Analytics>


