ui.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. var lines;
  2. var subscription;
  3. var ws;
  4. var acts = {};
  5. var transitions = [];
  6. var lastpos;
  7. var sub = 'topic' + '=' + 'activity' + '&' +// {{{
  8. 'events' + '=' + 'calling' + '&' +
  9. 'topic' + '=' + 'condition' + '&' +
  10. 'events' + '=' + 'eval' + '&' +
  11. 'topic' + '=' + 'dataelements' + '&' +
  12. 'events' + '=' + 'change' + '&' +
  13. 'topic' + '=' + 'position' + '&' +
  14. 'events' + '=' + 'change';// }}}
  15. function transdraw() {
  16. var buff = [];
  17. while (transitions.length > 0) {
  18. var trans = transitions.shift();
  19. if (acts[trans.unmark] && acts[trans.at]) {
  20. $(lines).each(function(k,val){
  21. if (val['From'] == acts[trans.unmark] && val['To'] == acts[trans.at]) {
  22. changelines('green','red');
  23. drawline(val['From'],val['To'],val['Between'],'green');
  24. }
  25. });
  26. } else {
  27. buff.push(trans);
  28. }
  29. }
  30. transitions = buff;
  31. }
  32. function transdraw2(station) {
  33. if (lastpos) {
  34. $(lines).each(function(k,val){
  35. if (val['From'] == lastpos && val['To'] == station) {
  36. changelines('green','red');
  37. drawline(val['From'],val['To'],val['Between'],'green');
  38. //console.log(lastpos);
  39. }
  40. });
  41. }
  42. lastpos = station;
  43. }
  44. function websocket() { //{{{
  45. var url = $('body').attr('current-instance');
  46. var Socket = "MozWebSocket" in window ? MozWebSocket : WebSocket;
  47. if (ws) ws.close();
  48. ws = new Socket(url.replace(/http/,'ws') + "/notifications/subscriptions/" + subscription + "/ws/");
  49. ws.onopen = function() {
  50. console.log("monitoring", "opened", "");
  51. };
  52. ws.onmessage = function(e) {
  53. data = $.parseXML(e.data);
  54. if ($('event > topic',data).length > 0) {
  55. switch($('event > topic',data).text()) {
  56. case 'condition':
  57. var data = JSON.parse($('event > notification',data).text());
  58. if (data.condition == "true") {
  59. $('#detailcolumn .stations').append($('<div class="station-condition">' + data.code + '</div>'));
  60. }
  61. case 'dataelements':
  62. var data = JSON.parse($('event > notification',data).text());
  63. var schrott = data.values.schrott;
  64. console.log(schrott);
  65. console.log(schrott["tatsächlicher Status"]);
  66. console.log(schrott["schrott"]);
  67. //var schrott_value = (JSON.parse(schrott)["schrott"]);
  68. var schrott_value = schrott["schrott"];
  69. var schrott_percent = schrott_value*100;
  70. var schrott_grenze = schrott['Wahrscheinlickeitsgrenze'];
  71. var grenze_percent = schrott_grenze*100
  72. console.log(data);
  73. if (data.label == 'Identifikation 110'){
  74. $('#detailcolumn .instance').append($('<br> <table class="station-id"><tbody><tr><td>Verschrottungswahrscheinlichkeit:</td><td> '
  75. + schrott_percent.toFixed(2)
  76. + '%</td></tr><tr><td>Status lt. Daten:</td><td>' + schrott['tatsächlicher Status']
  77. + '</td></tr><tr><td>Vorhersage: </td><td>' + schrott['Vorhersage'] + ' (Grenze von ' + grenze_percent.toFixed(2) + '%) '
  78. +'</tr></tbody></table>'));
  79. }
  80. case 'position':
  81. // var data = JSON.parse($('event > notification',data).text());
  82. // if (data.unmark && data.at) {
  83. // transitions.push({unmark: data.unmark[0], at: data.at[0]});
  84. // transdraw();
  85. // }
  86. break;
  87. case 'activity':
  88. var data = JSON.parse($('event > notification',data).text());
  89. var activity = data.activity;
  90. var label = data.label;
  91. var station = label.match(/ ([\d\/-]+)$/)[1];
  92. if (station.split('/').length > 1) {
  93. station = station.split('/')[0];
  94. $(station.split('/')).each(function(k,val){
  95. acts[activity] = val;
  96. });
  97. } else {
  98. acts[activity] = station;
  99. }
  100. $('g.node[data-id=' + station + ']').addClass('active');
  101. transdraw2(station);
  102. $('#detailcolumn .stations').append($('<div class="station-id">' + station + '</div>'));
  103. break;
  104. }
  105. }
  106. if ($('vote > topic',data).length > 0) {
  107. }
  108. };
  109. ws.onclose = function() {
  110. console.log("monitoring", "closed", "server down i assume.");
  111. };
  112. } //}}}
  113. $(document).ready(function(){
  114. // $("#graphcolumn .draw").on('click','g.node',getnode);
  115. // $("#graphcolumn .draw").click('click',getpos);
  116. $.get("nodes.yaml", function(res) {
  117. var nodes = jsyaml.load(res);
  118. $(nodes).each(function(k,val){
  119. drawnode(val['ID'],val['X'],val['Y'],val['Name']);
  120. });
  121. });
  122. $.get("lines.yaml", function(res) {
  123. lines = jsyaml.load(res);
  124. });
  125. $('#run').click(function(){
  126. var value = $('#inumber').val();
  127. var jsonv = {radsatz: value};
  128. var value_json = JSON.stringify(jsonv);
  129. //var endpoint = "http://172.21.0.30/test.php?radsatz=" + value;
  130. //var jsonend = {read_me_out: endpoint};
  131. //var endpoint_json = JSON.stringify(jsonend);
  132. console.log('Here it comes');
  133. console.log(value);
  134. $('#detailcolumn .stations').empty();
  135. $('#graphcolumn .draw .lines').empty();
  136. $('#graphcolumn .draw .texts g.node.active').removeClass('active');
  137. $.ajax({
  138. type: "POST",
  139. //url: "http://localhost:9090/cpee-cockpit/start/instantiation",
  140. // url: "http://localhost:8080/testsets/Concurrent.xml"
  141. //url: "centurio.loc:9090/cpee-cockpit/testsets/Fulltest_3.6.xml"
  142. //Url: "http://172.21.0.30/cpee-cockpit/testsets/Fulltest_3.6.xml"
  143. url: 'http://localhost:9296/url',
  144. data: { info: "OEBB Sim", behavior: "fork_ready", url: "http://172.18.0.30/cpee-cockpit/testsets/Fulltest_3.6.xml", init: value_json},
  145. success: function(url){
  146. console.log(url);
  147. url = url['CPEE-INSTANCE-URL'];
  148. $('#detailcolumn .instance').show();
  149. $('#detailcolumn .instance a').text(url);
  150. $('#detailcolumn .instance a').attr('href','http://localhost:9090/cpee-cockpit/?monitor=' + url);
  151. $('body').attr('current-instance',url);
  152. $.ajax({
  153. type: "POST",
  154. url: url + "/notifications/subscriptions/",
  155. data: sub,
  156. success: function(res){
  157. res = res.unserialize();
  158. $.each(res,function(a,b){
  159. if (b[0] == 'key') {
  160. subscription = b[1];
  161. }
  162. });
  163. websocket();
  164. }
  165. });
  166. }
  167. });
  168. });
  169. });