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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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="2" 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" />
  26. </sqltablearray>
  27. <layout type="horizontal">
  28. <label>Green Weight:</label>
  29. <line id="green" writable="false">0.0</line>
  30. </layout>
  31. <layout type="horizontal">
  32. <button name="Load Profile" type="push" id="load" />
  33. <button name="No Profile" type="push" id="noprofile" />
  34. </layout>
  35. <layout type="horizontal">
  36. <label>Time:</label>
  37. <line id="time" writable="false" />
  38. <label>Duration:</label>
  39. <line id="duration" writable="false" />
  40. </layout>
  41. <layout type="horizontal">
  42. <label>Roasted Weight:</label>
  43. <line id="roast" validator="numeric" />
  44. <label>Weight Loss:</label>
  45. <line id="wloss" writable="false" />
  46. <button type="check" id="approval" name="Approved" />
  47. </layout>
  48. <layout type="horizontal">
  49. <label>Annotation:</label>
  50. <textarea id="annotation" />
  51. </layout>
  52. <layout type="horizontal">
  53. <button name="Submit" id="submit" type="push" />
  54. <button name="Save log as target profile" type="check" id="target" />
  55. </layout>
  56. </layout>
  57. <layout type="vertical">
  58. <label>Connected Scales</label>
  59. <layout type="vertical" id="scales" />
  60. <stretch />
  61. </layout>
  62. </layout>
  63. <program>
  64. <![CDATA[
  65. var unitBox = findChildObject(this, 'unit');
  66. unitBox.addItem("g");
  67. unitBox.addItem("Kg");
  68. unitBox.addItem("oz");
  69. unitBox.addItem("lb");
  70. unitBox.currentIndex = (QSettings.value("script/batch_unit", unitBox.findText("lb")));
  71. var machine = findChildObject(this, "machine");
  72. machine.setText(selectedRoasterName + " (" + selectedRoasterID + ")");
  73. var newMenu = findChildObject(this, 'new');
  74. newMenu.triggered.connect(function() {
  75. var bwindow = createWindow("batchWindow");
  76. bwindow.windowTitle = "Typica - [*]New Batch";
  77. });
  78. var batch = this;
  79. var table = findChildObject(this, 'greens');
  80. var green = findChildObject(this, 'green');
  81. var model = table.model();
  82. var lossField = findChildObject(this, 'wloss');
  83. lossField.maximumWidth = 80;
  84. var roasted = findChildObject(this, 'roasted');
  85. var roastwt = findChildObject(this, 'roast');
  86. roastwt.maximumWidth = 80;
  87. var scalesLayout = findChildObject(this, 'scales');
  88. scalesLayout.spacing = 10;
  89. if(navigationwindow.loggingWindow.scales.length > 0) {
  90. for(var i = 0; i < navigationwindow.loggingWindow.scales.length; i++) {
  91. var scale = navigationwindow.loggingWindow.scales[i];
  92. var label = new DragLabel();
  93. var weighButton = new QPushButton();
  94. weighButton.text = "Weigh";
  95. weighButton.clicked.connect(scale.weigh);
  96. label.updateMeasurement = function(m, u) {
  97. switch(unitBox.currentIndex) {
  98. case 0:
  99. this.text = Units.convertWeight(m, u, Units.Gram).toFixed(1);
  100. break;
  101. case 1:
  102. this.text = Units.convertWeight(m, u, Units.Kilogram).toFixed(4);
  103. break;
  104. case 2:
  105. this.text = Units.convertWeight(m, u, Units.Ounce).toFixed(3);
  106. break;
  107. case 3:
  108. this.text = Units.convertWeight(m, u, Units.Pound).toFixed(4);
  109. break;
  110. }
  111. };
  112. scalesLayout.addWidget(label);
  113. scalesLayout.addWidget(weighButton);
  114. scale.newMeasurement.connect(function(m, u) {
  115. label.updateMeasurement(m, u);
  116. });
  117. scale.weigh();
  118. unitBox['currentIndexChanged(int)'].connect(scale.weigh);
  119. }
  120. }
  121. model.dataChanged.connect(function() {
  122. var deleteRow = -1;
  123. /* The combo box delegate updates user data before display data
  124. and this code is executed before the model update is fully
  125. complete. Rather than rely on this behavior continuing, we
  126. check that the display value has also been updated and defer
  127. row removal until both updates are complete.
  128. */
  129. while((deleteRow = table.findData("delete", 0)) > -1) {
  130. if(table.data(deleteRow, 0, 0) == "Delete") {
  131. table.removeRow(table.findData("delete", 0));
  132. } else {
  133. break;
  134. }
  135. }
  136. green.text = table.columnSum(1, 0);
  137. table.resizeColumnToContents(0);
  138. if(parseFloat(green.text) > 0)
  139. {
  140. if(parseFloat(roastwt.text) > 0)
  141. {
  142. lossField.text = (((parseFloat(green.text) - parseFloat(roastwt.text)) / parseFloat(green.text)) * 100).toFixed(2) + "%";
  143. }
  144. else
  145. {
  146. lossField.text = "100%";
  147. }
  148. }
  149. });
  150. roastwt.textChanged.connect(function() {
  151. if(parseFloat(green.text) > 0)
  152. {
  153. if(parseFloat(roastwt.text) > 0)
  154. {
  155. lossField.text = (((parseFloat(green.text) - parseFloat(roastwt.text)) / parseFloat(green.text)) * 100).toFixed(2) + "%";
  156. }
  157. else
  158. {
  159. lossField.text = "100%";
  160. }
  161. }
  162. });
  163. var convertToPounds = function(w, u) {
  164. switch(u) {
  165. case "g":
  166. return w * 0.0022;
  167. case "oz":
  168. return w * 0.0625;
  169. case "Kg":
  170. return w * 2.2;
  171. }
  172. return w;
  173. };
  174. var profilebutton = findChildObject(this, 'load');
  175. profilebutton.setEnabled(false);
  176. roasted['currentIndexChanged(int)'].connect(function() {
  177. table.clear();
  178. var query = new QSqlQuery();
  179. var q = "SELECT EXISTS(SELECT 1 FROM item_files WHERE item = ";
  180. q = q + roasted.currentData();
  181. q = q + ")";
  182. query.exec(q);
  183. if(query.next())
  184. {
  185. if(query.value(0) == 'false')
  186. {
  187. profilebutton.setEnabled(false);
  188. }
  189. else
  190. {
  191. profilebutton.setEnabled(true);
  192. }
  193. }
  194. else
  195. {
  196. profilebutton.setEnabled(false);
  197. }
  198. var title = "Typica - [*]New Batch (";
  199. title = title + roasted.currentText;
  200. title = title + ")";
  201. batch.windowTitle = title;
  202. q = "SELECT unroasted_id FROM roasting_log WHERE roasted_id = ";
  203. q = q + roasted.currentData();
  204. q = q + " AND time = (SELECT max(time) FROM roasting_log WHERE roasted_id = ";
  205. q = q + roasted.currentData();
  206. q = q + ")";
  207. query.exec(q);
  208. if(query.next())
  209. {
  210. var unroasted_items = sqlToArray(query.value(0));
  211. var names = [];
  212. q = "SELECT name FROM items WHERE id = :id AND quantity <> 0";
  213. query.prepare(q);
  214. var allInStock = true;
  215. for(var i = 0; i < unroasted_items.length; i++)
  216. {
  217. query.bind("id", unroasted_items[i]);
  218. query.exec();
  219. if(query.next())
  220. {
  221. names[i] = query.value(0);
  222. }
  223. else
  224. {
  225. allInStock = false;
  226. }
  227. }
  228. if(allInStock)
  229. {
  230. for(var i = 0; i < unroasted_items.length; i++)
  231. {
  232. table.setData(i, 0, names[i], 0);
  233. table.setData(i, 0, unroasted_items[i], 32);
  234. }
  235. }
  236. }
  237. });
  238. profilebutton.clicked.connect(function() {
  239. batch.windowModified = true;
  240. currentBatchInfo = batch;
  241. query = new QSqlQuery();
  242. var q = "SELECT files FROM item_files WHERE item = :item AND time = (SELECT max(time) FROM item_files WHERE item = :again)";
  243. query.prepare(q);
  244. query.bind(":item", Number(roasted.currentData()));
  245. query.bind(":again", Number(roasted.currentData()));
  246. query.exec();
  247. if(query.next())
  248. {
  249. var files = query.value(0);
  250. files = files.replace("{", "(");
  251. files = files.replace("}", ")");
  252. q = "SELECT file, name FROM files WHERE id IN ";
  253. q = q + files;
  254. q = q + " AND type = 'profile'";
  255. query.exec(q);
  256. if(query.next())
  257. {
  258. var targetseries = -1;
  259. var buffer = new QBuffer(query.value(0));
  260. var pname = query.value(1);
  261. var input = new XMLInput(buffer, 1);
  262. var graph = findChildObject(navigationwindow.loggingWindow, 'graph');
  263. var log = findChildObject(navigationwindow.loggingWindow, 'log');
  264. log.clear();
  265. graph.clear();
  266. input.newTemperatureColumn.connect(log.setHeaderData);
  267. input.newTemperatureColumn.connect(function(col, text) {
  268. if(text == navigationwindow.loggingWindow.targetcolumnname)
  269. {
  270. targetseries = col;
  271. }
  272. });
  273. input.newAnnotationColumn.connect(log.setHeaderData);
  274. input.measure.connect(graph.newMeasurement);
  275. input.measure.connect(log.newMeasurement);
  276. input.measure.connect(function(data, series) {
  277. if(series == targetseries)
  278. {
  279. targetDetector.newMeasurement(data);
  280. }
  281. });
  282. var lc;
  283. input.lastColumn.connect(function(c) {
  284. lc = c;
  285. QSettings.setValue("liveColumn", c + 1);
  286. navigationwindow.loggingWindow.postLoadColumnSetup(c)
  287. });
  288. input.annotation.connect(function(note, tcol, ncol) {
  289. for(var i = tcol; i < ncol; i++) {
  290. log.newAnnotation(note, i, ncol);
  291. }
  292. });
  293. }
  294. }
  295. query = query.invalidate();
  296. navigationwindow.loggingWindow.windowTitle = "Typica - [*]" + pname;
  297. navigationwindow.loggingWindow.raise();
  298. navigationwindow.loggingWindow.activateWindow();
  299. input.input();
  300. log.newAnnotation("End", 1, lc);
  301. });
  302. var noprofilebutton = findChildObject(this, 'noprofile');
  303. noprofilebutton.clicked.connect(function() {
  304. batch.windowModified = true;
  305. currentBatchInfo = batch;
  306. navigationwindow.loggingWindow.raise();
  307. navigationwindow.loggingWindow.activateWindow();
  308. });
  309. var submitbutton = findChildObject(this, 'submit');
  310. var timefield = findChildObject(this, 'time');
  311. var notes = findChildObject(this, 'annotation');
  312. var duration = findChildObject(this, 'duration');
  313. var approval = findChildObject(this, 'approval');
  314. var target = findChildObject(this, 'target');
  315. submitbutton.clicked.connect(function() {
  316. checkQuery = new QSqlQuery();
  317. checkQuery.exec("SELECT 1 FROM machine WHERE id = " + selectedRoasterID);
  318. if(!checkQuery.next())
  319. {
  320. checkQuery.prepare("INSERT INTO machine VALUES(:id, :name)");
  321. checkQuery.bind(":id", selectedRoasterID);
  322. checkQuery.bind(":name", selectedRoasterName);
  323. checkQuery.exec();
  324. }
  325. checkQuery = checkQuery.invalidate();
  326. var q = "INSERT INTO files VALUES(default, :name, 'profile', NULL, :data) RETURNING id";
  327. query = new QSqlQuery();
  328. query.prepare(q);
  329. query.bind(":name", timefield.text + " " + roasted.currentText);
  330. query.bindFileData(":data", batch.tempData);
  331. query.exec();
  332. query.next();
  333. var fileno = query.value(0);
  334. var file = new QFile(batch.tempData);
  335. file.remove();
  336. var q2 = "INSERT INTO roasting_log VALUES(:time, ";
  337. q2 = q2 + table.columnArray(0, 32);
  338. q2 = q2 + ", ";
  339. for(var i = 0; table.data(i, 1, 0).value != ""; i++)
  340. {
  341. table.setData(i, 1, convertToPounds(parseFloat(table.data(i, 1, 0)), unitBox.currentText) ,32)
  342. }
  343. q2 = q2 + table.columnArray(1, 32);
  344. q2 = q2 + ", ";
  345. q2 = q2 + convertToPounds(parseFloat(green.text), unitBox.currentText);
  346. q2 = q2 + ", ";
  347. q2 = q2 + roasted.currentData();
  348. q2 = q2 + ", ";
  349. q2 = q2 + convertToPounds(parseFloat(roastwt.text), unitBox.currentText);
  350. q2 = q2 + ", 'ROAST', :annotation, ";
  351. q2 = q2 + selectedRoasterID;
  352. q2 = q2 + ", :duration, :approval, NULL, NULL, NULL, NULL, '{";
  353. q2 = q2 + fileno;
  354. q2 = q2 + "}')";
  355. query2 = new QSqlQuery();
  356. query2.prepare(q2);
  357. query2.bind(":time", timefield.text);
  358. query2.bind(":annotation", notes.plainText);
  359. query2.bind(":duration", duration.text);
  360. query2.bind(":approval", approval.checked);
  361. query2.exec();
  362. query2 = query2.invalidate();
  363. if(target.checked) {
  364. var q3 = "INSERT INTO item_files VALUES(:time, :item, '{";
  365. q3 = q3 + fileno;
  366. q3 = q3 + "}')";
  367. query.prepare(q3);
  368. query.bind(":time", timefield.text);
  369. query.bind(":item", roasted.currentData());
  370. query.exec();
  371. }
  372. query = query.invalidate();
  373. batch.windowModified = false;
  374. batch.close();
  375. });
  376. ]]>
  377. </program>
  378. </window>