Typica is a free program for professional coffee roasters. https://typica.us
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

cuppingsession.xml 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <window id="session">
  2. <layout type="vertical">
  3. <layout type="horizontal">
  4. <label>Event:</label>
  5. <line id="event" />
  6. <label>Session:</label>
  7. <line id="session" />
  8. <label>Date:</label>
  9. <calendar id="date" />
  10. <button name="Blind" id="blind" type="check" />
  11. <button name="Add Sample" id="sample" type="push" />
  12. <button name="Add Item" id="additem" type="push" />
  13. </layout>
  14. <formarray id="form">
  15. <layout type="vertical">
  16. <layout type="horizontal">
  17. <label>Sample ID:</label>
  18. <line id="sample" />
  19. <label>Roasted At:</label>
  20. <line id="time" writable="false" />
  21. <label>On:</label>
  22. <line id="machine" writable="false" />
  23. </layout>
  24. <layout type="horizontal">
  25. <label>Time:</label>
  26. <line id="duration" writable="false" />
  27. <label>Bean Temperature:</label>
  28. <line id="temp" writable="false" />
  29. <label>Annotation:</label>
  30. <line id="note" writable="false" />
  31. </layout>
  32. <layout type="horizontal">
  33. <label>Item:</label>
  34. <line id="item" writable="false" />
  35. <label>Table Position:</label>
  36. <line id="position" />
  37. </layout>
  38. </layout>
  39. </formarray>
  40. <button type="push" name="Create Session" id="submit" />
  41. </layout>
  42. <program>
  43. <![CDATA[
  44. var window = this;
  45. this.showMaximized();
  46. var samples = findChildObject(this, 'form');
  47. var addSampleButton = findChildObject(this, 'sample');
  48. var addItemButton = findChildObject(this, 'additem');
  49. var submitButton = findChildObject(this, 'submit');
  50. addItemButton.clicked.connect(function() {
  51. var selectWindow = createWindow("sampleitemselection");
  52. var itemdrop = findChildObject(selectWindow, 'item');
  53. var button1 = findChildObject(selectWindow, 'additem');
  54. button1.clicked.connect(function() {
  55. samples.addElements(1);
  56. sampleID = findChildObject(samples.elementAt(samples.elements() - 1), 'sample');
  57. sampleID.text = itemdrop.currentText;
  58. position = findChildObject(samples.elementAt(samples.elements() - 1), 'position');
  59. position.text = samples.elements();
  60. itemID = findChildObject(samples.elementAt(samples.elements() - 1), 'item');
  61. itemID.text = itemdrop.currentData();
  62. selectWindow.close();
  63. });
  64. var itemname = findChildObject(selectWindow, 'itemname');
  65. var button2 = findChildObject(selectWindow, 'newitem');
  66. button2.clicked.connect(function() {
  67. samples.addElements(1);
  68. sampleID = findChildObject(samples.elementAt(samples.elements() - 1), 'sample');
  69. sampleID.text = itemname.text;
  70. position = findChildObject(samples.elementAt(samples.elements() - 1), 'position');
  71. position.text = samples.elements();
  72. var q = "INSERT INTO items VALUES(default, :name, NULL, 'lb', 0, 'Coffee: Sample') RETURNING id";
  73. var query = new QSqlQuery;
  74. query.prepare(q);
  75. query.bind(":name", itemname.text);
  76. query.exec();
  77. query.next();
  78. itemID = findChildObject(samples.elementAt(samples.elements() - 1), 'item');
  79. itemID.text = query.value(0);
  80. selectWindow.close();
  81. });
  82. });
  83. addSampleButton.clicked.connect(function() {
  84. var selectWindow = createWindow("sampleselection");
  85. var sampleTable = findChildObject(selectWindow, 'table');
  86. sampleTable.openEntry.connect(function(arg) {
  87. var q = "SELECT files FROM roasting_log WHERE time = :time";
  88. var query = new QSqlQuery;
  89. query.prepare(q);
  90. query.bind(":time", arg);
  91. var batchTime = arg;
  92. query.exec();
  93. var file = null;
  94. while(query.next())
  95. {
  96. var files = sqlToArray(query.value(0));
  97. for(var i = 0; i < files.length; i++)
  98. {
  99. q = "SELECT type FROM files WHERE id = :id";
  100. query.prepare(q);
  101. query.bind(":id", files[i]);
  102. query.exec();
  103. query.next();
  104. if(query.value(0) == "profile")
  105. {
  106. q = "SELECT file FROM files WHERE id = :id";
  107. query.prepare(q);
  108. query.bind(":id", files[i]);
  109. query.exec();
  110. query.next();
  111. file = query.value(0);
  112. break;
  113. }
  114. }
  115. if(file)
  116. {
  117. break;
  118. }
  119. }
  120. if(file)
  121. {
  122. var pointwindow = createWindow("selectsamples");
  123. var selectButton = findChildObject(pointwindow, 'select');
  124. selectButton.clicked.connect(function() {
  125. var checkbox;
  126. var sampleID;
  127. var roastTime;
  128. var machineID;
  129. var sampleDuration;
  130. var sampleBeanTemperature;
  131. var sampleAnnotation;
  132. var position;
  133. for(var i = 0; i < selectform.elements(); i++)
  134. {
  135. checkbox = findChildObject(selectform.elementAt(i), 'include');
  136. if(checkbox.checked)
  137. {
  138. samples.addElements(1);
  139. sampleID = findChildObject(samples.elementAt(samples.elements() - 1), 'sample');
  140. roastTime = findChildObject(samples.elementAt(samples.elements() - 1), 'time');
  141. machineID = findChildObject(samples.elementAt(samples.elements() - 1), 'machine');
  142. sampleDuration = findChildObject(samples.elementAt(samples.elements() - 1), 'duration');
  143. sampleBeanTemperature = findChildObject(samples.elementAt(samples.elements() - 1), 'temp');
  144. sampleAnnotation = findChildObject(samples.elementAt(samples.elements() - 1), 'note');
  145. position = findChildObject(samples.elementAt(samples.elements() - 1), 'position');
  146. sampleDuration.text = findChildObject(selectform.elementAt(i), 'time').text;
  147. sampleBeanTemperature.text = findChildObject(selectform.elementAt(i), 'temp').text;
  148. sampleAnnotation.text = findChildObject(selectform.elementAt(i), 'note').text;
  149. sampleID.text = sampleAnnotation.text;
  150. roastTime.text = batchTime;
  151. var q2 = "SELECT machine FROM roasting_log WHERE time = :time";
  152. var query2 = new QSqlQuery;
  153. query2.prepare(q2);
  154. query2.bind(":time", batchTime);
  155. query2.exec();
  156. query2.next();
  157. machineID.text = query2.value(0);
  158. position.text = samples.elements();
  159. }
  160. }
  161. pointwindow.close();
  162. });
  163. pointwindow.hide();
  164. var buffer = new QBuffer(file);
  165. buffer.open(1);
  166. var xq = new XQuery;
  167. xq.bind("profile", buffer);
  168. xq.setQuery('for $t in doc($profile) //tuple where exists ($t/annotation) return (string($t/time), ";", string($t/temperature[1]), ";", string($t/annotation), "~")');
  169. var result = xq.exec();
  170. buffer.close();
  171. var records = result.split("~");
  172. var selectform = findChildObject(pointwindow, 'form');
  173. var time;
  174. var temp;
  175. var note;
  176. for(var i = 0; i < records.length - 1; i++)
  177. {
  178. selectform.addElements(1);
  179. var record = records[i];
  180. var fields = record.split(";");
  181. time = findChildObject(selectform.elementAt(i), 'time');
  182. time.text = fields[0].replace(/^\s+|\s+$/g,"");
  183. temp = findChildObject(selectform.elementAt(i), 'temp');
  184. temp.text = fields[1].replace(/^\s+|\s+$/g,"");
  185. note = findChildObject(selectform.elementAt(i), 'note');
  186. note.text = fields[2].replace(/^\s+|\s+$/g,"");
  187. }
  188. pointwindow.showMaximized();
  189. }
  190. });
  191. });
  192. submitButton.clicked.connect(function() {
  193. var q = "INSERT INTO cupping_sessions VALUES (default, :event, :name, :time, :blind, true, NULL) RETURNING id";
  194. var query = new QSqlQuery;
  195. query.prepare(q);
  196. var eventField = findChildObject(window, 'event');
  197. if(eventField.text == "")
  198. {
  199. query.bind(":event", null);
  200. }
  201. else
  202. {
  203. query.bind(":event", eventField.text);
  204. }
  205. var nameField = findChildObject(window, 'session');
  206. query.bind(":name", nameField.text);
  207. var timeField = findChildObject(window, 'date');
  208. query.bind(":time", timeField.date);
  209. var blindBox = findChildObject(window, 'blind');
  210. query.bind(":blind", blindBox.checked);
  211. query.exec();
  212. query.next();
  213. var newSessionID = query.value(0);
  214. q = "INSERT INTO cupping_samples VALUES(:session, :sample, :position, :type, :time, :machine, :point, :item)";
  215. query.prepare(q);
  216. query.bind(":session", newSessionID);
  217. var element;
  218. for(var i = 0; i < samples.elements(); i++)
  219. {
  220. element = samples.elementAt(i);
  221. query.bind(":sample", findChildObject(element, 'sample').text);
  222. query.bind(":position", Number(findChildObject(element, 'position').text));
  223. var elementItem = findChildObject(element, 'item');
  224. if(elementItem.text == "")
  225. {
  226. query.bind(":type", "SAMPLE");
  227. query.bind(":time", findChildObject(element, 'time').text);
  228. query.bind(":machine", Number(findChildObject(element, 'machine').text));
  229. query.bind(":point", findChildObject(element, 'duration').text);
  230. query.bind(":item", null);
  231. }
  232. else
  233. {
  234. query.bind(":type", "ITEM");
  235. query.bind(":time", null);
  236. query.bind(":machine", null);
  237. query.bind(":point", null);
  238. query.bind(":item", elementItem.text);
  239. }
  240. query.exec();
  241. }
  242. window.close();
  243. });
  244. ]]>
  245. </program>
  246. </window>