| 1 |  |  | """Contains factory class of process with calls stages.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 | 1 |  | from grortir.main.model.processes.calls_process import CallsProcess | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 | 1 |  | from grortir.main.model.stages.calls_stage import CallsStage | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 | 1 |  | class CallsProcessFactory: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |     """Class which produce process with the same type of stages. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |     Attributes: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |         structure_type (str): represent type of structure | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |         how_many_nodes (int): how many nodes should be in generated process | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |         max_calls (int): max_calls for stages | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |         process (CallsProcess): process which will be incrementally build | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |         initial_vec (tuple): initial vector | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     """ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 | 1 |  |     def __init__(self, structure_type, how_many_nodes, max_calls, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |                  initial_vec=()): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         """Constructor.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 | 1 |  |         self.max_calls = max_calls | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 | 1 |  |         self._stages_to_add = [] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 | 1 |  |         self.structure_type = structure_type | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 | 1 |  |         self.how_many_nodes = how_many_nodes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 | 1 |  |         self.process = CallsProcess() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 | 1 |  |         self.initial_vec = initial_vec | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 | 1 |  |     def _update_structure(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         """Update structure of process.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 | 1 |  |         if self.structure_type == "linear": | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 | 1 |  |             self.process.add_path(self._stages_to_add) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         else: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 | 1 |  |             raise NotImplementedError() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 | 1 |  |     def _create_stages(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         """Create stages which will be injected to process.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 | 1 |  |         for i in range(self.how_many_nodes): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 | 1 |  |             self._stages_to_add += [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |                 CallsStage(str(i), self.max_calls, self.initial_vec)] | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 41 | 1 |  |     def construct_process(self): | 
            
                                                        
            
                                    
            
            
                | 42 |  |  |         """Construct process.""" | 
            
                                                        
            
                                    
            
            
                | 43 | 1 |  |         self._create_stages() | 
            
                                                        
            
                                    
            
            
                | 44 | 1 |  |         self._update_structure() | 
            
                                                        
            
                                    
            
            
                | 45 |  |  |         return self.process | 
            
                                                        
            
                                    
            
            
                | 46 |  |  |  |