<commit_before>"""
Created on 11 Jul 2017

@author: <NAME> (<EMAIL>)

settings for OPCMonitor

example JSON:
{"model": "N2", "sample-period": 10, "power-saving": false}
"""

from collections import OrderedDict

from scs_core.data.json import PersistentJSONable

from scs_dfe.particulate.opc_monitor import OPCMonitor
from scs_dfe.particulate.opc_n2 import OPCN2


# --------------------------------------------------------------------------------------------------------------------

class OPCConf(PersistentJSONable):
    """
    classdocs
    """

    __FILENAME = "opc_conf.json"

    @classmethod
    def filename(cls, host):
        return host.conf_dir() + cls.__FILENAME


    # ----------------------------------------------------------------------------------------------------------------

    @classmethod
    def construct_from_jdict(cls, jdict):
        if not jdict:
            return None

        model = jdict.get('model')
        sample_period = jdict.get('sample-period')
        power_saving = jdict.get('power-saving')

        return OPCConf(model, sample_period, power_saving)


    # ----------------------------------------------------------------------------------------------------------------

    def __init__(self, model, sample_period, power_saving):
        """
        Constructor
        """
        super().__init__()

        self.__model = model
        self.__sample_period = int(sample_period)
        self.__power_saving = bool(power_saving)


    # ----------------------------------------------------------------------------------------------------------------

    def opc_monitor(self, host):
        if self.model == 'N2':
            opc = OPCN2(host.opc_bus(), host.opc_device())
        else:
            raise ValueError('unknown model: %s' % self.model)

        return OPCMonitor(opc, self)


    # ----------------------------------------------------------------------------------------------------------------

    def has_monitor(self):
        return self.model is not None
<commit_msg>Fixed a bug in OPCConf.<commit_after>"""
Created on 11 Jul 2017

@author: <NAME> (<EMAIL>)

settings for OPCMonitor

example JSON:
{"model": "N2", "sample-period": 10, "power-saving": false}
"""

from collections import OrderedDict

from scs_core.data.json import PersistentJSONable

from scs_dfe.particulate.opc_monitor import OPCMonitor
from scs_dfe.particulate.opc_n2 import OPCN2


# --------------------------------------------------------------------------------------------------------------------

class OPCConf(PersistentJSONable):
    """
    classdocs
    """

    __FILENAME = "opc_conf.json"

    @classmethod
    def filename(cls, host):
        return host.conf_dir() + cls.__FILENAME


    # ----------------------------------------------------------------------------------------------------------------

    @classmethod
    def construct_from_jdict(cls, jdict):
        if not jdict:
            return None

        model = jdict.get('model')
        sample_period = jdict.get('sample-period')
        power_saving = jdict.get('power-saving')

        return OPCConf(model, sample_period, power_saving)


    # ----------------------------------------------------------------------------------------------------------------

    def __init__(self, model, sample_period, power_saving):
        """
        Constructor
        """
        super().__init__()

        self.__model = model
        self.__sample_period = int(sample_period)
        self.__power_saving = bool(power_saving)


    # ----------------------------------------------------------------------------------------------------------------

    def opc_monitor(self, host):
        if self.model == 'N2':
            opc = OPCN2(host.opc_spi_bus(), host.opc_spi_device())
        else:
            raise ValueError('unknown model: %s' % self.model)

        return OPCMonitor(opc, self)


    # ----------------------------------------------------------------------------------------------------------------

    def has_monitor(self):
        return self.model is not None

{'fraction_non_alphanumeric': 0.35421745490004874, 'fraction_numerical': 0.006338371526084837, 'mean_word_length': 1.0891038696537678, 'pattern_counts': {'":': 6, '<': 7, '<?xml version=': 0, '>': 7, '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': '4651496', 'n_tokens_mistral': 1029, 'n_tokens_neox': 956, 'n_words': 214}