Typica is a free program for professional coffee roasters. https://typica.us
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

batchdetailsnew.xml 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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="viewprofile" name="View profile" />
  6. <button type="push" id="compare" name="Compare profile" />
  7. <button type="push" id="edit" name="Edit" />
  8. </layout>
  9. <webview id="view" />
  10. </layout>
  11. <program>
  12. <![CDATA[
  13. var window = this;
  14. dataView = findChildObject(this, 'view');
  15. var fileID;
  16. var target = findChildObject(this, 'target');
  17. var compare = findChildObject(this, 'compare');
  18. var edit = findChildObject(this, 'edit');
  19. edit.enabled = false;
  20. if(typeof(navigationwindow) == "undefined") {
  21. compare.enabled = false;
  22. target.enabled = false;
  23. } else if(typeof(navigationwindow.loggingWindow) == "undefined") {
  24. compare.enabled = false;
  25. target.enabled = false;
  26. }
  27. var tableReference;
  28. var rowReference;
  29. var batchTime;
  30. var machine;
  31. var approval;
  32. var annotation;
  33. edit.clicked.connect(function() {
  34. var editWindow = createWindow("editBatchDetails");
  35. editWindow.loadData(window, tableReference, rowReference, batchTime, machine, approval, annotation);
  36. });
  37. compare.clicked.connect(function() {
  38. var query = new QSqlQuery;
  39. query.prepare("SELECT file, name FROM files WHERE id = :id");
  40. query.bind(":id", Number(fileID));
  41. query.exec();
  42. query.next();
  43. var buffer = new QBuffer(query.value(0));
  44. var pname = query.value(1);
  45. query = query.invalidate();
  46. var startSeries = Number(QSettings.value('cseries', 3));
  47. var nextSeries = startSeries + 2;
  48. QSettings.setValue('cseries', nextSeries);
  49. var input = new XMLInput(buffer, startSeries);
  50. var graph = findChildObject(navigationwindow.loggingWindow, 'graph');
  51. input.measure.connect(graph.newMeasurement);
  52. input.input();
  53. query = query.invalidate();
  54. });
  55. target.clicked.connect(function() {
  56. var query = new QSqlQuery;
  57. query.prepare("SELECT file, name FROM files WHERE id = :id");
  58. query.bind(":id", Number(fileID));
  59. query.exec();
  60. query.next();
  61. var buffer = new QBuffer(query.value(0));
  62. var pname = query.value(1);
  63. query = query.invalidate();
  64. var input = new XMLInput(buffer, 1);
  65. var graph = findChildObject(navigationwindow.loggingWindow, 'graph');
  66. var log = findChildObject(navigationwindow.loggingWindow, 'log');
  67. log.clear();
  68. graph.clear();
  69. input.newTemperatureColumn.connect(log.setHeaderData);
  70. input.newTemperatureColumn.connect(function(col, text) {
  71. if(text == navigationwindow.loggingWindow.targetcolumnname)
  72. {
  73. targetseries = col;
  74. }
  75. });
  76. input.newAnnotationColumn.connect(log.setHeaderData);
  77. input.measure.connect(graph.newMeasurement);
  78. input.measure.connect(log.newMeasurement);
  79. input.measure.connect(function(data, series) {
  80. if(series == targetseries)
  81. {
  82. targetDetector.newMeasurement(data);
  83. }
  84. });
  85. var lc;
  86. input.lastColumn.connect(function(c) {
  87. lc = c;
  88. QSettings.setValue("liveColumn", c + 1);
  89. navigationwindow.loggingWindow.postLoadColumnSetup(c);
  90. });
  91. input.annotation.connect(log.newAnnotation);
  92. input.annotation.connect(function(note, tcol, ncol) {
  93. for(var i = tcol; i < ncol; i++) {
  94. log.newAnnotation(note, i, ncol);
  95. }
  96. });
  97. navigationwindow.loggingWindow.windowTitle = "Typica - " + pname;
  98. navigationwindow.loggingWindow.raise();
  99. navigationwindow.loggingWindow.activateWindow();
  100. input.input();
  101. log.newAnnotation("End", 1, lc);
  102. query = query.invalidate();
  103. });
  104. var viewbutton = findChildObject(this, 'viewprofile');
  105. viewbutton.clicked.connect(function() {
  106. var query = new QSqlQuery;
  107. query.prepare("SELECT file, name FROM files WHERE id = :id");
  108. query.bind(":id", Number(fileID));
  109. query.exec();
  110. if(query.next()) {
  111. var viewer = createWindow('offline');
  112. var buffer = new QBuffer(query.value(0));
  113. var pname = query.value(1);
  114. query = query.invalidate();
  115. var input = new XMLInput(buffer, 1);
  116. var graph = findChildObject(viewer, 'graph');
  117. var log = findChildObject(viewer, 'log');
  118. input.newTemperatureColumn.connect(log.setHeaderData);
  119. input.newTemperatureColumn.connect(function(column) {
  120. viewer.saveTemperatureColumns.push(column);
  121. });
  122. input.newAnnotationColumn.connect(log.setHeaderData);
  123. input.newAnnotationColumn.connect(function(column) {
  124. viewer.saveAnnotationColumns.push(column);
  125. });
  126. input.measure.connect(graph.newMeasurement);
  127. input.measure.connect(log.newMeasurement);
  128. input.annotation.connect(log.newAnnotation);
  129. var lc;
  130. input.lastColumn.connect(function(c) {
  131. lc = c;
  132. if(c < 3)
  133. {
  134. log.setHeaderData(3, "");
  135. }
  136. });
  137. input.annotation.connect(function(note, tcol, ncol) {
  138. for(var i = tcol; i < ncol; i++) {
  139. log.newAnnotation(note, i, ncol);
  140. }
  141. });
  142. viewer.windowTitle = "Typica - " + pname;
  143. viewer.raise();
  144. viewer.activateWindow();
  145. input.input();
  146. log.newAnnotation("End", 1, lc);
  147. }
  148. else {
  149. print("Query returned no results");
  150. }
  151. query = query.invalidate();
  152. });
  153. window.loadData = function(table, row) {
  154. tableReference = table;
  155. rowReference = row;
  156. var buffer = new QBuffer;
  157. buffer.open(3);
  158. var output = new XmlWriter(buffer);
  159. output.writeStartDocument("1.0");
  160. 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">');
  161. output.writeStartElement("html");
  162. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  163. output.writeStartElement("head");
  164. output.writeTextElement("title", "Batch Details");
  165. output.writeEndElement();
  166. output.writeStartElement("body");
  167. output.writeStartElement("div");
  168. output.writeAttribute("style", "float: left; padding-right: 10px");
  169. output.writeStartElement("p");
  170. output.writeTextElement("strong", "Roasted Coffee: ");
  171. output.writeTextElement("span", table.data(row, 2));
  172. output.writeEndElement();
  173. output.writeEndElement();
  174. output.writeStartElement("div");
  175. output.writeAttribute("style", "float: left");
  176. output.writeStartElement("p");
  177. output.writeTextElement("strong", "Roasted On: ");
  178. batchTime = table.data(row, 0);
  179. output.writeTextElement("span", batchTime);
  180. output.writeEndElement();
  181. output.writeStartElement("p");
  182. output.writeTextElement("strong", "Batch Duration: ");
  183. output.writeTextElement("span", table.data(row, 6));
  184. output.writeEndElement();
  185. output.writeEndElement();
  186. output.writeStartElement("div");
  187. output.writeAttribute("style", "clear: both");
  188. output.writeEndElement();
  189. output.writeStartElement("table");
  190. output.writeStartElement("thead");
  191. output.writeStartElement("tr");
  192. output.writeTextElement("th", "Green Coffee");
  193. output.writeTextElement("th", "Weight (lb)");
  194. output.writeEndElement();
  195. output.writeEndElement();
  196. output.writeStartElement("tbody");
  197. var query = new QSqlQuery();
  198. query.prepare("SELECT unroasted_id, unroasted_quantity, approval, files, annotation FROM roasting_log WHERE time = :time AND machine = :machine");
  199. query.bind(":time", batchTime);
  200. machine = table.data(row, 1);
  201. query.bind(":machine", machine);
  202. query.exec();
  203. query.next();
  204. approval = query.value(2);
  205. annotation = query.value(4);
  206. var items = sqlToArray(query.value(0));
  207. var quantities = sqlToArray(query.value(1));
  208. var nameQuery = new QSqlQuery();
  209. nameQuery.prepare("SELECT name FROM items WHERE id = :id");
  210. for(var i = 0; i < items.length; i++) {
  211. output.writeStartElement("tr");
  212. nameQuery.bind(":id", items[i]);
  213. nameQuery.exec();
  214. nameQuery.next();
  215. output.writeTextElement("td", nameQuery.value(0));
  216. output.writeStartElement("td");
  217. output.writeAttribute("align", "center");
  218. output.writeCharacters(quantities[i]);
  219. output.writeEndElement();
  220. output.writeEndElement();
  221. }
  222. nameQuery = nameQuery.invalidate();
  223. output.writeEndElement();
  224. output.writeStartElement("tfoot");
  225. output.writeStartElement("tr");
  226. output.writeStartElement("td");
  227. output.writeAttribute("align", "right");
  228. output.writeTextElement("strong", "Green Total:");
  229. output.writeEndElement();
  230. output.writeStartElement("td");
  231. output.writeAttribute("align", "center");
  232. output.writeCharacters(table.data(row, 3));
  233. output.writeEndElement();
  234. output.writeEndElement();
  235. output.writeStartElement("tr");
  236. output.writeStartElement("td");
  237. output.writeAttribute("align", "right");
  238. output.writeTextElement("strong", "Roasted Weight:");
  239. output.writeEndElement();
  240. output.writeStartElement("td");
  241. output.writeAttribute("align", "center");
  242. output.writeCharacters(table.data(row, 4));
  243. output.writeEndElement();
  244. output.writeEndElement();
  245. output.writeStartElement("tr");
  246. output.writeStartElement("td");
  247. output.writeAttribute("align", "right");
  248. output.writeTextElement("strong", "Weight Loss:");
  249. output.writeEndElement();
  250. output.writeStartElement("td");
  251. output.writeAttribute("align", "center");
  252. output.writeCharacters(table.data(row, 5));
  253. output.writeCharacters("%");
  254. output.writeEndElement();
  255. output.writeEndElement();
  256. output.writeEndElement();
  257. output.writeEndElement();
  258. output.writeStartElement("p");
  259. output.writeTextElement("strong", "Approved: ");
  260. output.writeCharacters(approval);
  261. output.writeEndElement();
  262. output.writeStartElement("p");
  263. output.writeTextElement("strong", "Files: ");
  264. output.writeCharacters(query.value(3));
  265. output.writeEndElement();
  266. output.writeStartElement("p");
  267. output.writeTextElement("strong", "Annotations:");
  268. var files = sqlToArray(query.value(3));
  269. var annotations = annotationFromRecord(files[0]);
  270. fileID = files[0];
  271. var buffer2 = new QBuffer("<points>"+annotations+"</points>");
  272. buffer2.open(1);
  273. var colQuery = new XQuery;
  274. colQuery.bind("profile", buffer2);
  275. colQuery.setQuery('for $i in doc($profile)//tuple[1]/temperature/@series return (string($i), ";")');
  276. var result = colQuery.exec();
  277. buffer2.close();
  278. var seriesHeaders = new Array();
  279. seriesHeaders.push("Time");
  280. var records = result.split(";");
  281. for(var i = 0; i < records.length - 1; i++) {
  282. seriesHeaders.push(records[i].replace(/^\s+|\s+$/g,""));
  283. }
  284. seriesHeaders.push("Note");
  285. output.writeStartElement("table");
  286. output.writeStartElement("thead");
  287. output.writeStartElement("tr");
  288. for(var i = 0; i < seriesHeaders.length; i++) {
  289. output.writeTextElement("th", seriesHeaders[i]);
  290. }
  291. output.writeEndElement();
  292. output.writeEndElement();
  293. buffer2.open(1);
  294. var rq = 'for $t in doc($profile) //tuple return (string($t/time), ";", ';
  295. for(var i = 0; i < seriesHeaders.length - 2; i++) {
  296. rq = rq + 'string($t/temperature[' + Number(i+1) + ']), ";", ';
  297. }
  298. rq = rq + 'string($t/annotation), "~")';
  299. colQuery.setQuery(rq);
  300. var annotationData = colQuery.exec();
  301. colQuery = colQuery.invalidate();
  302. buffer2.close();
  303. output.writeStartElement("tbody");
  304. var annotationRecords = annotationData.split("~");
  305. for(var i = 0; i < annotationRecords.length - 1; i++) {
  306. output.writeStartElement("tr");
  307. var annotationRow = annotationRecords[i].split(";");
  308. for(var j = 0; j < annotationRow.length; j++) {
  309. output.writeStartElement("td");
  310. output.writeAttribute("style", "border-left: 1px solid #000000");
  311. if(j > 0) {
  312. output.writeAttribute("align", "center");
  313. }
  314. if(j > 0 && j < annotationRow.length - 1) {
  315. output.writeCharacters(Number(annotationRow[j].replace(/^\s+|\s+$/g,"")).toFixed(2));
  316. }
  317. else {
  318. output.writeCharacters(annotationRow[j].replace(/^\s+|\s+$/g,""));
  319. }
  320. output.writeEndElement();
  321. }
  322. output.writeEndElement();
  323. }
  324. output.writeEndElement();
  325. output.writeEndElement();
  326. output.writeCharacters(annotation);
  327. output.writeEndElement();
  328. output.writeEndElement();
  329. output.writeEndElement();
  330. output.writeEndDocument();
  331. dataView.setContent(buffer);
  332. buffer.close();
  333. query = query.invalidate();
  334. edit.enabled = true;
  335. };
  336. ]]>
  337. </program>
  338. </window>