Typica is a free program for professional coffee roasters. https://typica.us
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

batchdetailsnew.xml 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  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="compare" name="Compare profile" />
  6. </layout>
  7. <tabbar id="tabs" />
  8. <layout type="stack" id="pages">
  9. <page>
  10. <layout type="vertical">
  11. <webview id="view" />
  12. </layout>
  13. </page>
  14. <page>
  15. <layout type="vertical">
  16. <splitter type="horizontal" id="logsplit">
  17. <measurementtable id="log">
  18. <column>Time</column>
  19. <column>Bean</column>
  20. <column>Air</column>
  21. <column>Note</column>
  22. </measurementtable>
  23. <graph id="graph" />
  24. </splitter>
  25. </layout>
  26. </page>
  27. <page>
  28. <layout type="vertical">
  29. <layout type="horizontal">
  30. <label>Roasted Weight: </label>
  31. <line id="roasted" validator="numeric" />
  32. <line id="roastunit" writable="false" />
  33. <stretch />
  34. </layout>
  35. <label>Degree of Roast</label>
  36. <layout type="horizontal">
  37. <label>Whole Bean:</label>
  38. <roastcoloredit id="wholecolor" />
  39. <stretch />
  40. </layout>
  41. <label id="wholespec">-</label>
  42. <layout type="horizontal">
  43. <label>Ground:</label>
  44. <roastcoloredit id="groundcolor" />
  45. <stretch />
  46. </layout>
  47. <label id="groundspec">-</label>
  48. <button type="check" name="Approved" id="approval" />
  49. <layout type="horizontal">
  50. <label>Annotation</label>
  51. <textarea id="annotation" />
  52. </layout>
  53. <button type="push" id="submit" name="Save" />
  54. <stretch />
  55. </layout>
  56. </page>
  57. <page>
  58. <layout type="vertical">
  59. </layout>
  60. </page>
  61. </layout>
  62. </layout>
  63. <menu name="File">
  64. <item id="save" shortcut="Ctrl+S">Save Profile...</item>
  65. <item id="print" shortcut="Ctrl+P">Print Report...</item>
  66. </menu>
  67. <menu name="Log">
  68. <item id="showC">Display Celsius</item>
  69. <item id="showF">Display Fahrenheit</item>
  70. <separator />
  71. <item id="ms">Millisecond View</item>
  72. <item id="1s">1 Second View</item>
  73. <item id="5s">5 Second View</item>
  74. <item id="10s">10 Second View</item>
  75. <item id="15s">15 Second View</item>
  76. <item id="30s">30 Second View</item>
  77. <item id="1m">1 Minute View</item>
  78. </menu>
  79. <program>
  80. <![CDATA[
  81. var window = this;
  82. var tabs = findChildObject(this, 'tabs');
  83. tabs.addTab("Report");
  84. tabs.addTab("Profile");
  85. tabs.addTab("Edit");
  86. tabs.addTab("Batch Tag");
  87. var pages = findChildObject(this, 'pages');
  88. tabs.currentChanged.connect(function(index) {
  89. pages.setCurrentIndex(index);
  90. });
  91. var log = findChildObject(this, 'log');
  92. var graph = findChildObject(this, 'graph');
  93. var showC = findChildObject(this, 'showC');
  94. showC.triggered.connect(function() {
  95. log.setDisplayUnits(Units.Celsius);
  96. graph.showC();
  97. });
  98. var showF = findChildObject(this, 'showF');
  99. showF.triggered.connect(function() {
  100. log.setDisplayUnits(Units.Fahrenheit);
  101. graph.showF();
  102. });
  103. var v1 = findChildObject(this, 'ms');
  104. v1.triggered.connect(log.LOD_ms);
  105. var v2 = findChildObject(this, '1s');
  106. v2.triggered.connect(log.LOD_1s);
  107. var v3 = findChildObject(this, '5s');
  108. v3.triggered.connect(log.LOD_5s);
  109. var v4 = findChildObject(this, '10s');
  110. v4.triggered.connect(log.LOD_10s);
  111. var v5 = findChildObject(this, '15s');
  112. v5.triggered.connect(log.LOD_15s);
  113. var v6 = findChildObject(this, '30s');
  114. v6.triggered.connect(log.LOD_30s);
  115. var v7 = findChildObject(this, '1m');
  116. v7.triggered.connect(log.LOD_1m);
  117. var splitter = findChildObject(this, 'logsplit');
  118. splitter.restoreState("script/offlineViewSplitter");
  119. window.saveTemperatureColumns = new Array();
  120. window.saveAnnotationColumns = new Array();
  121. this.aboutToClose.connect(function() {
  122. splitter.saveState("script/batchdetails/profileSplitter");
  123. });
  124. var unit = QSettings.value("script/history_unit", 1);
  125. var conversion = 1;
  126. if(unit == 0)
  127. {
  128. conversion = 2.2;
  129. }
  130. var unitText = (unit == 0 ? TTR("batchDetails", "Kg") :
  131. TTR("batchDetails", "Lb"));
  132. dataView = findChildObject(this, 'view');
  133. var printMenu = findChildObject(this, 'print');
  134. printMenu.triggered.connect(function() {
  135. dataView.print();
  136. });
  137. var fileID;
  138. var target = findChildObject(this, 'target');
  139. var compare = findChildObject(this, 'compare');
  140. if(typeof(Windows.loggingWindow) == "undefined") {
  141. compare.enabled = false;
  142. target.enabled = false;
  143. }
  144. var tableReference;
  145. var rowReference;
  146. var batchTime;
  147. var machine;
  148. var approval;
  149. var annotation;
  150. var roastWeight;
  151. compare.clicked.connect(function() {
  152. var query = new QSqlQuery;
  153. query.prepare("SELECT file, name FROM files WHERE id = :id");
  154. query.bind(":id", Number(fileID));
  155. query.exec();
  156. query.next();
  157. var buffer = new QBuffer(query.value(0));
  158. var pname = query.value(1);
  159. query = query.invalidate();
  160. var startSeries = Number(QSettings.value('cseries', 3));
  161. var nextSeries = startSeries + 2;
  162. QSettings.setValue('cseries', nextSeries);
  163. var input = new XMLInput(buffer, startSeries);
  164. var graph = findChildObject(Windows.loggingWindow, 'graph');
  165. input.measure.connect(graph.newMeasurement);
  166. input.input();
  167. query = query.invalidate();
  168. });
  169. target.clicked.connect(function() {
  170. var query = new QSqlQuery;
  171. query.prepare("SELECT file, name FROM files WHERE id = :id");
  172. query.bind(":id", Number(fileID));
  173. query.exec();
  174. query.next();
  175. var buffer = new QBuffer(query.value(0));
  176. var pname = query.value(1);
  177. query = query.invalidate();
  178. var input = new XMLInput(buffer, 1);
  179. var graph = findChildObject(Windows.loggingWindow, 'graph');
  180. var log = findChildObject(Windows.loggingWindow, 'log');
  181. log.clear();
  182. graph.clear();
  183. input.newTemperatureColumn.connect(log.setHeaderData);
  184. input.newTemperatureColumn.connect(function(col, text) {
  185. if(text == Windows.loggingWindow.targetcolumnname) {
  186. targetseries = col;
  187. }
  188. });
  189. input.newAnnotationColumn.connect(log.setHeaderData);
  190. input.measure.connect(graph.newMeasurement);
  191. input.measure.connect(log.newMeasurement);
  192. input.measure.connect(function(data, series) {
  193. if(series == targetseries) {
  194. targetDetector.newMeasurement(data);
  195. }
  196. });
  197. var lc;
  198. input.lastColumn.connect(function(c) {
  199. lc = c;
  200. QSettings.setValue("liveColumn", c + 1);
  201. Windows.loggingWindow.postLoadColumnSetup(c);
  202. });
  203. input.annotation.connect(log.newAnnotation);
  204. input.annotation.connect(function(note, tcol, ncol) {
  205. for(var i = tcol; i < ncol; i++) {
  206. log.newAnnotation(note, i, ncol);
  207. }
  208. });
  209. Windows.loggingWindow.windowTitle = "Typica - " + pname;
  210. Windows.loggingWindow.raise();
  211. Windows.loggingWindow.activateWindow();
  212. input.input();
  213. log.newAnnotation(TTR("batchDetails", "End"), 1, lc);
  214. query = query.invalidate();
  215. });
  216. var approvalButton = findChildObject(this, 'approval');
  217. var annotationField = findChildObject(this, 'annotation');
  218. var roastedEdit = findChildObject(this, 'roasted');
  219. var unitEdit = findChildObject(this, 'roastunit');
  220. var wholecolor = findChildObject(this, 'wholecolor');
  221. var groundcolor = findChildObject(this, 'groundcolor');
  222. window.loadBatch = function(mref, tref) {
  223. machine = mref;
  224. batchTime = tref;
  225. var query = new QSqlQuery();
  226. var q = "WITH names AS ( WITH greens AS ( SELECT unnest(unroasted_id) AS gitem, machine, time FROM roasting_log WHERE machine = :machine AND time = :time) SELECT array_agg((SELECT name FROM items WHERE id = greens.gitem) || ' (' || gitem || ')') AS names, max(greens.machine) AS machine, max(greens.time) AS time FROM greens LIMIT 1) SELECT (SELECT name FROM items WHERE id = roasted_id), duration, names, unroasted_quantity, (unroasted_total_quantity/:c1)::numeric(12,3), (roasted_quantity/:c2)::numeric(12,3), approval, files, annotation, (SELECT file FROM files WHERE id = files[1]) AS file, additional_data FROM names, roasting_log WHERE roasting_log.machine = names.machine AND roasting_log.time = names.time";
  227. query.prepare(q);
  228. query.bind(":machine", mref);
  229. query.bind(":time", tref);
  230. query.bind(":c1", conversion);
  231. query.bind(":c2", conversion);
  232. query.exec();
  233. query.next();
  234. var buffer = new QBuffer;
  235. buffer.open(3);
  236. var output = new XmlWriter(buffer);
  237. output.writeStartDocument("1.0");
  238. 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">');
  239. output.writeStartElement("html");
  240. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  241. output.writeStartElement("head");
  242. output.writeTextElement("title", "Batch Details");
  243. output.writeEndElement();
  244. output.writeStartElement("body");
  245. output.writeStartElement("div");
  246. output.writeAttribute("style", "float: left; padding-right: 10px");
  247. output.writeStartElement("p");
  248. output.writeTextElement("strong", TTR("batchDetails", "Roasted Coffee: "));
  249. output.writeTextElement("span", query.value(0));
  250. output.writeEndElement();
  251. output.writeEndElement();
  252. output.writeStartElement("div");
  253. output.writeAttribute("style", "float: left");
  254. output.writeStartElement("p");
  255. output.writeTextElement("strong", TTR("batchDetails", "Roasted At: "));
  256. output.writeTextElement("span", batchTime);
  257. output.writeEndElement();
  258. output.writeStartElement("p");
  259. output.writeTextElement("strong", TTR("batchDetails", "Batch Duration: "));
  260. output.writeTextElement("span", query.value(1));
  261. output.writeEndElement();
  262. output.writeEndElement();
  263. output.writeStartElement("div");
  264. output.writeAttribute("style", "clear: both");
  265. output.writeEndElement();
  266. output.writeStartElement("table");
  267. output.writeStartElement("thead");
  268. output.writeStartElement("tr");
  269. output.writeTextElement("th", TTR("batchDetails", "Green Coffee"));
  270. output.writeTextElement("th", TTR("batchDetails", "Weight") + "(" + unitText + ")");
  271. output.writeEndElement();
  272. output.writeEndElement();
  273. output.writeStartElement("tbody");
  274. var items = sqlToArray(query.value(2));
  275. var quantities = sqlToArray(query.value(3));
  276. for(var i = 0; i < items.length; i++) {
  277. output.writeStartElement("tr");
  278. output.writeTextElement("td", items[i]);
  279. output.writeStartElement("td");
  280. output.writeAttribute("align", "center");
  281. output.writeCharacters(Number(quantities[i]/conversion).toFixed(3));
  282. output.writeEndElement();
  283. output.writeEndElement();
  284. }
  285. output.writeEndElement();
  286. output.writeStartElement("tfoot");
  287. output.writeStartElement("tr");
  288. output.writeStartElement("td");
  289. output.writeAttribute("align", "right");
  290. output.writeTextElement("strong", TTR("batchDetails", "Green Total:"));
  291. output.writeEndElement();
  292. output.writeStartElement("td");
  293. output.writeAttribute("align", "center");
  294. output.writeCharacters(query.value(4));
  295. output.writeEndElement();
  296. output.writeEndElement();
  297. output.writeStartElement("tr");
  298. output.writeStartElement("td");
  299. output.writeAttribute("align", "right");
  300. output.writeTextElement("strong", TTR("batchDetails", "Roasted Weight:"));
  301. output.writeEndElement();
  302. output.writeStartElement("td");
  303. output.writeAttribute("align", "center");
  304. output.writeCharacters(query.value(5));
  305. output.writeEndElement();
  306. output.writeEndElement();
  307. output.writeStartElement("tr");
  308. output.writeStartElement("td");
  309. output.writeAttribute("align", "right");
  310. output.writeTextElement("strong", TTR("batchDetails", "Weight Loss:"));
  311. output.writeEndElement();
  312. output.writeStartElement("td");
  313. output.writeAttribute("align", "center");
  314. if(Number(query.value(4)) > 0) {
  315. output.writeCharacters(Number(((Number(query.value(4)) - Number(query.value(5)))/Number(query.value(4))) * 100).toFixed(2));
  316. output.writeCharacters("%");
  317. } else {
  318. output.writeCharacters("unknown");
  319. }
  320. output.writeEndElement();
  321. output.writeEndElement();
  322. output.writeEndElement();
  323. output.writeEndElement();
  324. if(query.value(10).length > 0) {
  325. var extradata = JSON.parse(query.value(10));
  326. if(extradata.color) {
  327. output.writeStartElement("p");
  328. output.writeTextElement("strong", TTR("batchDetails", "Degree of Roast"));
  329. output.writeEndElement();
  330. if(extradata.color.whole) {
  331. wholecolor.value = extradata.color.whole;
  332. output.writeStartElement("p");
  333. output.writeTextElement("strong", TTR("batchDetails", "Whole Bean: "));
  334. output.writeTextElement("span", extradata.color.whole);
  335. output.writeEndElement();
  336. } else {
  337. wholecolor.value = "";
  338. }
  339. if(extradata.color.ground) {
  340. groundcolor.value = extradata.color.ground;
  341. output.writeStartElement("p");
  342. output.writeTextElement("strong", TTR("batchDetails", "Ground: "));
  343. output.writeTextElement("span", extradata.color.ground);
  344. output.writeEndElement();
  345. } else {
  346. groundcolor.value = "";
  347. }
  348. } else {
  349. wholecolor.value = "";
  350. groundcolor.value = "";
  351. }
  352. }
  353. output.writeStartElement("p");
  354. output.writeTextElement("strong", TTR("batchDetails", "Approved: "));
  355. output.writeCharacters(query.value(6));
  356. output.writeEndElement();
  357. output.writeStartElement("p");
  358. output.writeTextElement("strong", TTR("batchDetails", "Files: "));
  359. output.writeCharacters(query.value(7));
  360. output.writeEndElement();
  361. output.writeStartElement("p");
  362. output.writeTextElement("strong", TTR("batchDetails", "Annotations:"));
  363. var files = sqlToArray(query.value(7));
  364. var annotations = annotationFromRecord(files[0]);
  365. fileID = files[0];
  366. var buffer2 = new QBuffer("<points>"+annotations+"</points>");
  367. buffer2.open(1);
  368. var colQuery = new XQuery;
  369. colQuery.bind("profile", buffer2);
  370. colQuery.setQuery('for $i in doc($profile)//tuple[1]/temperature/@series return (string($i), ";")');
  371. var result = colQuery.exec();
  372. buffer2.close();
  373. var seriesHeaders = new Array();
  374. seriesHeaders.push(TTR("batchDetails", "Time"));
  375. var records = result.split(";");
  376. for(var i = 0; i < records.length - 1; i++) {
  377. seriesHeaders.push(records[i].replace(/^\s+|\s+$/g,""));
  378. }
  379. seriesHeaders.push(TTR("batchDetails", "Note"));
  380. output.writeStartElement("table");
  381. output.writeStartElement("thead");
  382. output.writeStartElement("tr");
  383. for(var i = 0; i < seriesHeaders.length; i++) {
  384. output.writeTextElement("th", seriesHeaders[i]);
  385. }
  386. output.writeEndElement();
  387. output.writeEndElement();
  388. buffer2.open(1);
  389. var rq = 'for $t in doc($profile) //tuple return (string($t/time), ";", ';
  390. for(var i = 0; i < seriesHeaders.length - 2; i++) {
  391. rq += 'string($t/temperature[' + Number(i+1) + ']), ";", ';
  392. }
  393. rq += 'string($t/annotation), "~")';
  394. colQuery.setQuery(rq);
  395. var annotationData = colQuery.exec();
  396. colQuery = colQuery.invalidate();
  397. buffer2.close();
  398. output.writeStartElement("tbody");
  399. var annotationRecords = annotationData.split("~");
  400. for(var i = 0; i < annotationRecords.length - 1; i++) {
  401. output.writeStartElement("tr");
  402. var annotationRow = annotationRecords[i].split(";");
  403. for(var j = 0; j < annotationRow.length; j++) {
  404. output.writeStartElement("td");
  405. output.writeAttribute("style", "border-left: 1px solid #000000");
  406. if(j > 0) {
  407. output.writeAttribute("align", "center");
  408. }
  409. if(j > 0 && j < annotationRow.length - 1) {
  410. output.writeCharacters(Number(annotationRow[j].replace(/^\s+|\s+$/g,"")).toFixed(2));
  411. } else {
  412. output.writeCharacters(annotationRow[j].replace(/^\s+|\s+$/g,""));
  413. }
  414. output.writeEndElement();
  415. }
  416. output.writeEndElement();
  417. }
  418. output.writeEndElement();
  419. output.writeEndElement();
  420. output.writeCharacters(query.value(8));
  421. output.writeEndElement();
  422. output.writeEndElement();
  423. output.writeEndElement();
  424. output.writeEndDocument();
  425. dataView.setContent(buffer);
  426. buffer.close();
  427. log.clear();
  428. graph.clear();
  429. var buffer3 = new QBuffer(query.value(9));
  430. var input = new XMLInput(buffer3, 1);
  431. input.newTemperatureColumn.connect(log.setHeaderData);
  432. input.newAnnotationColumn.connect(log.setHeaderData);
  433. var lc;
  434. input.lastColumn.connect(function(c) {
  435. lc = c;
  436. if(c < 3) {
  437. log.setHeaderData(3, "");
  438. }
  439. });
  440. input.measure.connect(graph.newMeasurement);
  441. input.measure.connect(log.newMeasurement);
  442. input.annotation.connect(function(note,tcol,ncol) {
  443. for(var i = tcol; i < ncol; i++) {
  444. log.newAnnotation(note, i, ncol);
  445. }
  446. });
  447. graph.updatesEnabled = false;
  448. log.updatesEnabled = false;
  449. input.input();
  450. log.updatesEnabled = true;
  451. graph.updatesEnabled = true;
  452. log.newAnnotation("End", 1, lc);
  453. if(query.value(6) == "true") {
  454. approvalButton.checked = true;
  455. }
  456. annotationField.plainText = query.value(8);
  457. unitEdit.text = unitText;
  458. roastedEdit.text = query.value(5);
  459. query = query.invalidate();
  460. }
  461. var saveMenu = findChildObject(this, 'save');
  462. saveMenu.triggered.connect(function() {
  463. var filename = QFileDialog.getSaveFileName(window, TTR("batchDetails", "Save Log As..."), QSettings.value("script/lastDir", "") + "/");
  464. if(filename != "") {
  465. saveFileFromDatabase(fileID, filename);
  466. }
  467. });
  468. var submit = findChildObject(this, 'submit');
  469. submit.clicked.connect(function() {
  470. var query = new QSqlQuery;
  471. query.prepare("UPDATE roasting_log SET roasted_quantity = :roasted, approval = :approval, annotation = :annotation, additional_data = :extradata WHERE time = :time AND machine = :machine");
  472. query.bind(":approval", approvalButton.checked);
  473. query.bind(":annotation", annotationField.plainText);
  474. query.bind(":roasted", Number(Number(roastedEdit.text)*conversion));
  475. var extradata = new Object;
  476. var colordata = new Object;
  477. if(wholecolor.value.length > 0) {
  478. colordata.whole = wholecolor.value;
  479. }
  480. if(groundcolor.value.length > 0) {
  481. colordata.ground = groundcolor.value;
  482. }
  483. if(colordata.whole || colordata.ground) {
  484. extradata.color = colordata;
  485. }
  486. query.bind(":extradata", JSON.stringify(extradata));
  487. query.bind(":time", batchTime);
  488. query.bind(":machine", Number(machine));
  489. query.exec();
  490. window.loadBatch(machine, batchTime);
  491. displayInfo(TTR("batchDetails", "Batch Data Saved"),
  492. TTR("roastspec", "New batch details saved"));
  493. });
  494. ]]>
  495. </program>
  496. </window>