prevalue_set.html 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <!DOCTYPE html>
  2. <html lang="en" xml:lang="en">
  3. <head>
  4. <title>Set PreValue</title>
  5. <meta charset="UTF-8" />
  6. <style>
  7. h1 {font-size: 2em;}
  8. h2 {font-size: 1.5em; margin-block-start: 0.0em; margin-block-end: 0.2em;}
  9. h3 {font-size: 1.2em;}
  10. p {font-size: 1em;}
  11. div {
  12. padding: 3px 5px;
  13. display: inline-block;
  14. border: 1px solid #ccc;
  15. font-size: 16px;
  16. height: 20px;
  17. width: 120px;
  18. vertical-align: middle;
  19. }
  20. input[type=number] {
  21. width: 120px;
  22. margin-right: 10px;
  23. padding: 3px 5px;
  24. display: inline-block;
  25. border: 1px solid #ccc;
  26. font-size: 16px;
  27. }
  28. .invalid-input {
  29. background-color: #FFAA00;
  30. }
  31. th, td {
  32. padding: 5px 5px 5px 0px;
  33. }
  34. select {
  35. padding: 3px 5px;
  36. display: inline-block;
  37. border: 1px solid #ccc;
  38. font-size: 16px;
  39. margin-right: 10px;
  40. min-width: 100px;
  41. vertical-align: middle;
  42. }
  43. .button {
  44. padding: 5px 10px;
  45. width: 205px;
  46. font-size: 16px;
  47. }
  48. table {
  49. width: 660px;
  50. padding: 5px;
  51. }
  52. </style>
  53. <link href="firework.css?v=$COMMIT_HASH" rel="stylesheet">
  54. </head>
  55. <body style="font-family: arial; padding: 0px 10px;">
  56. <h2>Set "Previous Value"</h2>
  57. <details id="desc_details">
  58. <summary><b>CLICK HERE</b> for usage description. More infos in documentation:
  59. <a href=https://jomjol.github.io/AI-on-the-edge-device-docs/FAQs/#pre-value target=_blank>"Previous Value"</a>
  60. </summary>
  61. <p>
  62. Set the "previous value" for consistency checks and substitution for NaN
  63. </p>
  64. <p>
  65. Previous value is a bit missleading, because normally it is the last valid value but not always the value of the previous round.
  66. The result of the the new round, as long it's a vaild result, will be promoted to the new "previous value". If the result is not usable the
  67. "previous value" will not be updated.
  68. If activated in configuration, the "previous value" will be used in the following round to check negtive rates, high rates
  69. (MaxRateValue / MaxRateType) and for the option "Check Digit Increase Consistency" (configuration paramter, only for dig-class11 models).
  70. </p>
  71. <p>
  72. The field to enter new "previous value" is prefilled with actual "raw value" because it's the most likely use case. Nevertheless every other
  73. positive value can be set as new "previous value".
  74. </p>
  75. </details>
  76. <hr />
  77. <table>
  78. <colgroup>
  79. <col span="1" style="width: 35.0%;">
  80. <col span="1" style="width: 65.0%;">
  81. </colgroup>
  82. <tr>
  83. <td style="height: 40px;">
  84. <class id="Numbers_text" style="color:black;">Number sequence:</class>
  85. </td>
  86. <td>
  87. <select id="Numbers_value1" onchange="numberChanged()"></select>
  88. </td>
  89. </tr>
  90. </table>
  91. <hr />
  92. <table>
  93. <colgroup>
  94. <col span="1" style="width: 35%;">
  95. <col span="1" style="width: 65%;">
  96. </colgroup>
  97. <tr>
  98. <td>Current "previous value":</td>
  99. <td>
  100. <div style="padding-left:5px" id="prevalue"></div>
  101. </td>
  102. </tr>
  103. <tr>
  104. <td style="vertical-align: text-top; padding-top: 12px;">Enter new "previous value":</td>
  105. <td>
  106. <input required type="number" id="myInput" name="myInput" min="0" oninput="(!validity.rangeUnderflow||(value=0));">
  107. <button class="button" type="button" onclick="setprevalue()">Update Value</button>
  108. <p style="padding-left: 5px;">NOTE: The current "raw value" is prefilled as
  109. <br>the suggested new "previous value"</p>
  110. </td>
  111. </tr>
  112. <tr>
  113. <td id="result_text">"Previous value" updated to:</td>
  114. <td>
  115. <div id="result" style="padding-left:5px;"></div>
  116. </td>
  117. </tr>
  118. </table>
  119. <script type="text/javascript" src="jquery-3.6.0.min.js?v=$COMMIT_HASH"></script>
  120. <script type="text/javascript" src="firework.js?v=$COMMIT_HASH"></script>
  121. <script type="text/javascript" src="common.js?v=$COMMIT_HASH"></script>
  122. <script type="text/javascript" src="readconfigcommon.js?v=$COMMIT_HASH"></script>
  123. <script type="text/javascript" src="readconfigparam.js?v=$COMMIT_HASH"></script>
  124. <script type="text/javascript">
  125. var domainname = getDomainname();
  126. var NUMBERS;
  127. async function setprevalue() {
  128. var inputVal = document.getElementById("myInput").value.replace(",", ".");
  129. var sel = document.getElementById("Numbers_value1");
  130. var number = sel.options[sel.selectedIndex].text;
  131. try {
  132. var url = domainname + "/setPreValue?value=" + encodeURIComponent(inputVal) +
  133. "&numbers=" + encodeURIComponent(number);
  134. const response = await fetch(url);
  135. const result = await response.text();
  136. if (!response.ok) {
  137. throw new Error(result || response.statusText);
  138. }
  139. document.getElementById("result").innerHTML = result;
  140. firework.launch('New "previous value" set', 'success', 5000);
  141. } catch (error) {
  142. console.error("Could not set previous value:", error);
  143. firework.launch('Failed to set previous value!', 'danger', 30000);
  144. }
  145. }
  146. async function loadPrevalue(_domainname) {
  147. var sel = document.getElementById("Numbers_value1");
  148. if (!sel.options.length) {
  149. return;
  150. }
  151. var number = sel.options[sel.selectedIndex].text;
  152. try {
  153. var url = _domainname + "/setPreValue?numbers=" + encodeURIComponent(number);
  154. const prevalueResponse = await fetch(url);
  155. if (!prevalueResponse.ok) {
  156. throw new Error(prevalueResponse.statusText);
  157. }
  158. document.getElementById("prevalue").innerHTML = await prevalueResponse.text();
  159. const rawResponse = await fetch(_domainname + "/value?all=true&type=raw");
  160. if (!rawResponse.ok) {
  161. throw new Error(rawResponse.statusText);
  162. }
  163. const lines = (await rawResponse.text()).split(/\\r?\\n/);
  164. for (const line of lines) {
  165. const values = line.split("\\t");
  166. if (number === values[0]) {
  167. document.getElementById("myInput").value = Number(values[1]);
  168. break;
  169. }
  170. }
  171. } catch (error) {
  172. console.error("Could not load previous value:", error);
  173. firework.launch('Failed to get data from device!', 'danger', 30000);
  174. }
  175. }
  176. async function numberChanged() {
  177. await loadPrevalue(domainname);
  178. }
  179. async function UpdateNUMBERS(_sel){
  180. zw = getNUMBERInfo();
  181. index = 0;
  182. var _index = document.getElementById("Numbers_value1");
  183. while (_index.length){
  184. _index.remove(0);
  185. }
  186. for (var i = 0; i < zw.length; ++i){
  187. var option = document.createElement("option");
  188. option.text = zw[i]["name"];
  189. option.value = i;
  190. _index.add(option);
  191. if (typeof _sel !== 'undefined') {
  192. if (zw[i]["name"] == _sel)
  193. index = i
  194. }
  195. }
  196. _index.selectedIndex = index;
  197. await loadPrevalue(domainname);
  198. }
  199. async function init(){
  200. domainname = getDomainname();
  201. if (!await loadConfig(domainname)) {
  202. firework.launch('Configuration could not be loaded! Please reload the page!', 'danger', 30000);
  203. return;
  204. }
  205. ParseConfig();
  206. await UpdateNUMBERS();
  207. }
  208. init().catch(function (error) { console.error('Could not initialize previous value page:', error); });
  209. </script>
  210. </body>
  211. </html>