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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <window id="lossplots">
  2. <reporttitle>Production:->Weight Loss By Item and Operator</reporttitle>
  3. <layout type="vertical">
  4. <webview id="report" />
  5. </layout>
  6. <menu name="File">
  7. <item id="print" shortcut="Ctrl+P">Print...</item>
  8. </menu>
  9. <menu name="Reports" type="reports" src="Reports" />
  10. <program>
  11. <![CDATA[
  12. this.windowTitle = TTR("lossplots", "Typica - Weight Loss By Item and Operator");
  13. var report = findChildObject(this, 'report');
  14. var printMenu = findChildObject(this, 'print');
  15. printMenu.triggered.connect(function() {
  16. report.print();
  17. });
  18. var refresh = function() {
  19. var query = new QSqlQuery;
  20. query.exec("WITH a AS (SELECT roasted_id, max(time) AS last_batch FROM roasting_log WHERE roasted_id IN (SELECT item FROM current_items) GROUP BY roasted_id), b AS (SELECT roasted_id, last_batch, (SELECT unroasted_id FROM roasting_log WHERE roasted_id = a.roasted_id AND time = last_batch) FROM a), c AS (SELECT roasting_log.roasted_id, ((unroasted_total_quantity - roasted_quantity)/unroasted_total_quantity) AS loss FROM roasting_log, b WHERE roasting_log.roasted_id = b.roasted_id AND roasting_log.unroasted_id = b.unroasted_id AND unroasted_total_quantity > 0 AND approval = true) SELECT roasted_id, (SELECT name FROM items WHERE id = roasted_id) AS name, count(1), min(loss), percentile_cont(0.25) WITHIN GROUP (ORDER BY loss) AS lower_quart, percentile_cont(0.5) WITHIN GROUP (ORDER BY loss) AS median, percentile_cont(0.75) WITHIN GROUP (ORDER BY loss) AS upper_quart, max(loss), avg(loss) FROM c GROUP BY roasted_id ORDER BY name ASC");
  21. var items = new Array;
  22. while(query.next()) {
  23. var item = new Object;
  24. item.roasted_id = query.value(0);
  25. item.name = query.value(1);
  26. item.mean = query.value(8);
  27. item.min = query.value(3);
  28. item.max = query.value(7);
  29. item.plots = new Array;
  30. var plot = new Object;
  31. plot.count = query.value(2);
  32. plot.min = item.min;
  33. plot.max = item.max;
  34. plot.lower_quart = query.value(4);
  35. plot.median = query.value(5);
  36. plot.upper_quart = query.value(6);
  37. plot.name = "All";
  38. item.plots.push(plot);
  39. items.push(item);
  40. }
  41. query.exec("WITH a AS (SELECT roasted_id, max(time) AS last_batch FROM roasting_log WHERE roasted_id IN (SELECT item FROM current_items) GROUP BY roasted_id), b AS (SELECT roasted_id, last_batch, (SELECT unroasted_id FROM roasting_log WHERE roasted_id = a.roasted_id AND time = last_batch) FROM a), c AS (SELECT roasting_log.roasted_id, ((unroasted_total_quantity - roasted_quantity)/unroasted_total_quantity) AS loss, person FROM roasting_log, b WHERE roasting_log.roasted_id = b.roasted_id AND roasting_log.unroasted_id = b.unroasted_id AND unroasted_total_quantity > 0 AND approval = true) SELECT roasted_id, person, count(1), min(loss), percentile_cont(0.25) WITHIN GROUP (ORDER BY loss) AS lower_quart, percentile_cont(0.5) WITHIN GROUP (ORDER BY loss) AS median, percentile_cont(0.75) WITHIN GROUP (ORDER BY loss) AS upper_quart, max(loss) FROM c GROUP BY roasted_id, person");
  42. while(query.next()) {
  43. var plot = new Object;
  44. plot.count = query.value(2);
  45. plot.min = query.value(3);
  46. plot.max = query.value(7);
  47. plot.lower_quart = query.value(4);
  48. plot.median = query.value(5);
  49. plot.upper_quart = query.value(6);
  50. plot.name = query.value(1);
  51. for(var i = 0; i < items.length; i++) {
  52. if(items[i].roasted_id == query.value(0)) {
  53. items[i].plots.push(plot);
  54. break;
  55. }
  56. }
  57. }
  58. query = query.invalidate();
  59. var buffer = new QBuffer;
  60. buffer.open(3);
  61. var output = new XmlWriter(buffer);
  62. output.writeStartDocument("1.0");
  63. 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">');
  64. output.writeStartElement("html");
  65. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  66. output.writeStartElement("head");
  67. output.writeTextElement("style", ".box {font: 10px sans-serif;} .whisker {font: 10px sans-serif;} .axis {font: 12px sans-serif;} .axis path {fill: none; stroke: #000; shape-rendering: crispEdges;} .axis line {fill: none; stroke: #000; shape-rendering: crispEdges;} .x.axis path {fill: none; stroke: #000; shape-rendering: crispEdges;}");
  68. output.writeEndElement(); //head
  69. output.writeStartElement("body");
  70. var cdt = new Date(Date.now());
  71. output.writeTextElement("p", cdt.toLocaleDateString(TTR("reports", "en-US")) + " " + cdt.toLocaleTimeString(TTR("reports", "en-US")));
  72. function position(value, min, max) {
  73. return 300 - (((Number(value)-Number(min))/(Number(max)-Number(min)))*300);
  74. }
  75. for(var i = 0; i < items.length; i++) {
  76. output.writeStartElement("svg");
  77. output.writeAttribute("xmlns", "http://www.w3.org/2000/svg");
  78. output.writeAttribute("height", "420");
  79. output.writeAttribute("width", 84 + (items[i].plots.length * 179));
  80. output.writeStartElement("g"); //plots
  81. output.writeAttribute("transform", "translate(50,30)");
  82. var plotMin = items[i].min;
  83. var plotMax = items[i].max;
  84. for(var j = 0; j < items[i].plots.length; j++) {
  85. output.writeStartElement("g"); //plot
  86. output.writeAttribute("transform", "translate(" + (55 + (179 * j)).toString() + ",30)");
  87. output.writeStartElement("line"); //center line
  88. output.writeAttribute("class", "center");
  89. output.writeAttribute("style", "fill: #000; stroke: #000; stroke-width: 1px;");
  90. output.writeAttribute("x1", "27");
  91. output.writeAttribute("x2", "27");
  92. output.writeAttribute("y1", position(items[i].plots[j].min, plotMin, plotMax));
  93. output.writeAttribute("y2", position(items[i].plots[j].max, plotMin, plotMax));
  94. output.writeEndElement(); //line
  95. output.writeStartElement("rect"); //upper and lower quartiles box
  96. output.writeAttribute("class", "box");
  97. output.writeAttribute("style", "fill: #12DD11; stroke: #000; stroke-width: 1px;");
  98. output.writeAttribute("x", "0");
  99. output.writeAttribute("width", "54");
  100. output.writeAttribute("y", position(items[i].plots[j].upper_quart, plotMin, plotMax));
  101. output.writeAttribute("height", position(items[i].plots[j].lower_quart, plotMin, plotMax) - position(items[i].plots[j].upper_quart, plotMin, plotMax));
  102. output.writeEndElement(); //rect
  103. output.writeStartElement("line"); //median line
  104. output.writeAttribute("class", "median");
  105. output.writeAttribute("style", "fill: #12DD11; stroke: #000; stroke-width: 1px;");
  106. output.writeAttribute("x1", "0");
  107. output.writeAttribute("x2", "54");
  108. output.writeAttribute("y1", position(items[i].plots[j].median, plotMin, plotMax));
  109. output.writeAttribute("y2", position(items[i].plots[j].median, plotMin, plotMax));
  110. output.writeEndElement(); //line
  111. output.writeStartElement("line"); //minimum whisker
  112. output.writeAttribute("class", "whisker");
  113. output.writeAttribute("style", "fill: #12DD11; stroke: #000; stroke-width: 1px;");
  114. output.writeAttribute("x1", "0");
  115. output.writeAttribute("x2", "54");
  116. output.writeAttribute("y1", position(items[i].plots[j].min, plotMin, plotMax));
  117. output.writeAttribute("y2", position(items[i].plots[j].min, plotMin, plotMax));
  118. output.writeEndElement(); //line
  119. output.writeStartElement("line"); //maximum whisker
  120. output.writeAttribute("class", "whisker");
  121. output.writeAttribute("style", "fill: #12DD11; stroke: #000; stroke-width: 1px;");
  122. output.writeAttribute("x1", "0");
  123. output.writeAttribute("x2", "54");
  124. output.writeAttribute("y1", position(items[i].plots[j].max, plotMin, plotMax));
  125. output.writeAttribute("y2", position(items[i].plots[j].max, plotMin, plotMax));
  126. output.writeEndElement(); //line
  127. output.writeStartElement("text"); //upper quartile label
  128. output.writeAttribute("class", "box");
  129. output.writeAttribute("dy", ".3em");
  130. output.writeAttribute("dx", "-6");
  131. output.writeAttribute("x", "0");
  132. output.writeAttribute("y", position(items[i].plots[j].upper_quart, plotMin, plotMax));
  133. output.writeAttribute("text-anchor", "end");
  134. output.writeCharacters(Number(items[i].plots[j].upper_quart * 100).toFixed(2) + "%");
  135. output.writeEndElement(); //text
  136. output.writeStartElement("text"); //lower quartile label
  137. output.writeAttribute("class", "box");
  138. output.writeAttribute("dy", ".3em");
  139. output.writeAttribute("dx", "-6");
  140. output.writeAttribute("x", "0");
  141. output.writeAttribute("y", position(items[i].plots[j].lower_quart, plotMin, plotMax));
  142. output.writeAttribute("text-anchor", "end");
  143. output.writeCharacters(Number(items[i].plots[j].lower_quart * 100).toFixed(2) + "%");
  144. output.writeEndElement(); //text
  145. output.writeStartElement("text"); //median label
  146. output.writeAttribute("class", "box");
  147. output.writeAttribute("dy", ".3em");
  148. output.writeAttribute("dx", "6");
  149. output.writeAttribute("x", "54");
  150. output.writeAttribute("y", position(items[i].plots[j].median, plotMin, plotMax));
  151. output.writeAttribute("text-anchor", "start");
  152. output.writeCharacters(Number(items[i].plots[j].median * 100).toFixed(2) + "%");
  153. output.writeEndElement(); //text
  154. output.writeStartElement("text"); //minimum label
  155. output.writeAttribute("class", "whisker");
  156. output.writeAttribute("dy", ".3em");
  157. output.writeAttribute("dx", "6");
  158. output.writeAttribute("x", "54");
  159. output.writeAttribute("y", position(items[i].plots[j].min, plotMin, plotMax));
  160. output.writeAttribute("text-anchor", "start");
  161. output.writeCharacters(Number(items[i].plots[j].min * 100).toFixed(2) + "%");
  162. output.writeEndElement(); //text
  163. output.writeStartElement("text"); //maximum label
  164. output.writeAttribute("class", "whisker");
  165. output.writeAttribute("dy", ".3em");
  166. output.writeAttribute("dx", "6");
  167. output.writeAttribute("x", "54");
  168. output.writeAttribute("y", position(items[i].plots[j].max, plotMin, plotMax));
  169. output.writeAttribute("text-anchor", "start");
  170. output.writeCharacters(Number(items[i].plots[j].max * 100).toFixed(2) + "%");
  171. output.writeEndElement(); //text
  172. output.writeEndElement(); //g
  173. }
  174. output.writeStartElement("g"); //mean line and label
  175. output.writeAttribute("transform", "translate(0, 30)");
  176. output.writeStartElement("line");
  177. output.writeAttribute("class", "center");
  178. output.writeAttribute("style", "stroke: #000; stroke-width: 1px;");
  179. output.writeAttribute("x1", "0");
  180. output.writeAttribute("x2", (items[i].plots.length * 179) - 16);
  181. output.writeAttribute("y1", position(items[i].mean, plotMin, plotMax));
  182. output.writeAttribute("y2", position(items[i].mean, plotMin, plotMax));
  183. output.writeEndElement(); //line
  184. output.writeStartElement("text");
  185. output.writeAttribute("class", "box");
  186. output.writeAttribute("dy", ".3em");
  187. output.writeAttribute("dx", "-6");
  188. output.writeAttribute("x", "0");
  189. output.writeAttribute("y", position(items[i].mean, plotMin, plotMax));
  190. output.writeAttribute("text-anchor", "end");
  191. output.writeCharacters(Number(items[i].mean * 100).toFixed(2) + "%");
  192. output.writeEndElement(); //text
  193. output.writeEndElement(); //g
  194. output.writeStartElement("g") //x axis
  195. output.writeAttribute("class", "x axis");
  196. output.writeAttribute("transform", "translate(0,340)");
  197. for(var j = 0; j < items[i].plots.length; j++) {
  198. output.writeStartElement("g"); //name and population size
  199. output.writeAttribute("class", "tick");
  200. output.writeAttribute("transform", "translate(" + (82 + (j * 179)) + ",0)");
  201. output.writeStartElement("line"); //tick
  202. output.writeAttribute("y2", "6");
  203. output.writeAttribute("x2", "0");
  204. output.writeEndElement(); //line
  205. output.writeStartElement("text"); //label
  206. output.writeAttribute("style", "text-anchor: middle");
  207. output.writeAttribute("y", "9");
  208. output.writeAttribute("x", "0");
  209. output.writeStartElement("tspan");
  210. output.writeAttribute("x", "0");
  211. output.writeAttribute("dy", ".71em");
  212. output.writeCharacters(items[i].plots[j].name);
  213. output.writeEndElement(); //tspan
  214. output.writeStartElement("tspan");
  215. output.writeAttribute("x", "0");
  216. output.writeAttribute("dy", "1.42em");
  217. output.writeCharacters("(n=" + items[i].plots[j].count + ")");
  218. output.writeEndElement(); //tspan
  219. output.writeEndElement(); //text
  220. output.writeEndElement(); //g
  221. }
  222. output.writeStartElement("path");
  223. output.writeAttribute("class", "domain");
  224. output.writeAttribute("d", "M0,6V0H" + ((items[i].plots.length * 179) - 16) + "V6");
  225. output.writeEndElement(); //path
  226. output.writeEndElement(); //g
  227. output.writeStartElement("text") //chart title
  228. output.writeAttribute("x", (84 + (items[i].plots.length * 179))/2);
  229. output.writeAttribute("y", "15");
  230. output.writeAttribute("text-anchor", "middle");
  231. output.writeAttribute("style", "font-size: 18px;");
  232. output.writeCharacters(items[i].name);
  233. output.writeEndElement(); //text
  234. output.writeEndElement(); //g
  235. output.writeEndElement(); //svg
  236. }
  237. output.writeEndElement(); //body
  238. output.writeEndElement(); //html
  239. output.writeEndDocument();
  240. report.setContent(buffer);
  241. buffer.close();
  242. };
  243. refresh();
  244. var notifier = Application.subscribe("roastinglogchange");
  245. notifier.notify.connect(function() {
  246. refresh();
  247. });
  248. ]]>
  249. </program>
  250. </window>