separate into method
@@ -357,7 +357,7 @@ class daily_stats(Analyzer):
days (list): days on which to print out statistics (if None, assume all)
keys (list): list of states of people to provide statistics on (if None, assume all)
verbose (bool): whether to print on each timestep
- reporter (func): if supplied, a custom parser of the stats object into a report
+ reporter (func): if supplied, a custom parser of the stats object into a report (see make_report() function for syntax)
**Example**::
@@ -463,8 +463,22 @@ class daily_stats(Analyzer):
# Turn into report
if self.reporter is not None:
- report = self.reporter(stats)
+ report = self.reporter(self, sim, stats)
else:
+ report = self.make_report(sim, stats)
+
+ # Save
+ today = sim.date(sim.t)
+ self.stats[today] = stats
+ self.reports[today] = report
+
+ if self.verbose:
+ print(report)
+ return
+
+
+ def make_report(self, sim, stats):
+ ''' Turn the statistics into a report '''
def make_entry(basekey, show_empty=True):
string = '\n'.join([f' {k:13s} = {v}' for k,v in stats[basekey].items() if k != 'empty'])
@@ -486,14 +500,8 @@ class daily_stats(Analyzer):
report += make_entry('quar')
report += f'*** End of report for day {sim.t} ***\n'
- # Save
- today = sim.date(sim.t)
- self.stats[today] = stats
- self.reports[today] = report
+ return report
- if self.verbose:
- print(self.reports[today])
- return
class Fit(sc.prettyobj):
