Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

« Previous Version 3 Next »

  • 이 API는 원하는 Tag들의 최소 시간값, 최대 시간값을 얻는 API이다.

HTTP Request

GET https://${CloudVendor}.${CountryCode}.machlake.com/lakes/${lake_id}/values/time_range
Content-Type: application/json; charset=utf8
x-api-key: {API Key}

Parameters

Optional

Type

Description

Example

tag_name

string

Tag의 이름. 여러개를 명시하려면 ',' 문자를 이용하여 나열할 수 있다.

&tag_name=tag1,tag2,tag3

date_format

string

Time값의 포멧 지정 DATE_FORMAT 혹은 timestamp 단위 ("SECOND", "MILLISECOND", "MICROSECOND", "NANOSECOND")

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

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

separator

string

매개변수의 tag_name, columns, and_condition들을 구분하는 구분자

&separator=| (default : ,)

value_return_form

int

결과 출력 방법

차트 라이브러리에서 입력받는 방식에 따라 변경하여 사용함

0 : separate standard (default)
or
1 : merged standard

Request Example

GET https://aws1.us.machlake.com/lakes/xbacd1234/values/time_range?tag_name=tag_01,tag_02&value_return_form=0 
Content-Type: application/json; charset=utf8
x-api-key: {API Key}

Response Example

Status 200
 
// return format = 0
{
    "status": "success",
    "data": {
        "columns": [
            {"length": 4096, "name": "MIN", "type": 5},
            {"length": 4096, "name": "MAX", "type": 5}
        ],
        "samples": [
            {
                "tag_name": "tag_02",
                "data": [
                    {
                        "MAX": "2021-07-06 12:12:27",
                        "MIN": "2021-06-16 11:36:44"
                    }
                ]
            },
            {
                "tag_name": "tag_01",
                "data": [
                    {
                        "MAX": "2021-07-06 12:12:25",
                        "MIN": "2021-06-15 17:52:35"
                    }
                ]
            }
        ]
    }
}
 
// return format = 1
{
    "status": "success",
    "data": {
        "columns": [
            {"length": 4096, "name": "MIN", "type": 5},
            {"length": 4096, "name": "MAX", "type": 5}
        ],
        "samples": [
            {
                "tag_name": "tag_02",
                "data": {
                    "MAX": ["2021-07-06 12:12:27"],
                    "MIN": ["2021-06-16 11:36:44"]
                }
            },
            {
                "tag_name": "tag_01",
                "data": {
                    "MAX": ["2021-07-06 12:12:25"],
                    "MIN": ["2021-06-15 17:52:35"]
                }
            }
        ]
    }
}

Sample Code

 window(batch)

github

chcp 65001 
:: Text Encoding to UTF-8 in CMD
:: Example For Select Data by Time Range 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/time_range"

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

:: CASE - Current DATA GET with date format YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn
set TAG_NAME=sensor1,sensor2
set DATE_FORMAT=YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn

curl -k -G %URL% -H %CONTENT_HEADER% -H %API_HEADER% --data-urlencode "tag_name=%TAG_NAME%" --data-urlencode "date_format=%DATE_FORMAT%"

:: Return Format
:: {"data":{"columns":[{"length":4096,"name":"MIN","type":5},{"length":4096,"name":"MAX","type":5}],"samples":[{"data":[{"MAX":"2021-01-07 02:00:00 009:000:000","MIN":"2021-01-06 17:00:00 000:000:000"}],"tag_name":"sensor2"},{"data":[{"MAX":"2021-01-06 20:00:06 000:000:000","MIN":"2021-01-06 17:00:00 001:000:000"}],"tag_name":"sensor1"}]},"status":"success"}

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

:: CASE - Current DATA GET with date format nanosecond timestamp
set TAG_NAME=sensor1,sensor2
set DATE_FORMAT=NANOSECOND

curl -k -G %URL% -H %CONTENT_HEADER% -H %API_HEADER% --data-urlencode "tag_name=%TAG_NAME%" --data-urlencode "date_format=%DATE_FORMAT%"

:: Return Format
:: {"data":{"columns":[{"length":20,"name":"MIN","type":12},{"length":20,"name":"MAX","type":12}],"samples":[{"data":[{"MAX":1609952400009000000,"MIN":1609920000000000000}],"tag_name":"sensor2"},{"data":[{"MAX":1609930806000000000,"MIN":1609920000001000000}],"tag_name":"sensor1"}]},"status":"success"}

:: ------------------------------------------------------------------------------------------------- ::
 linux(shell)

github

# Text Encoding to UTF-8 in CMD
# Example For Select Data by Time Range 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
TAG_NAME=$YOUR_TAG_NAME

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

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

# CASE - Current DATA GET with date format YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn
TAG_NAME=sensor1,sensor2
DATE_FORMAT="YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn"

curl -k -G $URL -H $CONTENT_HEADER -H $API_HEADER --data-urlencode "tag_name=$TAG_NAME" --data-urlencode "date_format=$DATE_FORMAT"

# Return Format
# {"data":{"columns":[{"length":4096,"name":"MIN","type":5},{"length":4096,"name":"MAX","type":5}],"samples":[{"data":[{"MAX":"2021-01-07 02:00:00 009:000:000","MIN":"2021-01-06 17:00:00 000:000:000"}],"tag_name":"sensor2"},{"data":[{"MAX":"2021-01-06 20:00:06 000:000:000","MIN":"2021-01-06 17:00:00 001:000:000"}],"tag_name":"sensor1"}]},"status":"success"}

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

# CASE - Current DATA GET with date format nanosecond timestamp
TAG_NAME=sensor1,sensor2
DATE_FORMAT=NANOSECOND

curl -k -G $URL -H $CONTENT_HEADER -H $API_HEADER --data-urlencode "tag_name=$TAG_NAME" --data-urlencode "date_format=$DATE_FORMAT"

# Return Format
# {"data":{"columns":[{"length":20,"name":"MIN","type":12},{"length":20,"name":"MAX","type":12}],"samples":[{"data":[{"MAX":1609952400009000000,"MIN":1609920000000000000}],"tag_name":"sensor2"},{"data":[{"MAX":1609930806000000000,"MIN":1609920000001000000}],"tag_name":"sensor1"}]},"status":"success"}
 javascript

github

// Example For Select Data by Time Range 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 TAG_NAME = "YOUR_TAG";
const URL = `https://${CLOUD_VENDOR}.${CLOUD_REGION}.machlake.com/lakes/${LAKE_ID}/values/time_range`;

var request = require('request');

// CASE - Current DATA GET with date format YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn
request.get({
    url: URL, 
    qs: {
        tag_name: TAG_NAME,
        date_format: 'YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn'
    },
    headers: {
        'x-api-key': API_KEY
    }}, 
    function(error, response, body) {
        // {"data":{"columns":[{"length":4096,"name":"MIN","type":5},{"length":4096,"name":"MAX","type":5}],"samples":[{"data":[{"MAX":"2021-01-07 02:00:00 009:000:000","MIN":"2021-01-06 17:00:00 000:000:000"}],"tag_name":"sensor2"},{"data":[{"MAX":"2021-01-06 20:00:06 000:000:000","MIN":"2021-01-06 17:00:00 001:000:000"}],"tag_name":"sensor1"}]},"status":"success"}
        console.log(body)
    })


// CASE - Current DATA GET with date format nanosecond timestamp
request.get({
    url: URL, 
    qs: {
        tag_name: TAG_NAME,
        date_format: 'NANOSECOND'
    },
    headers: {
        'x-api-key': API_KEY
    }}, 
    function(error, response, body) {
        // {"data":{"columns":[{"length":20,"name":"MIN","type":12},{"length":20,"name":"MAX","type":12}],"samples":[{"data":[{"MAX":1609952400009000000,"MIN":1609920000000000000}],"tag_name":"sensor2"},{"data":[{"MAX":1609930806000000000,"MIN":1609920000001000000}],"tag_name":"sensor1"}]},"status":"success"}
        console.log(body)
    })
 python

github

"""
Example For Select Data by Time Range for tag API by using request in python
written by yeony kim
sensor1, sensor2 is applied in lake
"""

import requests

API_KEY = "YOUT_API_TOKEN"
LAKE_ID = "YOUR_LAKE_ID"
CLOUD_VENDOR="CLOUD_VENDOR"
CLOUD_REGION="CLOUD_REGION"

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

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

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

params = {
    'tag_name': 'sensor1',
    'date_format': 'YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn',
}

response = requests.get(URL, headers=headers,  params=params, verify=False)
print(response.content.decode('utf-8'))  # {"data":{"columns":[{"length":4096,"name":"MIN","type":5},{"length":4096,"name":"MAX","type":5}],"samples":[{"data":[{"MAX":"2021-01-06 20:00:06 000:000:000","MIN":"2021-01-06 17:00:00 001:000:000"}],"tag_name":"sensor1"}]},"status":"success"}


# CASE - Current DATA GET with date format nanosecond timestamp

params = {
    'tag_name': 'sensor1,sensor2',
    'date_format': 'NANOSECOND',
}

response = requests.get(URL, headers=headers,  params=params, verify=False)
print(response.content.decode('utf-8'))  # {"data":{"columns":[{"length":20,"name":"MIN","type":12},{"length":20,"name":"MAX","type":12}],"samples":[{"data":[{"MAX":1609952400009000000,"MIN":1609920000000000000}],"tag_name":"sensor2"},{"data":[{"MAX":1609930806000000000,"MIN":1609920000001000000}],"tag_name":"sensor1"}]},"status":"success"}

  • No labels