This repository has been archived by the owner on Apr 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot-results.py
125 lines (113 loc) · 4.13 KB
/
plot-results.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
import argparse
import urllib.parse as url
from io import BytesIO
import google.cloud.storage as gs
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
# conda+mamba - shades of green (Derived from anaconda website)
# poetry - shades of blue (Derived from their logo)
# pip,venv - shades of yellow (Python native tool)
# pip-tools - shades of red (Jazz Band)
# pyenv - orange (A color distinct from the others, but most related to Python native stuff)
# pipenv - shades of violet (A color distinct from the others)
# anaconda_green = '#89cb6f'
# mamba_black = '#1c1c19'
# poetry_blues = ['#5062cc', '#398cd7', '#52bcea']
# pipenv
# jazz_band_reds = ['#8b3520', '#d77058']
# python_blue = '#235789'
# python_yellow = '#f1d302'
colors = {
'conda': '#89cb6f',
'conda-lock': '#c6e6ba',
'conda+pip': '#99ad8d',
'mamba': '#3c6524',
'mamba-lock': '#4e822f',
'mamba+pip': '#434b3e',
'pip-compile': '#8b3520',
'pip-lock': '#d77058',
'pip-wheel-lock': '#ebb7ab',
'pip+pyenv': '#f19702',
'pip+venv': '#f1d302',
'pipenv': '#9370db',
'pipenv-lock': '#b79fe7',
'pipenv-skip-lock': '#c970db',
'poetry': '#5062cc',
'poetry-lock': '#398cd7'
}
def plot(project, df, image_file, python_version, show_image=False):
sorted_indices = df.groupby('env').median().sort_values('time').index
sorted_colors = [colors[i] for i in sorted_indices]
sns_plot = sns.barplot(x='env',
y='time',
data=df,
order=sorted_indices,
palette=sorted_colors,
estimator=np.median)
ax = plt.gca()
ax.set_ylabel('Time (s)')
ax.set_xlabel('Environment Resolver')
_ = plt.xticks(rotation=15)
ax.set_title(
f'{project.capitalize()} Environment Resolution Time (Python {python_version})'
)
if show_image:
plt.show()
fig = sns_plot.figure
fig.set_size_inches(1800 / fig.dpi, 900 / fig.dpi)
fig.savefig(image_file)
def process_results_file(results_file_uri):
parse_results = url.urlparse(results_file_uri)
if 'gs' == parse_results.scheme:
client = gs.Client()
bucket = client.get_bucket(parse_results.netloc)
blob_name = parse_results.path.lstrip('/')
return pd.read_csv(
BytesIO(bucket.get_blob(blob_name).download_as_string()))
else:
return pd.read_csv(results_file_uri)
def main():
parser = argparse.ArgumentParser(
description=
'Plot Python environment manager profiling results from input text file. '
'File can be local or object in Google storage bucket with URI starting with "gs://". '
'File must be formatted as CSV file with header \"env,time\". '
'Plot will be saved to an output image file.')
parser.add_argument('-p',
'--project',
type=str,
default=False,
required=True,
help='Project name.')
parser.add_argument('-f',
'--results-file',
type=str,
default=False,
required=True,
help='Path to the input results file.')
parser.add_argument('-i',
'--image-file',
type=str,
default=False,
required=True,
help='Path to the output image file.')
parser.add_argument('-s',
'--show',
action='store_true',
help='Show image onscreen before saving.')
parser.add_argument(
'-v',
'--python-version',
default=False,
required=True,
help='Python version used for profiling. Example: --python-version=3.7'
)
parser.set_defaults(show=False)
args = parser.parse_args()
results_df = process_results_file(args.results_file)
plot(args.project, results_df, args.image_file, args.python_version,
args.show)
if '__main__' == __name__:
main()