API - Получение данных для графика/en — различия между версиями

Материал из WebHMI Wiki
Перейти к: навигация, поиск
(Новая страница: «Example of getting data for graph #1:»)
(Новая страница: «Headers: <pre> Accept: application/json Content-Type: application/json Accept-Encoding: gzip, deflate, sdch X-WH-APIKEY: F3C74230818DA487BB2017CE5D0290F4DABCAFD7…»)
Строка 34: Строка 34:
 
'''Method''': GET
 
'''Method''': GET
  
Заголовки:
+
Headers:
 
<pre>
 
<pre>
 
Accept: application/json
 
Accept: application/json

Версия 09:41, 16 апреля 2018

Другие языки:
English • ‎русский

To get data from graph log, it is necessary to run following GET-query for URL http://192.168.1.1/api/graph-data/2. Here 2 - is the ID of the graph of interest.

Also, instead of specifying the graph ID, you can send the X-WH-REGS header. It specifies, through the comma, the ID of the registers for which data is to be extracted. Example:

X-WH-REGS: 23,12,4

In the request headers, you must pass the API key, the boundaries of the time interval of interest (X-WH-START, X-WH-END) and the number of values ​​(X-WH-SLICES). X-WH-START and X-WH-END are transmitted in UnixTime format. For example:

X-WH-APIKEY: F3C74230818DA487BB2017CE5D0290F4DABCAFD7
X-WH-START: 1422797440
X-WH-END: 1422997405
X-WH-SLICES: 300

X-WH-SLICES is the number of values. The time interval X-WH-START-X-WH-END will be divided into X-WH-SLICES of equal intervals and the system will take the most detailed values ​​for each of them.
X-WH-SLICES should be chosen based on the necessary detail of the graph. So, if you need to build a graph 800 pixels wide, then it makes no sense to choose more than 800 values ​​from the log. And sometimes there will be enough 200-400 values ​​depending on the width of the line on the graph.

To speed up the operation, the system can store the averaged values ​​of the registers for different intervals (1 minute, 2 minutes, 5 minutes, 15 minutes, 1 hour). In the configuration of each register, you can specify the required detail of the stored data. Depending on the selected time interval and the number of values, the system will attempt to take data from the most appropriate table of averaged values. or from the register register (if it is included for the specified register)

Also, in the headers, you must specify the desired data exchange format. Currently, only the JSON format is supported.

Accept: application/json
Content-Type: application/json

Example of getting data for graph #1:

URL: http://192.168.1.1/api/graph-data/1
Method: GET

Headers:

Accept: application/json
Content-Type: application/json
Accept-Encoding: gzip, deflate, sdch
X-WH-APIKEY: F3C74230818DA487BB2017CE5D0290F4DABCAFD7
X-WH-START: 1422854081
X-WH-END: 1422856235
X-WH-SLICES: 20

Пример ответа:

[
  {
    "8": "NaN;NaN;NaN",
    "10": "NaN;NaN;NaN",
    "16": "NaN;NaN;NaN",
    "x": 1422861065000
  },
  {
    "8": "NaN;NaN;NaN",
    "10": "NaN;NaN;NaN",
    "16": "NaN;NaN;NaN",
    "x": 1422861173000
  },
  {
    "8": "NaN;NaN;NaN",
    "10": "NaN;NaN;NaN",
    "16": "NaN;NaN;NaN",
    "x": 1422861281000
  },
  {
    "8": "NaN;NaN;NaN",
    "10": "NaN;NaN;NaN",
    "16": "NaN;NaN;NaN",
    "x": 1422861388000
  },
  {
    "8": "0.000000;9.292714;19.000000",
    "10": "NaN;NaN;NaN",
    "16": "0.000000;0.674894;1.000000",
    "x": 1422861496000
  },
  {
    "8": "0.000000;9.489933;19.000000",
    "10": "NaN;NaN;NaN",
    "16": "0.000000;0.742101;1.000000",
    "x": 1422861604000
  },
  {
    "8": "0.000000;9.500000;19.000000",
    "10": "NaN;NaN;NaN",
    "16": "0.000000;0.747650;1.176471",
    "x": 1422861711000
  },
  {
    "8": "0.000000;9.500000;19.000000",
    "10": "NaN;NaN;NaN",
    "16": "0.000000;0.748471;1.176471",
    "x": 1422861819000
  },
  {
    "8": "0.000000;9.500000;19.000000",
    "10": "NaN;NaN;NaN",
    "16": "0.000000;0.746659;1.176701",
    "x": 1422861927000
  },
  {
    "8": "0.000000;9.500000;19.000000",
    "10": "NaN;NaN;NaN",
    "16": "0.000000;0.755068;1.176932",
    "x": 1422862034000
  },
  {
    "8": "0.000000;9.500000;19.000000",
    "10": "NaN;NaN;NaN",
    "16": "0.000000;0.741844;1.000000",
    "x": 1422862142000
  },
  {
    "8": "0.000000;9.500000;19.000000",
    "10": "NaN;NaN;NaN",
    "16": "0.000000;0.740291;1.000000",
    "x": 1422862250000
  },
  {
    "8": "0.000000;9.500000;19.000000",
    "10": "NaN;NaN;NaN",
    "16": "0.000000;0.756320;1.176701",
    "x": 1422862358000
  },
  {
    "8": "0.000000;9.500000;19.000000",
    "10": "NaN;NaN;NaN",
    "16": "0.000000;0.746004;1.176471",
    "x": 1422862465000
  },
  {
    "8": "0.000000;9.500000;19.000000",
    "10": "NaN;NaN;NaN",
    "16": "0.000000;0.754233;1.176932",
    "x": 1422862573000
  },
  {
    "8": "0.000000;9.500000;19.000000",
    "10": "NaN;NaN;NaN",
    "16": "0.000000;0.740343;1.000000",
    "x": 1422862681000
  },
  {
    "8": "0.000000;9.500000;19.000000",
    "10": "NaN;NaN;NaN",
    "16": "0.000000;0.751393;1.176932",
    "x": 1422862788000
  },
  {
    "8": "0.000000;9.500000;19.000000",
    "10": "NaN;NaN;NaN",
    "16": "0.000000;0.750868;1.176932",
    "x": 1422862896000
  },
  {
    "8": "0.000000;9.500000;19.000000",
    "10": "NaN;NaN;NaN",
    "16": "0.000000;0.745956;1.176701",
    "x": 1422863004000
  },
  {
    "8": "0.000000;9.500000;19.000000",
    "10": "NaN;NaN;NaN",
    "16": "0.000000;0.758306;1.176932",
    "x": 1422863111000
  },
  {
    "8": "0.000000;9.500000;19.000000",
    "10": "NaN;NaN;NaN",
    "16": "0.000000;0.741780;1.000000",
    "x": 1422863219000
  },
  {
    "8": "0.000000;9.500000;19.000000",
    "10": "NaN;NaN;NaN",
    "16": "0.000000;0.741780;1.000000",
    "x": 1422863327000
  },
  {
    "8": "NaN;NaN;NaN",
    "10": "NaN;NaN;NaN",
    "16": "NaN;NaN;NaN",
    "x": 1422863435000
  },
  {
    "8": "NaN;NaN;NaN",
    "10": "NaN;NaN;NaN",
    "16": "NaN;NaN;NaN",
    "x": 1422863542000
  }
]

Структура возвращаемых данный следующая. Возвращается массив объектов. В каждом объекте есть атрибут "x" - это временная метка данной записи. Формат времени - UnixTime умноженный на 1000 (размерность - миллисекудны).
Также в этом объекте есть атрибуты со значениями для каждого регистра. Имя атрибута - это ID регистра. Значение атрибута - это строка где через точку с запятой объединены минимальное, среднее и максимальное значение регистра на этом интервале. Например, "0.000000;0.755068;1.176932" означает что регистр принимал значения от 0 до 1.176932, при этом его среднее арифметическое было 0.755068. Если же в данном промежутке нет данных о значении данного регистра то система будет возвращать "NaN;NaN;NaN".