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.

newsamplebatch.xml 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <window id="sampleRoastingBatch">
  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. <label>Sample Details:</label>
  8. <layout type="grid">
  9. <row>
  10. <column><label>Name:</label></column>
  11. <column><line id="name" /></column>
  12. </row>
  13. <row>
  14. <column><label>Vendor:</label></column>
  15. <column><line id="vendor" /></column>
  16. </row>
  17. <row>
  18. <column><label>Date:</label></column>
  19. <column><calendar id="date" /></column>
  20. </row>
  21. </layout>
  22. <label>Optional Details:</label>
  23. <sqltablearray columns="2" id="attributes">
  24. <column name="Attribute" />
  25. <column name="Value" />
  26. </sqltablearray>
  27. <stretch />
  28. </layout>
  29. <layout type="vertical">
  30. <label>Roasting Details:</label>
  31. <layout type="grid">
  32. <row>
  33. <column><label>Machine:</label></column>
  34. <column><line id="machine" writable="false" /></column>
  35. </row>
  36. <row>
  37. <column><label>Target Profile:</label></column>
  38. <column>
  39. <sqldrop data="0" display="0" showdata="false" editable="true" id="profile">
  40. <query>SELECT DISTINCT profile_name FROM sample_roast_profiles UNION SELECT '' ORDER BY profile_name ASC</query>
  41. </sqldrop>
  42. </column>
  43. </row>
  44. <row>
  45. <column><label>Green Weight:</label></column>
  46. <column><line id="greenWt" /></column>
  47. <column>
  48. <sqldrop data="0" display="0" showdata="false" editable="false" id="Gunits" />
  49. </column>
  50. </row>
  51. <row>
  52. <column><label>Roasted Weight:</label></column>
  53. <column><line id="roastedWt" /></column>
  54. </row>
  55. <row>
  56. <column><label>Weight Loss:</label></column>
  57. <column><line writable="false" id="loss" /></column>
  58. </row>
  59. <row>
  60. <column><label>Time:</label></column>
  61. <column><line id="time" writable="false" /></column>
  62. </row>
  63. <row>
  64. <column><label>Duration:</label></column>
  65. <column><line id="duration" writable="false" /></column>
  66. </row>
  67. </layout>
  68. <label>Notes:</label>
  69. <textarea id="annotation" />
  70. <layout type="horizontal">
  71. <button name="Roast" type="push" id="load" />
  72. <button name="Submit" type="push" id="submit" />
  73. </layout>
  74. <button name="Save log as target profile" type="check" id="target" />
  75. <stretch />
  76. </layout>
  77. <layout type="vertical">
  78. <label>Connected Scales</label>
  79. <layout type="vertical" id="scales" />
  80. <stretch />
  81. </layout>
  82. </layout>
  83. <program>
  84. <![CDATA[
  85. var machine = findChildObject(this, 'machine');
  86. machine.setText(selectedRoasterName + " (" + selectedRoasterID + ")");
  87. var GunitBox = findChildObject(this, 'Gunits');
  88. GunitBox.addItem("g");
  89. GunitBox.addItem("Kg");
  90. GunitBox.addItem("oz");
  91. GunitBox.addItem("lb");
  92. var scalesLayout = findChildObject(this, 'scales');
  93. scalesLayout.spacing = 10;
  94. if(navigationwindow.loggingWindow.scales.length > 0)
  95. {
  96. for(var i = 0; i < navigationwindow.loggingWindow.scales.length; i++)
  97. {
  98. var scale = navigationwindow.loggingWindow.scales[i];
  99. var label = new DragLabel();
  100. var weighButton = new QPushButton();
  101. weighButton.text = "Weigh";
  102. weighButton.clicked.connect(scale.weigh);
  103. label.updateMeasurement = function(m, u) {
  104. switch(GunitBox.currentIndex) {
  105. case 0:
  106. this.text = Units.convertWeight(m, u, Units.Gram).toFixed(1);
  107. break;
  108. case 1:
  109. this.text = Units.convertWeight(m, u, Units.Kilogram).toFixed(4);
  110. break;
  111. case 2:
  112. this.text = Units.convertWeight(m, u, Units.Ounce).toFixed(3);
  113. break;
  114. case 3:
  115. this.text = Units.convertWeight(m, u, Units.Pound).toFixed(4);
  116. break;
  117. }
  118. };
  119. scalesLayout.addWidget(label);
  120. scalesLayout.addWidget(weighButton);
  121. scale.newMeasurement.connect(function(m, u) {
  122. label.updateMeasurement(m, u);
  123. });
  124. scale.weigh();
  125. GunitBox['currentIndexChanged(int)'].connect(scale.weigh);
  126. }
  127. }
  128. var submit = findChildObject(this, 'submit');
  129. submit.setEnabled(false);
  130. this.windowTitle = "Typica - New Sample Roasting Batch";
  131. var newMenu = findChildObject(this, 'new');
  132. newMenu.triggered.connect(function() {
  133. createWindow("sampleRoastingBatch");
  134. });
  135. var batch = this;
  136. batch.submitButton = submit;
  137. var name = findChildObject(this, 'name');
  138. var green = findChildObject(this, 'greenWt');
  139. var roasted = findChildObject(this, 'roastedWt');
  140. var loss = findChildObject(this, 'loss');
  141. var timefield = findChildObject(this, 'time');
  142. var convertToPounds = function(w, u) {
  143. switch(u)
  144. {
  145. case "g":
  146. return w * 0.0022;
  147. case "oz":
  148. return w * 0.0625;
  149. case "Kg":
  150. return w * 2.2;
  151. }
  152. return w;
  153. };
  154. var updateWeightLoss = function() {
  155. var cgreen = parseFloat(green.text);
  156. var croast = parseFloat(roasted.text);
  157. if(cgreen > 0)
  158. {
  159. if(croast > 0)
  160. {
  161. loss.text = (((cgreen - croast) / cgreen) * 100).toFixed(2) + "%";
  162. }
  163. else
  164. {
  165. loss.text = "100%";
  166. }
  167. }
  168. };
  169. green.textChanged.connect(function() {
  170. updateWeightLoss();
  171. });
  172. roasted.textChanged.connect(function() {
  173. updateWeightLoss();
  174. });
  175. var roastButton = findChildObject(this, 'load');
  176. var profileName = findChildObject(this, 'profile');
  177. var greenName = findChildObject(this, 'name');
  178. var stop = findChildObject(navigationwindow.loggingWindow, 'stopbutton');
  179. stop.clicked.connect(function() {
  180. submit.setEnabled(true);
  181. });
  182. roastButton.clicked.connect(function() {
  183. var lc = 1;
  184. currentBatchInfo = batch;
  185. query = new QSqlQuery();
  186. var q = "SELECT file FROM sample_roast_profiles WHERE profile_name = :name AND time = (SELECT max(time) FROM sample_roast_profiles WHERE profile_name = :again)";
  187. query.prepare(q);
  188. query.bind(":name", profileName.currentText);
  189. query.bind(":again", profileName.currentText);
  190. query.exec();
  191. if(query.next())
  192. {
  193. var file = query.value(0);
  194. query.prepare("SELECT file FROM files WHERE id = :id");
  195. query.bind(":id", file);
  196. query.exec();
  197. if(query.next())
  198. {
  199. var targetseries = -1;
  200. var buffer = new QBuffer(query.value(0));
  201. var input = new XMLInput(buffer, 1);
  202. var graph = findChildObject(navigationwindow.loggingWindow, 'graph');
  203. var log = findChildObject(navigationwindow.loggingWindow, 'log');
  204. log.clear();
  205. graph.clear();
  206. input.newTemperatureColumn.connect(function(col, text) {
  207. log.setHeaderData(col, text);
  208. if(text == navigationwindow.loggingWindow.targetcolumnname)
  209. {
  210. targetseries = col;
  211. }
  212. });
  213. input.newAnnotationColumn.connect(log.setHeaderData);
  214. input.measure.connect(graph.newMeasurement);
  215. input.measure.connect(log.newMeasurement);
  216. input.measure.connect(function(data, series) {
  217. if(series == targetseries)
  218. {
  219. targetDetector.newMeasurement(data);
  220. }
  221. });
  222. input.annotation.connect(log.newAnnotation);
  223. input.lastColumn.connect(function(c) {
  224. lc = c;
  225. QSettings.setValue("liveColumn", c+1);
  226. navigationwindow.loggingWindow.postLoadColumnSetup(c);
  227. });
  228. navigationwindow.loggingWindow.raise();
  229. navigationwindow.loggingWindow.activateWindow();
  230. log.updatesEnabled = false;
  231. graph.updatesEnabled = false;
  232. input.input();
  233. graph.updatesEnabled = true;
  234. log.updatesEnabled = true;
  235. log.newAnnotation("End", 1, lc);
  236. }
  237. }
  238. query = query.invalidate();
  239. var t = "Typica - Sample Roasting: [*]" + name.text;
  240. if(profileName.currentText != '')
  241. {
  242. t = t + ", " + profileName.currentText;
  243. }
  244. navigationwindow.loggingWindow.windowTitle = t;
  245. });
  246. var notes = findChildObject(this, 'annotation');
  247. var machine = findChildObject(this, 'machine');
  248. var duration = findChildObject(this, 'duration');
  249. var arrival = findChildObject(this, 'date');
  250. var vendor = findChildObject(this, 'vendor');
  251. var attributes = findChildObject(this, 'attributes');
  252. var target = findChildObject(this, 'target');
  253. submit.clicked.connect(function() {
  254. query = new QSqlQuery();
  255. query.prepare("INSERT INTO files (id, name, type, note, file) VALUES(DEFAULT, :name, 'profile', NULL, :data) RETURNING id");
  256. query.bind(":name", timefield.text + " " + name.text + " " + profileName.currentText);
  257. query.bindFileData(":data", batch.tempData);
  258. query.exec();
  259. query.next();
  260. var fileno = query.value(0);
  261. var file = new QFile(batch.tempData);
  262. file.remove();
  263. if(target.checked)
  264. {
  265. query.prepare("INSERT INTO sample_roast_profiles (time, profile_name, file) VALUES(:time, :name, :file)");
  266. query.bind(":time", timefield.text);
  267. query.bind(":name", profileName.currentText);
  268. query.bind(":file", Number(fileno));
  269. query.exec();
  270. }
  271. var attnames = sqlToArray(attributes.columnArray(0, 0));
  272. for(var i = 0; i < attnames.length; i++)
  273. {
  274. var attname = attnames[i];
  275. if(attname[0] == '{') {
  276. attname = attname.substr(1);
  277. }
  278. if(attname[0] == ' ') {
  279. attname = attname.substr(1);
  280. }
  281. if(attname[attname.length -1] == '}') {
  282. attname = attname.substr(0, attname.length - 1);
  283. }
  284. if(attname.length == 0) {
  285. break;
  286. }
  287. query.prepare("SELECT id FROM item_attributes WHERE name = :name");
  288. query.bind(":name", attname);
  289. query.exec();
  290. if(query.next())
  291. {
  292. attributes.setData(i, 0, query.value(0), 32);
  293. }
  294. else
  295. {
  296. query.prepare("INSERT INTO item_attributes (id, name) VALUES(DEFAULT, :name) RETURNING id");
  297. query.bind(":name", attname);
  298. query.exec();
  299. query.next();
  300. attributes.setData(i, 0, query.value(0), 32);
  301. }
  302. }
  303. query.prepare("INSERT INTO coffee_sample_items (id, name, reference, unit, quantity, category, arrival, vendor, attribute_ids, attribute_values) VALUES(DEFAULT, :name, NULL, 'lb', 0, 'Coffee: Green Sample', :arrival, :vendor, :attrids, :attrvals) RETURNING id");
  304. query.bind(":name", name.text);
  305. query.bind(":arrival", arrival.date);
  306. query.bind(":vendor", vendor.text);
  307. query.bind(":attrids", attributes.bindableColumnArray(0, 32));
  308. query.bind(":attrvals", attributes.bindableQuotedColumnArray(1, 0));
  309. query.exec();
  310. query.next();
  311. var greenId = query.value(0);
  312. query.prepare("INSERT INTO items (id, name, reference, unit, quantity, category) VALUES(DEFAULT, :name, NULL, 'lb', 0, 'Coffee: Roasted Sample') RETURNING id");
  313. query.bind(":name", name.text + " " + profileName.currentText);
  314. query.exec();
  315. query.next();
  316. var roastedId = query.value(0);
  317. query.prepare("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, :unroastedids, :greens, :green, :roastedid, :roasted, 'SAMPLEROAST', :note, :machine, :duration, TRUE, NULL, NULL, NULL, NULL, :files)");
  318. query.bind(":time", timefield.text);
  319. query.bind(":unroastedids", "{" + greenId + "}");
  320. query.bind(":greens", "{" + convertToPounds(parseFloat(green.text), GunitBox.currentText) + "}");
  321. query.bind(":green", convertToPounds(parseFloat(green.text), GunitBox.currentText));
  322. query.bind(":roastedid", Number(roastedId));
  323. query.bind(":roasted", convertToPounds(parseFloat(roasted.text), GunitBox.currentText));
  324. query.bind(":note", notes.plainText);
  325. query.bind(":machine", Number(selectedRoasterID));
  326. query.bind(":duration", duration.text);
  327. query.bind(":files", "{" + fileno + "}");
  328. query.exec();
  329. query = query.invalidate();
  330. batch.close();
  331. });
  332. ]]>
  333. </program>
  334. </window>