Typica is a free program for professional coffee roasters. https://typica.us
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

batchdetailsnew.xml 18KB

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