status.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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['varname'][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. {% if "background" in data %}
  110. <img src="{{ static_url( data['background'] ) }}"></img>
  111. {% else %}
  112. <img src="{{ static_url( 'background.png' ) }}"></img>
  113. {% end %}
  114. <!-- java script -->
  115. <script src="{{ static_url("jquery-1.12.3.min.js") }}"></script>
  116. <script src="{{ static_url("jquery-ui.min.js") }}"></script>
  117. <script src="{{ static_url("math.min.js") }}"></script>
  118. <script>
  119. jQuery(window).load(function () {
  120. myTimer();
  121. var myVar = setInterval(myTimer, 10000);
  122. function myTimer() {
  123. var dataToSend = {};
  124. $.ajax({
  125. url: '/getdata/',
  126. type: 'GET',
  127. data: dataToSend,
  128. success: function (response) {
  129. //var objresponse = JSON.parse(response);
  130. console.log(response);
  131. for (var key in response) {
  132. //console.log(key, response[key]);
  133. data_type = $("#" + key).attr('data-type');
  134. if($("#" + key).length > 0) {
  135. if (data_type == "data") {
  136. var datavalue, set_color, formula;
  137. var formula_attr = $("#" + key).attr('data-formula');
  138. if (response[key]) {
  139. if (formula_attr) {
  140. datavalue = parseFloat(response[key]).toFixed(2);
  141. formula = formula_attr.replace("x", datavalue.toString());
  142. datavalue = math.round(math.eval(formula),2);
  143. datavalue = datavalue.toFixed(2);
  144. } else {
  145. datavalue = parseFloat(response[key]).toFixed(2);
  146. }
  147. set_color = "green";
  148. } else {
  149. datavalue = "---";
  150. set_color = "black";
  151. }
  152. $(".varval", "#" + key).text(datavalue);
  153. var condition_attr = $("#" + key).attr('data-cond');
  154. var lesser_attr = $("#" + key).attr('data-lesser');
  155. var larger_attr = $("#" + key).attr('data-larger');
  156. //console.log(condition_attr);
  157. if (condition_attr) {
  158. if (response[key] == condition_attr) {
  159. set_color = "red";
  160. }
  161. }
  162. if (lesser_attr) {
  163. if (parseFloat(response[key]) < parseFloat(lesser_attr)) {
  164. set_color = "red";
  165. }
  166. }
  167. if (larger_attr) {
  168. if (parseFloat(response[key]) > parseFloat(larger_attr)) {
  169. set_color = "red";
  170. }
  171. }
  172. $(".varval", "#" + key).css("color", set_color);
  173. $(".unit_title", "#" + key).css("color", set_color);
  174. } else if (data_type == "ventil") {
  175. var on_attr = $("#" + key).attr('data-on');
  176. var off_attr = $("#" + key).attr('data-off');
  177. if (parseFloat(response[key]) == parseFloat(on_attr)) {
  178. $("img", "#" + key).attr("src", "{{ static_url('ventil_green.png') }}");
  179. }
  180. if (parseFloat(response[key]) == parseFloat(off_attr)) {
  181. $("img", "#" + key).attr("src", "{{ static_url('ventil_red.png') }}");
  182. }
  183. } else if (data_type == "integer-to-string") {
  184. var dict_attr = JSON.parse($("#" + key).attr('data-dict'));
  185. var dict_cond;
  186. if ($("#"+key).attr("data-cond")) {
  187. dict_cond = JSON.parse($("#" + key).attr('data-cond'));
  188. } else {
  189. dict_cond = {};
  190. }
  191. var dict_color = "";
  192. if (key in response) {
  193. var token = response[key];
  194. if (token in dict_cond) {
  195. dict_color = dict_cond[token];
  196. }
  197. }
  198. $(".varval", "#" + key).css("color", dict_color);
  199. $(".varval", "#" + key).text(dict_attr[response[key]]);
  200. }
  201. }
  202. }
  203. $('[id^=virtual_]').each(function( index ) {
  204. var key = this.id;
  205. var ref = key.split("_");
  206. ref = ref[1];
  207. data_type = $("#" + key).attr('data-type');
  208. if($("#" + key).length > 0) {
  209. if (data_type == "data") {
  210. console.log(key);
  211. var datavalue, set_color, formula;
  212. var formula_attr = $("#" + key).attr('data-formula');
  213. if (response[ref]) {
  214. if (formula_attr) {
  215. datavalue = parseFloat(response[ref]).toFixed(2);
  216. formula = formula_attr.replace("x", datavalue.toString());
  217. datavalue = math.round(math.eval(formula),2);
  218. datavalue = datavalue.toFixed(2);
  219. } else {
  220. datavalue = parseFloat(response[ref]).toFixed(2);
  221. }
  222. set_color = "green";
  223. } else {
  224. datavalue = "---";
  225. set_color = "black";
  226. }
  227. $(".varval", "#" + key).text(datavalue);
  228. var condition_attr = $("#" + key).attr('data-cond');
  229. var lesser_attr = $("#" + key).attr('data-lesser');
  230. var larger_attr = $("#" + key).attr('data-larger');
  231. //console.log(condition_attr);
  232. if (condition_attr) {
  233. if (response[ref] == condition_attr) {
  234. set_color = "red";
  235. }
  236. }
  237. if (lesser_attr) {
  238. if (parseFloat(response[ref]) < parseFloat(lesser_attr)) {
  239. set_color = "red";
  240. }
  241. }
  242. if (larger_attr) {
  243. if (parseFloat(response[ref]) > parseFloat(larger_attr)) {
  244. set_color = "red";
  245. }
  246. }
  247. $(".varval", "#" + key).css("color", set_color);
  248. $(".unit_title", "#" + key).css("color", set_color);
  249. } else if (data_type == "ventil") {
  250. var on_attr = $("#" + key).attr('data-on');
  251. var off_attr = $("#" + key).attr('data-off');
  252. if (parseFloat(response[ref]) == parseFloat(on_attr)) {
  253. $("img", "#" + key).attr("src", "{{ static_url('ventil_green.png') }}");
  254. }
  255. if (parseFloat(response[ref]) == parseFloat(off_attr)) {
  256. $("img", "#" + key).attr("src", "{{ static_url('ventil_red.png') }}");
  257. }
  258. } else if (data_type == "integer-to-string") {
  259. var dict_attr = JSON.parse($("#" + key).attr('data-dict'));
  260. var dict_cond;
  261. if ($("#"+key).attr("data-cond")) {
  262. dict_cond = JSON.parse($("#" + key).attr('data-cond'));
  263. } else {
  264. dict_cond = {};
  265. }
  266. var dict_color = "";
  267. if (ref in response) {
  268. var token = response[ref];
  269. if (token in dict_cond) {
  270. dict_color = dict_cond[token];
  271. }
  272. }
  273. $(".varval", "#" + key).css("color", dict_color);
  274. $(".varval", "#" + key).text(dict_attr[response[ref]]);
  275. }
  276. }
  277. });
  278. $('[id^=calc_]').each(function( index ) {
  279. console.log(this.id);
  280. console.log($(this).attr('data-formula'));
  281. var myformula = $(this).attr('data-formula').trim();
  282. /*
  283. myformula = myformula.replace(/\[.*?\]/g, '__');
  284. console.log(myformula);
  285. */
  286. var data = myformula;
  287. var re= /\[(.*?)\]/g;
  288. var buffer = []
  289. for(m = re.exec(data); m; m = re.exec(data)){
  290. buffer.push(m[1]);
  291. }
  292. console.log("Debug:");
  293. console.log(buffer);
  294. var finalstring = "";
  295. var pattern = /\[(.*?)\]/g;
  296. var teststring = myformula.split(/[\[\]]+/);
  297. console.log(teststring);
  298. console.log(finalstring);
  299. for (var i = 0; i < teststring.length; i++) {
  300. var val = "";
  301. if (teststring[i] in response) {
  302. val = response[teststring[i]];
  303. } else {
  304. val = teststring[i];
  305. }
  306. finalstring += val;
  307. finalstring += " ";
  308. }
  309. finalstring = finalstring.trim();
  310. console.log(finalstring);
  311. var myvalue = math.round(math.eval(finalstring),2);
  312. myvalue = myvalue.toFixed(2);
  313. set_color = "green";
  314. console.log(myvalue);
  315. $(".varval", "#" + this.id).text(myvalue);
  316. var condition_attr = $("#" + this.id).attr('data-cond');
  317. var lesser_attr = $("#" + this.id).attr('data-lesser');
  318. var larger_attr = $("#" + this.id).attr('data-larger');
  319. //console.log(condition_attr);
  320. if (condition_attr) {
  321. if (myvalue == condition_attr) {
  322. set_color = "red";
  323. }
  324. }
  325. if (lesser_attr) {
  326. if (parseFloat(myvalue) < parseFloat(lesser_attr)) {
  327. set_color = "red";
  328. }
  329. }
  330. if (larger_attr) {
  331. if (parseFloat(myvalue) > parseFloat(larger_attr)) {
  332. set_color = "red";
  333. }
  334. }
  335. $(".varval", "#" + this.id).css("color", set_color);
  336. $(".unit_title", "#" + this.id).css("color", set_color);
  337. });
  338. var datetime = "CPS data monitoring page. Last Sync: " + response["time"];
  339. $("#page_info").text(datetime);
  340. console.log(datetime);
  341. },
  342. error: function () {
  343. console.log("Error.")
  344. }
  345. });
  346. }
  347. });
  348. </script>
  349. </body>
  350. </html>