"""Fixed 350-task default, stratified by language/difficulty/task family.""" from collections import defaultdict import hashlib ALLOCATION_1000={'python':(75,38,12),'javascript':(75,37,13),'html':(60,30,10),'css':(60,30,10), 'cpp':(68,34,11),'c':(68,34,11),'lua':(60,30,10),'csharp':(67,34,11),'rust':(67,33,12)} ALLOCATION={'python':(26,13,5),'javascript':(27,13,4),'html':(21,11,3),'css':(21,10,4), 'cpp':(24,12,4),'c':(23,12,4),'lua':(21,11,3),'csharp':(24,11,4),'rust':(23,12,4)} VERSION='smolscript-0.3.0' def select(rows,allocation=None,version=None): allocation=ALLOCATION if allocation is None else allocation version=VERSION if version is None else version chosen=set() for lang,counts in allocation.items(): for diff,count in zip(('easy','medium','moderate'),counts): groups=defaultdict(list) for r in rows: if r['language']==lang and r['difficulty']==diff:groups[(r['metadata']['family'],r['category'])].append(r) total=sum(map(len,groups.values())) quotas={k:count*len(v)//total for k,v in groups.items()} for k in sorted(groups,key=lambda k:(-(count*len(groups[k])%total),k))[:count-sum(quotas.values())]:quotas[k]+=1 for k,group in groups.items(): ranked=sorted(group,key=lambda r:hashlib.sha256((version+':'+r['id']).encode()).digest()) chosen.update(r['id'] for r in ranked[:quotas[k]]) result=[{**r,'metadata':{**r['metadata'],'protocol':version}} for r in rows if r['id'] in chosen] assert len(result)==sum(sum(v) for v in allocation.values()) return result