Commit 7865d2e3 authored by ben's avatar ben

Added prettier statistics printing, stats averaging


git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup@106 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109
parent ddc7e439
......@@ -17,7 +17,7 @@ class StatsObj:
'ChangedFiles',
'ChangedSourceSize', 'ChangedMirrorSize',
'IncrementFileSize')
stat_time_attrs = ('StartTime', 'EndTime')
stat_time_attrs = ('StartTime', 'EndTime', 'ElapsedTime')
stat_attrs = stat_time_attrs + stat_file_attrs
# Set all stats to None, indicating info not available
......@@ -36,10 +36,23 @@ class StatsObj:
def get_stats_string(self):
"""Return string printing out statistics"""
slist = ["%s %s" % (attr, self.get_stat(attr))
for attr in self.stat_attrs
timelist = []
if self.StartTime is not None:
timelist.append("StartTime %s (%s)" %
(self.StartTime, Time.timetopretty(self.StartTime)))
if self.EndTime is not None:
timelist.append("EndTime %s (%s)" %
(self.EndTime, Time.timetopretty(self.EndTime)))
if self.StartTime is not None and self.EndTime is not None:
if self.ElapsedTime is None:
self.ElapsedTime = self.EndTime - self.StartTime
timelist.append("ElapsedTime %s (%s)" %
(self.ElapsedTime, Time.inttopretty(self.ElapsedTime)))
filelist = ["%s %s" % (attr, self.get_stat(attr))
for attr in self.stat_file_attrs
if self.get_stat(attr) is not None]
return "\n".join(slist)
return "\n".join(timelist + filelist)
def init_stats_from_string(self, s):
"""Initialize attributes from string, return self for convenience"""
......@@ -78,6 +91,26 @@ class StatsObj:
if self.get_stat(attr) != s.get_stat(attr): return None
return 1
def set_to_average(self, statobj_list):
"""Set self's attributes to average of those in statobj_list"""
for attr in self.stat_attrs: self.set_stat(attr, 0)
for statobj in statobj_list:
for attr in self.stat_attrs:
if statobj.get_stat(attr) is None: self.set_stat(attr, None)
elif self.get_stat(attr) is not None:
self.set_stat(attr, statobj.get_stat(attr) +
self.get_stat(attr))
# Don't compute average starting/stopping time
self.StartTime = None
self.EndTime = None
for attr in self.stat_attrs:
if self.get_stat(attr) is not None:
self.set_stat(attr,
self.get_stat(attr)/float(len(statobj_list)))
return self
class StatsITR(IterTreeReducer, StatsObj):
"""Keep track of per directory statistics
......
......@@ -17,7 +17,7 @@ class StatsObj:
'ChangedFiles',
'ChangedSourceSize', 'ChangedMirrorSize',
'IncrementFileSize')
stat_time_attrs = ('StartTime', 'EndTime')
stat_time_attrs = ('StartTime', 'EndTime', 'ElapsedTime')
stat_attrs = stat_time_attrs + stat_file_attrs
# Set all stats to None, indicating info not available
......@@ -36,10 +36,23 @@ class StatsObj:
def get_stats_string(self):
"""Return string printing out statistics"""
slist = ["%s %s" % (attr, self.get_stat(attr))
for attr in self.stat_attrs
timelist = []
if self.StartTime is not None:
timelist.append("StartTime %s (%s)" %
(self.StartTime, Time.timetopretty(self.StartTime)))
if self.EndTime is not None:
timelist.append("EndTime %s (%s)" %
(self.EndTime, Time.timetopretty(self.EndTime)))
if self.StartTime is not None and self.EndTime is not None:
if self.ElapsedTime is None:
self.ElapsedTime = self.EndTime - self.StartTime
timelist.append("ElapsedTime %s (%s)" %
(self.ElapsedTime, Time.inttopretty(self.ElapsedTime)))
filelist = ["%s %s" % (attr, self.get_stat(attr))
for attr in self.stat_file_attrs
if self.get_stat(attr) is not None]
return "\n".join(slist)
return "\n".join(timelist + filelist)
def init_stats_from_string(self, s):
"""Initialize attributes from string, return self for convenience"""
......@@ -78,6 +91,26 @@ class StatsObj:
if self.get_stat(attr) != s.get_stat(attr): return None
return 1
def set_to_average(self, statobj_list):
"""Set self's attributes to average of those in statobj_list"""
for attr in self.stat_attrs: self.set_stat(attr, 0)
for statobj in statobj_list:
for attr in self.stat_attrs:
if statobj.get_stat(attr) is None: self.set_stat(attr, None)
elif self.get_stat(attr) is not None:
self.set_stat(attr, statobj.get_stat(attr) +
self.get_stat(attr))
# Don't compute average starting/stopping time
self.StartTime = None
self.EndTime = None
for attr in self.stat_attrs:
if self.get_stat(attr) is not None:
self.set_stat(attr,
self.get_stat(attr)/float(len(statobj_list)))
return self
class StatsITR(IterTreeReducer, StatsObj):
"""Keep track of per directory statistics
......
......@@ -82,6 +82,22 @@ class Time:
"""Return pretty version of time given w3 time string"""
return cls.timetopretty(cls.stringtotime(timestring))
def inttopretty(cls, seconds):
"""Convert num of seconds to readable string like "2 hours"."""
partlist = []
hours, seconds = divmod(seconds, 3600)
if hours > 1: partlist.append("%d hours" % hours)
elif hours == 1: partlist.append("1 hour")
minutes, seconds = divmod(seconds, 60)
if minutes > 1: partlist.append("%d minutes" % minutes)
elif minutes == 1: partlist.append("1 minute")
if seconds == 1: partlist.append("1 second")
elif not partlist or seconds > 1:
partlist.append("%s seconds" % seconds)
return " ".join(partlist)
def intstringtoseconds(cls, interval_string):
"""Convert a string expressing an interval (e.g. "4D2s") to seconds"""
def error():
......
Markdown is supported
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