-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathto_graph.py
executable file
·99 lines (83 loc) · 3.61 KB
/
to_graph.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/python2
# -*- coding: utf-8 -*-
#
# NightOwl - who tests your unit tests?
#
# Copyright (C) 2012 DResearch Fahrzeugelektronik GmbH
# Written and maintained by Erik Bernoth <[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
# 2 of the License, or (at your option) any later version.
#
import sys
import re
import argparse
import json
import numpy as np
import matplotlib
matplotlib.use('AGG') #nessesary here for generating output without a window object
import matplotlib.pyplot as plt
from constants import *
def make_msgline(x=None,y=None):
"""creates a touple that will be used for drawing diagrams
:param x: a numpy array
:param y: a numpy array
:return: a 'msgline'
"""
if not x: x = np.array([])
if not y: y = np.array([])
return (x,y)
def append_msgline(msgline,px,py):
"""helper function for adding stuff to an object generated by make_msgline()
:param msgline: a touple as returned by make_msgline() or append_msgline()
:param px: a new x-value to add
:param py: a new y-value to add
:return: a 'msgline'
"""
return (np.concatenate((msgline[0],np.array([px]))),
np.concatenate((msgline[1],np.array([py]))))
def main():
parser = argparse.ArgumentParser(
description="generates graphs from error-json lines")
parser.add_argument("filename",nargs="?",default="plot",type=str,
help="name of the picture-file")
parser.add_argument("title",nargs="?",default="plot",type=str,
help="the written title over the plot")
parser.add_argument("xlabel",nargs="?",default="build no.",type=str,
help="label for x-axis")
parser.add_argument("ylabel_warn",nargs="?",default="No. of Warnings",
type=str,help="label for left y-axis, i.e. warnings")
parser.add_argument("ylabel_err",nargs="?",default="No. of Errors",
type=str,help="label for right y-axis, i.e. errors")
parser.add_argument("format_warnings",nargs="?",type=str,default="g--",
help="Matlab formatting for the warnings")
parser.add_argument("format_errors",nargs="?",type=str,default="r-o",
help="Matlab formatting for the errors")
args = parser.parse_args()
warnings = make_msgline()
errors = make_msgline()
#all this stuff just reads the json and tries to put it into a plot()
for line in sys.stdin:
msgjson = json.loads(line)
if msgjson['type'] == TYPE_WARN_COUNT:
warnings = append_msgline(warnings,warnings[0].size,float(msgjson['count']))
elif msgjson['type'] == TYPE_ERROR_COUNT:
errors = append_msgline(errors,errors[0].size,float(msgjson['count']))
else:
raise Exception("Strange type "+msgjson['type']+"!")
warn_plot = plt.figure().add_subplot(111)
warn_plot.set_xlabel(args.xlabel)
warn_plot.set_ylabel(args.ylabel_warn)
warn_plot.plot(warnings[0],warnings[1],args.format_warnings, label="Warnings")
warn_plot.axis([0, warnings[0].max()*1.1, 0, warnings[1].max()*1.1])
err_plot = warn_plot.twinx()
err_plot.set_xlabel(args.xlabel)
err_plot.set_ylabel(args.ylabel_err)
err_plot.plot(errors[0],errors[1],args.format_errors,label="Errors")
err_plot.axis([0, errors[0].max()*1.15, 0, errors[1].max()*1.15])
plt.title(args.title)
plt.savefig(args.filename)
if __name__ == '__main__':
main()