graph.html 8.9 KB

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