<commit_before>#!/usr/bin/env python
#coding=utf-8

__author__ = '<NAME>'

import time
import serial
import struct
import minimalmodbus
from cts602_registers import registers

class CTS602API(minimalmodbus.Instrument):

    def __init__(self, portname='/dev/ttyUSB0', slaveaddr=30):
        minimalmodbus.Instrument.__init__(self, portname, slaveaddr)
        self.registers = registers
        self.serial.parity = serial.PARITY_EVEN
        self.serial.timeout = 1.0
        self.format = 'bbbhh'
        self.reg2addr = dict([(x['name'], x['address']) for x in registers])

    def normalize(self, record, value):
        if record.get('values',False):
            return record['values'].get(value, value)
        ru = record['unit']
        if ru in ['ascii', 'text']: # 2 chars
            return value
        elif ru == '%':
            return value / 100.0
        elif ru == '\xc2\xb0C':
            return value / 100.0
        elif ru == 'Step':
            # TODO?
            return value
        elif ru == 'min': # minutes
            return value

    def getVP18KWTRealtimeData(self):
        o = []
        for i in self.registers:
            new_i = dict(i)
            fc = i['type'] == 'Input' and 4 or 3
            v = self.read_register(i['address'], functioncode=fc)
            new_i['raw'] = v
            new_i['value'] = self.normalize(i, v)
            o.append(new_i)<commit_msg>round to 1 decimal<commit_after>#!/usr/bin/env python
#coding=utf-8

__author__ = '<NAME>'

import time
import serial
import struct
import minimalmodbus
from cts602_registers import registers

class CTS602API(minimalmodbus.Instrument):

    def __init__(self, portname='/dev/ttyUSB0', slaveaddr=30):
        minimalmodbus.Instrument.__init__(self, portname, slaveaddr)
        self.registers = registers
        self.serial.parity = serial.PARITY_EVEN
        self.serial.timeout = 1.0
        self.format = 'bbbhh'
        self.reg2addr = dict([(x['name'], x['address']) for x in registers])

    def normalize(self, record, value):
        if record.get('values',False):
            return record['values'].get(value, value)
        ru = record['unit']
        if ru in ['ascii', 'text']: # 2 chars
            return value
        elif ru == '%':
            return round(value / 100.0, 1)
        elif ru == '\xc2\xb0C':
            return round(value / 100.0, 1)
        elif ru == 'Step':
            # TODO?
            return value
        elif ru == 'min': # minutes
            return value

    def getVP18KWTRealtimeData(self):
        o = []
        for i in self.registers:
            new_i = dict(i)
            fc = i['type'] == 'Input' and 4 or 3
            v = self.read_register(i['address'], functioncode=fc)
            new_i['raw'] = v
            new_i['value'] = self.normalize(i, v)
            o.append(new_i)
{'fraction_non_alphanumeric': 0.12776412776412777, 'fraction_numerical': 0.02070902070902071, 'mean_word_length': 2.097826086956522, 'pattern_counts': {'":': 0, '<': 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': '5061570', 'n_tokens_mistral': 919, 'n_tokens_neox': 862, 'n_words': 222}