-
Notifications
You must be signed in to change notification settings - Fork 0
/
legend.py
executable file
·173 lines (160 loc) · 3.76 KB
/
legend.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/env python3
# Mapping of labels to plot line specifications and legend generation
import functools
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.patheffects
import numpy as np
import os.path
# Mapping from concurrency control protocol to an initial marker
cc = {
'Cicada': 'cicada',
'Doppel': 'doppel',
'ERMIA': 'ermia',
'MOCC': 'mocc',
'MVCC': 'msto',
'OCC': 'osto',
'TicToc': 'tsto',
}
# Mapping from marker to style
cc_style = {
'cicada': {
'color': (148, 103, 189),
'linestyle': 'solid',
'linewidth': 2,
'marker': '$C$',
},
'doppel': {
'color': (152, 223, 138),
'linestyle': 'solid',
'linewidth': 1,
'marker': '$D$',
},
'ermia': {
'color': (140, 86, 75),
'linestyle': 'solid',
'linewidth': 2,
'marker': '$E$',
},
'mocc': {
'color': (227, 119, 194),
'linestyle': 'solid',
'linewidth': 2,
'marker': '$M$',
},
'msto': {
'color': (16, 76, 100),
'linestyle': (0, (1, 5)),
'linewidth': 1,
'marker': 's',
},
'osto': {
'color': (23, 190, 207),
'linestyle': (0, (1, 5)),
'linewidth': 1,
'marker': '8',
},
'tsto': {
'color': (31, 119, 180),
'linestyle': (0, (1, 5)),
'linewidth': 1,
'marker': 'D',
},
}
# Mapping from marker to concurrency control protocol name, if difference from above
cc_name = {
'msto': 'MSTO',
'osto': 'OSTO',
'tsto': 'TSTO',
}
# Optimization options
cc_opts = {
'20phases': '20p',
'90phases': '90p',
'160phases': '160p',
'ATS': 'ats',
'DU': 'du',
'STS': 'sts',
}
# Optimization styles
cc_opts_style = {
'20p': {
'path_effects': [
mpl.patheffects.withTickedStroke(spacing=1, angle=45),
],
},
'90p': {
'path_effects': [
mpl.patheffects.withTickedStroke(spacing=4, angle=45),
],
},
'160p': {
'path_effects': [
mpl.patheffects.withTickedStroke(spacing=9, angle=45),
],
},
'ats': {
'fillstyle': 'top',
'markerfacecoloralt': 'white',
},
'du': {
'linestyle': (0, (5, 5)),
},
'sts': {
'fillstyle': 'right',
'markerfacecoloralt': 'gray',
},
}
# Toggle-specific options
cc_toggle_style = {
'secondary': {
'color': (0.5, 0.5, 0.5),
'linestyle': (0, (1, 3)),
'linewidth': 1.25,
}
}
# Converting back into human-readable
def series_to_name(shorthand):
cclabel, *opts = shorthand.split('.')
if cclabel in cc_name:
name = cc_name[cclabel]
else:
for name, label in cc.items():
if label == cclabel:
break
for ccopt in opts:
for opt, label in cc_opts.items():
if label == ccopt:
break
optname = functools.reduce(lambda acc, x: \
f'{acc} {x}' if acc and (acc[-1].isdigit() != x.isdigit()) else acc + x, opt, '')
if optname[0].isdigit():
name += f' ({optname})'
else:
name += f'+{optname}'
return name
# Mapping from filename to prefix
def filename_to_prefix(fname):
return os.path.basename(fname).split('-', 1)[0].split('_', 1)[0]
# Mapping from prefix to experiment
experiment_prefixes = {
'adapting': 'adapting',
'c': 'tpcc',
'd': 'like',
'e': 'tpcc',
'like': 'like',
'mocc': 'tpcc',
'rubis': 'rubis',
'tpcc': 'tpcc',
'wiki': 'wiki',
'ycsb': 'ycsb',
}
def filename_to_experiment(fname):
return experiment_prefixes[filename_to_prefix(fname)]
# Mapping from prefix to value scale; assumed 1 if not specified
scaling_prefixes = {
'c': 1e6,
'mocc': 1e6,
}
def filename_to_scaling(fname):
return scaling_prefixes.get(filename_to_prefix(fname), 1)