1888 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
41 lines
3.3 KiB
Python
41 lines
3.3 KiB
Python
"""Use the existing catalogue converter for the complete source recipe cohort."""
|
|
from pathlib import Path
|
|
import sys,json,hashlib,collections
|
|
R=Path.cwd();sys.path.insert(0,str(R/'ops'));W=Path(__file__).parent
|
|
from item_catalog_stage import compile_catalog,compose_metadata_batch,icon_catalog
|
|
from item_batch_stage import BASIC_INPUTS
|
|
from item_icon_preflight import observed_item_display,normalize_icon,listfile_index
|
|
from item_package_preflight import target_index
|
|
from item_sparse_compat import fields,check_db2,package_payloads
|
|
from item_basic_compat import fields as basic_fields,check_db2 as basic_check
|
|
from turtle_data import inventory_item_snapshot
|
|
load=lambda p:json.loads(Path(p).read_text())
|
|
base=W/'baseline-40263-package.json'
|
|
if not base.exists():base.write_bytes(BASIC_INPUTS['package'].read_bytes())
|
|
package=load(base)
|
|
if len(package['rows'])!=40263 or package['push_id']!=package_payloads(package['rows'])[0]:raise ValueError('Pinned recipe batch baseline changed')
|
|
snapshot=inventory_item_snapshot(BASIC_INPUTS['source_snapshot']);source=[r['raw_fields']for r in snapshot['records']if r['raw_fields']['class']==9]
|
|
check_db2(BASIC_INPUTS['db2']);schema=fields(BASIC_INPUTS['dbd']);basic_check(BASIC_INPUTS['basic_db2']);basic_fields(BASIC_INPUTS['basic_dbd'])
|
|
dbc,context=observed_item_display(load(BASIC_INPUTS['observed_inventory']),BASIC_INPUTS['source_dbc'].read_bytes())
|
|
keys=set()
|
|
for p in source:
|
|
d=dbc.by_id.get(p['display_id'])
|
|
if d is not None:
|
|
try:keys.add(normalize_icon(dbc.string(d[5]),source=True)['path'])
|
|
except ValueError:pass
|
|
with (R.parent/'listfiles/community-listfile.csv').open('rb')as f:_,refs=listfile_index(f,set(),keys)
|
|
icons,requests=icon_catalog(source,dbc,refs['source_icon_references'])
|
|
basics=target_index(load(BASIC_INPUTS['full_basic']),'Item');points=target_index(load(BASIC_INPUTS['points']),'RandPropPoints');native=target_index(load(BASIC_INPUTS['native']),'ItemSparse')
|
|
compiled=compile_catalog(source,basics,points,native,schema,icons,lambda p:None,package,[])
|
|
items,counts,errors=compiled['items'],compiled['counts'],compiled['exception_counts']
|
|
(W/'catalogue.json').write_text(json.dumps(items,sort_keys=True,separators=(',',':'))+'\n')
|
|
result=compose_metadata_batch(package,items,[dict(entry=p['entry'],scope='complete-source-recipes')for p in source],schema,all_source=True,complete_partial_pairs=True)
|
|
prior={(r['table_name'],r['id']):r for r in package['rows']};after={(r['table_name'],r['id']):r for r in result['package']['rows']}
|
|
assert all(after[k]==v for k,v in prior.items())
|
|
report=dict(counts=counts,conversion_errors=errors,selected=result['selected'],excluded=result['excluded'],preserved_rows=len(prior),total_rows=len(after),source_identity=snapshot['source_identity'],source_display_context=context,listfile_sha256=refs['sha256'],all_prior_rows_unchanged=True,mechanics_verified=False,engine_loaded=False,baseline_sha256=hashlib.sha256(base.read_bytes()).hexdigest())
|
|
(W/'stage-report.json').write_text(json.dumps(report,indent=2)+'\n');(W/'package.json').write_text(json.dumps(result['package'],sort_keys=True,separators=(',',':'))+'\n')
|
|
print('Source recipes',len(source),'new pairs',len(result['selected']),'excluded',len(result['excluded']),'total rows',len(after))
|
|
print('Conversion errors',errors)
|
|
for item in items:
|
|
if item['entry']in(22209,22214,22766,22767,22768):print(item['entry'],item['errors'],len(item['components']))
|