Typica is a free program for professional coffee roasters. https://typica.us
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

batchdetailsnew.xml 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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(Windows.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(Windows.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(Windows.loggingWindow, 'graph');
  63. var log = findChildObject(Windows.loggingWindow, 'log');
  64. log.clear();
  65. graph.clear();
  66. input.newTemperatureColumn.connect(log.setHeaderData);
  67. input.newTemperatureColumn.connect(function(col, text) {
  68. if(text == Windows.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. Windows.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. Windows.loggingWindow.windowTitle = "Typica - " + pname;
  95. Windows.loggingWindow.raise();
  96. Windows.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. graph.updatesEnabled = false;
  143. log.updatesEnabled = false;
  144. input.input();
  145. log.updatesEnabled = true;
  146. graph.updatesEnabled = true;
  147. log.newAnnotation("End", 1, lc);
  148. }
  149. else {
  150. print("Query returned no results");
  151. }
  152. query = query.invalidate();
  153. });
  154. window.loadData = function(table, row) {
  155. tableReference = table;
  156. rowReference = row;
  157. var buffer = new QBuffer;
  158. buffer.open(3);
  159. var output = new XmlWriter(buffer);
  160. output.writeStartDocument("1.0");
  161. 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">');
  162. output.writeStartElement("html");
  163. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  164. output.writeStartElement("head");
  165. output.writeTextElement("title", "Batch Details");
  166. output.writeEndElement();
  167. output.writeStartElement("body");
  168. output.writeStartElement("div");
  169. output.writeAttribute("style", "float: left; padding-right: 10px");
  170. output.writeStartElement("p");
  171. output.writeTextElement("strong", "Roasted Coffee: ");
  172. output.writeTextElement("span", table.data(row, 2));
  173. output.writeEndElement();
  174. output.writeEndElement();
  175. output.writeStartElement("div");
  176. output.writeAttribute("style", "float: left");
  177. output.writeStartElement("p");
  178. output.writeTextElement("strong", "Roasted On: ");
  179. batchTime = table.data(row, 0);
  180. output.writeTextElement("span", batchTime);
  181. output.writeEndElement();
  182. output.writeStartElement("p");
  183. output.writeTextElement("strong", "Batch Duration: ");
  184. output.writeTextElement("span", table.data(row, 6));
  185. output.writeEndElement();
  186. output.writeEndElement();
  187. output.writeStartElement("div");
  188. output.writeAttribute("style", "clear: both");
  189. output.writeEndElement();
  190. output.writeStartElement("table");
  191. output.writeStartElement("thead");
  192. output.writeStartElement("tr");
  193. output.writeTextElement("th", "Green Coffee");
  194. output.writeTextElement("th", "Weight (lb)");
  195. output.writeEndElement();
  196. output.writeEndElement();
  197. output.writeStartElement("tbody");
  198. var query = new QSqlQuery();
  199. query.prepare("SELECT unroasted_id, unroasted_quantity, approval, files, annotation FROM roasting_log WHERE time = :time AND machine = :machine");
  200. query.bind(":time", batchTime);
  201. machine = table.data(row, 1);
  202. query.bind(":machine", machine);
  203. query.exec();
  204. query.next();
  205. approval = query.value(2);
  206. annotation = query.value(4);
  207. var items = sqlToArray(query.value(0));
  208. var quantities = sqlToArray(query.value(1));
  209. var nameQuery = new QSqlQuery();
  210. nameQuery.prepare("SELECT name FROM items WHERE id = :id");
  211. for(var i = 0; i < items.length; i++) {
  212. output.writeStartElement("tr");
  213. nameQuery.bind(":id", items[i]);
  214. nameQuery.exec();
  215. nameQuery.next();
  216. output.writeTextElement("td", nameQuery.value(0));
  217. output.writeStartElement("td");
  218. output.writeAttribute("align", "center");
  219. output.writeCharacters(quantities[i]);
  220. output.writeEndElement();
  221. output.writeEndElement();
  222. }
  223. nameQuery = nameQuery.invalidate();
  224. output.writeEndElement();
  225. output.writeStartElement("tfoot");
  226. output.writeStartElement("tr");
  227. output.writeStartElement("td");
  228. output.writeAttribute("align", "right");
  229. output.writeTextElement("strong", "Green Total:");
  230. output.writeEndElement();
  231. output.writeStartElement("td");
  232. output.writeAttribute("align", "center");
  233. output.writeCharacters(table.data(row, 3));
  234. output.writeEndElement();
  235. output.writeEndElement();
  236. output.writeStartElement("tr");
  237. output.writeStartElement("td");
  238. output.writeAttribute("align", "right");
  239. output.writeTextElement("strong", "Roasted Weight:");
  240. output.writeEndElement();
  241. output.writeStartElement("td");
  242. output.writeAttribute("align", "center");
  243. output.writeCharacters(table.data(row, 4));
  244. output.writeEndElement();
  245. output.writeEndElement();
  246. output.writeStartElement("tr");
  247. output.writeStartElement("td");
  248. output.writeAttribute("align", "right");
  249. output.writeTextElement("strong", "Weight Loss:");
  250. output.writeEndElement();
  251. output.writeStartElement("td");
  252. output.writeAttribute("align", "center");
  253. output.writeCharacters(table.data(row, 5));
  254. output.writeCharacters("%");
  255. output.writeEndElement();
  256. output.writeEndElement();
  257. output.writeEndElement();
  258. output.writeEndElement();
  259. output.writeStartElement("p");
  260. output.writeTextElement("strong", "Approved: ");
  261. output.writeCharacters(approval);
  262. output.writeEndElement();
  263. output.writeStartElement("p");
  264. output.writeTextElement("strong", "Files: ");
  265. output.writeCharacters(query.value(3));
  266. output.writeEndElement();
  267. output.writeStartElement("p");
  268. output.writeTextElement("strong", "Annotations:");
  269. var files = sqlToArray(query.value(3));
  270. var annotations = annotationFromRecord(files[0]);
  271. fileID = files[0];
  272. var buffer2 = new QBuffer("<points>"+annotations+"</points>");
  273. buffer2.open(1);
  274. var colQuery = new XQuery;
  275. colQuery.bind("profile", buffer2);
  276. colQuery.setQuery('for $i in doc($profile)//tuple[1]/temperature/@series return (string($i), ";")');
  277. var result = colQuery.exec();
  278. buffer2.close();
  279. var seriesHeaders = new Array();
  280. seriesHeaders.push("Time");
  281. var records = result.split(";");
  282. for(var i = 0; i < records.length - 1; i++) {
  283. seriesHeaders.push(records[i].replace(/^\s+|\s+$/g,""));
  284. }
  285. seriesHeaders.push("Note");
  286. output.writeStartElement("table");
  287. output.writeStartElement("thead");
  288. output.writeStartElement("tr");
  289. for(var i = 0; i < seriesHeaders.length; i++) {
  290. output.writeTextElement("th", seriesHeaders[i]);
  291. }
  292. output.writeEndElement();
  293. output.writeEndElement();
  294. buffer2.open(1);
  295. var rq = 'for $t in doc($profile) //tuple return (string($t/time), ";", ';
  296. for(var i = 0; i < seriesHeaders.length - 2; i++) {
  297. rq = rq + 'string($t/temperature[' + Number(i+1) + ']), ";", ';
  298. }
  299. rq = rq + 'string($t/annotation), "~")';
  300. colQuery.setQuery(rq);
  301. var annotationData = colQuery.exec();
  302. colQuery = colQuery.invalidate();
  303. buffer2.close();
  304. output.writeStartElement("tbody");
  305. var annotationRecords = annotationData.split("~");
  306. for(var i = 0; i < annotationRecords.length - 1; i++) {
  307. output.writeStartElement("tr");
  308. var annotationRow = annotationRecords[i].split(";");
  309. for(var j = 0; j < annotationRow.length; j++) {
  310. output.writeStartElement("td");
  311. output.writeAttribute("style", "border-left: 1px solid #000000");
  312. if(j > 0) {
  313. output.writeAttribute("align", "center");
  314. }
  315. if(j > 0 && j < annotationRow.length - 1) {
  316. output.writeCharacters(Number(annotationRow[j].replace(/^\s+|\s+$/g,"")).toFixed(2));
  317. }
  318. else {
  319. output.writeCharacters(annotationRow[j].replace(/^\s+|\s+$/g,""));
  320. }
  321. output.writeEndElement();
  322. }
  323. output.writeEndElement();
  324. }
  325. output.writeEndElement();
  326. output.writeEndElement();
  327. output.writeCharacters(annotation);
  328. output.writeEndElement();
  329. output.writeEndElement();
  330. output.writeEndElement();
  331. output.writeEndDocument();
  332. dataView.setContent(buffer);
  333. buffer.close();
  334. query = query.invalidate();
  335. edit.enabled = true;
  336. };
  337. ]]>
  338. </program>
  339. </window>