<commit_before>import json,logging
from datetime import datetime,timedelta
from redis import StrictRedis
from util import output
from container import Container

log = logging.getLogger('statsquid')

class Stat(object):
    """
    Stat object, created from json received from stat collector
    """
    def __init__(self,statjson):
        self.raw = statjson
        self.statdict = json.loads(self.raw)
        self.timestamp = self._readtime(self.statdict['read'])
        self.container_name = self.statdict['container_name'].split('/')[-1]
        self.container_id = self.statdict['container_id'].split('/')[-1]

        self.container_cpu = self.statdict['cpu_stats']['cpu_usage']['total_usage']
        self.system_cpu = self.statdict['cpu_stats']['system_cpu_usage']
        self.cpu_count =  self.statdict['ncpu']

        for s in self.statdict['blkio_stats']['io_service_bytes_recursive']:
            if s['op'] == 'Read':
                self.read_io = s['value']
            if s['op'] == 'Write':
                self.write_io = s['value']

    def _readtime(self,timestamp):
        #TODO: use time.strptime<commit_msg>add read/write io default of zero<commit_after>import json,logging
from datetime import datetime,timedelta
from redis import StrictRedis
from util import output
from container import Container

log = logging.getLogger('statsquid')

class Stat(object):
    """
    Stat object, created from json received from stat collector
    """
    def __init__(self,statjson):
        self.raw = statjson
        self.statdict = json.loads(self.raw)
        self.timestamp = self._readtime(self.statdict['read'])
        self.container_name = self.statdict['container_name'].split('/')[-1]
        self.container_id = self.statdict['container_id'].split('/')[-1]

        self.container_cpu = self.statdict['cpu_stats']['cpu_usage']['total_usage']
        self.system_cpu = self.statdict['cpu_stats']['system_cpu_usage']
        self.cpu_count =  self.statdict['ncpu']

        self.read_io = 0
        self.write_io = 0
        for s in self.statdict['blkio_stats']['io_service_bytes_recursive']:
            if s['op'] == 'Read':
                self.read_io = s['value']
            if s['op'] == 'Write':
                self.write_io = s['value']

    def _readtime(self,timestamp):
        #TODO: use time.strptime
{'fraction_non_alphanumeric': 0.13432835820895522, 'fraction_numerical': 0.00255863539445629, 'mean_word_length': 3.08, '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': '2604045', 'n_tokens_mistral': 712, 'n_tokens_neox': 697, 'n_words': 144}