DecodeMarketing FloWeinert Claude Opus 4.7 (1M context) commited on
Commit
e4dd324
·
unverified ·
1 Parent(s): 604577b

Deploy: lowercase sub-block letter fix for Name stims by block (#17)

Browse files

* ci: add CODEOWNERS for restructure

* docs: add github-security-posture per decode-ai-standards

* Refresh CODEOWNERS + posture doc to match current branch-protection model (#6)

* Refresh .github/CODEOWNERS to match current branch-protection model

* Refresh docs/github-security-posture.md to match current branch-protection model

* [ai-standards][slice-2] structure and dependency reproducibility (#8)

* [ai-standards][slice-1] orientation and deploy boundary (#7)

Adds docs-only governance artifacts per the shrunken slice-1 plan
(post hardening commits 1878a50..c7599a7). No changes to app code,
requirements, devcontainer, .streamlit, existing workflows, existing
.claude/.githooks, or CLAUDE.md. README.md changes are additive only.

Artifacts:
- AGENTS.md (thin entrypoint -> CLAUDE.md + docs/INDEX.md)
- SECURITY.md (HF_TOKEN handling, deploy boundary)
- docs/ (INDEX, architecture, reference, guides, progress)
- .github/pull_request_template.md (deploy-boundary checklist)
- scripts/repo_validate.py (py_compile sweep + requirements parse)
- .github/workflows/repo_validate.yml (PR-only, parallel to gate.yml)
- README.md: additive Verification + Branch & Deploy + Architecture sections

Refs decode-ai-standards@81c3f17.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* [ai-standards][slice-2] structure and dependency reproducibility

Adds dependency reproducibility artifacts and policy/runbook documentation
per the shrunken slice-2 plan (workflow hardening deferred to a later slice
on user instruction to keep deploy risk at zero for this slice).

Artifacts:
- pyproject.toml (PEP 621 metadata; no [project.dependencies] to avoid
drift; requirements.txt remains the source of truth consumed by HF Spaces)
- requirements.lock (47 packages, autogenerated by
`uv pip compile --python-version=3.12 requirements.txt`)
- .python-version (3.12; matches runtime.txt and HF Spaces)
- .env.example (comment-only; declares no local env vars; documents
HF_TOKEN as a GitHub Actions secret consumed only by main.yml)
- docs/policies/naming-conventions.md (tab<N>.py rule, helper.py role,
what we explicitly do NOT do)
- docs/policies/root-artifact-policy.md (what is tracked at root, what is
gitignored, what is tolerated locally)
- docs/runbooks/local-setup.md (Windows / macOS / Linux setup walkthrough,
troubleshooting table)
- docs/INDEX.md (link the three new docs under new ## policies and
## runbooks sections; remove their entries from the "planned" stub)

Out of scope (deferred):
- Workflow SHA pinning + permissions blocks on main.yml, gate.yml,
check-file-size.yml — deferred to a later slice because main.yml is the
HF deploy pipeline and deserves its own focused PR + verification cycle
- .gitignore additions for .ruff_cache/, .venv/, .pytest_cache/ — deferred

No changes to app code (app.py, helper.py, tab1.py-tab8.py), requirements.txt,
runtime.txt, .streamlit/, .devcontainer/, existing workflows, existing
.githooks/, existing .claude/, CLAUDE.md, or .gitignore. HF Spaces deploy
is a no-op for this slice because no runtime file is touched.

Refs decode-ai-standards@81c3f17.

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(tab5): carry lowercase sub-block letter into stim labels and reports

Block folders briefed as <NN><lowercase-letter><Category> (e.g. 05cColours)
encode a sub-block. The previous logic stripped every non-digit from the
folder name, dropping the letter, so stims were labelled 01B05whisper... instead
of 01B05cwhisper... A new parse_block() helper extracts the block number and the
optional single lowercase letter (uppercase = start of category name, so 05Colours
has no letter). Applied at every block-ID construction site used by the
'Name stims by block' tool (tab5) and the Asset Overview PDF (tab4).

tab6 (Rerun Matrix): rebuild the brand index from the Excel 'factor' column and
the leading brand number instead of regex-parsing the brand out of the ID, since
the optional sub-block letter makes ID-based brand parsing ambiguous.

tab5 instructions updated to document the lowercase-letter naming convention.

---------

Co-authored-by: FloWeinert <weinert@decodemarketing.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

Files changed (3) hide show
  1. helper.py +36 -16
  2. tab5.py +9 -1
  3. tab6.py +7 -5
helper.py CHANGED
@@ -38,6 +38,26 @@ ALL_ALLOWED_EXTENSIONS = (ALLOWED_IMAGE_EXTENSIONS | ALLOWED_TEXT_EXTENSIONS |
38
  ALLOWED_DATA_EXTENSIONS | ALLOWED_OTHER_EXTENSIONS)
39
 
40
  # Helper functions from both files
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  def extract_zip_to_temp(uploaded_file):
42
  """Extract uploaded zip file to temporary directory"""
43
  temp_dir = tempfile.mkdtemp()
@@ -112,8 +132,8 @@ def process_files(input_folder, marken_index, output_root):
112
  for subfolder in sorted(Path(input_folder).iterdir()):
113
  if not subfolder.is_dir():
114
  continue
115
- blocknummer = re.sub(r'\D', '', subfolder.name)[:2].zfill(2)
116
-
117
  files_to_process = []
118
  for file in sorted(subfolder.iterdir()):
119
  # Skip if not a file
@@ -148,7 +168,7 @@ def process_files(input_folder, marken_index, output_root):
148
  markennummer = marken_index[marke]
149
  cleaned = get_cleaned_filename_without_brand(file.name, marke)
150
 
151
- neuer_name = f"{markennummer}B{blocknummer}{marke}{count_str}{cleaned}{file.suffix.lower()}"
152
  ziel = output_root / neuer_name
153
 
154
  if file.suffix.lower() in ALLOWED_IMAGE_EXTENSIONS:
@@ -318,12 +338,12 @@ def add_brand_pages_with_png_extensions(elements, marken_spalten, renamed_files_
318
  brand_counter = 1 # Add sequential counter for each brand in each folder
319
  for pfad, original_name in folder_assets:
320
  # Generate the ID name with .png extension for display
321
- blocknummer = re.sub(r'\D', '', folder)[:2].zfill(2)
322
  markennummer = marken_index[marke]
323
  count_str = f"{brand_counter:02d}" # Format as 01, 02, 03, etc.
324
  cleaned = get_cleaned_filename_without_brand(original_name, marke)
325
  original_ext = Path(original_name).suffix.lower() # Get actual extension
326
- id_name = f"{markennummer}B{blocknummer}{marke}{count_str}{cleaned}{original_ext}" # Include counter
327
  assets.append((pfad, id_name))
328
  brand_counter += 1 # Increment counter for next file
329
 
@@ -434,12 +454,12 @@ def generate_filename_based_pdf_report_with_extensions(input_folder, erste_marke
434
  brand_counter = 1 # Add sequential counter for each brand
435
  for p, original_name in eintraege:
436
  # Generate the ID name and add .png extension for display
437
- blocknummer = re.sub(r'\D', '', folder)[:2].zfill(2)
438
  markennummer = marken_index[marke]
439
  count_str = f"{brand_counter:02d}" # Format as 01, 02, 03, etc.
440
  cleaned = get_cleaned_filename_without_brand(original_name, marke)
441
  original_ext = Path(original_name).suffix.lower() # Get actual extension
442
- id_name = f"{markennummer}B{blocknummer}{marke}{count_str}{cleaned}{original_ext}" # Include counter
443
 
444
  cell = get_asset_cell(p, id_name, len(headers))
445
  zellen.append(cell)
@@ -1021,12 +1041,12 @@ def generate_filename_based_pdf_report(input_folder, erste_marke=None, processed
1021
  zellen = []
1022
  for original_path, original_name in eintraege:
1023
  # Generate the final processed ID name
1024
- blocknummer = re.sub(r'\D', '', folder)[:2].zfill(2)
1025
  markennummer = marken_index[marke]
1026
  cleaned = get_cleaned_filename_without_brand(original_name, marke)
1027
  # Create the final ID without file extension for display
1028
- final_id = f"{markennummer}B{blocknummer}{marke}{cleaned}"
1029
-
1030
  # Create cell with original path but final ID label
1031
  cell = get_asset_cell(original_path, final_id, len(headers))
1032
  zellen.append(cell)
@@ -1084,10 +1104,10 @@ def add_brand_pages_with_final_labels(elements, marken_spalten, renamed_files_by
1084
  folder_assets = renamed_files_by_folder_and_marke[folder].get(marke, [])
1085
  for original_path, original_name in folder_assets:
1086
  # Generate the final processed ID name (same logic as in Excel generation)
1087
- blocknummer = re.sub(r'\D', '', folder)[:2].zfill(2)
1088
  markennummer = marken_index[marke]
1089
  cleaned = get_cleaned_filename_without_brand(original_name, marke)
1090
- final_id = f"{markennummer}B{blocknummer}{marke}{cleaned}"
1091
  assets.append((original_path, final_id))
1092
 
1093
  if not assets:
@@ -1178,12 +1198,12 @@ def generate_two_section_pdf_report(input_folder, erste_marke=None):
1178
  zellen = []
1179
  for p, original_name in eintraege:
1180
  # Generate the ID name - KEEP THE FILE EXTENSION
1181
- blocknummer = re.sub(r'\D', '', folder)[:2].zfill(2)
1182
  markennummer = marken_index[marke]
1183
  cleaned = get_cleaned_filename_without_brand(original_name, marke)
1184
  # Keep the original file extension
1185
  file_extension = Path(original_name).suffix.lower()
1186
- id_name = f"{markennummer}B{blocknummer}{marke}{cleaned}{file_extension}"
1187
 
1188
  # Pass the full filename with extension to get_asset_cell
1189
  cell = get_asset_cell(p, id_name, len(headers))
@@ -1236,13 +1256,13 @@ def generate_two_section_pdf_report(input_folder, erste_marke=None):
1236
  brand_counter = 1 # Start counting from 1 for each brand in each folder
1237
  for pfad, original_name in folder_assets:
1238
  # Generate the ID name with sequential count - KEEP THE FILE EXTENSION
1239
- blocknummer = re.sub(r'\D', '', folder)[:2].zfill(2)
1240
  markennummer = marken_index[marke]
1241
  count_str = f"{brand_counter:02d}"
1242
  cleaned = get_cleaned_filename_without_brand(original_name, marke)
1243
  # Keep the original file extension
1244
  file_extension = Path(original_name).suffix.lower()
1245
- id_name = f"{markennummer}B{blocknummer}{marke}{count_str}{cleaned}{file_extension}"
1246
  assets.append((pfad, id_name))
1247
  brand_counter += 1
1248
 
 
38
  ALLOWED_DATA_EXTENSIONS | ALLOWED_OTHER_EXTENSIONS)
39
 
40
  # Helper functions from both files
41
+ def parse_block(folder_name):
42
+ """Extract the block number and optional lowercase block letter from a folder name.
43
+
44
+ Block folders are briefed as ``<digits><Category>`` (e.g. ``05Colours``) or, when a
45
+ block is split into sub-blocks, ``<digits><lowercase-letter><Category>`` (e.g.
46
+ ``05cColours``). The optional block letter is a SINGLE lowercase letter directly
47
+ after the leading digits. Because category names start with an uppercase letter,
48
+ a lowercase letter there is unambiguous — ``05Colours`` has no block letter, while
49
+ ``05cColours`` has block letter ``c``.
50
+
51
+ Returns ``(blocknummer, blockletter)``, e.g. ``("05", "c")`` or ``("05", "")``.
52
+ """
53
+ # Block number: first two digits found, preserving the previous behaviour.
54
+ blocknummer = re.sub(r'\D', '', folder_name)[:2].zfill(2)
55
+ # Block letter: a single lowercase letter immediately following the leading digits.
56
+ match = re.match(r'\d+([a-z])', folder_name)
57
+ blockletter = match.group(1) if match else ''
58
+ return blocknummer, blockletter
59
+
60
+
61
  def extract_zip_to_temp(uploaded_file):
62
  """Extract uploaded zip file to temporary directory"""
63
  temp_dir = tempfile.mkdtemp()
 
132
  for subfolder in sorted(Path(input_folder).iterdir()):
133
  if not subfolder.is_dir():
134
  continue
135
+ blocknummer, blockletter = parse_block(subfolder.name)
136
+
137
  files_to_process = []
138
  for file in sorted(subfolder.iterdir()):
139
  # Skip if not a file
 
168
  markennummer = marken_index[marke]
169
  cleaned = get_cleaned_filename_without_brand(file.name, marke)
170
 
171
+ neuer_name = f"{markennummer}B{blocknummer}{blockletter}{marke}{count_str}{cleaned}{file.suffix.lower()}"
172
  ziel = output_root / neuer_name
173
 
174
  if file.suffix.lower() in ALLOWED_IMAGE_EXTENSIONS:
 
338
  brand_counter = 1 # Add sequential counter for each brand in each folder
339
  for pfad, original_name in folder_assets:
340
  # Generate the ID name with .png extension for display
341
+ blocknummer, blockletter = parse_block(folder)
342
  markennummer = marken_index[marke]
343
  count_str = f"{brand_counter:02d}" # Format as 01, 02, 03, etc.
344
  cleaned = get_cleaned_filename_without_brand(original_name, marke)
345
  original_ext = Path(original_name).suffix.lower() # Get actual extension
346
+ id_name = f"{markennummer}B{blocknummer}{blockletter}{marke}{count_str}{cleaned}{original_ext}" # Include counter
347
  assets.append((pfad, id_name))
348
  brand_counter += 1 # Increment counter for next file
349
 
 
454
  brand_counter = 1 # Add sequential counter for each brand
455
  for p, original_name in eintraege:
456
  # Generate the ID name and add .png extension for display
457
+ blocknummer, blockletter = parse_block(folder)
458
  markennummer = marken_index[marke]
459
  count_str = f"{brand_counter:02d}" # Format as 01, 02, 03, etc.
460
  cleaned = get_cleaned_filename_without_brand(original_name, marke)
461
  original_ext = Path(original_name).suffix.lower() # Get actual extension
462
+ id_name = f"{markennummer}B{blocknummer}{blockletter}{marke}{count_str}{cleaned}{original_ext}" # Include counter
463
 
464
  cell = get_asset_cell(p, id_name, len(headers))
465
  zellen.append(cell)
 
1041
  zellen = []
1042
  for original_path, original_name in eintraege:
1043
  # Generate the final processed ID name
1044
+ blocknummer, blockletter = parse_block(folder)
1045
  markennummer = marken_index[marke]
1046
  cleaned = get_cleaned_filename_without_brand(original_name, marke)
1047
  # Create the final ID without file extension for display
1048
+ final_id = f"{markennummer}B{blocknummer}{blockletter}{marke}{cleaned}"
1049
+
1050
  # Create cell with original path but final ID label
1051
  cell = get_asset_cell(original_path, final_id, len(headers))
1052
  zellen.append(cell)
 
1104
  folder_assets = renamed_files_by_folder_and_marke[folder].get(marke, [])
1105
  for original_path, original_name in folder_assets:
1106
  # Generate the final processed ID name (same logic as in Excel generation)
1107
+ blocknummer, blockletter = parse_block(folder)
1108
  markennummer = marken_index[marke]
1109
  cleaned = get_cleaned_filename_without_brand(original_name, marke)
1110
+ final_id = f"{markennummer}B{blocknummer}{blockletter}{marke}{cleaned}"
1111
  assets.append((original_path, final_id))
1112
 
1113
  if not assets:
 
1198
  zellen = []
1199
  for p, original_name in eintraege:
1200
  # Generate the ID name - KEEP THE FILE EXTENSION
1201
+ blocknummer, blockletter = parse_block(folder)
1202
  markennummer = marken_index[marke]
1203
  cleaned = get_cleaned_filename_without_brand(original_name, marke)
1204
  # Keep the original file extension
1205
  file_extension = Path(original_name).suffix.lower()
1206
+ id_name = f"{markennummer}B{blocknummer}{blockletter}{marke}{cleaned}{file_extension}"
1207
 
1208
  # Pass the full filename with extension to get_asset_cell
1209
  cell = get_asset_cell(p, id_name, len(headers))
 
1256
  brand_counter = 1 # Start counting from 1 for each brand in each folder
1257
  for pfad, original_name in folder_assets:
1258
  # Generate the ID name with sequential count - KEEP THE FILE EXTENSION
1259
+ blocknummer, blockletter = parse_block(folder)
1260
  markennummer = marken_index[marke]
1261
  count_str = f"{brand_counter:02d}"
1262
  cleaned = get_cleaned_filename_without_brand(original_name, marke)
1263
  # Keep the original file extension
1264
  file_extension = Path(original_name).suffix.lower()
1265
+ id_name = f"{markennummer}B{blocknummer}{blockletter}{marke}{count_str}{cleaned}{file_extension}"
1266
  assets.append((pfad, id_name))
1267
  brand_counter += 1
1268
 
tab5.py CHANGED
@@ -292,7 +292,15 @@ def brand_renamer_tool():
292
  4. Generate a PDF report showing all assets with original filenames and extensions
293
  5. Create an Excel overview of the processed files (all file types)
294
  6. Package everything for easy download
295
-
 
 
 
 
 
 
 
 
296
  **Supported file types:** All extensions are supported including:
297
  - Images: .png, .jpg, .jpeg, .gif, .bmp, .svg, .webp
298
  - Videos: .mp4, .avi, .mov, .mkv, .webm
 
292
  4. Generate a PDF report showing all assets with original filenames and extensions
293
  5. Create an Excel overview of the processed files (all file types)
294
  6. Package everything for easy download
295
+
296
+ **Block folder naming (important):**
297
+ - Name each block folder starting with its two-digit block number, e.g. `05Colours`.
298
+ - If a block is split into sub-blocks, add a **lowercase** letter directly after the
299
+ number, e.g. `05aColours`, `05bColours`, `05cColours`. The lowercase letter is carried
300
+ into the stim labels (e.g. `01B05cwhisper01...`) and into the reports.
301
+ - The letter **must be lowercase** — an uppercase letter (e.g. `05CColours`) is treated as
302
+ the start of the category name and is **not** picked up as a sub-block.
303
+
304
  **Supported file types:** All extensions are supported including:
305
  - Images: .png, .jpg, .jpeg, .gif, .bmp, .svg, .webp
306
  - Videos: .mp4, .avi, .mov, .mkv, .webm
tab6.py CHANGED
@@ -138,11 +138,13 @@ def extract_metadata_from_excel(excel_data: Dict) -> Dict:
138
  metadata['file_to_factorgroup'][file_id] = factorgroup
139
  metadata['folder_names'].add(factorgroup)
140
 
141
- # Extract brand number from ID (first 2 digits)
142
- match = re.match(r'(\d{2})B\d{2}([a-zA-Z]+)', file_id)
143
- if match:
144
- brand_num, brand_name = match.groups()
145
- metadata['marken_index'][brand_name.lower()] = brand_num
 
 
146
 
147
  return metadata
148
 
 
138
  metadata['file_to_factorgroup'][file_id] = factorgroup
139
  metadata['folder_names'].add(factorgroup)
140
 
141
+ # Brand number = leading two digits of the ID. The brand NAME is taken from the
142
+ # already-resolved 'factor' column, NOT parsed out of the ID: an optional lowercase
143
+ # sub-block letter can now sit between the block number and the brand
144
+ # (e.g. 01B05c<brand>), which makes parsing the brand out of the ID ambiguous.
145
+ num_match = re.match(r'(\d{2})B', file_id)
146
+ if num_match and factor and factor.lower() != 'nan':
147
+ metadata['marken_index'][factor.lower()] = num_match.group(1)
148
 
149
  return metadata
150