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.
This commit is contained in:
Thierry Carrez 2013-03-21 17:05:08 +01:00
parent 3e1bc6b24a
commit 0a2dfc1032
3 changed files with 13 additions and 3 deletions

View File

@ -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.

View File

@ -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)

View File

@ -9,5 +9,6 @@
{ "project": "swift" },
{ "project": "openstack-manuals", "title": "Manuals" },
{ "project": "tempest" }
]
],
"rotation": 2
}