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

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