<commit_before>__author__ = '<NAME>'

from pypro.snmp import config
from pypro import utils
from influxdb import InfluxDBClient
from influxdb.exceptions import InfluxDBClientError

class InFluxLogger:
    indices = {}

    def __init__(self):
        self.client = InfluxDBClient(config.INFLUX_HOST, config.INFLUX_PORT, config.INFLUX_USER, config.INFLUX_PW, config.DB_NAME)
        try:
            self.client.create_database(config.DB_NAME)
        except InfluxDBClientError as e:
            print("Error while creating database, assuming it already exists:"+str(e))

    def close(self):
        pass

    def start(self, epoch):
        pass

    def stop(self, epoch):
        pass

    def value(self, epoch, oid, name, value):
        print("writing to influx "+str(epoch))
#        epoch *= 1000
#        epoch *= 1000000
#        name = oid._name()
        name = name.replace(' ', '_')
        #get index with default value of 0, add 1
        index = self.indices.get(name, 0) + 1
        self.indices[name] = index
        #TODO: logging
        is_error = False
        str_value = str(value)
        if oid.is_numeric() and not utils.is_number(str_value):
            is_error = True
            print("Error: received non-numeric value for numeric value:"+str_value)
            return
        if oid.is_numeric(): value = float(value)
        else: value = str_value   #select * from free_RAM
        data = [{"measurement": name,
                      "tags": {"tom": oid.target_name, "oid": str(oid.oid_id)},
                      "time": epoch,
                      "fields": {"value": value}
                     }
                    ]
        self.client.write_points(data, time_precision='ms')
#        self.client.write_points(json_body)
        print("wrote to influx "+str(epoch))
        if config.PRINT_CONSOLE: print(data)

    def error(self, epoch, description):
        pass
<commit_msg>removed excess debug prints from previous commit<commit_after>__author__ = '<NAME>'

from pypro.snmp import config
from pypro import utils
from influxdb import InfluxDBClient
from influxdb.exceptions import InfluxDBClientError

class InFluxLogger:
    indices = {}

    def __init__(self):
        self.client = InfluxDBClient(config.INFLUX_HOST, config.INFLUX_PORT, config.INFLUX_USER, config.INFLUX_PW, config.DB_NAME)
        try:
            self.client.create_database(config.DB_NAME)
        except InfluxDBClientError as e:
            print("Error while creating database, assuming it already exists:"+str(e))

    def close(self):
        pass

    def start(self, epoch):
        pass

    def stop(self, epoch):
        pass

    def value(self, epoch, oid, name, value):
        name = name.replace(' ', '_')
        #get index with default value of 0, add 1
        index = self.indices.get(name, 0) + 1
        self.indices[name] = index
        #TODO: logging
        is_error = False
        str_value = str(value)
        if oid.is_numeric() and not utils.is_number(str_value):
            is_error = True
            print("Error: received non-numeric value for numeric value:"+str_value)
            return
        if oid.is_numeric(): value = float(value)
        else: value = str_value   #select * from free_RAM
        data = [{"measurement": name,
                      "tags": {"tom": oid.target_name, "oid": str(oid.oid_id)},
                      "time": epoch,
                      "fields": {"value": value}
                     }
                    ]
        self.client.write_points(data, time_precision='ms')
        if config.PRINT_CONSOLE: print(data)

    def error(self, epoch, description):
        pass

{'fraction_non_alphanumeric': 0.10313778990450205, 'fraction_numerical': 0.005184174624829468, 'mean_word_length': 2.1767764298093586, 'pattern_counts': {'":': 14, '<': 5, '<?xml version=': 0, '>': 5, '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': '1200203', 'n_tokens_mistral': 1112, 'n_tokens_neox': 1056, 'n_words': 283}