Filip Szarek

Standard Deviation Query Type

stddev
Share on facebook
Share on twitter
Share on pinterest

Hello Keen Community! We have released a new query type, standard deviation, to add even more flexibility to your computing capabilities.

What is a standard deviation?

In statistics, standard deviation is a measure used to quantify the amount of variation or dispersion of a set of data values. A low standard deviation indicates that the data points tend to be close to the mean (also called the expected value) of the set, while a high standard deviation indicates that the data points are spread out over a wider range of values.

stddev

An example of standard deviation in practice

For our customers that charge for their products with usage-based pricing models, standard deviation can provide useful insights into pricing fluctuations to help their users better understand and evaluate their usage and pricing patterns. For example, if a customer’s daily usage costs $50 on average but has a standard deviation of $200, that suggests that their monthly bill may be dominated by a few one-off spikes. This scenario could be flagged for the customer so that they can investigate the cause of the spikes and mitigate them, or explore alternate pricing options.

Simple implementation example:

When you want to get the standard deviation of all your data you can execute a GET request:

curl https://api.keen.io/3.0/projects/PROJECT_ID/queries/standard_deviation?api_key=READ_KEY&event_collection=COLLECTION_NAME&target_property=TARGET_PROPERTY

This is the easiest way of getting the same information in specific time frames using POST:

Using cURL

curl https://api.keen.io/3.0/projects/PROJECT_ID/queries/standard_deviation \
    -H "AuthorizationL READ_KEY" \
    -H "Content-Type: application/json" \
    -d "{
            \"event_collection\": \"COLLECTION_NAME\",
            \"target_property\": \"TARGET_PROPERTY\",
            \"timeframe\": \"this_2_months\"
        }"

Using our updated KeenClient-Java:

String KEEN_PROJECT_ID="<PROJECT_ID>";
String KEEN_WRITE_KEY="<WRITE_KEY>";
String KEEN_READ_KEY="<READ_KEY>";

KeenProject keenProject = new KeenProject(KEEN_PROJECT_ID, KEEN_WRITE_KEY, KEEN_READ_KEY);
KeenQueryClient keenQueryClient = new KeenQueryClient.Builder(keenProject).build();

try {
    standard_deviation = keenQuerytClient
        .standardDeviation(
            eventCollection: "<EVENT_COLLECTION>",
            targetProperty: "<TARGET_PROPERTY>",
            new RelativeTimeFrame("<TIME_FRAME>"));
} catch (IOException e) {
    e.printStackTrace();
}

Or any other sdk

Thank you for reading!

Filip Szarek
Back-End developer

Share this post with your friends

Share on facebook
Share on google
Share on twitter
Share on linkedin

Subscribe to our Newsletter

Leave a Reply

Your email address will not be published. Required fields are marked *