"""Produce source inventory, review sheets and an offline dataset browser.""" import collections import hashlib import html import json from pathlib import Path from PIL import Image, ImageOps, ImageDraw from knowledge import KNOWLEDGE ROOT=Path(__file__).resolve().parents[1] def save_json(path,obj):path.write_text(json.dumps(obj,ensure_ascii=False,indent=2)+'\n') def sha(path): h=hashlib.sha256() with path.open('rb') as f: for chunk in iter(lambda:f.read(4*1024*1024),b''):h.update(chunk) return h.hexdigest() def sources(): records=[ ('led_reliability','Reliability of High-Power LEDs and Solder Pastes','https://www.kaggle.com/datasets/andreaszippelius/hellastudy-of-leds2','data/raw/led_reliability.zip','CC BY-NC-SA 4.0','Measured SAM cracking after thermal shock and initial X-ray voiding. Matched by LED type, solder, panel, device and cycle. Thresholds are selection rules, not acceptance criteria.'), ('led_reliability_paper','Investigations on High-Power LEDs and Solder Interconnects in Automotive Application: Part II—Reliability','https://d-nb.info/1376074273/34','data/raw/led_paper.pdf','CC BY-NC-ND 4.0 (article)','Schmid et al., IEEE TDMR 23(3), 2023, pp. 419–429. Study-level mechanisms; no independently confirmed per-device cause.'), ('ulger','Solder Joint Dataset','https://github.com/furkanulger/solder-joint-dataset','data/raw/ulger.zip','not_specified','Images are source-labelled crops. No data license found in the pinned repository.'), ('soldef','SolDef_AI','https://www.kaggle.com/datasets/mauriziocalabrese/soldef-ai-pcb-dataset-for-defect-detection','data/raw/soldef.zip','GPL 3 (publisher metadata)','Version 1. Cite Fontana et al., 2024, doi:10.3390/jmmp8030117.'), ('soldef_paper','SolDef_AI paper','https://mdpi-res.com/d_attachment/jmmp/jmmp-08-00117/article_deploy/jmmp-08-00117.pdf','data/raw/soldef_paper.pdf','CC BY 4.0 (article)','Pages 9-12 establish no_good=placement defect and poor_solder=insufficient solder. Article and dataset licenses differ.'), ('aim_smt','AIM SMT Troubleshooting Guide','https://www.aimsolder.com/sites/default/files/smt_ts.pdf','data/raw/aim_smt.pdf','not_specified','Manufacturer examples and class-level causes, not sample-specific manufacturing logs.'), ('aim_wave','AIM Wave Troubleshooting Guide','https://www.aimsolder.com/wp-content/uploads/Wave_ts.pdf','data/raw/aim_wave.pdf','not_specified','Manufacturer examples and class-level troubleshooting.'), ('kester_faq','Kester FAQ','https://www.kester.com/knowledge-base/faq','data/raw/kester_faq.html','not_specified','Supplementary background. No images counted from this page.'), ('calce_cracked','CALCE Cracked Solder','https://calce.umd.edu/cracked-solder','data/raw/cracked-solder.html','not_specified','Class-level reliability and fracture mechanisms.'), ('calce_void','CALCE Solder Joint Voids','https://calce.umd.edu/solder-joint-voids','data/raw/solder-joint-voids.html','not_specified','Supplementary background; not counted as image samples.'), ('calce_cold','CALCE Cold Solder','https://calce.umd.edu/cold-solder','data/raw/cold-solder.html','not_specified','Supplementary background.'), ('calce_insufficient','CALCE Insufficient Solder','https://calce.umd.edu/insufficient-solder','data/raw/insufficient-solder.html','not_specified','Supplementary background.'), ('calce_wetting','CALCE Poor Solderability','https://calce.umd.edu/poor-solderability-leads','data/raw/poor-solderability-leads.html','not_specified','Supplementary background.'), ('technolab','TechnoLab Soldering Defect Dictionary','https://solderdict.technolab.de/','data/raw/technolab_home.html','not_specified','Each admitted figure has a direct case-context link in cases.json; acceptable examples were excluded.'), ('technolab_cold','TechnoLab Cold Solder Joints','https://solderdict.technolab.de/smd-hmd/cold-solder-joints.php','data/raw/technolab_cold-solder-joints.html','not_specified','Broad terminology includes stress cracks; original wording retained in source context.'), ('technolab_opens','TechnoLab Opens','https://solderdict.technolab.de/smd-hmd/opens.php','data/raw/technolab_opens.html','not_specified','Open and lifted-lead figure contexts.'), ('technolab_separation','TechnoLab Metallization Separation','https://solderdict.technolab.de/smd-hmd/separation.php','data/raw/technolab_separation.html','not_specified','Detachment examples concern component termination metallization.'), ('technolab_alignment','TechnoLab Alignment','https://solderdict.technolab.de/smd-hmd/deficiencies-in-component-alignment.php','data/raw/technolab_deficiencies-in-component-alignment.html','not_specified','Acceptable, borderline and pre-solder examples excluded.'), ('bobwillis_lifting','Root Causes of Component Lifting','https://pcdandf.com/pcdesign/index.php/current-issue/240-database/14841-root-causes-of-component-lifting','data/raw/lifting.html','not_specified','Bob Willis, July 2020, figure 1a/1b.'), ('huanan_failure','PCBA焊点疲劳开裂失效分析','https://www.gdhnjc.com/companyInfo/69.html','data/raw/huanan_failure.html','not_specified','Source-reported case, optical/microsection/SEM/EDS evidence grouped into one sample. Not independently verified.'), ('hf_candidate','Soldering-Data-Tiny-1004-unsolder-area','https://huggingface.co/datasets/AndyLiu0104/Soldering-Data-Tiny-1004-unsolder-area','data/raw/hf_tiny.parquet','not_specified','10,481 128px candidates excluded from valid count: black padding, possible transformed repeats, unknown acquisition and ambiguous empty labels.'), ('nasa_archive','Historical NASA workmanship pictorial reference (mirror)','https://www.dotmana.com/weblog/wp-content/uploads/NASA_workmanship_standard_pictorial_reference.pdf','data/raw/nasa_smt.pdf','mixed_not_assessed','Historical reference only, not current acceptance standard; no samples counted. Downloaded from a third-party mirror.'), ] out=[] for sid,title,url,file,license,note in records: p=ROOT/file out.append(dict(id=sid,title=title,url=url,local_file=file,license_as_observed=license,note=note, retrieved_date_utc='2026-09-21',sha256=sha(p),bytes=p.stat().st_size)) save_json(ROOT/'data/sources.json',out) inventory=[] for p in sorted((ROOT/'data/raw').rglob('*')): if p.is_file() and p.suffix!='.part':inventory.append(dict(path=str(p.relative_to(ROOT)),bytes=p.stat().st_size,sha256=sha(p))) save_json(ROOT/'data/raw_inventory.json',inventory) def gallery(rows): compact=[dict(id=r['id'],image='../'+r['image'],labels=r['labels_zh'],label_ids=r['labels'], caption=r['caption_zh'],split=r['split'],source=r['source']['source_id'],url=r['source']['page_url'], causes=r['root_cause']['possible_causes_zh'],repair=r['repair']['steps_zh'], modality=r['source']['modality'],evidence=[dict(image='../'+e['image'],description=e['description']) for e in r.get('additional_evidence_images',[])], rights=r['source']['rights_status'],size=f'{r["width"]}×{r["height"]}') for r in rows] text='''
原始标签与中文弱监督文本。根因多为排查假设,维修建议未逐例验证。图片和资料按各自来源授权使用。