Просмотр исходного кода

Add unit selection to batch log.

Neal Wilson 9 лет назад
Родитель
Сommit
6201787513
2 измененных файлов: 338 добавлений и 326 удалений
  1. 322
    325
      config/Windows/batchdetailsnew.xml
  2. 16
    1
      config/Windows/history.xml

+ 322
- 325
config/Windows/batchdetailsnew.xml Просмотреть файл

@@ -2,45 +2,45 @@
2 2
     <layout type="vertical">
3 3
         <layout type="horizontal">
4 4
             <button type="push" id="target" name="Load profile as target" />
5
-			<button type="push" id="viewprofile" name="View profile" />
6
-			<button type="push" id="compare" name="Compare profile" />
7
-			<button type="push" id="edit" name="Edit" />
5
+            <button type="push" id="viewprofile" name="View profile" />
6
+            <button type="push" id="compare" name="Compare profile" />
7
+            <button type="push" id="edit" name="Edit" />
8 8
         </layout>
9 9
         <webview id="view" />
10 10
     </layout>
11 11
 	<menu name="File">
12
-		<item id="save" shortcut="Ctrl+S">Save…</item>
12
+            <item id="save" shortcut="Ctrl+S">Save…</item>
13 13
 	</menu>
14 14
     <program>
15 15
         <![CDATA[
16
-			var window = this;
17
-			dataView = findChildObject(this, 'view');
18
-			var fileID;
19
-			var target = findChildObject(this, 'target');
20
-			var compare = findChildObject(this, 'compare');
21
-			var edit = findChildObject(this, 'edit');
22
-			edit.enabled = false;
23
-			if(typeof(Windows.loggingWindow) == "undefined") {
24
-				compare.enabled = false;
25
-				target.enabled = false;
26
-			}
27
-			var tableReference;
28
-			var rowReference;
29
-			var batchTime;
30
-			var machine;
31
-			var approval;
32
-			var annotation;
33
-			edit.clicked.connect(function() {
34
-				var editWindow = createWindow("editBatchDetails");
35
-				editWindow.loadData(window, tableReference, rowReference, batchTime, machine, approval, annotation);
36
-			});
37
-			compare.clicked.connect(function() {
38
-				var query = new QSqlQuery;
39
-				query.prepare("SELECT file, name FROM files WHERE id = :id");
40
-				query.bind(":id", Number(fileID));
41
-				query.exec();
42
-				query.next();
43
-				var buffer = new QBuffer(query.value(0));
16
+            var window = this;
17
+            dataView = findChildObject(this, 'view');
18
+            var fileID;
19
+            var target = findChildObject(this, 'target');
20
+            var compare = findChildObject(this, 'compare');
21
+            var edit = findChildObject(this, 'edit');
22
+            edit.enabled = false;
23
+            if(typeof(Windows.loggingWindow) == "undefined") {
24
+                compare.enabled = false;
25
+                target.enabled = false;
26
+            }
27
+            var tableReference;
28
+            var rowReference;
29
+            var batchTime;
30
+            var machine;
31
+            var approval;
32
+            var annotation;
33
+            edit.clicked.connect(function() {
34
+                var editWindow = createWindow("editBatchDetails");
35
+                editWindow.loadData(window, tableReference, rowReference, batchTime, machine, approval, annotation);
36
+            });
37
+            compare.clicked.connect(function() {
38
+                var query = new QSqlQuery;
39
+                query.prepare("SELECT file, name FROM files WHERE id = :id");
40
+                query.bind(":id", Number(fileID));
41
+                query.exec();
42
+                query.next();
43
+                var buffer = new QBuffer(query.value(0));
44 44
                 var pname = query.value(1);
45 45
                 query = query.invalidate();
46 46
                 var startSeries = Number(QSettings.value('cseries', 3));
@@ -50,300 +50,297 @@
50 50
                 var graph = findChildObject(Windows.loggingWindow, 'graph');
51 51
                 input.measure.connect(graph.newMeasurement);
52 52
                 input.input();
53
-				query = query.invalidate();
54
-			});
55
-			target.clicked.connect(function() {
56
-				var query = new QSqlQuery;
57
-				query.prepare("SELECT file, name FROM files WHERE id = :id");
58
-				query.bind(":id", Number(fileID));
59
-				query.exec();
60
-				query.next();
61
-				var buffer = new QBuffer(query.value(0));
62
-				var pname = query.value(1);
63 53
                 query = query.invalidate();
64
-				var input = new XMLInput(buffer, 1);
65
-				var graph = findChildObject(Windows.loggingWindow, 'graph');
66
-				var log = findChildObject(Windows.loggingWindow, 'log');
67
-				log.clear();
68
-				graph.clear();
69
-				input.newTemperatureColumn.connect(log.setHeaderData);
70
-				input.newTemperatureColumn.connect(function(col, text) {
71
-					if(text == Windows.loggingWindow.targetcolumnname)
72
-					{
73
-						targetseries = col;
74
-					}
75
-				});
76
-				input.newAnnotationColumn.connect(log.setHeaderData);
77
-				input.measure.connect(graph.newMeasurement);
78
-				input.measure.connect(log.newMeasurement);
79
-				input.measure.connect(function(data, series) {
80
-					if(series == targetseries)
81
-					{
82
-						targetDetector.newMeasurement(data);
83
-					}
84
-				});
85
-				var lc;
86
-				input.lastColumn.connect(function(c) {
87
-					lc = c;
88
-					QSettings.setValue("liveColumn", c + 1);
89
-					Windows.loggingWindow.postLoadColumnSetup(c);
90
-				});
91
-				input.annotation.connect(log.newAnnotation);
92
-				input.annotation.connect(function(note, tcol, ncol) {
93
-					for(var i = tcol; i < ncol; i++) {
94
-						log.newAnnotation(note, i, ncol);
95
-					}
96
-				});
97
-				Windows.loggingWindow.windowTitle = "Typica - " + pname;
98
-				Windows.loggingWindow.raise();
99
-				Windows.loggingWindow.activateWindow();
100
-				input.input();
101
-				log.newAnnotation("End", 1, lc);
102
-				query = query.invalidate();
103
-			});
104
-			var viewbutton = findChildObject(this, 'viewprofile');
105
-			viewbutton.clicked.connect(function() {
106
-				var query = new QSqlQuery;
107
-				query.prepare("SELECT file, name FROM files WHERE id = :id");
108
-				query.bind(":id", Number(fileID));
109
-				query.exec();
110
-				if(query.next()) {
111
-					var viewer = createWindow('offline');
112
-					var buffer = new QBuffer(query.value(0));
113
-					var pname = query.value(1);
114
-					query = query.invalidate();
115
-					var input = new XMLInput(buffer, 1);
116
-					var graph = findChildObject(viewer, 'graph');
117
-					var log = findChildObject(viewer, 'log');
118
-					input.newTemperatureColumn.connect(log.setHeaderData);
119
-					input.newTemperatureColumn.connect(function(column) {
120
-						viewer.saveTemperatureColumns.push(column);
121
-					});
122
-					input.newAnnotationColumn.connect(log.setHeaderData);
123
-					input.newAnnotationColumn.connect(function(column) {
124
-						viewer.saveAnnotationColumns.push(column);
125
-					});
126
-					input.measure.connect(graph.newMeasurement);
127
-					input.measure.connect(log.newMeasurement);
128
-					input.annotation.connect(log.newAnnotation);
129
-					var lc;
130
-					input.lastColumn.connect(function(c) {
131
-						lc = c;
132
-						if(c < 3)
133
-						{
134
-							log.setHeaderData(3, "");
135
-						}
136
-					});
137
-					input.annotation.connect(function(note, tcol, ncol) {
138
-						for(var i = tcol; i < ncol; i++) {
139
-							log.newAnnotation(note, i, ncol);
140
-						}
141
-					});
142
-					viewer.windowTitle = "Typica - " + pname;
143
-					viewer.raise();
144
-					viewer.activateWindow();
145
-					graph.updatesEnabled = false;
146
-					log.updatesEnabled = false;
147
-					input.input();
148
-					log.updatesEnabled = true;
149
-					graph.updatesEnabled = true;
150
-					log.newAnnotation("End", 1, lc);
151
-				}
152
-				else {
153
-					print("Query returned no results");
154
-				}
155
-				query = query.invalidate();
156
-			});
157
-			window.loadData = function(table, row) {
158
-				tableReference = table;
159
-				rowReference = row;
160
-				var buffer = new QBuffer;
161
-				buffer.open(3);
162
-				var output = new XmlWriter(buffer);
163
-				output.writeStartDocument("1.0");
164
-				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">');
165
-				output.writeStartElement("html");
166
-				output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
167
-				output.writeStartElement("head");
168
-				output.writeTextElement("title", "Batch Details");
169
-				output.writeEndElement();
170
-				output.writeStartElement("body");
171
-				output.writeStartElement("div");
172
-				output.writeAttribute("style", "float: left; padding-right: 10px");
173
-				output.writeStartElement("p");
174
-				output.writeTextElement("strong", "Roasted Coffee: ");
175
-				output.writeTextElement("span", table.data(row, 2));
176
-				output.writeEndElement();
177
-				output.writeEndElement();
178
-				output.writeStartElement("div");
179
-				output.writeAttribute("style", "float: left");
180
-				output.writeStartElement("p");
181
-				output.writeTextElement("strong", "Roasted On: ");
182
-				batchTime = table.data(row, 0);
183
-				output.writeTextElement("span", batchTime);
184
-				output.writeEndElement();
185
-				output.writeStartElement("p");
186
-				output.writeTextElement("strong", "Batch Duration: ");
187
-				output.writeTextElement("span", table.data(row, 6));
188
-				output.writeEndElement();
189
-				output.writeEndElement();
190
-				output.writeStartElement("div");
191
-				output.writeAttribute("style", "clear: both");
192
-				output.writeEndElement();
193
-				output.writeStartElement("table");
194
-				output.writeStartElement("thead");
195
-				output.writeStartElement("tr");
196
-				output.writeTextElement("th", "Green Coffee");
197
-				output.writeTextElement("th", "Weight (lb)");
198
-				output.writeEndElement();
199
-				output.writeEndElement();
200
-				output.writeStartElement("tbody");
201
-				var query = new QSqlQuery();
202
-				query.prepare("SELECT unroasted_id, unroasted_quantity, approval, files, annotation FROM roasting_log WHERE time = :time AND machine = :machine");
203
-				query.bind(":time", batchTime);
204
-				machine = table.data(row, 1);
205
-				query.bind(":machine", machine);
206
-				query.exec();
207
-				query.next();
208
-				approval = query.value(2);
209
-				annotation = query.value(4);
210
-				var items = sqlToArray(query.value(0));
211
-				var quantities = sqlToArray(query.value(1));
212
-				var nameQuery = new QSqlQuery();
213
-				nameQuery.prepare("SELECT name FROM items WHERE id = :id");
214
-				for(var i = 0; i < items.length; i++) {
215
-					output.writeStartElement("tr");
216
-					nameQuery.bind(":id", items[i]);
217
-					nameQuery.exec();
218
-					nameQuery.next();
219
-					output.writeTextElement("td", nameQuery.value(0) + " (" + items[i] + ")");
220
-					output.writeStartElement("td");
221
-					output.writeAttribute("align", "center");
222
-					output.writeCharacters(quantities[i]);
223
-					output.writeEndElement();
224
-					output.writeEndElement();
225
-				}
226
-				nameQuery = nameQuery.invalidate();
227
-				output.writeEndElement();
228
-				output.writeStartElement("tfoot");
229
-				output.writeStartElement("tr");
230
-				output.writeStartElement("td");
231
-				output.writeAttribute("align", "right");
232
-				output.writeTextElement("strong", "Green Total:");
233
-				output.writeEndElement();
234
-				output.writeStartElement("td");
235
-				output.writeAttribute("align", "center");
236
-				output.writeCharacters(table.data(row, 3));
237
-				output.writeEndElement();
238
-				output.writeEndElement();
239
-				output.writeStartElement("tr");
240
-				output.writeStartElement("td");
241
-				output.writeAttribute("align", "right");
242
-				output.writeTextElement("strong", "Roasted Weight:");
243
-				output.writeEndElement();
244
-				output.writeStartElement("td");
245
-				output.writeAttribute("align", "center");
246
-				output.writeCharacters(table.data(row, 4));
247
-				output.writeEndElement();
248
-				output.writeEndElement();
249
-				output.writeStartElement("tr");
250
-				output.writeStartElement("td");
251
-				output.writeAttribute("align", "right");
252
-				output.writeTextElement("strong", "Weight Loss:");
253
-				output.writeEndElement();
254
-				output.writeStartElement("td");
255
-				output.writeAttribute("align", "center");
256
-				output.writeCharacters(table.data(row, 5));
257
-				output.writeCharacters("%");
258
-				output.writeEndElement();
259
-				output.writeEndElement();
260
-				output.writeEndElement();
261
-				output.writeEndElement();
262
-				output.writeStartElement("p");
263
-				output.writeTextElement("strong", "Approved: ");
264
-				output.writeCharacters(approval);
265
-				output.writeEndElement();
266
-				output.writeStartElement("p");
267
-				output.writeTextElement("strong", "Files: ");
268
-				output.writeCharacters(query.value(3));
269
-				output.writeEndElement();
270
-				output.writeStartElement("p");
271
-				output.writeTextElement("strong", "Annotations:");
272
-				var files = sqlToArray(query.value(3));
273
-				var annotations = annotationFromRecord(files[0]);
274
-				fileID = files[0];
275
-				var buffer2 = new QBuffer("<points>"+annotations+"</points>");
276
-				buffer2.open(1);
277
-				var colQuery = new XQuery;
278
-				colQuery.bind("profile", buffer2);
279
-				colQuery.setQuery('for $i in doc($profile)//tuple[1]/temperature/@series return (string($i), ";")');
280
-				var result = colQuery.exec();
281
-				buffer2.close();
282
-				var seriesHeaders = new Array();
283
-				seriesHeaders.push("Time");
284
-				var records = result.split(";");
285
-				for(var i = 0; i < records.length - 1; i++) {
286
-					seriesHeaders.push(records[i].replace(/^\s+|\s+$/g,""));
287
-				}
288
-				seriesHeaders.push("Note");
289
-				output.writeStartElement("table");
290
-				output.writeStartElement("thead");
291
-				output.writeStartElement("tr");
292
-				for(var i = 0; i < seriesHeaders.length; i++) {
293
-					output.writeTextElement("th", seriesHeaders[i]);
294
-				}
295
-				output.writeEndElement();
296
-				output.writeEndElement();
297
-				buffer2.open(1);
298
-				var rq = 'for $t in doc($profile) //tuple return (string($t/time), ";", ';
299
-				for(var i = 0; i < seriesHeaders.length - 2; i++) {
300
-					rq = rq + 'string($t/temperature[' + Number(i+1) + ']), ";", ';
301
-				}
302
-				rq = rq + 'string($t/annotation), "~")';
303
-				colQuery.setQuery(rq);
304
-				var annotationData = colQuery.exec();
305
-				colQuery = colQuery.invalidate();
306
-				buffer2.close();
307
-				output.writeStartElement("tbody");
308
-				var annotationRecords = annotationData.split("~");
309
-				for(var i = 0; i < annotationRecords.length - 1; i++) {
310
-					output.writeStartElement("tr");
311
-					var annotationRow = annotationRecords[i].split(";");
312
-					for(var j = 0; j < annotationRow.length; j++) {
313
-						output.writeStartElement("td");
314
-						output.writeAttribute("style", "border-left: 1px solid #000000");
315
-						if(j > 0) {
316
-							output.writeAttribute("align", "center");
317
-						}
318
-						if(j > 0 && j < annotationRow.length - 1) {
319
-							output.writeCharacters(Number(annotationRow[j].replace(/^\s+|\s+$/g,"")).toFixed(2));
320
-						}
321
-						else {
322
-							output.writeCharacters(annotationRow[j].replace(/^\s+|\s+$/g,""));
323
-						}
324
-						output.writeEndElement();
325
-					}
326
-					output.writeEndElement();
327
-				}
328
-				output.writeEndElement();
329
-				output.writeEndElement();
330
-				output.writeCharacters(annotation);
331
-				output.writeEndElement();
332
-				output.writeEndElement();
333
-				output.writeEndElement();
334
-				output.writeEndDocument();
335
-				dataView.setContent(buffer);
336
-				buffer.close();
337
-				query = query.invalidate();
338
-				edit.enabled = true;
339
-			};
340
-			var saveMenu = findChildObject(this, 'save');
341
-			saveMenu.triggered.connect(function() {
342
-				var filename = QFileDialog.getSaveFileName(window, "Save Log As…", QSettings.value("script/lastDir", "") + "/");
343
-				if(filename != "") {
344
-					saveFileFromDatabase(fileID, filename);
345
-				}
346
-			});
54
+            });
55
+            target.clicked.connect(function() {
56
+                var query = new QSqlQuery;
57
+                query.prepare("SELECT file, name FROM files WHERE id = :id");
58
+                query.bind(":id", Number(fileID));
59
+                query.exec();
60
+                query.next();
61
+                var buffer = new QBuffer(query.value(0));
62
+                var pname = query.value(1);
63
+                query = query.invalidate();
64
+                var input = new XMLInput(buffer, 1);
65
+                var graph = findChildObject(Windows.loggingWindow, 'graph');
66
+                var log = findChildObject(Windows.loggingWindow, 'log');
67
+                log.clear();
68
+                graph.clear();
69
+                input.newTemperatureColumn.connect(log.setHeaderData);
70
+                input.newTemperatureColumn.connect(function(col, text) {
71
+                    if(text == Windows.loggingWindow.targetcolumnname) {
72
+                        targetseries = col;
73
+                    }
74
+                });
75
+                input.newAnnotationColumn.connect(log.setHeaderData);
76
+                input.measure.connect(graph.newMeasurement);
77
+                input.measure.connect(log.newMeasurement);
78
+                input.measure.connect(function(data, series) {
79
+                    if(series == targetseries) {
80
+                        targetDetector.newMeasurement(data);
81
+                    }
82
+                });
83
+                var lc;
84
+                input.lastColumn.connect(function(c) {
85
+                    lc = c;
86
+                    QSettings.setValue("liveColumn", c + 1);
87
+                    Windows.loggingWindow.postLoadColumnSetup(c);
88
+                });
89
+                input.annotation.connect(log.newAnnotation);
90
+                input.annotation.connect(function(note, tcol, ncol) {
91
+                    for(var i = tcol; i < ncol; i++) {
92
+                        log.newAnnotation(note, i, ncol);
93
+                    }
94
+                });
95
+                Windows.loggingWindow.windowTitle = "Typica - " + pname;
96
+                Windows.loggingWindow.raise();
97
+                Windows.loggingWindow.activateWindow();
98
+                input.input();
99
+                log.newAnnotation("End", 1, lc);
100
+                query = query.invalidate();
101
+            });
102
+            var viewbutton = findChildObject(this, 'viewprofile');
103
+            viewbutton.clicked.connect(function() {
104
+                var query = new QSqlQuery;
105
+                query.prepare("SELECT file, name FROM files WHERE id = :id");
106
+                query.bind(":id", Number(fileID));
107
+                query.exec();
108
+                if(query.next()) {
109
+                    var viewer = createWindow('offline');
110
+                    var buffer = new QBuffer(query.value(0));
111
+                    var pname = query.value(1);
112
+                    query = query.invalidate();
113
+                    var input = new XMLInput(buffer, 1);
114
+                    var graph = findChildObject(viewer, 'graph');
115
+                    var log = findChildObject(viewer, 'log');
116
+                    input.newTemperatureColumn.connect(log.setHeaderData);
117
+                    input.newTemperatureColumn.connect(function(column) {
118
+                        viewer.saveTemperatureColumns.push(column);
119
+                    });
120
+                    input.newAnnotationColumn.connect(log.setHeaderData);
121
+                    input.newAnnotationColumn.connect(function(column) {
122
+                        viewer.saveAnnotationColumns.push(column);
123
+                    });
124
+                    input.measure.connect(graph.newMeasurement);
125
+                    input.measure.connect(log.newMeasurement);
126
+                    input.annotation.connect(log.newAnnotation);
127
+                    var lc;
128
+                    input.lastColumn.connect(function(c) {
129
+                        lc = c;
130
+                        if(c < 3) {
131
+                            log.setHeaderData(3, "");
132
+                        }
133
+                    });
134
+                    input.annotation.connect(function(note, tcol, ncol) {
135
+                        for(var i = tcol; i < ncol; i++) {
136
+                            log.newAnnotation(note, i, ncol);
137
+                        }
138
+                    });
139
+                    viewer.windowTitle = "Typica - " + pname;
140
+                    viewer.raise();
141
+                    viewer.activateWindow();
142
+                    graph.updatesEnabled = false;
143
+                    log.updatesEnabled = false;
144
+                    input.input();
145
+                    log.updatesEnabled = true;
146
+                    graph.updatesEnabled = true;
147
+                    log.newAnnotation("End", 1, lc);
148
+                }
149
+                else {
150
+                    print("Query returned no results");
151
+                }
152
+                query = query.invalidate();
153
+            });
154
+            window.loadData = function(table, row) {
155
+                tableReference = table;
156
+                rowReference = row;
157
+                var buffer = new QBuffer;
158
+                buffer.open(3);
159
+                var output = new XmlWriter(buffer);
160
+                output.writeStartDocument("1.0");
161
+                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">');
162
+                output.writeStartElement("html");
163
+                output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
164
+                output.writeStartElement("head");
165
+                output.writeTextElement("title", "Batch Details");
166
+                output.writeEndElement();
167
+                output.writeStartElement("body");
168
+                output.writeStartElement("div");
169
+                output.writeAttribute("style", "float: left; padding-right: 10px");
170
+                output.writeStartElement("p");
171
+                output.writeTextElement("strong", "Roasted Coffee: ");
172
+                output.writeTextElement("span", table.data(row, 2));
173
+                output.writeEndElement();
174
+                output.writeEndElement();
175
+                output.writeStartElement("div");
176
+                output.writeAttribute("style", "float: left");
177
+                output.writeStartElement("p");
178
+                output.writeTextElement("strong", "Roasted On: ");
179
+                batchTime = table.data(row, 0);
180
+                output.writeTextElement("span", batchTime);
181
+                output.writeEndElement();
182
+                output.writeStartElement("p");
183
+                output.writeTextElement("strong", "Batch Duration: ");
184
+                output.writeTextElement("span", table.data(row, 6));
185
+                output.writeEndElement();
186
+                output.writeEndElement();
187
+                output.writeStartElement("div");
188
+                output.writeAttribute("style", "clear: both");
189
+                output.writeEndElement();
190
+                output.writeStartElement("table");
191
+                output.writeStartElement("thead");
192
+                output.writeStartElement("tr");
193
+                output.writeTextElement("th", "Green Coffee");
194
+                output.writeTextElement("th", "Weight (lb)");
195
+                output.writeEndElement();
196
+                output.writeEndElement();
197
+                output.writeStartElement("tbody");
198
+                var query = new QSqlQuery();
199
+                query.prepare("SELECT unroasted_id, unroasted_quantity, approval, files, annotation, unroasted_total_quantity, roasted_quantity FROM roasting_log WHERE time = :time AND machine = :machine");
200
+                query.bind(":time", batchTime);
201
+                machine = table.data(row, 1);
202
+                query.bind(":machine", machine);
203
+                query.exec();
204
+                query.next();
205
+                approval = query.value(2);
206
+                annotation = query.value(4);
207
+                var items = sqlToArray(query.value(0));
208
+                var quantities = sqlToArray(query.value(1));
209
+                var nameQuery = new QSqlQuery();
210
+                nameQuery.prepare("SELECT name FROM items WHERE id = :id");
211
+                for(var i = 0; i < items.length; i++) {
212
+                    output.writeStartElement("tr");
213
+                    nameQuery.bind(":id", items[i]);
214
+                    nameQuery.exec();
215
+                    nameQuery.next();
216
+                    output.writeTextElement("td", nameQuery.value(0) + " (" + items[i] + ")");
217
+                    output.writeStartElement("td");
218
+                    output.writeAttribute("align", "center");
219
+                    output.writeCharacters(quantities[i]);
220
+                    output.writeEndElement();
221
+                    output.writeEndElement();
222
+                }
223
+                nameQuery = nameQuery.invalidate();
224
+                output.writeEndElement();
225
+                output.writeStartElement("tfoot");
226
+                output.writeStartElement("tr");
227
+                output.writeStartElement("td");
228
+                output.writeAttribute("align", "right");
229
+                output.writeTextElement("strong", "Green Total:");
230
+                output.writeEndElement();
231
+                output.writeStartElement("td");
232
+                output.writeAttribute("align", "center");
233
+                output.writeCharacters(query.value(5));
234
+                output.writeEndElement();
235
+                output.writeEndElement();
236
+                output.writeStartElement("tr");
237
+                output.writeStartElement("td");
238
+                output.writeAttribute("align", "right");
239
+                output.writeTextElement("strong", "Roasted Weight:");
240
+                output.writeEndElement();
241
+                output.writeStartElement("td");
242
+                output.writeAttribute("align", "center");
243
+                output.writeCharacters(query.value(6));
244
+                output.writeEndElement();
245
+                output.writeEndElement();
246
+                output.writeStartElement("tr");
247
+                output.writeStartElement("td");
248
+                output.writeAttribute("align", "right");
249
+                output.writeTextElement("strong", "Weight Loss:");
250
+                output.writeEndElement();
251
+                output.writeStartElement("td");
252
+                output.writeAttribute("align", "center");
253
+                output.writeCharacters(table.data(row, 5));
254
+                output.writeCharacters("%");
255
+                output.writeEndElement();
256
+                output.writeEndElement();
257
+                output.writeEndElement();
258
+                output.writeEndElement();
259
+                output.writeStartElement("p");
260
+                output.writeTextElement("strong", "Approved: ");
261
+                output.writeCharacters(approval);
262
+                output.writeEndElement();
263
+                output.writeStartElement("p");
264
+                output.writeTextElement("strong", "Files: ");
265
+                output.writeCharacters(query.value(3));
266
+                output.writeEndElement();
267
+                output.writeStartElement("p");
268
+                output.writeTextElement("strong", "Annotations:");
269
+                var files = sqlToArray(query.value(3));
270
+                var annotations = annotationFromRecord(files[0]);
271
+                fileID = files[0];
272
+                var buffer2 = new QBuffer("<points>"+annotations+"</points>");
273
+                buffer2.open(1);
274
+                var colQuery = new XQuery;
275
+                colQuery.bind("profile", buffer2);
276
+                colQuery.setQuery('for $i in doc($profile)//tuple[1]/temperature/@series return (string($i), ";")');
277
+                var result = colQuery.exec();
278
+                buffer2.close();
279
+                var seriesHeaders = new Array();
280
+                seriesHeaders.push("Time");
281
+                var records = result.split(";");
282
+                for(var i = 0; i < records.length - 1; i++) {
283
+                    seriesHeaders.push(records[i].replace(/^\s+|\s+$/g,""));
284
+                }
285
+                seriesHeaders.push("Note");
286
+                output.writeStartElement("table");
287
+                output.writeStartElement("thead");
288
+                output.writeStartElement("tr");
289
+                for(var i = 0; i < seriesHeaders.length; i++) {
290
+                        output.writeTextElement("th", seriesHeaders[i]);
291
+                }
292
+                output.writeEndElement();
293
+                output.writeEndElement();
294
+                buffer2.open(1);
295
+                var rq = 'for $t in doc($profile) //tuple return (string($t/time), ";", ';
296
+                for(var i = 0; i < seriesHeaders.length - 2; i++) {
297
+                        rq = rq + 'string($t/temperature[' + Number(i+1) + ']), ";", ';
298
+                }
299
+                rq = rq + 'string($t/annotation), "~")';
300
+                colQuery.setQuery(rq);
301
+                var annotationData = colQuery.exec();
302
+                colQuery = colQuery.invalidate();
303
+                buffer2.close();
304
+                output.writeStartElement("tbody");
305
+                var annotationRecords = annotationData.split("~");
306
+                for(var i = 0; i < annotationRecords.length - 1; i++) {
307
+                    output.writeStartElement("tr");
308
+                    var annotationRow = annotationRecords[i].split(";");
309
+                    for(var j = 0; j < annotationRow.length; j++) {
310
+                        output.writeStartElement("td");
311
+                        output.writeAttribute("style", "border-left: 1px solid #000000");
312
+                        if(j > 0) {
313
+                            output.writeAttribute("align", "center");
314
+                        }
315
+                        if(j > 0 && j < annotationRow.length - 1) {
316
+                            output.writeCharacters(Number(annotationRow[j].replace(/^\s+|\s+$/g,"")).toFixed(2));
317
+                        }
318
+                        else {
319
+                            output.writeCharacters(annotationRow[j].replace(/^\s+|\s+$/g,""));
320
+                        }
321
+                        output.writeEndElement();
322
+                    }
323
+                    output.writeEndElement();
324
+                }
325
+                output.writeEndElement();
326
+                output.writeEndElement();
327
+                output.writeCharacters(annotation);
328
+                output.writeEndElement();
329
+                output.writeEndElement();
330
+                output.writeEndElement();
331
+                output.writeEndDocument();
332
+                dataView.setContent(buffer);
333
+                buffer.close();
334
+                query = query.invalidate();
335
+                edit.enabled = true;
336
+            };
337
+            var saveMenu = findChildObject(this, 'save');
338
+            saveMenu.triggered.connect(function() {
339
+                var filename = QFileDialog.getSaveFileName(window, "Save Log As…", QSettings.value("script/lastDir", "") + "/");
340
+                if(filename != "") {
341
+                    saveFileFromDatabase(fileID, filename);
342
+                }
343
+            });
347 344
         ]]>
348 345
     </program>
349 346
 </window>

+ 16
- 1
config/Windows/history.xml Просмотреть файл

@@ -6,6 +6,8 @@
6 6
             <label>Approval: </label>
7 7
             <sqldrop id="approval" />
8 8
             <daterange id="dates" initial="6" /><!-- Last 7 Days -->
9
+            <label>Weight Unit:</label>
10
+            <sqldrop id="unit" />
9 11
             <stretch />
10 12
         </layout>
11 13
         <sqlview id="table" />
@@ -26,6 +28,14 @@
26 28
             dateSelect.setLifetimeRange(lifetimeStartDate, lifetimeEndDate);
27 29
             dateQuery.invalidate();
28 30
             dateSelect.currentIndex = QSettings.value("script/history/dateIndex", 6);
31
+            var unitBox = findChildObject(this, 'unit');
32
+            unitBox.addItem("Kg");
33
+            unitBox.addItem("Lb");
34
+            unitBox.currentIndex = QSettings.value("script/history_unit", 1);
35
+            unitBox['currentIndexChanged(int)'].connect(function() {
36
+                QSettings.setValue("script/history_unit", unitBox.currentIndex);
37
+                refresh();
38
+            });
29 39
             var batchType = findChildObject(this, 'batchtype');
30 40
             batchType.addItem("Any");
31 41
             batchType.addItem("Production Roasts");
@@ -77,7 +87,12 @@
77 87
                 var dateRange = dateSelect.currentRange();
78 88
                 var startDate = "'"+dateRange[0]+"'";
79 89
                 var endDate = "'"+dateRange[dateRange.length - 1]+"'";
80
-                var q = "SELECT time, machine, (SELECT name FROM items WHERE id = roasted_id) AS name, unroasted_total_quantity AS green, roasted_quantity AS roasted, CASE WHEN unroasted_total_quantity = 0 THEN NULL ELSE ((unroasted_total_quantity - roasted_quantity) / unroasted_total_quantity * 100::numeric)::numeric(12,2) END AS weight_loss, duration, annotation FROM roasting_log WHERE time >= " + startDate + "::date AND time < " + endDate + "::date + interval '1 day'" + transaction_filter + approval_filter + " ORDER BY time DESC";
90
+                var conversion = 1;
91
+                if(unitBox.currentIndex == 0)
92
+                {
93
+                    conversion = 2.2;
94
+                }
95
+                var q = "SELECT time, machine, (SELECT name FROM items WHERE id = roasted_id) AS name, unroasted_total_quantity / " + conversion + " AS green, roasted_quantity  / " + conversion + " AS roasted, CASE WHEN unroasted_total_quantity = 0 THEN NULL ELSE ((unroasted_total_quantity - roasted_quantity) / unroasted_total_quantity * 100::numeric)::numeric(12,2) END AS weight_loss, duration, annotation FROM roasting_log WHERE time >= " + startDate + "::date AND time < " + endDate + "::date + interval '1 day'" + transaction_filter + approval_filter + " ORDER BY time DESC";
81 96
                 table.setQuery(q);
82 97
                 table.hideColumn(1);
83 98
             }

Загрузка…
Отмена
Сохранить