-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_vulnerability.py
executable file
·63 lines (50 loc) · 2.15 KB
/
plot_vulnerability.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
#!/usr/bin/env python3
# 1st-party
import logging
import math
import os
import sys
# 3rd-party
import matplotlib
# Force matplotlib to not use any Xwindows backend.
# http://stackoverflow.com/a/3054314
matplotlib.use('Agg')
import matplotlib.pyplot as pyplot
import numpy
def plot(points, color, label, markersize=10):
INDICES = numpy.arange(len(points))
pyplot.plot(INDICES, points, color, label=label, markersize=markersize)
# http://stackoverflow.com/questions/12444716/how-do-i-set-figure-title-and-axes-labels-font-size-in-matplotlib#12444777
# http://stackoverflow.com/questions/16774197/variable-point-size-in-matplotlib#16774289
def save(number_of_users, plot_filename, fontsize=16):
# add title, labels, ticks, legends
pyplot.title('User impact in the event of a repository compromise',
fontsize=fontsize)
pyplot.legend(loc='upper left', fontsize=fontsize)
pyplot.xlabel('Time before a compromise is detected (weeks)',
fontsize=fontsize)
week_numbers = numpy.arange(5)
week_xticks = numpy.array([i*7 for i in week_numbers])
week_labels = ['{} weeks'.format(i) for i in week_numbers]
pyplot.xticks(week_xticks, week_labels, fontsize=fontsize)
pyplot.ylabel('Number of vulnerable users', fontsize=fontsize)
magnitude = int(math.log(number_of_users, 10))
scalar = int(math.ceil(number_of_users/10**magnitude))
logging.info('{:,} ~= {} * 10^{} users'.format(number_of_users,
scalar,
magnitude))
assert magnitude == 5
multipliers = numpy.arange(11)
user_yticks = numpy.array([((multiplier*scalar)/10) * 10**magnitude \
for multiplier in multipliers])
user_labels = ['{}K'.format(multiplier*scalar*10) \
for multiplier in multipliers]
pyplot.yticks(user_yticks, user_labels, fontsize=fontsize)
# write the actual plot
pyplot.savefig(plot_filename)
# clear figure
pyplot.clf()
if __name__ == '__main__':
# rw for owner and group but not others
os.umask(0o07)
raise NotImplementedError('read(list_of_points)')