diff options
author | Anton Khirnov <anton@khirnov.net> | 2020-11-20 21:52:03 +0100 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2020-11-20 21:53:45 +0100 |
commit | 6e2085b798ddadfc34625e5897f45fbcac8abad9 (patch) | |
tree | 4c1afdde6b2c59c3d2ecd36d2e74db10048c25c2 /lbup/repository.py | |
parent | 3c6f463280cad0db2537b42bcefe39d76a994acb (diff) |
repository: add code for reading the stats
Diffstat (limited to 'lbup/repository.py')
-rw-r--r-- | lbup/repository.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lbup/repository.py b/lbup/repository.py index d3a6b33..398c912 100644 --- a/lbup/repository.py +++ b/lbup/repository.py @@ -4,6 +4,7 @@ import os import os.path import subprocess import datetime +import statistics class StepResult: success = None @@ -20,6 +21,18 @@ class BackupResult: self.target_results = {} self.par2_result = StepResult() +class BackupStats: + + def __init__(self, fname): + def parse_line(line): + date, size = line.strip().split() + return datetime.datetime.fromisoformat(date), float(size) + + with open(fname, 'r') as f: + self.entries = dict(map(parse_line, f)) + + self.dist = statistics.NormalDist.from_samples(self.entries.values()) + class Repo: """ A single Bup repository into which the data will be backed up, plus a @@ -120,3 +133,7 @@ class Repo: self._logger.debug('Backup finished') return result + + def read_stats(self, tgt_name): + filename = os.path.join(self.data_dir, tgt_name, self.sizestat_name) + return BackupStats(filename) |