Commit 1b6a49a2 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[stats] Fixed documentation related warnings

Also unused import cleanup
parent 095e9d9a
......@@ -35,7 +35,6 @@ A class that can read, validate and update statistical information
import os
import time
import copy
import simplejson
......@@ -73,45 +72,46 @@ class Statistics(object):
self.errors = []
if data:
self._load(data) #also runs validation
self._load(data) # also runs validation
else:
self._data, self.errors = prototypes.load('statistics') #also validates
self._data, self.errors = prototypes.load('statistics') # also validates
def _load(self, data):
"""Loads the statistics
Parameters:
data (object, str, file): The piece of data to load. The input can be a
valid python object that represents a JSON structure, a file, from
which the JSON contents will be read out or a string. See
data (object, str, file): The piece of data to load. The input can be
a valid python object that represents a JSON structure, a file,
from which the JSON contents will be read out or a string. See
:py:func:`schema.validate` for more details.
"""
# reset
self._data = None
self.errors = []
if not isinstance(data, dict): #user has passed a file pointer
if not isinstance(data, dict): # user has passed a file pointer
if not os.path.exists(data):
self.errors.append('File not found: %s' % data)
return
# this runs basic validation, including JSON loading if required
self._data, self.errors = schema.validate('statistics', data)
if self.errors: return #don't proceed with the rest of validation
if self.errors: return # don't proceed with the rest of validation
@property
def schema_version(self):
"""Returns the schema version"""
return self.data.get('schema_version', 1)
@property
def cpu(self):
"""Returns only CPU information"""
return self._data['cpu']
@cpu.setter
......@@ -128,6 +128,7 @@ class Statistics(object):
@property
def memory(self):
"""Returns only memory information"""
return self._data['memory']
......@@ -141,6 +142,7 @@ class Statistics(object):
@property
def data(self):
"""Returns only I/O information"""
return self._data['data']
......@@ -205,11 +207,20 @@ class Statistics(object):
def as_json(self, indent=None):
"""Returns self as as JSON
Parameters:
:param indent int: Indentation to use for the JSON generation
Returns:
dict: JSON representation
"""
return simplejson.dumps(self._data, indent=indent)
def as_dict(self):
"""Returns self as a dictionary"""
return self._data
......@@ -222,7 +233,7 @@ class Statistics(object):
with open(f, 'wt') as fobj: fobj.write(str(self))
#----------------------------------------------------------
# ----------------------------------------------------------
def cpu_statistics(start, end):
......@@ -257,8 +268,8 @@ def cpu_statistics(start, end):
user_cpu = end['cpu_usage']['total_usage']
total_cpu = end['system_cpu_usage']
user_cpu /= 1000000000. #in seconds
total_cpu /= 1000000000. #in seconds
user_cpu /= 1000000000. # in seconds
total_cpu /= 1000000000. # in seconds
processors = len(end['cpu_usage']['percpu_usage']) if \
end['cpu_usage']['percpu_usage'] is not None else 1
......@@ -271,7 +282,7 @@ def cpu_statistics(start, end):
}
#----------------------------------------------------------
# ----------------------------------------------------------
def memory_statistics(data):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment