Typica is a free program for professional coffee roasters. https://typica.us
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

batchdetailsnew.xml 18KB

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