Statistics   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 36
rs 10
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __init__() 0 10 3
A get_stat() 0 10 2
A __str__() 0 2 1
A set_stat() 0 7 2
1
"""Statistic package
2
3
.. Authors:
4
    Philippe Dessauw
5
    [email protected]
6
7
.. Sponsor:
8
    Alden Dima
9
    [email protected]
10
    Information Systems Group
11
    Software and Systems Division
12
    Information Technology Laboratory
13
    National Institute of Standards and Technology
14
    http://www.nist.gov/itl/ssd/is
15
"""
16
from __future__ import division
17
import logging
18
19
20
class Statistics(object):
21
    """Statistics of one text file
22
    """
23
24
    def __init__(self, stat_names):
25
        if type(stat_names) != list:
26
            raise TypeError
27
28
        self.stats = {}
29
30
        for name in stat_names:
31
            self.stats[name] = None
32
33
        logging.debug("Statistics initialized")
34
35
    def set_stat(self, name, value):
36
        """Add a new stat to the model
37
        """
38
        if name not in self.stats:
39
            raise KeyError("Key '"+name+"' does not exists")
40
41
        self.stats[name] = value
42
43
    def get_stat(self, name):
44
        """Return a statistic value
45
46
        Returns:
47
            float: Value of the stat
48
        """
49
        if name not in self.stats:
50
            raise KeyError("Key '"+name+"' does not exists")
51
52
        return self.stats[name]
53
54
    def __str__(self):
55
        return str(self.stats)
56