Typica is a free program for professional coffee roasters. https://typica.us
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

batchdetailsnew.xml 13KB

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