Skip to content

Commit

Permalink
Improve GPG Key Distribution Chart
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoHood committed Aug 6, 2017
1 parent 3bd80ee commit ac75999
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
23 changes: 18 additions & 5 deletions LSD/gpg.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,27 @@ def sync_keys(self):

def evaluate(self, keys=None):
ret = r.db(self.db).table(self.table).filter(lambda doc: r.expr(keys).contains(doc['fingerprint']) if keys else True).group('algo', 'length').count().ungroup().order_by('group').run(self.conn)
count = r.db(self.db).table(self.table).filter(lambda doc: r.expr(keys).contains(doc['fingerprint']) if keys else True).count().run(self.conn)

# Convert id into human readable string (RSA 4096)
# Collect data. Summarize all algorithms with < 2%
algorithms = []
counts = []
limit = int(count * 1 / 100)
other = 0
other_algos = []
for row in ret:
#print(self.gpgAlgorithmIDs[row['group'][0]], row['group'][1], row['reduction']) # TODO verboseprint
algorithms += [self.gpgAlgorithmIDs[row['group'][0]] + ' ' + row['group'][1]]
counts += [row['reduction']]
# Convert id into human readable string (RSA 4096)
rowcount = row['reduction']
algo = self.gpgAlgorithmIDs[row['group'][0]] + ' ' + row['group'][1]
if rowcount < limit:
other += rowcount
other_algos += ['{} ({})'.format(algo, rowcount)]
else:
algorithms += [algo]
counts += [rowcount]
if other:
algorithms += ['Other']
counts += [other]

# TODO find expired keys
return {'algorithms': algorithms, 'counts': counts}
return {'algorithms': algorithms, 'counts': counts, 'other_algos': other_algos}
28 changes: 22 additions & 6 deletions LSD/lsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ def warning(self, *args):
print('Warning:', *args)

def plot_gpg(self):
trace = Pie(labels=self.gpg['algorithms'], values=self.gpg['counts'])
self.plot('GPG Key Distribution', [trace], timestamp=True)
colors = ['#2CA02C', '#0077BB', '#FF7F0E', '#D62728', '#9467BD']
trace = Pie(labels=self.gpg['algorithms'], values=self.gpg['counts'], marker=dict(colors=colors), sort=False)
self.plot('GPG Key Distribution', [trace], timestamp=True, extra_text='<b>Other Algorithms:</b><br>' + '<br>'.join(self.gpg['other_algos']))

def plot_archlinux(self, data, name):
# Prepare graph data
Expand Down Expand Up @@ -264,17 +265,18 @@ def plot_archlinux(self, data, name):
print(pkg['name'] + ': ' + ', '.join(pkg['avail_https']), file=text_file)
print('Output written to', outfile)

def plot(self, title, trace, barmode=None, updatemenus=None, timestamp=False):
def plot(self, title, trace, barmode=None, updatemenus=None, timestamp=False, extra_text=None):
if updatemenus:
layout = Layout(title=title, barmode=barmode, updatemenus=updatemenus)
else:
layout = Layout(title=title, barmode=barmode)
fig = Figure(data=trace, layout=layout)
self.plot_figure(fig, timestamp=timestamp)
self.plot_figure(fig, timestamp=timestamp, extra_text=extra_text)

def plot_figure(self, figure, timestamp=False):
def plot_figure(self, figure, timestamp=False, extra_text=None):
annotations = []
if timestamp:
annotations =[
annotations += [
dict(
text=self.time,
x=1,
Expand All @@ -284,6 +286,20 @@ def plot_figure(self, figure, timestamp=False):
showarrow=False,
)
]
if extra_text:
annotations += [
dict(
text=extra_text,
x=0,
y=0,
xref="paper",
yref="paper",
showarrow=False,
xanchor='left',
align='left',
)
]
if annotations:
figure.layout.update({'annotations': annotations})

filename = figure.layout.title.lower().replace(' ', '_') + '.div'
Expand Down

0 comments on commit ac75999

Please sign in to comment.