Porovnávané verzie

Kľúč

  • Tento riadok sa pridal
  • Riadok je odstránený.
  • Formátovanie sa zmenilo.

Obsah

Obe rozhrania Comet aj REST API zdieľajú ten istý spôsob serializácie komunikácie prostredníctvom JSON formátu. Výnimku tvorí len volanie SBA RPC metód, ktoré slúžia na posielanie a získavanie binárnych dát z D2000 - v tomto prípade sa dáta posielajú v binárnej forme. JSON formát je univerzálnym formátom implementovaným snáď v každom programovacom jazyku. Jeho výhodou je nielen natívna podpora v každom prehliadači ale aj jednoduchá čitateľnosť človekom, pretože sa jedná o textový formát. Nevýhoda väčšieho objemu správy oproti akémukoľvek binárnemu formátu je minimalizovaná použitím gzip kompresie implicitne podporovanej ako v REST tak aj v Comet API.

Serializácia typu Unival

Both the Comet and the REST API interfaces share the same way of communication serialization using the JSON format. The only exception is calling SBA RPC methods which serve for sending and acquiring binary data from D2000 - in this case, the data is sent in a binary form. The JSON format is a universal format implemented almost in every programming language. Its advantage is not only native support in every browser but also easy readability for people since it is a text format. The disadvantage of the bigger capacity of a message in comparison with any binary format is minimalized by the use of a gzip compression implicitly supported by the REST and also the Comet API. 

Serialization of the Unival Type

The basic unit of data change between a client and the D2000 system is the Unival type - clustering basic object attributes in D2000. The following example of the unival value in the JSON format represents a value of a real number type with the Valid stateZákladnou jednotkou výmeny dát medzi klientom aj D2000 systémom je typ Unival - zoskupujúci základné atribúty objektov v D2000. Nasledujúci príklad unival hodnoty v JSON formáte, reprezentuje hodnotu typu reálne číslo so stavom Valid.

Blok kódu
languagejs
titlePríklad zápisu Unival hodnotyExample of writing a Unival value
{
  "type": "real",
  "value": 123.456,
  "status": ["Valid"]
}

Každý Unival hodnota má jasne definovaný typ pomocou atribútu type. V prípade posielania Unival hodnôt do D2000 systému atribút type musí byť vždy definovaný. Výnimku tvorí iba možnosť keď namiesto objektového zápisu Unival typu, pošleme priamo hodnotu, v našom prípade 123,456. Tá je SmartWeb serverom automaticky konvertovaná na typ "real", keďže sa jedná o hodnotu s desatinnou čiarkou (v prípade poslania reťazca by bol typ nastavený automaticky na hodnotu "text" a celého čísla na hodnotu "int").Every Unival value has a clearly defined type with the use of the type attribute. In the case of sending Unival values into the D2000 system, the type attribute has to be always defined. The only exception is the possibility when we send instead of an object log of the Unival type the value directly, in our case 123,456. This value is automatically converted to the "real", type by the SmartWeb server since it is a value with a decimal point (in the case of sending a string, the type would be automatically set to the "text" value and in the case of sending an integer to the "int" value. 

Blok kódu
languagejs
titleSkrátený zápis Unival hodnotyShort notation of the Unival value
123.456

Odpoveď zo SmartWeb servera, nikdy nechodí v tomto skrátenom zápise, ale v "objektovom" zápise s definovaným typom (atribút type) a hodnotou (atribút value) ak je platná.

Info

Ostatné atribúty nie sú v odpovedi zo SmartWeb servera implicitne vrátené kvôli optimalizácii, ale klient si ich vie vyžiadať cez špeciálny atribút returnAs (popísaný nižšie). 

Atribút type môže nadobúdať nasledovné hodnoty:

The answer from the SmartWeb server never comes in this shortened log but in the "object" log with a defined type (type attribute) and a value (value attribute) if it is valid.

Info

Other attributes are not implicitly returned in the answer form the SmartWeb server because of optimization but a client can ask for them through a special attribute returnAs (below described). 

The type attribute may gain the following values:

Value of the type attributeDescription of the value type
"nan"none
"bool"VBool type
"int"integer
"real"real number
"station"VStation type
"alarm"VAlarm type
"process"VProcess type
"time"integer (number of milliseconds from epoch)
"timespan"real number (number of seconds
Hodnota atribútu typePopis typu hodnoty"nan"žiadna"bool"typ VBool"int"celé číslo"real"reálne číslo"station"typ VStation"alarm"typ VAlarm"process"typ VProcess"time"celé číslo (počet milisekúnd od epochy)"timespan"reálne číslo (počet sekúnd
)
"text"text
"array"
pole objektov 
field of objects D2ApiValue
"qval"
typ 
VQval type
"record"
dvojrozmerné pole (riadok, stĺpec) hodnôt

Zoznam všetkých atribútov Unival objektu je vypísaný v nasledujúcej tabuľke:

two-dimensional field (row, column) of values

The list of all attributes of the Unival object is in the following table:  

AttributeValue typeMandatoryDefault valueNote
AtribútTyp hodnotyPovinnýPredvolená hodnotaPoznámka
typetext
áno
yes

value
podľa typunienenastavený atribút automaticky znamená neplatnú hodnotu, nastavený platnú (ak príznak nie je preťažený v atribúte status)valueTimecelé číslo (počet milisekúnd od epochy)nieaktuálny časčasová značkavalueTimesdvojrozmerné pole (riadok, stĺpec) celých čísel (počet milisekúnd od epochy)nieaktuálny časčasové značky hodnôt v štruktúre, len pre typ "record"alarmTimecelé číslo (počet milisekúnd od epochy)niečasová značka alarmualarmTimesdvojrozmerné pole (riadok, stĺpec) celých čísel (počet milisekúnd od epochy)niečasové značky alarmov v štruktúre, len pre typ "record"
according to the typeno
unset attributes automatically mean invalid value, set attributes mean valid value (if the attribute is not overloaded in the status attribute) 
valueTimeinteger (number of milliseconds from epoch)nocurrent timetime stamp
valueTimestwo-dimensional field (row, column) of integers (number of milliseconds from epoch)nocurrent time time stamps of values in a structure, only for the "record" type
alarmTimeinteger (number of milliseconds from epoch)no
time stamp of an alarm
alarmTimestwo-dimensional field (row, column) of integers (number of milliseconds from epoch)no
time stamps of alarms in a structure, only for the "record" type
flagsfield of texts (listed Flag type)nono flagsfield of user flags, possible values are from "A" to "P"
flagsSetstwo-dimensional field (row, column) of text fields (listed Flag type)nono flagstwo-dimensional field of fields of user flags of structure values, only for the "record" type
limitStatustext (listed LimitStatus type)no"InLimit"limited state, possible values are
flagspole textov (vymenovaný typ Flag)niežiadny príznakpole uživateľských príznakov, možné hodnoty sú "A""P"flagsSetsdvojrozmerné pole (riadok, stĺpec) polí textov (vymenovaný typ Flag)niežiadny príznakdvojrozmerné pole polí uživateľských príznakov hodnôt štruktúry, len pre typ "record"limitStatustext (vymenovaný typ LimitStatus)nie"InLimit"limitný stav, možné hodnoty sú
: "InLimit", "VeryLow", "Low", "High", "VeryHigh", "LimitsProblem"
limitStatuses
dvojrozmerné pole (riadok, stĺpec) polí textov (vymenovaný typ LimitStatus)
two-dimensional field (row, column) of text fields (listed LimitStatus type)no
nie
"InLimit"
dvojrozmerné pole limitných stavov hodnôt štruktúry, len pre typ
two-dimensional field of limited statuses of structure values, only for the "record" type
processAlarmStatus
texto
text (
vymenovaný typ
listed ProcessAlarmStatus type)
nie
no"NoAlarm"
stav alarmu procesu, možné hodnoty sú
status of a process alarm, possible values are: "NoAlarm", "ToOn", "ToOff", "On", "Off", "Err", "Oscillate", "ErrCmdOn", "ErrCmdOff", "SwToTrans", "SwToOff", "SwToOn", "SwToErr", "SwTrans", "SwOff", "SwOn", "SwErr", "ErrZalCmdOff", "HL", "VHL", "LL", "VLL", "ToHL", "ToVHL", "ToLL", "ToVLL", "ErrWriteCmd", "Change", "A29", "A30", "A31", "SysPrAl"
processAlarmStatuses
dvojrozmerné pole (riadok, stĺpec) polí textov (vymenovaný typ ProcessAlarmStatus)
two-dimensional field (row, column) of text fields (listed ProcessAlarmStatus type)no
nie
"NoAlarm"
dvojrozmerné pole stavov alarmu procesov v štruktúre, len pre typ
two-dimensional field of statuses of process alarms ina structure, only for the "record" type
status
pole textov (vymenovaný typ Status
text fields (listed Status type)
nie
no
príznak
"Valid"
pole stavov, možné hodnoty sú
status fields, possible values are: "Valid", "ProcAlarm", "NoAckPAlarm", "PrAlSilent", "Weak", "NoAckValue", "Transient", "Default", "Manual", "AlCrit", "Unknown"
statusSets
dvojrozmerné pole (riadok, stĺpec) polí textov (vymenovaný typ Status)niepríznak "Valid"
two-dimensional field (row, column) of text fields (listed Status type)no"Valid"two-dimensional field of statuses of structure values, only for the "record" type
dvojrozmerné pole stavov hodnôt štruktúry, len pre typ "record"
formattedValuetext
niev atribúte sa vracia v odpovedi zo servera formátovaná hodnota objektu D2000, nemá význam pri volaniach RPC metód
no
in the attribute, the formatted value of D2000 object returns in the answer from the server, unnecessary when calling RPC methods 
structTypetext
áno
yes
meno štruktúry, len pre typ

structure name, only for the "record"
, povinný na každom type
type, mandatory on every "record"
posielanom do
type sent to D2000
definition
objekt D2RecordDefinition
D2RecordDefinition object-
definícia Štruktúry, len pre typ

structure definition, only for the "record"
, nastavený na každej hodnote s typom
type, set on every value with the "record"
vracanej z
type returned from D2000
returnAstext
niemá význam len pri volaní RPC metód s výstupnými parametrami, definuje logický názov, pod ktorým bude vrátená výstupná hodnota
no
have sense only when calling RPC methods with output parameters, defines logical name which will have the returned output value 
returnFieldstext fieldsnoempty fielda special attribute defines additional returning attributes required by a client from the server 
returnTransformationReturnTransformation objectnonullonly for the "record" type with one numerical column and growing time stamps of values, it contains the configuration of processing (downscaling) of a numerical column performed on a server before sending answers to a client, because of the big data range, values are described below  
returnFieldspole textovnieprázdne polešpeciálny atribút definuje dodatočné návratové atribúty požadované klientom od serverareturnTransformationobjekt ReturnTransformationnienulllen pre typ "record" s jedným číselnym stĺpcom a rastúcimi časovými značkami hodnôt, obsahuje konfiguráciu spracovania (downscalingu) časového radu, vykonávanom na serveri pred posielaním odpovede klientovi, kvôli veľkému rozsahu dát, hodnoty sú popísané nižšie

Kotva
implicitConversion
implicitConversion

...

Implicit Conversion of Simple JSON Types to Unival Value

To simplify working through the API interface, it is possible to use simple types instead of Unival type objects as input values to the D2000 system. Such values have the validity attribute, the time of origin to the current time automatically set and other attributes gain their default value.

JSON format typeCorresponding Unival typeNote

Pre zjednodušenie práce cez API rozhrania je možné ako vstupné hodnoty do systému D2000 používať aj jednoduché typy namiesto objektov typu Unival. Takéto hodnoty majú automaticky nastavený príznak platnosti, čas vzniku na aktuálny čas a ostatné príznaky nadobúdajú ich predvolenú hodnotu.

Typ formátu JSONZodpovedajúci typ UnivalPoznámka
boolean"bool"
number"bool"
Ak je cieľový typ v D2000 BOOL. Čísla sú interpretované podľa poradia v type VBool
If the target type is in the D2000 BOOL. Numbers are interpreted according to the order in the VBool type.
number"int"
Ak je cieľový typ v D2000 INT. Ak bolo zadané reálne číslo, tak bude zaokrúhlené na celé
If the target type is in the D2000 INT. If the given number was a real number, it will be rounded to an integer number.
number"real"
Ak je cieľový typ v
If the target type is in the D2000 REAL.
number"time"
Ak je cieľový typ v
If the target type is in the D2000 TIME.
 Pozor: Číslo je interpretované ako počet sekúnd od
 Warning: The number is interpreted as a number of seconds from 1972-01-01 00:00:00 UTC,
nie ako počet milisekúnd od epochy
not as a number of milliseconds from the epoch.
string"text"

Kotva
returnAs
returnAs

...

Defining of Returned Values from RPC Methods

The attribute returnFields defines the logical name of an output parameter required by a client from the server. 

Image Added

In the figure, there is represented an example of the SimpleSum method calling by a client. The first two parameters are simple JSON types that are implicitly converted to right Unival values. The third parameter is an output one and the client defines in the returnAs attribute the logical name under which will be the output Unival value returned; in this case, it is the logical name 

Atribút returnFields definuje logický názov výstupného parametra požadovaného klientom od servera.

Image Removed

 Na obrázku je znázornený príklad volania metódy SimpleSum klientom. Prvé dva parametre sú jednoduché JSON typy ktoré su implicitne konvertované na správne Unival hodnoty. Tretí parameter je výstupný a klient definuje v atribúte returnAs, logický názov pod ktorým mu bude výstupná unival hodnota vrátená, v tomto prípade je to logický názov "vysledok".

Kotva
returnFields
returnFields

...

Optimization of the Content of the Returned Unival Value

Because of the minimization of transmitted data, the Unival objects standardly contain on the output from D2000 only type and value attribute (if the value is valid). In the case of need of other extended value attributes, which are provided by the D2000 system, it is possible to set the returnFields attribute when calling and name required attributes in it.  The value of the returnFields attribute has a format of a text field. Allowed values are in the following table.

Value in the returnFields fieldFilled in attributes in response form server 

Kvôli minimalizácii prenášaných dát Unival objekty štandardne na výstupe z D2000 obsahujú len atribút type value (ak je hodnota platná). V prípade potreby ostatných rozširujúcich atribútov hodnoty, ktoré poskytuje systém D2000, je možné pri volaní nastaviť atribút returnFields a v ňom vymenovať požadované atribúty. Hodnota atribútu returnFields má formát poľa textov. Prípustné hodnoty sú v nasledujúcej tabuľke.

Hodnota v poli returnFieldsVypĺňané atribúty v odpovedi zoservera
"AlarmTime"alarmTime, alarmTimes
"Flags"flags, flagsSets
"LimitStatus"limitStatus, limitStatuses
"ProcessAlarmStatus"processAlarmStatus, processAlarmStatuses
"Status"status, statusSets
"ValueTime"valueTime, valueTimes
"FormattedValue"formattedValue

Unival

...

type Structure ("record")

...

 

The value of the structure type has its values and attributes stored as a two-dimensional field (row, column). Values gain the type according to the definition of structure in the D2000 system. It does not use extended attributesHodnota typu štruktúra má svoje hodnoty a atribúty uložené ako dvojrozmerné pole (riadok, stĺpec). Hodnoty nadobúrajú typ podľa definície štruktúry v systéme D2000. Nepoužíva rozširujúce atribúty alarmTime, flags, limitStatus, processAlarmStatus, status a valueTime. Namiesto nich používa atribúty Instead of them, it uses attributes alarmTimes, flagsSets, limitStatuses, processAlarmStatuses, statusSets, valueTimes, ktoré sú dvojrozmerným poľom a prvky majú rovnaký typ ako pôvodné atribúty. Ďalšími atribútmi používanými len pri štruktúrach sú definition structType. Atribút definition (objekt D2RecordDefinition) je vždy automaticky nastavený na všetkých štruktúrovaných hodnotách, ktoré vystupujú zo systému D2000. Tento atribút popisuje názvy stĺpcov a ich typy v štrukturovanej premennej. Typy stĺpcov v štruktúre sú zjednodušenou verziou typov Unival.which are a two-dimensional field and components have the same type as the original attributes. Other attributes used only in structures are definition and structType. The definition attribute (D2RecordDefinition object) is always automatically set on all structural values that come from the D2000 system. This attribute describes columns' names and their types in a structured variable. Columns' types in a structure are a simplified version of Unival types.

Column typeValue type
"bool"VBool type
"integer"integer
"real"real number
"time"integer (number of milliseconds from epoch
Typ stĺpcaTyp hodnoty"bool"typ VBool"integer"celé číslo"real"reálne číslo"time"celé číslo (počet milisekúnd od epochy
)
"timespan"
reálne číslo (počet sekúnd
real number (number of seconds)
"text"text
"object"
podľa typu referencovaného D2000 objektu
according to the type of referenced D2000 object

The structType attribute is a text attribute and defines the name of the D2000 object of the structure definition type. It is mandatory to set it for every structured value that is inputted into the D2000 systemAtribút structType je textový a určuje meno objektu D2000 typu definícia štruktúry. Je povinné ho nastaviť pre každú štrukturovanú hodnotu, ktorá vstupuje do systému D2000.

Blok kódu
languagejs
titlePríklad posielanéj hodnoty typu štruktúra - definícia SD.ArrReal_Text, 2 stĺpce (int, text), 3 riadky:
{
  "type": "record",
  "structType": "SD.Arr_Real_Text",
  "value": [[1, "One"], [2, "Two"], [3, "Three"]]
}

...

Blok kódu
languagejs
titlePríklad vracanej hodnoty typu štruktúra - definícia SD.ArrReal_Text, 2 stĺpce (int, text), 3 riadky:
{
  "type": "record",
  "definition": {
    "columnTypes": ["integer", "text"],
    "columnNames": ["digit", "name"]
  },
  "value": [[1, "One"], [2, "Two"], [3, "Three"]]
}

Transformácie časových radov

Pod časovým radom sa rozumie jednostĺpcová štruktúra, kde hodnoty sú reálne čísla a majú nastavené rastúce časové značky. Pri zobrazení časových radov často nie sú potrebné alebo žiadané (najmä kvôli výkonu) všetky hodnoty z požadovaného intervalu. Pre takéto potreby sú implementované transformácie časových radov, ktoré zmenšujú počet prenášaných dát. Transformáciu je možné vyžiadať nastavením atribútu transformation na výstupnej štrukturovanej hodnote.

Downsampling

Transformations of Time Rows

Time row is a one-column structure in which values are real numbers and have increasing time stamps set. When displaying time rows, all values from requested interval are often not necessary or required (especially because of performance).  For such needs, transformations of time rows are implemented which decrease the number of transmitted data. It is possible to request the transformation by setting the transformation attribute on the output structured value.

Downsampling

Downsampling is reducing the number of values according to the given step or to the given number of values. The used algorithm tries as much as possible to keep the course of the curve of the original time row and does not smooth the final curve as the common resampling using averaging.  Downsampling je zredukovanie počtu hodnôt podľa daného kroku alebo na daný počet hodnôt. Použitý algoritmus sa snaží čo najviac zachovať priebeh krivky pôvodného časového radu a nevyhladzuje výslednú krivku ako bežné prevzorkovanie používajúce priemerovanie.

Blok kódu
languagejs
titleVyžiadané zredukovanie algoritmom Largest Triangle Three Buckets na 100 hodnôt
{
  "type": "record",
  "structType": "SD.Arr_Real",
  "returnTransformation": {
    "type": "lttb",
    "threshold": 100
  }
}

...

Blok kódu
languagejs
titleVyžiadané zredukovanie algoritmom Largest Triangle Three Buckets s krokom 86400 sekúnd (1 deň)
{
  "type": "record",
  "structType": "SD.Arr_Real",
  "returnTransformation": {
    "type": "lttb",
    "step": 86400
  }
}

OHLC

The OHLC (Open-High-Low-Close) algoritmus transformuje výstupný časový rad tak, že pre každý interval nájde prvú, maximálnu, minimálnu a poslednú hodnotu. Voliteľne pri tomto algoritme je možné nastaviť či majú byť intervaly spojité (po sebe nasledujúce intervaly majú spoločnú poslednú a prvú hodnota - predvolene) alebo diskrétne - atribút discrete a kde má byť umiestnená časová značka hodnoty reprezentujúcej celý interval (začiatok "Start" alebo stred "Midpoint" - predvolene) - atribút timestampPlacement.algorithm transforms the output time row in a way that for every interval it finds first, maximal, minimal and last value. Optionally when using this algorithm, it is possible to set whether the intervals should be continuous (successive intervals have the first and the last value common - by default) or discrete - the discrete attribute and where should be the time stamp of the value representing the whole interval placed (the beginning "Start" or in the middle "Midpoint" - by default) - the timestampPlacement attribute. 

Blok kódu
languagejs
titleVyžiadané OHLC transformácie s krokom 86400 sekúnd (1 deň) s diskrétnymi intervalmi a časovými značkami na začiatku intervalu
{
  "type": "record",
  "structType": "SD.Arr_Real",
  "returnTransformation": {
    "type": "ohlc",
    "step": 86400,
    "discrete": true,
    "timestampPlacement": "Start"
  }
}

...