Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.69 KB | None | 0 0
  1. var riot = require("riot");
  2.  
  3. var simple_template = {
  4. "name" : "compute over time",
  5. "description": "What is the {{Device_group}} {{Function}}" +
  6. " {{Sensor}} every {{Window_Size}} with shift of {{Interval}} {{GroupBy}}",
  7. "aliases": {
  8. "Function": {
  9. "type": "aggregate-function",
  10. "hintText": "Select function"
  11. },
  12. "Device_group": {
  13. "type": "device_group_selector",
  14. "hintText": "Select group"
  15. },
  16. "Sensor": {
  17. "type": "selector",
  18. "valueType": "sensor_name",
  19. "hintText": "Select sensor",
  20. "dependsOn": "Device_group"
  21. },
  22. "Window_Size": {
  23. "type": "input",
  24. "inputType": "number",
  25. "multiplier": {
  26. "defaultValue": 1000,
  27. "hintText": "Select units",
  28. "values": {
  29. "sec": 1000,
  30. "min": 60000
  31. }
  32. }
  33. },
  34. "Interval": {
  35. "type": "input",
  36. "inputType": "number",
  37. "multiplier": {
  38. "defaultValue": 1000,
  39. "hintText": "Select units",
  40. "values": {
  41. "sec": 1000,
  42. "min": 60000
  43. }
  44. }
  45. },
  46. "GroupBy": {
  47. "type": "checkbox",
  48. "inputType": "boolean",
  49. "values": ["ALL", "device"],
  50. "hintText": "partition by device"
  51. }
  52. },
  53. "analyticsScriptTemplate":{
  54. "name": "compute",
  55. "metadata": {
  56. "deviceGroupId": "{{Device_group}}"
  57. },
  58. "query" : {
  59. "function" : {
  60. "type": "{{Function}}"
  61. },
  62. "groupBy": "{{GroupBy}}",
  63. "sensorName": "{{Sensor}}",
  64. "window" : {
  65. "type": "time",
  66. "args" : ["{{Window_Size}}", "{{Interval}}"]
  67. }
  68. }
  69. },
  70. "aliasesValues": {
  71. "Function": "avg",
  72. "Sensor": "Speed",
  73. "Window_Size": 10,
  74. "Interval": 1,
  75. "GroupBy": "device"
  76. }
  77. };
  78.  
  79. var all_device = {
  80. "name": "Some_sensor_all_devices",
  81. "description": "Show me: {{sensor}} of all devices",
  82. "aliases": {
  83. "sensor": {
  84. "type": "selector",
  85. "valueType": "sensor_name",
  86. "hintText": "Select sensor"
  87. }
  88. },
  89. "analyticsScriptTemplate": {
  90. "name": "identity",
  91. "query": {
  92. "sensorName": "{{sensor}}"
  93. }
  94. },
  95. "aliasesValues":{
  96. }
  97. };
  98.  
  99. var velocity_pattern_aggregator = {
  100. "name": "Velocity_with_pattern_aggregator",
  101. "description": "Show me when changing {{sensor}} by {{sensor_delta_value}}{{sensor_delta_unit}} " +
  102. "within {{duration}} " +
  103. "took {{time_delta_value}}{{time_delta_unit}} time to previous {{prev_dimension_count}}",
  104. "aliases": {
  105. "sensor": {
  106. "type": "selector",
  107. "valueType": "sensor_name",
  108. "hintText": "Select sensor"
  109. },
  110. "sensor_delta_value": {
  111. "type": "input",
  112. "inputType": "number",
  113. "hintText": ""
  114. },
  115. "sensor_delta_unit": {
  116. "type": "list",
  117. "values": {
  118. "%": "percent",
  119. "unit": "value"
  120. },
  121. "hintText": "Select units type"
  122. },
  123. "time_delta_value": {
  124. "type": "input",
  125. "inputType": "number",
  126. "hintText": "Input time delta"
  127. },
  128. "time_delta_unit": {
  129. "type": "list",
  130. "values": {
  131. "%": "percent",
  132. "unit": "value"
  133. },
  134. "hintText": "Select units type"
  135. },
  136. "prev_dimension_count": {
  137. "type": "input",
  138. "inputType": "number",
  139. "hintText": "Count of previous dimensions"
  140. },
  141. "duration": {
  142. "type": "input",
  143. "inputType": "number",
  144. "hintText": "hint",
  145. "multiplier": {
  146. "defaultValue": 1000,
  147. "hintText": "Select units",
  148. "values": {
  149. "sec": 1000,
  150. "min": 60000
  151. }
  152. }
  153. }
  154.  
  155. },
  156. "analyticsScriptTemplate": {
  157. "name": "velocity",
  158. "query": {
  159. "type": "{{time_delta_unit}}",
  160. "differenceValue": "{{time_delta_value}}",
  161. "valuesToCompare": "{{prev_dimension_count}}",
  162. "dimension": "time"
  163. },
  164. "streams": {
  165. "base": {
  166. "type": "query",
  167. "value": {
  168. "name": "patternAggregator",
  169. "query": {
  170. "type": "length"
  171. },
  172. "streams": {
  173. "base": {
  174. "type": "query",
  175. "value": {
  176. "name": "pattern",
  177. "query": {
  178. "durations": ["{{duration}}"],
  179. "patterns": {
  180. "{{sensor}}" : [
  181. {
  182. "type": "change",
  183. "args": ["{{sensor_delta_value}}", "{{sensor_delta_unit}}"]
  184. }
  185. ]
  186. },
  187. "matchPolicy": "oncePerMatch"
  188. }
  189. }
  190. }
  191. }
  192. }
  193. }
  194. }
  195. },
  196. "aliasesValues": {
  197. "sensor": "Speed",
  198. "sensor_delta_value": 10,
  199. "sensor_delta_unit": "value",
  200. "time_delta_value": 10,
  201. "time_delta_unit": "percent",
  202. "prev_dimension_count": 1,
  203. "duration": 4
  204. }
  205. };
  206.  
  207. var velocity_compute = {
  208. "name": "Velocity_with_compute",
  209. "description": "Show me when device have {{sensor}} changed by " +
  210. "{{sensor_delta_value}}{{sensor_delta_unit}} comparing to {{function}} " +
  211. "on {{prev_dimension_count}} previous {{dimension}}",
  212. "aliases": {
  213. "sensor": {
  214. "type": "selector",
  215. "valueType": "sensor_name",
  216. "hintText": "Select sensor"
  217. },
  218. "sensor_delta_value": {
  219. "type": "input",
  220. "inputType": "number",
  221. "hintText": ""
  222. },
  223. "sensor_delta_unit": {
  224. "type": "list",
  225. "values": {
  226. "%": "percent",
  227. "unit": "value"
  228. },
  229. "hintText": "Select units type"
  230. },
  231. "function": {
  232. "type": "aggregate-function",
  233. "hintText": "Select function"
  234. },
  235. "prev_dimension_count": {
  236. "type": "input",
  237. "inputType": "number",
  238. "hintText": "Count of previous dimensions"
  239. },
  240. "device_group": {
  241. "type": "device_group_selector",
  242. "hintText": "Select group"
  243. },
  244. "dimension": {
  245. "type": "input",
  246. "inputType": "text",
  247. "hintText": "Input dimension"
  248. }
  249. },
  250. "analyticsScriptTemplate": {
  251. "name": "velocity",
  252. "query": {
  253. "type": "{{sensor_delta_unit}}",
  254. "differenceValue": "{{sensor_delta_value}}",
  255. "valuesToCompare": "{{prev_dimension_count}}",
  256. "dimension": "{{dimension}}"
  257. },
  258. "streams": {
  259. "base": {
  260. "type": "query",
  261. "value": {
  262. "name": "compute",
  263. "query": {
  264. "function": {
  265. "type": "{{function}}"
  266. },
  267. "groupBy": "device",
  268. "sensorName": "{{sensor}}",
  269. "window": {
  270. "type": "dimension",
  271. "args": [ "{{dimension}}" ]
  272. }
  273. }
  274. }
  275. }
  276. }
  277. },
  278. "aliasesValues": {
  279. "sensor": "Speed",
  280. "sensor_delta_value": 10,
  281. "sensor_delta_unit": "value",
  282. "function": "avg",
  283. "prev_dimension_count": 1,
  284. "dimension": ""
  285. }
  286. };
  287.  
  288. riot.registerTemplate(simple_template);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement