-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.py
102 lines (86 loc) · 2.84 KB
/
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
100
101
102
#!/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.
#
"""
prepare data for presentation in a :py:class:diagram.Diagram
"""
from __future__ import print_function
import sys
import re
import argparse
import json
from constants import *
class Graph(object):
"""
contains all data and information about a single graph inside a
:py:class:diagram.Diagram.
"""
def __init__(self,name, signal_accumulators, ylabel, formatting):
"""
:param name: how the graph will be called in the diagram
:param signal_accumulators: an iterator for signal_accumulators
:param ylabel: naming of the corresponding y-axis in the diagram
:param formatting: Matlab style formatting for this graph
"""
self.name = name
self.__signal_accumulators = signal_accumulators
self.ylabel = ylabel
self.formatting = formatting
self.__xdata = np.array([])
self.__ydata = np.array([])
self.__applied = False
def __apply_accumulators():
"""
generate pylab parsable data from accumulators
"""
self.__xdata = np.array([])
self.__ydata = np.array([])
for acc in self.signal_accumulators:
self.__xdata = __array_append(self.__xdata,acc.attempt)
self.__ydata = __array_append(self.__ydata,acc.count)
self.__applied = True
@property
def signal_accumulators(self):
return self.__signal_accumulators
@signal_accumulators.setter
def signal_accumulators(self,value):
self.__signal_accumulators = value
self.__applied = False
@signal_accumulators.deleter
def signal_accumulators(self):
self.__signal_accumulators = None
self.__applied = False
@property
def x_data(self):
"""
generates data for the x values of a pylab graph plot
"""
if not self.__applied:
self.__apply_accumulators()
return self.__xdata
@property
def y_data(self):
"""
generates data for the y values of a pylab graph plot
"""
if not self.__applied:
self.__apply_accumulators()
return self.__ydata
def __array_append(self, in_a,in_b):
"""
append a numpy array to another
:param in_a: a numpy array
:param in_b: a numpy array or a number
"""
in_b = np.array([in_b]) if isinstance(in_b,(int,float,long,complex)) else in_b
return np.concatenate((in_a,in_b))