-
Notifications
You must be signed in to change notification settings - Fork 3
/
__init__.py
43 lines (33 loc) · 1.09 KB
/
__init__.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
import matplotlib.pyplot as plt
class Metric(object):
"""
Base metric class.
"""
def __init__(self, name, results):
self.name = name
self.results = results
def get_all_site_names(self):
return list(set([result["siteName"] for result in self.results]))
def config(self, site_names):
"""
Returns the config that is passed to matplot.
Override upon inheritance.
Returns:
dict
"""
raise NotImplemented
def plot(self, site_names=None):
"""
Generates the chart for the given site names.
Args:
site_names (list): a list of site names.
"""
if not site_names: site_names = self.get_all_site_names()
config = self.config(site_names)
plt.xlabel(config["xLabel"])
plt.ylabel(config["yLabel"])
if config.get("title"): plt.title(config["title"])
for item in config["series"]:
plt.plot(item["xValues"], item["yValues"], label=item["name"])
if config["legend"]: plt.legend()
plt.show()