forked from yuweichiu/spc_analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspc_data_generator.py
344 lines (273 loc) · 10.3 KB
/
spc_data_generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
# -*- coding: utf-8 -*-
# """
# Created on 2020/12/19 下午 01:26
# @author: Ivan Y.W.Chiu
# """
import pandas as pd
import numpy as np
import os, sys, time, random
from datetime import datetime
# %%
class SPCDataConfig:
def __init__(self, start_date_str, end_date_str, stage_id, ctype, cnt, data_order, sl, cl, target):
self.start_date_str = start_date_str
self.end_date_str = end_date_str
self.stage_id = stage_id
self.ctype = ctype
self.cnt = cnt
self.data_order = data_order
self.sl = sl
self.cl = cl
self.target = target
self.dt_fmt = '%Y/%m/%d %H:%M:%S.%f'
self.start_date_dt = datetime.strptime(self.start_date_str, self.dt_fmt)
self.end_date_dt = datetime.strptime(self.end_date_str, self.dt_fmt)
self.start_date_num = int(self.start_date_dt.timestamp())
self.end_date_num = int(self.end_date_dt.timestamp())
self.lookup_tb = pd.read_csv("param\stage_layer_table.csv")
class DataTimeGenerator:
def __init__(self, cfg):
self.cfg = cfg
def gen(self):
time_series_num = np.random.randint(self.cfg.start_date_num, self.cfg.end_date_num, self.cfg.cnt)
time_series_num = np.sort(time_series_num)
time_series = [datetime.fromtimestamp(x) for x in time_series_num]
return time_series
class RawDataGenerator:
def __init__(self, cfg):
self.cfg = cfg
def gen(self):
values = np.random.randn(self.cfg.cnt) * self.cfg.data_order
if self.cfg.ctype == 'RANGE':
values = np.abs(values)
return values
class SpecGenerator:
def __init__(self, cfg):
self.cfg = cfg
def gen(self):
SPEC = self.cfg.sl
USL = np.ones(self.cfg.cnt) * SPEC
if self.cfg.ctype == 'RANGE':
LSL = np.zeros(self.cfg.cnt)
else:
LSL = np.ones(self.cfg.cnt) * -SPEC
return USL, LSL
class ControlLimitGenerator:
def __init__(self, cfg):
self.cfg = cfg
def gen(self):
CL = self.cfg.cl
UCL = np.ones(self.cfg.cnt) * CL
if self.cfg.ctype == 'RANGE':
LCL = np.zeros(self.cfg.cnt)
else:
LCL = np.ones(self.cfg.cnt) * -CL
return UCL, LCL
class TargetGenerator:
def __init__(self, cfg):
self.cfg = cfg
def gen(self):
TARGET = np.ones(self.cfg.cnt) * self.cfg.target
return TARGET
class LotIdGenerator:
def __init__(self, cfg):
self.cfg = cfg
def gen(self):
LETTER = ['W', 'X', 'Y', 'Z']
lotid = ['A21{0:s}{0:s}{1:03d}'.format(LETTER[random.randint(0, 3)], random.randint(1, 999)) for i in range(self.cfg.cnt)]
itemid = ['{0:02d}'.format(random.randint(1, 25)) for i in range(self.cfg.cnt)]
lot_info = pd.DataFrame({
'Lot': lotid, 'Item2': itemid
}, columns=['Lot', 'Item2'])
lot_info["Lot_ID"] = lot_info['Lot']
lot_info["Item_ID"] = lot_info['Lot'].str.cat(lot_info['Item2'].values, sep='.')
return lot_info
class SEqpIdGenerator:
def __init__(self, cfg):
self.cfg = cfg
def gen(self):
LETTER = ['X', 'Y', 'Z']
SERIAL = ['001', '003', '005']
eqpid = ['{0:s}SE{1:s}'.format(LETTER[random.randint(0, 2)], SERIAL[random.randint(0, 2)]) for i in range(self.cfg.cnt)]
return eqpid
class CEqpIdGenerator:
def __init__(self, cfg):
self.cfg = cfg
def gen(self):
LETTER = ['Y', 'Z']
SERIAL = ['B', 'C']
eqpid = ['{0:s}CO{1:s}'.format(LETTER[random.randint(0, 1)], SERIAL[random.randint(0, 1)]) for i in range(self.cfg.cnt)]
return eqpid
class MEqpIdGenerator:
def __init__(self, cfg):
self.cfg = cfg
def gen(self):
LETTER = ['W', 'X']
SERIAL = ['20', '33']
eqpid = ['{0:s}CD{1:s}'.format(LETTER[random.randint(0, 1)], SERIAL[random.randint(0, 1)]) for i in range(self.cfg.cnt)]
return eqpid
class StageIdGenerator:
def __init__(self, cfg):
self.cfg = cfg
def gen(self):
stg_id = self.cfg.stage_id
stage_id_list = [stg_id for i in range(self.cfg.cnt)]
return stage_id_list
class LayerIdGenerator:
def __init__(self, cfg):
self.cfg = cfg
self.lookup_tb = self.cfg.lookup_tb
def gen(self):
layer_id = self.lookup_tb[self.lookup_tb['Stage_ID'] == self.cfg.stage_id]['Layer_ID'].tolist()[0]
EDITION = ['1', '2', '3']
layer_id_list = ['{0:s}-{1:s}'.format(layer_id, EDITION[random.randint(0, 2)]) for i in range(self.cfg.cnt)]
return layer_id_list
class MaterialGenerator:
def __init__(self, cfg):
self.cfg = cfg
self.lookup_tb = self.cfg.lookup_tb
def gen(self):
material_id = self.lookup_tb[self.lookup_tb['Stage_ID'] == self.cfg.stage_id]['Material_ID'].tolist()[0]
material_id_list = [material_id for i in range(self.cfg.cnt)]
return material_id_list
class ProdGroupGenerator:
def __init__(self, cfg):
self.cfg = cfg
def gen(self):
PROD = ['A', 'B', 'C', 'D']
prod_id_list = ['Prod{0:s}'.format(PROD[random.randint(0, 3)]) for i in range(self.cfg.cnt)]
return prod_id_list
class EqpSUnit1Generator:
def __init__(self, cfg) -> None:
self.cfg = cfg
def gen(self):
SU1_ID = ['01', '02', '03', '04']
sunit1_list = ['s#U1-{0:s}'.format(SU1_ID[random.randint(0, 3)]) for i in range(self.cfg.cnt)]
return sunit1_list
class EqpSUnit2Generator:
def __init__(self, cfg) -> None:
self.cfg = cfg
def gen(self):
SU2_ID = ['01', '02', '03', '04']
sunit2_list = ['s#U2-{0:s}'.format(SU2_ID[random.randint(0, 3)]) for i in range(self.cfg.cnt)]
return sunit2_list
class EqpSRecipeGenerator:
def __init__(self, cfg) -> None:
self.cfg = cfg
self.lookup_tb = self.cfg.lookup_tb
def gen(self):
layer_id = self.lookup_tb[self.lookup_tb['Stage_ID'] == self.cfg.stage_id]['Layer_ID'].tolist()[0]
RCP_EDITION = ['H', 'I', 'J']
s_recipe_list = ['SRCP-{0:s}-{1:s}'.format(layer_id, RCP_EDITION[random.randint(0, 2)]) for i in range(self.cfg.cnt)]
return s_recipe_list
class EqpSSubRecipeGenerator:
def __init__(self, cfg) -> None:
self.cfg = cfg
self.lookup_tb = self.cfg.lookup_tb
def gen(self):
layer_id = self.lookup_tb[self.lookup_tb['Stage_ID'] == self.cfg.stage_id]['Layer_ID'].tolist()[0]
RCP_EDITION = ['001', '002']
switch_position = random.randint(int(self.cfg.cnt*0.8), int(self.cfg.cnt))
s_sub_recipe_list = []
for i in range(self.cfg.cnt):
if i < switch_position:
s_sub_recipe_list.append('SRCPSUB-{0:s}-{1:s}'.format(layer_id, RCP_EDITION[0]))
else:
s_sub_recipe_list.append('SRCPSUB-{0:s}-{1:s}'.format(layer_id, RCP_EDITION[1]))
return s_sub_recipe_list
# class STimeCostGenerator:
# def __init__(self, cfg) -> None:
# self.cfg = cfg
# def gen(self):
# np.random.randn(self.cfg.cnt)
class EqpMRecipeGenerator:
def __init__(self, cfg) -> None:
self.cfg = cfg
self.lookup_tb = self.cfg.lookup_tb
def gen(self):
layer_id = self.lookup_tb[self.lookup_tb['Stage_ID'] == self.cfg.stage_id]['Layer_ID'].tolist()[0]
RCP_EDITION = ['.003', '.004', '.005']
s_recipe_list = ['MRCP-{0:s}-{1:s}'.format(layer_id, RCP_EDITION[random.randint(0, 2)]) for i in range(self.cfg.cnt)]
return s_recipe_list
class SPCDataGenerator:
def __init__(self, cfg):
self.cfg = cfg
def gen(self):
TS = DataTimeGenerator(self.cfg)
RD = RawDataGenerator(self.cfg)
SL = SpecGenerator(self.cfg)
CL = ControlLimitGenerator(self.cfg)
TG = TargetGenerator(self.cfg)
LI = LotIdGenerator(self.cfg)
SEQP = SEqpIdGenerator(self.cfg)
CEQP = CEqpIdGenerator(self.cfg)
MEQP = MEqpIdGenerator(self.cfg)
STAGE = StageIdGenerator(self.cfg)
LAYER = LayerIdGenerator(self.cfg)
MATERIAL = MaterialGenerator(self.cfg)
PROD = ProdGroupGenerator(self.cfg)
SU1 = EqpSUnit1Generator(self.cfg)
SU2 = EqpSUnit2Generator(self.cfg)
SEQPRCP = EqpSRecipeGenerator(self.cfg)
SEQPSUBRCP = EqpSSubRecipeGenerator(self.cfg)
MEQPRCP = EqpMRecipeGenerator(self.cfg)
# TODO:
# s_param
time_series = TS.gen()
values = RD.gen()
USL, LSL = SL.gen()
UCL, LCL = CL.gen()
target = TG.gen()
lot_info = LI.gen()
seqp = SEQP.gen()
ceqp = CEQP.gen()
meqp = MEQP.gen()
stg = STAGE.gen()
layer = LAYER.gen()
material = MATERIAL.gen()
prod = PROD.gen()
su1 = SU1.gen()
su2 = SU2.gen()
seqprcp = SEQPRCP.gen()
seqpsubrcp = SEQPSUBRCP.gen()
meqprcp = MEQPRCP.gen()
self.df = pd.DataFrame({
'Data_Time': time_series,
'Lot_ID': lot_info['Lot_ID'].values,
'Item_ID': lot_info['Item_ID'].values,
'Value': values,
'Target': target,
'USL': USL,
'UCL': UCL,
'LCL': LCL,
'LSL': LSL,
'Stage_ID': stg,
'Layer_ID': layer,
'Prod_ID': prod,
'Eqp_S': seqp,
'Eqp_S_Unit1': su1,
'Eqp_S_Unit2': su2,
'S_Recipe': seqprcp,
'S_SubRecipe': seqpsubrcp,
'Eqp_C': ceqp,
'Material_ID': material,
'Eqp_M': meqp,
'M_Recipe': meqprcp,
})
self.df = self.df[[
'Data_Time', 'Lot_ID', 'Item_ID', 'Value',
'Target', 'USL', 'UCL', 'LCL', 'LSL',
'Stage_ID', 'Layer_ID', 'Prod_ID', 'Eqp_S', 'Eqp_S_Unit1', 'Eqp_S_Unit2',
'S_Recipe', 'S_SubRecipe',
'Eqp_C', 'Material_ID', 'Eqp_M', 'M_Recipe']]
self.df['Chart_Type'] = self.cfg.ctype
return self.df
def main():
cfg = SPCDataConfig(
'2020/11/17 00:00:00.0', '2020/12/18 00:00:00.0',
stage_id='stageE11', ctype='MEAN', cnt=300, data_order=0.1, sl=0.3, cl=0.2, target=0)
SPC = SPCDataGenerator(cfg)
SPC.gen()
return SPC.df
if __name__ == '__main__':
spc_df = main()