From zero to Internet of Things analytics

You'll learn how to create a database and create analytics with an Internet Of Things (IoT) dataset using the API and the Data Exploration & Visualization Module.

In this page

Introduction

This tutorial will introduce you on how to use SlicingDice for storing, making queries of IoT data and visualize it using the built-in Data Exploration & Visualization Module.
For this tutorial, we'll purpose a dataset where you collect data from Internet-enabled devices from airplanes and insert it on SlicingDice. We'll also use API to the queries and insertion processes.


Retrieving your Team API Key

As we'll use the API, you'll need to retrieve your Team API Key in order to create a new database. Go to Control Panel, then open the Database Section. Click on Team API Key button and copy your Team API Key.

You can use any API REST client you prefer to execute your API requests or you can do it using curl as shown in the examples on this tutorial.


Creating a database

To create a database using API, you'll need to send a POST request to the /database API Endpoint, like the following example. You should receive a success message after the execution.

curl -X POST https://api.slicingdice.com/v1/database \
    -H 'Authorization: TEAM_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '{
    	"database": {
      		"name": "IoTDB",
      		"description": "Database to store airplanes data",
      		"type": "test",
      		"pricing-model": "pay-per-column",
      		"query-load": "normal",
      		"insertion-load": "normal",
            "cloud_provider": "ovh",
            "cloud_area": "global"
    		}
}'

Retrieving your Database Key

As your database is created, you'll now need to retrieve the Database Key to start modeling and using it. Go to Control Panel, open the Database Section. Find your database name, click on Show Keys and copy the Master Key.


Creating columns

Before inserting data, we need to create some columns. For this tutorial, we'll use the default dimension. We'll also create new columns, based on the table below.

Column Name Data Type
entity-id Unique-ID
latest-traveled-route String
route-consumed-fuel Decimal-Event

We'll use a POST request on the /column endpoint to create a new column. You can also use our SDK Clients to create them. The command you should execute will be like this:

$ curl -X POST https://api.slicingdice.com/v1/column \
    -H 'Authorization: MASTER_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '[
        {
            "name": "latest-traveled-route",
            "api-name": "latest-traveled-route",
            "type": "string",
            "storage": "latest-value",
            "dimension": "default"
        }, {
            "name": "route-consumed-fuel",
            "api-name": "route-consumed-fuel",
            "type": "decimal-event",
            "decimal-places": 2,
            "dimension": "default"
        }
    ]'
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY', uses_test_endpoint=True)

columns_data = [
        {
            "name": "latest-traveled-route",
            "api-name": "latest-traveled-route",
            "type": "string",
            "storage": "latest-value",
            "dimension": "default"
        }, {
            "name": "route-consumed-fuel",
            "api-name": "route-consumed-fuel",
            "type": "decimal-event",
            "decimal-places": 2,
            "dimension": "default"
        }
]
print(slicingdice.create_column(columns_data))
import com.slicingdice.jslicer.SlicingDice;
import java.io.IOException;
import org.json.JSONObject;
import org.json.JSONArray;

public class Example {
    public static void main(String[] args) throws IOException {
        SlicingDice slicingdice = new SlicingDice("MASTER_API_KEY", true);

        JSONArray columnData = new JSONArray()
        .put(new JSONObject()
            .put("name", "latest-traveled-route")
            .put("api-name", "latest-traveled-rout")
            .put("type", "string")
            .put("storage", "latest-value")
            .put("dimension", "default"))
        .put(new JSONObject()
            .put("name", "route-consumed-fuel")
            .put("api-name", "route-consumed-fuel")
            .put("type", "decimal-event")
            .put("decimal-places", 2)
            .put("dimension", "default"));
        JSONObject result = slicingdice.createColumn(columnData);
        System.out.println(result.toString());
    }
}
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY', uses_test_endpoint: true)

column_data = [
        {
            "name" => "latest-traveled-route",
            "api-name" => "latest-traveled-route",
            "type" => "string",
            "storage" => "latest-value",
            "dimension" => "default"
        }, {
            "name" => "route-consumed-fuel",
            "api-name" => "route-consumed-fuel",
            "type" => "decimal-event",
            "decimal-places" => 2,
            "dimension" => "default"
        }
]
puts slicingdice.create_column(column_data)
const SlicingDice = require('slicerjs');

const usesTestEndpoint = true;
const slicingdice = new SlicingDice({masterKey: 'MASTER_API_KEY'}, usesTestEndpoint);

const columnData = [
        {
            "name": "latest-traveled-route",
            "api-name": "latest-traveled-route",
            "type": "string",
            "storage": "latest-value",
            "dimension": "default"
        }, {
            "name": "route-consumed-fuel",
            "api-name": "route-consumed-fuel",
            "type": "decimal-event",
            "decimal-places": 2,
            "dimension": "default"
        }
];

slicingdice.createColumn(columnData).then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});
<?php
use Slicer\SlicingDice;
$usesTestEndpoint = true;
$slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"), $usesTestEndpoint);

$columnData = array(
    array(
        "name" => "latest-traveled-route",
        "api-name" => "latest-traveled-route",
        "type" => "string",
        "storage" => "latest-value",
        "dimension" => "default"
    ),
    array(
        "name" => "route-consumed-fuel",
        "api-name" => "route-consumed-fuel",
        "type" => "decimal-event",
        "decimal-places" => 2,
        "dimension" => "default"
    )
);

print_r($slicingdice->createColumn($columnData));
?>
using System.Collections.Generic;
using Slicer;
using Newtonsoft.Json;

namespace SlicerTester.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            var slicingdice = new SlicingDice(masterKey: "MASTER_API_KEY", usesTestEndpoint: true);

            var columnData = new List<dynamic>{
                new Dictionary<string, dynamic>{
                    {"name", "latest-traveled-route"},
                    {"api-name", "latest-traveled-route"},
                    {"type", "string"},
                    {"storage", "latest-value"},
                    {"dimension", "default"}
                },
                new Dictionary<string, dynamic>{
                    {"name", "route-consumed-fuel"},
                    {"api-name", "route-consumed-fuel"},
                    {"type", "decimal-event"},
                    {"decimal-places", 2},
                    {"dimension", "default"},
                }
            };

            var result = slicingdice.createColumn(columnData);
            System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
        }
    }
}
package main
import (
    "fmt"
    "github.com/SlicingDice/slicingdice-go/slicingdice"
)

func main() {
    keys := new(slicingdice.APIKey)
    keys.MasterKey = "MASTER_API_KEY"
    slicingdice := slicingdice.New(keys, 60)
    slicingdice.Test = true

    columnData := []interface{}{
        map[string]interface{}{
            "name": "latest-traveled-route",
            "api-name": "latest-traveled-route",
            "type": "string",
            "storage": "latest-value",
            "dimension": "default",
        },
        map[string]interface{}{
            "name": "route-consumed-fuel",
            "api-name": "route-consumed-fuel",
            "type": "decimal-event",
            "decimal-places": 2,
            "dimension": "default",
        },
    }

    fmt.Println(slicingdice.createColumn(columnData))
}

If you receive a success message, your columns are created and ready to have data inserted on them.


Inserting data

Now we're going to insert some data. You can use a POST request on the /insert endpoint, the POST /sql endpoint or use our SDK Clients to insert data. The data in the table below will be inserted in the default dimension using the following commands.

entity-id latest-traveled-route route-consumed-fuel
airplane-02 london-rome
  • 9103.2 - 2019-05-01T10:00:00Z
  • 8905.1 - 2019-05-01T11:00:00Z
  • 9410.3 - 2019-05-01T12:00:00Z
  • airplane-01 beijing-paris
  • 51230.1 - 2019-05-01T08:00:00Z
  • 57680.3 - 2019-05-01T09:00:00Z
  • 528345.7 - 2019-05-01T10:00:00Z
  • curl -X POST https://api.slicingdice.com/v1/insert \
        -H 'Authorization: PASTE_YOUR_PERSONAL_DEMO_API_KEY_HERE' \
        -H 'Content-Type: application/json' \
        -d '{
        "airplane-01": {
            "latest-traveled-route": "beijing-paris",
            "route-consumed-fuel": [
                {
                    "value": 51230.1,
                    "date": "2019-04-29T08:35:12Z"
                },
                {
                    "value": 57680.3,
                    "date": "2019-05-01T10:25:21Z"
                },
                {
                    "value": 528345.7,
                    "date": "2019-05-05T12:15:23Z"
                }
            ]
        },
        "airplane-02": {
            "latest-traveled-route": "london-rome",
            "route-consumed-fuel": [
                {
                    "value": 9103.2,
                    "date": "2019-04-26T09:35:12Z"
                },
                {
                    "value": 8905.1,
                    "date": "2019-04-30T11:25:25Z"
                },
                {
                    "value": 9410.3,
                    "date": "2019-05-05T13:15:27Z"
                }
            ]
        }
    }'
    curl -X POST https://api.slicingdice.com/v1/sql \
    	    -H 'Authorization: PASTE_YOUR_PERSONAL_DEMO_API_KEY_HERE' \
    	    -H 'Content-Type: application/sql' \
    	    -d 'INSERT INTO default ([entity-id], [latest-traveled-route], [route-consumed-fuel.0.value], [route-consumed-fuel.0.date], [route-consumed-fuel.1.value], [route-consumed-fuel.1.date], [route-consumed-fuel.2.value], [route-consumed-fuel.2.date]) VALUES ('airplane-02', 'londom-rome', 9103.2, '2019-04-26T09:35:12Z', 8905.1, '2019-04-30T11:25:25Z', 9410.3, '2019-05-05T13:15:27Z'); INSERT INTO default ([entity-id], [latest-traveled-route], [route-consumed-fuel.0.value], [route-consumed-fuel.0.date], [route-consumed-fuel.1.value], [route-consumed-fuel.1.date], [route-consumed-fuel.2.value], [route-consumed-fuel.2.date]) VALUES ('airplane-01', 'beijing-paris', 51230.1, '2019-04-29T08:35:12Z', 57680.3, '2019-05-01T10:25:21Z', 528345.7, '2019-05-05T12:15:23Z');'
    from pyslicer import SlicingDice
    slicingdice = SlicingDice(master_key='MASTER_API_KEY')
    
    insert_data = {
        "airplane-01": {
            "latest-traveled-route": "beijing-paris",
            "route-consumed-fuel": [
                {
                    "date": "2019-04-29T08:35:12Z",
                    "value": 51230.1
                },
                {
                    "date": "2019-05-01T10:25:21Z",
                    "value": 57680.3
                },
                {
                    "date": "2019-05-05T12:15:23Z",
                    "value": 528345.7
                }
            ]
        },
        "airplane-02": {
            "latest-traveled-route": "london-rome",
            "route-consumed-fuel": [
                {
                    "date": "2019-04-26T09:35:12Z",
                    "value": 9103.2
                },
                {
                    "date": "2019-04-30T11:25:25Z",
                    "value": 8905.1
                },
                {
                    "date": "2019-05-05T13:15:27Z",
                    "value": 9410.3
                }
            ]
        }
    }
    
    print(slicingdice.insert(insert_data))
    
    import com.slicingdice.jslicer.SlicingDice;
    import java.io.IOException;
    import org.json.JSONObject;
    import org.json.JSONArray;
    
    public class Example {
        public static void main(String[] args) throws IOException {
            SlicingDice slicingdice = new SlicingDice("MASTER_API_KEY");
    
            JSONObject insertData = new JSONObject()
            .put("airplane-01", new JSONObject()
                .put("latest-traveled-route", "beijing-paris")
                .put("route-consumed-fuel", new JSONArray()
                    .put(new JSONObject()
                        .put("date", "2019-04-29T08:35:12Z")
                        .put("value", 51230.1))
                    .put(new JSONObject()
                        .put("date", "2019-05-01T10:25:21Z")
                        .put("value", 57680.3))
                    .put(new JSONObject()
                        .put("date", "2019-05-05T12:15:23Z")
                        .put("value", 528345.7))))
            .put("airplane-02", new JSONObject()
                .put("latest-traveled-route", "london-rome")
                .put("route-consumed-fuel", new JSONArray()
                    .put(new JSONObject()
                        .put("date", "2019-04-26T09:35:12Z")
                        .put("value", 9103.2))
                    .put(new JSONObject()
                        .put("date", "2019-04-30T11:25:25Z")
                        .put("value", 8905.1))
                    .put(new JSONObject()
                        .put("date", "2019-05-05T13:15:27Z")
                        .put("value", 9410.3))));
    
            JSONObject result = slicingdice.insert(insertData);
            System.out.println(result.toString());
        }
    }
    require 'rbslicer'
    slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY')
    
    insert_data = {
        "airplane-01" => {
            "latest-traveled-route" => "beijing-paris",
            "route-consumed-fuel" => [
                {
                    "date" => "2019-04-29T08:35:12Z",
                    "value" => 51230.1
                },
                {
                    "date" => "2019-05-01T10:25:21Z",
                    "value" => 57680.3
                },
                {
                    "date" => "2019-05-05T12:15:23Z",
                    "value" => 528345.7
                }
            ]
        },
        "airplane-02" => {
            "latest-traveled-route" => "london-rome",
            "route-consumed-fuel" => [
                {
                    "date" => "2019-04-26T09:35:12Z",
                    "value" => 9103.2
                },
                {
                    "date" => "2019-04-30T11:25:25Z",
                    "value" => 8905.1
                },
                {
                    "date" => "2019-05-05T13:15:27Z",
                    "value" => 9410.3
                }
            ]
        }
    }
    
    puts slicingdice.insert(insert_data)
    
    const SlicingDice = require('slicerjs');
    
    const slicingdice = new SlicingDice({masterKey: 'MASTER_API_KEY'});
    
    const insertData = {
        "airplane-01": {
            "latest-traveled-route": "beijing-paris",
            "route-consumed-fuel": [
                {
                    "date": "2019-04-29T08:35:12Z",
                    "value": 51230.1
                },
                {
                    "date": "2019-05-01T10:25:21Z",
                    "value": 57680.3
                },
                {
                    "date": "2019-05-05T12:15:23Z",
                    "value": 528345.7
                }
            ]
        },
        "airplane-02": {
            "latest-traveled-route": "london-rome",
            "route-consumed-fuel": [
                {
                    "date": "2019-04-26T09:35:12Z",
                    "value": 9103.2
                },
                {
                    "date": "2019-04-30T11:25:25Z",
                    "value": 8905.1
                },
                {
                    "date": "2019-05-05T13:15:27Z",
                    "value": 9410.3
                }
            ]
        }
    };
    
    slicingdice.insert(insertData).then((resp) => {
        console.log(resp);
    }, (err) => {
        console.error(err);
    });
    <?php
    use Slicer\SlicingDice;
    $slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));
    
    $insertData = array(
        "airplane-01" => array(
            "latest-traveled-route" => "beijing-paris",
            "route-consumed-fuel" => array(
                array(
                    "date" => "2019-04-29T08:35:12Z",
                    "value" => 51230.1
                ),
                array(
                    "date" => "2019-05-01T10:25:21Z",
                    "value" => 57680.3
                ),
                array(
                    "date" => "2019-05-05T12:15:23Z",
                    "value" => 528345.7
                )
            )
        ),
        "airplane-02" => array(
            "latest-traveled-route" => "london-rome",
            "route-consumed-fuel" => array(
                array(
                    "date" => "2019-04-26T09:35:12Z",
                    "value" => 9103.2
                ),
                array(
                    "date" => "2019-04-30T11:25:25Z",
                    "value" => 8905.1
                ),
                array(
                    "date" => "2019-05-05T13:15:27Z",
                    "value" => 9410.3
                )
            )
        )
    );
    
    print_r($slicingdice->insert($insertData));
    ?>
    using System.Collections.Generic;
    using Slicer;
    using Newtonsoft.Json;
    
    namespace SlicerTester.Console
    {
        class Program
        {
            static void Main(string[] args)
            {
                var slicingdice = new SlicingDice(masterKey: "MASTER_API_KEY");
    
                var insertData = new Dictionary<string, dynamic>{
                    {"airplane-01", new Dictionary<string, dynamic>{
                        {"latest-traveled-route", "beijing-paris"},
                        {"route-consumed-fuel", new List<dynamic>{
                            new Dictionary<string, dynamic>{
                                {"date", "2019-04-29T08:35:12Z"},
                                {"value", 51230.1}
                            },
                            new Dictionary<string, dynamic>{
                                {"date", "2019-05-01T10:25:21Z"},
                                {"value", 57680.3}
                            },
                            new Dictionary<string, dynamic>{
                                {"date", "2019-05-05T12:15:23Z"},
                                {"value", 528345.7}
                            }
                        }}
                    }},
                    {"airplane-02", new Dictionary<string, dynamic>{
                        {"latest-traveled-route", "london-rome"},
                        {"route-consumed-fuel", new List<dynamic>{
                            new Dictionary<string, dynamic>{
                                {"date", "2019-04-26T09:35:12Z"},
                                {"value", 9103.2}
                            },
                            new Dictionary<string, dynamic>{
                                {"date", "2019-04-30T11:25:25Z"},
                                {"value", 8905.1}
                            },
                            new Dictionary<string, dynamic>{
                                {"date", "2019-05-05T13:15:27Z"},
                                {"value", 9410.3}
                            }
                        }}
                    }},
                };
    
                var result = slicingdice.Insert(insertData);
                System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
            }
        }
    }
    package main
    import (
        "fmt"
        "github.com/SlicingDice/slicingdice-go/slicingdice"
    )
    func main() {
        keys := new(slicingdice.APIKey)
        keys.MasterKey = "MASTER_API_KEY"
        slicingdice := slicingdice.New(keys, 60)
    
        insertData := map[string]interface{}{
            "airplane-01": map[string]interface{}{
                "latest-traveled-route": "beijing-paris",
                "route-consumed-fuel": []interface{}{
                    map[string]interface{}{
                        "date": "2019-04-29T08:35:12Z",
                        "value": 51230.1,
                    },
                    map[string]interface{}{
                        "date": "2019-05-01T10:25:21Z",
                        "value": 57680.3,
                    },
                    map[string]interface{}{
                        "date": "2019-05-05T12:15:23Z",
                        "value": 528345.7,
                    },
                },
            },
            "airplane-02": map[string]interface{}{
                "latest-traveled-route": "london-rome",
                "route-consumed-fuel": []interface{}{
                    map[string]interface{}{
                        "date": "2019-04-26T09:35:12Z",
                        "value": 9103.2,
                    },
                    map[string]interface{}{
                        "date": "2019-04-30T11:25:25Z",
                        "value": 8905.1,
                    },
                    map[string]interface{}{
                        "date": "2019-05-05T13:15:27Z",
                        "value": 9410.3,
                    },
                },
            },
        }
        fmt.Println(slicingdice.Insert(insertData))
    }

    Querying your data

    It's possible to do multiple queries using the API and you can also make queries using the SDK Clients or any SQL workbench you prefer. For this tutorial purpose, we'll make two different data analysis as you'll see below.

    • 1st analysis
    • On this first analysis, we'll answer the following question:
      What is the average airplane fuel consumption per air route?

      To answer the question, you'll make an aggregation query that is a powerful way to cross data in order to find insights and unexpected patterns.

      The query below will ask to SlicingDice to retrieve the Top 5 most common values of the latest-traveled-route column and then for each value get the average of the route-consumed-fuel column values that took place between 2019-05-05T23:59:59Z and 2019-04-05T00:00:00Z

      curl -X POST https://api.slicingdice.com/v1/query/aggregation \
          -H 'Authorization: PASTE_YOUR_PERSONAL_DEMO_API_KEY_HERE' \
          -H 'Content-Type: application/json' \
          -d '{
          "query": [
              {
                  "latest-traveled-route": 5
              },
              {
                  "route-consumed-fuel": "avg",
                  "between": [
                      "2019-05-05T23:59:59Z",
                      "2019-04-05T00:00:00Z"
                  ]
              }
          ]
      }'
      curl -X POST https://api.slicingdice.com/v1/sql \
      	    -H 'Authorization: PASTE_YOUR_PERSONAL_DEMO_API_KEY_HERE' \
      	    -H 'Content-Type: application/sql' \
      	    -d 'SELECT [latest-traveled-route], AVG([route-consumed-fuel.value]) FROM default WHERE [route-consumed-fuel.date] BETWEEN '2019-05-05T23:59:59Z' AND '2019-04-05T00:00:00Z' GROUP BY [latest-traveled-route] LIMIT 5;'
      from pyslicer import SlicingDice
      slicingdice = SlicingDice(master_key='MASTER_API_KEY')
      
      query_data = {
          "query": [
              {
                  "latest-traveled-route": 5
              },
              {
                  "route-consumed-fuel": "avg",
                  "between": [
                      "2019-05-05T23:59:59Z",
                      "2019-04-05T00:00:00Z"
                  ]
              }
          ]
      }
      
      print(slicingdice.aggregation(query_data))
      import com.slicingdice.jslicer.SlicingDice;
      import java.io.IOException;
      import org.json.JSONObject;
      import org.json.JSONArray;
      
      public class Example {
          public static void main(String[] args) throws IOException {
              SlicingDice slicingdice = new SlicingDice("MASTER_API_KEY");
      
              JSONObject queryData = new JSONObject()
              .put("query", new JSONArray()
                  .put(new JSONObject()
                      .put("latest-traveled-route", 5))
                  .put(new JSONObject()
                      .put("route-consumed-fuel", "avg")
                      .put("between", new JSONArray()
                          .put("2019-05-05T23:59:59Z")
                          .put("2019-04-05T00:00:00Z"))));
              JSONObject result = slicingdice.aggregation(queryData);
              System.out.println(result.toString());
          }
      }
      require 'rbslicer'
      slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY')
      
      query_data = {
          "query" => [
              {
                  "latest-traveled-route" => 5
              },
              {
                  "route-consumed-fuel" => "avg",
                  "between" => [
                      "2019-05-05T23:59:59Z",
                      "2019-04-05T00:00:00Z"
                  ]
              }
          ]
      }
      
      puts slicingdice.aggregation(query_data)
      const SlicingDice = require('slicerjs');
      
      const slicingdice = new SlicingDice({masterKey: 'MASTER_API_KEY'});
      
      const queryData = {
          "query": [
              {
                  "latest-traveled-route": 5
              },
              {
                  "route-consumed-fuel": "avg",
                  "between": [
                      "2019-05-05T23:59:59Z",
                      "2019-04-05T00:00:00Z"
                  ]
              }
          ]
      };
      
      slicingdice.aggregation(queryData).then((resp) => {
          console.log(resp);
      }, (err) => {
          console.error(err);
      });
       "MASTER_API_KEY"));
      
      $queryData = array(
          "query" => array(
              array(
                  "latest-traveled-route" => 5
              ),
              array(
                  "route-consumed-fuel" => "avg",
                  "between" => array(
                      "2019-05-05T23:59:59Z",
                      "2019-04-05T00:00:00Z"
                  )
              )
          )
      );
      
      print_r($slicingdice->aggregation($queryData));
      ?>
      using System.Collections.Generic;
      using Slicer;
      using Newtonsoft.Json;
      
      namespace SlicerTester.Console
      {
          class Program
          {
              static void Main(string[] args)
              {
                  var slicingdice = new SlicingDice(masterKey: "MASTER_API_KEY");
      
                  var queryData = new Dictionary<string, dynamic>{
                      {"query", new List<dynamic>{
                          new Dictionary<string, dynamic>{
                              {"latest-traveled-route", 5}
                          },
                          new Dictionary<string, dynamic>{
                              {"route-consumed-fuel", "avg"},
                              {"between", new List<dynamic>{
                                  "2019-05-05T23:59:59Z",
                                  "2019-04-05T00:00:00Z"
                              }}
                          }
                      }}
                  };
      
                  var result = slicingdice.Aggregation(queryData);
                  System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
              }
          }
      }
      package main
      import (
          "fmt"
          "github.com/SlicingDice/slicingdice-go/slicingdice"
      )
      func main() {
          keys := new(slicingdice.APIKey)
          keys.MasterKey = "MASTER_API_KEY"
          slicingdice := slicingdice.New(keys, 60)
      
          queryData := map[string]interface{}{
              "query": []interface{}{
                  map[string]interface{}{
                      "latest-traveled-route": 5,
                  },
                  map[string]interface{}{
                      "route-consumed-fuel": "avg",
                      "between": []interface{}{
                          "2019-05-05T23:59:59Z",
                          "2019-04-05T00:00:00Z",
                      },
                  },
              },
          }
      
          fmt.Println(slicingdice.Aggregation(queryData))
      }

      After running this query, you should be able to see the following result.

      {
         "status":"success",
         "result":{
            "latest-traveled-route":[
               {
                  "route-consumed-fuel":{
                     "avg":212418.7
                  },
                  "value":"beijing-paris",
                  "quantity":1
               },
               {
                  "route-consumed-fuel":{
                     "avg":9139.53333
                  },
                  "value":"london-rome",
                  "quantity":1
               }
            ]
         },
         "took":0.164
      }

      As you can see, the results are basically showing the average fuel consumption per airplane route.

    • 2nd analysis
    • Now another question we'll make is the following one:
      How many airplanes consumed at least 10.000 liters in one travel in April 2019?

      We can answer this question using the Count Entities query that are useful to know how many unique entities (in this case, servers) you have that satisfies some set of conditions.

      In this case, we want to know how many unique airplanes (entities) have consumed at least 10.000 liters of fuel in one row between 2019-04-01 and 2019-05-02 We will also insert a name for this query, calling it as number-of-high-fuel-usage-airplanes.

      curl -X POST https://api.slicingdice.com/v1/query/count/entity \
          -H 'Authorization: PASTE_YOUR_PERSONAL_DEMO_API_KEY_HERE' \
          -H 'Content-Type: application/json' \
          -d '{
          "query": [
              {
                  "route-consumed-fuel": {
                      "gt": 10000,
                      "between": [
                          "2019-04-01T00:00:00Z",
                          "2019-04-30T23:59:59Z"
                      ]
                  }
              }
          ],
          "query-name": "number-of-high-fuel-usage-airplanes"
      }'
      curl -X POST https://api.slicingdice.com/v1/sql \
      	    -H 'Authorization: PASTE_YOUR_PERSONAL_DEMO_API_KEY_HERE' \
      	    -H 'Content-Type: application/sql' \
      	    -d 'SELECT COUNT([entity-id]) FROM default WHERE [route-consumed-fuel.value] > 10000 AND [route-consumed-fuel.date] BETWEEN '2019-04-01T00:00:00Z' AND '2019-04-30T23:59:59Z';'
      from pyslicer import SlicingDice
      slicingdice = SlicingDice(master_key='MASTER_API_KEY')
      
      query_data = {
          "query": [
              [
              {
                  "route-consumed-fuel": {
                      "gt": 10000,
                      "between": [
                          "2019-04-01T00:00:00Z",
                          "2019-04-30T23:59:59Z"
                      ]
                  }
              }
          ],
          "query-name": "number-of-high-fuel-usage-airplanes"
      }
      ]
      
      print(slicingdice.count_entity(query_data))
      import com.slicingdice.jslicer.SlicingDice;
      import java.io.IOException;
      import org.json.JSONObject;
      import org.json.JSONArray;
      
      public class Example {
          public static void main(String[] args) throws IOException {
              SlicingDice slicingdice = new SlicingDice("MASTER_API_KEY");
      
              JSONObject queryData = new JSONObject()
              .put("query", new JSONArray()
                  .put(new JSONObject()
                      .put("route-consumed-fuel", new JSONObject()
                          .put("gt", 10000)
                          .put("between", new JSONArray()
                              .put("2019-04-01T00:00:00Z")
                              .put("2019-04-30T23:59:59Z")))))
              .put("query-name", "number-of-high-fuel-usage-airplanes");
              JSONObject result = slicingdice.countEntity(queryData);
              System.out.println(result.toString());
          }
      }
      require 'rbslicer'
      slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY')
      
      query_data = {
          "query" => [
              {
                  "route-consumed-fuel" => {
                      "gt" => 10000,
                      "between" => [
                          "2019-04-01T00:00:00Z",
                          "2019-04-30T23:59:59Z"
                      ]
                  }
              }
          ],
          "query-name" => "number-of-high-fuel-usage-airplanes"
      }
      
      puts slicingdice.count_entity(query_data)
      const SlicingDice = require('slicerjs');
      
      const slicingdice = new SlicingDice({masterKey: 'MASTER_API_KEY'});
      
      const queryData = {
          "query": [
              {
                  "route-consumed-fuel": {
                      "gt": 10000,
                      "between": [
                          "2019-04-01T00:00:00Z",
                          "2019-04-30T23:59:59Z"
                      ]
                  }
              }
          ],
          "query-name": "number-of-high-fuel-usage-airplanes"
      };
      
      slicingdice.countEntity(queryData).then((resp) => {
          console.log(resp);
      }, (err) => {
          console.error(err);
      });
      <?php
      use Slicer\SlicingDice;
      $slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));
      
      $queryData = array(
          "query" => array(
              array(
                  "route-consumed-fuel" => array(
                      "gt" => 10000,
                      "between" => array(
                          "2019-04-01T00:00:00Z",
                          "2019-04-30T23:59:59Z"
                      )
                  )
              )
          ),
          "query-name" => "number-of-high-fuel-usage-airplanes"
      );
      
      print_r($slicingdice->countEntity($queryData));
      ?>
      using System.Collections.Generic;
      using Slicer;
      using Newtonsoft.Json;
      
      namespace SlicerTester.Console
      {
          class Program
          {
              static void Main(string[] args)
              {
                  var slicingdice = new SlicingDice(masterKey: "MASTER_API_KEY");
      
                  var queryData = new Dictionary<string, dynamic>{
                      {"query", new List<dynamic>{
                          new Dictionary<string, dynamic>{
                              {"route-consumed-fuel", new Dictionary<string, dynamic>{
                                  {"gt", 10000},
                                  {"between", new List<dynamic>{
                                      "2019-04-01T00:00:00Z",
                                      "2019-04-30T23:59:59Z"
                                  }}
                              }}
                          }
                      }},
                      {"query-name", "number-of-high-fuel-usage-airplanes"}
                  };
      
                  var result = slicingdice.CountEntity(queryData);
                  System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
              }
          }
      }
      package main
      import (
          "fmt"
          "github.com/SlicingDice/slicingdice-go/slicingdice"
      )
      func main() {
          keys := new(slicingdice.APIKey)
          keys.MasterKey = "MASTER_API_KEY"
          slicingdice := slicingdice.New(keys, 60)
      
          queryData := map[string]interface{}{
              "query": []interface{}{
                  map[string]interface{}{
                      "route-consumed-fuel": map[string]interface{}{
                          "gt": 10000,
                          "between": []interface{}{
                              "2019-04-01T00:00:00Z",
                              "2019-04-30T23:59:59Z",
                          },
                      },
                  },
              },
              "query-name": "number-of-high-fuel-usage-airplanes",
          }
      
          fmt.Println(slicingdice.CountEntity(queryData))
      }
      

      After run this query, you'll see the following result.

      {
        "status": "success",
        "result": {
          "number-of-high-fuel-usage-airplanes": 1
        },
        "took": 0.122
      }

      As you can see above, the results shows that 2 servers presented some instability in the last 24 hours. But which of them? Check the next analysis to find out.


    Visualizing your data

    You can use the Data Visualization tool to create charts to visualize your data. On this section, you'll learn how to create one to visualize the answer for the following question:

    What are the usage of fuel by Airplane 01 each registered day? And what is the trend?

    The answer for this question would look like the following chart. Below you'll learn how to build it.


    Creating the dataset for visualization

    Before creating a chart to visualize your data, you need to create a dataset. Watch the following quick video or read the written instructions below.

    Go to the Data Visualization Module, find the database name and click on Browse datasets. Click on Write SQL query and insert the following code to build a visualization dataset with all data you have stored.

    SELECT * FROM default;

    After that, click on Run. You'll see that the module returned the fields and data you have. Click on Done, name your dataset, click on Rename, then click on Done again to save your dataset.


    Creating the chart

    After the dataset is created, you can now create your chart. Watch the following time-lapse video to see how the chart at the start of this section was made or if you prefer read how to create your own.

    To create a chart, in the Dataset Browser, click on the dataset you just created and then select the option Create saved chart. The chart designer will open. You should use the following parameters:

    • In the Chart Type, select Time series
    • In the Value axis, select route-consumed-fuel value and select the Sum measure.
    • Still in the Value Axis, click on Add breakdown dimension and select entity-id.
    • In the Filters section, select the entity-id, select the airplane-01 then click on Apply.
    • In the Format menu, in the Chart section, go to Markers, switch on the visible button, and select the size as 10px.
    • Go back to the Chart section, now go to the Abbreviate thousands and millions section. Deactivate it.
    • Go back to the Chart section, switch to Elements section.
    • Click on the Title, and replace the text to Fuel consumed by Airplane 01.
    • Go back to the Elements section, then click on Labels. Enable it.
    • Go back to the Elements section, then click on Trendline. Click on Linear option.
    • Go back to the Elements section, then click on Series. Click on the airplane-01 option. Replace the text to Airplane 01.
    • Click on the Series color option and select a color. In this example, its orange.
    • Click on the Done button.
    • Click on the floppy disk icon, insert a name for the saved chart and click OK.