diff --git a/LSD/gpg.py b/LSD/gpg.py
index ff523e6..78e8355 100755
--- a/LSD/gpg.py
+++ b/LSD/gpg.py
@@ -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}
diff --git a/LSD/lsa.py b/LSD/lsa.py
index 14c98bf..469b71a 100644
--- a/LSD/lsa.py
+++ b/LSD/lsa.py
@@ -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='Other Algorithms:
' + '
'.join(self.gpg['other_algos']))
def plot_archlinux(self, data, name):
# Prepare graph data
@@ -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,
@@ -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'