status.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Status display</title>
  6. <meta name="description"
  7. content="Status display generated by BORA.">
  8. <link rel="stylesheet" href="{{ static_url("style.css") }}">
  9. <link rel="stylesheet" href="{{ static_url("jquery-ui.min.css") }}">
  10. <!--[if IE]>
  11. <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  12. <![endif]-->
  13. </head>
  14. <body>
  15. <div id="page_info">CPS data monitoring. Last refreshed</div>
  16. {% if data['style'] %}
  17. {% for key in data['style'] %}
  18. {% if data['style'][key]['type'] == "calc" %}
  19. <div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{
  20. data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px;
  21. height:{{ data['style'][key]['height'] }}px;'
  22. {% if "condition" in data['style'][key] %}
  23. data-cond="{{ data['style'][key]['condition'] }}"
  24. {% else%}position
  25. {% end%}
  26. {% if "formula" in data['style'][key] %}
  27. data-formula="{{ data['style'][key]['formula'] }}" tooltip="{{ data['style'][key]['formula'] }}"
  28. {% else %}
  29. {% end %}
  30. {% if "lesser" in data['style'][key] %}
  31. data-lesser="{{ data['style'][key]['lesser'] }}"
  32. {% else %}
  33. {% end %}
  34. {% if "larger" in data['style'][key] %}
  35. data-larger="{{ data['style'][key]['larger'] }}"
  36. {% else %}
  37. {% end %}
  38. data-type="{{ data['style'][key]['type'] }}" class='databox' id="{{ key }}">
  39. <p><span style="color: #000; font-size: {{ data['style'][key]['header']['size'] }}px; font-weight: {{ data['style'][key]['header']['weight'] }};" class="title">{{ data['style'][key]['header']['title'] }} </span><span style="color: #000; font-size: {{ data['style'][key]['unit']['size'] }}px; font-weight: {{ data['style'][key]['unit']['weight'] }};" class="varval"> XXX.XX </span><span class='unit_title' style="color: #000; font-size: {{ data['style'][key]['unit']['size'] }}px; font-weight: {{ data['style'][key]['unit']['weight'] }};" > {{ data['style'][key]['unit']['title'] }}</span></p>
  40. </div>
  41. {% else %}
  42. {% end %}
  43. {% if data['style'][key]['type'] == "data" %}
  44. {% if "ref" in data['style'][key] %}
  45. <div tooltip="{{ data['style'][key]['ref'] }}"
  46. {% else %}
  47. <div tooltip="{{ key }}"
  48. {% end %}
  49. class="databox" style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{ data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px; height:{{ data['style'][key]['height'] }}px;'
  50. {% if "condition" in data['style'][key] %}
  51. data-cond="{{ data['style'][key]['condition'] }}"
  52. {% else%}
  53. {% end%}
  54. {% if "formula" in data['style'][key] %}
  55. data-formula="{{ data['style'][key]['formula'] }}"
  56. {% else %}
  57. {% end %}
  58. {% if "lesser" in data['style'][key] %}
  59. data-lesser="{{ data['style'][key]['lesser'] }}"
  60. {% else %}
  61. {% end %}
  62. {% if "larger" in data['style'][key] %}
  63. data-larger="{{ data['style'][key]['larger'] }}"
  64. {% else %}
  65. {% end %}
  66. {% if "ref" in data['style'][key] %}
  67. data-type="{{ data['style'][key]['type'] }}" onclick="window.open('http://katrin.kit.edu/adei-katrin/#module=graph&{{ data['style'][key]['ref'] }}&experiment=-&window=0&module=graph&virtual=srctree&srctree=&infomod=legend', '_blank');" id="{{ key }}">
  68. <p><span style="color: #000; font-size: {{ data['style'][key]['header']['size'] }}px; font-weight: {{ data['style'][key]['header']['weight'] }};" class="title">{{ data['style'][key]['header']['title'] }} </span><span style="color: #000; font-size: {{ data['style'][key]['unit']['size'] }}px; font-weight: {{ data['style'][key]['unit']['weight'] }};" class="varval"> XXX.XX </span><span class='unit_title' style="color: #000; font-size: {{ data['style'][key]['unit']['size'] }}px; font-weight: {{ data['style'][key]['unit']['weight'] }};"> {{ data['style'][key]['unit']['title'] }}</span></p>
  69. </div>
  70. {% else %}
  71. data-type="{{ data['style'][key]['type'] }}" onclick="window.open('http://katrin.kit.edu/adei-katrin/#module=graph&{{ data['varname'][key]}}&experiment=-&window=0&module=graph&virtual=srctree&srctree=&infomod=legend', '_blank');" id="{{ key }}">
  72. <p><span style="color: #000; font-size: {{ data['style'][key]['header']['size'] }}px; font-weight: {{ data['style'][key]['header']['weight'] }};" class="title">{{ data['style'][key]['header']['title'] }} </span><span style="color: #000; font-size: {{ data['style'][key]['unit']['size'] }}px; font-weight: {{ data['style'][key]['unit']['weight'] }};" class="varval"> XXX.XX </span><span class='unit_title' style="color: #000; font-size: {{ data['style'][key]['unit']['size'] }}px; font-weight: {{ data['style'][key]['unit']['weight'] }};"> {{ data['style'][key]['unit']['title'] }}</span></p>
  73. </div>
  74. {% end %}
  75. {% else %}
  76. {% end %}
  77. {% if data['style'][key]['type'] == "ventil" %}
  78. <div tooltip="{{ key }}" style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{ data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px; height:{{ data['style'][key]['height'] }}px;' data-type="{{ data['style'][key]['type'] }}" data-off="{{ data['style'][key]['off'] }}" data-on="{{ data['style'][key]['on'] }}" onclick="window.open('http://katrin.kit.edu/adei-katrin/#module=graph&{{ data['varname'][key]}}&experiment=-&window=0&module=graph&virtual=srctree&srctree=&infomod=legend', '_blank');" class='databox' id="{{ key }}">
  79. <img width='100%' height='100%' src='{{ static_url("ventil_inactive.png") }}'></img>
  80. </div>
  81. {% else %}
  82. {% end %}
  83. {% if data['style'][key]['type'] == "integer-to-string" %}
  84. <div tooltip="{{ key }}" style='position: absolute; top: {{
  85. data['style'][key]['top'] }}; left:{{ data['style'][key]['left'] }};
  86. width:{{ data['style'][key]['width'] }}px; height:{{
  87. data['style'][key]['height'] }}px;'
  88. {% if "cond" in data['style'][key] %}
  89. data-cond="{{ data['style'][key]['cond'] }}"
  90. {% else %}
  91. {% end %}
  92. data-dict="{{ data['style'][key]['dict'] }}" data-type="{{ data['style'][key]['type'] }}" onclick="window.open('http://katrin.kit.edu/adei-katrin/#module=graph&{{ data['varname'][key]}}&experiment=-&window=0&module=graph&virtual=srctree&srctree=&infomod=legend', '_blank');" class='databox' id="{{ key }}">
  93. <p><span style="color: #000; font-size: {{ data['style'][key]['header']['size'] }}px; font-weight: {{ data['style'][key]['header']['weight'] }};" class="title">{{ data['style'][key]['header']['title'] }} </span><br /><span style="color: #000; font-size: {{ data['style'][key]['unit']['size'] }}px; font-weight: {{ data['style'][key]['unit']['weight'] }};" class="varval">--- </span></p>
  94. </div>
  95. {% else %}
  96. {% end %}
  97. {% if data['style'][key]['type'] == "header" %}
  98. <div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{
  99. data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px;
  100. height:{{ data['style'][key]['height'] }}px;' data-type="{{
  101. data['style'][key]['type'] }}" class='databox' id="{{ key }}">
  102. <p><span style="color: #000; font-size: {{ data['style'][key]['header']['size'] }}px; font-weight: {{ data['style'][key]['header']['weight'] }};" class="title">{{ data['style'][key]['header']['title'] }} </span></p>
  103. </div>
  104. {% else %}
  105. {% end %}
  106. {% end %}
  107. {% else %}
  108. {% end %}
  109. <img src="{{ static_url('background.png') }}"></img>
  110. <!-- java script -->
  111. <script src="{{ static_url("jquery-1.12.3.min.js") }}"></script>
  112. <script src="{{ static_url("jquery-ui.min.js") }}"></script>
  113. <script src="{{ static_url("math.min.js") }}"></script>
  114. <script>
  115. jQuery(window).load(function () {
  116. myTimer();
  117. var myVar = setInterval(myTimer, 10000);
  118. function myTimer() {
  119. var dataToSend = {};
  120. $.ajax({
  121. url: '/getdata/',
  122. type: 'GET',
  123. data: dataToSend,
  124. success: function (response) {
  125. //var objresponse = JSON.parse(response);
  126. console.log(response);
  127. for (var key in response) {
  128. //console.log(key, response[key]);
  129. data_type = $("#" + key).attr('data-type');
  130. if($("#" + key).length > 0) {
  131. if (data_type == "data") {
  132. var datavalue, set_color, formula;
  133. var formula_attr = $("#" + key).attr('data-formula');
  134. if (response[key]) {
  135. if (formula_attr) {
  136. datavalue = parseFloat(response[key]).toFixed(2);
  137. formula = formula_attr.replace("x", datavalue.toString());
  138. datavalue = math.round(math.eval(formula),2);
  139. datavalue = datavalue.toFixed(2);
  140. } else {
  141. datavalue = parseFloat(response[key]).toFixed(2);
  142. }
  143. set_color = "green";
  144. } else {
  145. datavalue = "---";
  146. set_color = "black";
  147. }
  148. $(".varval", "#" + key).text(datavalue);
  149. var condition_attr = $("#" + key).attr('data-cond');
  150. var lesser_attr = $("#" + key).attr('data-lesser');
  151. var larger_attr = $("#" + key).attr('data-larger');
  152. //console.log(condition_attr);
  153. if (condition_attr) {
  154. if (response[key] == condition_attr) {
  155. set_color = "red";
  156. }
  157. }
  158. if (lesser_attr) {
  159. if (parseFloat(response[key]) < parseFloat(lesser_attr)) {
  160. set_color = "red";
  161. }
  162. }
  163. if (larger_attr) {
  164. if (parseFloat(response[key]) > parseFloat(larger_attr)) {
  165. set_color = "red";
  166. }
  167. }
  168. $(".varval", "#" + key).css("color", set_color);
  169. $(".unit_title", "#" + key).css("color", set_color);
  170. } else if (data_type == "ventil") {
  171. var on_attr = $("#" + key).attr('data-on');
  172. var off_attr = $("#" + key).attr('data-off');
  173. if (parseFloat(response[key]) == parseFloat(on_attr)) {
  174. $("img", "#" + key).attr("src", "{{ static_url('ventil_green.png') }}");
  175. }
  176. if (parseFloat(response[key]) == parseFloat(off_attr)) {
  177. $("img", "#" + key).attr("src", "{{ static_url('ventil_red.png') }}");
  178. }
  179. } else if (data_type == "integer-to-string") {
  180. var dict_attr = JSON.parse($("#" + key).attr('data-dict'));
  181. var dict_cond;
  182. if ($("#"+key).attr("data-cond")) {
  183. dict_cond = JSON.parse($("#" + key).attr('data-cond'));
  184. } else {
  185. dict_cond = {};
  186. }
  187. var dict_color = "";
  188. if (key in response) {
  189. var token = response[key];
  190. if (token in dict_cond) {
  191. dict_color = dict_cond[token];
  192. }
  193. }
  194. $(".varval", "#" + key).css("color", dict_color);
  195. $(".varval", "#" + key).text(dict_attr[response[key]]);
  196. }
  197. }
  198. }
  199. $('[id^=virtual_]').each(function( index ) {
  200. var vkey = this.id;
  201. var ref = vkey.split("_");
  202. ref = ref[1];
  203. data_type = $("#" + vkey).attr('data-type');
  204. if($("#" + vkey).length > 0) {
  205. if (data_type == "data") {
  206. console.log(vkey);
  207. var datavalue, set_color, formula;
  208. var formula_attr = $("#" + vkey).attr('data-formula');
  209. if (response[ref]) {
  210. if (formula_attr) {
  211. datavalue = parseFloat(response[ref]).toFixed(2);
  212. formula = formula_attr.replace("x", datavalue.toString());
  213. datavalue = math.round(math.eval(formula),2);
  214. datavalue = datavalue.toFixed(2);
  215. } else {
  216. datavalue = parseFloat(response[ref]).toFixed(2);
  217. }
  218. set_color = "green";
  219. } else {
  220. datavalue = "---";
  221. set_color = "black";
  222. }
  223. $(".varval", "#" + vkey).text(datavalue);
  224. var condition_attr = $("#" + vkey).attr('data-cond');
  225. var lesser_attr = $("#" + vkey).attr('data-lesser');
  226. var larger_attr = $("#" + vkey).attr('data-larger');
  227. //console.log(condition_attr);
  228. if (condition_attr) {
  229. if (response[ref] == condition_attr) {
  230. set_color = "red";
  231. }
  232. }
  233. if (lesser_attr) {
  234. if (parseFloat(response[ref]) < parseFloat(lesser_attr)) {
  235. set_color = "red";
  236. }
  237. }
  238. if (larger_attr) {
  239. if (parseFloat(response[ref]) > parseFloat(larger_attr)) {
  240. set_color = "red";
  241. }
  242. }
  243. $(".varval", "#" + vkey).css("color", set_color);
  244. $(".unit_title", "#" + vkey).css("color", set_color);
  245. } else if (data_type == "ventil") {
  246. var on_attr = $("#" + key).attr('data-on');
  247. var off_attr = $("#" + key).attr('data-off');
  248. if (parseFloat(response[ref]) == parseFloat(on_attr)) {
  249. $("img", "#" + key).attr("src", "{{ static_url('ventil_green.png') }}");
  250. }
  251. if (parseFloat(response[ref]) == parseFloat(off_attr)) {
  252. $("img", "#" + key).attr("src", "{{ static_url('ventil_red.png') }}");
  253. }
  254. } else if (data_type == "integer-to-string") {
  255. var dict_attr = JSON.parse($("#" + key).attr('data-dict'));
  256. var dict_cond;
  257. if ($("#"+key).attr("data-cond")) {
  258. dict_cond = JSON.parse($("#" + key).attr('data-cond'));
  259. } else {
  260. dict_cond = {};
  261. }
  262. var dict_color = "";
  263. if (ref in response) {
  264. var token = response[ref];
  265. if (token in dict_cond) {
  266. dict_color = dict_cond[token];
  267. }
  268. }
  269. $(".varval", "#" + key).css("color", dict_color);
  270. $(".varval", "#" + key).text(dict_attr[response[ref]]);
  271. }
  272. }
  273. });
  274. $('[id^=calc_]').each(function( index ) {
  275. console.log(this.id);
  276. console.log($(this).attr('data-formula'));
  277. var myformula = $(this).attr('data-formula').trim();
  278. /*
  279. myformula = myformula.replace(/\[.*?\]/g, '__');
  280. console.log(myformula);
  281. */
  282. var data = myformula;
  283. var re= /\[(.*?)\]/g;
  284. var buffer = []
  285. for(m = re.exec(data); m; m = re.exec(data)){
  286. buffer.push(m[1]);
  287. }
  288. console.log(buffer);
  289. var finalstring = "";
  290. var pattern = /\[(.*?)\]/g;
  291. var teststring = myformula.split(" ");
  292. console.log(teststring);
  293. console.log(finalstring);
  294. for (var i = 0; i < teststring.length; i++) {
  295. var val = "";
  296. if (pattern.exec(teststring[i]) != null) {
  297. var cleanref = teststring[i].replace(/[\[\]']+/g,'');
  298. val = response[cleanref];
  299. } else {
  300. val = teststring[i];
  301. }
  302. finalstring += val;
  303. finalstring += " ";
  304. }
  305. finalstring = finalstring.trim();
  306. console.log(finalstring);
  307. var myvalue = math.round(math.eval(finalstring),2);
  308. myvalue = myvalue.toFixed(2);
  309. set_color = "green";
  310. console.log(myvalue);
  311. $(".varval", "#" + this.id).text(myvalue);
  312. var condition_attr = $("#" + this.id).attr('data-cond');
  313. var lesser_attr = $("#" + this.id).attr('data-lesser');
  314. var larger_attr = $("#" + this.id).attr('data-larger');
  315. //console.log(condition_attr);
  316. if (condition_attr) {
  317. if (myvalue == condition_attr) {
  318. set_color = "red";
  319. }
  320. }
  321. if (lesser_attr) {
  322. if (parseFloat(myvalue) < parseFloat(lesser_attr)) {
  323. set_color = "red";
  324. }
  325. }
  326. if (larger_attr) {
  327. if (parseFloat(myvalue) > parseFloat(larger_attr)) {
  328. set_color = "red";
  329. }
  330. }
  331. $(".varval", "#" + this.id).css("color", set_color);
  332. $(".unit_title", "#" + this.id).css("color", set_color);
  333. });
  334. var datetime = "CPS data monitoring page. Last Sync: " + response["time"];
  335. $("#page_info").text(datetime);
  336. console.log(datetime);
  337. },
  338. error: function () {
  339. console.log("Error.")
  340. }
  341. });
  342. }
  343. });
  344. </script>
  345. </body>
  346. </html>