Page MenuHomePhabricator
Paste P55431

plot and get values for captcha attemps
ActivePublic

Authored by Ladsgroup on Jan 23 2024, 11:50 PM.
Tags
None
Referenced Files
F41711790: plot and get values for captcha attemps
Jan 23 2024, 11:50 PM
Subscribers
None
import json
from collections import defaultdict
import matplotlib.pyplot as plt
with open('success.json', 'r') as f:
success = json.load(f)
with open('fail.json', 'r') as f:
fail = json.load(f)
wikis = defaultdict(dict)
for bucket in success['aggregations']['2']['buckets']:
wikis[bucket['key']]['success'] = bucket['doc_count']
for bucket in fail['aggregations']['2']['buckets']:
wikis[bucket['key']]['fail'] = bucket['doc_count']
for wiki in wikis:
wikis[wiki]['fail_ratio'] = wikis[wiki].get('fail', 0) / (wikis[wiki].get('fail', 0) + wikis[wiki].get('success', 0))
xs = []
ys = []
prev = 0
for case in sorted(wikis.items(), key=lambda i: i[1]['fail_ratio']):
prev += case[1].get('fail', 0) + case[1].get('success', 0)
xs.append(prev)
ys.append(case[1]['fail_ratio']*100)
if (case[1].get('fail', 0) + case[1].get('success', 0)) > 500:
print('|' + case[0] + '|' + str(round(case[1]['fail_ratio']*100, 1)) + '%')
fig, ax = plt.subplots()
ax.plot(xs, ys, 'o', linewidth=2.0)
ax.set_xlabel('cumulative captcha attempts')
ax.set_ylabel('Failure rate (%)')
plt.grid(True)
plt.show()