Add files using upload-large-folder tool
Browse files- derived/Source/README.md +7 -2
- derived/Source/scripts/generate_visual_sheets.py +305 -0
- derived/Source/sheets/original/EXP/EXP_sheet_001.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_002.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_003.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_004.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_005.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_006.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_007.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_008.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_009.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_010.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_011.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_012.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_013.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_014.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_015.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_016.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_017.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_021.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_022.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_024.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_026.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_027.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_028.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_029.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_030.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_031.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_032.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_033.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_034.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_035.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_036.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_037.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_039.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_040.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_041.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_042.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_043.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_046.png +3 -0
- derived/Source/sheets/original/EXP/EXP_sheet_047.png +3 -0
- derived/Source/sheets/original/REF/REF_sheet_001.png +3 -0
- derived/Source/sheets/original/REF/REF_sheet_002.png +3 -0
- derived/Source/sheets/original/REF/REF_sheet_003.png +3 -0
- derived/Source/sheets/original/REF/REF_sheet_004.png +3 -0
- derived/Source/sheets/original/REF/REF_sheet_005.png +3 -0
- derived/Source/sheets/original/REF/REF_sheet_006.png +3 -0
- derived/Source/sheets/original/REF/REF_sheet_007.png +3 -0
- derived/Source/sheets/original/REF/REF_sheet_008.png +3 -0
- derived/Source/sheets/sheet_manifest.csv +0 -0
derived/Source/README.md
CHANGED
|
@@ -11,8 +11,8 @@ Important version note:
|
|
| 11 |
- Verification for the industrial-instrumentation rows therefore uses the external version-matched `liii_2v16.pdf` from ibiblio rather than the bundled `2.33` PDF.
|
| 12 |
|
| 13 |
Outputs:
|
| 14 |
-
- [
|
| 15 |
-
- [
|
| 16 |
- [circuit_generation_code](/workspace/SchemID/derived/Source/circuit_generation_code) contains the extracted EPS code used to generate circuit diagrams.
|
| 17 |
- [rendered](/workspace/SchemID/derived/Source/rendered) contains regenerated PNGs and no-text PNGs.
|
| 18 |
- [metadata](/workspace/SchemID/derived/Source/metadata) contains structure and verification manifests.
|
|
@@ -24,6 +24,11 @@ Build command:
|
|
| 24 |
python3 /workspace/SchemID/derived/Source/scripts/build_circuit_dataset.py --repo-root /workspace/SchemID
|
| 25 |
```
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
Upload command:
|
| 28 |
```bash
|
| 29 |
python3 /workspace/SchemID/derived/Source/scripts/build_circuit_dataset.py --repo-root /workspace/SchemID --upload
|
|
|
|
| 11 |
- Verification for the industrial-instrumentation rows therefore uses the external version-matched `liii_2v16.pdf` from ibiblio rather than the bundled `2.33` PDF.
|
| 12 |
|
| 13 |
Outputs:
|
| 14 |
+
- [sheets](/workspace/SchemID/derived/Source/sheets) contains high-resolution PNG visualization sheets with multiple rendered circuits per page.
|
| 15 |
+
- [sheets/sheet_manifest.csv](/workspace/SchemID/derived/Source/sheets/sheet_manifest.csv) lists the generated sheet pages and the figures included in each one.
|
| 16 |
- [circuit_generation_code](/workspace/SchemID/derived/Source/circuit_generation_code) contains the extracted EPS code used to generate circuit diagrams.
|
| 17 |
- [rendered](/workspace/SchemID/derived/Source/rendered) contains regenerated PNGs and no-text PNGs.
|
| 18 |
- [metadata](/workspace/SchemID/derived/Source/metadata) contains structure and verification manifests.
|
|
|
|
| 24 |
python3 /workspace/SchemID/derived/Source/scripts/build_circuit_dataset.py --repo-root /workspace/SchemID
|
| 25 |
```
|
| 26 |
|
| 27 |
+
Sheet build command:
|
| 28 |
+
```bash
|
| 29 |
+
python3 /workspace/SchemID/derived/Source/scripts/generate_visual_sheets.py
|
| 30 |
+
```
|
| 31 |
+
|
| 32 |
Upload command:
|
| 33 |
```bash
|
| 34 |
python3 /workspace/SchemID/derived/Source/scripts/build_circuit_dataset.py --repo-root /workspace/SchemID --upload
|
derived/Source/scripts/generate_visual_sheets.py
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import csv
|
| 6 |
+
import html
|
| 7 |
+
import json
|
| 8 |
+
import math
|
| 9 |
+
import re
|
| 10 |
+
import textwrap
|
| 11 |
+
from collections import defaultdict
|
| 12 |
+
from pathlib import Path
|
| 13 |
+
|
| 14 |
+
from PIL import Image, ImageDraw, ImageFont
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
REPO_ROOT = Path("/workspace/SchemID")
|
| 18 |
+
SOURCE_ROOT = REPO_ROOT / "derived" / "Source"
|
| 19 |
+
ROWS_PATH = SOURCE_ROOT / "metadata" / "rows.jsonl"
|
| 20 |
+
SHEETS_ROOT = SOURCE_ROOT / "sheets"
|
| 21 |
+
SHEETS_ORIGINAL_ROOT = SHEETS_ROOT / "original"
|
| 22 |
+
MANIFEST_PATH = SHEETS_ROOT / "sheet_manifest.csv"
|
| 23 |
+
|
| 24 |
+
PAGE_W = 4200
|
| 25 |
+
PAGE_H = 5940
|
| 26 |
+
MARGIN_X = 140
|
| 27 |
+
MARGIN_Y = 140
|
| 28 |
+
PAGE_HEADER_H = 180
|
| 29 |
+
COLS = 2
|
| 30 |
+
ROWS = 3
|
| 31 |
+
GRID_GAP_X = 90
|
| 32 |
+
GRID_GAP_Y = 90
|
| 33 |
+
CARD_PADDING = 36
|
| 34 |
+
CARD_RADIUS = 28
|
| 35 |
+
PER_PAGE = COLS * ROWS
|
| 36 |
+
|
| 37 |
+
FONT_REGULAR = "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"
|
| 38 |
+
FONT_BOLD = "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf"
|
| 39 |
+
TAG_RE = re.compile(r"<[^>]+>")
|
| 40 |
+
SPACE_RE = re.compile(r"\s+")
|
| 41 |
+
|
| 42 |
+
BOOK_ORDER = ["DC", "AC", "SEMI", "DIGI", "REF", "EXP", "LIII"]
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def load_font(path: str, size: int) -> ImageFont.FreeTypeFont:
|
| 46 |
+
return ImageFont.truetype(path, size=size)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
TITLE_FONT = load_font(FONT_BOLD, 52)
|
| 50 |
+
CONTEXT_FONT = load_font(FONT_REGULAR, 34)
|
| 51 |
+
META_FONT = load_font(FONT_REGULAR, 30)
|
| 52 |
+
PAGE_TITLE_FONT = load_font(FONT_BOLD, 72)
|
| 53 |
+
PAGE_META_FONT = load_font(FONT_REGULAR, 36)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def clean_text(value: str | None) -> str:
|
| 57 |
+
if not value:
|
| 58 |
+
return ""
|
| 59 |
+
value = html.unescape(value)
|
| 60 |
+
value = TAG_RE.sub("", value)
|
| 61 |
+
value = SPACE_RE.sub(" ", value).strip()
|
| 62 |
+
return value
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def first_ref(source_payload: dict) -> dict:
|
| 66 |
+
refs = source_payload.get("references") or []
|
| 67 |
+
return refs[0] if refs else {}
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def sort_key(source_payload: dict) -> tuple:
|
| 71 |
+
ref = first_ref(source_payload)
|
| 72 |
+
return (
|
| 73 |
+
clean_text(ref.get("reference_source")),
|
| 74 |
+
ref.get("line") or 0,
|
| 75 |
+
source_payload.get("figure_id") or "",
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def pick_primary_title(source_payload: dict) -> str:
|
| 80 |
+
ref = first_ref(source_payload)
|
| 81 |
+
for key in ("caption", "subsection", "section", "chapter"):
|
| 82 |
+
text = clean_text(ref.get(key))
|
| 83 |
+
if text:
|
| 84 |
+
return text
|
| 85 |
+
return f"{source_payload['book']} {source_payload['figure_id']}"
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def pick_context(source_payload: dict) -> str:
|
| 89 |
+
ref = first_ref(source_payload)
|
| 90 |
+
parts: list[str] = []
|
| 91 |
+
for key in ("chapter", "section", "subsection"):
|
| 92 |
+
text = clean_text(ref.get(key))
|
| 93 |
+
if text and text not in parts:
|
| 94 |
+
parts.append(text)
|
| 95 |
+
primary = pick_primary_title(source_payload)
|
| 96 |
+
parts = [part for part in parts if part != primary]
|
| 97 |
+
return " / ".join(parts)
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def pick_source_line(source_payload: dict) -> str:
|
| 101 |
+
ref = first_ref(source_payload)
|
| 102 |
+
source_file = clean_text(ref.get("reference_source")) or "unknown"
|
| 103 |
+
line = ref.get("line")
|
| 104 |
+
line_text = f":{line}" if line else ""
|
| 105 |
+
return (
|
| 106 |
+
f"{source_payload['book']} {source_payload['figure_id']} | "
|
| 107 |
+
f"{source_file}{line_text}"
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
def draw_rounded_box(draw: ImageDraw.ImageDraw, box: tuple[int, int, int, int]) -> None:
|
| 112 |
+
draw.rounded_rectangle(box, radius=CARD_RADIUS, fill="white", outline="#cfcfcf", width=4)
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
def fit_image(image: Image.Image, max_w: int, max_h: int) -> Image.Image:
|
| 116 |
+
image = trim_image(image.convert("RGBA"))
|
| 117 |
+
scale = min(max_w / image.width, max_h / image.height)
|
| 118 |
+
new_size = (max(1, int(image.width * scale)), max(1, int(image.height * scale)))
|
| 119 |
+
resized = image.resize(new_size, Image.Resampling.LANCZOS)
|
| 120 |
+
white_bg = Image.new("RGBA", resized.size, (255, 255, 255, 255))
|
| 121 |
+
return Image.alpha_composite(white_bg, resized).convert("RGB")
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
def trim_image(image: Image.Image) -> Image.Image:
|
| 125 |
+
bg = Image.new("RGBA", image.size, (255, 255, 255, 255))
|
| 126 |
+
flattened = Image.alpha_composite(bg, image).convert("RGB")
|
| 127 |
+
pixels = flattened.load()
|
| 128 |
+
min_x = flattened.width
|
| 129 |
+
min_y = flattened.height
|
| 130 |
+
max_x = -1
|
| 131 |
+
max_y = -1
|
| 132 |
+
|
| 133 |
+
for y in range(flattened.height):
|
| 134 |
+
for x in range(flattened.width):
|
| 135 |
+
r, g, b = pixels[x, y]
|
| 136 |
+
if r < 250 or g < 250 or b < 250:
|
| 137 |
+
if x < min_x:
|
| 138 |
+
min_x = x
|
| 139 |
+
if y < min_y:
|
| 140 |
+
min_y = y
|
| 141 |
+
if x > max_x:
|
| 142 |
+
max_x = x
|
| 143 |
+
if y > max_y:
|
| 144 |
+
max_y = y
|
| 145 |
+
|
| 146 |
+
if max_x < min_x or max_y < min_y:
|
| 147 |
+
return image
|
| 148 |
+
|
| 149 |
+
pad = 20
|
| 150 |
+
min_x = max(0, min_x - pad)
|
| 151 |
+
min_y = max(0, min_y - pad)
|
| 152 |
+
max_x = min(image.width, max_x + pad + 1)
|
| 153 |
+
max_y = min(image.height, max_y + pad + 1)
|
| 154 |
+
return image.crop((min_x, min_y, max_x, max_y))
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
def wrap_lines(text: str, width: int) -> list[str]:
|
| 158 |
+
if not text:
|
| 159 |
+
return []
|
| 160 |
+
wrapped = textwrap.wrap(text, width=width, break_long_words=False, replace_whitespace=False)
|
| 161 |
+
return wrapped or [text]
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
def build_page(rows: list[dict], display_name: str, book: str, page_number: int, page_count: int, output_path: Path) -> None:
|
| 165 |
+
page = Image.new("RGB", (PAGE_W, PAGE_H), "white")
|
| 166 |
+
draw = ImageDraw.Draw(page)
|
| 167 |
+
|
| 168 |
+
draw.text((MARGIN_X, MARGIN_Y - 10), display_name, fill="#111111", font=PAGE_TITLE_FONT)
|
| 169 |
+
meta_text = f"Sheet {page_number} / {page_count} | {len(rows)} circuits on this page"
|
| 170 |
+
draw.text((MARGIN_X, MARGIN_Y + 86), meta_text, fill="#444444", font=PAGE_META_FONT)
|
| 171 |
+
|
| 172 |
+
grid_top = MARGIN_Y + PAGE_HEADER_H
|
| 173 |
+
usable_w = PAGE_W - (2 * MARGIN_X) - ((COLS - 1) * GRID_GAP_X)
|
| 174 |
+
usable_h = PAGE_H - grid_top - MARGIN_Y - ((ROWS - 1) * GRID_GAP_Y)
|
| 175 |
+
card_w = usable_w // COLS
|
| 176 |
+
card_h = usable_h // ROWS
|
| 177 |
+
|
| 178 |
+
for idx, row in enumerate(rows):
|
| 179 |
+
col = idx % COLS
|
| 180 |
+
r = idx // COLS
|
| 181 |
+
x0 = MARGIN_X + col * (card_w + GRID_GAP_X)
|
| 182 |
+
y0 = grid_top + r * (card_h + GRID_GAP_Y)
|
| 183 |
+
x1 = x0 + card_w
|
| 184 |
+
y1 = y0 + card_h
|
| 185 |
+
draw_rounded_box(draw, (x0, y0, x1, y1))
|
| 186 |
+
|
| 187 |
+
content_x = x0 + CARD_PADDING
|
| 188 |
+
content_y = y0 + CARD_PADDING
|
| 189 |
+
content_w = card_w - (2 * CARD_PADDING)
|
| 190 |
+
content_h = card_h - (2 * CARD_PADDING)
|
| 191 |
+
|
| 192 |
+
primary = wrap_lines(row["primary_title"], width=42)[:3]
|
| 193 |
+
context = wrap_lines(row["context"], width=60)[:3]
|
| 194 |
+
meta = wrap_lines(row["source_line"], width=68)[:2]
|
| 195 |
+
|
| 196 |
+
y_cursor = content_y
|
| 197 |
+
for line in primary:
|
| 198 |
+
draw.text((content_x, y_cursor), line, fill="#111111", font=TITLE_FONT)
|
| 199 |
+
y_cursor += 62
|
| 200 |
+
|
| 201 |
+
if context:
|
| 202 |
+
y_cursor += 8
|
| 203 |
+
for line in context:
|
| 204 |
+
draw.text((content_x, y_cursor), line, fill="#444444", font=CONTEXT_FONT)
|
| 205 |
+
y_cursor += 42
|
| 206 |
+
|
| 207 |
+
image_box_top = y_cursor + 18
|
| 208 |
+
meta_h = 40 * max(1, len(meta))
|
| 209 |
+
image_box_h = content_h - (image_box_top - content_y) - meta_h - 18
|
| 210 |
+
|
| 211 |
+
with Image.open(row["image_path"]) as circuit:
|
| 212 |
+
fitted = fit_image(circuit, content_w, image_box_h)
|
| 213 |
+
image_x = content_x + (content_w - fitted.width) // 2
|
| 214 |
+
image_y = image_box_top + max(0, (image_box_h - fitted.height) // 2)
|
| 215 |
+
page.paste(fitted.convert("RGB"), (image_x, image_y))
|
| 216 |
+
|
| 217 |
+
meta_y = content_y + content_h - meta_h
|
| 218 |
+
for line in meta:
|
| 219 |
+
draw.text((content_x, meta_y), line, fill="#666666", font=META_FONT)
|
| 220 |
+
meta_y += 38
|
| 221 |
+
|
| 222 |
+
output_path.parent.mkdir(parents=True, exist_ok=True)
|
| 223 |
+
page.save(output_path, format="PNG", compress_level=3)
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
def main() -> None:
|
| 227 |
+
SHEETS_ORIGINAL_ROOT.mkdir(parents=True, exist_ok=True)
|
| 228 |
+
|
| 229 |
+
grouped: dict[str, list[dict]] = defaultdict(list)
|
| 230 |
+
display_names: dict[str, str] = {}
|
| 231 |
+
|
| 232 |
+
with ROWS_PATH.open() as handle:
|
| 233 |
+
for line in handle:
|
| 234 |
+
raw = json.loads(line)
|
| 235 |
+
source_payload = json.loads(raw["Source"])
|
| 236 |
+
book = source_payload["book"]
|
| 237 |
+
display_names[book] = source_payload["display_name"]
|
| 238 |
+
grouped[book].append(
|
| 239 |
+
{
|
| 240 |
+
"book": book,
|
| 241 |
+
"figure_id": source_payload["figure_id"],
|
| 242 |
+
"image_path": Path(raw["Circuit generated image"]),
|
| 243 |
+
"primary_title": pick_primary_title(source_payload),
|
| 244 |
+
"context": pick_context(source_payload),
|
| 245 |
+
"source_line": pick_source_line(source_payload),
|
| 246 |
+
"source_payload": source_payload,
|
| 247 |
+
}
|
| 248 |
+
)
|
| 249 |
+
|
| 250 |
+
manifest_rows: list[dict[str, str]] = []
|
| 251 |
+
for book in BOOK_ORDER:
|
| 252 |
+
rows = grouped.get(book)
|
| 253 |
+
if not rows:
|
| 254 |
+
continue
|
| 255 |
+
rows.sort(key=lambda row: sort_key(row["source_payload"]))
|
| 256 |
+
display_name = display_names[book]
|
| 257 |
+
page_count = math.ceil(len(rows) / PER_PAGE)
|
| 258 |
+
for page_index in range(page_count):
|
| 259 |
+
start = page_index * PER_PAGE
|
| 260 |
+
end = start + PER_PAGE
|
| 261 |
+
page_rows = rows[start:end]
|
| 262 |
+
output_path = (
|
| 263 |
+
SHEETS_ORIGINAL_ROOT
|
| 264 |
+
/ book
|
| 265 |
+
/ f"{book}_sheet_{page_index + 1:03d}.png"
|
| 266 |
+
)
|
| 267 |
+
build_page(
|
| 268 |
+
page_rows,
|
| 269 |
+
display_name=display_name,
|
| 270 |
+
book=book,
|
| 271 |
+
page_number=page_index + 1,
|
| 272 |
+
page_count=page_count,
|
| 273 |
+
output_path=output_path,
|
| 274 |
+
)
|
| 275 |
+
manifest_rows.append(
|
| 276 |
+
{
|
| 277 |
+
"book": book,
|
| 278 |
+
"display_name": display_name,
|
| 279 |
+
"page_number": str(page_index + 1),
|
| 280 |
+
"page_count": str(page_count),
|
| 281 |
+
"sheet_png": str(output_path.relative_to(SHEETS_ROOT)),
|
| 282 |
+
"figure_ids": "|".join(row["figure_id"] for row in page_rows),
|
| 283 |
+
"titles": " || ".join(row["primary_title"] for row in page_rows),
|
| 284 |
+
}
|
| 285 |
+
)
|
| 286 |
+
|
| 287 |
+
with MANIFEST_PATH.open("w", newline="") as handle:
|
| 288 |
+
writer = csv.DictWriter(
|
| 289 |
+
handle,
|
| 290 |
+
fieldnames=[
|
| 291 |
+
"book",
|
| 292 |
+
"display_name",
|
| 293 |
+
"page_number",
|
| 294 |
+
"page_count",
|
| 295 |
+
"sheet_png",
|
| 296 |
+
"figure_ids",
|
| 297 |
+
"titles",
|
| 298 |
+
],
|
| 299 |
+
)
|
| 300 |
+
writer.writeheader()
|
| 301 |
+
writer.writerows(manifest_rows)
|
| 302 |
+
|
| 303 |
+
|
| 304 |
+
if __name__ == "__main__":
|
| 305 |
+
main()
|
derived/Source/sheets/original/EXP/EXP_sheet_001.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_002.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_003.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_004.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_005.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_006.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_007.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_008.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_009.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_010.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_011.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_012.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_013.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_014.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_015.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_016.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_017.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_021.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_022.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_024.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_026.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_027.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_028.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_029.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_030.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_031.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_032.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_033.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_034.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_035.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_036.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_037.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_039.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_040.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_041.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_042.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_043.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_046.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/EXP/EXP_sheet_047.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/REF/REF_sheet_001.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/REF/REF_sheet_002.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/REF/REF_sheet_003.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/REF/REF_sheet_004.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/REF/REF_sheet_005.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/REF/REF_sheet_006.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/REF/REF_sheet_007.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/original/REF/REF_sheet_008.png
ADDED
|
Git LFS Details
|
derived/Source/sheets/sheet_manifest.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|