status.html 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>{{ data['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">{{ data['title'] }} data monitoring. Last refreshed</div>
  16. <div id="page_title_cache" style="display:none;">{{ data['title'] }}</div>
  17. {% if data['style'] %}
  18. {% for key in data['style'] %}
  19. {% if data['style'][key]['type'] == "calc" %}
  20. <div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{
  21. data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px;
  22. height:{{ data['style'][key]['height'] }}px; background-color:{{ data['style'][key]['background_color'] }};'
  23. {% if "condition" in data['style'][key] %}
  24. data-cond="{{ data['style'][key]['condition'] }}"
  25. {% else%}position
  26. {% end%}
  27. {% if "formula" in data['style'][key] %}
  28. data-formula="{{ data['style'][key]['formula'] }}" tooltip="{{ data['style'][key]['formula'] }}"
  29. {% else %}
  30. {% end %}
  31. {% if "lesser" in data['style'][key] %}
  32. data-lesser="{{ data['style'][key]['lesser'] }}"
  33. {% else %}
  34. {% end %}
  35. {% if "larger" in data['style'][key] %}
  36. data-larger="{{ data['style'][key]['larger'] }}"
  37. {% else %}
  38. {% end %}
  39. data-type="{{ data['style'][key]['type'] }}" class='databox' id="{{ key }}">
  40. <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"> --- </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>
  41. </div>
  42. {% else %}
  43. {% end %}
  44. {% if data['style'][key]['type'] == "data" %}
  45. {% if "ref" in data['style'][key] %}
  46. <div tooltip="{{ data['style'][key]['ref'] }}"
  47. {% else %}
  48. <div tooltip="{{ key }}"
  49. {% end %}
  50. 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; background-color:{{ data['style'][key]['background_color'] }};'
  51. {% if "condition" in data['style'][key] %}
  52. data-cond="{{ data['style'][key]['condition'] }}"
  53. {% else%}
  54. {% end%}
  55. {% if "formula" in data['style'][key] %}
  56. data-formula="{{ data['style'][key]['formula'] }}"
  57. {% else %}
  58. {% end %}
  59. {% if "lesser" in data['style'][key] %}
  60. data-lesser="{{ data['style'][key]['lesser'] }}"
  61. {% else %}
  62. {% end %}
  63. {% if "larger" in data['style'][key] %}
  64. data-larger="{{ data['style'][key]['larger'] }}"
  65. {% else %}
  66. {% end %}
  67. {% if "exponential" in data['style'][key] %}
  68. data-exponential="{{ data['style'][key]['exponential'] }}"
  69. {% else %}
  70. {% end %}
  71. {% if "ref" in data['style'][key] %}
  72. data-type="{{ data['style'][key]['type'] }}" onclick="window.open('http://pcebessadei.competence-e.kit.edu/adei-battery/#module=graph&{{ data['varname'][data['style'][key]['ref']] }}&experiment=-&window=86400&module=graph&virtual=srctree&srctree=&infomod=legend', '_blank');" id="{{ key }}">
  73. <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"> --- </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>
  74. </div>
  75. {% else %}
  76. data-type="{{ data['style'][key]['type'] }}" onclick="window.open('http://pcebessadei.competence-e.kit.edu/adei-battery/#module=graph&{{ data['varname'][key]}}&experiment=-&window=86400&module=graph&virtual=srctree&srctree=&infomod=legend', '_blank');" id="{{ key }}">
  77. <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"> --- </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>
  78. </div>
  79. {% end %}
  80. {% else %}
  81. {% end %}
  82. {% if data['style'][key]['type'] == "valve" %}
  83. {% if "ref" in data['style'][key] %}
  84. <div tooltip="{{ data['style'][key]['ref'] }}"
  85. {% else %}
  86. <div tooltip="{{ key }}"
  87. {% end %}
  88. 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;'
  89. {% if "ref" in data['style'][key] %}
  90. data-type="{{ data['style'][key]['type'] }}" data-off="{{ data['style'][key]['off'] }}" data-on="{{ data['style'][key]['on'] }}" onclick="window.open('http://pcebessadei.competence-e.kit.edu/adei-battery/#module=graph&{{ data['varname'][data['style'][key]['ref']]}}&experiment=-&window=86400&module=graph&virtual=srctree&srctree=&infomod=legend', '_blank');" class='databox' id="{{ key }}">
  91. <img width='100%' height='100%' src='{{ static_url("ventil_inactive.png") }}'></img>
  92. </div>
  93. {% else %}
  94. data-type="{{ data['style'][key]['type'] }}" data-off="{{ data['style'][key]['off'] }}" data-on="{{ data['style'][key]['on'] }}" onclick="window.open('http://pcebessadei.competence-e.kit.edu/adei-battery/#module=graph&{{ data['varname'][key]}}&experiment=-&window=86400&module=graph&virtual=srctree&srctree=&infomod=legend', '_blank');" class='databox' id="{{ key }}">
  95. <img width='100%' height='100%' src='{{ static_url("ventil_inactive.png") }}'></img>
  96. {% end %}
  97. {% else %}
  98. {% end %}
  99. {% if data['style'][key]['type'] == "commbit" %}
  100. {% if "ref" in data['style'][key] %}
  101. <div tooltip="{{ data['style'][key]['ref'] }}"
  102. {% else %}
  103. <div tooltip="{{ key }}"
  104. {% end %}
  105. 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;'
  106. {% if "ref" in data['style'][key] %}
  107. data-type="{{ data['style'][key]['type'] }}" data-off="{{ data['style'][key]['off'] }}" data-on="{{ data['style'][key]['on'] }}" onclick="window.open('http://pcebessadei.competence-e.kit.edu/adei-battery/#module=graph&{{ data['varname'][data['style'][key]['ref']]}}&experiment=-&window=86400&module=graph&virtual=srctree&srctree=&infomod=legend', '_blank');" class='databox' id="{{ key }}">
  108. <img width='100%' height='100%' src='{{ static_url("Bit_inactive.svg") }}'></img>
  109. </div>
  110. {% else %}
  111. data-type="{{ data['style'][key]['type'] }}" data-off="{{ data['style'][key]['off'] }}" data-on="{{ data['style'][key]['on'] }}" onclick="window.open('http://pcebessadei.competence-e.kit.edu/adei-battery/#module=graph&{{ data['varname'][key]}}&experiment=-&window=86400&module=graph&virtual=srctree&srctree=&infomod=legend', '_blank');" class='databox' id="{{ key }}">
  112. <img width='100%' height='100%' src='{{ static_url("Bit_inactive.svg") }}'></img>
  113. </div>
  114. {% end %}
  115. {% else %}
  116. {% end %}
  117. {% if data['style'][key]['type'] == "alarm" %}
  118. {% if "ref" in data['style'][key] %}
  119. <div tooltip="{{ data['style'][key]['ref'] }}"
  120. {% else %}
  121. <div tooltip="{{ key }}"
  122. {% end %}
  123. 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;'
  124. {% if "ref" in data['style'][key] %}
  125. data-type="{{ data['style'][key]['type'] }}" data-off="{{ data['style'][key]['off'] }}" data-on="{{ data['style'][key]['on'] }}" onclick="window.open('http://pcebessadei.competence-e.kit.edu/adei-battery/#module=graph&{{ data['varname'][data['style'][key]['ref']]}}&experiment=-&window=86400&module=graph&virtual=srctree&srctree=&infomod=legend', '_blank');" class='databox' id="{{ key }}">
  126. <img width='100%' height='100%' src='{{ static_url("alarm_inactive.svg") }}'></img>
  127. </div>
  128. {% else %}
  129. data-type="{{ data['style'][key]['type'] }}" data-off="{{ data['style'][key]['off'] }}" data-on="{{ data['style'][key]['on'] }}" onclick="window.open('http://pcebessadei.competence-e.kit.edu/adei-battery/#module=graph&{{ data['varname'][key]}}&experiment=-&window=86400&module=graph&virtual=srctree&srctree=&infomod=legend', '_blank');" class='databox' id="{{ key }}">
  130. <img width='100%' height='100%' src='{{ static_url("alarm_inactive.svg") }}'></img>
  131. </div>
  132. {% end %}
  133. {% else %}
  134. {% end %}
  135. {% if data['style'][key]['type'] == "integer-to-string" %}
  136. <div tooltip="{{ key }}" style='position: absolute; top: {{
  137. data['style'][key]['top'] }}; left:{{ data['style'][key]['left'] }};
  138. width:{{ data['style'][key]['width'] }}px; height:{{
  139. data['style'][key]['height'] }}px; background-color:{{ data['style'][key]['background_color'] }};'
  140. {% if "cond" in data['style'][key] %}
  141. data-cond="{{ data['style'][key]['cond'] }}"
  142. {% else %}
  143. {% end %}
  144. data-dict="{{ data['style'][key]['dict'] }}" data-type="{{ data['style'][key]['type'] }}" onclick="window.open('http://pcebessadei.competence-e.kit.edu/adei-battery/#module=graph&{{ data['varname'][key]}}&experiment=-&window=86400&module=graph&virtual=srctree&srctree=&infomod=legend', '_blank');" class='databox' id="{{ key }}">
  145. <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>
  146. </div>
  147. {% else %}
  148. {% end %}
  149. {% if data['style'][key]['type'] == "header" %}
  150. <div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{
  151. data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px;
  152. height:{{ data['style'][key]['height'] }}px; background-color:{{ data['style'][key]['background_color'] }};' data-type="{{
  153. data['style'][key]['type'] }}" class='databox' id="{{ key }}">
  154. <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>
  155. </div>
  156. {% else %}
  157. {% end %}
  158. {% end %}
  159. {% else %}
  160. {% end %}
  161. {% if "background" in data %}
  162. <img src="{{ static_url( data['background'] ) }}"></img>
  163. {% else %}
  164. <img src="{{ static_url( 'background.png' ) }}"></img>
  165. {% end %}
  166. <!-- java script -->
  167. <script src="{{ static_url("jquery-1.12.3.min.js") }}"></script>
  168. <script src="{{ static_url("jquery-ui.min.js") }}"></script>
  169. <script src="{{ static_url("math.min.js") }}"></script>
  170. <script>
  171. jQuery(window).load(function () {
  172. myTimer();
  173. var myVar = setInterval(myTimer, 10000);
  174. function myTimer() {
  175. var dataToSend = {};
  176. $.ajax({
  177. url: '/getdata/',
  178. type: 'GET',
  179. data: dataToSend,
  180. success: function (response) {
  181. //var objresponse = JSON.parse(response);
  182. console.log(response);
  183. for (var key in response) {
  184. //console.log(key, response[key]);
  185. data_type = $("#" + key).attr('data-type');
  186. if($("#" + key).length > 0) {
  187. if (data_type == "data") {
  188. //console.log("data");
  189. var datavalue, set_color, formula;
  190. var formula_attr = $("#" + key).attr('data-formula');
  191. if (response[key]) {
  192. if (formula_attr) {
  193. datavalue = parseFloat(response[key]).toFixed(2);
  194. formula = formula_attr.replace("x", datavalue.toString());
  195. datavalue = math.round(math.eval(formula),2);
  196. datavalue = datavalue.toFixed(2);
  197. } else {
  198. if ( ($("#" + key).attr('data-exponential')) == "True" || ($("#" + key).attr('data-exponential')) == "true" ) {
  199. datavalue = parseFloat(response[key]);
  200. datavalue = datavalue.toExponential(2)
  201. } else {
  202. datavalue = parseFloat(response[key]).toFixed(2);
  203. }
  204. }
  205. set_color = "green";
  206. } else {
  207. datavalue = "---";
  208. set_color = "black";
  209. }
  210. $(".varval", "#" + key).text(datavalue);
  211. var condition_attr = $("#" + key).attr('data-cond');
  212. var lesser_attr = $("#" + key).attr('data-lesser');
  213. var larger_attr = $("#" + key).attr('data-larger');
  214. //console.log(condition_attr);
  215. if (condition_attr) {
  216. if (response[key] == condition_attr) {
  217. set_color = "red";
  218. }
  219. }
  220. if (lesser_attr) {
  221. if (parseFloat(response[key]) < parseFloat(lesser_attr)) {
  222. set_color = "red";
  223. }
  224. }
  225. if (larger_attr) {
  226. if (parseFloat(response[key]) > parseFloat(larger_attr)) {
  227. set_color = "red";
  228. }
  229. }
  230. $(".varval", "#" + key).css("color", set_color);
  231. $(".unit_title", "#" + key).css("color", set_color);
  232. } else if (data_type == "ventil") {
  233. //console.log("ventil");
  234. var on_attr = $("#" + key).attr('data-on');
  235. var off_attr = $("#" + key).attr('data-off');
  236. if (parseFloat(response[key]) == parseFloat(on_attr)) {
  237. $("img", "#" + key).attr("src", "{{ static_url('ventil_green.png') }}");
  238. }
  239. if (parseFloat(response[key]) == parseFloat(off_attr)) {
  240. $("img", "#" + key).attr("src", "{{ static_url('ventil_red.png') }}");
  241. }
  242. } else if (data_type == "commbit") {
  243. //console.log("commbit");
  244. var on_attr = $("#" + key).attr('data-on');
  245. var off_attr = $("#" + key).attr('data-off');
  246. if (parseFloat(response[key]) == parseFloat(on_attr)) {
  247. $("img", "#" + key).attr("src", "{{ static_url('Bit_green.svg') }}");
  248. }
  249. if (parseFloat(response[key]) == parseFloat(off_attr)) {
  250. $("img", "#" + key).attr("src", "{{ static_url('Bit_red.svg') }}");
  251. }
  252. } else if (data_type == "alarm") {
  253. //console.log("alarm");
  254. var on_attr = $("#" + key).attr('data-on');
  255. var off_attr = $("#" + key).attr('data-off');
  256. if (parseFloat(response[key]) == parseFloat(on_attr)) {
  257. $("img", "#" + key).attr("src", "{{ static_url('alarm_active.svg') }}");
  258. }
  259. if (parseFloat(response[key]) == parseFloat(off_attr)) {
  260. $("img", "#" + key).attr("src", "{{ static_url('alarm_inactive.svg') }}");
  261. }
  262. } else if (data_type == "integer-to-string") {
  263. //console.log("integer-to-string");
  264. var dict_attr = JSON.parse($("#" + key).attr('data-dict'));
  265. var dict_cond;
  266. if ($("#"+key).attr("data-cond")) {
  267. dict_cond = JSON.parse($("#" + key).attr('data-cond'));
  268. } else {
  269. dict_cond = {};
  270. }
  271. var dict_color = "";
  272. if (key in response) {
  273. var token = response[key];
  274. if (token in dict_cond) {
  275. dict_color = dict_cond[token];
  276. }
  277. }
  278. $(".varval", "#" + key).css("color", dict_color);
  279. $(".varval", "#" + key).text(dict_attr[response[key]]);
  280. }
  281. }
  282. }
  283. $('[id^=virtual_]').each(function( index ) {
  284. var key = this.id;
  285. var ref = key.split("_");
  286. ref.shift();
  287. ref.pop();
  288. ref = ref.join("_");
  289. //ref = ref[1];
  290. console.log(ref);
  291. data_type = $("#" + key).attr('data-type');
  292. if($("#" + key).length > 0) {
  293. if (data_type == "data") {
  294. console.log(key);
  295. var datavalue, set_color, formula;
  296. var formula_attr = $("#" + key).attr('data-formula');
  297. if (response[ref]) {
  298. if (formula_attr) {
  299. datavalue = parseFloat(response[ref]).toFixed(2);
  300. formula = formula_attr.replace("x", datavalue.toString());
  301. datavalue = math.round(math.eval(formula),2);
  302. datavalue = datavalue.toFixed(2);
  303. } else {
  304. datavalue = parseFloat(response[ref]).toFixed(2);
  305. }
  306. set_color = "green";
  307. } else {
  308. datavalue = "---";
  309. set_color = "black";
  310. }
  311. $(".varval", "#" + key).text(datavalue);
  312. var condition_attr = $("#" + key).attr('data-cond');
  313. var lesser_attr = $("#" + key).attr('data-lesser');
  314. var larger_attr = $("#" + key).attr('data-larger');
  315. //console.log(condition_attr);
  316. if (condition_attr) {
  317. if (response[ref] == condition_attr) {
  318. set_color = "red";
  319. }
  320. }
  321. if (lesser_attr) {
  322. if (parseFloat(response[ref]) < parseFloat(lesser_attr)) {
  323. set_color = "red";
  324. }
  325. }
  326. if (larger_attr) {
  327. if (parseFloat(response[ref]) > parseFloat(larger_attr)) {
  328. set_color = "red";
  329. }
  330. }
  331. $(".varval", "#" + key).css("color", set_color);
  332. $(".unit_title", "#" + key).css("color", set_color);
  333. } else if (data_type == "ventil") {
  334. var on_attr = $("#" + key).attr('data-on');
  335. var off_attr = $("#" + key).attr('data-off');
  336. if (parseFloat(response[ref]) == parseFloat(on_attr)) {
  337. $("img", "#" + key).attr("src", "{{ static_url('ventil_green.png') }}");
  338. }
  339. if (parseFloat(response[ref]) == parseFloat(off_attr)) {
  340. $("img", "#" + key).attr("src", "{{ static_url('ventil_red.png') }}");
  341. }
  342. } else if (data_type == "commbit") {
  343. var on_attr = $("#" + key).attr('data-on');
  344. var off_attr = $("#" + key).attr('data-off');
  345. if (parseFloat(response[ref]) == parseFloat(on_attr)) {
  346. $("img", "#" + key).attr("src", "{{ static_url('Bit_green.svg') }}");
  347. }
  348. if (parseFloat(response[ref]) == parseFloat(off_attr)) {
  349. $("img", "#" + key).attr("src", "{{ static_url('Bit_red.svg') }}");
  350. }
  351. } else if (data_type == "alarm") {
  352. var on_attr = $("#" + key).attr('data-on');
  353. var off_attr = $("#" + key).attr('data-off');
  354. if (parseFloat(response[ref]) == parseFloat(on_attr)) {
  355. $("img", "#" + key).attr("src", "{{ static_url('alarm_active.svg') }}");
  356. }
  357. if (parseFloat(response[ref]) == parseFloat(off_attr)) {
  358. $("img", "#" + key).attr("src", "{{ static_url('alarm_inactive.svg') }}");
  359. }
  360. } else if (data_type == "integer-to-string") {
  361. var dict_attr = JSON.parse($("#" + key).attr('data-dict'));
  362. var dict_cond;
  363. if ($("#"+key).attr("data-cond")) {
  364. dict_cond = JSON.parse($("#" + key).attr('data-cond'));
  365. } else {
  366. dict_cond = {};
  367. }
  368. var dict_color = "";
  369. if (ref in response) {
  370. var token = response[ref];
  371. if (token in dict_cond) {
  372. dict_color = dict_cond[token];
  373. }
  374. }
  375. $(".varval", "#" + key).css("color", dict_color);
  376. $(".varval", "#" + key).text(dict_attr[response[ref]]);
  377. }
  378. }
  379. });
  380. $('[id^=calc_]').each(function( index ) {
  381. console.log(this.id);
  382. console.log($(this).attr('data-formula'));
  383. var myformula = $(this).attr('data-formula').trim();
  384. /*
  385. myformula = myformula.replace(/\[.*?\]/g, '__');
  386. console.log(myformula);
  387. */
  388. var data = myformula;
  389. var re= /\[(.*?)\]/g;
  390. var buffer = []
  391. for(m = re.exec(data); m; m = re.exec(data)){
  392. buffer.push(m[1]);
  393. }
  394. console.log("Debug:");
  395. console.log(buffer);
  396. var finalstring = "";
  397. var pattern = /\[(.*?)\]/g;
  398. var teststring = myformula.split(/[\[\]]+/);
  399. console.log(teststring);
  400. console.log(finalstring);
  401. for (var i = 0; i < teststring.length; i++) {
  402. var val = "";
  403. if (teststring[i] in response) {
  404. val = response[teststring[i]];
  405. } else {
  406. val = teststring[i];
  407. }
  408. finalstring += val;
  409. finalstring += " ";
  410. }
  411. finalstring = finalstring.trim();
  412. console.log(finalstring);
  413. var myvalue = math.round(math.eval(finalstring),2);
  414. myvalue = myvalue.toFixed(2);
  415. set_color = "green";
  416. console.log(myvalue);
  417. $(".varval", "#" + this.id).text(myvalue);
  418. var condition_attr = $("#" + this.id).attr('data-cond');
  419. var lesser_attr = $("#" + this.id).attr('data-lesser');
  420. var larger_attr = $("#" + this.id).attr('data-larger');
  421. //console.log(condition_attr);
  422. if (condition_attr) {
  423. if (myvalue == condition_attr) {
  424. set_color = "red";
  425. }
  426. }
  427. if (lesser_attr) {
  428. if (parseFloat(myvalue) < parseFloat(lesser_attr)) {
  429. set_color = "red";
  430. }
  431. }
  432. if (larger_attr) {
  433. if (parseFloat(myvalue) > parseFloat(larger_attr)) {
  434. set_color = "red";
  435. }
  436. }
  437. $(".varval", "#" + this.id).css("color", set_color);
  438. $(".unit_title", "#" + this.id).css("color", set_color);
  439. });
  440. var page_title_cache = $("#page_title_cache").text();
  441. var datetime = page_title_cache + " data monitoring page. Last Sync: " + response["time"];
  442. $("#page_info").text(datetime);
  443. console.log(datetime);
  444. },
  445. error: function () {
  446. console.log("Error.")
  447. }
  448. });
  449. }
  450. });
  451. </script>
  452. </body>
  453. </html>