From 0a2dfc1032ca6ba245cc4ed2f160e8a8f3c8ba31 Mon Sep 17 00:00:00 2001 From: Thierry Carrez Date: Thu, 21 Mar 2013 17:05:08 +0100 Subject: [PATCH] Optionally rotate old data Introduces a 'rotation' parameter in config.js that will remove entries older than n days from the datasets, resulting in a rolling view of bug activity. --- README.rst | 4 ++++ bugdaystats.py | 9 +++++++-- config.js.sample | 3 ++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index ad6c591..9c167be 100644 --- a/README.rst +++ b/README.rst @@ -35,3 +35,7 @@ to generate data for. "height" is an optional parameter detailing the size of the graph (230 pixels is the default value). "title" is an optional parameter for the name of the project in the index page. + +You can also optionally specify a 'rotation' parameter. Entries older +than the value (in days) will be removed from the dataset, resulting +in a rolling view of bug activity. diff --git a/bugdaystats.py b/bugdaystats.py index 341e2b9..984fef6 100755 --- a/bugdaystats.py +++ b/bugdaystats.py @@ -41,7 +41,7 @@ def create_files(templatepath, outputpath, projects): template.stream(project=project).dump(projectfile) -def update_stats(outputpath, project_name): +def update_stats(outputpath, project_name, rotation): now = int(time.time()) records = [] @@ -55,6 +55,10 @@ def update_stats(outputpath, project_name): json_data = json.load(data_file) data_file.close() for record in json_data['records']: + if rotation: + if (now - record['date']) > (rotation * 24 * 60 * 60): + print "skip" + continue records.append(record) except IOError: pass @@ -157,6 +161,7 @@ if __name__ == '__main__': with open(configpath, 'r') as configfile: config = json.load(configfile) projects = config['projects'] + rotation = config.get('rotation') # Create files in output directory, if needed create_files(templatepath, outputpath, projects) @@ -166,4 +171,4 @@ if __name__ == '__main__': cachedir) for p in projects: - update_stats(outputpath, p['project']) + update_stats(outputpath, p['project'], rotation) diff --git a/config.js.sample b/config.js.sample index d049fb3..bfee5ec 100644 --- a/config.js.sample +++ b/config.js.sample @@ -9,5 +9,6 @@ { "project": "swift" }, { "project": "openstack-manuals", "title": "Manuals" }, { "project": "tempest" } - ] + ], + "rotation": 2 }