Typica is a free program for professional coffee roasters. https://typica.us
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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 ? TTR("batchDetails", "Kg") :
  25. TTR("batchDetails", "Lb"));
  26. dataView = findChildObject(this, 'view');
  27. var printMenu = findChildObject(this, 'print');
  28. printMenu.triggered.connect(function() {
  29. dataView.print();
  30. });
  31. var fileID;
  32. var target = findChildObject(this, 'target');
  33. var compare = findChildObject(this, 'compare');
  34. var edit = findChildObject(this, 'edit');
  35. edit.enabled = false;
  36. if(typeof(Windows.loggingWindow) == "undefined") {
  37. compare.enabled = false;
  38. target.enabled = false;
  39. }
  40. var tableReference;
  41. var rowReference;
  42. var batchTime;
  43. var machine;
  44. var approval;
  45. var annotation;
  46. var roastWeight;
  47. edit.clicked.connect(function() {
  48. var editWindow = createWindow("editBatchDetails");
  49. editWindow.loadData(window, tableReference, rowReference, batchTime, machine, approval, annotation, roastWeight, unit);
  50. });
  51. compare.clicked.connect(function() {
  52. var query = new QSqlQuery;
  53. query.prepare("SELECT file, name FROM files WHERE id = :id");
  54. query.bind(":id", Number(fileID));
  55. query.exec();
  56. query.next();
  57. var buffer = new QBuffer(query.value(0));
  58. var pname = query.value(1);
  59. query = query.invalidate();
  60. var startSeries = Number(QSettings.value('cseries', 3));
  61. var nextSeries = startSeries + 2;
  62. QSettings.setValue('cseries', nextSeries);
  63. var input = new XMLInput(buffer, startSeries);
  64. var graph = findChildObject(Windows.loggingWindow, 'graph');
  65. input.measure.connect(graph.newMeasurement);
  66. input.input();
  67. query = query.invalidate();
  68. });
  69. target.clicked.connect(function() {
  70. var query = new QSqlQuery;
  71. query.prepare("SELECT file, name FROM files WHERE id = :id");
  72. query.bind(":id", Number(fileID));
  73. query.exec();
  74. query.next();
  75. var buffer = new QBuffer(query.value(0));
  76. var pname = query.value(1);
  77. query = query.invalidate();
  78. var input = new XMLInput(buffer, 1);
  79. var graph = findChildObject(Windows.loggingWindow, 'graph');
  80. var log = findChildObject(Windows.loggingWindow, 'log');
  81. log.clear();
  82. graph.clear();
  83. input.newTemperatureColumn.connect(log.setHeaderData);
  84. input.newTemperatureColumn.connect(function(col, text) {
  85. if(text == Windows.loggingWindow.targetcolumnname) {
  86. targetseries = col;
  87. }
  88. });
  89. input.newAnnotationColumn.connect(log.setHeaderData);
  90. input.measure.connect(graph.newMeasurement);
  91. input.measure.connect(log.newMeasurement);
  92. input.measure.connect(function(data, series) {
  93. if(series == targetseries) {
  94. targetDetector.newMeasurement(data);
  95. }
  96. });
  97. var lc;
  98. input.lastColumn.connect(function(c) {
  99. lc = c;
  100. QSettings.setValue("liveColumn", c + 1);
  101. Windows.loggingWindow.postLoadColumnSetup(c);
  102. });
  103. input.annotation.connect(log.newAnnotation);
  104. input.annotation.connect(function(note, tcol, ncol) {
  105. for(var i = tcol; i < ncol; i++) {
  106. log.newAnnotation(note, i, ncol);
  107. }
  108. });
  109. Windows.loggingWindow.windowTitle = "Typica - " + pname;
  110. Windows.loggingWindow.raise();
  111. Windows.loggingWindow.activateWindow();
  112. input.input();
  113. log.newAnnotation(TTR("batchDetails", "End"), 1, lc);
  114. query = query.invalidate();
  115. });
  116. var viewbutton = findChildObject(this, 'viewprofile');
  117. viewbutton.clicked.connect(function() {
  118. var query = new QSqlQuery;
  119. query.prepare("SELECT file, name FROM files WHERE id = :id");
  120. query.bind(":id", Number(fileID));
  121. query.exec();
  122. if(query.next()) {
  123. var viewer = createWindow('offline');
  124. var buffer = new QBuffer(query.value(0));
  125. var pname = query.value(1);
  126. query = query.invalidate();
  127. var input = new XMLInput(buffer, 1);
  128. var graph = findChildObject(viewer, 'graph');
  129. var log = findChildObject(viewer, 'log');
  130. input.newTemperatureColumn.connect(log.setHeaderData);
  131. input.newTemperatureColumn.connect(function(column) {
  132. viewer.saveTemperatureColumns.push(column);
  133. });
  134. input.newAnnotationColumn.connect(log.setHeaderData);
  135. input.newAnnotationColumn.connect(function(column) {
  136. viewer.saveAnnotationColumns.push(column);
  137. });
  138. input.measure.connect(graph.newMeasurement);
  139. input.measure.connect(log.newMeasurement);
  140. input.annotation.connect(log.newAnnotation);
  141. var lc;
  142. input.lastColumn.connect(function(c) {
  143. lc = c;
  144. if(c < 3) {
  145. log.setHeaderData(3, "");
  146. }
  147. });
  148. input.annotation.connect(function(note, tcol, ncol) {
  149. for(var i = tcol; i < ncol; i++) {
  150. log.newAnnotation(note, i, ncol);
  151. }
  152. });
  153. viewer.windowTitle = "Typica - " + pname;
  154. viewer.raise();
  155. viewer.activateWindow();
  156. graph.updatesEnabled = false;
  157. log.updatesEnabled = false;
  158. input.input();
  159. log.updatesEnabled = true;
  160. graph.updatesEnabled = true;
  161. log.newAnnotation("End", 1, lc);
  162. }
  163. query = query.invalidate();
  164. });
  165. window.loadData = function(table, row) {
  166. tableReference = table;
  167. rowReference = row;
  168. var buffer = new QBuffer;
  169. buffer.open(3);
  170. var output = new XmlWriter(buffer);
  171. output.writeStartDocument("1.0");
  172. 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">');
  173. output.writeStartElement("html");
  174. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  175. output.writeStartElement("head");
  176. output.writeTextElement("title", TTR("batchDetails", "Batch Details"));
  177. output.writeEndElement();
  178. output.writeStartElement("body");
  179. output.writeStartElement("div");
  180. output.writeAttribute("style", "float: left; padding-right: 10px");
  181. output.writeStartElement("p");
  182. output.writeTextElement("strong", TTR("batchDetails", "Roasted Coffee: "));
  183. output.writeTextElement("span", table.data(row, 2));
  184. output.writeEndElement();
  185. output.writeEndElement();
  186. output.writeStartElement("div");
  187. output.writeAttribute("style", "float: left");
  188. output.writeStartElement("p");
  189. output.writeTextElement("strong", TTR("batchDetails", "Roasted On: "));
  190. batchTime = table.data(row, 0);
  191. output.writeTextElement("span", batchTime);
  192. output.writeEndElement();
  193. output.writeStartElement("p");
  194. output.writeTextElement("strong", TTR("batchDetails", "Batch Duration: "));
  195. output.writeTextElement("span", table.data(row, 6));
  196. output.writeEndElement();
  197. output.writeEndElement();
  198. output.writeStartElement("div");
  199. output.writeAttribute("style", "clear: both");
  200. output.writeEndElement();
  201. output.writeStartElement("table");
  202. output.writeStartElement("thead");
  203. output.writeStartElement("tr");
  204. output.writeTextElement("th", TTR("batchDetails", "Green Coffee"));
  205. output.writeTextElement("th", TTR("batchDetails", "Weight (") + unitText + ")");
  206. output.writeEndElement();
  207. output.writeEndElement();
  208. output.writeStartElement("tbody");
  209. var query = new QSqlQuery();
  210. 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");
  211. query.bind(":time", batchTime);
  212. query.bind(":c1", conversion);
  213. query.bind(":c2", conversion);
  214. machine = table.data(row, 1);
  215. query.bind(":machine", machine);
  216. query.exec();
  217. query.next();
  218. approval = query.value(2);
  219. annotation = query.value(4);
  220. var items = sqlToArray(query.value(0));
  221. var quantities = sqlToArray(query.value(1));
  222. var nameQuery = new QSqlQuery();
  223. nameQuery.prepare("SELECT name FROM items WHERE id = :id");
  224. for(var i = 0; i < items.length; i++) {
  225. output.writeStartElement("tr");
  226. nameQuery.bind(":id", items[i]);
  227. nameQuery.exec();
  228. nameQuery.next();
  229. output.writeTextElement("td", nameQuery.value(0) + " (" + items[i] + ")");
  230. output.writeStartElement("td");
  231. output.writeAttribute("align", "center");
  232. output.writeCharacters((Number(quantities[i])/conversion).toFixed(3));
  233. output.writeEndElement();
  234. output.writeEndElement();
  235. }
  236. nameQuery = nameQuery.invalidate();
  237. output.writeEndElement();
  238. output.writeStartElement("tfoot");
  239. output.writeStartElement("tr");
  240. output.writeStartElement("td");
  241. output.writeAttribute("align", "right");
  242. output.writeTextElement("strong", TTR("batchDetails", "Green Total:"));
  243. output.writeEndElement();
  244. output.writeStartElement("td");
  245. output.writeAttribute("align", "center");
  246. output.writeCharacters(query.value(5));
  247. output.writeEndElement();
  248. output.writeEndElement();
  249. output.writeStartElement("tr");
  250. output.writeStartElement("td");
  251. output.writeAttribute("align", "right");
  252. output.writeTextElement("strong", TTR("batchDetails", "Roasted Weight:"));
  253. output.writeEndElement();
  254. output.writeStartElement("td");
  255. output.writeAttribute("align", "center");
  256. output.writeCharacters(query.value(6));
  257. roastWeight = 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", TTR("batchDetails", "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", TTR("batchDetails", "Approved: "));
  275. output.writeCharacters(approval);
  276. output.writeEndElement();
  277. output.writeStartElement("p");
  278. output.writeTextElement("strong", TTR("batchDetails", "Files: "));
  279. output.writeCharacters(query.value(3));
  280. output.writeEndElement();
  281. output.writeStartElement("p");
  282. output.writeTextElement("strong", TTR("batchDetails", "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(TTR("batchDetails", "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(TTR("batchDetails", "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, TTR("batchDetails", "Save Log As..."), QSettings.value("script/lastDir", "") + "/");
  354. if(filename != "") {
  355. saveFileFromDatabase(fileID, filename);
  356. }
  357. });
  358. ]]>
  359. </program>
  360. </window>