Browse Source

New report: Degree of Roast by Item

Neal Wilson 6 years ago
parent
commit
4eb425443a
1 changed files with 304 additions and 0 deletions
  1. 304
    0
      config/Reports/colorplots.xml

+ 304
- 0
config/Reports/colorplots.xml View File

@@ -0,0 +1,304 @@
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
+
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
+        
135
+        output.writeStartElement("g"); //plot (ground)
136
+        output.writeAttribute("transform", "translate(234,30)");
137
+        output.writeStartElement("line"); //center line
138
+        output.writeAttribute("class", "center");
139
+        output.writeAttribute("style", "fill: #000; stroke: #000; stroke-width: 1px;");
140
+        output.writeAttribute("x1", "27");
141
+        output.writeAttribute("x2", "27");
142
+        output.writeAttribute("y1", position(Number(query.value(5)), plotMin, plotMax));
143
+        output.writeAttribute("y2", position(Number(query.value(13)), plotMin, plotMax));
144
+        output.writeEndElement(); //line
145
+        output.writeStartElement("rect"); //upper and lower quartiles box
146
+        output.writeAttribute("class", "box");
147
+        output.writeAttribute("style", "fill: #12DD11; stroke: #000; stroke-width: 1px;");
148
+        output.writeAttribute("x", "0");
149
+        output.writeAttribute("width", "54");
150
+        output.writeAttribute("y", position(Number(query.value(11)), plotMin, plotMax));
151
+        output.writeAttribute("height", position(Number(query.value(7)), plotMin, plotMax) - position(Number(query.value(11)), plotMin, plotMax));
152
+        output.writeEndElement(); //rect
153
+        output.writeStartElement("line"); //median line
154
+        output.writeAttribute("class", "median");
155
+        output.writeAttribute("style", "fill: #12DD11; stroke: #000; stroke-width: 1px;");
156
+        output.writeAttribute("x1", "0");
157
+        output.writeAttribute("x2", "54");
158
+        output.writeAttribute("y1", position(Number(query.value(9)), plotMin, plotMax));
159
+        output.writeAttribute("y2", position(Number(query.value(9)), plotMin, plotMax));
160
+        output.writeEndElement(); //line
161
+        output.writeStartElement("line"); //minimum whisker
162
+        output.writeAttribute("class", "whisker");
163
+        output.writeAttribute("style", "fill: #12DD11; stroke: #000; stroke-width: 1px;");
164
+        output.writeAttribute("x1", "0");
165
+        output.writeAttribute("x2", "54");
166
+        output.writeAttribute("y1", position(Number(query.value(5)), plotMin, plotMax));
167
+        output.writeAttribute("y2", position(Number(query.value(5)), plotMin, plotMax));
168
+        output.writeEndElement(); //line
169
+        output.writeStartElement("line"); //maximum whisker
170
+        output.writeAttribute("class", "whisker");
171
+        output.writeAttribute("style", "fill: #12DD11; stroke: #000; stroke-width: 1px;");
172
+        output.writeAttribute("x1", "0");
173
+        output.writeAttribute("x2", "54");
174
+        output.writeAttribute("y1", position(Number(query.value(13)), plotMin, plotMax));
175
+        output.writeAttribute("y2", position(Number(query.value(13)), plotMin, plotMax));
176
+        output.writeEndElement(); //line
177
+        output.writeStartElement("text"); //upper quartile label
178
+        output.writeAttribute("class", "box");
179
+        output.writeAttribute("dy", ".3em");
180
+        output.writeAttribute("dx", "-6");
181
+        output.writeAttribute("x", "0");
182
+        output.writeAttribute("y", position(Number(query.value(11)), plotMin, plotMax));
183
+        output.writeAttribute("text-anchor", "end");
184
+        output.writeCharacters(query.value(11));
185
+        output.writeEndElement(); //text
186
+        output.writeStartElement("text"); //lower quartile label
187
+        output.writeAttribute("class", "box");
188
+        output.writeAttribute("dy", ".3em");
189
+        output.writeAttribute("dx", "-6");
190
+        output.writeAttribute("x", "0");
191
+        output.writeAttribute("y", position(Number(query.value(7)), plotMin, plotMax));
192
+        output.writeAttribute("text-anchor", "end");
193
+        output.writeCharacters(query.value(7));
194
+        output.writeEndElement(); //text
195
+        output.writeStartElement("text"); //median label
196
+        output.writeAttribute("class", "box");
197
+        output.writeAttribute("dy", ".3em");
198
+        output.writeAttribute("dx", "6");
199
+        output.writeAttribute("x", "54");
200
+        output.writeAttribute("y", position(Number(query.value(9)), plotMin, plotMax));
201
+        output.writeAttribute("text-anchor", "start");
202
+        output.writeCharacters(query.value(9));
203
+        output.writeEndElement(); //text
204
+        output.writeStartElement("text"); //minimum label
205
+        output.writeAttribute("class", "whisker");
206
+        output.writeAttribute("dy", ".3em");
207
+        output.writeAttribute("dx", "6");
208
+        output.writeAttribute("x", "54");
209
+        output.writeAttribute("y", position(Number(query.value(5)), plotMin, plotMax));
210
+        output.writeAttribute("text-anchor", "start");
211
+        output.writeCharacters(query.value(5));
212
+        output.writeEndElement(); //text
213
+        output.writeStartElement("text"); //maximum label
214
+        output.writeAttribute("class", "whisker");
215
+        output.writeAttribute("dy", ".3em");
216
+        output.writeAttribute("dx", "6");
217
+        output.writeAttribute("x", "54");
218
+        output.writeAttribute("y", position(Number(query.value(13)), plotMin, plotMax));
219
+        output.writeAttribute("text-anchor", "start");
220
+        output.writeCharacters(query.value(13));
221
+        output.writeEndElement(); //text
222
+        output.writeEndElement(); //g
223
+        
224
+        output.writeStartElement("g") //x axis
225
+        output.writeAttribute("class", "x axis");
226
+        output.writeAttribute("transform", "translate(0,340)");
227
+
228
+        output.writeStartElement("g"); //name and population size
229
+        output.writeAttribute("class", "tick");
230
+        output.writeAttribute("transform", "translate(82,0)");
231
+        output.writeStartElement("line"); //tick
232
+        output.writeAttribute("y2", "6");
233
+        output.writeAttribute("x2", "0");
234
+        output.writeEndElement(); //line
235
+        output.writeStartElement("text"); //label
236
+        output.writeAttribute("style", "text-anchor: middle");
237
+        output.writeAttribute("y", "9");
238
+        output.writeAttribute("x", "0");
239
+        output.writeStartElement("tspan");
240
+        output.writeAttribute("x", "0");
241
+        output.writeAttribute("dy", ".71em");
242
+        output.writeCharacters(TTR("colorplots", "whole"));
243
+        output.writeEndElement(); //tspan
244
+        output.writeStartElement("tspan");
245
+        output.writeAttribute("x", "0");
246
+        output.writeAttribute("dy", "1.42em");
247
+        output.writeCharacters("(n=" + query.value(2) + ")");
248
+        output.writeEndElement(); //tspan
249
+        output.writeEndElement(); //text
250
+        output.writeEndElement(); //g
251
+        
252
+        output.writeStartElement("g"); //name and population size
253
+        output.writeAttribute("class", "tick");
254
+        output.writeAttribute("transform", "translate(261,0)");
255
+        output.writeStartElement("line"); //tick
256
+        output.writeAttribute("y2", "6");
257
+        output.writeAttribute("x2", "0");
258
+        output.writeEndElement(); //line
259
+        output.writeStartElement("text"); //label
260
+        output.writeAttribute("style", "text-anchor: middle");
261
+        output.writeAttribute("y", "9");
262
+        output.writeAttribute("x", "0");
263
+        output.writeStartElement("tspan");
264
+        output.writeAttribute("x", "0");
265
+        output.writeAttribute("dy", ".71em");
266
+        output.writeCharacters(TTR("colorplots", "ground"));
267
+        output.writeEndElement(); //tspan
268
+        output.writeStartElement("tspan");
269
+        output.writeAttribute("x", "0");
270
+        output.writeAttribute("dy", "1.42em");
271
+        output.writeCharacters("(n=" + query.value(3) + ")");
272
+        output.writeEndElement(); //tspan
273
+        output.writeEndElement(); //text
274
+        output.writeEndElement(); //g
275
+
276
+        output.writeStartElement("path");
277
+        output.writeAttribute("class", "domain");
278
+        output.writeAttribute("d", "M0,6V0H" + 342 + "V6");
279
+        output.writeEndElement(); //path
280
+        output.writeEndElement(); //g
281
+        output.writeStartElement("text") //chart title
282
+        output.writeAttribute("x", "174");
283
+        output.writeAttribute("y", "15");
284
+        output.writeAttribute("text-anchor", "middle");
285
+        output.writeAttribute("style", "font-size: 18px;");
286
+        output.writeCharacters(query.value(1));
287
+        output.writeEndElement(); //text
288
+        output.writeEndElement(); //g
289
+        output.writeEndElement(); //svg
290
+    }
291
+    output.writeEndElement(); //body
292
+    output.writeEndElement(); //html
293
+    output.writeEndDocument();
294
+    report.setContent(buffer);
295
+    buffer.close();
296
+};
297
+refresh();
298
+var notifier = Application.subscribe("roastinglogchange");
299
+notifier.notify.connect(function() {
300
+    refresh();
301
+});
302
+        ]]>
303
+    </program>
304
+</window>

Loading…
Cancel
Save