<commit_before># -*- coding: utf-8 -*-
from __future__ import print_function, division
import numpy as np
import operator
from qsrlib_qsrs.qsr_arg_relations_abstractclass import QSR_Arg_Relations_Abstractclass
from qsrlib_io.world_qsr_trace import *


class QSR_Arg_Relations_Distance(QSR_Arg_Relations_Abstractclass):
    def __init__(self, config=None):
        super(QSR_Arg_Relations_Distance, self).__init__()
        self._unique_id = "argd"
        self.allowed_value_types = (int, float)
        self.value_sort_key = operator.itemgetter(1) # Sort by threshold
        # todo this config thing does not seem right; it should be passed during request not during creation; in fact it should be handled on client side
        if config:
            self._set_from_config_file(config)

    # todo IMPORTANT: qsr_relations_and_values should not be a member, but enforced to be passed everytime
    # todo this is incompatible with how the rest of the QSRs are obtaining their parameters
    def _process_qsr_parameters_from_request_parameters(self, req_params, **kwargs):
        # todo need to integrate the read from config file somewhere, or deprecate the config file on the server side completely; can then provide a client-side utility for it
        # try:
        #     if kwargs["config"]:
        #         self.set_from_config_file(kwargs["config"])
        # except:
        #     pass

        try:
            self.set_qsr_relations_and_values(qsr_relations_and_values=req_params["dynamic_args"][self._unique_id]["qsr_relations_and_values"])
        except KeyError:
            raise KeyError("qsr_relations_and_values not set")
        return None

    def make_world_qsr_trace(self, world_trace, timestamps, qsr_params, **kwargs):
        ret = World_QSR_Trace(qsr_type=self._unique_id)<commit_msg>config functionality for argd should be working again<commit_after># -*- coding: utf-8 -*-
from __future__ import print_function, division
import numpy as np
import operator
from qsrlib_qsrs.qsr_arg_relations_abstractclass import QSR_Arg_Relations_Abstractclass
from qsrlib_io.world_qsr_trace import *


class QSR_Arg_Relations_Distance(QSR_Arg_Relations_Abstractclass):
    def __init__(self):
        super(QSR_Arg_Relations_Distance, self).__init__()
        self._unique_id = "argd"
        self.allowed_value_types = (int, float)
        self.value_sort_key = operator.itemgetter(1)  # Sort by threshold

    # todo IMPORTANT: qsr_relations_and_values should not be a member, but enforced to be passed everytime
    # todo this is incompatible with how the rest of the QSRs are obtaining their parameters
    def _process_qsr_parameters_from_request_parameters(self, req_params, **kwargs):
        # todo feel uncomfortable with config files here as IMO they should be loaded on client side; most likely to deprecate this functionality
        if req_params["config"]:
            self._set_from_config_file(req_params["config"])
        else:
            try:
                self.set_qsr_relations_and_values(qsr_relations_and_values=req_params["dynamic_args"][self._unique_id]["qsr_relations_and_values"])
            except KeyError:
                raise KeyError("qsr_relations_and_values not set")

    def make_world_qsr_trace(self, world_trace, timestamps, qsr_params, **kwargs):
        ret = World_QSR_Trace(qsr_type=self._unique_id)
{'fraction_non_alphanumeric': 0.06684491978609626, 'fraction_numerical': 0.0011883541295306002, 'mean_word_length': 3.851585014409222, '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': '1366651', 'n_tokens_mistral': 1006, 'n_tokens_neox': 966, 'n_words': 270}