graph.html 8.8 KB

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