<commit_before>from online_monitor.converter.correlator import Correlator
import json

from online_monitor.utils import utils


class PositionCorrelator(Correlator):

    def deserialize_data(self, data):
        return json.loads(data, object_hook=utils.json_numpy_obj_hook)

    def setup_interpretation(self):
        self.data_buffer = {}  # the data does not have to arrive at the same receive command since ZMQ buffers data and the DUT can have different time behavior

    def interpret_data(self, data):
        for actual_device_data in data:  # loop over all devices of actual received data
            for actual_data_type, actual_data in actual_device_data[1].items():
                if 'time_stamp' not in actual_data_type:
                    data_buffer = {actual_device_data[0]: actual_data}
                else:
                    actual_time_stamp = actual_data


#         print actual_interpret_data
#         intepreted_data = []
#         for one_receiver_data in data:
#             intepreted_data.append(yaml.load(one_receiver_data, object_hook=utils.json_numpy_obj_hook))
        return None<commit_msg>ENH: better draft<commit_after>import json

from online_monitor.converter.transceiver import Transceiver
from online_monitor.utils import utils


class PositionCorrelator(Transceiver):

    def deserialize_data(self, data):
        return json.loads(data, object_hook=utils.json_numpy_obj_hook)

    def setup_interpretation(self):
        # Buffer data, since data does not have to arrive at the same receive command
        # since ZMQ buffers data and the DUT can have different time behavior
        self.data_buffer = {}

    def interpret_data(self, data):
        # Data is a list filled with data of the actual readout, since multiple receivers are used
        # the size can be between 0 and n_receivers
        # One entry in the list is a tuple, with the front end address in the first and
        # the data in the second. This allows to distinguish from which FE the data is.
        for actual_device in data:  # loop over all devices of actual received data
            # Loop over the data of the device (is a dict with time_stamp, position keys)
            dev_addrs = actual_device[0]
            dev_data = actual_device[1]

            try:
                values = self.data_buffer[dev_data['time_stamp']]
                print values, dev_data
            except KeyError:
                self.data_buffer[dev_data['time_stamp']] = dev_data['position']
{'fraction_non_alphanumeric': 0.05781499202551834, 'fraction_numerical': 0.001993620414673046, 'mean_word_length': 2.8363914373088686, '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': '133807', 'n_tokens_mistral': 692, 'n_tokens_neox': 672, 'n_words': 234}