Typica is a free program for professional coffee roasters. https://typica.us
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

newbatch.xml 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. <window id="batchWindow">
  2. <menu name="Batch">
  3. <item id="new" shortcut="Ctrl+N">New Batch…</item>
  4. </menu>
  5. <layout type="horizontal">
  6. <layout type="vertical">
  7. <layout type="horizontal">
  8. <label>Machine:</label>
  9. <line id="machine" writable="false" />
  10. <label>Unit:</label>
  11. <sqldrop id="unit" />
  12. <stretch />
  13. </layout>
  14. <layout type="horizontal">
  15. <label>Roasted Coffee:</label>
  16. <sqldrop data="0" display="1" showdata="true" id="roasted">
  17. <null />
  18. <query>SELECT id, name FROM items WHERE category = 'Coffee: Roasted' AND id IN (SELECT item FROM current_items) ORDER BY name</query>
  19. </sqldrop>
  20. <stretch />
  21. </layout>
  22. <label>Green Coffee:</label>
  23. <sqltablearray columns="3" id="greens">
  24. <column name="Coffee" delegate="sql" showdata="true" null="true" nulltext="Delete" nulldata="delete" data="0" display="1">SELECT id, name FROM coffees WHERE quantity &lt;&gt; 0 ORDER BY name</column>
  25. <column name="Weight" delegate="numeric" />
  26. <column name="Remaining" />
  27. </sqltablearray>
  28. <layout type="horizontal">
  29. <label>Green Weight:</label>
  30. <line id="green" writable="false">0.0</line>
  31. </layout>
  32. <layout type="horizontal">
  33. <button name="Load Profile" type="push" id="load" />
  34. <button name="No Profile" type="push" id="noprofile" />
  35. </layout>
  36. <layout type="horizontal">
  37. <label>Time:</label>
  38. <line id="time" writable="false" />
  39. <label>Duration:</label>
  40. <line id="duration" writable="false" />
  41. </layout>
  42. <layout type="horizontal">
  43. <label>Roasted Weight:</label>
  44. <line id="roast" validator="numeric" />
  45. <label>Weight Loss:</label>
  46. <line id="wloss" writable="false" />
  47. <button type="check" id="approval" name="Approved" />
  48. </layout>
  49. <layout type="horizontal">
  50. <label>Annotation:</label>
  51. <textarea id="annotation" />
  52. </layout>
  53. <layout type="horizontal">
  54. <button name="Submit" id="submit" type="push" />
  55. <button name="Save log as target profile" type="check" id="target" />
  56. </layout>
  57. </layout>
  58. <layout type="vertical">
  59. <label>Connected Scales</label>
  60. <layout type="vertical" id="scales" />
  61. <label>Expected Weight Loss</label>
  62. <line id="lossspec" writable="false" />
  63. <label>Expected Roasted Weight</label>
  64. <layout type="horizontal">
  65. <label>Min:</label>
  66. <line id="minroastweight" writable="false" />
  67. </layout>
  68. <layout type="horizontal">
  69. <label>Expected:</label>
  70. <line id="expectedroastweight" writable="false" />
  71. </layout>
  72. <layout type="horizontal">
  73. <label>Max:</label>
  74. <line id="maxroastweight" writable="false" />
  75. </layout>
  76. <label>Specification Details</label>
  77. <textarea id="specnotes" />
  78. <stretch />
  79. </layout>
  80. </layout>
  81. <program>
  82. <![CDATA[
  83. var unitBox = findChildObject(this, 'unit');
  84. unitBox.addItem("g");
  85. unitBox.addItem("Kg");
  86. unitBox.addItem("oz");
  87. unitBox.addItem("lb");
  88. unitBox.currentIndex = (QSettings.value("script/batch_unit", unitBox.findText("lb")));
  89. unitBox['currentIndexChanged(int)'].connect(function() {
  90. QSettings.setValue("script/batch_unit", unitBox.currentIndex);
  91. });
  92. var machine = findChildObject(this, "machine");
  93. machine.setText(selectedRoasterName + " (" + selectedRoasterID + ")");
  94. var newMenu = findChildObject(this, 'new');
  95. newMenu.triggered.connect(function() {
  96. var bwindow = createWindow("batchWindow");
  97. bwindow.windowTitle = "Typica - [*]New Batch";
  98. });
  99. var batch = this;
  100. var table = findChildObject(this, 'greens');
  101. var green = findChildObject(this, 'green');
  102. var model = table.model();
  103. var lossField = findChildObject(this, 'wloss');
  104. lossField.maximumWidth = 80;
  105. var roasted = findChildObject(this, 'roasted');
  106. var roastwt = findChildObject(this, 'roast');
  107. roastwt.maximumWidth = 80;
  108. var scalesLayout = findChildObject(this, 'scales');
  109. scalesLayout.spacing = 10;
  110. if(navigationwindow.loggingWindow.scales.length > 0) {
  111. for(var i = 0; i < navigationwindow.loggingWindow.scales.length; i++) {
  112. var scale = navigationwindow.loggingWindow.scales[i];
  113. var label = new DragLabel();
  114. var weighButton = new QPushButton();
  115. weighButton.text = "Weigh";
  116. weighButton.clicked.connect(scale.weigh);
  117. label.updateMeasurement = function(m, u) {
  118. switch(unitBox.currentIndex) {
  119. case 0:
  120. this.text = Units.convertWeight(m, u, Units.Gram).toFixed(1);
  121. break;
  122. case 1:
  123. this.text = Units.convertWeight(m, u, Units.Kilogram).toFixed(4);
  124. break;
  125. case 2:
  126. this.text = Units.convertWeight(m, u, Units.Ounce).toFixed(3);
  127. break;
  128. case 3:
  129. this.text = Units.convertWeight(m, u, Units.Pound).toFixed(4);
  130. break;
  131. }
  132. };
  133. scalesLayout.addWidget(label);
  134. scalesLayout.addWidget(weighButton);
  135. scale.newMeasurement.connect(function(m, u) {
  136. label.updateMeasurement(m, u);
  137. });
  138. scale.weigh();
  139. unitBox['currentIndexChanged(int)'].connect(scale.weigh);
  140. }
  141. }
  142. var remainingStock = new Array();
  143. var query = new QSqlQuery();
  144. query.exec("SELECT id, quantity, (SELECT conversion FROM lb_bag_conversion WHERE item = id) FROM coffees WHERE quantity <> 0");
  145. while(query.next()) {
  146. remainingStock.push({id: query.value(0),
  147. quantity: query.value(1),
  148. conversion: query.value(2)});
  149. }
  150. query = query.invalidate();
  151. var convertToPounds = function(w, u) {
  152. switch(u) {
  153. case "g":
  154. return w * 0.0022;
  155. case "oz":
  156. return w * 0.0625;
  157. case "Kg":
  158. return w * 2.2;
  159. }
  160. return w;
  161. };
  162. var convertFromPounds = function(w, u) {
  163. switch(u) {
  164. case "g":
  165. return w / 0.0022;
  166. case "oz":
  167. return w / 0.0625;
  168. case "Kg":
  169. return w / 2.2;
  170. }
  171. return w;
  172. };
  173. var specnotes = findChildObject(this, 'specnotes');
  174. specnotes.readOnly = true;
  175. var lossspec = findChildObject(this, 'lossspec');
  176. var minfield = findChildObject(this, 'minroastweight');
  177. var midfield = findChildObject(this, 'expectedroastweight');
  178. var maxfield = findChildObject(this, 'maxroastweight');
  179. var minloss = 0;
  180. var maxloss = 0;
  181. var expectloss = 0;
  182. var updateGreenTable = function() {
  183. var deleteRow = -1;
  184. /* The combo box delegate updates user data before display data
  185. and this code is executed before the model update is fully
  186. complete. Rather than rely on this behavior continuing, we
  187. check that the display value has also been updated and defer
  188. row removal until both updates are complete.
  189. */
  190. while((deleteRow = table.findData("delete", 0)) > -1) {
  191. if(table.data(deleteRow, 0, 0) == "Delete") {
  192. table.removeRow(table.findData("delete", 0));
  193. } else {
  194. break;
  195. }
  196. }
  197. green.text = table.columnSum(1, 0);
  198. table.resizeColumnToContents(0);
  199. var gid = 0;
  200. var r = 0;
  201. while(gid >= 0)
  202. {
  203. gid = Number(table.data(r, 0, 32));
  204. if(isNaN(gid))
  205. {
  206. gid = -1;
  207. break;
  208. }
  209. var bagConversion = 1;
  210. for(var i = 0; i < remainingStock.length; i++)
  211. {
  212. if(gid == Number(remainingStock[i].id))
  213. {
  214. var displayValue = Number(remainingStock[i].quantity);
  215. bagConversion = Number(remainingStock[i].conversion);
  216. if(!isNaN(Number(table.data(r, 1, 0))))
  217. {
  218. var change = Number(table.data(r, 1, 0));
  219. switch(unitBox.currentIndex)
  220. {
  221. case 0:
  222. change = convertToPounds(change, "g");
  223. break;
  224. case 1:
  225. change = convertToPounds(change, "Kg");
  226. break;
  227. case 2:
  228. change = convertToPounds(change, "oz");
  229. break;
  230. }
  231. displayValue -= change;
  232. }
  233. var bagCount = (displayValue / bagConversion).toFixed(2);
  234. switch(unitBox.currentIndex)
  235. {
  236. case 0:
  237. displayValue = convertFromPounds(displayValue, "g");
  238. break;
  239. case 1:
  240. displayValue = convertFromPounds(displayValue, "Kg");
  241. break;
  242. case 2:
  243. displayValue = convertFromPounds(displayValue, "oz");
  244. break;
  245. }
  246. displayValue = "" + displayValue + " (" + bagCount + " bags)";
  247. if(table.data(r, 2, 0) != displayValue)
  248. {
  249. table.setData(r, 2, displayValue, 0);
  250. table.setData(r, 2, displayValue, 2);
  251. table.resizeColumnToContents(2);
  252. }
  253. }
  254. }
  255. r++;
  256. }
  257. if(parseFloat(green.text) > 0)
  258. {
  259. var expectedLossDesc = "";
  260. if(lossspec.text.length > 0) {
  261. if(minloss != expectloss) {
  262. minfield.text = (-(parseFloat(green.text)) * (maxloss - 1)).toFixed(2);
  263. maxfield.text = (-(parseFloat(green.text)) * (minloss - 1)).toFixed(2);
  264. }
  265. midfield.text = (-(parseFloat(green.text)) * (expectloss - 1)).toFixed(2);
  266. }
  267. if(parseFloat(roastwt.text) > 0)
  268. {
  269. lossField.text = (((parseFloat(green.text) - parseFloat(roastwt.text)) / parseFloat(green.text)) * 100).toFixed(2) + "%";
  270. }
  271. else
  272. {
  273. lossField.text = "100%";
  274. }
  275. }
  276. };
  277. model.dataChanged.connect(updateGreenTable);
  278. unitBox['currentIndexChanged(int)'].connect(updateGreenTable);
  279. roastwt.textChanged.connect(function() {
  280. if(parseFloat(green.text) > 0)
  281. {
  282. if(parseFloat(roastwt.text) > 0)
  283. {
  284. lossField.text = (((parseFloat(green.text) - parseFloat(roastwt.text)) / parseFloat(green.text)) * 100).toFixed(2) + "%";
  285. }
  286. else
  287. {
  288. lossField.text = "100%";
  289. }
  290. }
  291. });
  292. var profilebutton = findChildObject(this, 'load');
  293. profilebutton.setEnabled(false);
  294. roasted['currentIndexChanged(int)'].connect(function() {
  295. table.clear();
  296. var query = new QSqlQuery();
  297. var q = "SELECT EXISTS(SELECT 1 FROM item_files WHERE item = ";
  298. q = q + roasted.currentData();
  299. q = q + ")";
  300. query.exec(q);
  301. if(query.next())
  302. {
  303. if(query.value(0) == 'false')
  304. {
  305. profilebutton.setEnabled(false);
  306. }
  307. else
  308. {
  309. profilebutton.setEnabled(true);
  310. }
  311. }
  312. else
  313. {
  314. profilebutton.setEnabled(false);
  315. }
  316. var title = "Typica - [*]New Batch (";
  317. title = title + roasted.currentText;
  318. title = title + ")";
  319. batch.windowTitle = title;
  320. q = "SELECT unroasted_id FROM roasting_log WHERE roasted_id = ";
  321. q = q + roasted.currentData();
  322. q = q + " AND time = (SELECT max(time) FROM roasting_log WHERE roasted_id = ";
  323. q = q + roasted.currentData();
  324. q = q + ")";
  325. query.exec(q);
  326. if(query.next())
  327. {
  328. var unroasted_items = sqlToArray(query.value(0));
  329. var names = [];
  330. q = "SELECT name FROM items WHERE id = :id AND quantity <> 0";
  331. query.prepare(q);
  332. var allInStock = true;
  333. for(var i = 0; i < unroasted_items.length; i++)
  334. {
  335. query.bind("id", unroasted_items[i]);
  336. query.exec();
  337. if(query.next())
  338. {
  339. names[i] = query.value(0);
  340. }
  341. else
  342. {
  343. allInStock = false;
  344. }
  345. }
  346. if(allInStock)
  347. {
  348. for(var i = 0; i < unroasted_items.length; i++)
  349. {
  350. table.setData(i, 0, names[i], 0);
  351. table.setData(i, 0, unroasted_items[i], 32);
  352. }
  353. }
  354. }
  355. query.prepare("SELECT loss, tolerance, notes FROM roasting_specification WHERE item = :id1 AND time = (SELECT max(time) FROM roasting_specification WHERE item = :id2)");
  356. query.bind(":id1", roasted.currentData());
  357. query.bind(":id2", roasted.currentData());
  358. query.exec();
  359. var lossSpecDescription = "";
  360. if(query.next()) {
  361. if(query.value(0).length > 0) {
  362. lossSpecDescription += (Number(query.value(0)) * 100).toFixed(2);
  363. minloss = Number(query.value(0));
  364. maxloss = Number(query.value(0));
  365. expectloss = Number(query.value(0));
  366. }
  367. if(query.value(1).length > 0) {
  368. lossSpecDescription += " +/- " + (Number(query.value(1)) * 100).toFixed(2);
  369. minloss -= Number(query.value(1));
  370. maxloss += Number(query.value(1));
  371. }
  372. if(lossSpecDescription.length > 0) {
  373. lossSpecDescription += "%";
  374. }
  375. lossspec.text = lossSpecDescription;
  376. specnotes.plainText = query.value(2);
  377. } else {
  378. lossspec.text = "";
  379. specnotes.plainText = "";
  380. }
  381. roastestimate.text = "";
  382. query = query.invalidate();
  383. });
  384. profilebutton.clicked.connect(function() {
  385. batch.windowModified = true;
  386. currentBatchInfo = batch;
  387. query = new QSqlQuery();
  388. var q = "SELECT files FROM item_files WHERE item = :item AND time = (SELECT max(time) FROM item_files WHERE item = :again)";
  389. query.prepare(q);
  390. query.bind(":item", Number(roasted.currentData()));
  391. query.bind(":again", Number(roasted.currentData()));
  392. query.exec();
  393. var graph;
  394. var log;
  395. if(query.next())
  396. {
  397. var files = query.value(0);
  398. files = files.replace("{", "(");
  399. files = files.replace("}", ")");
  400. q = "SELECT file, name FROM files WHERE id IN ";
  401. q = q + files;
  402. q = q + " AND type = 'profile'";
  403. query.exec(q);
  404. if(query.next())
  405. {
  406. var targetseries = -1;
  407. var buffer = new QBuffer(query.value(0));
  408. var pname = query.value(1);
  409. var input = new XMLInput(buffer, 1);
  410. graph = findChildObject(navigationwindow.loggingWindow, 'graph');
  411. log = findChildObject(navigationwindow.loggingWindow, 'log');
  412. log.clear();
  413. graph.clear();
  414. input.newTemperatureColumn.connect(log.setHeaderData);
  415. input.newTemperatureColumn.connect(function(col, text) {
  416. if(text == navigationwindow.loggingWindow.targetcolumnname)
  417. {
  418. targetseries = col;
  419. }
  420. });
  421. input.newAnnotationColumn.connect(log.setHeaderData);
  422. input.measure.connect(graph.newMeasurement);
  423. input.measure.connect(log.newMeasurement);
  424. input.measure.connect(function(data, series) {
  425. if(series == targetseries)
  426. {
  427. targetDetector.newMeasurement(data);
  428. }
  429. });
  430. var lc;
  431. input.lastColumn.connect(function(c) {
  432. lc = c;
  433. QSettings.setValue("liveColumn", c + 1);
  434. navigationwindow.loggingWindow.postLoadColumnSetup(c)
  435. });
  436. input.annotation.connect(function(note, tcol, ncol) {
  437. for(var i = tcol; i < ncol; i++) {
  438. log.newAnnotation(note, i, ncol);
  439. }
  440. });
  441. }
  442. }
  443. query = query.invalidate();
  444. navigationwindow.loggingWindow.windowTitle = "Typica - [*]" + pname;
  445. navigationwindow.loggingWindow.raise();
  446. navigationwindow.loggingWindow.activateWindow();
  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. });
  454. var noprofilebutton = findChildObject(this, 'noprofile');
  455. noprofilebutton.clicked.connect(function() {
  456. batch.windowModified = true;
  457. currentBatchInfo = batch;
  458. navigationwindow.loggingWindow.raise();
  459. navigationwindow.loggingWindow.activateWindow();
  460. });
  461. var submitbutton = findChildObject(this, 'submit');
  462. var timefield = findChildObject(this, 'time');
  463. var notes = findChildObject(this, 'annotation');
  464. var duration = findChildObject(this, 'duration');
  465. var approval = findChildObject(this, 'approval');
  466. approval.checked = true;
  467. var target = findChildObject(this, 'target');
  468. submitbutton.clicked.connect(function() {
  469. checkQuery = new QSqlQuery();
  470. checkQuery.exec("SELECT 1 FROM machine WHERE id = " + selectedRoasterID);
  471. if(!checkQuery.next())
  472. {
  473. checkQuery.prepare("INSERT INTO machine (id, name) VALUES(:id, :name)");
  474. checkQuery.bind(":id", selectedRoasterID);
  475. checkQuery.bind(":name", selectedRoasterName);
  476. checkQuery.exec();
  477. }
  478. checkQuery = checkQuery.invalidate();
  479. var q = "INSERT INTO files (id, name, type, note, file) VALUES(default, :name, 'profile', NULL, :data) RETURNING id";
  480. query = new QSqlQuery();
  481. query.prepare(q);
  482. query.bind(":name", timefield.text + " " + roasted.currentText);
  483. query.bindFileData(":data", batch.tempData);
  484. query.exec();
  485. query.next();
  486. var fileno = query.value(0);
  487. var file = new QFile(batch.tempData);
  488. file.remove();
  489. var q2 = "INSERT INTO roasting_log (time, unroasted_id, unroasted_quantity, unroasted_total_quantity, roasted_id, roasted_quantity, transaction_type, annotation, machine, duration, approval, humidity, barometric, indoor_air, outdoor_air, files) VALUES(:time, ";
  490. q2 = q2 + table.columnArray(0, 32);
  491. q2 = q2 + ", ";
  492. for(var i = 0; table.data(i, 1, 0).value != ""; i++)
  493. {
  494. table.setData(i, 1, convertToPounds(parseFloat(table.data(i, 1, 0)), unitBox.currentText) ,32)
  495. }
  496. q2 = q2 + table.columnArray(1, 32);
  497. q2 = q2 + ", ";
  498. q2 = q2 + convertToPounds(parseFloat(green.text), unitBox.currentText);
  499. q2 = q2 + ", ";
  500. q2 = q2 + roasted.currentData();
  501. q2 = q2 + ", ";
  502. q2 = q2 + convertToPounds(parseFloat(roastwt.text), unitBox.currentText);
  503. q2 = q2 + ", 'ROAST', :annotation, ";
  504. q2 = q2 + selectedRoasterID;
  505. q2 = q2 + ", :duration, :approval, NULL, NULL, NULL, NULL, '{";
  506. q2 = q2 + fileno;
  507. q2 = q2 + "}')";
  508. query2 = new QSqlQuery();
  509. query2.prepare(q2);
  510. query2.bind(":time", timefield.text);
  511. query2.bind(":annotation", notes.plainText);
  512. query2.bind(":duration", duration.text);
  513. query2.bind(":approval", approval.checked);
  514. query2.exec();
  515. query2 = query2.invalidate();
  516. if(target.checked) {
  517. var q3 = "INSERT INTO item_files (time, item, files) VALUES(:time, :item, '{";
  518. q3 = q3 + fileno;
  519. q3 = q3 + "}')";
  520. query.prepare(q3);
  521. query.bind(":time", timefield.text);
  522. query.bind(":item", roasted.currentData());
  523. query.exec();
  524. }
  525. query = query.invalidate();
  526. batch.windowModified = false;
  527. batch.close();
  528. });
  529. ]]>
  530. </program>
  531. </window>