<commit_before>from abc import abstractmethod
from typing import Dict

import jsonpickle

from plenum.common.types import EVENT_PERIODIC_STATS_THROUGHPUT, \
    EVENT_NODE_STARTED, EVENT_REQ_ORDERED, EVENT_PERIODIC_STATS_LATENCIES, \
    PLUGIN_TYPE_STATS_CONSUMER, EVENT_VIEW_CHANGE
from plenum.common.util import getlogger
from plenum.config import STATS_SERVER_IP, STATS_SERVER_PORT
from plenum.server.plugin_loader import HasDynamicallyImportedModules
from plenum.server.stats_consumer import StatsConsumer
from .stats_publisher import StatsPublisher, Topic

logger = getlogger()


class FirebaseStatsConsumer(StatsConsumer, HasDynamicallyImportedModules):
    pluginType = PLUGIN_TYPE_STATS_CONSUMER

    def __init__(self):
        super().__init__()
        self.statsPublisher = StatsPublisher(STATS_SERVER_IP, STATS_SERVER_PORT)
        self._eventToFunc = {
            EVENT_REQ_ORDERED: self._sendStatsOnReqOrdered,
            EVENT_NODE_STARTED: self._sendStatsOnNodeStart,
            EVENT_PERIODIC_STATS_THROUGHPUT: self._periodicStatsThroughput,
            EVENT_VIEW_CHANGE: self._viewChange,
            EVENT_PERIODIC_STATS_LATENCIES: self._sendLatencies
        }

    @abstractmethod
    def isModuleImportedSuccessfully(self):
        return True

    def _send(self, data: Dict[str, object]):
        self.statsPublisher.send(jsonpickle.dumps(data))

    def sendStats(self, event: str, stats: Dict[str, object]):
        self._eventToFunc[event](stats)

    def _periodicStatsThroughput(self, stats: Dict[str, object]):
        stats["eventName"] = str(Topic.PublishMtrStats)
        self._send(stats)<commit_msg>fixing import error<commit_after>from abc import abstractmethod
from typing import Dict

import jsonpickle

from plenum.common.types import EVENT_PERIODIC_STATS_THROUGHPUT, \
    EVENT_NODE_STARTED, EVENT_REQ_ORDERED, EVENT_PERIODIC_STATS_LATENCIES, \
    PLUGIN_TYPE_STATS_CONSUMER, EVENT_VIEW_CHANGE
from plenum.common.util import getlogger
from plenum.config import STATS_SERVER_IP, STATS_SERVER_PORT
from plenum.server.plugin.stats_consumer.stats_publisher import StatsPublisher, \
    Topic
from plenum.server.plugin_loader import HasDynamicallyImportedModules
from plenum.server.stats_consumer import StatsConsumer

logger = getlogger()


class FirebaseStatsConsumer(StatsConsumer, HasDynamicallyImportedModules):
    pluginType = PLUGIN_TYPE_STATS_CONSUMER

    def __init__(self):
        super().__init__()
        self.statsPublisher = StatsPublisher(STATS_SERVER_IP, STATS_SERVER_PORT)
        self._eventToFunc = {
            EVENT_REQ_ORDERED: self._sendStatsOnReqOrdered,
            EVENT_NODE_STARTED: self._sendStatsOnNodeStart,
            EVENT_PERIODIC_STATS_THROUGHPUT: self._periodicStatsThroughput,
            EVENT_VIEW_CHANGE: self._viewChange,
            EVENT_PERIODIC_STATS_LATENCIES: self._sendLatencies
        }

    @abstractmethod
    def isModuleImportedSuccessfully(self):
        return True

    def _send(self, data: Dict[str, object]):
        self.statsPublisher.send(jsonpickle.dumps(data))

    def sendStats(self, event: str, stats: Dict[str, object]):
        self._eventToFunc[event](stats)

    def _periodicStatsThroughput(self, stats: Dict[str, object]):
        stats["eventName"] = str(Topic.PublishMtrStats)
        self._send(stats)
{'fraction_non_alphanumeric': 0.06973249173429516, 'fraction_numerical': 0.0, 'mean_word_length': 4.367741935483871, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5832651', 'n_tokens_mistral': 1084, 'n_tokens_neox': 1032, 'n_words': 185}