forked from rmeloca/EcosystemsAnalysis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotDistributions.py
More file actions
299 lines (285 loc) · 9.81 KB
/
plotDistributions.py
File metadata and controls
299 lines (285 loc) · 9.81 KB
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
import sys
import os
import plotly
import plotly.offline as offline
import plotly.graph_objs as go
import math
from ecosystemDataManager.ecosystemDataManager import EcosystemDataManager
"""
Functions to plot charts, all the plot is a html file;
"""
"""
Function to plot a histogram, most be put params: vector (numbers of histogram) and name to histogram.
"""
def plotHistogram(vector, name_histogram):
trace = go.Histogram(
name='Results',
x = vector,
xbins=dict(
start=1,
# end=50,
size=0.5
)
)
data = [trace]
plotly.offline.plot(data, filename=name_histogram)
"""
Function to plot a range of hitograms, the params is a vector by vector.
"""
def plotHistograms(vectors, name_histogram):
data = []
for vector in vectors:
trace = go.Histogram(
x = vectors[vector],
name = vector,
xbins=dict(
start=0,
# end=2,
size=0.1,
)
)
data.append(trace)
plotly.offline.plot(data, filename=name_histogram)
"""
Function to plot a boxplot, the params is a vector and name to boxplot.
"""
def plotBoxPlot(vector, name_boxplot):
trace0 = go.Box(
y=vector,
)
data = [trace0]
plotly.offline.plot(data, filename=name_boxplot)
"""
Function to plot a range of boxplot, the params is a vector by vector and name to boxplot.
"""
def plotMultBoxPlot(vectors, name_boxplot):
data = []
for vector in vectors:
trace = go.Box(
y=vectors[vector],
boxpoints='all',
name=vector
)
data.append(trace)
plotly.offline.plot(data, filename=name_boxplot)
"""
Function to plot a bar chart, the params is a vector with X positions, vector with Y positions
and name to barchart.
"""
def plorBarChart(vector_x, vector_y, nameBarChart):
data = [go.Bar(
x=vector_x,
y=vector_y
)]
plotly.offline.plot(data, filename=nameBarChart)
"""
Function to plot a range of bar chart, the params is a vector with name each barchart,
vector with X positions, vector with Y positions and name to barchart.
"""
def plotMultBarsChart(setName, vector_x, vectors_y, nameBarChart):
data = []
i = 0
for vector in vectors_y:
trace = go.Bar(
x=vector_x,
y=vector,
name=setName[i]
)
i += 1
data.append(trace)
layout = go.Layout(
barmode='group'
)
fig = go.Figure(data=data, layout=layout)
plotly.offline.plot(fig, filename=nameBarChart)
"""
Function to plot a scatter plot chart, the params is vector with X positions,
vector with Y positions and name to scatter plot chart.
"""
def plorScatterChart(vector_x, vector_y, nameBarChart):
data = [go.Scatter(
x=vector_x,
y=vector_y,
mode = 'lines+markers'
)]
plotly.offline.plot(data, filename=nameBarChart)
"""
Function to plot a scatter plot chart, the params is vector with X positions,
vector with Y positions and name to scatter plot chart.
"""
def plotMultScatterChart(setName, vector_x, vectors_y, nameBarChart):
data = []
i = 0
for vector in vectors_y:
trace = go.Scatter(
x=vector_x,
y=vector,
name=setName[i],
mode = 'lines+markers'
)
i += 1
data.append(trace)
plotly.offline.plot(data, filename=nameBarChart)
"""
Function to plot the most popular licenses in bar chart
"""
def plotMostPopularLicenses(keys, values, chartName):
trace = go.Bar(
name=chartName,
y = values,
x = keys
)
data = [trace]
plotly.offline.plot(data, filename=chartName)
"""
Function to plot the package history using a mult scatter plot
"""
def plotPackageHistory(package, chartName):
historyVersions = package.getHistory()
listLocalRegularityRate = []
listGlobalRegularityRate = []
listGlobalRegularityMean = []
versionsName = []
for version in historyVersions:
if version.getDatetime():
versionsName.append(version.getName())
listLocalRegularityRate.append((version.getLocalRegularityRate()))
listGlobalRegularityRate.append((version.getGlobalRegularityRate()))
listGlobalRegularityMean.append((version.getGlobalRegularityMean()))
setName = ["Local Regularity Rate", "Global Regularity Rate", "Global Regularity Mean"]
plotMultScatterChart(setName, versionsName, [listLocalRegularityRate, listGlobalRegularityRate, listGlobalRegularityMean], chartName)
def plotNumberDependenciesBetweenPackages(ecosystemDataManager):
packages = ecosystemDataManager.getPackages()
lenVersionsDependencies = []
for package in packages:
for version in package.getVersions():
lenVersionDependencies = len(version.getDependencies())
lenVersionsDependencies.append(lenVersionDependencies)
return lenVersionsDependencies
"""
Function to plot package history by versions, the out plot is a scatter plot.
"""
def popularVersionHistory(package, chartName):
versionsOccurrences = []
localRegularityRate = []
globalRegularityRate = []
globalRegularityMean = []
nameVersions = []
for version in package.getHistory():
if version.getDatetime():
versionsOccurrences.append(len(version.getOccurrences()))
nameVersions.append("version = " + version.getName())
localRegularityRate.append(version.getLocalRegularityRate())
globalRegularityRate.append(version.getGlobalRegularityRate())
globalRegularityMean.append(version.getGlobalRegularityMean())
x = [i for i in range(len(versionsOccurrences))]
trace0 = go.Scatter(
x=x,
y=localRegularityRate,
name="Local Regularity Rate",
text=nameVersions,
mode='markers',
marker=dict(
size = versionsOccurrences,
sizemode ='area',
)
)
trace1 = go.Scatter(
x=x,
y=globalRegularityRate,
name="Global Regularity Rate",
text=nameVersions,
mode='markers',
marker=dict(
size = versionsOccurrences,
sizemode ='area'
)
)
trace2 = go.Scatter(
x=x,
y=globalRegularityMean,
name="Global Regularity Mean",
text=nameVersions,
mode='markers',
marker=dict(
size = versionsOccurrences,
sizemode ='area'
)
)
data = [trace0, trace1, trace2]
plotly.offline.plot(data, filename=chartName)
if __name__ == '__main__':
if len(sys.argv) < 2:
print("Usage:", sys.argv[0], "<ecosystem> [history[=<package>]] [package-size] [most-popular-metrics[=<most-popular-size>]] [number-dependencies] ][licenses] [metrics]")
sys.exit(1)
if len(sys.argv) == 2:
print("No options provided. all plots will be rendered")
x = input('Can plots all charts? (Y/n): ')
if (x == 'y' or x == 'Y'):
options = {"history": None, "package-size": None, "most-popular-metrics": None, "licenses": None, "metrics": None, "number-dependencies": None}
else:
print ("No charts to render.")
exit()
else:
options = {}
for argument in sys.argv[2:]:
split = argument.split("=")
if len(split) > 1:
options[split[0]] = split[1]
else:
options[split[0]] = None
try:
os.makedirs("visualizations")
except Exception as e:
pass
ecosystem = sys.argv[1]
ecosystemDataManager = EcosystemDataManager(ecosystem)
irregularPackages = None
if "package-size" in options:
packageSizeDistribution = [len(package) for package in ecosystemDataManager.getPackages()]
plotBoxPlot(packageSizeDistribution, "visualizations/" + ecosystem + '_boxplot_packageSizeDistribution.html')
plotHistogram(packageSizeDistribution, "visualizations/" + ecosystem + '_histogram_packageSizeDistribution.html')
if "most-popular-metrics" in options:
mostPopularSize = options["most-popular-metrics"]
if not mostPopularSize:
print("<most-popular-size> not provided. Default size will be used")
mostPopularSize = 10
irregularPackages = ecosystemDataManager.getMostPopularIrregularPackages(mostPopularSize)
irregularPackagesHasLocalRegularityRates = {irregularPackage.getName(): irregularPackage.getLocalRegularityRates() for irregularPackage in irregularPackages}
try:
plotMultBoxPlot(irregularPackagesHasLocalRegularityRates, "visualizations/" + ecosystem + '_boxplot_regularityRateVersions.html')
plotHistograms(irregularPackagesHasLocalRegularityRates, "visualizations/" + ecosystem + '_histogram_regularityRateVersions.html')
except Exception as e:
pass
if "licenses" in options:
licensePerVersion = [len(licenses) for licenses in ecosystemDataManager.getLicensesPerVersion()]
plotBoxPlot(licensePerVersion, "visualizations/" + ecosystem + '_boxplot_licensesPerVersion.html')
licenses = ecosystemDataManager.getMostPopularLicenses(25)
licenses = licenses[4]
plotMostPopularLicenses([str(k) for k, v in licenses], [v for k, v in licenses], "visualizations/" + ecosystem + "_bars_mostPopularLicenses.html")
plotMostPopularLicenses([str(k) for k, v in licenses], [math.log10(v) for k, v in licenses], "visualizations/" + ecosystem + "_bars_log10_mostPopularLicenses.html")
if "metrics" in options:
metrics = {}
metrics["Local Regularity Rate"] = ecosystemDataManager.getLocalRegularityRates()
metrics["Global Regularity Rate"] = ecosystemDataManager.getGlobalRegularityRates()
metrics["Global Regularity Mean"] = ecosystemDataManager.getGlobalRegularityMeans()
plotMultBoxPlot(metrics, "visualizations/" + ecosystem + '_boxplot_metrics.html')
if "history" in options:
package = options["history"]
if package:
package = ecosystemDataManager.getPackage(package)
else:
print("<package> not provided. Most popular and irregular package will be used to plot their history")
if not irregularPackages:
irregularPackages = ecosystemDataManager.getMostPopularIrregularPackages(1)
try:
package = irregularPackages[0]
plotPackageHistory(package, "visualizations/" + ecosystem + "_" + package.getName() + '_regularity_rate_bars.html')
popularVersionHistory(package, "visualizations/" + ecosystem + "_" + package.getName() + '_popular_version.html')
except Exception as e:
pass
if "number-dependencies" in options:
versionsHasDependencies = [len(version.getDependencies()) for package in ecosystemDataManager.getPackages() for version in package.getVersions()]
plotBoxPlot(versionsHasDependencies, "visualizations/" + ecosystem+"_dependencies_between_packages")
if "groups" in options:
plotMultBarsChart([1,2], [2,3], [3], "teste.html")