Typica is a free program for professional coffee roasters. https://typica.us
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

batchdetailsnew.xml 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <window id="batchDetails">
  2. <layout type="vertical">
  3. <layout type="horizontal">
  4. <button type="push" id="target" name="Load profile as target" />
  5. <button type="push" id="viewprofile" name="View profile" />
  6. <button type="push" id="compare" name="Compare profile" />
  7. <button type="push" id="edit" name="Edit" />
  8. </layout>
  9. <webview id="view" />
  10. </layout>
  11. <program>
  12. <![CDATA[
  13. var window = this;
  14. dataView = findChildObject(this, 'view');
  15. var fileID;
  16. var target = findChildObject(this, 'target');
  17. var compare = findChildObject(this, 'compare');
  18. var edit = findChildObject(this, 'edit');
  19. edit.enabled = false;
  20. if(typeof(navigationwindow.loggingWindow) == "undefined") {
  21. compare.enabled = false;
  22. target.enabled = false;
  23. }
  24. var tableReference;
  25. var rowReference;
  26. var batchTime;
  27. var machine;
  28. var approval;
  29. var annotation;
  30. edit.clicked.connect(function() {
  31. var editWindow = createWindow("editBatchDetails");
  32. editWindow.loadData(window, tableReference, rowReference, batchTime, machine, approval, annotation);
  33. });
  34. compare.clicked.connect(function() {
  35. var query = new QSqlQuery;
  36. query.prepare("SELECT file, name FROM files WHERE id = :id");
  37. query.bind(":id", Number(fileID));
  38. query.exec();
  39. query.next();
  40. var buffer = new QBuffer(query.value(0));
  41. var pname = query.value(1);
  42. query = query.invalidate();
  43. var startSeries = Number(QSettings.value('cseries', 3));
  44. var nextSeries = startSeries + 2;
  45. QSettings.setValue('cseries', nextSeries);
  46. var input = new XMLInput(buffer, startSeries);
  47. var graph = findChildObject(navigationwindow.loggingWindow, 'graph');
  48. input.measure.connect(graph.newMeasurement);
  49. input.input();
  50. query = query.invalidate();
  51. });
  52. target.clicked.connect(function() {
  53. var query = new QSqlQuery;
  54. query.prepare("SELECT file, name FROM files WHERE id = :id");
  55. query.bind(":id", Number(fileID));
  56. query.exec();
  57. query.next();
  58. var buffer = new QBuffer(query.value(0));
  59. var pname = query.value(1);
  60. query = query.invalidate();
  61. var input = new XMLInput(buffer, 1);
  62. var graph = findChildObject(navigationwindow.loggingWindow, 'graph');
  63. var log = findChildObject(navigationwindow.loggingWindow, 'log');
  64. log.clear();
  65. graph.clear();
  66. input.newTemperatureColumn.connect(log.setHeaderData);
  67. input.newTemperatureColumn.connect(function(col, text) {
  68. if(text == navigationwindow.loggingWindow.targetcolumnname)
  69. {
  70. targetseries = col;
  71. }
  72. });
  73. input.newAnnotationColumn.connect(log.setHeaderData);
  74. input.measure.connect(graph.newMeasurement);
  75. input.measure.connect(log.newMeasurement);
  76. input.measure.connect(function(data, series) {
  77. if(series == targetseries)
  78. {
  79. targetDetector.newMeasurement(data);
  80. }
  81. });
  82. var lc;
  83. input.lastColumn.connect(function(c) {
  84. lc = c;
  85. QSettings.setValue("liveColumn", c + 1);
  86. navigationwindow.loggingWindow.postLoadColumnSetup(c);
  87. });
  88. input.annotation.connect(log.newAnnotation);
  89. input.annotation.connect(function(note, tcol, ncol) {
  90. for(var i = tcol; i < ncol; i++) {
  91. log.newAnnotation(note, i, ncol);
  92. }
  93. });
  94. navigationwindow.loggingWindow.windowTitle = "Typica - " + pname;
  95. navigationwindow.loggingWindow.raise();
  96. navigationwindow.loggingWindow.activateWindow();
  97. input.input();
  98. log.newAnnotation("End", 1, lc);
  99. query = query.invalidate();
  100. });
  101. var viewbutton = findChildObject(this, 'viewprofile');
  102. viewbutton.clicked.connect(function() {
  103. var query = new QSqlQuery;
  104. query.prepare("SELECT file, name FROM files WHERE id = :id");
  105. query.bind(":id", Number(fileID));
  106. query.exec();
  107. if(query.next()) {
  108. var viewer = createWindow('offline');
  109. var buffer = new QBuffer(query.value(0));
  110. var pname = query.value(1);
  111. query = query.invalidate();
  112. var input = new XMLInput(buffer, 1);
  113. var graph = findChildObject(viewer, 'graph');
  114. var log = findChildObject(viewer, 'log');
  115. input.newTemperatureColumn.connect(log.setHeaderData);
  116. input.newTemperatureColumn.connect(function(column) {
  117. viewer.saveTemperatureColumns.push(column);
  118. });
  119. input.newAnnotationColumn.connect(log.setHeaderData);
  120. input.newAnnotationColumn.connect(function(column) {
  121. viewer.saveAnnotationColumns.push(column);
  122. });
  123. input.measure.connect(graph.newMeasurement);
  124. input.measure.connect(log.newMeasurement);
  125. input.annotation.connect(log.newAnnotation);
  126. var lc;
  127. input.lastColumn.connect(function(c) {
  128. lc = c;
  129. if(c < 3)
  130. {
  131. log.setHeaderData(3, "");
  132. }
  133. });
  134. input.annotation.connect(function(note, tcol, ncol) {
  135. for(var i = tcol; i < ncol; i++) {
  136. log.newAnnotation(note, i, ncol);
  137. }
  138. });
  139. viewer.windowTitle = "Typica - " + pname;
  140. viewer.raise();
  141. viewer.activateWindow();
  142. input.input();
  143. log.newAnnotation("End", 1, lc);
  144. }
  145. else {
  146. print("Query returned no results");
  147. }
  148. query = query.invalidate();
  149. });
  150. window.loadData = function(table, row) {
  151. tableReference = table;
  152. rowReference = row;
  153. var buffer = new QBuffer;
  154. buffer.open(3);
  155. var output = new XmlWriter(buffer);
  156. output.writeStartDocument("1.0");
  157. output.writeDTD('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg.dtd">');
  158. output.writeStartElement("html");
  159. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  160. output.writeStartElement("head");
  161. output.writeTextElement("title", "Batch Details");
  162. output.writeEndElement();
  163. output.writeStartElement("body");
  164. output.writeStartElement("div");
  165. output.writeAttribute("style", "float: left; padding-right: 10px");
  166. output.writeStartElement("p");
  167. output.writeTextElement("strong", "Roasted Coffee: ");
  168. output.writeTextElement("span", table.data(row, 2));
  169. output.writeEndElement();
  170. output.writeEndElement();
  171. output.writeStartElement("div");
  172. output.writeAttribute("style", "float: left");
  173. output.writeStartElement("p");
  174. output.writeTextElement("strong", "Roasted On: ");
  175. batchTime = table.data(row, 0);
  176. output.writeTextElement("span", batchTime);
  177. output.writeEndElement();
  178. output.writeStartElement("p");
  179. output.writeTextElement("strong", "Batch Duration: ");
  180. output.writeTextElement("span", table.data(row, 6));
  181. output.writeEndElement();
  182. output.writeEndElement();
  183. output.writeStartElement("div");
  184. output.writeAttribute("style", "clear: both");
  185. output.writeEndElement();
  186. output.writeStartElement("table");
  187. output.writeStartElement("thead");
  188. output.writeStartElement("tr");
  189. output.writeTextElement("th", "Green Coffee");
  190. output.writeTextElement("th", "Weight (lb)");
  191. output.writeEndElement();
  192. output.writeEndElement();
  193. output.writeStartElement("tbody");
  194. var query = new QSqlQuery();
  195. query.prepare("SELECT unroasted_id, unroasted_quantity, approval, files, annotation FROM roasting_log WHERE time = :time AND machine = :machine");
  196. query.bind(":time", batchTime);
  197. machine = table.data(row, 1);
  198. query.bind(":machine", machine);
  199. query.exec();
  200. query.next();
  201. approval = query.value(2);
  202. annotation = query.value(4);
  203. var items = sqlToArray(query.value(0));
  204. var quantities = sqlToArray(query.value(1));
  205. var nameQuery = new QSqlQuery();
  206. nameQuery.prepare("SELECT name FROM items WHERE id = :id");
  207. for(var i = 0; i < items.length; i++) {
  208. output.writeStartElement("tr");
  209. nameQuery.bind(":id", items[i]);
  210. nameQuery.exec();
  211. nameQuery.next();
  212. output.writeTextElement("td", nameQuery.value(0));
  213. output.writeStartElement("td");
  214. output.writeAttribute("align", "center");
  215. output.writeCharacters(quantities[i]);
  216. output.writeEndElement();
  217. output.writeEndElement();
  218. }
  219. nameQuery = nameQuery.invalidate();
  220. output.writeEndElement();
  221. output.writeStartElement("tfoot");
  222. output.writeStartElement("tr");
  223. output.writeStartElement("td");
  224. output.writeAttribute("align", "right");
  225. output.writeTextElement("strong", "Green Total:");
  226. output.writeEndElement();
  227. output.writeStartElement("td");
  228. output.writeAttribute("align", "center");
  229. output.writeCharacters(table.data(row, 3));
  230. output.writeEndElement();
  231. output.writeEndElement();
  232. output.writeStartElement("tr");
  233. output.writeStartElement("td");
  234. output.writeAttribute("align", "right");
  235. output.writeTextElement("strong", "Roasted Weight:");
  236. output.writeEndElement();
  237. output.writeStartElement("td");
  238. output.writeAttribute("align", "center");
  239. output.writeCharacters(table.data(row, 4));
  240. output.writeEndElement();
  241. output.writeEndElement();
  242. output.writeStartElement("tr");
  243. output.writeStartElement("td");
  244. output.writeAttribute("align", "right");
  245. output.writeTextElement("strong", "Weight Loss:");
  246. output.writeEndElement();
  247. output.writeStartElement("td");
  248. output.writeAttribute("align", "center");
  249. output.writeCharacters(table.data(row, 5));
  250. output.writeCharacters("%");
  251. output.writeEndElement();
  252. output.writeEndElement();
  253. output.writeEndElement();
  254. output.writeEndElement();
  255. output.writeStartElement("p");
  256. output.writeTextElement("strong", "Approved: ");
  257. output.writeCharacters(approval);
  258. output.writeEndElement();
  259. output.writeStartElement("p");
  260. output.writeTextElement("strong", "Files: ");
  261. output.writeCharacters(query.value(3));
  262. output.writeEndElement();
  263. output.writeStartElement("p");
  264. output.writeTextElement("strong", "Annotations:");
  265. var files = sqlToArray(query.value(3));
  266. var annotations = annotationFromRecord(files[0]);
  267. fileID = files[0];
  268. var buffer2 = new QBuffer("<points>"+annotations+"</points>");
  269. buffer2.open(1);
  270. var colQuery = new XQuery;
  271. colQuery.bind("profile", buffer2);
  272. colQuery.setQuery('for $i in doc($profile)//tuple[1]/temperature/@series return (string($i), ";")');
  273. var result = colQuery.exec();
  274. buffer2.close();
  275. var seriesHeaders = new Array();
  276. seriesHeaders.push("Time");
  277. var records = result.split(";");
  278. for(var i = 0; i < records.length - 1; i++) {
  279. seriesHeaders.push(records[i].replace(/^\s+|\s+$/g,""));
  280. }
  281. seriesHeaders.push("Note");
  282. output.writeStartElement("table");
  283. output.writeStartElement("thead");
  284. output.writeStartElement("tr");
  285. for(var i = 0; i < seriesHeaders.length; i++) {
  286. output.writeTextElement("th", seriesHeaders[i]);
  287. }
  288. output.writeEndElement();
  289. output.writeEndElement();
  290. buffer2.open(1);
  291. var rq = 'for $t in doc($profile) //tuple return (string($t/time), ";", ';
  292. for(var i = 0; i < seriesHeaders.length - 2; i++) {
  293. rq = rq + 'string($t/temperature[' + Number(i+1) + ']), ";", ';
  294. }
  295. rq = rq + 'string($t/annotation), "~")';
  296. colQuery.setQuery(rq);
  297. var annotationData = colQuery.exec();
  298. buffer2.close();
  299. output.writeStartElement("tbody");
  300. var annotationRecords = annotationData.split("~");
  301. for(var i = 0; i < annotationRecords.length - 1; i++) {
  302. output.writeStartElement("tr");
  303. var annotationRow = annotationRecords[i].split(";");
  304. for(var j = 0; j < annotationRow.length; j++) {
  305. output.writeStartElement("td");
  306. output.writeAttribute("style", "border-left: 1px solid #000000");
  307. if(j > 0) {
  308. output.writeAttribute("align", "center");
  309. }
  310. if(j > 0 && j < annotationRow.length - 1) {
  311. output.writeCharacters(Number(annotationRow[j].replace(/^\s+|\s+$/g,"")).toFixed(2));
  312. }
  313. else {
  314. output.writeCharacters(annotationRow[j].replace(/^\s+|\s+$/g,""));
  315. }
  316. output.writeEndElement();
  317. }
  318. output.writeEndElement();
  319. }
  320. output.writeEndElement();
  321. output.writeEndElement();
  322. output.writeCharacters(annotation);
  323. output.writeEndElement();
  324. output.writeEndElement();
  325. output.writeEndElement();
  326. output.writeEndDocument();
  327. dataView.setContent(buffer);
  328. buffer.close();
  329. query = query.invalidate();
  330. edit.enabled = true;
  331. };
  332. ]]>
  333. </program>
  334. </window>