Commit 6bf0d886 authored by legoktm's avatar legoktm

Use matplotlib to generate a chart of code coverage

parent 68a04fa5
#!/usr/bin/env python
"""
chart.py - charts MediaWiki core coverage results
Copyright (C) 2017 Kunal Mehta <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import datetime
import matplotlib.pyplot as plot
import os
import xml.etree.cElementTree as etree
def find_files(path: str):
return sorted(os.path.join(path, fname) for fname in os.listdir(path))
def process_file(fname):
date = datetime.datetime.strptime(os.path.basename(fname), 'clover-%Y-%m-%d.xml')
print(date)
tree = etree.parse(fname)
root = tree.getroot()
project = root.getchildren()[0]
assert project.tag == 'project'
metrics = project.getchildren()[0]
assert metrics.tag == 'metrics'
stuff = [
'methods', 'conditionals', 'statements', 'elements'
]
total = sum(int(metrics.attrib[thing]) for thing in stuff)
div = sum(int(metrics.attrib['covered%s' % thing]) for thing in stuff)
covered = round(div/total*100)
return [date, covered]
def main():
x = []
y = []
path = os.path.expanduser('~/mediawiki')
for fname in find_files(path):
date, covered = process_file(fname)
x.append(date)
y.append(covered)
plot.plot(x, y)
plot.xlabel('Date')
plot.ylabel('Percentage covered')
plot.title('MediaWiki core code coverage')
chart = os.path.join(path, 'chart.png')
plot.savefig(chart)
print('Created %s' % chart)
if __name__ == '__main__':
main()
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