예제 #1
0
    def wavyfin(self):
        product_master_data = []
        master_dict = {}

        product_name = 'wavyfin_part'
        product_code = 'wavyfin'  # PK
        product_class = 'N03'
        product_num = 'PART2'

        product_target_l = 'wavyfin_l_100'
        product_target_w = 'wavyfin_w_50'
        product_target_h = 'wavyfin_h_60'

        master_dict['product_name'] = product_name
        master_dict['product_code'] = product_code  # PK
        master_dict['product_class'] = product_class
        master_dict['product_num'] = product_num

        master_dict['product_target_l'] = product_target_l
        master_dict['product_target_w'] = product_target_w
        master_dict['product_target_h'] = product_target_h

        product_master_data.append(master_dict)
        MySQL_query.insert_product_master(product_master_data)
        return master_dict
예제 #2
0
    def body(self):
        product_master_data = []
        master_dict = {}

        product_name = 'body_part'
        product_code = 'body'  # PK
        product_class = 'N03'
        product_num = 'PART1'

        product_target_l = 'body_l_200'
        product_target_w = 'body_w_100'
        product_target_h = 'body_h_50'

        master_dict['product_name'] = product_name
        master_dict['product_code'] = product_code  # PK
        master_dict['product_class'] = product_class
        master_dict['product_num'] = product_num

        master_dict['product_target_l'] = product_target_l
        master_dict['product_target_w'] = product_target_w
        master_dict['product_target_h'] = product_target_h

        product_master_data.append(master_dict)
        MySQL_query.insert_product_master(product_master_data)
        return master_dict
def Pareto():

    count_list = []
    count_All_list = []
    All_list = []
    All_pareto_list = []
    OP10_NOK = MySQL_query.get_data_for_pareto('OP10')
    OP20_NOK = MySQL_query.get_data_for_pareto('OP20')
    OP30_NOK = MySQL_query.get_data_for_pareto('OP30')
    OP40_NOK = MySQL_query.get_data_for_pareto('OP40')
    OP50_NOK = MySQL_query.get_data_for_pareto('OP50')

    count_OP10 = OP10_NOK[0]['NOK']
    count_OP20 = OP20_NOK[0]['NOK']
    count_OP30 = OP30_NOK[0]['NOK']
    count_OP40 = OP40_NOK[0]['NOK']
    count_OP50 = OP50_NOK[0]['NOK']

    count_list.append(count_OP10)
    count_list.append(count_OP20)
    count_list.append(count_OP30)
    count_list.append(count_OP40)
    count_list.append(count_OP50)
    count_All_list.append(count_list)
    count_All_list.append(count_list)
    All_list.append(count_All_list)
    All_pareto_list.append(All_list)

    return jsonify(All_list)
예제 #4
0
    def op30_WIP(self):
        master_dict = {}
        product_master_data = []

        product_name = 'WIP30'
        product_code = 'op30_WIP'  # PK
        product_class = 'N02'
        product_num = 'WIP3'

        product_target_l = 'op30_l_200'
        product_target_w = 'op30_w_180'
        product_target_h = 'op30_h_60'

        master_dict['product_name'] = product_name
        master_dict['product_code'] = product_code  # PK
        master_dict['product_class'] = product_class
        master_dict['product_num'] = product_num

        master_dict['product_target_l'] = product_target_l
        master_dict['product_target_w'] = product_target_w
        master_dict['product_target_h'] = product_target_h

        product_master_data.append(master_dict)
        MySQL_query.insert_product_master(product_master_data)
        return master_dict
def Search():
    if not 'ID' in session:
        return ''' <script> location.href = "http://54.180.83.130:5000/" </script> '''
        # return ''' <script> location.href = "http://127.0.0.1:5000/" </script> '''
    else:
        key60 = 'P10001'
        product_key = MySQL_query.get_key_product_for_search(key60)
        product_key = product_key[0]['product_key']
        content_list = Search_data(product_key)

        if request.method == 'GET':

            key60 = request.args.get('key')
            if key60 == None:
                key60 = 'P10001'

            product_key = MySQL_query.get_key_product_for_search(key60)
            product_key = product_key[0]['product_key']
            content_list = Search_data(product_key)

            ## 넘겨받은 값을 원래 페이지로 리다이렉트
            html = render_template('Search.html',
                                   data_list=content_list,
                                   key=product_key)
            return html

        return render_template('Search.html',
                               data_list=content_list,
                               key=product_key)
예제 #6
0
    def flange2(self):
        product_master_data = []
        master_dict = {}

        product_name = 'flange2_part'
        product_code = 'flange2'  # PK
        product_class = 'N03'
        product_num = 'PART6'

        product_target_l = 'flange2_l_30'
        product_target_w = 'flange2_w_50'
        product_target_h = 'flange2_h_30'

        master_dict['product_name'] = product_name
        master_dict['product_code'] = product_code  # PK
        master_dict['product_class'] = product_class
        master_dict['product_num'] = product_num

        master_dict['product_target_l'] = product_target_l
        master_dict['product_target_w'] = product_target_w
        master_dict['product_target_h'] = product_target_h

        product_master_data.append(master_dict)
        MySQL_query.insert_product_master(product_master_data)
        return master_dict
def Quality_load():
    if request.method == 'GET':
        char1 = request.args.get('date1')
        char2 = request.args.get('date2')
        NOK_count_list = []
        OK_count_list = []
        OP10_NOK_list = MySQL_query.get_data_for_pareto_NOK(
            'OP10', char1, char2)
        OP20_NOK_list = MySQL_query.get_data_for_pareto_NOK(
            'OP20', char1, char2)
        OP30_NOK_list = MySQL_query.get_data_for_pareto_NOK(
            'OP30', char1, char2)
        OP40_NOK_list = MySQL_query.get_data_for_pareto_NOK(
            'OP40', char1, char2)
        OP50_NOK_list = MySQL_query.get_data_for_pareto_NOK(
            'OP50', char1, char2)

        NOK_OP10 = OP10_NOK_list[0]['NOK']
        NOK_OP20 = OP20_NOK_list[0]['NOK']
        NOK_OP30 = OP30_NOK_list[0]['NOK']
        NOK_OP40 = OP40_NOK_list[0]['NOK']
        NOK_OP50 = OP50_NOK_list[0]['NOK']

        OP10_OK_list = MySQL_query.get_data_for_pareto_OK('OP10', char1, char2)
        OP20_OK_list = MySQL_query.get_data_for_pareto_OK('OP20', char1, char2)
        OP30_OK_list = MySQL_query.get_data_for_pareto_OK('OP30', char1, char2)
        OP40_OK_list = MySQL_query.get_data_for_pareto_OK('OP40', char1, char2)
        OP50_OK_list = MySQL_query.get_data_for_pareto_OK('OP50', char1, char2)

        OK_OP10 = OP10_OK_list[0]['OK']
        OK_OP20 = OP20_OK_list[0]['OK']
        OK_OP30 = OP30_OK_list[0]['OK']
        OK_OP40 = OP40_OK_list[0]['OK']
        OK_OP50 = OP50_OK_list[0]['OK']

        NOK_count_list.append(NOK_OP10)
        NOK_count_list.append(NOK_OP20)
        NOK_count_list.append(NOK_OP30)
        NOK_count_list.append(NOK_OP40)
        NOK_count_list.append(NOK_OP50)

        OK_count_list.append(OK_OP10)
        OK_count_list.append(OK_OP20)
        OK_count_list.append(OK_OP30)
        OK_count_list.append(OK_OP40)
        OK_count_list.append(OK_OP50)

        html = render_template('Quality.html',
                               quality_OK_list=OK_count_list,
                               quality_NOK_list=NOK_count_list,
                               date1=char1,
                               date2=char2)

        return html
def Scatter_OP40():
    machine_code = 'OP40'

    size_L = 'l'
    size_H = 'h'
    size_W = 'w'
    data_All_list = []
    data_L_list = []
    data_H_list = []
    data_W_list = []
    list_L_dict = MySQL_query.get_data_for_scatter(machine_code, size_L)

    for i in range(len(list_L_dict)):
        temp_L_list = []

        x = list_L_dict[i]['machine_data']
        y = list_L_dict[i]['product_size']
        temp_L_list.append(x)
        temp_L_list.append(y)
        data_L_list.append(temp_L_list)

    list_H_dict = MySQL_query.get_data_for_scatter(machine_code, size_H)

    for i in range(len(list_H_dict)):
        temp_H_list = []

        x = list_H_dict[i]['machine_data']
        y = list_H_dict[i]['product_size']
        temp_H_list.append(x)
        temp_H_list.append(y)
        data_H_list.append(temp_H_list)

    list_W_dict = MySQL_query.get_data_for_scatter(machine_code, size_W)

    for i in range(len(list_W_dict)):
        temp_W_list = []

        x = list_W_dict[i]['machine_data']
        y = list_W_dict[i]['product_size']
        temp_W_list.append(x)
        temp_W_list.append(y)
        data_W_list.append(temp_W_list)
    data_All_list.append(data_L_list)
    data_All_list.append(data_H_list)
    data_All_list.append(data_W_list)
    data_All_list_list = []
    data_All_list_list.append(data_All_list)

    return jsonify(data_All_list_list)
    def progress_gauge(self):  # 게이지 값 리턴하는 함수
        data = MySQL_query.get_item_count_for_gauge()

        count_new_product = data[0]['item_count']

        get_gauge = (count_new_product / 8640) * 100

        return get_gauge
    def Productivity_Calculator(self):

        data = MySQL_query.get_item_count_for_productivity(1)

        total_productivity = (data[0]['total_item_count'] / 8640) * 100

        total_productivity = round(total_productivity, 1)

        return total_productivity
    def op50(self):
        machine_master_data = []
        master_dict = {}

        machine_code = 'OP50'  # 설비 코드명
        machine_class = 'MCO2'  # 용접 조립
        machine_process_time = 'exp10'
        machine_assembly = 'op40_flange2'
        machine_data_code = 'T01'

        master_dict['machine_code'] = machine_code  # PK
        master_dict['machine_class'] = machine_class
        master_dict['machine_process_time'] = machine_process_time
        master_dict['machine_assembly'] = machine_assembly
        master_dict['machine_data_code'] = machine_data_code

        machine_master_data.append(master_dict)
        MySQL_query.insert_machine_master(machine_master_data)
        return master_dict
    def op30(self):
        machine_master_data = []
        master_dict = {}

        machine_code = 'OP30'  # 설비 코드명
        machine_class = 'MCO1'  # 단순 조립
        machine_process_time = 'exp10'
        machine_assembly = 'op20_pipe2'
        machine_data_code = 'E01'

        master_dict['machine_code'] = machine_code  # PK
        master_dict['machine_class'] = machine_class
        master_dict['machine_process_time'] = machine_process_time
        master_dict['machine_assembly'] = machine_assembly
        master_dict['machine_data_code'] = machine_data_code

        machine_master_data.append(master_dict)
        MySQL_query.insert_machine_master(machine_master_data)
        return master_dict
    def op60(self):
        machine_master_data = []
        master_dict = {}

        machine_code = 'OP60'  # 설비 코드명
        machine_class = 'MCO3'  # 최종 검사
        machine_process_time = 'exp10'
        machine_assembly = 'final_test'
        machine_data_code = 'TEST'

        master_dict['machine_code'] = machine_code  # PK
        master_dict['machine_class'] = machine_class
        master_dict['machine_process_time'] = machine_process_time
        master_dict['machine_assembly'] = machine_assembly
        master_dict['machine_data_code'] = machine_data_code

        machine_master_data.append(master_dict)

        MySQL_query.insert_machine_master(machine_master_data)
        return master_dict
def real_value():
    now_data = MySQL_query.get_count_for_progress(1)  # 실제값 하루 생산되는 양품수
    OK_count = now_data[0]['product_count']
    quality = round(OK_count, 1)
    data = [(time.time() + 32400) * 1000, quality]

    response = make_response(json.dumps(data))

    response.content_type = 'application/json'

    return response
예제 #15
0
    def EGRC(self):  # EGR Cooler 제품
        master_dict = {}
        product_master_data = []
        product_name = 'EGR_Cooler'
        product_code = 'EGRC'  # PK
        product_class = 'N01'
        product_num = 'P01'

        product_target_l = 'op60_l_260'
        product_target_w = 'op60_w_180'
        product_target_h = 'op60_h_60'

        master_dict['product_name'] = product_name
        master_dict['product_code'] = product_code  # PK
        master_dict['product_class'] = product_class
        master_dict['product_num'] = product_num
        master_dict['product_target_l'] = product_target_l
        master_dict['product_target_w'] = product_target_w
        master_dict['product_target_h'] = product_target_h

        product_master_data.append(master_dict)
        MySQL_query.insert_product_master(product_master_data)
        return master_dict
    def Quality_Calculator(self):

        data = MySQL_query.get_item_count_for_quality(1)

        OK_count = data[0]['item_count']

        NOK_count = data[1]['item_count']

        if OK_count < NOK_count:
            temp = OK_count
            OK_count = NOK_count
            NOK_count = temp

        quality = OK_count / (OK_count + NOK_count) * 100

        quality = round(quality, 1)

        return quality
    def op30(op20):
        op30_data = {}
        std = 0.0025

        product_key = op20[0]

        pipe2_l = np.random.normal(30, std)
        pipe2_l = round(pipe2_l, 5)

        pipe2_w = np.random.normal(50, std)
        pipe2_w = round(pipe2_w, 5)

        pipe2_h = np.random.normal(30, std)
        pipe2_h = round(pipe2_h, 5)

        op30_process_time = op20[4]

        op30_electricity = np.random.uniform(89.5, 100)
        op30_electricity = round(op30_electricity, 5)

        op30_data['pipe2_l'] = pipe2_l
        op30_data['pipe2_w'] = pipe2_w
        op30_data['pipe2_h'] = pipe2_h

        if op30_electricity < 90:
            op30_w = op20[2] + pipe2_w - op30_electricity * 0.11
            op30_w = round(op30_w, 5)
        else:
            op30_w = op20[2] + pipe2_w - 10
            op30_w = round(op30_w, 5)

        op30_l = op20[1]
        op30_data['op30_l'] = op20[1]

        op30_data['op30_w'] = op30_w
        op30_h = op20[3]
        op30_data['op30_h'] = op20[3]

        op30_data['op30_electricity'] = op30_electricity
        op30_data['op30_process_time'] = op30_process_time

        if (op30_l < 199.99) or (op30_l > 200.01):
            length_test = 1
        else:
            length_test = 0

        if (op30_w < 179.99) or (op30_w > 180.01):
            width_test = 1
        else:
            width_test = 0

        if (op30_h < 59.99) or (op30_h > 60.01):
            height_test = 1
        else:
            height_test = 0

        if length_test == 0 and width_test == 0 and height_test == 0:
            op30_test = 'OK'
            op30_data['op30_test'] = op30_test
        else:
            op30_test = 'NOK'
            op30_data['op30_test'] = op30_test

        # 부품 테스트
        if (pipe2_l < 29.99) or (pipe2_l > 30.01):
            length_test = 1
        else:
            length_test = 0

        if (pipe2_w < 49.99) or (pipe2_w > 50.01):
            width_test = 1
        else:
            width_test = 0

        if (pipe2_h < 29.99) or (pipe2_h > 30.01):
            height_test = 1
        else:
            height_test = 0

        if length_test == 0 and width_test == 0 and height_test == 0:
            pipe2_test = 'OK'
        else:
            pipe2_test = 'NOK'

        now = op20[5]
        time_stamp = now + timedelta(seconds=10)
        op30_data['op30_time_stamp'] = time_stamp
        time_stamp = str(time_stamp)

        product_key = time_stamp + product_key
        op30_data['product_key'] = product_key

        # product_history 적재
        product_history_data_list = []
        product_history_insert = {}
        op30_master_data = product_master.op30_WIP(1)
        product_code = op30_master_data['product_code']

        product_history_insert['product_key'] = product_key
        product_history_insert['product_code'] = product_code
        product_history_insert['product_timestamp'] = time_stamp

        product_history_data_list.append(product_history_insert)

        MySQL_query.insert_product_history(
            product_history_data_list)  # 히스토리 데이터 DB 적재

        # 부품 데이터 모아서 적재 (pipe2)
        part_data_list = []
        part_history_insert = {}
        part_history_insert['product_key'] = time_stamp + '-pipe2'
        part_history_insert['product_code'] = 'pipe2'
        part_history_insert['product_timestamp'] = time_stamp
        part_data_list.append(part_history_insert)

        MySQL_query.insert_product_history(part_data_list)  # 히스토리 데이터 DB 적재

        # product_quality 적재
        product_quality_data_list = []  # 딕셔너리 데이터 저장할 리스트
        product_quality_insert = {}  # DB 저장할 데이터 모아주는 딕셔너리

        product_quality_insert['product_key'] = product_key
        product_quality_insert['product_size_l'] = str(op30_l)
        product_quality_insert['product_size_w'] = str(op30_w)
        product_quality_insert['product_size_h'] = str(op30_h)
        product_quality_insert['product_test'] = str(op30_test)
        product_quality_insert['product_test_timestamp'] = str(time_stamp)

        product_quality_data_list.append(product_quality_insert)

        MySQL_query.insert_product_quality(
            product_quality_data_list)  # 품질 데이터 DB 적재

        # 부품 quality 적재 (pipe2)
        part_quality_data_list = []  # 딕셔너리 데이터 저장할 리스트
        part_quality_insert = {}  # DB 저장할 데이터 모아주는 딕셔너리

        part_quality_insert['product_key'] = time_stamp + '-pipe2'
        part_quality_insert['product_size_l'] = str(pipe2_l)
        part_quality_insert['product_size_w'] = str(pipe2_w)
        part_quality_insert['product_size_h'] = str(pipe2_h)
        part_quality_insert['product_test'] = str(pipe2_test)
        part_quality_insert['product_test_timestamp'] = str(time_stamp)

        part_quality_data_list.append(part_quality_insert)

        MySQL_query.insert_product_quality(
            part_quality_data_list)  # 품질 데이터 DB 적재

        # machine 적재
        machine_data_list = []  # 딕셔너리 데이터 저장할 리스트
        machine_data_insert = {}  # DB 저장할 데이터 모아주는 딕셔너리

        machine_master_data = machine_master.op30(1)  # machine_code 가져오기
        machine_code = machine_master_data['machine_code']

        machine_data_insert['machine_code'] = machine_code
        machine_data_insert['product_key'] = product_key
        machine_data_insert['start_time'] = str(now)
        machine_data_insert['end_time'] = str(time_stamp)
        machine_data_insert['makespan'] = '123'
        machine_data_insert['process_time'] = str(op30_process_time)
        machine_data_insert['machine_data'] = str(op30_electricity)
        machine_data_insert['machine_data_code'] = 'E01'

        machine_data_list.append(machine_data_insert)

        MySQL_query.insert_machine(machine_data_list)  # machine 데이터 DB 적재

        return op30_data
    def op10(body):
        op10_data = {}

        std = 0.0025  # 표준편차

        product_key = body[0]  # 값 리스트 받을 때 첫번째 요소

        wavyfin_l = np.random.normal(100, std)
        wavyfin_l = round(wavyfin_l, 5)

        wavyfin_w = np.random.normal(50, std)
        wavyfin_w = round(wavyfin_w, 5)

        wavyfin_h = np.random.normal(60, std)
        wavyfin_h = round(wavyfin_h, 5)

        op10_electricity = np.random.uniform(89.75, 100)  # 균일 분포 / (최소, 최대)
        op10_electricity = round(op10_electricity, 5)

        op10_data['body_l'] = body[1]
        op10_data['body_w'] = body[2]
        op10_data['body_h'] = body[3]

        op10_data['wavyfin_l'] = wavyfin_l
        op10_data['wavyfin_w'] = wavyfin_w
        op10_data['wavyfin_h'] = wavyfin_h

        op10_l = body[1]  # 값이 안바껴서 그대로 둠
        op10_data['op10_l'] = op10_l
        op10_w = body[2]
        op10_data['op10_w'] = op10_w
        op10_h = wavyfin_h
        op10_data['op10_h'] = op10_h

        op10_process_time = body[4]

        op10_data['op10_electricity'] = op10_electricity
        op10_data['op10_process_time'] = op10_process_time

        # 재공품 테스트
        if (op10_l < 199.99) or (op10_l > 200.01):
            length_test = 1
        else:
            length_test = 0

        if (op10_w < 99.99) or (op10_w > 100.01):
            width_test = 1
        else:
            width_test = 0

        if (op10_h < 59.99) or (op10_h > 60.01):
            height_test = 1
        else:
            height_test = 0

        if length_test == 0 and width_test == 0 and height_test == 0:
            op10_test = 'OK'
            op10_data['op10_test'] = op10_test
        else:
            op10_test = 'NOK'
            op10_data['op10_test'] = op10_test

        # 부품 테스트 (body)
        if (body[1] < 199.99) or (body[1] > 200.01):
            length_test = 1
        else:
            length_test = 0

        if (body[2] < 99.99) or (body[2] > 100.01):
            width_test = 1
        else:
            width_test = 0

        if (body[3] < 49.99) or (body[3] > 50.01):
            height_test = 1
        else:
            height_test = 0

        if length_test == 0 and width_test == 0 and height_test == 0:
            body_test = 'OK'
        else:
            body_test = 'NOK'

        # 부품 테스트
        if (wavyfin_l < 99.99) or (wavyfin_l > 100.01):
            length_test = 1
        else:
            length_test = 0

        if (wavyfin_w < 49.99) or (wavyfin_w > 50.01):
            width_test = 1
        else:
            width_test = 0

        if (wavyfin_h < 59.99) or (wavyfin_h > 60.01):
            height_test = 1
        else:
            height_test = 0

        if length_test == 0 and width_test == 0 and height_test == 0:
            wavyfin_test = 'OK'
        else:
            wavyfin_test = 'NOK'

        now = body[5]  # 현재 시간
        time_stamp = now + timedelta(
            seconds=10)  # 현재 시간에서 가동시간만큼 추가된 시간 / 형식 = datetime
        op10_data['op10_time_stamp'] = time_stamp  # 추가된 시간이 완료되고 나가는 시간
        time_stamp = str(time_stamp)  # 문자형으로 저장
        product_key = time_stamp + product_key  # 키는 시간 + 아이템 정보로 저장
        op10_data['product_key'] = product_key

        # product_history 적재
        product_history_data_list = []
        product_history_insert = {}
        op10_master_data = product_master.op10_WIP(1)
        product_code = op10_master_data['product_code']

        product_history_insert['product_key'] = product_key
        product_history_insert['product_code'] = product_code
        product_history_insert['product_timestamp'] = time_stamp

        product_history_data_list.append(product_history_insert)

        MySQL_query.insert_product_history(
            product_history_data_list)  # 히스토리 데이터 DB 적재

        # 부품 히스토리 데이터 모아서 적재 (body)
        part_data_list_body = []
        part_history_insert_body = {}
        part_history_insert_body['product_key'] = time_stamp + '-body'
        part_history_insert_body['product_code'] = 'body'
        part_history_insert_body['product_timestamp'] = time_stamp
        part_data_list_body.append(part_history_insert_body)

        MySQL_query.insert_product_history(
            part_data_list_body)  # 히스토리 데이터 DB 적재

        # 부품 히스토리 데이터 모아서 적재 (wavyfin)
        part_data_list = []
        part_history_insert = {}
        part_history_insert['product_key'] = time_stamp + '-wavyfin'
        part_history_insert['product_code'] = 'wavyfin'
        part_history_insert['product_timestamp'] = time_stamp
        part_data_list.append(part_history_insert)

        MySQL_query.insert_product_history(part_data_list)  # 히스토리 데이터 DB 적재

        # product_quality 적재
        product_quality_data_list = []  # 딕셔너리 데이터 저장할 리스트
        product_quality_insert = {}  # DB 저장할 데이터 모아주는 딕셔너리

        product_quality_insert['product_key'] = product_key
        product_quality_insert['product_size_l'] = str(op10_l)
        product_quality_insert['product_size_w'] = str(op10_w)
        product_quality_insert['product_size_h'] = str(op10_h)
        product_quality_insert['product_test'] = str(op10_test)
        product_quality_insert['product_test_timestamp'] = str(time_stamp)

        product_quality_data_list.append(product_quality_insert)

        MySQL_query.insert_product_quality(
            product_quality_data_list)  # 품질 데이터 DB 적재

        # 부품 quality 적재 (body)
        part_quality_data_list_body = []  # 딕셔너리 데이터 저장할 리스트
        part_quality_insert_body = {}  # DB 저장할 데이터 모아주는 딕셔너리

        part_quality_insert_body['product_key'] = time_stamp + '-body'
        part_quality_insert_body['product_size_l'] = str(body[1])
        part_quality_insert_body['product_size_w'] = str(body[2])
        part_quality_insert_body['product_size_h'] = str(body[3])
        part_quality_insert_body['product_test'] = str(body_test)
        part_quality_insert_body['product_test_timestamp'] = str(time_stamp)

        part_quality_data_list_body.append(part_quality_insert_body)

        MySQL_query.insert_product_quality(
            part_quality_data_list_body)  # 품질 데이터 DB 적재

        # 부품 quality 적재 (wavyfin)
        part_quality_data_list = []  # 딕셔너리 데이터 저장할 리스트
        part_quality_insert = {}  # DB 저장할 데이터 모아주는 딕셔너리

        part_quality_insert['product_key'] = time_stamp + '-wavyfin'
        part_quality_insert['product_size_l'] = str(wavyfin_l)
        part_quality_insert['product_size_w'] = str(wavyfin_w)
        part_quality_insert['product_size_h'] = str(wavyfin_h)
        part_quality_insert['product_test'] = str(wavyfin_test)
        part_quality_insert['product_test_timestamp'] = str(time_stamp)

        part_quality_data_list.append(part_quality_insert)

        MySQL_query.insert_product_quality(
            part_quality_data_list)  # 품질 데이터 DB 적재

        # machine 적재
        machine_data_list = []  # 딕셔너리 데이터 저장할 리스트
        machine_data_insert = {}  # DB 저장할 데이터 모아주는 딕셔너리

        machine_master_data = machine_master.op10(1)  # machine_code 가져오기
        machine_code = machine_master_data['machine_code']

        machine_data_insert['machine_code'] = machine_code
        machine_data_insert['product_key'] = product_key
        machine_data_insert['start_time'] = str(now)
        machine_data_insert['end_time'] = str(time_stamp)
        machine_data_insert['makespan'] = '123'
        machine_data_insert['process_time'] = str(op10_process_time)
        machine_data_insert['machine_data'] = str(op10_electricity)
        machine_data_insert['machine_data_code'] = 'E01'

        machine_data_list.append(machine_data_insert)

        MySQL_query.insert_machine(machine_data_list)  # machine 데이터 DB 적재

        return op10_data
예제 #19
0
from SQL import MySQL_query
from machine_master_table import machine_master

op10 = machine_master.op10(1)
op20 = machine_master.op20(1)
op30 = machine_master.op30(1)
op40 = machine_master.op40(1)
op50 = machine_master.op50(1)
op60 = machine_master.op60(1)

MySQL_query.insert_machine_master(op10)
MySQL_query.insert_machine_master(op20)
MySQL_query.insert_machine_master(op30)
MySQL_query.insert_machine_master(op40)
MySQL_query.insert_machine_master(op50)
MySQL_query.insert_machine_master(op60)
def Predict_data():

    key_list = MySQL_query.get_product_key_for_test(app.predict_count)

    total_big_bottle = []

    for i in range(len(key_list)):
        total_dict = {}

        key30 = key_list[i]['key30']
        key20 = key_list[i]['key20']
        key10 = key_list[i]['key10']
        predict_result = key_list[i]['predict_result']

        op30_data = MySQL_query.get_test_data_op30(key30)
        op20_data = MySQL_query.get_test_data_op20(key20)
        op10_data = MySQL_query.get_test_data_op10(key10)

        body_data = MySQL_query.get_test_data_parts_body(key10)
        wavyfin_data = MySQL_query.get_test_data_parts_wavyfin(key10)
        pipe1_data = MySQL_query.get_test_data_parts_pipe1(key20)
        pipe2_data = MySQL_query.get_test_data_parts_pipe2(key30)

        product_key = op30_data[0]['product_key']

        body_size_l = body_data[0]['product_size_l']
        body_size_w = body_data[0]['product_size_w']
        body_size_h = body_data[0]['product_size_h']

        wavyfin_size_l = wavyfin_data[0]['product_size_l']
        wavyfin_size_w = wavyfin_data[0]['product_size_w']
        wavyfin_size_h = wavyfin_data[0]['product_size_h']

        pipe1_size_l = pipe1_data[0]['product_size_l']
        pipe1_size_w = pipe1_data[0]['product_size_w']
        pipe1_size_h = pipe1_data[0]['product_size_h']

        pipe2_size_l = pipe2_data[0]['product_size_l']
        pipe2_size_w = pipe2_data[0]['product_size_w']
        pipe2_size_h = pipe2_data[0]['product_size_h']

        op10_machine_data = op10_data[0]['machine_data']
        op10_size_l = op10_data[0]['product_size_l']
        op10_size_w = op10_data[0]['product_size_w']
        op10_size_h = op10_data[0]['product_size_h']

        op20_machine_data = op20_data[0]['machine_data']
        op20_size_l = op20_data[0]['product_size_l']
        op20_size_w = op20_data[0]['product_size_w']
        op20_size_h = op20_data[0]['product_size_h']

        op30_machine_data = op30_data[0]['machine_data']
        op30_size_l = op30_data[0]['product_size_l']
        op30_size_w = op30_data[0]['product_size_w']
        op30_size_h = op30_data[0]['product_size_h']

        total_dict['product_key'] = product_key
        total_dict['body_size_l'] = str(body_size_l)
        total_dict['body_size_w'] = str(body_size_w)
        total_dict['body_size_h'] = str(body_size_h)
        total_dict['wavyfin_size_l'] = str(wavyfin_size_l)
        total_dict['wavyfin_size_w'] = str(wavyfin_size_w)
        total_dict['wavyfin_size_h'] = str(wavyfin_size_h)
        total_dict['op10_machine_data'] = str(op10_machine_data)
        total_dict['op10_size_l'] = str(op10_size_l)
        total_dict['op10_size_w'] = str(op10_size_w)
        total_dict['op10_size_h'] = str(op10_size_h)

        total_dict['pipe1_size_l'] = str(pipe1_size_l)
        total_dict['pipe1_size_w'] = str(pipe1_size_w)
        total_dict['pipe1_size_h'] = str(pipe1_size_h)
        total_dict['op20_machine_data'] = str(op20_machine_data)
        total_dict['op20_size_l'] = str(op20_size_l)
        total_dict['op20_size_w'] = str(op20_size_w)
        total_dict['op20_size_h'] = str(op20_size_h)

        total_dict['pipe2_size_l'] = str(pipe2_size_l)
        total_dict['pipe2_size_w'] = str(pipe2_size_w)
        total_dict['pipe2_size_h'] = str(pipe2_size_h)
        total_dict['op30_machine_data'] = str(op30_machine_data)
        total_dict['op30_size_l'] = str(op30_size_l)
        total_dict['op30_size_w'] = str(op30_size_w)
        total_dict['op30_size_h'] = str(op30_size_h)

        total_dict['predict_result'] = str(predict_result)

        total_big_bottle.append(total_dict)

    app.predict_count += 1

    if app.predict_count >= 10:
        app.predict_count = 10

    return jsonify(total_big_bottle)
def Search_data(key60):

    key = key60

    total_big_bottle = []
    data_dict = {}

    index1 = 0
    bar_count = 0
    for index in range(len(key)):

        if key[index] == '-':
            bar_count = bar_count + 1

            if bar_count == 3:
                index1 = index
                break

    key60_head = key[index1 + 1:]
    key50_head = key60_head.replace('W6', 'W5')
    key40_head = key50_head.replace('W5', 'W4')
    key30_head = key40_head.replace('W4', 'W3')
    key20_head = key30_head.replace('W3', 'W2')
    key10_head = key20_head.replace('W2', 'W1')

    key50 = MySQL_query.get_key_for_search(key50_head)
    key50 = key50[0]['product_key']
    key40 = MySQL_query.get_key_for_search(key40_head)
    key40 = key40[0]['product_key']
    key30 = MySQL_query.get_key_for_search(key30_head)
    key30 = key30[0]['product_key']
    key20 = MySQL_query.get_key_for_search(key20_head)
    key20 = key20[0]['product_key']
    key10 = MySQL_query.get_key_for_search(key10_head)
    key10 = key10[0]['product_key']

    body_data = MySQL_query.get_body_data_for_search(key10)
    wavyfin_data = MySQL_query.get_wavyfin_data_for_search(key10)
    pipe1_data = MySQL_query.get_pipe1_data_for_search(key20)
    pipe2_data = MySQL_query.get_pipe2_data_for_search(key30)
    flange1_data = MySQL_query.get_flange1_data_for_search(key40)
    flange2_data = MySQL_query.get_flange2_data_for_search(key50)

    op10_data = MySQL_query.get_op10_data_for_search(key10)
    op20_data = MySQL_query.get_op20_data_for_search(key20)
    op30_data = MySQL_query.get_op30_data_for_search(key30)
    op40_data = MySQL_query.get_op40_data_for_search(key40)
    op50_data = MySQL_query.get_op50_data_for_search(key50)
    op60_data = MySQL_query.get_op60_data_for_search(key60)

    product_key = op60_data[0]['product_key']
    op60_timestamp = op60_data[0]['product_test_timestamp']

    op50_machine_data = op50_data[0]['machine_data']
    op50_process_time = op50_data[0]['process_time']
    op50_product_size_l = op50_data[0]['product_size_l']
    op50_product_size_w = op50_data[0]['product_size_w']
    op50_product_size_h = op50_data[0]['product_size_h']

    flange2_l = flange2_data[0]['product_size_l']
    flange2_w = flange2_data[0]['product_size_w']
    flange2_h = flange2_data[0]['product_size_h']

    op40_machine_data = op40_data[0]['machine_data']
    op40_process_time = op40_data[0]['process_time']
    op40_product_size_l = op40_data[0]['product_size_l']
    op40_product_size_w = op40_data[0]['product_size_w']
    op40_product_size_h = op40_data[0]['product_size_h']

    flange1_l = flange1_data[0]['product_size_l']
    flange1_w = flange1_data[0]['product_size_w']
    flange1_h = flange1_data[0]['product_size_h']

    op30_machine_data = op30_data[0]['machine_data']
    op30_process_time = op30_data[0]['process_time']
    op30_product_size_l = op30_data[0]['product_size_l']
    op30_product_size_w = op30_data[0]['product_size_w']
    op30_product_size_h = op30_data[0]['product_size_h']

    pipe2_l = pipe2_data[0]['product_size_l']
    pipe2_w = pipe2_data[0]['product_size_w']
    pipe2_h = pipe2_data[0]['product_size_h']

    op20_machine_data = op20_data[0]['machine_data']
    op20_process_time = op20_data[0]['process_time']
    op20_product_size_l = op20_data[0]['product_size_l']
    op20_product_size_w = op20_data[0]['product_size_w']
    op20_product_size_h = op20_data[0]['product_size_h']

    pipe1_l = pipe1_data[0]['product_size_l']
    pipe1_w = pipe1_data[0]['product_size_w']
    pipe1_h = pipe1_data[0]['product_size_h']

    op10_machine_data = op10_data[0]['machine_data']
    op10_process_time = op10_data[0]['process_time']
    op10_product_size_l = op10_data[0]['product_size_l']
    op10_product_size_w = op10_data[0]['product_size_w']
    op10_product_size_h = op10_data[0]['product_size_h']

    wavyfin_l = wavyfin_data[0]['product_size_l']
    wavyfin_w = wavyfin_data[0]['product_size_w']
    wavyfin_h = wavyfin_data[0]['product_size_h']

    body_l = body_data[0]['product_size_l']
    body_w = body_data[0]['product_size_w']
    body_h = body_data[0]['product_size_h']

    data_dict['product_key'] = product_key
    data_dict['op60_timestamp'] = op60_timestamp

    data_dict['body_l'] = body_l
    data_dict['body_w'] = body_w
    data_dict['body_h'] = body_h

    data_dict['wavyfin_l'] = wavyfin_l
    data_dict['wavyfin_w'] = wavyfin_w
    data_dict['wavyfin_h'] = wavyfin_h

    data_dict['op10_machine_data'] = op10_machine_data
    data_dict['op10_process_time'] = op10_process_time
    data_dict['op10_product_size_l'] = op10_product_size_l
    data_dict['op10_product_size_w'] = op10_product_size_w
    data_dict['op10_product_size_h'] = op10_product_size_h

    data_dict['pipe1_l'] = pipe1_l
    data_dict['pipe1_w'] = pipe1_w
    data_dict['pipe1_h'] = pipe1_h

    data_dict['op20_machine_data'] = op20_machine_data
    data_dict['op20_process_time'] = op20_process_time
    data_dict['op20_product_size_l'] = op20_product_size_l
    data_dict['op20_product_size_w'] = op20_product_size_w
    data_dict['op20_product_size_h'] = op20_product_size_h

    data_dict['pipe2_l'] = pipe2_l
    data_dict['pipe2_w'] = pipe2_w
    data_dict['pipe2_h'] = pipe2_h

    data_dict['op30_machine_data'] = op30_machine_data
    data_dict['op30_process_time'] = op30_process_time
    data_dict['op30_product_size_l'] = op30_product_size_l
    data_dict['op30_product_size_w'] = op30_product_size_w
    data_dict['op30_product_size_h'] = op30_product_size_h

    data_dict['flange1_l'] = flange1_l
    data_dict['flange1_w'] = flange1_w
    data_dict['flange1_h'] = flange1_h

    data_dict['op40_machine_data'] = op40_machine_data
    data_dict['op40_process_time'] = op40_process_time
    data_dict['op40_product_size_l'] = op40_product_size_l
    data_dict['op40_product_size_w'] = op40_product_size_w
    data_dict['op40_product_size_h'] = op40_product_size_h

    data_dict['flange2_l'] = flange2_l
    data_dict['flange2_w'] = flange2_w
    data_dict['flange2_h'] = flange2_h

    data_dict['op50_machine_data'] = op50_machine_data
    data_dict['op50_process_time'] = op50_process_time
    data_dict['op50_product_size_l'] = op50_product_size_l
    data_dict['op50_product_size_w'] = op50_product_size_w
    data_dict['op50_product_size_h'] = op50_product_size_h

    total_big_bottle.append(data_dict)

    return total_big_bottle
예제 #22
0
def machine_master():
    machine_master_data = []

    ### 10
    master_dict = {}

    machine_code = 'OP10'  # 설비 코드명
    machine_class = 'MCO1'  # 단순 조립
    machine_process_time = 'exp10'
    machine_assembly = 'body_wavyfin'
    machine_data_code = 'E01'

    master_dict['machine_code'] = machine_code  # PK
    master_dict['machine_class'] = machine_class
    master_dict['machine_process_time'] = machine_process_time
    master_dict['machine_assembly'] = machine_assembly
    master_dict['machine_data_code'] = machine_data_code

    machine_master_data.append(master_dict)

    ### 20
    master_dict = {}

    machine_code = 'OP20'  # 설비 코드명
    machine_class = 'MCO1'  # 단순 조립
    machine_process_time = 'exp10'
    machine_assembly = 'op10_pipe1'
    machine_data_code = 'E01'

    master_dict['machine_code'] = machine_code  # PK
    master_dict['machine_class'] = machine_class
    master_dict['machine_process_time'] = machine_process_time
    master_dict['machine_assembly'] = machine_assembly
    master_dict['machine_data_code'] = machine_data_code

    machine_master_data.append(master_dict)

    ### 30
    master_dict = {}

    machine_code = 'OP30'  # 설비 코드명
    machine_class = 'MCO1'  # 단순 조립
    machine_process_time = 'exp10'
    machine_assembly = 'op20_pipe2'
    machine_data_code = 'E01'

    master_dict['machine_code'] = machine_code  # PK
    master_dict['machine_class'] = machine_class
    master_dict['machine_process_time'] = machine_process_time
    master_dict['machine_assembly'] = machine_assembly
    master_dict['machine_data_code'] = machine_data_code

    machine_master_data.append(master_dict)

    ### 40
    master_dict = {}

    machine_code = 'OP40'  # 설비 코드명
    machine_class = 'MCO2'  # 용접 조립
    machine_process_time = 'exp10'
    machine_assembly = 'op30_flange1'
    machine_data_code = 'T01'

    master_dict['machine_code'] = machine_code  # PK
    master_dict['machine_class'] = machine_class
    master_dict['machine_process_time'] = machine_process_time
    master_dict['machine_assembly'] = machine_assembly
    master_dict['machine_data_code'] = machine_data_code

    machine_master_data.append(master_dict)

    ### 50
    master_dict = {}

    machine_code = 'OP50'  # 설비 코드명
    machine_class = 'MCO2'  # 용접 조립
    machine_process_time = 'exp10'
    machine_assembly = 'op40_flange2'
    machine_data_code = 'T01'

    master_dict['machine_code'] = machine_code  # PK
    master_dict['machine_class'] = machine_class
    master_dict['machine_process_time'] = machine_process_time
    master_dict['machine_assembly'] = machine_assembly
    master_dict['machine_data_code'] = machine_data_code

    machine_master_data.append(master_dict)

    ### 60
    master_dict = {}

    machine_code = 'OP60'  # 설비 코드명
    machine_class = 'MCO3'  # 최종 검사
    machine_process_time = 'exp10'
    machine_assembly = 'final_test'
    machine_data_code = 'TEST'

    master_dict['machine_code'] = machine_code  # PK
    master_dict['machine_class'] = machine_class
    master_dict['machine_process_time'] = machine_process_time
    master_dict['machine_assembly'] = machine_assembly
    master_dict['machine_data_code'] = machine_data_code

    machine_master_data.append(master_dict)

    MySQL_query.insert_machine_master(machine_master_data)

    return machine_master_data
    def op50(op40):
        op50_data = {}
        std = 0.0025

        product_key = op40[0]

        flange2_l = np.random.normal(30, std)
        flange2_l = round(flange2_l, 5)

        flange2_w = np.random.normal(80, std)
        flange2_w = round(flange2_w, 5)

        flange2_h = np.random.normal(40, std)
        flange2_h = round(flange2_h, 5)

        op50_process_time = op40[4]

        op50_temperature = np.random.uniform(489.75, 510.25)
        op50_temperature = round(op50_temperature, 5)

        op50_data['flange2_l'] = flange2_l
        op50_data['flange2_w'] = flange2_w
        op50_data['flange2_h'] = flange2_h

        if 490 < op50_temperature < 510:
            op50_l = op40[1] + flange2_l
            op50_l = round(op50_l, 5)
        else:
            op50_l = op40[1] + flange2_l - 1

        op50_data['op50_l'] = op50_l

        op50_w = op40[2]
        op50_data['op50_w'] = op50_w

        op50_h = op40[3]
        op50_data['op50_h'] = op50_h

        op50_data['op50_temperature'] = op50_temperature
        op50_data['op50_process_time'] = op50_process_time

        if (op50_l < 259.99) or (op50_l > 260.01):
            length_test = 1
        else:
            length_test = 0

        if (op50_w < 179.99) or (op50_w > 180.01):
            width_test = 1
        else:
            width_test = 0

        if (op50_h < 59.99) or (op50_h > 60.01):
            height_test = 1
        else:
            height_test = 0

        if length_test == 0 and width_test == 0 and height_test == 0:
            op50_test = 'OK'
            op50_data['op50_test'] = op50_test
        else:
            op50_test = 'NOK'
            op50_data['op50_test'] = op50_test

        # 부품 테스트
        if (flange2_l < 29.99) or (flange2_l > 30.01):
            length_test = 1
        else:
            length_test = 0

        if (flange2_w < 79.99) or (flange2_w > 80.01):
            width_test = 1
        else:
            width_test = 0

        if (flange2_h < 39.99) or (flange2_h > 40.01):
            height_test = 1
        else:
            height_test = 0

        if length_test == 0 and width_test == 0 and height_test == 0:
            flange2_test = 'OK'
        else:
            flange2_test = 'NOK'

        now = op40[5]
        time_stamp = now + timedelta(seconds=10)
        op50_data['op50_time_stamp'] = time_stamp
        time_stamp = str(time_stamp)

        product_key = time_stamp + product_key
        op50_data['product_key'] = product_key

        # product_history 적재
        product_history_data_list = []
        product_history_insert = {}
        op50_master_data = product_master.op50_WIP(1)
        product_code = op50_master_data['product_code']

        product_history_insert['product_key'] = product_key
        product_history_insert['product_code'] = product_code
        product_history_insert['product_timestamp'] = time_stamp

        product_history_data_list.append(product_history_insert)

        MySQL_query.insert_product_history(
            product_history_data_list)  # 히스토리 데이터 DB 적재

        # 부품 데이터 모아서 적재 (flange2)
        part_data_list = []
        part_history_insert = {}
        part_history_insert['product_key'] = time_stamp + '-flange2'
        part_history_insert['product_code'] = 'flange2'
        part_history_insert['product_timestamp'] = time_stamp
        part_data_list.append(part_history_insert)

        MySQL_query.insert_product_history(part_data_list)  # 히스토리 데이터 DB 적재

        # product_quality 적재
        product_quality_data_list = []  # 딕셔너리 데이터 저장할 리스트
        product_quality_insert = {}  # DB 저장할 데이터 모아주는 딕셔너리

        product_quality_insert['product_key'] = product_key
        product_quality_insert['product_size_l'] = str(op50_l)
        product_quality_insert['product_size_w'] = str(op50_w)
        product_quality_insert['product_size_h'] = str(op50_h)
        product_quality_insert['product_test'] = str(op50_test)
        product_quality_insert['product_test_timestamp'] = str(time_stamp)

        product_quality_data_list.append(product_quality_insert)

        MySQL_query.insert_product_quality(
            product_quality_data_list)  # 품질 데이터 DB 적재

        # product_quality 적재
        product_quality_data_list = []  # 딕셔너리 데이터 저장할 리스트
        product_quality_insert = {}  # DB 저장할 데이터 모아주는 딕셔너리

        product_quality_insert['product_key'] = time_stamp + '-flange2'
        product_quality_insert['product_size_l'] = str(flange2_l)
        product_quality_insert['product_size_w'] = str(flange2_w)
        product_quality_insert['product_size_h'] = str(flange2_h)
        product_quality_insert['product_test'] = str(flange2_test)
        product_quality_insert['product_test_timestamp'] = str(time_stamp)

        product_quality_data_list.append(product_quality_insert)

        MySQL_query.insert_product_quality(
            product_quality_data_list)  # 품질 데이터 DB 적재

        # machine 적재
        machine_data_list = []  # 딕셔너리 데이터 저장할 리스트
        machine_data_insert = {}  # DB 저장할 데이터 모아주는 딕셔너리

        machine_master_data = machine_master.op50(1)  # machine_code 가져오기
        machine_code = machine_master_data['machine_code']

        machine_data_insert['machine_code'] = machine_code
        machine_data_insert['product_key'] = product_key
        machine_data_insert['start_time'] = str(now)
        machine_data_insert['end_time'] = str(time_stamp)
        machine_data_insert['makespan'] = '123'
        machine_data_insert['process_time'] = str(op50_process_time)
        machine_data_insert['machine_data'] = str(op50_temperature)
        machine_data_insert['machine_data_code'] = 'T01'

        machine_data_list.append(machine_data_insert)

        MySQL_query.insert_machine(machine_data_list)  # machine 데이터 DB 적재

        return op50_data
예제 #24
0
def train():
    machine_data = MySQL_query.get_machine_data_list_for_predict(1)
    quality_data = MySQL_query.get_quality_data_list_for_predict(1)

    machine_df = pd.DataFrame(machine_data)
    quality_df = pd.DataFrame(quality_data)

    product_key_list = []
    body_l_list = []
    body_w_list = []
    body_h_list = []

    wavyfin_l_list = []
    wavyfin_w_list = []
    wavyfin_h_list = []

    op10_l_list = []
    op10_w_list = []
    op10_h_list = []

    pipe1_l_list = []
    pipe1_w_list = []
    pipe1_h_list = []

    op20_l_list = []
    op20_w_list = []
    op20_h_list = []

    pipe2_l_list = []
    pipe2_w_list = []
    pipe2_h_list = []

    op30_l_list = []
    op30_w_list = []
    op30_h_list = []

    flange1_l_list = []
    flange1_w_list = []
    flange1_h_list = []

    op40_l_list = []
    op40_w_list = []
    op40_h_list = []

    flange2_l_list = []
    flange2_w_list = []
    flange2_h_list = []

    op50_l_list = []
    op50_w_list = []
    op50_h_list = []

    op60_l_list = []
    op60_w_list = []
    op60_h_list = []

    op10_electricity_list = []
    op10_process_time_list = []

    op20_electricity_list = []
    op20_process_time_list = []

    op30_electricity_list = []
    op30_process_time_list = []

    op40_temperature_list = []
    op40_process_time_list = []

    op50_temperature_list = []
    op50_process_time_list = []

    op60_process_time_list = []

    op10_test_list = []
    op20_test_list = []
    op30_test_list = []
    op40_test_list = []
    op50_test_list = []
    op60_test_list = []

    op10_timestamp = []
    op20_timestamp = []
    op30_timestamp = []
    op40_timestamp = []
    op50_timestamp = []
    op60_timestamp = []

    for instance in quality_data:

        if (instance['product_key'][27:29] == 'W6'):
            product_key_list.append(instance['product_key'])

        if (instance['product_key'][27:] == 'body'):
            body_l_list.append(instance['product_size_l'])
            body_w_list.append(instance['product_size_w'])
            body_h_list.append(instance['product_size_h'])

        if (instance['product_key'][27:] == 'wavyfin'):
            wavyfin_l_list.append(instance['product_size_l'])
            wavyfin_w_list.append(instance['product_size_w'])
            wavyfin_h_list.append(instance['product_size_h'])

        if (instance['product_key'][27:29] == 'W1'):
            op10_l_list.append(instance['product_size_l'])
            op10_w_list.append(instance['product_size_w'])
            op10_h_list.append(instance['product_size_h'])

        if (instance['product_key'][27:29] == 'W1'):
            if instance['product_test'] == 'OK':
                op10_test_list.append(0)
            else:
                op10_test_list.append(1)

        if (instance['product_key'][27:] == 'pipe1'):
            pipe1_l_list.append(instance['product_size_l'])
            pipe1_w_list.append(instance['product_size_w'])
            pipe1_h_list.append(instance['product_size_h'])

        if (instance['product_key'][27:29] == 'W2'):
            op20_l_list.append(instance['product_size_l'])
            op20_w_list.append(instance['product_size_w'])
            op20_h_list.append(instance['product_size_h'])

        if (instance['product_key'][27:29] == 'W2'):
            if instance['product_test'] == 'OK':
                op20_test_list.append(0)
            else:
                op20_test_list.append(1)

        if (instance['product_key'][27:] == 'pipe2'):
            pipe2_l_list.append(instance['product_size_l'])
            pipe2_w_list.append(instance['product_size_w'])
            pipe2_h_list.append(instance['product_size_h'])

        if (instance['product_key'][27:29] == 'W3'):
            op30_l_list.append(instance['product_size_l'])
            op30_w_list.append(instance['product_size_w'])
            op30_h_list.append(instance['product_size_h'])

        if (instance['product_key'][27:29] == 'W3'):
            if instance['product_test'] == 'OK':
                op30_test_list.append(0)
            else:
                op30_test_list.append(1)

        if (instance['product_key'][27:] == 'flange1'):
            flange1_l_list.append(instance['product_size_l'])
            flange1_w_list.append(instance['product_size_w'])
            flange1_h_list.append(instance['product_size_h'])

        if (instance['product_key'][27:29] == 'W4'):
            op40_l_list.append(instance['product_size_l'])
            op40_w_list.append(instance['product_size_w'])
            op40_h_list.append(instance['product_size_h'])

        if (instance['product_key'][27:29] == 'W4'):
            if instance['product_test'] == 'OK':
                op40_test_list.append(0)
            else:
                op40_test_list.append(1)

        if (instance['product_key'][27:] == 'flange2'):
            flange2_l_list.append(instance['product_size_l'])
            flange2_w_list.append(instance['product_size_w'])
            flange2_h_list.append(instance['product_size_h'])

        if (instance['product_key'][27:29] == 'W5'):
            op50_l_list.append(instance['product_size_l'])
            op50_w_list.append(instance['product_size_w'])
            op50_h_list.append(instance['product_size_h'])

        if (instance['product_key'][27:29] == 'W5'):
            if instance['product_test'] == 'OK':
                op50_test_list.append(0)
            else:
                op50_test_list.append(1)

        if (instance['product_key'][27:29] == 'W6'):
            op60_l_list.append(instance['product_size_l'])
            op60_w_list.append(instance['product_size_w'])
            op60_h_list.append(instance['product_size_h'])

        if (instance['product_key'][27:29] == 'W6'):
            if instance['product_test'] == 'OK':
                op60_test_list.append(0)
            else:
                op60_test_list.append(1)

    for instance in machine_data:

        if (instance['product_key'][27:29] == 'W1'):
            op10_electricity_list.append(instance['machine_data'])

        if (instance['product_key'][27:29] == 'W1'):
            op10_process_time_list.append(instance['process_time'])

        if (instance['product_key'][27:29] == 'W1'):
            op10_timestamp.append(instance['end_time'])

        if (instance['product_key'][27:29] == 'W2'):
            op20_electricity_list.append(instance['machine_data'])

        if (instance['product_key'][27:29] == 'W2'):
            op20_process_time_list.append(instance['process_time'])

        if (instance['product_key'][27:29] == 'W2'):
            op20_timestamp.append(instance['end_time'])

        if (instance['product_key'][27:29] == 'W3'):
            op30_electricity_list.append(instance['machine_data'])

        if (instance['product_key'][27:29] == 'W3'):
            op30_process_time_list.append(instance['process_time'])

        if (instance['product_key'][27:29] == 'W3'):
            op30_timestamp.append(instance['end_time'])

        if (instance['product_key'][27:29] == 'W4'):
            op40_temperature_list.append(instance['machine_data'])

        if (instance['product_key'][27:29] == 'W4'):
            op40_process_time_list.append(instance['process_time'])

        if (instance['product_key'][27:29] == 'W4'):
            op40_timestamp.append(instance['end_time'])

        if (instance['product_key'][27:29] == 'W5'):
            op50_temperature_list.append(instance['machine_data'])

        if (instance['product_key'][27:29] == 'W5'):
            op50_process_time_list.append(instance['process_time'])

        if (instance['product_key'][27:29] == 'W5'):
            op50_timestamp.append(instance['end_time'])

        if (instance['product_key'][27:29] == 'W6'):
            op60_process_time_list.append(instance['process_time'])

        if (instance['product_key'][27:29] == 'W6'):
            op60_timestamp.append(instance['end_time'])

    df = pd.DataFrame({
        "product_key": product_key_list,
        'body_l': body_l_list,
        'body_w': body_w_list,
        'body_h': body_h_list,
        'wavyfin_l': wavyfin_l_list,
        'wavyfin_w': wavyfin_w_list,
        'wavyfin_h': wavyfin_h_list,
        'op10_l': op10_l_list,
        'op10_w': op10_w_list,
        'op10_h': op10_h_list,
        'op10_electricity': op10_electricity_list,
        'op10_process_time': op10_process_time_list,
        'op10_test': op10_test_list,
        'op10_timestamp': op10_timestamp,
        'pipe1_l': pipe1_l_list,
        'pipe1_w': pipe1_w_list,
        'pipe1_h': pipe1_h_list,
        'op20_l': op20_l_list,
        'op20_w': op20_w_list,
        'op20_h': op20_h_list,
        'op20_electricity': op20_electricity_list,
        'op20_process_time': op20_process_time_list,
        'op20_test': op20_test_list,
        'op20_timestamp': op20_timestamp,
        'pipe2_l': pipe2_l_list,
        'pipe2_w': pipe2_w_list,
        'pipe2_h': pipe2_h_list,
        'op30_l': op30_l_list,
        'op30_w': op30_w_list,
        'op30_h': op30_h_list,
        'op30_electricity': op30_electricity_list,
        'op30_process_time': op30_process_time_list,
        'op30_test': op30_test_list,
        'op30_timestamp': op30_timestamp,
        'flange1_l': flange1_l_list,
        'flange1_w': flange1_w_list,
        'flange1_h': flange1_h_list,
        'op40_l': op40_l_list,
        'op40_w': op40_w_list,
        'op40_h': op40_h_list,
        'op40_temperature': op40_temperature_list,
        'op40_process_time': op40_process_time_list,
        'op40_test': op40_test_list,
        'op40_timestamp': op40_timestamp,
        'flange2_l': flange2_l_list,
        'flange2_w': flange2_w_list,
        'flange2_h': flange2_h_list,
        'op50_l': op50_l_list,
        'op50_w': op50_w_list,
        'op50_h': op50_h_list,
        'op50_temperature': op50_temperature_list,
        'op50_process_time': op50_process_time_list,
        'op50_test': op50_test_list,
        'op50_timestamp': op50_timestamp,
        'op60_l': op60_l_list,
        'op60_w': op60_w_list,
        'op60_h': op60_h_list,
        'op60_process_time': op60_process_time_list,
        'op60_test': op60_test_list,
        'op60_timestamp': op60_timestamp
    })

    X = df.drop([
        'op60_timestamp', 'op60_process_time', 'op60_h', 'op60_w', 'op60_l',
        'op60_test', 'op50_timestamp', 'op50_process_time', 'op50_h', 'op50_w',
        'op50_l', 'op50_temperature', 'op50_test', 'op40_timestamp',
        'op40_process_time', 'op40_h', 'op40_w', 'op40_l', 'op40_temperature',
        'op40_test', 'flange1_l', 'flange1_w', 'flange1_h', 'flange2_l',
        'flange2_w', 'flange2_h', 'op10_timestamp', 'op20_timestamp',
        'op30_timestamp', 'product_key'
    ],
                axis=1)

    y = df['op60_test']

    X_train, X_test, y_train, y_test = train_test_split(X,
                                                        y,
                                                        test_size=0.1,
                                                        shuffle=False,
                                                        random_state=1004)

    rf_clf = RandomForestClassifier(random_state=0)  # 랜덤 포레스트 모델
    rf_clf.fit(X_train, y_train)  # 학습
    saved_model = pickle.dumps(rf_clf)  # 모델 저장

    preds = rf_clf.predict(X_test)
    accuracy = accuracy_score(y_test, preds)
    print('랜덤 포레스트 정확도: {0:.4f}'.format(accuracy))
    joblib.dump(rf_clf, 'pretrained_model.pkl')
    print("파일 저장완료")
    def process_start(amount):
        std = 0.0025  # 표준편차   100만개 중에 12개 불량

        num = MySQL_query.key_for_count(1)  # 키 번호를 매기기 위한 값을 DB에서 가져옴 op10 키

        if num == []:  # 아무것도 없으면 -> 생산이 안됐음
            n = 10001  # 처음 10001 번 품목으로 키값을 찍어라. n은 P10001 <- 요 숫자
        else:  # 하나라도 있으면

            n = num[0][
                'product_key']  # ['product_key' : 'xxxx']  n은 키 값 -> str 형식
            bar_count = 0  # 키 파싱하기 위한
            for index in range(len(n)):

                if n[index] == '-':
                    bar_count = bar_count + 1

                    if bar_count == 3:
                        break

            n = int(n[index + 4:]) + 1  # 지금까지 만들어진 품목 번호 + 1을 시작값으로 만들겠다.

        total_test_data = []  # 예측할 test 데이터들을 뽑기 위한 모음

        stop_button = None  # 정지 버튼 True 되면 공정 스탑 하고 정지하거나 리셋

        ##### 전체적인 진행: body 생성 -> op10 실행 -> DB 저장 -> 저장한 데이터 가져오기 -> op10_data 변수 저장 -> 다음 공정 실행

        body_P0 = []  # 공정에 넣을 body 데이터 리스트 틀 -> Machine에 넣을 예정

        product_key_W1P0 = '-' + 'W1' + 'P' + str(
            n)  # 첫번째 제품 primary_key 생성 -> machine에서 시간 추가할 예정
        body_P0.append(product_key_W1P0)

        body_l_P0 = np.random.normal(200, std)  # body 치수 데이터 생성
        body_l_P0 = round(body_l_P0, 5)  # 소수점 5째 자리까지 만들어줘
        body_P0.append(body_l_P0)  # 리스트에 담기

        body_w_P0 = np.random.normal(100, std)
        body_w_P0 = round(body_w_P0, 5)
        body_P0.append(body_w_P0)

        body_h_P0 = np.random.normal(50, std)
        body_h_P0 = round(body_h_P0, 5)
        body_P0.append(body_h_P0)

        op10_process_time_P0 = np.random.triangular(
            9, 10, 10)  # process_time 생성  (최소, 최대, 최빈)
        op10_process_time_P0 = round(op10_process_time_P0, 5)

        body_P0.append(op10_process_time_P0)

        body_P0.append(
            datetime.now() +
            timedelta(hours=9))  # 첫번째 제품은 현재시간부터 시작한다고 가정, 한국시간에 맞추기 위해 9시간 추가

        print('한개 생산 중')
        time.sleep(10)  # 10초 텀 실제 시간으로 텀을 주도록 만듬

        # op10 공정 실행 (W1P0)
        op10_data_P0 = machine_operate.op10(body_P0)
        product_key_W1P0 = op10_data_P0['product_key']

        ##### 여기에 웹페이지로 쏴주는 기능 추가 #####

        #################################### W1P0 생산 및 DB 저장 완료 #####################################

        # 다음 공정에 넣기 위한 데이터 가져와서 넣기
        op10_data_P0_from_DB = MySQL_query.get_quality_data_for_process(
            product_key_W1P0)

        op10_data_list_P0 = []  # P0 재공품 다음공정으로 넣어줄 데이터 저장할 리스트

        op10_l_P0 = op10_data_P0_from_DB[0][
            'product_size_l']  # 재공품 치수 데이터 가져오기
        op10_w_P0 = op10_data_P0_from_DB[0]['product_size_w']
        op10_h_P0 = op10_data_P0_from_DB[0]['product_size_h']

        op20_process_time_P0 = np.random.triangular(
            9, 10, 10)  # 다음 공정에 넣어줄 process_time 새로 생성
        op20_process_time_P0 = round(op20_process_time_P0, 5)

        op20_product_key_P0 = '-' + 'W2' + 'P' + str(n)  # 제품 키 생성

        op20_start_time_P0 = datetime.now() + timedelta(hours=9)

        op10_data_list_P0.append(op20_product_key_P0)  # 2번째 제품 키 - 인덱스 0번
        op10_data_list_P0.append(op10_l_P0)  # 1번 - 길이
        op10_data_list_P0.append(op10_w_P0)  # 2번 - 너비
        op10_data_list_P0.append(op10_h_P0)  # 3번 - 높이
        op10_data_list_P0.append(
            op20_process_time_P0)  # 4번 - 다음 공정 작업할 process_time
        op10_data_list_P0.append(
            op20_start_time_P0
        )  # 재공품 정보에 시작해야할 시간 저장 / 인덱스 5번 // # op20 넣기위한 리스트를 만들어주고 있음.

        body_P1 = []  # P1 제품에 대한 body 값 저장할 리스트

        product_key_W1P1 = '-' + 'W1' + 'P' + str(
            n + 1)  # 첫번째 제품 primary_key 생성 -> machine에서 시간 추가할 예정
        body_P1.append(product_key_W1P1)

        body_l_P1 = np.random.normal(200, std)  # body 치수 데이터 생성
        body_l_P1 = round(body_l_P1, 5)
        body_P1.append(body_l_P1)

        body_w_P1 = np.random.normal(100, std)
        body_w_P1 = round(body_w_P1, 5)
        body_P1.append(body_w_P1)

        body_h_P1 = np.random.normal(50, std)
        body_h_P1 = round(body_h_P1, 5)
        body_P1.append(body_h_P1)

        op10_process_time_P1 = np.random.triangular(9, 10,
                                                    10)  # process_time 생성
        op10_process_time_P1 = round(op10_process_time_P1, 5)

        body_P1.append(op10_process_time_P1)
        body_P1.append(datetime.now() + timedelta(hours=9))

        print('두개 생산 중')
        time.sleep(10)  # 10초 텀

        # op20 공정 실행 (W2P0)
        op20_data_P0 = machine_operate.op20(
            op10_data_list_P0)  # <- 앞공정 재공품 받아서 실행 //  리스트를 넣어줌
        product_key_W2P0 = op20_data_P0['product_key']

        #################################### W2P0 생산 및 DB 저장 완료 #####################################

        # op10 공정 실행 (W1P1)
        op10_data_P1 = machine_operate.op10(body_P1)
        product_key_W1P1 = op10_data_P1['product_key']

        #################################### W1P1 생산 및 DB 저장 완료 #####################################

        # 다음 공정에 넣기 위한 데이터 가져오기
        op20_data_P0_from_DB = MySQL_query.get_quality_data_for_process(
            product_key_W2P0)
        # 다음 공정에 넣기 위한 데이터 가져오기
        op10_data_P1_from_DB = MySQL_query.get_quality_data_for_process(
            product_key_W1P1)

        # op20 P0 생산 끝낸 데이터를 다음 공정에 넣을 변수에 저장하기
        op20_data_list_P0 = []

        product_key_W3P0 = '-' + 'W3' + 'P' + str(n)  # 제품 키 생성
        op20_l_P0 = op20_data_P0_from_DB[0]['product_size_l']
        op20_w_P0 = op20_data_P0_from_DB[0]['product_size_w']
        op20_h_P0 = op20_data_P0_from_DB[0]['product_size_h']

        op20_timestamp_P0 = op20_data_P0_from_DB[0][
            'product_test_timestamp']  # op20 끝난시간

        op30_process_time_P0 = np.random.triangular(
            9, 10, 10)  # 다음 공정에 넣어줄 process_time
        op30_process_time_P0 = round(op30_process_time_P0, 5)

        op30_start_time_P0 = datetime.now() + timedelta(hours=9)

        op20_data_list_P0.append(product_key_W3P0)
        op20_data_list_P0.append(op20_l_P0)
        op20_data_list_P0.append(op20_w_P0)
        op20_data_list_P0.append(op20_h_P0)
        op20_data_list_P0.append(op30_process_time_P0)
        op20_data_list_P0.append(op30_start_time_P0)

        # op10 P1 생산 끝낸 데이터를 다음 공정에 넣을 변수에 저장하기
        op10_data_list_P1 = []

        product_key_W2P1 = '-' + 'W2' + 'P' + str(n + 1)  # 제품 키 생성
        op10_l_P1 = op10_data_P1_from_DB[0]['product_size_l']
        op10_w_P1 = op10_data_P1_from_DB[0]['product_size_w']
        op10_h_P1 = op10_data_P1_from_DB[0]['product_size_h']

        op10_timestamp_P1 = op10_data_P1_from_DB[0][
            'product_test_timestamp']  # op20 끝난시간

        op20_process_time_P1 = np.random.triangular(
            9, 10, 10)  # 다음 공정에 넣어줄 process_time
        op20_process_time_P1 = round(op20_process_time_P1, 5)

        op20_start_time_P1 = datetime.now() + timedelta(hours=9)

        op10_data_list_P1.append(
            product_key_W2P1)  # 재공품 데이터 -> 다음 공정에 투입 (P1제품)
        op10_data_list_P1.append(op10_l_P1)
        op10_data_list_P1.append(op10_w_P1)
        op10_data_list_P1.append(op10_h_P1)
        op10_data_list_P1.append(op20_process_time_P1)
        op10_data_list_P1.append(op20_start_time_P1)

        body_P2 = []  # P1 제품에 대한 body 값 저장할 리스트

        product_key_W1P2 = '-' + 'W1' + 'P' + str(
            n + 2)  # 첫번째 제품 primary_key 생성 -> machine에서 시간 추가할 예정
        body_P2.append(product_key_W1P2)

        body_l_P2 = np.random.normal(200, std)  # body 치수 데이터 생성
        body_l_P2 = round(body_l_P2, 5)
        body_P2.append(body_l_P2)

        body_w_P2 = np.random.normal(100, std)
        body_w_P2 = round(body_w_P2, 5)
        body_P2.append(body_w_P2)

        body_h_P2 = np.random.normal(50, std)
        body_h_P2 = round(body_h_P2, 5)
        body_P2.append(body_h_P2)

        op10_process_time_P2 = np.random.triangular(9, 10,
                                                    10)  # process_time 생성
        op10_process_time_P2 = round(op10_process_time_P2, 5)

        body_P2.append(op10_process_time_P2)
        body_P2.append(datetime.now() +
                       timedelta(hours=9))  # 세번째 제품은 P1 끝난시간부터 시작

        # op30, 20, 10 시작

        print('세개 생산 중')
        time.sleep(10)

        # op30 공정 실행 (W3P0)
        op30_data_P0 = machine_operate.op30(
            op20_data_list_P0)  # <- 앞공정 재공품 받아서 실행

        pred_P0 = Predict.predict_quality(op10_data_P0, op20_data_P0,
                                          op30_data_P0)
        print("P0 예측값 : " + str(pred_P0))

        MySQL_query.insert_product_prediction(op30_data_P0, op20_data_P0,
                                              op10_data_P0, pred_P0)

        product_key_W3P0 = op30_data_P0['product_key']

        #################################### W3P0 생산 및 DB 저장 완료 #####################################

        # op20 공정 실행 (W2P1)
        op20_data_P1 = machine_operate.op20(
            op10_data_list_P1)  # <- 앞공정 재공품 받아서 실행
        product_key_W2P1 = op20_data_P1['product_key']

        #################################### W2P1 생산 및 DB 저장 완료 #####################################

        # op10 공정 실행 (W1P2)
        op10_data_P2 = machine_operate.op10(body_P2)
        product_key_W1P2 = op10_data_P2['product_key']

        #################################### W1P2 생산 및 DB 저장 완료 #####################################

        # 다음 공정에 넣기 위한 데이터 가져오기
        op30_data_P0_from_DB = MySQL_query.get_quality_data_for_process(
            product_key_W3P0)
        # 다음 공정에 넣기 위한 데이터 가져오기
        op20_data_P1_from_DB = MySQL_query.get_quality_data_for_process(
            product_key_W2P1)
        # 다음 공정에 넣기 위한 데이터 가져오기
        op10_data_P2_from_DB = MySQL_query.get_quality_data_for_process(
            product_key_W1P2)

        # op30 P0 생산 끝낸 데이터를 다음 공정에 넣을 변수에 저장하기
        op30_data_list_P0 = []

        product_key_W4P0 = '-' + 'W4' + 'P' + str(n)  # 제품 키 생성
        op30_l_P0 = op30_data_P0_from_DB[0]['product_size_l']
        op30_w_P0 = op30_data_P0_from_DB[0]['product_size_w']
        op30_h_P0 = op30_data_P0_from_DB[0]['product_size_h']

        op30_timestamp_P0 = op30_data_P0_from_DB[0][
            'product_test_timestamp']  # op20 끝난시간

        op40_process_time_P0 = np.random.triangular(
            9, 10, 10)  # 다음 공정에 넣어줄 process_time
        op40_process_time_P0 = round(op40_process_time_P0, 5)

        op40_start_time_P0 = datetime.now() + timedelta(hours=9)

        op30_data_list_P0.append(product_key_W4P0)
        op30_data_list_P0.append(op30_l_P0)
        op30_data_list_P0.append(op30_w_P0)
        op30_data_list_P0.append(op30_h_P0)
        op30_data_list_P0.append(op40_process_time_P0)
        op30_data_list_P0.append(op40_start_time_P0)

        # op20 P1 생산 끝낸 데이터를 다음 공정에 넣을 변수에 저장하기
        op20_data_list_P1 = []

        product_key_W3P1 = '-' + 'W3' + 'P' + str(n + 1)  # 제품 키 생성
        op20_l_P1 = op20_data_P1_from_DB[0]['product_size_l']
        op20_w_P1 = op20_data_P1_from_DB[0]['product_size_w']
        op20_h_P1 = op20_data_P1_from_DB[0]['product_size_h']

        op30_process_time_P1 = np.random.triangular(
            9, 10, 10)  # 다음 공정에 넣어줄 process_time
        op30_process_time_P1 = round(op30_process_time_P1, 5)

        op30_start_time_P1 = datetime.now() + timedelta(hours=9)

        op20_data_list_P1.append(product_key_W3P1)
        op20_data_list_P1.append(op20_l_P1)
        op20_data_list_P1.append(op20_w_P1)
        op20_data_list_P1.append(op20_h_P1)
        op20_data_list_P1.append(op30_process_time_P1)
        op20_data_list_P1.append(op30_start_time_P1)

        # op10 P2 생산 끝낸 데이터를 다음 공정에 넣을 변수에 저장하기
        op10_data_list_P2 = []

        product_key_W2P2 = '-' + 'W2' + 'P' + str(n + 2)  # 제품 키 생성
        op10_l_P2 = op10_data_P2_from_DB[0]['product_size_l']
        op10_w_P2 = op10_data_P2_from_DB[0]['product_size_w']
        op10_h_P2 = op10_data_P2_from_DB[0]['product_size_h']

        op20_process_time_P2 = np.random.triangular(
            9, 10, 10)  # 다음 공정에 넣어줄 process_time
        op20_process_time_P2 = round(op20_process_time_P2, 5)

        op20_start_time_P2 = datetime.now() + timedelta(hours=9)

        op10_data_list_P2.append(product_key_W2P2)
        op10_data_list_P2.append(op10_l_P2)
        op10_data_list_P2.append(op10_w_P2)
        op10_data_list_P2.append(op10_h_P2)
        op10_data_list_P2.append(op20_process_time_P2)
        op10_data_list_P2.append(op20_start_time_P2)

        body_P3 = []  # P3 제품에 대한 body 값 저장할 리스트

        product_key_W1P3 = '-' + 'W1' + 'P' + str(
            n + 3)  # 첫번째 제품 primary_key 생성 -> machine에서 시간 추가할 예정
        body_P3.append(product_key_W1P3)

        body_l_P2 = np.random.normal(200, std)  # body 치수 데이터 생성
        body_l_P2 = round(body_l_P2, 5)
        body_P3.append(body_l_P2)

        body_w_P2 = np.random.normal(100, std)
        body_w_P2 = round(body_w_P2, 5)
        body_P3.append(body_w_P2)

        body_h_P2 = np.random.normal(50, std)
        body_h_P2 = round(body_h_P2, 5)
        body_P3.append(body_h_P2)

        op10_process_time_P2 = np.random.triangular(9, 10,
                                                    10)  # process_time 생성
        op10_process_time_P2 = round(op10_process_time_P2, 5)

        body_P3.append(op10_process_time_P2)
        body_P3.append(datetime.now() + timedelta(hours=9))

        print('네개 생산 중')
        time.sleep(10)

        # op40 공정 실행 (W4P0)
        op40_data_P0 = machine_operate.op40(
            op30_data_list_P0)  # <- 앞공정 재공품 받아서 실행
        product_key_W4P0 = op40_data_P0['product_key']

        #################################### W4P0 생산 및 DB 저장 완료 #####################################

        # op30 공정 실행 (W3P1)
        op30_data_P1 = machine_operate.op30(
            op20_data_list_P1)  # <- 앞공정 재공품 받아서 실행

        pred_P1 = Predict.predict_quality(op10_data_P1, op20_data_P1,
                                          op30_data_P1)
        print("P1 예측값 : " + str(pred_P1))

        MySQL_query.insert_product_prediction(op30_data_P1, op20_data_P1,
                                              op10_data_P1, pred_P1)

        product_key_W3P1 = op30_data_P1['product_key']

        #################################### W3P1 생산 및 DB 저장 완료 #####################################

        # op20 공정 실행 (W2P2)
        op20_data_P2 = machine_operate.op20(op10_data_list_P2)
        product_key_W2P2 = op20_data_P2['product_key']

        #################################### W2P2 생산 및 DB 저장 완료 #####################################

        # op10 공정 실행 (W1P3)
        op10_data_P3 = machine_operate.op10(body_P3)
        product_key_W1P3 = op10_data_P3['product_key']
        total_test_data.append(op10_data_P3)

        #################################### W1P3 생산 및 DB 저장 완료 #####################################

        # 다음 공정에 넣기 위한 데이터 가져오기
        op40_data_P0_from_DB = MySQL_query.get_quality_data_for_process(
            product_key_W4P0)
        # 다음 공정에 넣기 위한 데이터 가져오기
        op30_data_P1_from_DB = MySQL_query.get_quality_data_for_process(
            product_key_W3P1)
        # 다음 공정에 넣기 위한 데이터 가져오기
        op20_data_P2_from_DB = MySQL_query.get_quality_data_for_process(
            product_key_W2P2)
        # 다음 공정에 넣기 위한 데이터 가져오기
        op10_data_P3_from_DB = MySQL_query.get_quality_data_for_process(
            product_key_W1P3)

        # op40 P0 생산 끝낸 데이터를 다음 공정에 넣을 변수에 저장하기
        op40_data_list_P0 = []

        product_key_W5P0 = '-' + 'W5' + 'P' + str(n)  # 제품 키 생성
        op40_l_P0 = op40_data_P0_from_DB[0]['product_size_l']
        op40_w_P0 = op40_data_P0_from_DB[0]['product_size_w']
        op40_h_P0 = op40_data_P0_from_DB[0]['product_size_h']

        op40_timestamp_P0 = op40_data_P0_from_DB[0][
            'product_test_timestamp']  # op20 끝난시간

        op50_process_time_P0 = np.random.triangular(
            9, 10, 10)  # 다음 공정에 넣어줄 process_time
        op50_process_time_P0 = round(op50_process_time_P0, 5)

        op50_start_time_P0 = datetime.now() + timedelta(hours=9)

        op40_data_list_P0.append(product_key_W5P0)
        op40_data_list_P0.append(op40_l_P0)
        op40_data_list_P0.append(op40_w_P0)
        op40_data_list_P0.append(op40_h_P0)
        op40_data_list_P0.append(op50_process_time_P0)
        op40_data_list_P0.append(op50_start_time_P0)

        # op30 P1 생산 끝낸 데이터를 다음 공정에 넣을 변수에 저장하기
        op30_data_list_P1 = []

        product_key_W4P1 = '-' + 'W4' + 'P' + str(n + 1)  # 제품 키 생성
        op30_l_P1 = op30_data_P1_from_DB[0]['product_size_l']
        op30_w_P1 = op30_data_P1_from_DB[0]['product_size_w']
        op30_h_P1 = op30_data_P1_from_DB[0]['product_size_h']

        op30_timestamp_P1 = op30_data_P1_from_DB[0][
            'product_test_timestamp']  # op30 끝난시간

        op40_process_time_P1 = np.random.triangular(
            9, 10, 10)  # 다음 공정에 넣어줄 process_time
        op40_process_time_P1 = round(op40_process_time_P1, 5)

        op40_start_time_P1 = datetime.now() + timedelta(hours=9)

        op30_data_list_P1.append(product_key_W4P1)
        op30_data_list_P1.append(op30_l_P1)
        op30_data_list_P1.append(op30_w_P1)
        op30_data_list_P1.append(op30_h_P1)
        op30_data_list_P1.append(op40_process_time_P1)
        op30_data_list_P1.append(op40_start_time_P1)

        # op20 P2 생산 끝낸 데이터를 다음 공정에 넣을 변수에 저장하기
        op20_data_list_P2 = []

        product_key_W3P2 = '-' + 'W3' + 'P' + str(n + 2)  # 제품 키 생성
        op20_l_P2 = op20_data_P2_from_DB[0]['product_size_l']
        op20_w_P2 = op20_data_P2_from_DB[0]['product_size_w']
        op20_h_P2 = op20_data_P2_from_DB[0]['product_size_h']

        op30_process_time_P2 = np.random.triangular(
            9, 10, 10)  # 다음 공정에 넣어줄 process_time
        op30_process_time_P2 = round(op30_process_time_P2, 5)

        op30_start_time_P2 = datetime.now() + timedelta(hours=9)

        op20_data_list_P2.append(product_key_W3P2)
        op20_data_list_P2.append(op20_l_P2)
        op20_data_list_P2.append(op20_w_P2)
        op20_data_list_P2.append(op20_h_P2)
        op20_data_list_P2.append(op30_process_time_P2)
        op20_data_list_P2.append(op30_start_time_P2)

        # op10 P1 생산 끝낸 데이터를 다음 공정에 넣을 변수에 저장하기
        op10_data_list_P3 = []

        product_key_W2P3 = '-' + 'W2' + 'P' + str(n + 3)  # 제품 키 생성
        op10_l_P3 = op10_data_P3_from_DB[0]['product_size_l']
        op10_w_P3 = op10_data_P3_from_DB[0]['product_size_w']
        op10_h_P3 = op10_data_P3_from_DB[0]['product_size_h']

        op20_process_time_P3 = np.random.triangular(
            9, 10, 10)  # 다음 공정에 넣어줄 process_time
        op20_process_time_P3 = round(op20_process_time_P3, 5)

        op20_start_time_P3 = datetime.now() + timedelta(hours=9)

        op10_data_list_P3.append(product_key_W2P3)
        op10_data_list_P3.append(op10_l_P3)
        op10_data_list_P3.append(op10_w_P3)
        op10_data_list_P3.append(op10_h_P3)
        op10_data_list_P3.append(op20_process_time_P3)
        op10_data_list_P3.append(op20_start_time_P3)

        body_P4 = []  # P1 제품에 대한 body 값 저장할 리스트

        product_key_W1P4 = '-' + 'W1' + 'P' + str(
            n + 4)  # 첫번째 제품 primary_key 생성 -> machine에서 시간 추가할 예정
        body_P4.append(product_key_W1P4)

        body_l_P3 = np.random.normal(200, std)  # body 치수 데이터 생성
        body_l_P3 = round(body_l_P3, 5)
        body_P4.append(body_l_P3)

        body_w_P3 = np.random.normal(100, std)
        body_w_P3 = round(body_w_P3, 5)
        body_P4.append(body_w_P3)

        body_h_P3 = np.random.normal(50, std)
        body_h_P3 = round(body_h_P3, 5)
        body_P4.append(body_h_P3)

        op10_process_time_P3 = np.random.triangular(9, 10,
                                                    10)  # process_time 생성
        op10_process_time_P3 = round(op10_process_time_P3, 5)

        body_P4.append(op10_process_time_P3)
        body_P4.append(datetime.now() +
                       timedelta(hours=9))  # 다섯 번째 제품은 P3 끝난시간부터 시작

        print('다섯개 생산 중')
        time.sleep(10)

        # op50 공정 실행 (W5P0)
        op50_data_P0 = machine_operate.op50(
            op40_data_list_P0)  # <- 앞공정 재공품 받아서 실행
        product_key_W5P0 = op50_data_P0['product_key']

        #################################### W5P0 생산 및 DB 저장 완료 #####################################

        # op40 공정 실행 (W4P1)
        op40_data_P1 = machine_operate.op40(
            op30_data_list_P1)  # <- 앞공정 재공품 받아서 실행
        product_key_W4P1 = op40_data_P1['product_key']

        #################################### W4P1 생산 및 DB 저장 완료 #####################################

        # op30 공정 실행 (W3P2)
        op30_data_P2 = machine_operate.op30(
            op20_data_list_P2)  # <- 앞공정 재공품 받아서 실행

        pred_P2 = Predict.predict_quality(op10_data_P2, op20_data_P2,
                                          op30_data_P2)
        print("P2 예측값 : " + str(pred_P2))

        MySQL_query.insert_product_prediction(op30_data_P2, op20_data_P2,
                                              op10_data_P2, pred_P2)

        product_key_W3P2 = op30_data_P2['product_key']

        #################################### W3P2 생산 및 DB 저장 완료 #####################################

        # op20 공정 실행 (W2P3)
        op20_data_P3 = machine_operate.op20(op10_data_list_P3)
        product_key_W2P3 = op20_data_P3['product_key']
        total_test_data.append(op20_data_P3)

        #################################### W2P3 생산 및 DB 저장 완료 #####################################

        # op10 공정 실행 (W1P4)
        op10_data_P4 = machine_operate.op10(body_P4)
        product_key_W1P4 = op10_data_P4['product_key']
        total_test_data.append(op10_data_P4)

        #################################### W1P4 생산 및 DB 저장 완료 #####################################

        # 여기서부터 6개씩 반복
        print('for문 진입')

        for i in range(n + 5, 100000):  # 6번째 제품부터 반복 시작

            op10_process_time = np.random.triangular(9, 10, 10)
            op10_process_time = round(op10_process_time, 5)

            op20_process_time = np.random.triangular(9, 10, 10)
            op20_process_time = round(op20_process_time, 5)

            op30_process_time = np.random.triangular(9, 10, 10)
            op30_process_time = round(op30_process_time, 5)

            op40_process_time = np.random.triangular(9, 10, 10)
            op40_process_time = round(op40_process_time, 5)

            op50_process_time = np.random.triangular(9, 10, 10)
            op50_process_time = round(op50_process_time, 5)

            op60_process_time = np.random.triangular(9, 10, 10)
            op60_process_time = round(op60_process_time, 5)

            if i == n + 5:  # 딱 처음 for 문 진입했을 때만 실행

                op50_data_P0_from_DB = MySQL_query.get_quality_data_for_process(
                    product_key_W5P0)  # 전 공정에서 끝나고 결과 데이터

                op50_WIP = []  # op60에 넣기 위한 리스트

                product_key_W6P0 = '-' + 'W6' + 'P' + str(i - 5)  # key값 부여
                op50_l_P0 = op50_data_P0_from_DB[0][
                    'product_size_l']  # 데이터 나눠서 변수에 저장
                op50_w_P0 = op50_data_P0_from_DB[0]['product_size_w']
                op50_h_P0 = op50_data_P0_from_DB[0]['product_size_h']
                op60_start_time = op50_data_P0_from_DB[0][
                    'product_test_timestamp']

                op50_WIP.append(product_key_W6P0)  # 변수에 저장한거 하나씩 리스테에 저장
                op50_WIP.append(op50_l_P0)
                op50_WIP.append(op50_w_P0)
                op50_WIP.append(op50_h_P0)
                op50_WIP.append(op60_process_time)
                op50_WIP.append(op60_start_time)

                op40_data_P1_from_DB = MySQL_query.get_quality_data_for_process(
                    product_key_W4P1)
                op40_WIP = []
                product_key_W5P1 = '-' + 'W5' + 'P' + str(i - 4)
                op40_l_P1 = op40_data_P1_from_DB[0]['product_size_l']
                op40_w_P1 = op40_data_P1_from_DB[0]['product_size_w']
                op40_h_P1 = op40_data_P1_from_DB[0]['product_size_h']
                op50_start_time = op40_data_P1_from_DB[0][
                    'product_test_timestamp']

                op40_WIP.append(product_key_W5P1)
                op40_WIP.append(op40_l_P1)
                op40_WIP.append(op40_w_P1)
                op40_WIP.append(op40_h_P1)
                op40_WIP.append(op50_process_time)
                op40_WIP.append(op50_start_time)

                op30_data_P2_from_DB = MySQL_query.get_quality_data_for_process(
                    product_key_W3P2)
                op30_WIP = []
                product_key_W4P2 = '-' + 'W4' + 'P' + str(i - 3)
                op30_l_P2 = op30_data_P2_from_DB[0]['product_size_l']
                op30_w_P2 = op30_data_P2_from_DB[0]['product_size_w']
                op30_h_P2 = op30_data_P2_from_DB[0]['product_size_h']
                op40_start_time = op30_data_P2_from_DB[0][
                    'product_test_timestamp']

                op30_WIP.append(product_key_W4P2)
                op30_WIP.append(op30_l_P2)
                op30_WIP.append(op30_w_P2)
                op30_WIP.append(op30_h_P2)
                op30_WIP.append(op40_process_time)
                op30_WIP.append(op40_start_time)

                op20_data_P3_from_DB = MySQL_query.get_quality_data_for_process(
                    product_key_W2P3)
                op20_WIP = []
                product_key_W3P3 = '-' + 'W3' + 'P' + str(i - 2)
                op20_l_P3 = op20_data_P3_from_DB[0]['product_size_l']
                op20_w_P3 = op20_data_P3_from_DB[0]['product_size_w']
                op20_h_P3 = op20_data_P3_from_DB[0]['product_size_h']
                op30_start_time = op20_data_P3_from_DB[0][
                    'product_test_timestamp']

                op20_WIP.append(product_key_W3P3)
                op20_WIP.append(op20_l_P3)
                op20_WIP.append(op20_w_P3)
                op20_WIP.append(op20_h_P3)
                op20_WIP.append(op30_process_time)
                op20_WIP.append(op30_start_time)

                op10_data_P4_from_DB = MySQL_query.get_quality_data_for_process(
                    product_key_W1P4)
                op10_WIP = []
                product_key_W2P4 = '-' + 'W2' + 'P' + str(i - 1)
                op10_l_P4 = op10_data_P4_from_DB[0]['product_size_l']
                op10_w_P4 = op10_data_P4_from_DB[0]['product_size_w']
                op10_h_P4 = op10_data_P4_from_DB[0]['product_size_h']
                op20_start_time = op10_data_P4_from_DB[0][
                    'product_test_timestamp']

                op10_WIP.append(product_key_W2P4)
                op10_WIP.append(op10_l_P4)
                op10_WIP.append(op10_w_P4)
                op10_WIP.append(op10_h_P4)
                op10_WIP.append(op20_process_time)
                op10_WIP.append(op20_start_time)

                op10_time_stamp = datetime.now() + timedelta(hours=9)

            else:  # 한바퀴 돌고 난 다음
                op50_WIP = []
                product_key_W6 = '-' + 'W6' + 'P' + str(i - 5)

                op50_l = op50_data['op50_l']
                op50_w = op50_data['op50_w']
                op50_h = op50_data['op50_h']

                op50_WIP.append(product_key_W6)
                op50_WIP.append(op50_l)
                op50_WIP.append(op50_w)
                op50_WIP.append(op50_h)
                op50_WIP.append(op60_process_time)
                op50_WIP.append(datetime.now() + timedelta(hours=9))

                op40_WIP = []
                product_key_W5 = '-' + 'W5' + 'P' + str(i - 4)

                op40_l = op40_data['op40_l']
                op40_w = op40_data['op40_w']
                op40_h = op40_data['op40_h']

                op40_WIP.append(product_key_W5)
                op40_WIP.append(op40_l)
                op40_WIP.append(op40_w)
                op40_WIP.append(op40_h)
                op40_WIP.append(op50_process_time)
                op40_WIP.append(datetime.now() + timedelta(hours=9))

                op30_WIP = []
                product_key_W4 = '-' + 'W4' + 'P' + str(i - 3)

                op30_l = op30_data['op30_l']
                op30_w = op30_data['op30_w']
                op30_h = op30_data['op30_h']

                op30_WIP.append(product_key_W4)
                op30_WIP.append(op30_l)
                op30_WIP.append(op30_w)
                op30_WIP.append(op30_h)
                op30_WIP.append(op40_process_time)
                op30_WIP.append(datetime.now() + timedelta(hours=9))

                op20_WIP = []
                product_key_W3 = '-' + 'W3' + 'P' + str(i - 2)

                op20_l = op20_data['op20_l']
                op20_w = op20_data['op20_w']
                op20_h = op20_data['op20_h']

                op20_WIP.append(product_key_W3)
                op20_WIP.append(op20_l)
                op20_WIP.append(op20_w)
                op20_WIP.append(op20_h)
                op20_WIP.append(op30_process_time)
                op20_WIP.append(datetime.now() + timedelta(hours=9))

                op10_WIP = []
                product_key_W2 = '-' + 'W2' + 'P' + str(i - 1)

                op10_l = op10_data['op10_l']
                op10_w = op10_data['op10_w']
                op10_h = op10_data['op10_h']

                op10_WIP.append(product_key_W2)
                op10_WIP.append(op10_l)
                op10_WIP.append(op10_w)
                op10_WIP.append(op10_h)
                op10_WIP.append(op20_process_time)
                op10_WIP.append(datetime.now() + timedelta(hours=9))

            # 새 제품 생산
            body = []

            product_key_W1 = '-' + 'W1' + 'P' + str(i)

            body_l = np.random.normal(200, std)  # body 치수 데이터 생성
            body_l = round(body_l, 5)
            body_w = np.random.normal(100, std)  # body 치수 데이터 생성
            body_w = round(body_w, 5)
            body_h = np.random.normal(50, std)  # body 치수 데이터 생성
            body_h = round(body_h, 5)

            op10_time_stamp = datetime.now() + timedelta(hours=9)

            body.append(product_key_W1)
            body.append(body_l)
            body.append(body_w)
            body.append(body_h)
            body.append(op10_process_time)
            body.append(op10_time_stamp)  # 시작 시간

            time.sleep(10)  # 공정 실행

            # 공정들 6개 실행
            op60_data = machine_operate.op60(op50_WIP)
            op50_data = machine_operate.op50(op40_WIP)
            op40_data = machine_operate.op40(op30_WIP)
            op30_data = machine_operate.op30(op20_WIP)
            op20_data = machine_operate.op20(op10_WIP)
            op10_data = machine_operate.op10(body)

            total_test_data.append(op30_data)
            total_test_data.append(op20_data)
            total_test_data.append(op10_data)

            op10_data = total_test_data.pop(0)
            op20_data = total_test_data.pop(0)
            op30_data = total_test_data.pop(1)

            pred = Predict.predict_quality(op10_data, op20_data, op30_data)
            print('P' + str(i - 2) + ' 품질 예측값: ' + str(pred))

            MySQL_query.insert_product_prediction(op30_data, op20_data,
                                                  op10_data, pred)

            now_product = op60_data['product_key']

            print('6개 생산 완료! %s 제품이 생산되었습니다.' % (now_product))

        return "공정 실행 완료!"
예제 #26
0
    def op10(body):
        op10_data = {}
        std = 0.0025

        product_key = body[0]

        wavyfin_l = np.random.normal(100, std)
        wavyfin_l = round(wavyfin_l, 5)

        wavyfin_w = np.random.normal(50, std)
        wavyfin_w = round(wavyfin_w, 5)

        wavyfin_h = np.random.normal(60, std)
        wavyfin_h = round(wavyfin_h, 5)

        op10_electricity = np.random.uniform(89, 100)
        op10_electricity = round(op10_electricity, 5)

        op10_data['product_key'] = product_key
        op10_data['body_l'] = body[1]
        op10_data['body_w'] = body[2]
        op10_data['body_h'] = body[3]

        op10_data['wavyfin_l'] = wavyfin_l
        op10_data['wavyfin_w'] = wavyfin_w
        op10_data['wavyfin_h'] = wavyfin_h

        op10_l = body[1]
        op10_data['op10_l'] = op10_l
        op10_w = body[2]
        op10_data['op10_w'] = op10_w
        op10_h = wavyfin_h
        op10_data['op10_h'] = op10_h

        op10_process_time = body[3]

        op10_data['op10_electricity'] = op10_electricity
        op10_data['op10_process_time'] = op10_process_time

        if (op10_l < 199.99) or (op10_l > 200.01):
            length_test = 1
        else:
            length_test = 0

        if (op10_w < 99.99) or (op10_w > 100.01):
            width_test = 1
        else:
            width_test = 0

        if (op10_h < 59.99) or (op10_h > 60.01):
            height_test = 1
        else:
            height_test = 0

        if length_test == 0 and width_test == 0 and height_test == 0:
            op10_test = 'OK'
            op10_data['op10_test'] = op10_test
        else:
            op10_test = 'NOK'
            op10_data['op10_test'] = op10_test

        now = datetime.now()
        time_stamp = now + timedelta(seconds=op10_process_time)
        op10_data['op10_time_stamp'] = time_stamp
        time_stamp = str(time_stamp)

        product_key = time_stamp + product_key

        # product_history 적재
        product_history_data_list = []
        product_history_insert = {}
        op10_master_data = product_master.op10_WIP(1)
        product_code = op10_master_data['product_code']

        product_history_insert['product_key'] = product_key
        product_history_insert['product_code'] = product_code
        product_history_insert['product_timestamp'] = time_stamp

        product_history_data_list.append(product_history_insert)

        MySQL_query.insert_product_history(product_history_data_list) # 히스토리 데이터 DB 적재

        # product_quality 적재
        product_quality_data_list = []  # 딕셔너리 데이터 저장할 리스트
        product_quality_insert = {}  # DB 저장할 데이터 모아주는 딕셔너리

        product_quality_insert['product_key'] = product_key
        product_quality_insert['product_size_l'] = str(op10_l)
        product_quality_insert['product_size_w'] = str(op10_w)
        product_quality_insert['product_size_h'] = str(op10_h)
        product_quality_insert['product_test'] = str(op10_test)
        product_quality_insert['product_test_timestamp'] = str(time_stamp)

        product_quality_data_list.append(product_quality_insert)

        MySQL_query.insert_product_quality(product_quality_data_list)  # 품질 데이터 DB 적재

        # machine 적재
        machine_data_list = []  # 딕셔너리 데이터 저장할 리스트
        machine_data_insert = {}  # DB 저장할 데이터 모아주는 딕셔너리

        machine_master_data = machine_master.op10(1) # machine_code 가져오기
        machine_code = machine_master_data['machine_code']

        machine_data_insert['machine_code'] = machine_code
        machine_data_insert['product_key'] = product_key
        machine_data_insert['start_time'] = str(now)
        machine_data_insert['end_time'] = str(time_stamp)
        machine_data_insert['makespan'] = '123'
        machine_data_insert['process_time'] = str(op10_process_time)
        machine_data_insert['machine_data'] = str(op10_electricity)
        machine_data_insert['machine_data_code'] = 'E01'

        machine_data_list.append(machine_data_insert)

        MySQL_query.insert_machine(machine_data_list)  # machine 데이터 DB 적재

        return op10_data
from SQL import MySQL_query
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split

machine_data = MySQL_query.get_machine_data_list_for_predict(1)
quality_data = MySQL_query.get_quality_data_list_for_predict(1)

machine_df = pd.DataFrame(machine_data)
quality_df = pd.DataFrame(quality_data)

product_key_list = []
body_l_list = []
body_w_list = []
body_h_list = []

wavyfin_l_list = []
wavyfin_w_list = []
wavyfin_h_list = []

op10_l_list = []
op10_w_list = []
op10_h_list = []

pipe1_l_list = []
pipe1_w_list = []
pipe1_h_list = []

op20_l_list = []
op20_w_list = []
예제 #28
0
def product_master():
    product_master_data = []

    # EGR Cooler 제품
    master_dict = {}

    product_name = 'EGR_Cooler'
    product_code = 'EGRC'  # PK
    product_class = 'N01'
    product_num = 'P01'

    product_target_l = 'op60_l_260'
    product_target_w = 'op60_w_180'
    product_target_h = 'op60_h_60'

    master_dict['product_name'] = product_name
    master_dict['product_code'] = product_code  # PK
    master_dict['product_class'] = product_class
    master_dict['product_num'] = product_num
    master_dict['product_target_l'] = product_target_l
    master_dict['product_target_w'] = product_target_w
    master_dict['product_target_h'] = product_target_h

    product_master_data.append(master_dict)

    # op10 반제품
    master_dict = {}

    product_name = 'WIP10'
    product_code = 'op10_WIP'  # PK
    product_class = 'N02'
    product_num = 'WIP1'

    product_target_l = 'op10_l_200'
    product_target_w = 'op10_w_100'
    product_target_h = 'op10_h_60'

    master_dict['product_name'] = product_name
    master_dict['product_code'] = product_code  # PK
    master_dict['product_class'] = product_class
    master_dict['product_num'] = product_num

    master_dict['product_target_l'] = product_target_l
    master_dict['product_target_w'] = product_target_w
    master_dict['product_target_h'] = product_target_h

    product_master_data.append(master_dict)

    # op20 반제품
    master_dict = {}

    product_name = 'WIP20'
    product_code = 'op20_WIP'  # PK
    product_class = 'N02'
    product_num = 'WIP2'

    product_target_l = 'op20_l_200'
    product_target_w = 'op20_w_140'
    product_target_h = 'op20_h_60'

    master_dict['product_name'] = product_name
    master_dict['product_code'] = product_code  # PK
    master_dict['product_class'] = product_class
    master_dict['product_num'] = product_num

    master_dict['product_target_l'] = product_target_l
    master_dict['product_target_w'] = product_target_w
    master_dict['product_target_h'] = product_target_h

    product_master_data.append(master_dict)

    # op30 반제품
    master_dict = {}

    product_name = 'WIP30'
    product_code = 'op30_WIP'  # PK
    product_class = 'N02'
    product_num = 'WIP3'

    product_target_l = 'op30_l_200'
    product_target_w = 'op30_w_180'
    product_target_h = 'op30_h_60'

    master_dict['product_name'] = product_name
    master_dict['product_code'] = product_code  # PK
    master_dict['product_class'] = product_class
    master_dict['product_num'] = product_num

    master_dict['product_target_l'] = product_target_l
    master_dict['product_target_w'] = product_target_w
    master_dict['product_target_h'] = product_target_h

    product_master_data.append(master_dict)

    # op40 반제품
    master_dict = {}

    product_name = 'WIP40'
    product_code = 'op40_WIP'  # PK
    product_class = 'N02'
    product_num = 'WIP4'

    product_target_l = 'op40_l_230'
    product_target_w = 'op40_w_180'
    product_target_h = 'op40_h_60'

    master_dict['product_name'] = product_name
    master_dict['product_code'] = product_code  # PK
    master_dict['product_class'] = product_class
    master_dict['product_num'] = product_num

    master_dict['product_target_l'] = product_target_l
    master_dict['product_target_w'] = product_target_w
    master_dict['product_target_h'] = product_target_h

    product_master_data.append(master_dict)

    # op50 반제품
    master_dict = {}

    product_name = 'WIP50'
    product_code = 'op50_WIP'  # PK
    product_class = 'N02'
    product_num = 'WIP5'

    product_target_l = 'op50_l_260'
    product_target_w = 'op50_w_180'
    product_target_h = 'op50_h_60'

    master_dict['product_name'] = product_name
    master_dict['product_code'] = product_code  # PK
    master_dict['product_class'] = product_class
    master_dict['product_num'] = product_num

    master_dict['product_target_l'] = product_target_l
    master_dict['product_target_w'] = product_target_w
    master_dict['product_target_h'] = product_target_h

    product_master_data.append(master_dict)

    # body 부품
    master_dict = {}

    product_name = 'body_part'
    product_code = 'body'  # PK
    product_class = 'N03'
    product_num = 'PART1'

    product_target_l = 'body_l_200'
    product_target_w = 'body_w_100'
    product_target_h = 'body_h_50'

    master_dict['product_name'] = product_name
    master_dict['product_code'] = product_code  # PK
    master_dict['product_class'] = product_class
    master_dict['product_num'] = product_num

    master_dict['product_target_l'] = product_target_l
    master_dict['product_target_w'] = product_target_w
    master_dict['product_target_h'] = product_target_h

    product_master_data.append(master_dict)

    # wavyfin 부품
    master_dict = {}

    product_name = 'wavyfin_part'
    product_code = 'wavyfin'  # PK
    product_class = 'N03'
    product_num = 'PART2'

    product_target_l = 'wavyfin_l_100'
    product_target_w = 'wavyfin_w_50'
    product_target_h = 'wavyfin_h_60'

    master_dict['product_name'] = product_name
    master_dict['product_code'] = product_code  # PK
    master_dict['product_class'] = product_class
    master_dict['product_num'] = product_num

    master_dict['product_target_l'] = product_target_l
    master_dict['product_target_w'] = product_target_w
    master_dict['product_target_h'] = product_target_h

    product_master_data.append(master_dict)

    # pipe1 부품
    master_dict = {}

    product_name = 'pipe1_part'
    product_code = 'pipe1'  # PK
    product_class = 'N03'
    product_num = 'PART3'

    product_target_l = 'pipe1_l_30'
    product_target_w = 'pipe1_w_50'
    product_target_h = 'pipe1_h_30'

    master_dict['product_name'] = product_name
    master_dict['product_code'] = product_code  # PK
    master_dict['product_class'] = product_class
    master_dict['product_num'] = product_num

    master_dict['product_target_l'] = product_target_l
    master_dict['product_target_w'] = product_target_w
    master_dict['product_target_h'] = product_target_h

    product_master_data.append(master_dict)

    # pipe2 부품
    master_dict = {}

    product_name = 'pipe2_part'
    product_code = 'pipe2'  # PK
    product_class = 'N03'
    product_num = 'PART4'

    product_target_l = 'pipe2_l_30'
    product_target_w = 'pipe2_w_50'
    product_target_h = 'pipe2_h_30'

    master_dict['product_name'] = product_name
    master_dict['product_code'] = product_code  # PK
    master_dict['product_class'] = product_class
    master_dict['product_num'] = product_num

    master_dict['product_target_l'] = product_target_l
    master_dict['product_target_w'] = product_target_w
    master_dict['product_target_h'] = product_target_h

    product_master_data.append(master_dict)

    # flange1 부품
    master_dict = {}

    product_name = 'flange1_part'
    product_code = 'flange1'  # PK
    product_class = 'N03'
    product_num = 'PART5'

    product_target_l = 'flange1_l_30'
    product_target_w = 'flange1_w_50'
    product_target_h = 'flange1_h_30'

    master_dict['product_name'] = product_name
    master_dict['product_code'] = product_code  # PK
    master_dict['product_class'] = product_class
    master_dict['product_num'] = product_num

    master_dict['product_target_l'] = product_target_l
    master_dict['product_target_w'] = product_target_w
    master_dict['product_target_h'] = product_target_h

    product_master_data.append(master_dict)

    # flange2 부품
    master_dict = {}

    product_name = 'flange2_part'
    product_code = 'flange2'  # PK
    product_class = 'N03'
    product_num = 'PART6'

    product_target_l = 'flange2_l_30'
    product_target_w = 'flange2_w_50'
    product_target_h = 'flange2_h_30'

    master_dict['product_name'] = product_name
    master_dict['product_code'] = product_code  # PK
    master_dict['product_class'] = product_class
    master_dict['product_num'] = product_num

    master_dict['product_target_l'] = product_target_l
    master_dict['product_target_w'] = product_target_w
    master_dict['product_target_h'] = product_target_h

    product_master_data.append(master_dict)

    MySQL_query.insert_product_master(product_master_data)

    return product_master_data
    def op60(op50):
        op60_data = {}
        std = 0.0025

        product_key = op50[0]

        op60_process_time = op50[4]

        op60_l = op50[1]
        op60_data['op60_l'] = op60_l

        op60_w = op50[2]
        op60_data['op60_w'] = op60_w

        op60_h = op50[3]
        op60_data['op60_h'] = op60_h

        op60_data['op60_process_time'] = op60_process_time

        if (op60_l < 259.99) or (op60_l > 260.01):
            length_test = 1
        else:
            length_test = 0

        if (op60_w < 179.99) or (op60_w > 180.01):
            width_test = 1
        else:
            width_test = 0

        if (op60_h < 59.99) or (op60_h > 60.01):
            height_test = 1
        else:
            height_test = 0

        if length_test == 0 and width_test == 0 and height_test == 0:
            op60_test = 'OK'
            op60_data['op60_test'] = op60_test
        else:
            op60_test = 'NOK'
            op60_data['op60_test'] = op60_test

        now = op50[5]
        time_stamp = now + timedelta(seconds=10)
        op60_data['op60_time_stamp'] = time_stamp
        time_stamp = str(time_stamp)

        product_key = time_stamp + product_key
        op60_data['product_key'] = product_key

        # product_history 적재
        product_history_data_list = []
        product_history_insert = {}
        op60_master_data = product_master.EGRC(1)
        product_code = op60_master_data['product_code']

        product_history_insert['product_key'] = product_key
        product_history_insert['product_code'] = product_code
        product_history_insert['product_timestamp'] = time_stamp

        product_history_data_list.append(product_history_insert)

        MySQL_query.insert_product_history(
            product_history_data_list)  # 히스토리 데이터 DB 적재

        # product_quality 적재
        product_quality_data_list = []  # 딕셔너리 데이터 저장할 리스트
        product_quality_insert = {}  # DB 저장할 데이터 모아주는 딕셔너리

        product_quality_insert['product_key'] = product_key
        product_quality_insert['product_size_l'] = str(op60_l)
        product_quality_insert['product_size_w'] = str(op60_w)
        product_quality_insert['product_size_h'] = str(op60_h)
        product_quality_insert['product_test'] = str(op60_test)
        product_quality_insert['product_test_timestamp'] = str(time_stamp)

        product_quality_data_list.append(product_quality_insert)

        MySQL_query.insert_product_quality(
            product_quality_data_list)  # 품질 데이터 DB 적재

        # machine 적재
        machine_data_list = []  # 딕셔너리 데이터 저장할 리스트
        machine_data_insert = {}  # DB 저장할 데이터 모아주는 딕셔너리

        machine_master_data = machine_master.op60(1)  # machine_code 가져오기
        machine_code = machine_master_data['machine_code']

        machine_data_insert['machine_code'] = machine_code
        machine_data_insert['product_key'] = product_key
        machine_data_insert['start_time'] = str(now)
        machine_data_insert['end_time'] = str(time_stamp)
        machine_data_insert['makespan'] = '123'
        machine_data_insert['process_time'] = str(op60_process_time)
        machine_data_insert['machine_data'] = str(131.1)
        machine_data_insert['machine_data_code'] = 'TEST'

        machine_data_list.append(machine_data_insert)

        MySQL_query.insert_machine(machine_data_list)  # machine 데이터 DB 적재

        return op60_data
    def count_product_today(self):  # 오늘 생산한 양품 갯수 리턴하는 함수
        data = MySQL_query.get_item_count_for_gauge()

        count_new_product = data[0]['item_count']

        return count_new_product