class TesterWorkcell(unittest.TestCase): def setUp(self): self.step = 1 self.wc1 = Workcell(step_idx=self.step, id=1) def test_start_production(self): wp1 = Workpiece(id=1) data = { "Step": [self.step], "Production_Time_Min": [20], "Production_Time_Max": [80] } df = pd.DataFrame(data) self.wc1.add_to_production(wp1) self.wc1.start_production(worksheet_df=df) r1 = wp1.status a1 = "in production" self.assertEqual(a1, r1) def test_render_actual_quality(self): data = { "Step": [1, 1, 1, 2], "Possible_State": ["Pass", "Fail", "Nope", "Nope"] } worksheet = pd.DataFrame(data) r1 = self.wc1.render_actual_quality(worksheet) print(r1) r2 = sum([val for key, val in r1.items()]) a2 = 100 self.assertEqual(a2, r2) def test_assigned_inspection(self): import ast payload = { "qc_list": ["node1", "node2"], "workpiece_id": "wp_id", "execution_info": { "production_time": 1 } } headers = { 'Content-Type': "application/json", } r1 = requests.post('http://localhost:5000/wc_1/inspection/assignment', data=json.dumps(payload), headers=headers) print(r1.text) self.assertIsInstance(r1.text, str) r2 = ast.literal_eval(r1.text) self.assertIsInstance(r2, dict)
def instantiate_objects(threshold, score_list, learning): # Instantiate objects print("Instantiating objects...") workcells = { f"wc_{i+1}": Workcell(step_idx=i + 1, id=f"wc_{i+1}", ip=ip, port=port, qc_id=f"wc_{i + 1}", consensus_mode="confidence", threshold=threshold, score=score_list[i], capability=capability_list[i], learning=learning) for i in range(total_workcells) } workpieces = { f"wp_{i+1}": Workpiece(id=f"wp_{i+1}") for i in range(total_products) } process_controllers = { # each workpiece has one process controller f"wp_{i+1}": ProcessController(workpiece_id=f"wc_{i+1}") # same name as workpiece for i in range(total_products) } transporter = Transporter() print("Objects instantiated...") return workcells, workpieces, transporter, process_controllers
def instantiate_objects(threshold, consensus_mode, score_list, learning): # Instantiate objects print("Instantiating objects...") # Instantiate objects quality_controllers = { f"wc_{i + 1}": Workcell( step_idx=i + 1, id=f"wc_{i + 1}", ip=ip, port=port, qc_id=f"wc_{i + 1}", consensus_mode=consensus_mode, threshold=threshold, score=1, learning=False ) for i in range(total_workcells) } print("Completed instantiating objects") workpieces = { f"wp_{i+1}": Workpiece(id=f"wp_{i+1}") for i in range(total_products) } transporter = Transporter() print("Objects instantiated...") return quality_controllers, workpieces, transporter
def test_get_next_step(self): workcells = { f"wc_{i + 1}": Workcell(step_idx=i + 1, id=f"wc_{i + 1}") for i in range(5) } self.p1.step_idx_status[1] = True r1, r2, r3 = self.p1.get_next_step_idx(workcells) a1 = [2, 3, 4] print(r2) print(r3) self.assertEqual(a1, r1)
def setUp(self): # app.config["TESTING"] = True self.app = app.test_client() total_workcells = 2 print("Instantiating objects...") quality_controllers = { f"wc_{i + 1}": Workcell(step_idx=i + 1, id=f"wc_{i + 1}", ip="localhost", port=5000, qc_id=f"wc_{i + 1}") for i in range(total_workcells) } print("Completed instantiating objects") add_routes(quality_controllers, 3) self.qc = quality_controllers["wc_1"] self.qc2 = quality_controllers["wc_2"] self.qc.register_workpiece("wp") self.qc2.register_workpiece("wp") print("Registering nodes...") payload = { "nodes": { qc_id: { "address": qc_inst.address } for qc_id, qc_inst in quality_controllers.items() } } for qc_id, qc_inst in quality_controllers.items(): res = self.app.post(f"{qc_inst.address}/blockchain/registration", data=json.dumps(payload), headers=headers) if res.status_code == 200: print(f"Nodes registered at {qc_id}.") else: raise ConnectionError( f"Node {qc_id} refuse to register nodes.") print("SetUp complete")
def setUp(self): self.step = 1 self.wc1 = Workcell(step_idx=self.step, id=1)
# score_list = [.4, .9, .7, .8, .7, .3, .2, .7, .1, .1, .1, .6, .6, .4, .1, .3, .8] # sim 2 input 11 # score_list = [.4, 1., .9, .9, .2, .5, .3, .6, .9, .7, .1, .3, .8, .2, .1, .8, .8] # sim 2 input 12 # score_list = [.4, 1., .2, .1, .5, .1, .6, .9, .5, 1., .8, .9, .8, .9, .5, .3, .5] # sim 2 input 13 # score_list = [.1, 1., .2, .5, .3, .5, .9, 1., .6, .6, .2, .1, .1, .5, .4, .2, .1] # sim 2 input 14 # score_list = [1., .8, .5, .2, .6, 1., .1, .6, .2, 1., .8, .5, .3, .2, 1., .8, .5] # sim 2 input 15 # score_list = [.7, .3, .2, .5, .5, .7, .6, .3, .8, 1., .3, .1, .2, .2, .2, .1, .9] # sim 2 input 16 # score_list = [.7, .8, .4, .1, .1, 1., 1., .1, .6, .3, .8, .9, .8, .2, .9, .8, .6] # sim 2 input 17 # score_list = [.7, .1, .1, .7, .8, .2, .9, .3, .1, .8, 1., 1., .1, .5, .5, .6, .6] # sim 2 input 18 # score_list = [.5, .2, .2, .4, .4, .1, .5, .1, .4, .5, .1, .1, .2, .1, .5, .3, .5] # sim 2 input 19 # score_list = [.1, .9, .6, .4, .1, .3, .9, .6, .7, 1., .1, .1, .1, 1., .4, .1, .7] # sim 2 input 20 workcells = { f"wc_{i+1}": Workcell( step_idx=i+1, id=f"wc_{i+1}", ip="localhost", port=5000, capability=score_list[i], # todo: Comment out to get randomly assigned capability ) for i in range(total_workcells) } workpieces = { f"wp_{i+1}": Workpiece(id=f"wp_{i+1}") for i in range(total_products) } process_controllers = { # each workpiece has one process controller f"wp_{i+1}": ProcessController(workpiece_id=f"wc_{i+1}") # same name as workpiece for i in range(total_products) } transporter = Transporter() print("Objects instantiated...")
rule=f'/{qc_id}/blockchain/registration', endpoint=f'{qc_id}_register_quality_controllers_{threshold}', view_func=qc_inst.register_quality_controllers, methods=['POST']) app.add_url_rule(rule=f'/{qc_id}/blockchain/mine', endpoint=f'{qc_id}_mine_{threshold}', view_func=qc_inst.mine, methods=['POST']) app.add_url_rule(rule=f'/{qc_id}/blockchain/consensus', endpoint=f'{qc_id}_consensus_{threshold}', view_func=qc_inst.consensus, methods=['POST']) if __name__ == '__main__': # Instantiate objects total_workcells = 17 print("Instantiating objects...") quality_controllers = { f"wc_{i + 1}": Workcell(step_idx=i + 1, id=f"wc_{i + 1}", ip="localhost", port=5000, qc_id=f"wc_{i + 1}") for i in range(total_workcells) } print("Completed instantiating objects") add_routes(quality_controllers) app.run(host='0.0.0.0', port=5000)