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.

colorplots.xml 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <window id="colorplots">
  2. <reporttitle>Production:->Degree of Roast By Item</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. <program>
  10. <![CDATA[
  11. this.windowTitle = TTR("colorplots", "Typica - Degree of Roast By Item");
  12. var report = findChildObject(this, 'report');
  13. var printMenu = findChildObject(this, 'print');
  14. printMenu.triggered.connect(function() {
  15. report.print();
  16. });
  17. var refresh = function() {
  18. var query = new QSqlQuery;
  19. 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, (additional_data#>>'{color,whole}')::numeric AS whole, (additional_data#>>'{color,ground}')::numeric AS ground FROM roasting_log, b WHERE roasting_log.roasted_id = b.roasted_id AND roasting_log.unroasted_id = b.unroasted_id AND additional_data?'color' AND approval=true) SELECT roasted_id, (SELECT name FROM items WHERE id = roasted_id) AS name, count(whole), count(ground), min(whole), min(ground), percentile_cont(0.25) WITHIN GROUP (ORDER BY whole), percentile_cont(0.25) WITHIN GROUP (ORDER BY ground), percentile_cont(0.5) WITHIN GROUP (ORDER BY whole), percentile_cont(0.5) WITHIN GROUP (ORDER BY ground), percentile_cont(0.75) WITHIN GROUP (ORDER BY whole), percentile_cont(0.75) WITHIN GROUP (ORDER BY ground), max(whole), max(ground) FROM c GROUP BY roasted_id ORDER BY name ASC");
  20. var buffer = new QBuffer;
  21. buffer.open(3);
  22. var output = new XmlWriter(buffer);
  23. output.writeStartDocument("1.0");
  24. 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">');
  25. output.writeStartElement("html");
  26. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  27. output.writeStartElement("head");
  28. 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;}");
  29. output.writeEndElement(); //head
  30. output.writeStartElement("body");
  31. var cdt = new Date(Date.now());
  32. output.writeTextElement("p", cdt.toLocaleDateString(TTR("reports", "en-US")) + " " + cdt.toLocaleTimeString(TTR("reports", "en-US")));
  33. function position(value, min, max) {
  34. return 300 - (((Number(value)-Number(min))/(Number(max)-Number(min)))*300);
  35. }
  36. while(query.next()) {
  37. output.writeStartElement("svg");
  38. output.writeAttribute("xmlns", "http://www.w3.org/2000/svg");
  39. output.writeAttribute("height", "420");
  40. output.writeAttribute("width", 84 + (2 * 179));
  41. output.writeStartElement("g"); //plots
  42. output.writeAttribute("transform", "translate(50,30)");
  43. var plotMin = Math.min(Number(query.value(4)), Number(query.value(5)));
  44. var plotMax = Math.max(Number(query.value(12)), Number(query.value(13)));
  45. output.writeStartElement("g"); //plot (whole)
  46. output.writeAttribute("transform", "translate(55,30)");
  47. output.writeStartElement("line"); //center line
  48. output.writeAttribute("class", "center");
  49. output.writeAttribute("style", "fill: #000; stroke: #000; stroke-width: 1px;");
  50. output.writeAttribute("x1", "27");
  51. output.writeAttribute("x2", "27");
  52. output.writeAttribute("y1", position(Number(query.value(4)), plotMin, plotMax));
  53. output.writeAttribute("y2", position(Number(query.value(12)), plotMin, plotMax));
  54. output.writeEndElement(); //line
  55. output.writeStartElement("rect"); //upper and lower quartiles box
  56. output.writeAttribute("class", "box");
  57. output.writeAttribute("style", "fill: #12DD11; stroke: #000; stroke-width: 1px;");
  58. output.writeAttribute("x", "0");
  59. output.writeAttribute("width", "54");
  60. output.writeAttribute("y", position(Number(query.value(10)), plotMin, plotMax));
  61. output.writeAttribute("height", position(Number(query.value(6)), plotMin, plotMax) - position(Number(query.value(10)), plotMin, plotMax));
  62. output.writeEndElement(); //rect
  63. output.writeStartElement("line"); //median line
  64. output.writeAttribute("class", "median");
  65. output.writeAttribute("style", "fill: #12DD11; stroke: #000; stroke-width: 1px;");
  66. output.writeAttribute("x1", "0");
  67. output.writeAttribute("x2", "54");
  68. output.writeAttribute("y1", position(Number(query.value(8)), plotMin, plotMax));
  69. output.writeAttribute("y2", position(Number(query.value(8)), plotMin, plotMax));
  70. output.writeEndElement(); //line
  71. output.writeStartElement("line"); //minimum whisker
  72. output.writeAttribute("class", "whisker");
  73. output.writeAttribute("style", "fill: #12DD11; stroke: #000; stroke-width: 1px;");
  74. output.writeAttribute("x1", "0");
  75. output.writeAttribute("x2", "54");
  76. output.writeAttribute("y1", position(Number(query.value(4)), plotMin, plotMax));
  77. output.writeAttribute("y2", position(Number(query.value(4)), plotMin, plotMax));
  78. output.writeEndElement(); //line
  79. output.writeStartElement("line"); //maximum whisker
  80. output.writeAttribute("class", "whisker");
  81. output.writeAttribute("style", "fill: #12DD11; stroke: #000; stroke-width: 1px;");
  82. output.writeAttribute("x1", "0");
  83. output.writeAttribute("x2", "54");
  84. output.writeAttribute("y1", position(Number(query.value(12)), plotMin, plotMax));
  85. output.writeAttribute("y2", position(Number(query.value(12)), plotMin, plotMax));
  86. output.writeEndElement(); //line
  87. output.writeStartElement("text"); //upper quartile label
  88. output.writeAttribute("class", "box");
  89. output.writeAttribute("dy", ".3em");
  90. output.writeAttribute("dx", "-6");
  91. output.writeAttribute("x", "0");
  92. output.writeAttribute("y", position(Number(query.value(10)), plotMin, plotMax));
  93. output.writeAttribute("text-anchor", "end");
  94. output.writeCharacters(query.value(10));
  95. output.writeEndElement(); //text
  96. output.writeStartElement("text"); //lower quartile label
  97. output.writeAttribute("class", "box");
  98. output.writeAttribute("dy", ".3em");
  99. output.writeAttribute("dx", "-6");
  100. output.writeAttribute("x", "0");
  101. output.writeAttribute("y", position(Number(query.value(6)), plotMin, plotMax));
  102. output.writeAttribute("text-anchor", "end");
  103. output.writeCharacters(query.value(6));
  104. output.writeEndElement(); //text
  105. output.writeStartElement("text"); //median label
  106. output.writeAttribute("class", "box");
  107. output.writeAttribute("dy", ".3em");
  108. output.writeAttribute("dx", "6");
  109. output.writeAttribute("x", "54");
  110. output.writeAttribute("y", position(Number(query.value(8)), plotMin, plotMax));
  111. output.writeAttribute("text-anchor", "start");
  112. output.writeCharacters(query.value(8));
  113. output.writeEndElement(); //text
  114. output.writeStartElement("text"); //minimum label
  115. output.writeAttribute("class", "whisker");
  116. output.writeAttribute("dy", ".3em");
  117. output.writeAttribute("dx", "6");
  118. output.writeAttribute("x", "54");
  119. output.writeAttribute("y", position(Number(query.value(4)), plotMin, plotMax));
  120. output.writeAttribute("text-anchor", "start");
  121. output.writeCharacters(query.value(4));
  122. output.writeEndElement(); //text
  123. output.writeStartElement("text"); //maximum label
  124. output.writeAttribute("class", "whisker");
  125. output.writeAttribute("dy", ".3em");
  126. output.writeAttribute("dx", "6");
  127. output.writeAttribute("x", "54");
  128. output.writeAttribute("y", position(Number(query.value(12)), plotMin, plotMax));
  129. output.writeAttribute("text-anchor", "start");
  130. output.writeCharacters(query.value(12));
  131. output.writeEndElement(); //text
  132. output.writeEndElement(); //g
  133. output.writeStartElement("g"); //plot (ground)
  134. output.writeAttribute("transform", "translate(234,30)");
  135. output.writeStartElement("line"); //center line
  136. output.writeAttribute("class", "center");
  137. output.writeAttribute("style", "fill: #000; stroke: #000; stroke-width: 1px;");
  138. output.writeAttribute("x1", "27");
  139. output.writeAttribute("x2", "27");
  140. output.writeAttribute("y1", position(Number(query.value(5)), plotMin, plotMax));
  141. output.writeAttribute("y2", position(Number(query.value(13)), plotMin, plotMax));
  142. output.writeEndElement(); //line
  143. output.writeStartElement("rect"); //upper and lower quartiles box
  144. output.writeAttribute("class", "box");
  145. output.writeAttribute("style", "fill: #12DD11; stroke: #000; stroke-width: 1px;");
  146. output.writeAttribute("x", "0");
  147. output.writeAttribute("width", "54");
  148. output.writeAttribute("y", position(Number(query.value(11)), plotMin, plotMax));
  149. output.writeAttribute("height", position(Number(query.value(7)), plotMin, plotMax) - position(Number(query.value(11)), plotMin, plotMax));
  150. output.writeEndElement(); //rect
  151. output.writeStartElement("line"); //median line
  152. output.writeAttribute("class", "median");
  153. output.writeAttribute("style", "fill: #12DD11; stroke: #000; stroke-width: 1px;");
  154. output.writeAttribute("x1", "0");
  155. output.writeAttribute("x2", "54");
  156. output.writeAttribute("y1", position(Number(query.value(9)), plotMin, plotMax));
  157. output.writeAttribute("y2", position(Number(query.value(9)), plotMin, plotMax));
  158. output.writeEndElement(); //line
  159. output.writeStartElement("line"); //minimum whisker
  160. output.writeAttribute("class", "whisker");
  161. output.writeAttribute("style", "fill: #12DD11; stroke: #000; stroke-width: 1px;");
  162. output.writeAttribute("x1", "0");
  163. output.writeAttribute("x2", "54");
  164. output.writeAttribute("y1", position(Number(query.value(5)), plotMin, plotMax));
  165. output.writeAttribute("y2", position(Number(query.value(5)), plotMin, plotMax));
  166. output.writeEndElement(); //line
  167. output.writeStartElement("line"); //maximum whisker
  168. output.writeAttribute("class", "whisker");
  169. output.writeAttribute("style", "fill: #12DD11; stroke: #000; stroke-width: 1px;");
  170. output.writeAttribute("x1", "0");
  171. output.writeAttribute("x2", "54");
  172. output.writeAttribute("y1", position(Number(query.value(13)), plotMin, plotMax));
  173. output.writeAttribute("y2", position(Number(query.value(13)), plotMin, plotMax));
  174. output.writeEndElement(); //line
  175. output.writeStartElement("text"); //upper quartile label
  176. output.writeAttribute("class", "box");
  177. output.writeAttribute("dy", ".3em");
  178. output.writeAttribute("dx", "-6");
  179. output.writeAttribute("x", "0");
  180. output.writeAttribute("y", position(Number(query.value(11)), plotMin, plotMax));
  181. output.writeAttribute("text-anchor", "end");
  182. output.writeCharacters(query.value(11));
  183. output.writeEndElement(); //text
  184. output.writeStartElement("text"); //lower quartile label
  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(Number(query.value(7)), plotMin, plotMax));
  190. output.writeAttribute("text-anchor", "end");
  191. output.writeCharacters(query.value(7));
  192. output.writeEndElement(); //text
  193. output.writeStartElement("text"); //median label
  194. output.writeAttribute("class", "box");
  195. output.writeAttribute("dy", ".3em");
  196. output.writeAttribute("dx", "6");
  197. output.writeAttribute("x", "54");
  198. output.writeAttribute("y", position(Number(query.value(9)), plotMin, plotMax));
  199. output.writeAttribute("text-anchor", "start");
  200. output.writeCharacters(query.value(9));
  201. output.writeEndElement(); //text
  202. output.writeStartElement("text"); //minimum label
  203. output.writeAttribute("class", "whisker");
  204. output.writeAttribute("dy", ".3em");
  205. output.writeAttribute("dx", "6");
  206. output.writeAttribute("x", "54");
  207. output.writeAttribute("y", position(Number(query.value(5)), plotMin, plotMax));
  208. output.writeAttribute("text-anchor", "start");
  209. output.writeCharacters(query.value(5));
  210. output.writeEndElement(); //text
  211. output.writeStartElement("text"); //maximum label
  212. output.writeAttribute("class", "whisker");
  213. output.writeAttribute("dy", ".3em");
  214. output.writeAttribute("dx", "6");
  215. output.writeAttribute("x", "54");
  216. output.writeAttribute("y", position(Number(query.value(13)), plotMin, plotMax));
  217. output.writeAttribute("text-anchor", "start");
  218. output.writeCharacters(query.value(13));
  219. output.writeEndElement(); //text
  220. output.writeEndElement(); //g
  221. output.writeStartElement("g") //x axis
  222. output.writeAttribute("class", "x axis");
  223. output.writeAttribute("transform", "translate(0,340)");
  224. output.writeStartElement("g"); //name and population size
  225. output.writeAttribute("class", "tick");
  226. output.writeAttribute("transform", "translate(82,0)");
  227. output.writeStartElement("line"); //tick
  228. output.writeAttribute("y2", "6");
  229. output.writeAttribute("x2", "0");
  230. output.writeEndElement(); //line
  231. output.writeStartElement("text"); //label
  232. output.writeAttribute("style", "text-anchor: middle");
  233. output.writeAttribute("y", "9");
  234. output.writeAttribute("x", "0");
  235. output.writeStartElement("tspan");
  236. output.writeAttribute("x", "0");
  237. output.writeAttribute("dy", ".71em");
  238. output.writeCharacters(TTR("colorplots", "whole"));
  239. output.writeEndElement(); //tspan
  240. output.writeStartElement("tspan");
  241. output.writeAttribute("x", "0");
  242. output.writeAttribute("dy", "1.42em");
  243. output.writeCharacters("(n=" + query.value(2) + ")");
  244. output.writeEndElement(); //tspan
  245. output.writeEndElement(); //text
  246. output.writeEndElement(); //g
  247. output.writeStartElement("g"); //name and population size
  248. output.writeAttribute("class", "tick");
  249. output.writeAttribute("transform", "translate(261,0)");
  250. output.writeStartElement("line"); //tick
  251. output.writeAttribute("y2", "6");
  252. output.writeAttribute("x2", "0");
  253. output.writeEndElement(); //line
  254. output.writeStartElement("text"); //label
  255. output.writeAttribute("style", "text-anchor: middle");
  256. output.writeAttribute("y", "9");
  257. output.writeAttribute("x", "0");
  258. output.writeStartElement("tspan");
  259. output.writeAttribute("x", "0");
  260. output.writeAttribute("dy", ".71em");
  261. output.writeCharacters(TTR("colorplots", "ground"));
  262. output.writeEndElement(); //tspan
  263. output.writeStartElement("tspan");
  264. output.writeAttribute("x", "0");
  265. output.writeAttribute("dy", "1.42em");
  266. output.writeCharacters("(n=" + query.value(3) + ")");
  267. output.writeEndElement(); //tspan
  268. output.writeEndElement(); //text
  269. output.writeEndElement(); //g
  270. output.writeStartElement("path");
  271. output.writeAttribute("class", "domain");
  272. output.writeAttribute("d", "M0,6V0H" + 342 + "V6");
  273. output.writeEndElement(); //path
  274. output.writeEndElement(); //g
  275. output.writeStartElement("text") //chart title
  276. output.writeAttribute("x", "174");
  277. output.writeAttribute("y", "15");
  278. output.writeAttribute("text-anchor", "middle");
  279. output.writeAttribute("style", "font-size: 18px;");
  280. output.writeCharacters(query.value(1));
  281. output.writeEndElement(); //text
  282. output.writeEndElement(); //g
  283. output.writeEndElement(); //svg
  284. }
  285. output.writeEndElement(); //body
  286. output.writeEndElement(); //html
  287. output.writeEndDocument();
  288. report.setContent(buffer);
  289. buffer.close();
  290. };
  291. refresh();
  292. var notifier = Application.subscribe("roastinglogchange");
  293. notifier.notify.connect(function() {
  294. refresh();
  295. });
  296. ]]>
  297. </program>
  298. </window>