EmoTouch R Webservice Dokumentation: Unterschied zwischen den Versionen
Zeile 2: | Zeile 2: | ||
Additional documentation is served by swagger when running R web service: | Additional documentation is served by swagger when running R web service: | ||
− | + | http://127.0.0.1:8000/__docs__/ | |
= Results structure = | = Results structure = | ||
Zeile 16: | Zeile 16: | ||
length = <span style="color: green;"> 1L</span> | length = <span style="color: green;"> 1L</span> | ||
) | ) | ||
+ | |||
+ | In case of an error: | ||
+ | |||
+ | list( | ||
+ | error = <span style="color: red;"> "an error message"</span>, | ||
+ | results = <span style="color: purple;"> NULL </span>, | ||
+ | type = <span style="color: purple;"> NULL</span>, | ||
+ | length = <span style="color: purple;"> NULL</span> | ||
+ | ) | ||
+ | |||
+ | == on JavaScript side == | ||
+ | Note that results field is always boxed, even for scalar result: | ||
+ | |||
+ | {"error":{},"result":[3],"type":"double","length":1} | ||
+ | |||
+ | An error: | ||
+ | |||
+ | {"error":"an error message","result":{},"type":{},"length":{}} | ||
+ | |||
+ | |||
+ | = Functions = | ||
+ | All functions that takes any arguments are meant to be called as POST method. Those without arguments via GET method. | ||
+ | |||
+ | == version == | ||
+ | Returns the version of the R webservice. | ||
+ | Takes no arguments. | ||
+ | |||
+ | curl -H "Content-Type: application/json" http://localhost:8000/version | ||
+ | |||
+ | {"error":{},"result":["0.3"],"type":"character","length":1} | ||
+ | |||
+ | == degap == | ||
+ | |||
+ | Synchronize multiple series according to their indexes. Fill gaps with Last Observation Carried Forward. | ||
+ | Indices provided in idx must have same sampling rate. Arguments: | ||
+ | * x: list of series of numeric values. | ||
+ | * idx: list of series of indexes, must be same number of series as series provided to x, must have same length as corresponding series provided to x. | ||
+ | * sync: boolean default to true, takes min and max index from all indices to expand all series of x into it. See examples below. | ||
+ | * how: character, default "locf" means that gaps are filled with last observation carried forward, could be also "nocb" for next observation carried backward, or "const" for the constant value specified in fill argument. | ||
+ | * fill: numeric to be used when how="const". | ||
+ | |||
+ | examples of sync=true (default), sampling rate 1. | ||
+ | |||
+ | x1 = [4,5,8,7,6] | ||
+ | x2 = [2,3,4,5,7] | ||
+ | idx1 = [2,3,5,6,8] | ||
+ | idx2 = [0,1,3,4,6] | ||
+ | |||
+ | synchronized indices | ||
+ | |||
+ | idx12 = [0,1,2,3,4,5,6,7,8] | ||
+ | x1gap = [ , ,4,5, ,8,7, ,6] | ||
+ | x2gap = [2,3, ,4,5, ,7, , ] | ||
+ | |||
+ | gaps filled with locf (default) | ||
+ | |||
+ | x1out = [ , ,4,5,5,8,7,7,6] | ||
+ | x2out = [2,3,3,4,5,5,7,7,7] | ||
+ | |||
+ | Note that x and idx can contain 1+ series. | ||
+ | |||
+ | Working example of 2 series (sampling rate 2): | ||
+ | |||
+ | curl -H "Content-Type: application/json" --data '{"x": [[1,2.5,3,4,5.5,6,7,8],[1.5,3.5,4,4,5.5,6,7]],"idx": [[0,2,4,8,10,14,16,18],[0,2,4,6,8,14,18]]}' http://localhost:8000/degap | ||
+ | #{"error":{}, "result":[[1,2.5,3,3,4,5.5,5.5,6,7,8],[1.5,3.5,4,4,5.5,5.5,5.5,6,6,7]], "type":"length":2} | ||
+ | |||
+ | When sync=false then each series has gaps filled only within its own min-max boundaries. | ||
+ | According to use cases discussed, use of sync=false and how!="locf" should be considered undesired. | ||
+ | |||
+ | Graphical representation of the function: | ||
+ | |||
+ | x = c(4,6.5,3,4,7.5,4,8,9) | ||
+ | idx = c(0,1,2,4,5,6,7,9) |
Version vom 19. November 2024, 20:42 Uhr
Additional documentation
Additional documentation is served by swagger when running R web service:
http://127.0.0.1:8000/__docs__/
Results structure
Results from R web service are always wrapped in a list to provide error handling and extra metadata about the returned object.
on R side
In case of successfully computed request (of a function returning scalar integer value 3):
list( error = NULL, results = 3L, type = "integer", length = 1L )
In case of an error:
list( error = "an error message", results = NULL , type = NULL, length = NULL )
on JavaScript side
Note that results field is always boxed, even for scalar result:
{"error":{},"result":[3],"type":"double","length":1}
An error:
{"error":"an error message","result":{},"type":{},"length":{}}
Functions
All functions that takes any arguments are meant to be called as POST method. Those without arguments via GET method.
version
Returns the version of the R webservice. Takes no arguments.
curl -H "Content-Type: application/json" http://localhost:8000/version
{"error":{},"result":["0.3"],"type":"character","length":1}
degap
Synchronize multiple series according to their indexes. Fill gaps with Last Observation Carried Forward. Indices provided in idx must have same sampling rate. Arguments:
- x: list of series of numeric values.
- idx: list of series of indexes, must be same number of series as series provided to x, must have same length as corresponding series provided to x.
- sync: boolean default to true, takes min and max index from all indices to expand all series of x into it. See examples below.
- how: character, default "locf" means that gaps are filled with last observation carried forward, could be also "nocb" for next observation carried backward, or "const" for the constant value specified in fill argument.
- fill: numeric to be used when how="const".
examples of sync=true (default), sampling rate 1.
x1 = [4,5,8,7,6] x2 = [2,3,4,5,7] idx1 = [2,3,5,6,8] idx2 = [0,1,3,4,6]
synchronized indices
idx12 = [0,1,2,3,4,5,6,7,8] x1gap = [ , ,4,5, ,8,7, ,6] x2gap = [2,3, ,4,5, ,7, , ]
gaps filled with locf (default)
x1out = [ , ,4,5,5,8,7,7,6] x2out = [2,3,3,4,5,5,7,7,7]
Note that x and idx can contain 1+ series.
Working example of 2 series (sampling rate 2):
curl -H "Content-Type: application/json" --data '{"x": [[1,2.5,3,4,5.5,6,7,8],[1.5,3.5,4,4,5.5,6,7]],"idx": [[0,2,4,8,10,14,16,18],[0,2,4,6,8,14,18]]}' http://localhost:8000/degap #{"error":{}, "result":[[1,2.5,3,3,4,5.5,5.5,6,7,8],[1.5,3.5,4,4,5.5,5.5,5.5,6,6,7]], "type":"length":2}
When sync=false then each series has gaps filled only within its own min-max boundaries. According to use cases discussed, use of sync=false and how!="locf" should be considered undesired.
Graphical representation of the function:
x = c(4,6.5,3,4,7.5,4,8,9) idx = c(0,1,2,4,5,6,7,9)