"""Plot distinct viable one-reset cuts, not the number of keys. python -B reset_244_figure.py figure.svg"""
from pathlib import Path
from itertools import accumulate
import matplotlib
matplotlib.use('Agg')
from matplotlib import pyplot as plt,rcParams
import gzip,json,sys,numpy as np
D=Path(__file__).resolve().parent;r=json.load(gzip.open(D/'reset_244_one_results.json.gz'))
rcParams.update({'svg.hashsalt':'reset244','svg.fonttype':'none','font.family':'DejaVu Sans','axes.spines.top':False,'axes.spines.right':False,'font.size':10})
fig,axes=plt.subplots(2,1,figsize=(7,3.8),sharex=True,sharey=True);bins=np.arange(0,3401,100)
for ax,p,c in zip(axes,[7,8],['#25606a','#4b6583']):
 a=r['reports'][str(p)];gaps=set(g for k,d in a['per_key_gaps_deltas'] for g in accumulate(d));assert len(gaps)==a['feasible_gaps']
 ax.hist(sorted(gaps),bins=bins,color=c,rwidth=.9);ax.set_ylim(0,108);ax.set_xlim(0,3316);ax.set_yticks([0,50,100]);ax.text(32,88,f'Period {p}: {len(gaps)} distinct cuts',color='#182c33',fontsize=10)
 for date in [2474,3008]:ax.axvline(date,ls='--',lw=.9,color='#ac482a')
axes[0].text(2474,108,'Grid',ha='center',color='#943b21',fontsize=9);axes[0].text(3008,108,'Heading',ha='center',color='#943b21',fontsize=9)
axes[-1].set_xlabel('Single cut position in section 8 (runes)');fig.supylabel('Viable cuts per 100 positions',fontsize=10);fig.tight_layout();fig.savefig(sys.argv[1],metadata={'Date':None,'Description':'Counts of viable single reset addresses by 100-rune windows. Neither physical mark individually permits a nonzero seven- or eight-position key.'})
