import logging from service.utils.module_tools import class_dict from .attr_gender_value_count import AttributeGenderValueCount from .attribute_group_average import AttributeGroupAverage from .attribute_group_value_count import AttributeGroupValueCount from .attribute_max import AttributeMax from .attribute_min import AttributeMin from .attribute_percent_of_total import AttributeGroupValuePercent from .attribute_rfm_components import AttributeRFMModelScoreComponents from .attribute_sum_by_segment import AttributeSumBySegment from .attribute_superfan_components import AttributeSuperfanModelScoreComponents from .attribute_value_count import AttributeValueCount from .attribute_value_histogram import AttributeValuePercentile from .attribute_values import AttributeValues from .collection_list import CollectionList from .interface import AnalyticsModuleInterface __all__ = [ "AttributeGenderValueCount", "AttributeGroupAverage", "AttributeGroupValueCount", "AttributeMax", "AttributeMin", "AttributeGroupValuePercent", "AttributeSuperfanModelScoreComponents", "AttributeSumBySegment", "AttributeRFMModelScoreComponents", "AttributeValueCount", "AttributeValuePercentile", "AttributeValues", "CollectionList", "AnalyticsModuleInterface", "MODULES", "get_am", ] logger = logging.getLogger(__name__) MODULES = class_dict(__name__, AnalyticsModuleInterface) def get_am(chart_conf): try: if "module" in chart_conf: name = chart_conf["module"] if name in MODULES: return ( MODULES[name](**chart_conf["inputs"]) if "inputs" in chart_conf else MODULES[name]() ) except Exception as e: logger.exception(e) raise RuntimeError("Unknown analytics module configuration")