graph.html 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <html>
  2. <head>
  3. <script type="text/javascript" src='plotly-basic-2.18.2.min.js?v=$COMMIT_HASH'></script>
  4. <script type="text/javascript" src="common.js?v=$COMMIT_HASH"></script>
  5. <script type="text/javascript" src="readconfigcommon.js?v=$COMMIT_HASH"></script>
  6. <script type="text/javascript" src="readconfigparam.js?v=$COMMIT_HASH"></script>
  7. <style>
  8. body {
  9. font-family: Arial, Helvetica, sans-serif;
  10. }
  11. </style>
  12. <script>
  13. function run() {
  14. datefile = document.getElementById("datafiles").value;
  15. numbername = document.getElementById("numbers").value;
  16. showRrelativeValues = document.getElementById("showRrelativeValues").checked;
  17. //alert("Auslesen: " + datefile + " " + numbername);
  18. _domainname = getDomainname();
  19. fetch(_domainname + '/fileserver/log/data/' + datefile)
  20. .then(response => {
  21. // handle the response
  22. if (response.status == 404) {
  23. firework.launch("No log data available for " + dateString, 'warning', 10000);
  24. }
  25. response.text()
  26. .then( result => {
  27. var lines = result.split("\n");
  28. var traceValue = { x: [], y: [], type: 'scatter', line: {width: 6}, name: 'Value'};
  29. var tracePreValue = { x: [], y: [], type: 'scatter', line: {width: 2}, name: 'Previous Value', visible: 'legendonly'};
  30. var traceChangeRate = { x: [], y: [], type: 'bar', yaxis: 'y2', opacity: 0.2, name: 'Change Rate'};
  31. var traceChangeAbsolute = { x: [], y: [], type: 'bar', yaxis: 'y2', opacity: 0.2, name: 'Change Absolute', visible: 'legendonly'};
  32. var timex = 1;
  33. for (let line of lines) {
  34. {
  35. //console.log(line);
  36. if (line.split(",")[1] == numbername)
  37. {
  38. var value = line.split(",")[3];
  39. var preValue = line.split(",")[4];
  40. var changeRate = line.split(",")[5];
  41. var changeAbsolute = line.split(",")[6];
  42. var time = line.split(",")[0];
  43. //console.log("> "+time+" "+value+"\n");
  44. traceValue.x.push(time);
  45. /* Catch empty fields */
  46. if (value == "" || isNaN(value)) {
  47. value = NaN;
  48. }
  49. if (preValue == "" || isNaN(preValue)) {
  50. preValue = NaN;
  51. }
  52. if (changeRate == "" || isNaN(changeRate)) {
  53. changeRate = NaN;
  54. }
  55. if (changeAbsolute == "" || isNaN(changeAbsolute)) {
  56. changeAbsolute = NaN;
  57. }
  58. traceValue.y.push(value);
  59. tracePreValue.y.push(preValue);
  60. traceChangeRate.y.push(changeRate);
  61. traceChangeAbsolute.y.push(changeAbsolute);
  62. }
  63. }
  64. }
  65. /* If the value trace starts with NaN, replace all those Nans with the first valid value */
  66. var firstNonNaNIndex = 0;
  67. for(var i = 0; i < traceValue.y.length; i++) {
  68. firstNonNaNIndex = i;
  69. if (! isNaN(traceValue.y[i])) {
  70. break;
  71. }
  72. }
  73. if (firstNonNaNIndex == (traceValue.y.length - 1)) {
  74. console.log("No data available for 'value'!");
  75. }
  76. else if (firstNonNaNIndex > 0) { // Replace all leading NaN with the first valid value
  77. console.log("The first leading values have all just NaN, replacing them with the value of",
  78. traceValue.y[firstNonNaNIndex], "at", traceValue.x[firstNonNaNIndex], "(Index:", firstNonNaNIndex, ")");
  79. for(var i = 0; i < firstNonNaNIndex; i++) {
  80. traceValue.y[i] = traceValue.y[firstNonNaNIndex];
  81. }
  82. }
  83. // Copy time to all traces
  84. tracePreValue.x = traceValue.x;
  85. traceChangeRate.x = traceValue.x;
  86. traceChangeAbsolute.x = traceValue.x;
  87. //console.log(traceValue.y);
  88. var offsetValue = traceValue.y[0];
  89. var offsetPreValue = tracePreValue.y[0];
  90. traceValue.connectgaps = true;
  91. if (showRrelativeValues) {
  92. traceValue.y.forEach(function(part, index, arr) {
  93. arr[index] = arr[index] - offsetValue;
  94. });
  95. tracePreValue.y.forEach(function(part, index, arr) {
  96. arr[index] = arr[index] - offsetPreValue;
  97. });
  98. }
  99. // console.log(traceValue.x)
  100. var data = [traceValue, tracePreValue, traceChangeRate, traceChangeAbsolute];
  101. var layout = {
  102. showlegend: true,
  103. colorway: ['green', 'black', 'blue', 'black'],
  104. yaxis: {title: 'Value'},
  105. yaxis2: {
  106. title: 'Change',
  107. overlaying: 'y',
  108. side: 'right'
  109. },
  110. margin: {
  111. l: 50,
  112. r: 50,
  113. b: 50,
  114. t: 50,
  115. pad: 4
  116. },
  117. legend: {
  118. x: 0.2,
  119. y: 0.9,
  120. xanchor: 'right'
  121. }
  122. };
  123. document.getElementById("chart").innerHTML = "";
  124. Plotly.newPlot('chart', data, layout, {displayModeBar: true});
  125. });
  126. }).catch((error) => {
  127. // handle the error
  128. console.log(error);
  129. });
  130. }
  131. </script>
  132. <link href="firework.css?v=$COMMIT_HASH" rel="stylesheet">
  133. <script type="text/javascript" src="jquery-3.6.0.min.js?v=$COMMIT_HASH"></script>
  134. <script type="text/javascript" src="firework.js?v=$COMMIT_HASH"></script>
  135. </head>
  136. <body>
  137. <h3>Data Graph</h3>
  138. <div id='chart'><p>Loading...<br></p></div>
  139. <select id="datafiles" onchange="run();"></select>
  140. <select id="numbers" onchange="run();"></select>
  141. <input type="checkbox" id="showRrelativeValues" onclick = 'run();' unchecked ><label for="showRrelativeValues">Show relative values</label>
  142. <button onclick="run();">Refresh</button>
  143. &nbsp;&nbsp;|&nbsp;&nbsp;
  144. <button onClick="window.location.href = 'data.html?v=$COMMIT_HASH'">Show data</button>
  145. <button onClick="window.location.href = getDomainname() + '/fileserver/log/data/'">Show data files</button>
  146. </div>
  147. <script>
  148. function WriteModelFiles()
  149. {
  150. list_data = getDATAList();
  151. var _indexDig = document.getElementById("datafiles");
  152. while (_indexDig.length)
  153. _indexDig.remove(0);
  154. for (var i = list_data.length - 1; i >= 0; --i)
  155. {
  156. var optionDig = document.createElement("option");
  157. var text = list_data[i];
  158. optionDig.text = text;
  159. optionDig.value = list_data[i];
  160. _indexDig.add(optionDig);
  161. }
  162. }
  163. function WriteNumbers()
  164. {
  165. list_data = getNUMBERSList();
  166. var _indexDig = document.getElementById("numbers");
  167. while (_indexDig.length)
  168. _indexDig.remove(0);
  169. for (var i = 0; i < list_data.length; ++i)
  170. {
  171. var optionDig = document.createElement("option");
  172. var text = list_data[i];
  173. optionDig.text = text;
  174. optionDig.value = list_data[i];
  175. _indexDig.add(optionDig);
  176. }
  177. }
  178. WriteModelFiles();
  179. WriteNumbers();
  180. run();
  181. </script>
  182. </body>
  183. </html>