| Total Complexity | 8 |
| Total Lines | 36 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 2 |
| 1 | """Statistic package |
||
| 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 |