回答編集履歴
1
プログラム内容
answer
CHANGED
@@ -2,20 +2,30 @@
|
|
2
2
|
import pandas as pd
|
3
3
|
from openpyxl import Workbook
|
4
4
|
import glob
|
5
|
+
import datetime
|
5
6
|
|
6
|
-
|
7
|
+
today = datetime.date.today()
|
8
|
+
year = today.year
|
7
|
-
|
9
|
+
month = today.month
|
8
|
-
file_list2=glob.glob('//192.168.3.140/pi/mydata'+t+'*')
|
9
|
-
file_list3=glob.glob('//192.168.3.139/pi/mydata'+t+'*')
|
10
|
-
file_list4=glob.glob('//192.168.3.135/pi/mydata'+t+'*')
|
11
|
-
file_list5=glob.glob('//192.168.3.132/pi/mydata'+t+'*')
|
12
|
-
file_list6=glob.glob('//192.168.3.131/pi/mydata'+t+'*')
|
13
|
-
file_list7=glob.glob('//192.168.3.134/pi/mydata'+t+'*')
|
14
10
|
|
11
|
+
input_value= input("{}年{:02}月分の集計を行います。Enterを押してください。 (別の月を集計する場合は6桁で年月を入力し、Enterを押してください) > ".format(year, month))
|
12
|
+
if not input_value:
|
13
|
+
input_value = "{}{:02}".format(year, month)
|
14
|
+
|
15
|
+
file_list1=glob.glob('//192.168.3.141/pi/mydata'+input_value+'*')
|
16
|
+
file_list2=glob.glob('//192.168.3.140/pi/mydata'+input_value+'*')
|
17
|
+
file_list3=glob.glob('//192.168.3.139/pi/mydata'+input_value+'*')
|
18
|
+
file_list4=glob.glob('//192.168.3.135/pi/mydata'+input_value+'*')
|
19
|
+
file_list5=glob.glob('//192.168.3.132/pi/mydata'+input_value+'*')
|
20
|
+
file_list6=glob.glob('//192.168.3.131/pi/mydata'+input_value+'*')
|
21
|
+
file_list7=glob.glob('//192.168.3.134/pi/mydata'+input_value+'*')
|
22
|
+
|
23
|
+
g='三課伸線稼働率(全機械)'
|
24
|
+
monthly_file =g+ f'{input_value}.xlsx'
|
25
|
+
|
15
26
|
rcd1={'日付' : [], '稼働時間(分)': [], '無人稼働時間(分)': [], '停止時間(分)': [],'トータル時間(分)': [],'稼働率(%)': []}
|
16
27
|
|
17
28
|
for file1 in file_list1:
|
18
|
-
|
19
29
|
a1=pd.read_csv(file1)
|
20
30
|
d1=(file1[25:33])
|
21
31
|
x1=a1.iloc[:,0].count()
|
@@ -29,18 +39,12 @@
|
|
29
39
|
rcd1['停止時間(分)'].append(u1)
|
30
40
|
rcd1['トータル時間(分)'].append(x1)
|
31
41
|
rcd1['稼働率(%)'].append(w1)
|
32
|
-
|
42
|
+
|
33
43
|
df1=pd.DataFrame(rcd1)
|
34
|
-
print(df1)
|
35
|
-
g1='全機稼働率'
|
36
44
|
|
37
|
-
monthly_file =g1+ f'{t}.xlsx'
|
38
|
-
|
39
|
-
|
40
45
|
rcd2={'日付' : [], '稼働時間(分)': [], '無人稼働時間(分)': [], '停止時間(分)': [],'トータル時間(分)': [],'稼働率(%)': []}
|
41
|
-
|
46
|
+
|
42
47
|
for file2 in file_list2:
|
43
|
-
|
44
48
|
a2=pd.read_csv(file2)
|
45
49
|
d2=(file2[25:33])
|
46
50
|
x2=a2.iloc[:,0].count()
|
@@ -56,22 +60,157 @@
|
|
56
60
|
rcd2['稼働率(%)'].append(w2)
|
57
61
|
|
58
62
|
df2=pd.DataFrame(rcd2)
|
59
|
-
print(df2)
|
60
63
|
|
64
|
+
rcd3={'日付' : [], '稼働時間(分)': [], '無人稼働時間(分)': [], '停止時間(分)': [],'トータル時間(分)': [],'稼働率(%)': []}
|
65
|
+
|
66
|
+
for file3 in file_list3:
|
67
|
+
a3=pd.read_csv(file3)
|
68
|
+
d3=(file2[25:33])
|
69
|
+
x3=a3.iloc[:,0].count()
|
70
|
+
y3=a3.iloc[:,1].sum()
|
71
|
+
z3=a3.iloc[:,2].sum()
|
72
|
+
u3=x3-y3-z3
|
73
|
+
w3=round(y2/x2*100,1)
|
74
|
+
rcd3['日付'].append(d3)
|
75
|
+
rcd3['稼働時間(分)'].append(y3)
|
76
|
+
rcd3['無人稼働時間(分)'].append(z3)
|
77
|
+
rcd3['停止時間(分)'].append(u3)
|
78
|
+
rcd3['トータル時間(分)'].append(x3)
|
79
|
+
rcd3['稼働率(%)'].append(w3)
|
80
|
+
|
81
|
+
df3=pd.DataFrame(rcd3)
|
82
|
+
|
83
|
+
rcd4={'日付' : [], '稼働時間(分)': [], '無人稼働時間(分)': [], '停止時間(分)': [],'トータル時間(分)': [],'稼働率(%)': []}
|
84
|
+
|
85
|
+
for file4 in file_list4:
|
86
|
+
a4=pd.read_csv(file4)
|
87
|
+
d4=(file4[25:33])
|
88
|
+
x4=a4.iloc[:,0].count()
|
89
|
+
y4=a4.iloc[:,1].sum()
|
90
|
+
z4=a4.iloc[:,2].sum()
|
91
|
+
u4=x4-y4-z4
|
92
|
+
w4=round(y2/x2*100,1)
|
93
|
+
rcd4['日付'].append(d4)
|
94
|
+
rcd4['稼働時間(分)'].append(y4)
|
95
|
+
rcd4['無人稼働時間(分)'].append(z4)
|
96
|
+
rcd4['停止時間(分)'].append(u4)
|
97
|
+
rcd4['トータル時間(分)'].append(x4)
|
98
|
+
rcd4['稼働率(%)'].append(w4)
|
99
|
+
|
100
|
+
df4=pd.DataFrame(rcd4)
|
101
|
+
|
102
|
+
rcd5={'日付' : [], '稼働時間(分)': [], '無人稼働時間(分)': [], '停止時間(分)': [],'トータル時間(分)': [],'稼働率(%)': []}
|
103
|
+
|
104
|
+
for file5 in file_list5:
|
105
|
+
a5=pd.read_csv(file5)
|
106
|
+
d5=(file5[25:33])
|
107
|
+
x5=a5.iloc[:,0].count()
|
108
|
+
y5=a5.iloc[:,1].sum()
|
109
|
+
z5=a5.iloc[:,2].sum()
|
110
|
+
u5=x5-y5-z5
|
111
|
+
w5=round(y2/x2*100,1)
|
112
|
+
rcd5['日付'].append(d5)
|
113
|
+
rcd5['稼働時間(分)'].append(y5)
|
114
|
+
rcd5['無人稼働時間(分)'].append(z5)
|
115
|
+
rcd5['停止時間(分)'].append(u5)
|
116
|
+
rcd5['トータル時間(分)'].append(x5)
|
117
|
+
rcd5['稼働率(%)'].append(w5)
|
118
|
+
df5=pd.DataFrame(rcd5)
|
119
|
+
|
120
|
+
rcd6={'日付' : [], '稼働時間(分)': [], '無人稼働時間(分)': [], '停止時間(分)': [],'トータル時間(分)': [],'稼働率(%)': []}
|
121
|
+
|
122
|
+
for file6 in file_list6:
|
123
|
+
a6=pd.read_csv(file6)
|
124
|
+
d6=(file6[25:33])
|
125
|
+
x6=a6.iloc[:,0].count()
|
126
|
+
y6=a6.iloc[:,1].sum()
|
127
|
+
z6=a6.iloc[:,2].sum()
|
128
|
+
u6=x6-y6-z6
|
129
|
+
w6=round(y2/x2*100,1)
|
130
|
+
rcd6['日付'].append(d6)
|
131
|
+
rcd6['稼働時間(分)'].append(y6)
|
132
|
+
rcd6['無人稼働時間(分)'].append(z6)
|
133
|
+
rcd6['停止時間(分)'].append(u6)
|
134
|
+
rcd6['トータル時間(分)'].append(x6)
|
135
|
+
rcd6['稼働率(%)'].append(w6)
|
136
|
+
|
137
|
+
df6=pd.DataFrame(rcd6)
|
138
|
+
|
139
|
+
rcd7={'日付' : [], '稼働時間(分)': [], '無人稼働時間(分)': [], '停止時間(分)': [],'トータル時間(分)': [],'稼働率(%)': []}
|
140
|
+
|
141
|
+
for file7 in file_list7:
|
142
|
+
a7=pd.read_csv(file7)
|
143
|
+
d7=(file7[25:33])
|
144
|
+
x7=a7.iloc[:,0].count()
|
145
|
+
y7=a7.iloc[:,1].sum()
|
146
|
+
z7=a7.iloc[:,2].sum()
|
147
|
+
u7=x7-y7-z7
|
148
|
+
w7=round(y2/x2*100,1)
|
149
|
+
rcd7['日付'].append(d7)
|
150
|
+
rcd7['稼働時間(分)'].append(y7)
|
151
|
+
rcd7['無人稼働時間(分)'].append(z7)
|
152
|
+
rcd7['停止時間(分)'].append(u7)
|
153
|
+
rcd7['トータル時間(分)'].append(x7)
|
154
|
+
rcd7['稼働率(%)'].append(w7)
|
155
|
+
|
156
|
+
df7=pd.DataFrame(rcd7)
|
157
|
+
|
61
158
|
try:
|
62
|
-
|
159
|
+
df_m1 = pd.read_excel(monthly_file,sheet_name=0,dtype={'日付': str})
|
63
|
-
df_output1 = pd.merge(
|
160
|
+
df_output1 = pd.merge(df_m1, df1,how='outer')
|
64
|
-
df_output2 = pd.merge(df_m, df2,how='outer')
|
65
161
|
except FileNotFoundError:
|
66
162
|
df_output1 = df1.copy()
|
67
163
|
df_output1['コメント'] = None
|
164
|
+
|
165
|
+
try:
|
166
|
+
df_m2 = pd.read_excel(monthly_file,sheet_name=1,dtype={'日付': str})
|
167
|
+
df_output2 = pd.merge(df_m2, df2,how='outer')
|
168
|
+
except FileNotFoundError:
|
68
169
|
df_output2 = df2.copy()
|
69
170
|
df_output2['コメント'] = None
|
171
|
+
|
172
|
+
try:
|
173
|
+
df_m3 = pd.read_excel(monthly_file,sheet_name=2,dtype={'日付': str})
|
174
|
+
df_output3 = pd.merge(df_m3, df3,how='outer')
|
175
|
+
except FileNotFoundError:
|
176
|
+
df_output3 = df3.copy()
|
177
|
+
df_output3['コメント'] = None
|
70
178
|
|
179
|
+
try:
|
71
|
-
|
180
|
+
df_m4 = pd.read_excel(monthly_file,sheet_name=3,dtype={'日付': str})
|
72
|
-
|
181
|
+
df_output4 = pd.merge(df_m4, df4,how='outer')
|
182
|
+
except FileNotFoundError:
|
183
|
+
df_output4 = df4.copy()
|
184
|
+
df_output4['コメント'] = None
|
73
185
|
|
186
|
+
try:
|
187
|
+
df_m5 = pd.read_excel(monthly_file,sheet_name=4,dtype={'日付': str})
|
188
|
+
df_output5 = pd.merge(df_m5, df5,how='outer')
|
189
|
+
except FileNotFoundError:
|
190
|
+
df_output5 = df5.copy()
|
191
|
+
df_output5['コメント'] = None
|
192
|
+
|
193
|
+
try:
|
194
|
+
df_m6 = pd.read_excel(monthly_file,sheet_name=5,dtype={'日付': str})
|
195
|
+
df_output6 = pd.merge(df_m6, df6,how='outer')
|
196
|
+
except FileNotFoundError:
|
197
|
+
df_output6 = df6.copy()
|
198
|
+
df_output6['コメント'] = None
|
199
|
+
|
200
|
+
try:
|
201
|
+
df_m7 = pd.read_excel(monthly_file,sheet_name=6,dtype={'日付': str})
|
202
|
+
df_output7 = pd.merge(df_m7, df7,how='outer')
|
203
|
+
except FileNotFoundError:
|
204
|
+
df_output7 = df7.copy()
|
205
|
+
df_output7['コメント'] = None
|
206
|
+
|
207
|
+
|
74
208
|
with pd.ExcelWriter('//192.168.3.225/Share\石岡工場/INV推進室\機械導入PJ/IOT/'+monthly_file) as writer:
|
75
209
|
df_output1.to_excel(writer,sheet_name='D31',index=False)
|
76
210
|
df_output2.to_excel(writer,sheet_name='D32',index=False)
|
211
|
+
df_output3.to_excel(writer,sheet_name='D33',index=False)
|
212
|
+
df_output4.to_excel(writer,sheet_name='D34',index=False)
|
213
|
+
df_output5.to_excel(writer,sheet_name='D35',index=False)
|
214
|
+
df_output6.to_excel(writer,sheet_name='D36',index=False)
|
215
|
+
df_output7.to_excel(writer,sheet_name='D37',index=False)
|
77
216
|
```
|