Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Paste code macro
languagehttp
themeSunburst
GET https://${CloudVendor}.${CountryCode}.machlake.com/v1/lakes/${lake_id}/values/pivoted
Content-Type: application/json; charset=utf8
x-api-key: {API Key}

...

Optional

Type

Description

Example

type

string

select type

&type=pivot

tag_name

string

tag name with , separator

&tag_name=tag1,tag2,tag3

calc_mode

string

min,max,cnt,avg,sum

&calc_mode=min (default : avg)

date_format

string

date format of select time
or
timestamp type ("SECOND", "MILLISECOND", "MICROSECOND", "NANOSECOND")

&date_format=YYYY-MM-DD HH24:MI:SS
or
&date_format=MILLISECOND

(default : YYYY-MM-DD HH24:MI:SS)

start_time

string

start time of select (MUST be less than end_time!)

type 1 : time string format

  • start_time=2018-01-16 14:40:05 000
    or

  • start_time=2018-01-16 14:40:05.000

type 2 : timestamp (second or millisecond)

  • start_time=1618813188
    or

  • start_time=1618813188123

&start_time=2018-01-16 14:40:05 000
or
&start_time=2018-01-16 14:40:05.000
or
&start_time=1618813188
or
&start_time=1618813188123

  • datetime of parameter supports up to millisecond.

end_time

string

end time of select  (MUST be more than start_time!)

  • same as start_time

same as start_time

interval_type

string

sec,min,hour,day (or s,m,h,d)

&interval_type=hour (default : sec)

interval_value

int

duration value

&interval_value=10 (default : 1)

limit

int

count of display

&limit=1000 (default : Restricted by 'lake tier' by lake tier)

offset

int

count of skip

&offset=500

direction

int

ascend or descent by time

&direction=0
0 : ascend (default)
1 : descend

value_return_form

int

result set format

Optimized for various chart libraries and configured to return

0 : separate standard (default)

1 : merged standard

Request Example

Paste code macro
languagehttp
themeSunburst
GET https://aws1.us.machlake.com/v1/lakes/xbacd1234/values/pivoted?type=pivot&tag_name=tag_01,tag_02tag01&calc_mode=avg&date_format=YYYY-MM-DD HH24:MI:SS&start_time=2021-06-16 11:35:00&end_time=2021-07-06 12:12:28&interval_type=min&limit=1000&value_return_form=0
Content-Type: application/json; charset=utf8
x-api-key: {API Key}

...

Paste code macro
languagejson
themeSunburst
Status 200

{
// return format = 0
{"success": true,
    "statusreason": "success",
    "data": {
        "calc_modecolumns": "AVG", [
            {
  "columns": [             {"name": "TIME",
"type": 5, "length": 4096},             {"name": "tag_01", "type": 205,
"length": 17},             {"name": "tag_02", "type": 20, "length": 17}4096
        ],    },
    "samples": [       {
     {                 "data"name": ["tag01",
                "type": 20,
  {              "length": 17
         "TIME": "2021-06-16 11:36:00", }
        ],
        "rows": [
    "tag_01": 1515.4806,       [
                "2023-01-03 "tag_02": 1524.368410:12:00",
                1625.333
    },        ],
            {[
                        "TIME": "2021-06-16 11:37:00"2023-01-03 10:12:05",
                1622.5
       "tag_01": 1513.4624,    ]
        ]
    }
}

Sample Code

Expand
titlewindow(batch)

github

Code Block
chcp 65001 
:: Text 
"tag_02": 1490.107 }, { "TIME": "2021-06-17 15:42:00", "tag_01": 1499.028979191633, "tag_02": null }, { "TIME": "2021-06-17 15:43:00",
Encoding to UTF-8 in CMD
:: Example For Select Pivoted Data for tag API by using curl in window script
:: written by yeony kim

set API_KEY=YOUR_API_KEY
set LAKE_ID=YOUR_LAKE_ID
set CLOUD_VENDOR=YOUR_CLOUD_VENDOR
set CLOUD_REGION=YOUR_CLOUD_REGION

set CONTENT_HEADER="Content-Type: application/json"
set API_HEADER="x-api-key: %API_KEY%"
set URL="https://%CLOUD_VENDOR%.%CLOUD_REGION%.machlake.com/lakes/%LAKE_ID%/values/pivoted"

set SELECT_TYPE=pivot

:: ------------------------------------------------------------------------------------------------- ::

:: CASE - Pivoted DATA GET with date format YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn
set TAG_NAME=sensor1,sensor2
set CALC_MODE=min
set DATE_FORMAT=YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn
set START_TIME=2021-01-06 17:00:00 000:000:000
set END_TIME=2021-01-06 21:00:00 000:000:000

curl -k -G %URL% -H %CONTENT_HEADER% -H %API_HEADER% \
    --data-urlencode "type=%SELECT_TYPE%" \
    --data-urlencode "tag_name=%TAG_NAME%" \
    --data-urlencode "calc_mode=%CALC_MODE%" \
    --data-urlencode "start_time=%START_TIME%" \
    --data-urlencode "end_time=%END_TIME%" \
    --data-urlencode "date_format=%DATE_FORMAT%"

:: Return Format
:: {
::     "success": true,
::     "reason": "success",
::     "data":{
::         "columns":[
::             
"tag_01": 1470.2225841476657,
{"name":"TIME","type":5,"length":4096},
::             
"tag_02": null
{"name":"sensor1","type":20,"length":17},
::             {"name":"sensor2","type":20,"length":17}
::       
},
  ],
::         "rows":[
::        
{
     ["2021-01-06 17:00:00 000:000:000",1,1],
::             
"TIME": "
["2021-01-06
-
 17:00:01 
15
000:
44
000:
00"
000",null,1.5],
::             ["2021-01-06 17:00:02 000:000:000",null,2],
::         
"tag_01": 1487.0528,
    ["2021-01-06 17:00:03 000:000:000",null,1],
::             ["2021-01-06 17:00:04 000:000:000",null,1.5],
::        
"tag_02":
 
1508.5176
    ["2021-01-06 17:00:05 000:000:000",null,2],
::             
},
["2021-01-06 18:00:00 000:000:000",2,2],
::             ["2021-01-06 20:00:04 000:000:000",2,2],
::    
{
         ["2021-01-06 20:00:05 000:000:000",2.2.5],
::             
"TIME
["
: "
2021-
07
01-06 
12:12:00",
20:00:06 000:000:000",2,2]
::         ]
::     
"tag_01": 1887.5, "tag_02": 1628 } ] } ] } } // return format = 1 { "status": "success", "data": { "calc_mode": "AVG", "columns": [ {"name": "TIME", "type": 5, "length": 4096}, {"name": "tag_01", "type": 20, "length": 17}, {"name": "tag_02", "type": 20, "length": 17} ], "samples": [ {
}
:: }
Expand
titlelinux(shell)

github

Code Block
languagebash
# Text Encoding to UTF-8 in CMD
# Example For Select Pivoted Data for tag API by using curl in ubuntu

LAKE_ID=$YOUR_LAKE_ID
API_KEY=$YOUR_API_KEY
CLOUD_VENDOR=$YOUR_CLOUD_VENDOR
CLOUD_REGION=$YOUR_CLOUD_REGION

CONTENT_HEADER=Content-Type:application/json
API_HEADER=x-api-key:$API_KEY
URL=https://${CLOUD_VENDOR}.${CLOUD_REGION}.machlake.com/v1/lakes/${LAKE_ID}/values

# ------------------------------------------------------------------------------------------------- #

# CASE - Pivoted DATA GET with date format YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn
SELECT_TYPE=pivot
TAG_NAME=sensor1,sensor2
CALC_MODE=min
DATE_FORMAT="YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn"
START_TIME="2021-01-06 17:00:00 000:000:000"
END_TIME="2021-01-06 21:00:00 000:000:000"

curl -k -G $URL -H $CONTENT_HEADER -H $API_HEADER \
    --data-urlencode "type=$SELECT_TYPE" \
    --data-urlencode "tag_name=$TAG_NAME" \
    --data-urlencode "calc_mode=$CALC_MODE" \
    --data-urlencode "start_time=$START_TIME" \
    --data-urlencode "end_time=$END_TIME" \
    --data-urlencode "date_format=$DATE_FORMAT"

# Return Format
# {
#     "success": true,
#     "reason": "success",
#     "data":{
#         "columns":[
#             
"data": {
{"name":"TIME","type":5,"length":4096},
#             {"name":"sensor1","type":20,"length":17},
#       
"TIME":
  
[
    {"name":"sensor2","type":20,"length":17}
#         ],
#         
"2021-06-16 11:36:00",
"rows":[
#             
["2021-01-06
-16
 
11
17:
37
00:00 000:000:000",1,1],
#             
["2021-01-06
-
 17:00:01 
15
000:
42
000:
00
000",null,1.5],
#             
["2021-01-06
-
 17:00:02 
15
000:
43
000:
00
000",null,2],
#             
["2021-01-06
-
 17:00:03 
15
000:
44
000:
00
000",null,1],
#             
["2021-01-06 17:00:04 000:000:000",null,1.5],
#             ["2021-
07
01-06 
12:12:00"
17:00:05 000:000:000",null,2],
#             ["2021-01-06 
18:00:00 000:000:000",2,2],
#             
"tag_01": [
["2021-01-06 20:00:04 000:000:000",2,2],
#             ["2021-01-06 20:00:05 000:000:000",2.2.5],
#         
1515.4806,
    ["2021-01-06 20:00:06 000:000:000",2,2]
#         ]
#     }
# }
1513.4624,

1499.028979191633, 1470.2225841476657, 1487.0528, 1887.5 ], "tag_02": [ 1524.3684, 1490.107, null, null, 1508.5176, 1628 ] } } ] } }

Sample Code

Expand
titlewindow(batch)

github

Code Block
chcp 65001 
:: Text Encoding to UTF-8 in CMD
:: Example For Select Pivoted Data for tag API by using curl in window script
:: written by yeony kim

set API_KEY=YOUR_API_TOKEN

set CONTENT_HEADER="Content-Type: application/json"
set API_HEADER="x-api-key: %API_KEY%"
set LAKE_ID=YOUR_LAKE_ID
set URL="https://%LAKE_ID%.machlake.com/lakes/values/pivoted"

:: ------------------------------------------------------------------------------------------------- ::

:: CASE - Pivoted DATA GET with date format YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn
set TAG_NAME=sensor1,sensor2
set CALC_MODE=min
set DATE_FORMAT=YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn
set START_TIME=2021-01-06 17:00:00 000:000:000
set END_TIME=2021-01-06 21:00:00 000:000:000

curl -k -G %URL% -H %CONTENT_HEADER% -H %API_HEADER% --data-urlencode "tag_name=%TAG_NAME%" --data-urlencode "calc_mode=%CALC_MODE%" --data-urlencode "start_time=%START_TIME%" --data-urlencode "end_time=%END_TIME%" --data-urlencode "date_format=%DATE_FORMAT%"

:: Return Format
:: {"data":{"calc_mode":"MIN","columns":[{"name":"TIME","type":5,"length":4096},{"name":"sensor1","type":20,"length":17},{"name":"sensor2","type":20,"length":17}],"samples":[{"data":[{"TIME":"2021-01-06 17:00:00 000:000:000","sensor1":1,"sensor2":1},{"TIME":"2021-01-06 17:00:01 000:000:000","sensor1":null,"sensor2":1.5},{"TIME":"2021-01-06 17:00:02 000:000:000","sensor1":null,"sensor2":2},{"TIME":"2021-01-06 17:00:03 000:000:000","sensor1":null,"sensor2":1},{"TIME":"2021-01-06 17:00:04 000:000:000","sensor1":null,"sensor2":1.5},{"TIME":"2021-01-06 17:00:05 000:000:000","sensor1":null,"sensor2":2},{"TIME":"2021-01-06 18:00:00 000:000:000","sensor1":2,"sensor2":2},{"TIME":"2021-01-06 20:00:04 000:000:000","sensor1":2,"sensor2":2},{"TIME":"2021-01-06 20:00:05 000:000:000","sensor1":2.5,"sensor2":2.5},{"TIME":"2021-01-06 20:00:06 000:000:000","sensor1":2,"sensor2":2}]}]},"status":"success"}

:: ------------------------------------------------------------------------------------------------- ::

:: CASE - Pivoted DATA GET with another value form
set VALUE_RETURN_FORM=1
set CALC_MODE=cnt

curl -k -G %URL% -H %CONTENT_HEADER% -H %API_HEADER% --data-urlencode "tag_name=%TAG_NAME%" --data-urlencode "calc_mode=%CALC_MODE%" --data-urlencode "start_time=%START_TIME%" --data-urlencode "end_time=%END_TIME%" --data-urlencode "date_format=%DATE_FORMAT%" --data-urlencode "value_return_form=%VALUE_RETURN_FORM%"

:: Return Format
:: {"data":{"calc_mode":"COUNT","columns":[{"name":"TIME","type":5,"length":4096},{"name":"sensor1","type":12,"length":20},{"name":"sensor2","type":12,"length":20}],"samples":[{"data":{"TIME":["2021-01-06 17:00:00 000:000:000","2021-01-06 17:00:01 000:000:000","2021-01-06 17:00:02 000:000:000","2021-01-06 17:00:03 000:000:000","2021-01-06 17:00:04 000:000:000","2021-01-06 17:00:05 000:000:000","2021-01-06 18:00:00 000:000:000","2021-01-06 20:00:04 000:000:000","2021-01-06 20:00:05 000:000:000","2021-01-06 20:00:06 000:000:000"],"sensor1":[9,0,0,0,0,0,3,1,1,1],"sensor2":[1,1,1,1,1,1,3,1,1,1]}}]},"status":"success"}

:: ------------------------------------------------------------------------------------------------- ::
Expand
titlelinux(shell)

github

Code Block
# Text Encoding to UTF-8 in CMD
# Example For Select Pivoted Data for tag API by using curl in ubuntu
# written by yeony kim

API_KEY=YOUR_API_TOKEN

CONTENT_HEADER=Content-Type:application/json
API_HEADER=x-api-key:$API_KEY
LAKE_ID=YOUR_LAKE_ID
URL=https://$LAKE_ID.machlake.com/lakes/values/pivoted

# ------------------------------------------------------------------------------------------------- #

# CASE - Pivoted DATA GET with date format YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn
TAG_NAME=sensor1,sensor2
CALC_MODE=min
DATE_FORMAT="YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn"
START_TIME="2021-01-06 17:00:00 000:000:000"
END_TIME="2021-01-06 21:00:00 000:000:000"

curl -k -G $URL -H $CONTENT_HEADER -H $API_HEADER --data-urlencode "tag_name=$TAG_NAME" --data-urlencode "calc_mode=$CALC_MODE" --data-urlencode "start_time=$START_TIME" --data-urlencode "end_time=$END_TIME" --data-urlencode "date_format=$DATE_FORMAT"

# Return Format
# {"data":{"calc_mode":"MIN","columns":[{"name":"TIME","type":5,"length":4096},{"name":"sensor1","type":20,"length":17},{"name":"sensor2","type":20,"length":17}],"samples":[{"data":[{"TIME":"2021-01-06 17:00:00 000:000:000","sensor1":1,"sensor2":1},{"TIME":"2021-01-06 17:00:01 000:000:000","sensor1":null,"sensor2":1.5},{"TIME":"2021-01-06 17:00:02 000:000:000","sensor1":null,"sensor2":2},{"TIME":"2021-01-06 17:00:03 000:000:000","sensor1":null,"sensor2":1},{"TIME":"2021-01-06 17:00:04 000:000:000","sensor1":null,"sensor2":1.5},{"TIME":"2021-01-06 17:00:05 000:000:000","sensor1":null,"sensor2":2},{"TIME":"2021-01-06 18:00:00 000:000:000","sensor1":2,"sensor2":2},{"TIME":"2021-01-06 20:00:04 000:000:000","sensor1":2,"sensor2":2},{"TIME":"2021-01-06 20:00:05 000:000:000","sensor1":2.5,"sensor2":2.5},{"TIME":"2021-01-06 20:00:06 000:000:000","sensor1":2,"sensor2":2}]}]},"status":"success"}

# ------------------------------------------------------------------------------------------------- #

# CASE - Pivoted DATA GET with another value form
VALUE_RETURN_FORM=1
CALC_MODE=cnt

curl -k -G $URL -H $CONTENT_HEADER -H $API_HEADER --data-urlencode "tag_name=$TAG_NAME" --data-urlencode "calc_mode=$CALC_MODE" --data-urlencode "start_time=$START_TIME" --data-urlencode "end_time=$END_TIME" --data-urlencode "date_format=$DATE_FORMAT" --data-urlencode "value_return_form=$VALUE_RETURN_FORM"

# Return Format
# {"data":{"calc_mode":"COUNT","columns":[{"name":"TIME","type":5,"length":4096},{"name":"sensor1","type":12,"length":20},{"name":"sensor2","type":12,"length":20}],"samples":[{"data":{"TIME":["2021-01-06 17:00:00 000:000:000","2021-01-06 17:00:01 000:000:000","2021-01-06 17:00:02 000:000:000","2021-01-06 17:00:03 000:000:000","2021-01-06 17:00:04 000:000:000","2021-01-06 17:00:05 000:000:000","2021-01-06 18:00:00 000:000:000","2021-01-06 20:00:04 000:000:000","2021-01-06 20:00:05 000:000:000","2021-01-06 20:00:06 000:000:000"],"sensor1":[9,0,0,0,0,0,3,1,1,1],"sensor2":[1,1,1,1,1,1,3,1,1,1]}}]},"status":"success"}

# ------------------------------------------------------------------------------------------------- #
Expand
titlejavascript

github

Code Block
languagejs
// Example For Select Pivoted Data for tag API by using request in node js
// written by yeony kim
// sensor1, sensor2 is applied in lake

process.env.NODE_TLS_REJECT_UNAUTHORIZED ="0";

const express = require('express');
const app = express();
const API_KEY ="YOUR_API_TOKEN";
const LAKE_ID ="YOUR_LAKE_ID"
const URL ="https://" + LAKE_ID +".machlake.com/lakes/values/pivoted";

// CASE - Pivoted DATA GET with date format YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn

app.get(
    '/select_pivoted_date_with_nano_time_date_string', function(req, res) {
        var request = require('request');

        const QueryParams = new URLSearchParams()
        
        QueryParams.set('tag_name', 'sensor1,sensor2')
        QueryParams.set('calc_mode', 'min')
        QueryParams.set('date_format', 'YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn')
        QueryParams.set('start_time', '2021-01-06 17:00:00 000:000:000')
        QueryParams.set('end_time', '2021-01-06 21:00:00 000:000:000')

        var option = {
            url: URL + "?" + QueryParams.toString(),
            headers: {
                'Content-Type': 'application/json',
                'x-api-key': API_KEY
            },
        };
        request.get( option, function(error, response, body) {
            if (!error) {
                res.writeHead(200);
                res.end(body);
                console.log(body) // {"data":{"calc_mode":"MIN","columns":[{"name":"TIME","type":5,"length":4096},{"name":"sensor1","type":20,"length":17},{"name":"sensor2","type":20,"length":17}],"samples":[{"data":[{"TIME":"2021-01-06 17:00:00 000:000:000","sensor1":1,"sensor2":1},{"TIME":"2021-01-06 17:00:01 000:000:000","sensor1":null,"sensor2":1.5},{"TIME":"2021-01-06 17:00:02 000:000:000","sensor1":null,"sensor2":2},{"TIME":"2021-01-06 17:00:03 000:000:000","sensor1":null,"sensor2":1},{"TIME":"2021-01-06 17:00:04 000:000:000","sensor1":null,"sensor2":1.5},{"TIME":"2021-01-06 17:00:05 000:000:000","sensor1":null,"sensor2":2},{"TIME":"2021-01-06 18:00:00 000:000:000","sensor1":2,"sensor2":2},{"TIME":"2021-01-06 20:00:04 000:000:000","sensor1":2,"sensor2":2},{"TIME":"2021-01-06 20:00:05 000:000:000","sensor1":2.5,"sensor2":2.5},{"TIME":"2021-01-06 20:00:06 000:000:000","sensor1":2,"sensor2":2}]}]},"status":"success"}
            } else {
                console.log(error)
            }
        })
    }
)

// CASE - Pivoted DATA GET with another value form

app.get(
    '/select_pivoted_date_with_nano_time_date_string_another_form', function(req, res) {
        var request = require('request');

        const QueryParams = new URLSearchParams()
        
        QueryParams.set('tag_name', 'sensor1,sensor2')
        QueryParams.set('calc_mode', 'cnt')
        QueryParams.set('date_format', '# ------------------------------------------------------------------------------------------------- #
Expand
titlejavascript

github

Code Block
languagejs
// Example For Select Pivoted Data for tag API by using request in node js
// written by yeony kim
// sensor1, sensor2 is applied in lake

// process.env.NODE_TLS_REJECT_UNAUTHORIZED ="0";

const API_KEY ="YOUR_API_TOKEN";
const LAKE_ID ="YOUR_LAKE_ID"
const CLOUD_VENDOR="CLOUD_VENDOR";
const CLOUD_REGION="CLOUD_REGION";
const URL = `https://${CLOUD_VENDOR}.${CLOUD_REGION}.machlake.com/v1/lakes/${LAKE_ID}/values`;

var request = require('request');

const TAG_NAME = "sensor1,sensor2";
const SELECT_TYPE="pivot";


/* ------------------------------------------------------------------------------------------------- */

// CASE - Pivoted DATA GET with date format YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn')

request.get({
    url:  QueryParams.set('start_time', '2021-01-06 17:00:00 000:000:000')
  URL, 
    qs: {
     QueryParams.set('end_time', '2021-01-06 21:00:00 000:000:000') type: SELECT_TYPE,
        QueryParams.set('value_return_form', 1)tag_name: TAG_NAME,
        calc_mode: 'min',
var option = {     date_format: 'YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn',
      url: URL + "?" + QueryParams.toString()start_time: '2021-01-06 17:00:00 000:000:000',
        end_time: '2021-01-06 21:00:00 000:000:000'
 headers: {  },
    headers: {
        'Contentx-api-Typekey': 'application/json',API_KEY
    }}, 
    function(error, response, body) {
  'x-api-key': API_KEY     console.log(body);
       }, // Return Format
     };    // {
   request.get( option, function(error, response, body) {//     "success": true,
      if (!error) { //     "reason": "success",
        //  res.writeHead(200);   "data":{
        //     res.end(body);    "columns":[
        //    console.log(body) // {"data":{"calc_mode":"COUNT","columns":[        {"name":"TIME","type":5,"length":4096},
        //             {"name":"sensor1","type":1220,"length":2017},
        //             {"name":"sensor2","type":1220,"length":20}],"samples":[{"data":{"TIME":["2021-01-06 17:00:00 000:000:000","2021-01-06 17:00:01 000:000:000","2021-01-06 17:00:02 000:000:000",17}
        //         ],
        //         "rows":[
        //             ["2021-01-06 17:00:0300 000:000:000","2021-01-06 17:00:04 000:000:000","2021-01-06 17:00:05 000:000:000","2021-01-06 18:00:00 000:000:000","2021-01-06 20:00:04 000:000:000","1,1],
        //             ["2021-01-06 2017:00:0501 000:000:000",null,1.5],
        //             ["2021-01-06 2017:00:0602 000:000:000"],"sensor1":[9,0,0,0,0,0,3,1,1,1],"sensor2":[1,1,1,1,1,1,3,1,1,1]}}]},"status":"success"}:000",null,2],
        //              } else {["2021-01-06 17:00:03 000:000:000",null,1],
        //         console.log(error)    ["2021-01-06 17:00:04 000:000:000",null,1.5],
      }  //       })     }
)

app.listen(8888, function() { ["2021-01-06 17:00:05 000:000:000",null,2],
      console.log('http://127.0.0.1:8888/select_pivoted_date_with_nano_time_date_string is result for select pivoted data with nano date time string')
    console.log('http://127.0.0.1:8888/select_pivoted_date_with_nano_time_date_string_another_form is result for select pivoted data with nano date time string with value return form = 1 and calc_mode = cnt')
})
Expand
titlepython

github

Code Block
languagepy
"""
Example For Select Pivoted Data for tag API by using request in python
written by yeony kim
sensor1, sensor2 is applied in lake
"""

import requests

API_KEY = "YOUR_API_TOKEN"
LAKE_ID = "YOUR_LAKE_ID"
URL = f"https://{LAKE_ID}.machlake.com/lakes/values/pivoted"

headers = {
    'Content-Type': 'application/json',
    'x-api-key': API_KEY
}

# CASE - Pivoted DATA GET with date format YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn

params = {
    'tag_name': 'sensor1',
    'calc_mode': 'min',
    'date_format': 'YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn',
    'start_time': '2021-01-06 17:00:00 000:000:000',
    'end_time': '2021-01-06 21:00:00 000:000:000'
}

response = requests.get(URL, headers=headers,  params=params, verify=False)
print(response.content.decode('utf-8'))  # {"data":{"calc_mode":"MIN","columns":[{"name":"TIME","type":5,"length":4096},{"name":"sensor1","type":20,"length":17}],"samples":[{"data":[{"TIME":"2021-01-06 17:00:00 000:000:000","sensor1":1},{"TIME":"2021-01-06 18:00:00 000:000:000","sensor1":2},{"TIME":"2021-01-06 20:00:04 000:000:000","sensor1":2},{"TIME":"2021-01-06 20:00:05 000:000:000","sensor1":2.5},{"TIME":"2021-01-06 20:00:06 000:000:000","sensor1":2}]}]},"status":"success"}
  //             ["2021-01-06 18:00:00 000:000:000",2,2],
        //             ["2021-01-06 20:00:04 000:000:000",2,2],
        //             ["2021-01-06 20:00:05 000:000:000",2.2.5],
        //             ["2021-01-06 20:00:06 000:000:000",2,2]
        //         ]
        //     }
        // }
    })
Expand
titlepython

github

Code Block
languagepy
"""
Example For Select Pivoted Data for tag API by using request in python
written by yeony kim
"""

import requests

API_KEY = "YOUR_API_TOKEN"
LAKE_ID = "YOUR_LAKE_ID"
CLOUD_VENDOR="CLOUD_VENDOR"
CLOUD_REGION="CLOUD_REGION"

URL = f"https://{CLOUD_VENDOR}.{CLOUD_REGION}.machlake.com/v1/lakes/{LAKE_ID}/values"

SELECT_TYPE="pivot"
TAG_NAME="sensor1,sensor2"

headers = {
    'Content-Type': 'application/json',
    'x-api-key': API_KEY
}

# ------------------------------------------------------------------------------------------------- #

# CASE - Pivoted DATA GET with another value form date format YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn

params = {
    "type": SELECT_TYPE,
 '   "tag_name'": 'sensor1,sensor2'TAG_NAME,
    'calc_mode': 'cntmin',
    'date_format': 'YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn',
    'start_time': '2021-01-06 17:00:00 000:000:000',
    'end_time': '2021-01-06 21:00:00 000:000:000',
    'value_return_form': 1'
}

response = requests.get(URL, headers=headers,  params=params, verify=False)
print(response.content.decode('utf-8'))

# Return Format
# {"data":{"calc_mode":"COUNT","columns":[
#     "success": true,
#     "reason": "success",
#     "data":{
#         "columns":[
#             {"name":"TIME","type":5,"length":4096},
#             {"name":"sensor1","type":1220,"length":2017},
#             {"name":"sensor2","type":1220,"length":20}],"samples":[{"data":{"TIME":17}
#         ],
#         "rows":[
#             ["2021-01-06 17:00:00 000:000:000",",1,1],
#             ["2021-01-06 17:00:01 000:000:000",null,1.5],
#             ["2021-01-06 17:00:02 000:000:000",null,2],
#             ["2021-01-06 17:00:03 000:000:000",null,1],
#             ["2021-01-06 17:00:04 000:000:000",",null,1.5],
#             ["2021-01-06 17:00:05 000:000:000",null,2],
#             ["2021-01-06 18:00:00 000:000:000",2,2],
#             ["2021-01-06 20:00:04 000:000:000",2,2],
#             ["2021-01-06 20:00:05 000:000:000",:000",2.2.5],
#             ["2021-01-06 20:00:06 000:000:000"],"sensor1":[9,0,0,0,0,0,3,1,1,1],"sensor2":[1,1,1,1,1,1,3,1,1,1]}}]},"status":"success"}
,2,2]
#         ]
#     }
# }