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 18KB

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