回答編集履歴

1

プログラム内容

2021/09/12 05:06

投稿

F91_
F91_

スコア16

test CHANGED
@@ -6,23 +6,45 @@
6
6
 
7
7
  import glob
8
8
 
9
-
9
+ import datetime
10
-
10
+
11
+
12
+
11
- t=input('更新したい月を入力してください')
13
+ today = datetime.date.today()
14
+
12
-
15
+ year = today.year
16
+
17
+ month = today.month
18
+
19
+
20
+
21
+ input_value= input("{}年{:02}月分の集計を行います。Enterを押してください。 (別の月を集計する場合は6桁で年月を入力し、Enterを押してください) > ".format(year, month))
22
+
23
+ if not input_value:
24
+
25
+ input_value = "{}{:02}".format(year, month)
26
+
27
+
28
+
13
- file_list1=glob.glob('//192.168.3.141/pi/mydata'+t+'*')
29
+ file_list1=glob.glob('//192.168.3.141/pi/mydata'+input_value+'*')
14
-
30
+
15
- file_list2=glob.glob('//192.168.3.140/pi/mydata'+t+'*')
31
+ file_list2=glob.glob('//192.168.3.140/pi/mydata'+input_value+'*')
16
-
32
+
17
- file_list3=glob.glob('//192.168.3.139/pi/mydata'+t+'*')
33
+ file_list3=glob.glob('//192.168.3.139/pi/mydata'+input_value+'*')
18
-
34
+
19
- file_list4=glob.glob('//192.168.3.135/pi/mydata'+t+'*')
35
+ file_list4=glob.glob('//192.168.3.135/pi/mydata'+input_value+'*')
20
-
36
+
21
- file_list5=glob.glob('//192.168.3.132/pi/mydata'+t+'*')
37
+ file_list5=glob.glob('//192.168.3.132/pi/mydata'+input_value+'*')
22
-
38
+
23
- file_list6=glob.glob('//192.168.3.131/pi/mydata'+t+'*')
39
+ file_list6=glob.glob('//192.168.3.131/pi/mydata'+input_value+'*')
24
-
40
+
25
- file_list7=glob.glob('//192.168.3.134/pi/mydata'+t+'*')
41
+ file_list7=glob.glob('//192.168.3.134/pi/mydata'+input_value+'*')
42
+
43
+
44
+
45
+ g='三課伸線稼働率(全機械)'
46
+
47
+ monthly_file =g+ f'{input_value}.xlsx'
26
48
 
27
49
 
28
50
 
@@ -32,8 +54,6 @@
32
54
 
33
55
  for file1 in file_list1:
34
56
 
35
-
36
-
37
57
  a1=pd.read_csv(file1)
38
58
 
39
59
  d1=(file1[25:33])
@@ -60,30 +80,18 @@
60
80
 
61
81
  rcd1['稼働率(%)'].append(w1)
62
82
 
63
-
83
+
64
84
 
65
85
  df1=pd.DataFrame(rcd1)
66
86
 
67
- print(df1)
68
-
69
- g1='全機稼働率'
70
-
71
-
72
-
73
- monthly_file =g1+ f'{t}.xlsx'
74
-
75
-
76
-
77
87
 
78
88
 
79
89
  rcd2={'日付' : [], '稼働時間(分)': [], '無人稼働時間(分)': [], '停止時間(分)': [],'トータル時間(分)': [],'稼働率(%)': []}
80
90
 
81
-
91
+
82
92
 
83
93
  for file2 in file_list2:
84
94
 
85
-
86
-
87
95
  a2=pd.read_csv(file2)
88
96
 
89
97
  d2=(file2[25:33])
@@ -114,17 +122,201 @@
114
122
 
115
123
  df2=pd.DataFrame(rcd2)
116
124
 
125
+
126
+
127
+ rcd3={'日付' : [], '稼働時間(分)': [], '無人稼働時間(分)': [], '停止時間(分)': [],'トータル時間(分)': [],'稼働率(%)': []}
128
+
129
+
130
+
131
+ for file3 in file_list3:
132
+
133
+ a3=pd.read_csv(file3)
134
+
135
+ d3=(file2[25:33])
136
+
137
+ x3=a3.iloc[:,0].count()
138
+
139
+ y3=a3.iloc[:,1].sum()
140
+
141
+ z3=a3.iloc[:,2].sum()
142
+
117
- print(df2)
143
+ u3=x3-y3-z3
144
+
118
-
145
+ w3=round(y2/x2*100,1)
146
+
119
-
147
+ rcd3['日付'].append(d3)
148
+
120
-
149
+ rcd3['稼働時間(分)'].append(y3)
150
+
151
+ rcd3['無人稼働時間(分)'].append(z3)
152
+
153
+ rcd3['停止時間(分)'].append(u3)
154
+
155
+ rcd3['トータル時間(分)'].append(x3)
156
+
157
+ rcd3['稼働率(%)'].append(w3)
158
+
159
+
160
+
161
+ df3=pd.DataFrame(rcd3)
162
+
163
+
164
+
165
+ rcd4={'日付' : [], '稼働時間(分)': [], '無人稼働時間(分)': [], '停止時間(分)': [],'トータル時間(分)': [],'稼働率(%)': []}
166
+
167
+
168
+
169
+ for file4 in file_list4:
170
+
171
+ a4=pd.read_csv(file4)
172
+
173
+ d4=(file4[25:33])
174
+
175
+ x4=a4.iloc[:,0].count()
176
+
177
+ y4=a4.iloc[:,1].sum()
178
+
179
+ z4=a4.iloc[:,2].sum()
180
+
181
+ u4=x4-y4-z4
182
+
183
+ w4=round(y2/x2*100,1)
184
+
185
+ rcd4['日付'].append(d4)
186
+
187
+ rcd4['稼働時間(分)'].append(y4)
188
+
189
+ rcd4['無人稼働時間(分)'].append(z4)
190
+
191
+ rcd4['停止時間(分)'].append(u4)
192
+
193
+ rcd4['トータル時間(分)'].append(x4)
194
+
195
+ rcd4['稼働率(%)'].append(w4)
196
+
197
+
198
+
199
+ df4=pd.DataFrame(rcd4)
200
+
201
+
202
+
203
+ rcd5={'日付' : [], '稼働時間(分)': [], '無人稼働時間(分)': [], '停止時間(分)': [],'トータル時間(分)': [],'稼働率(%)': []}
204
+
205
+
206
+
207
+ for file5 in file_list5:
208
+
209
+ a5=pd.read_csv(file5)
210
+
211
+ d5=(file5[25:33])
212
+
213
+ x5=a5.iloc[:,0].count()
214
+
215
+ y5=a5.iloc[:,1].sum()
216
+
217
+ z5=a5.iloc[:,2].sum()
218
+
219
+ u5=x5-y5-z5
220
+
221
+ w5=round(y2/x2*100,1)
222
+
223
+ rcd5['日付'].append(d5)
224
+
225
+ rcd5['稼働時間(分)'].append(y5)
226
+
227
+ rcd5['無人稼働時間(分)'].append(z5)
228
+
229
+ rcd5['停止時間(分)'].append(u5)
230
+
231
+ rcd5['トータル時間(分)'].append(x5)
232
+
233
+ rcd5['稼働率(%)'].append(w5)
234
+
235
+ df5=pd.DataFrame(rcd5)
236
+
237
+
238
+
239
+ rcd6={'日付' : [], '稼働時間(分)': [], '無人稼働時間(分)': [], '停止時間(分)': [],'トータル時間(分)': [],'稼働率(%)': []}
240
+
241
+
242
+
243
+ for file6 in file_list6:
244
+
245
+ a6=pd.read_csv(file6)
246
+
247
+ d6=(file6[25:33])
248
+
249
+ x6=a6.iloc[:,0].count()
250
+
251
+ y6=a6.iloc[:,1].sum()
252
+
253
+ z6=a6.iloc[:,2].sum()
254
+
255
+ u6=x6-y6-z6
256
+
257
+ w6=round(y2/x2*100,1)
258
+
259
+ rcd6['日付'].append(d6)
260
+
261
+ rcd6['稼働時間(分)'].append(y6)
262
+
263
+ rcd6['無人稼働時間(分)'].append(z6)
264
+
265
+ rcd6['停止時間(分)'].append(u6)
266
+
267
+ rcd6['トータル時間(分)'].append(x6)
268
+
269
+ rcd6['稼働率(%)'].append(w6)
270
+
271
+
272
+
273
+ df6=pd.DataFrame(rcd6)
274
+
275
+
276
+
277
+ rcd7={'日付' : [], '稼働時間(分)': [], '無人稼働時間(分)': [], '停止時間(分)': [],'トータル時間(分)': [],'稼働率(%)': []}
278
+
279
+
280
+
281
+ for file7 in file_list7:
282
+
283
+ a7=pd.read_csv(file7)
284
+
285
+ d7=(file7[25:33])
286
+
287
+ x7=a7.iloc[:,0].count()
288
+
289
+ y7=a7.iloc[:,1].sum()
290
+
291
+ z7=a7.iloc[:,2].sum()
292
+
293
+ u7=x7-y7-z7
294
+
295
+ w7=round(y2/x2*100,1)
296
+
297
+ rcd7['日付'].append(d7)
298
+
299
+ rcd7['稼働時間(分)'].append(y7)
300
+
301
+ rcd7['無人稼働時間(分)'].append(z7)
302
+
303
+ rcd7['停止時間(分)'].append(u7)
304
+
305
+ rcd7['トータル時間(分)'].append(x7)
306
+
307
+ rcd7['稼働率(%)'].append(w7)
308
+
309
+
310
+
311
+ df7=pd.DataFrame(rcd7)
312
+
313
+
314
+
121
- try:
315
+ try:
122
-
316
+
123
- df_m = pd.read_excel(monthly_file,dtype={'日付': str})
317
+ df_m1 = pd.read_excel(monthly_file,sheet_name=0,dtype={'日付': str})
124
-
318
+
125
- df_output1 = pd.merge(df_m, df1,how='outer')
319
+ df_output1 = pd.merge(df_m1, df1,how='outer')
126
-
127
- df_output2 = pd.merge(df_m, df2,how='outer')
128
320
 
129
321
  except FileNotFoundError:
130
322
 
@@ -132,15 +324,91 @@
132
324
 
133
325
  df_output1['コメント'] = None
134
326
 
327
+
328
+
329
+ try:
330
+
331
+ df_m2 = pd.read_excel(monthly_file,sheet_name=1,dtype={'日付': str})
332
+
333
+ df_output2 = pd.merge(df_m2, df2,how='outer')
334
+
335
+ except FileNotFoundError:
336
+
135
337
  df_output2 = df2.copy()
136
338
 
137
339
  df_output2['コメント'] = None
138
340
 
341
+
342
+
139
-
343
+ try:
140
-
344
+
141
- #df_output1.to_excel('//192.168.3.225/Share\石岡工場/INV推進室\機械導入PJ/IOT/'+monthly_file1,sheet_name='D31',index=False)
345
+ df_m3 = pd.read_excel(monthly_file,sheet_name=2,dtype={'日付': str})
346
+
142
-
347
+ df_output3 = pd.merge(df_m3, df3,how='outer')
348
+
349
+ except FileNotFoundError:
350
+
351
+ df_output3 = df3.copy()
352
+
353
+ df_output3['コメント'] = None
354
+
355
+
356
+
357
+ try:
358
+
143
- #df_output2.to_excel('//192.168.3.225/Share\石岡工場/INV推進室\機械導入PJ/IOT/'+monthly_file1,sheet_name='D32',index=False)
359
+ df_m4 = pd.read_excel(monthly_file,sheet_name=3,dtype={'日付': str})
360
+
361
+ df_output4 = pd.merge(df_m4, df4,how='outer')
362
+
363
+ except FileNotFoundError:
364
+
365
+ df_output4 = df4.copy()
366
+
367
+ df_output4['コメント'] = None
368
+
369
+
370
+
371
+ try:
372
+
373
+ df_m5 = pd.read_excel(monthly_file,sheet_name=4,dtype={'日付': str})
374
+
375
+ df_output5 = pd.merge(df_m5, df5,how='outer')
376
+
377
+ except FileNotFoundError:
378
+
379
+ df_output5 = df5.copy()
380
+
381
+ df_output5['コメント'] = None
382
+
383
+
384
+
385
+ try:
386
+
387
+ df_m6 = pd.read_excel(monthly_file,sheet_name=5,dtype={'日付': str})
388
+
389
+ df_output6 = pd.merge(df_m6, df6,how='outer')
390
+
391
+ except FileNotFoundError:
392
+
393
+ df_output6 = df6.copy()
394
+
395
+ df_output6['コメント'] = None
396
+
397
+
398
+
399
+ try:
400
+
401
+ df_m7 = pd.read_excel(monthly_file,sheet_name=6,dtype={'日付': str})
402
+
403
+ df_output7 = pd.merge(df_m7, df7,how='outer')
404
+
405
+ except FileNotFoundError:
406
+
407
+ df_output7 = df7.copy()
408
+
409
+ df_output7['コメント'] = None
410
+
411
+
144
412
 
145
413
 
146
414
 
@@ -150,4 +418,14 @@
150
418
 
151
419
  df_output2.to_excel(writer,sheet_name='D32',index=False)
152
420
 
421
+ df_output3.to_excel(writer,sheet_name='D33',index=False)
422
+
423
+ df_output4.to_excel(writer,sheet_name='D34',index=False)
424
+
425
+ df_output5.to_excel(writer,sheet_name='D35',index=False)
426
+
427
+ df_output6.to_excel(writer,sheet_name='D36',index=False)
428
+
429
+ df_output7.to_excel(writer,sheet_name='D37',index=False)
430
+
153
431
  ```