@@ -95,15 +95,14 @@ class Generator:
9595 def __init__ (self , component_group_name ):
9696 self .component_group_name = component_group_name
9797
98- def generate (self , main_config : dict ) -> dict [str , type [ Actor ] ]:
98+ def generate (self , main_config : dict ) -> dict [str , Actor ]:
9999 """
100100 Generate an actor class and actor start message from config dict
101101 """
102102 if self .component_group_name not in main_config :
103103 raise PowerAPIException ('Configuration error : no ' + self .component_group_name + ' specified' )
104104
105105 actors = {}
106-
107106 for component_name , component_config in main_config [self .component_group_name ].items ():
108107 try :
109108 actors [component_name ] = self ._gen_actor (component_config , main_config , component_name )
@@ -112,7 +111,7 @@ def generate(self, main_config: dict) -> dict[str, type[Actor]]:
112111
113112 return actors
114113
115- def _gen_actor (self , component_config : dict , main_config : dict , component_name : str ) -> type [ Actor ] :
114+ def _gen_actor (self , component_config : dict , main_config : dict , component_name : str ) -> Actor :
116115 raise NotImplementedError ()
117116
118117
@@ -346,6 +345,25 @@ def _actor_factory(self, actor_name: str, main_config: dict, component_config: d
346345 level_logger = logging .DEBUG if main_config [GENERAL_CONF_VERBOSE_KEY ] else logging .WARNING
347346 return PusherActor (actor_name , database , logger_level = level_logger )
348347
348+ def generate_report_type_to_actor_mapping (self , main_config : dict , actors : dict [str , Actor ]) -> dict [type [Report ], list [PusherActor ]]:
349+ """
350+ Generate the report type to actors mapping dict.
351+ :param main_config: Main configuration
352+ :param actors: Dictionary of actors (result of the `generate` method)
353+ :return: Dictionary mapping the report type to actors that should process it
354+ """
355+ if self .component_group_name not in main_config :
356+ raise PowerAPIException (f'Configuration error: Component "{ self .component_group_name } " is not defined' )
357+
358+ report_type_to_actor = {}
359+ for component_name , component_config in main_config [self .component_group_name ].items ():
360+ try :
361+ report_type_to_actor .setdefault (component_config [COMPONENT_MODEL_KEY ], []).append (actors [component_name ])
362+ except KeyError as exn :
363+ raise PowerAPIException (f'Undefined parameter for "{ component_name } " { self .component_group_name } ' ) from exn
364+
365+ return report_type_to_actor
366+
349367
350368class ProcessorGenerator (Generator ):
351369 """
0 commit comments