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

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