status.html 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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'] == "data" %}
  19. <div tooltip="{{ key }}" 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;'
  20. {% if data['style'][key]['condition'] %}
  21. data-cond="{{ data['style'][key]['condition'] }}"
  22. {% else%}
  23. {% end%}
  24. {% if "formula" in data['style'][key] %}
  25. data-formula="{{ data['style'][key]['formula'] }}"
  26. {% else %}
  27. {% end %}
  28. data-type="{{ data['style'][key]['type'] }}" data-lesser="{{ data['style'][key]['lesser'] }}" data-larger="{{ data['style'][key]['larger'] }}" 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 }}">
  29. <p><span style="color: #000; font-size: {{ data['style'][key]['header']['size'] }}; 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'] }}; 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'] }}; font-weight: {{ data['style'][key]['unit']['weight'] }};"> {{ data['style'][key]['unit']['title'] }}</span></p>
  30. </div>
  31. {% else %}
  32. {% end %}
  33. {% if data['style'][key]['type'] == "ventil" %}
  34. <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 }}">
  35. <img width='100%' height='100%' src='{{ static_url("ventil_inactive.png") }}'></img>
  36. </div>
  37. {% else %}
  38. {% end %}
  39. {% if data['style'][key]['type'] == "integer-to-string" %}
  40. <div tooltip="{{ key }}" style='position: absolute; top: {{
  41. data['style'][key]['top'] }}; left:{{ data['style'][key]['left'] }};
  42. width:{{ data['style'][key]['width'] }}px; height:{{
  43. data['style'][key]['height'] }}px;' data-cond="{{ data['style'][key]['cond'] }}" 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 }}">
  44. <p><span style="color: #000; font-size: {{ data['style'][key]['header']['size'] }}; 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'] }}; font-weight: {{ data['style'][key]['unit']['weight'] }};" class="varval">??? </span></p>
  45. </div>
  46. {% else %}
  47. {% end %}
  48. {% if data['style'][key]['type'] == "header" %}
  49. <div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{
  50. data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px;
  51. height:{{ data['style'][key]['height'] }}px;' data-type="{{
  52. data['style'][key]['type'] }}" class='databox' id="{{ key }}">
  53. <p><span style="color: #000; font-size: {{ data['style'][key]['header']['size'] }}; font-weight: {{ data['style'][key]['header']['weight'] }};" class="title">{{ data['style'][key]['header']['title'] }} </span></p>
  54. </div>
  55. {% else %}
  56. {% end %}
  57. {% end %}
  58. {% else %}
  59. {% end %}
  60. <img src="{{ static_url('background.png') }}"></img>
  61. <!-- java script -->
  62. <script src="{{ static_url("jquery-1.12.3.min.js") }}"></script>
  63. <script src="{{ static_url("jquery-ui.min.js") }}"></script>
  64. <script src="{{ static_url("math.min.js") }}"></script>
  65. <script>
  66. jQuery(window).load(function () {
  67. myTimer();
  68. var myVar = setInterval(myTimer, 10000);
  69. function myTimer() {
  70. var dataToSend = {};
  71. $.ajax({
  72. url: '/getdata/',
  73. type: 'GET',
  74. data: dataToSend,
  75. success: function (response) {
  76. //var objresponse = JSON.parse(response);
  77. console.log(response);
  78. for (var key in response) {
  79. //console.log(key, response[key]);
  80. data_type = $("#" + key).attr('data-type');
  81. if($("#" + key).length > 0) {
  82. if (data_type == "data") {
  83. var datavalue, set_color, formula;
  84. var formula_attr = $("#" + key).attr('data-formula');
  85. if (response[key]) {
  86. if (formula_attr) {
  87. datavalue = parseFloat(response[key]).toFixed(2);
  88. formula = formula_attr.replace("x", datavalue.toString());
  89. datavalue = math.eval(formula);
  90. } else {
  91. datavalue = parseFloat(response[key]).toFixed(2);
  92. }
  93. set_color = "green";
  94. } else {
  95. datavalue = "???";
  96. set_color = "black";
  97. }
  98. $(".varval", "#" + key).text(datavalue);
  99. var condition_attr = $("#" + key).attr('data-cond');
  100. var lesser_attr = $("#" + key).attr('data-lesser');
  101. var larger_attr = $("#" + key).attr('data-larger');
  102. //console.log(condition_attr);
  103. if (condition_attr) {
  104. if (response[key] == condition_attr) {
  105. set_color = "red";
  106. }
  107. }
  108. if (lesser_attr) {
  109. if (parseFloat(response[key]) < parseFloat(lesser_attr)) {
  110. set_color = "red";
  111. }
  112. }
  113. if (larger_attr) {
  114. if (parseFloat(response[key]) > parseFloat(larger_attr)) {
  115. set_color = "red";
  116. }
  117. }
  118. $(".varval", "#" + key).css("color", set_color);
  119. $(".unit_title", "#" + key).css("color", set_color);
  120. } else if (data_type == "ventil") {
  121. var on_attr = $("#" + key).attr('data-on');
  122. var off_attr = $("#" + key).attr('data-off');
  123. if (parseFloat(response[key]) == parseFloat(on_attr)) {
  124. $("img", "#" + key).attr("src", "{{ static_url('ventil_green.png') }}");
  125. }
  126. if (parseFloat(response[key]) == parseFloat(off_attr)) {
  127. $("img", "#" + key).attr("src", "{{ static_url('ventil_red.png') }}");
  128. }
  129. } else if (data_type == "integer-to-string") {
  130. var dict_attr = JSON.parse($("#" + key).attr('data-dict'));
  131. var dict_cond;
  132. if ($("#"+key).attr("data-cond")) {
  133. dict_cond = JSON.parse($("#" + key).attr('data-cond'));
  134. } else {
  135. dict_cond = {};
  136. }
  137. var dict_color = "";
  138. if (key in response) {
  139. var token = response[key];
  140. if (token in dict_cond) {
  141. dict_color = dict_cond[token];
  142. }
  143. }
  144. $(".varval", "#" + key).css("color", dict_color);
  145. $(".varval", "#" + key).text(dict_attr[response[key]]);
  146. }
  147. }
  148. }
  149. var datetime = "CPS data monitoring page. Last Sync: " + response["time"];
  150. $("#page_info").text(datetime);
  151. console.log(datetime);
  152. },
  153. error: function () {
  154. console.log("Error.")
  155. }
  156. });
  157. }
  158. });
  159. </script>
  160. </body>
  161. </html>