|
|
@@ -0,0 +1,546 @@
|
|
|
1
|
+from openpyxl import load_workbook
|
|
|
2
|
+import pyodbc
|
|
|
3
|
+import time
|
|
|
4
|
+import sys
|
|
|
5
|
+from pprint import pprint
|
|
|
6
|
+import datetime
|
|
|
7
|
+from openpyxl.styles import NamedStyle, Font
|
|
|
8
|
+from copy import deepcopy
|
|
|
9
|
+from openpyxl.chart import LineChart, Reference, Series
|
|
|
10
|
+from openpyxl.chart.text import RichText
|
|
|
11
|
+from openpyxl.drawing.text import RichTextProperties,Paragraph,ParagraphProperties, CharacterProperties
|
|
|
12
|
+
|
|
|
13
|
+# Specifying the ODBC driver, server name, database, etc. directly
|
|
|
14
|
+#cnxn = None
|
|
|
15
|
+#cursor = None
|
|
|
16
|
+'''cursor.execute('select * from data_wb')
|
|
|
17
|
+rows = cursor.fetchall()
|
|
|
18
|
+for row in rows:
|
|
|
19
|
+ print(row)'''
|
|
|
20
|
+
|
|
|
21
|
+wb = load_workbook(filename = './dctemplate2.xlsx')
|
|
|
22
|
+#wb.save(filename = './createfrompy.xlsx');
|
|
|
23
|
+def findCustomer(code):
|
|
|
24
|
+ global cursor
|
|
|
25
|
+ global env
|
|
|
26
|
+
|
|
|
27
|
+ tempResult = []
|
|
|
28
|
+ views = []
|
|
|
29
|
+ if env == "prod":
|
|
|
30
|
+ views = ["bel_master_view", "e_master_view", "mg_master_view", "v_master_view"]
|
|
|
31
|
+ else:
|
|
|
32
|
+ views = ["bel_master_view_dev", "e_master_view_dev", "mg_master_view_dev", "v_master_view_dev"]
|
|
|
33
|
+
|
|
|
34
|
+ ts = []
|
|
|
35
|
+
|
|
|
36
|
+ select = "distinct MI24 as unbStd, PRO1C as customer, cast(PRO8 as varchar) + ' ' + cast(PRO9 as varchar) + cast(PRO10 as varchar) + 'x' + cast(PRO11 as varchar ) + 'x' + cast(PRO12 as varchar) as sizestring, cast(PRO13 as varchar) + ' ' + cast(PRO14 as varchar) + ' ' + cast(PRO15 as varchar) + ' ' + cast(PRO16 as varchar) + ' ' + cast(PRO17 as varchar) + ' ' + cast(PRO18 as varchar) as spec"
|
|
|
37
|
+ where = "PRO1 = '{0}'".format(code)
|
|
|
38
|
+ for v in views:
|
|
|
39
|
+ sqlQuery = "select {0} from {1} where {2}".format(select, v, where)
|
|
|
40
|
+ ts.append(sqlQuery)
|
|
|
41
|
+ merged = []
|
|
|
42
|
+ for t in ts:
|
|
|
43
|
+ merged += cursor.execute(t)
|
|
|
44
|
+ return merged
|
|
|
45
|
+
|
|
|
46
|
+def findInMasterView(select, where):
|
|
|
47
|
+ global cursor
|
|
|
48
|
+ global env
|
|
|
49
|
+
|
|
|
50
|
+ tempResult = []
|
|
|
51
|
+ views = []
|
|
|
52
|
+ if env == "prod":
|
|
|
53
|
+ views = ["bel_master_view", "e_master_view", "mg_master_view", "v_master_view"]
|
|
|
54
|
+ else:
|
|
|
55
|
+ views = ["bel_master_view_dev", "e_master_view_dev", "mg_master_view_dev", "v_master_view_dev"]
|
|
|
56
|
+
|
|
|
57
|
+
|
|
|
58
|
+
|
|
|
59
|
+ ts = []
|
|
|
60
|
+ for v in views:
|
|
|
61
|
+ sqlQuery = "select {0} from {1} where {2}".format(select, v, where)
|
|
|
62
|
+ ts.append(sqlQuery);
|
|
|
63
|
+
|
|
|
64
|
+ qj = ';'.join(ts)
|
|
|
65
|
+ #print(qj)
|
|
|
66
|
+ merged = []
|
|
|
67
|
+ for t in ts:
|
|
|
68
|
+ merged += cursor.execute(t)
|
|
|
69
|
+ return merged
|
|
|
70
|
+
|
|
|
71
|
+def updateLength(lotno):
|
|
|
72
|
+ global cursor
|
|
|
73
|
+ global wb
|
|
|
74
|
+
|
|
|
75
|
+ q = "select * from data_wb where lot_no = '{0}' and judgement='OK' order by row_no asc".format(lotno)
|
|
|
76
|
+ #print(q);
|
|
|
77
|
+ return cursor.execute(q)
|
|
|
78
|
+
|
|
|
79
|
+def updateUb(lotno):
|
|
|
80
|
+ global cursor
|
|
|
81
|
+ global wb
|
|
|
82
|
+
|
|
|
83
|
+ q = "select * from data_wb where lot_no = '{0}' and judgement='NG' order by row_no asc".format(lotno)
|
|
|
84
|
+ #print(q);
|
|
|
85
|
+ return cursor.execute(q)
|
|
|
86
|
+
|
|
|
87
|
+def getMachineName(machineId):
|
|
|
88
|
+ global cursor
|
|
|
89
|
+ q = "select * from machines_wb where id = {0}".format(machineId)
|
|
|
90
|
+ #print(q)
|
|
|
91
|
+ cursor.execute(q)
|
|
|
92
|
+ rs = cursor.fetchall()
|
|
|
93
|
+ return rs[0].name
|
|
|
94
|
+
|
|
|
95
|
+def getMachineDetail(machineId):
|
|
|
96
|
+ global cursor
|
|
|
97
|
+ q = "select * from machines_wb where id = {0}".format(machineId)
|
|
|
98
|
+ #print(q)
|
|
|
99
|
+ cursor.execute(q)
|
|
|
100
|
+ rs = cursor.fetchall()
|
|
|
101
|
+ return rs[0]
|
|
|
102
|
+
|
|
|
103
|
+def createDayChart(chartTitle):
|
|
|
104
|
+ global wb
|
|
|
105
|
+ ws = wb['Chart']
|
|
|
106
|
+ wsd = wb['Daily Check']
|
|
|
107
|
+ c1 = LineChart()
|
|
|
108
|
+ c1.legend.position = "t";
|
|
|
109
|
+ c1.title = chartTitle
|
|
|
110
|
+ c1.title.font = Font(underline=Font.UNDERLINE_SINGLE)
|
|
|
111
|
+ c1.y_axis.title = "Std. Weight(g)"
|
|
|
112
|
+ c1.y_axis.number_format = "#,##0.00"
|
|
|
113
|
+ c1.x_axis.title = "Date"
|
|
|
114
|
+ c1.width = 30
|
|
|
115
|
+ c1.height = 10
|
|
|
116
|
+
|
|
|
117
|
+
|
|
|
118
|
+ #print(len(values))
|
|
|
119
|
+ MINDATACOL = 2
|
|
|
120
|
+ MAXDATACOL = 2 + 31
|
|
|
121
|
+ lt = Reference(wsd, min_col=3, max_col=33, min_row=5, max_row=5)
|
|
|
122
|
+
|
|
|
123
|
+ std = Reference(wsd, min_col=MINDATACOL, max_col=MAXDATACOL, min_row=6, max_row=6)
|
|
|
124
|
+ data = Reference(wsd, min_col=MINDATACOL, max_col=MAXDATACOL, min_row=10, max_row=10)
|
|
|
125
|
+
|
|
|
126
|
+ maxUB = Reference(wsd, min_col=MINDATACOL, max_col=MAXDATACOL, min_row=15, max_row=15)
|
|
|
127
|
+ minUB = Reference(wsd, min_col=MINDATACOL, max_col=MAXDATACOL, min_row=21, max_row=21)
|
|
|
128
|
+ avgUB = Reference(wsd, min_col=MINDATACOL, max_col=MAXDATACOL, min_row=26, max_row=26)
|
|
|
129
|
+ vsStd = Reference(wsd, min_col=MINDATACOL, max_col=MAXDATACOL, min_row=32, max_row=32)
|
|
|
130
|
+ vsStd2 = Reference(wsd, min_col=MINDATACOL, max_col=MAXDATACOL, min_row=37, max_row=37)
|
|
|
131
|
+
|
|
|
132
|
+
|
|
|
133
|
+ c1.add_data(data, from_rows=True, titles_from_data=True)
|
|
|
134
|
+ c1.add_data(maxUB, from_rows=True, titles_from_data=True)
|
|
|
135
|
+ c1.add_data(minUB, from_rows=True, titles_from_data=True)
|
|
|
136
|
+ c1.add_data(avgUB, from_rows=True, titles_from_data=True)
|
|
|
137
|
+ c1.add_data(vsStd, from_rows=True, titles_from_data=True)
|
|
|
138
|
+ c1.add_data(vsStd2, from_rows=True, titles_from_data=True)
|
|
|
139
|
+ c1.add_data(std, from_rows=True, titles_from_data=True)
|
|
|
140
|
+
|
|
|
141
|
+ s1 = c1.series[0]
|
|
|
142
|
+ s1.marker.symbol = "triangle"
|
|
|
143
|
+ s1.graphicalProperties.line.noFill = True
|
|
|
144
|
+
|
|
|
145
|
+ s1 = c1.series[1]
|
|
|
146
|
+ s1.marker.symbol = "circle"
|
|
|
147
|
+ s1.graphicalProperties.line.noFill = True
|
|
|
148
|
+
|
|
|
149
|
+ s1 = c1.series[2]
|
|
|
150
|
+ s1.marker.symbol = "square"
|
|
|
151
|
+ s1.graphicalProperties.line.noFill = True
|
|
|
152
|
+
|
|
|
153
|
+ s1 = c1.series[3]
|
|
|
154
|
+ s1.marker.symbol = "auto"
|
|
|
155
|
+ s1.graphicalProperties.line.noFill = True
|
|
|
156
|
+
|
|
|
157
|
+ s1 = c1.series[4]
|
|
|
158
|
+ s1.marker.symbol = "diamond"
|
|
|
159
|
+ s1.graphicalProperties.line.noFill = True
|
|
|
160
|
+
|
|
|
161
|
+ s1 = c1.series[5]
|
|
|
162
|
+ s1.marker.symbol = "auto"
|
|
|
163
|
+ s1.graphicalProperties.line.noFill = True
|
|
|
164
|
+
|
|
|
165
|
+ s1 = c1.series[6]
|
|
|
166
|
+ #s1.marker.symbol = "diamond"
|
|
|
167
|
+ #s1.graphicalProperties.line.noFill = True
|
|
|
168
|
+
|
|
|
169
|
+ c1.set_categories(lt)
|
|
|
170
|
+
|
|
|
171
|
+ '''c1.x_axis.txPr = RichText(bodyPr=RichTextProperties(anchor="ctr",anchorCtr="1",rot="-2700000",
|
|
|
172
|
+ spcFirstLastPara="1",vertOverflow="ellipsis",wrap="square"),
|
|
|
173
|
+ p=[Paragraph(pPr=ParagraphProperties(defRPr=CharacterProperties()), endParaRPr=CharacterProperties())])'''
|
|
|
174
|
+
|
|
|
175
|
+ ws.add_chart(c1, "b3")
|
|
|
176
|
+ #pass
|
|
|
177
|
+def createNightChart(chartTitle):
|
|
|
178
|
+ global wb
|
|
|
179
|
+ ws = wb['Chart']
|
|
|
180
|
+ wsd = wb['Daily Check']
|
|
|
181
|
+ c1 = LineChart()
|
|
|
182
|
+ c1.legend.position = "t";
|
|
|
183
|
+ c1.title = chartTitle
|
|
|
184
|
+ c1.title.font = Font(underline=Font.UNDERLINE_SINGLE)
|
|
|
185
|
+ c1.y_axis.title = "Std. Weight(g)"
|
|
|
186
|
+ c1.y_axis.number_format = "#,##0.00"
|
|
|
187
|
+ c1.x_axis.title = "Date"
|
|
|
188
|
+ c1.width = 30
|
|
|
189
|
+ c1.height = 10
|
|
|
190
|
+
|
|
|
191
|
+
|
|
|
192
|
+ #print(len(values))
|
|
|
193
|
+ MINDATACOL = 2
|
|
|
194
|
+ MAXDATACOL = 2 + 31
|
|
|
195
|
+ lt = Reference(wsd, min_col=3, max_col=33, min_row=5, max_row=5)
|
|
|
196
|
+
|
|
|
197
|
+ std = Reference(wsd, min_col=MINDATACOL, max_col=MAXDATACOL, min_row=6, max_row=6)
|
|
|
198
|
+ #begin data
|
|
|
199
|
+ data = Reference(wsd, min_col=MINDATACOL, max_col=MAXDATACOL, min_row=51, max_row=51)
|
|
|
200
|
+
|
|
|
201
|
+ maxUB = Reference(wsd, min_col=MINDATACOL, max_col=MAXDATACOL, min_row=56, max_row=56)
|
|
|
202
|
+ minUB = Reference(wsd, min_col=MINDATACOL, max_col=MAXDATACOL, min_row=62, max_row=62)
|
|
|
203
|
+ avgUB = Reference(wsd, min_col=MINDATACOL, max_col=MAXDATACOL, min_row=67, max_row=67)
|
|
|
204
|
+ vsStd = Reference(wsd, min_col=MINDATACOL, max_col=MAXDATACOL, min_row=73, max_row=73)
|
|
|
205
|
+ vsStd2 = Reference(wsd, min_col=MINDATACOL, max_col=MAXDATACOL, min_row=78, max_row=78)
|
|
|
206
|
+
|
|
|
207
|
+
|
|
|
208
|
+ c1.add_data(data, from_rows=True, titles_from_data=True)
|
|
|
209
|
+ c1.add_data(maxUB, from_rows=True, titles_from_data=True)
|
|
|
210
|
+ c1.add_data(minUB, from_rows=True, titles_from_data=True)
|
|
|
211
|
+ c1.add_data(avgUB, from_rows=True, titles_from_data=True)
|
|
|
212
|
+ c1.add_data(vsStd, from_rows=True, titles_from_data=True)
|
|
|
213
|
+ c1.add_data(vsStd2, from_rows=True, titles_from_data=True)
|
|
|
214
|
+ c1.add_data(std, from_rows=True, titles_from_data=True)
|
|
|
215
|
+
|
|
|
216
|
+ s1 = c1.series[0]
|
|
|
217
|
+ s1.marker.symbol = "triangle"
|
|
|
218
|
+ s1.graphicalProperties.line.noFill = True
|
|
|
219
|
+
|
|
|
220
|
+ s1 = c1.series[1]
|
|
|
221
|
+ s1.marker.symbol = "circle"
|
|
|
222
|
+ s1.graphicalProperties.line.noFill = True
|
|
|
223
|
+
|
|
|
224
|
+ s1 = c1.series[2]
|
|
|
225
|
+ s1.marker.symbol = "square"
|
|
|
226
|
+ s1.graphicalProperties.line.noFill = True
|
|
|
227
|
+
|
|
|
228
|
+ s1 = c1.series[3]
|
|
|
229
|
+ s1.marker.symbol = "auto"
|
|
|
230
|
+ s1.graphicalProperties.line.noFill = True
|
|
|
231
|
+
|
|
|
232
|
+ s1 = c1.series[4]
|
|
|
233
|
+ s1.marker.symbol = "diamond"
|
|
|
234
|
+ s1.graphicalProperties.line.noFill = True
|
|
|
235
|
+
|
|
|
236
|
+ s1 = c1.series[5]
|
|
|
237
|
+ s1.marker.symbol = "auto"
|
|
|
238
|
+ s1.graphicalProperties.line.noFill = True
|
|
|
239
|
+
|
|
|
240
|
+ s1 = c1.series[6]
|
|
|
241
|
+ #s1.marker.symbol = "diamond"
|
|
|
242
|
+ #s1.graphicalProperties.line.noFill = True
|
|
|
243
|
+
|
|
|
244
|
+ c1.set_categories(lt)
|
|
|
245
|
+
|
|
|
246
|
+ '''c1.x_axis.txPr = RichText(bodyPr=RichTextProperties(anchor="ctr",anchorCtr="1",rot="-2700000",
|
|
|
247
|
+ spcFirstLastPara="1",vertOverflow="ellipsis",wrap="square"),
|
|
|
248
|
+ p=[Paragraph(pPr=ParagraphProperties(defRPr=CharacterProperties()), endParaRPr=CharacterProperties())])'''
|
|
|
249
|
+
|
|
|
250
|
+ ws.add_chart(c1, "b22")
|
|
|
251
|
+
|
|
|
252
|
+def createExcel(codeno, filters):
|
|
|
253
|
+ global cursor
|
|
|
254
|
+ global wb
|
|
|
255
|
+ ws = wb["Daily Check"]
|
|
|
256
|
+
|
|
|
257
|
+
|
|
|
258
|
+ machineName = getMachineName(codeno)
|
|
|
259
|
+ machineDetail = getMachineDetail(codeno)
|
|
|
260
|
+
|
|
|
261
|
+ ws["C2"].value = machineName
|
|
|
262
|
+ ws["C3"].value = filters.replace("created_at between", "").replace("and", "to").replace("'", "")
|
|
|
263
|
+
|
|
|
264
|
+ ws["C43"].value = machineName
|
|
|
265
|
+ ws["C44"].value = filters.replace("created_at between", "").replace("and", "to").replace("'", "")
|
|
|
266
|
+
|
|
|
267
|
+ ws["C4"].value = machineDetail.machineStd;
|
|
|
268
|
+
|
|
|
269
|
+ if filters is not None:
|
|
|
270
|
+ q = "select * from daily_checks_wb where machine_id = '{0}' and {1}".format(codeno, filters)
|
|
|
271
|
+ else:
|
|
|
272
|
+ q = "select * from daily_checks_wb where machine_id = '{0}'".format(codeno)
|
|
|
273
|
+
|
|
|
274
|
+
|
|
|
275
|
+ #print(q)
|
|
|
276
|
+ cursor.execute(q)
|
|
|
277
|
+ rows = cursor.fetchall()
|
|
|
278
|
+ #print(rows)
|
|
|
279
|
+ a0740 = [];
|
|
|
280
|
+ a1230 = []
|
|
|
281
|
+ a1700 = []
|
|
|
282
|
+ a0030 = []
|
|
|
283
|
+ a1940 = []
|
|
|
284
|
+ a0500 = []
|
|
|
285
|
+
|
|
|
286
|
+ for i in range(31):
|
|
|
287
|
+ a0740.append([])
|
|
|
288
|
+ a1230.append([])
|
|
|
289
|
+ a1700.append([])
|
|
|
290
|
+ a0030.append([])
|
|
|
291
|
+ a1940.append([])
|
|
|
292
|
+ a0500.append([])
|
|
|
293
|
+
|
|
|
294
|
+
|
|
|
295
|
+ for r in rows:
|
|
|
296
|
+ i = r.created_at.day
|
|
|
297
|
+ if r.shift == "07.40":
|
|
|
298
|
+ a0740[i-1].append(r)
|
|
|
299
|
+ if r.shift == "12.30":
|
|
|
300
|
+ a1230[i-1].append(r)
|
|
|
301
|
+ if r.shift == "17.00":
|
|
|
302
|
+ #a1700.append(r)
|
|
|
303
|
+ a1700[i-1].append(r)
|
|
|
304
|
+ if r.shift == "00.30":
|
|
|
305
|
+ a0030[i-1].append(r)
|
|
|
306
|
+ if r.shift == "19.40":
|
|
|
307
|
+ a1940[i-1].append(r)
|
|
|
308
|
+ if r.shift == "05.00":
|
|
|
309
|
+ a0500[i-1].append(r)
|
|
|
310
|
+
|
|
|
311
|
+
|
|
|
312
|
+ #print(a0740)
|
|
|
313
|
+ for idx, val in enumerate(a0740):
|
|
|
314
|
+ j = 7
|
|
|
315
|
+ k = 12
|
|
|
316
|
+ users = []
|
|
|
317
|
+ #print(val)
|
|
|
318
|
+ ok = 0
|
|
|
319
|
+ ng = 0
|
|
|
320
|
+ for v in val:
|
|
|
321
|
+ #print(j , idx + )
|
|
|
322
|
+ #print(v.judgment)
|
|
|
323
|
+ if v.judgement == "OK":
|
|
|
324
|
+ ok += 1
|
|
|
325
|
+ if ok > 3:
|
|
|
326
|
+ continue
|
|
|
327
|
+ ws.cell(row = j , column = idx + 3 , value = v.weight)
|
|
|
328
|
+ j += 1
|
|
|
329
|
+ if v.judgement == "NG":
|
|
|
330
|
+ ng += 1
|
|
|
331
|
+ if ng > 3:
|
|
|
332
|
+ continue
|
|
|
333
|
+ ws.cell(row = k , column = idx + 3 , value = v.weight)
|
|
|
334
|
+ k += 1
|
|
|
335
|
+
|
|
|
336
|
+ #print(v.empid)
|
|
|
337
|
+ if v.empid not in users:
|
|
|
338
|
+ #print("insert in users")
|
|
|
339
|
+ users.append(v.empid)
|
|
|
340
|
+
|
|
|
341
|
+ #print(val)
|
|
|
342
|
+ if len(val) > 0:
|
|
|
343
|
+ q = "select * from users where empid in ({0})".format(",".join("'{0}'".format(w) for w in users))
|
|
|
344
|
+ #print(q)
|
|
|
345
|
+ cursor.execute(q)
|
|
|
346
|
+ us = cursor.fetchall()
|
|
|
347
|
+ names = [x.fname + " " + x.lname for x in us]
|
|
|
348
|
+ ws.cell(row = 17, column = idx + 3, value = ",".join(names))
|
|
|
349
|
+
|
|
|
350
|
+ for idx, val in enumerate(a1230):
|
|
|
351
|
+ j = 18
|
|
|
352
|
+ k = 23
|
|
|
353
|
+ users = []
|
|
|
354
|
+ ok = ng = 0
|
|
|
355
|
+ for v in val:
|
|
|
356
|
+ #print(j , idx)
|
|
|
357
|
+ if v.judgement == "OK":
|
|
|
358
|
+ ok += 1
|
|
|
359
|
+ if ok > 3:
|
|
|
360
|
+ continue
|
|
|
361
|
+ ws.cell(row = j , column = idx + 3 , value = v.weight)
|
|
|
362
|
+ j += 1
|
|
|
363
|
+ if v.judgement == "NG":
|
|
|
364
|
+ ng += 1
|
|
|
365
|
+ if ng > 3:
|
|
|
366
|
+ continue
|
|
|
367
|
+
|
|
|
368
|
+ ws.cell(row = k , column = idx + 3 , value = v.weight)
|
|
|
369
|
+ k += 1
|
|
|
370
|
+
|
|
|
371
|
+ if v.empid not in users:
|
|
|
372
|
+ users.append(v.empid)
|
|
|
373
|
+
|
|
|
374
|
+ if len(val) > 0:
|
|
|
375
|
+ q = "select * from users where empid in ({0})".format(",".join("'{0}'".format(w) for w in users))
|
|
|
376
|
+ #print(q)
|
|
|
377
|
+ cursor.execute(q)
|
|
|
378
|
+ us = cursor.fetchall()
|
|
|
379
|
+ names = [x.fname + " " + x.lname for x in us]
|
|
|
380
|
+ ws.cell(row = 28, column = idx + 3, value = ",".join(names))
|
|
|
381
|
+
|
|
|
382
|
+ for idx, val in enumerate(a1700):
|
|
|
383
|
+ j = 29
|
|
|
384
|
+ k = 34
|
|
|
385
|
+ users = []
|
|
|
386
|
+ ok = ng = 0
|
|
|
387
|
+
|
|
|
388
|
+ for v in val:
|
|
|
389
|
+ #print(j , idx)
|
|
|
390
|
+ if v.judgement == "OK":
|
|
|
391
|
+ ok += 1
|
|
|
392
|
+ if ok > 3:
|
|
|
393
|
+ continue
|
|
|
394
|
+
|
|
|
395
|
+ ws.cell(row = j , column = idx + 3 , value = v.weight)
|
|
|
396
|
+ j += 1
|
|
|
397
|
+ if v.judgement == "NG":
|
|
|
398
|
+ ng += 1
|
|
|
399
|
+ if ng > 3:
|
|
|
400
|
+ continue
|
|
|
401
|
+
|
|
|
402
|
+ ws.cell(row = k , column = idx + 3 , value = v.weight)
|
|
|
403
|
+ k += 1
|
|
|
404
|
+ if v.empid not in users:
|
|
|
405
|
+ users.append(v.empid)
|
|
|
406
|
+
|
|
|
407
|
+ if len(val) > 0:
|
|
|
408
|
+ q = "select * from users where empid in ({0})".format(",".join("'{0}'".format(w) for w in users))
|
|
|
409
|
+ #print(q)
|
|
|
410
|
+ cursor.execute(q)
|
|
|
411
|
+ us = cursor.fetchall()
|
|
|
412
|
+ names = [x.fname + " " + x.lname for x in us]
|
|
|
413
|
+ ws.cell(row = 39, column = idx + 3, value = ",".join(names))
|
|
|
414
|
+
|
|
|
415
|
+ for idx, val in enumerate(a1940):
|
|
|
416
|
+ j = 47
|
|
|
417
|
+ k = 53
|
|
|
418
|
+ users = []
|
|
|
419
|
+ ok = ng = 0
|
|
|
420
|
+ for v in val:
|
|
|
421
|
+ #print(j , idx)
|
|
|
422
|
+ if v.judgement == "OK":
|
|
|
423
|
+ ok += 1
|
|
|
424
|
+ if ok > 3:
|
|
|
425
|
+ continue
|
|
|
426
|
+
|
|
|
427
|
+ ws.cell(row = j , column = idx + 3 , value = v.weight)
|
|
|
428
|
+ j += 1
|
|
|
429
|
+ if v.judgement == "NG":
|
|
|
430
|
+ ng += 1
|
|
|
431
|
+ if ng > 3:
|
|
|
432
|
+ continue
|
|
|
433
|
+
|
|
|
434
|
+ ws.cell(row = k , column = idx + 3 , value = v.weight)
|
|
|
435
|
+ k += 1
|
|
|
436
|
+ if v.empid not in users:
|
|
|
437
|
+ users.append(v.empid)
|
|
|
438
|
+
|
|
|
439
|
+ if len(val) > 0:
|
|
|
440
|
+ q = "select * from users where empid in ({0})".format(",".join("'{0}'".format(w) for w in users))
|
|
|
441
|
+
|
|
|
442
|
+ #print(q)
|
|
|
443
|
+ cursor.execute(q)
|
|
|
444
|
+ us = cursor.fetchall()
|
|
|
445
|
+ names = [x.fname + " " + x.lname for x in us]
|
|
|
446
|
+ ws.cell(row = 58, column = idx + 3, value = ",".join(names))
|
|
|
447
|
+
|
|
|
448
|
+ for idx, val in enumerate(a0030):
|
|
|
449
|
+ j = 59
|
|
|
450
|
+ k = 64
|
|
|
451
|
+ users = []
|
|
|
452
|
+ ok = ng = 0
|
|
|
453
|
+ for v in val:
|
|
|
454
|
+ #print(j , idx)
|
|
|
455
|
+ if v.judgement == "OK":
|
|
|
456
|
+ ok += 1
|
|
|
457
|
+ if ok > 3:
|
|
|
458
|
+ continue
|
|
|
459
|
+
|
|
|
460
|
+ ws.cell(row = j , column = idx + 3 , value = v.weight)
|
|
|
461
|
+ j += 1
|
|
|
462
|
+ if v.judgement == "NG":
|
|
|
463
|
+ ng += 1
|
|
|
464
|
+ if ng > 3:
|
|
|
465
|
+ continue
|
|
|
466
|
+
|
|
|
467
|
+ ws.cell(row = k , column = idx + 3 , value = v.weight)
|
|
|
468
|
+ k += 1
|
|
|
469
|
+ if v.empid not in users:
|
|
|
470
|
+ users.append(v.empid)
|
|
|
471
|
+
|
|
|
472
|
+ if len(val) > 0:
|
|
|
473
|
+ q = "select * from users where empid in ({0})".format(",".join("'{0}'".format(w) for w in users))
|
|
|
474
|
+
|
|
|
475
|
+ #print(q)
|
|
|
476
|
+ cursor.execute(q)
|
|
|
477
|
+ us = cursor.fetchall()
|
|
|
478
|
+ names = [x.fname + " " + x.lname for x in us]
|
|
|
479
|
+ ws.cell(row = 69, column = idx + 3, value = ",".join(names))
|
|
|
480
|
+
|
|
|
481
|
+ for idx, val in enumerate(a0500):
|
|
|
482
|
+ j = 70
|
|
|
483
|
+ k = 75
|
|
|
484
|
+ users = []
|
|
|
485
|
+ ok = ng = 0
|
|
|
486
|
+ for v in val:
|
|
|
487
|
+ #print(j , idx)
|
|
|
488
|
+ if v.judgement == "OK":
|
|
|
489
|
+ ok += 1
|
|
|
490
|
+ if ok > 3:
|
|
|
491
|
+ continue
|
|
|
492
|
+
|
|
|
493
|
+ ws.cell(row = j , column = idx + 3 , value = v.weight)
|
|
|
494
|
+ j += 1
|
|
|
495
|
+ if v.judgement == "NG":
|
|
|
496
|
+ ng += 1
|
|
|
497
|
+ if ng > 3:
|
|
|
498
|
+ continue
|
|
|
499
|
+ ws.cell(row = k , column = idx + 3 , value = v.weight)
|
|
|
500
|
+ k += 1
|
|
|
501
|
+ if v.empid not in users:
|
|
|
502
|
+ users.append(v.empid)
|
|
|
503
|
+
|
|
|
504
|
+ if len(val) > 0:
|
|
|
505
|
+ q = "select * from users where empid in ({0})".format(",".join("'{0}'".format(w) for w in users))
|
|
|
506
|
+ #print(q)
|
|
|
507
|
+ cursor.execute(q)
|
|
|
508
|
+ us = cursor.fetchall()
|
|
|
509
|
+ names = [x.fname + " " + x.lname for x in us]
|
|
|
510
|
+ ws.cell(row = 80, column = idx + 3, value = ",".join(names))
|
|
|
511
|
+
|
|
|
512
|
+ createDayChart("Daily Check of Day Shift ({0})".format(machineName))
|
|
|
513
|
+
|
|
|
514
|
+ createNightChart("Daily Check of Night Shift ({0})".format(machineName))
|
|
|
515
|
+
|
|
|
516
|
+ ut = int(time.time())
|
|
|
517
|
+ filename = "dc{0}.xlsx".format(str(ut))
|
|
|
518
|
+ outfile = './public/excel/'+filename
|
|
|
519
|
+ wb.save(filename = outfile)
|
|
|
520
|
+ print(filename)
|
|
|
521
|
+
|
|
|
522
|
+if __name__ == "__main__":
|
|
|
523
|
+ env = sys.argv[1]
|
|
|
524
|
+ machine = sys.argv[2]
|
|
|
525
|
+ #print(len(sys.argv))
|
|
|
526
|
+
|
|
|
527
|
+ df = None
|
|
|
528
|
+ if len(sys.argv) == 4:
|
|
|
529
|
+ filter = sys.argv[3]
|
|
|
530
|
+ #import ast
|
|
|
531
|
+ #df = ast.literal_eval(filter)
|
|
|
532
|
+ #print(df['date'])
|
|
|
533
|
+ df = filter
|
|
|
534
|
+
|
|
|
535
|
+ global cnxn
|
|
|
536
|
+ global cursor
|
|
|
537
|
+
|
|
|
538
|
+ if env == "prod":
|
|
|
539
|
+ cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=192.168.0.253;DATABASE=OB2011DB;UID=user1;PWD=1234')
|
|
|
540
|
+ cursor = cnxn.cursor()
|
|
|
541
|
+ else:
|
|
|
542
|
+ cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=localhost;DATABASE=OB2011DB;UID=admin;PWD=1234')
|
|
|
543
|
+ cursor = cnxn.cursor()
|
|
|
544
|
+ #print("code is "+code)
|
|
|
545
|
+
|
|
|
546
|
+ createExcel(machine, df)
|