From 465f9b6dc6e654fc41ea44aa36eec8e27ac90f70 Mon Sep 17 00:00:00 2001 From: Kylian Schmidt Date: Mon, 21 Jul 2025 15:33:33 +0200 Subject: [PATCH] Try to fix metadata stuff again (does not work) --- assets/css/metadata.css | 2 +- config.yaml | 2 ++ debug_template.py | 49 --------------------------------------- generate_gallery.py | 5 ++++ orchestration/metadata.py | 2 +- refresh_gallery.py | 22 ++++++++++-------- templates/gallery.html | 6 ++++- 7 files changed, 26 insertions(+), 62 deletions(-) delete mode 100644 debug_template.py diff --git a/assets/css/metadata.css b/assets/css/metadata.css index 872fef6..d6ab001 100644 --- a/assets/css/metadata.css +++ b/assets/css/metadata.css @@ -47,7 +47,7 @@ /* Metadata popup */ .metadata-popup { - background: var(--card-background); + background: var(--card-bg); border: 1px solid var(--border-color); border-radius: 8px; box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3); diff --git a/config.yaml b/config.yaml index b268e06..14ef13b 100644 --- a/config.yaml +++ b/config.yaml @@ -47,3 +47,5 @@ metadata: sources: - name: "ttbar_analysis" path: "/work/kschmidt/NEEDLE/test_analysis/data/cf_store/test_analysis/cf.PlotVariables1D/run2_2016_nano_v9/" + - name: "NEEDLE_benchmarks" + path: "/work/kschmidt/NEEDLE/orchestrator/ml/benchmarks/plots" diff --git a/debug_template.py b/debug_template.py deleted file mode 100644 index 89e9c8a..0000000 --- a/debug_template.py +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env python3 - -from pathlib import Path -from jinja2 import Environment, FileSystemLoader - -# Test template rendering -env = Environment(loader=FileSystemLoader(".")) -template = env.get_template("templates/gallery.html") - -# Mock data -test_items = [{ - "name": "test_plot", - "pdf_href": "test_plot.pdf", - "png_href": "test_plot.png", - "metadata": {"key1": "value1", "key2": "value2"} -}] - -test_config = { - "paths": {"work_dir": "/work/kschmidt/web"}, - "ui": {"search_debounce_ms": 300, "max_recent_plots": 20} -} - -rendered = template.render( - title="Test Gallery", - items=test_items, - subdirs=["test_subdir"], - relpath="test/path", - paths=test_config["paths"], - ui=test_config["ui"], - stats={"file_count": 1, "folder_count": 1, "total_size": "100 KB", "total_size_bytes": 100000}, - folder_metadata={}, - assets_path="../assets" -) - -# Extract just the metadata button part -lines = rendered.split('\n') -for i, line in enumerate(lines): - if 'metadata-btn' in line: - print(f"Line {i}: {line.strip()}") - if i > 0: - print(f"Line {i-1}: {lines[i-1].strip()}") - if i < len(lines)-1: - print(f"Line {i+1}: {lines[i+1].strip()}") - break - -print("\n--- Assets path in template ---") -for i, line in enumerate(lines): - if 'assets_path' in line: - print(f"Line {i}: {line.strip()}") diff --git a/generate_gallery.py b/generate_gallery.py index 88fb3a5..0217a0f 100644 --- a/generate_gallery.py +++ b/generate_gallery.py @@ -144,6 +144,11 @@ def build_gallery(source_dir: Path, web_dir: Path, # Resolve metadata for this specific plot plot_metadata = resolve_metadata_for_plot(pdf_file, current_metadata) + if not plot_metadata: + plot_metadata = {} + for k, v in plot_metadata.items(): + if isinstance(v, str): + plot_metadata[k] = v.replace('<', '').replace('>', '').replace('&', '').replace('"', "'") plot_metadata_cache[pdf_file.stem] = plot_metadata items.append({ diff --git a/orchestration/metadata.py b/orchestration/metadata.py index d7c993d..4c1d9b8 100644 --- a/orchestration/metadata.py +++ b/orchestration/metadata.py @@ -45,7 +45,7 @@ def load_metadata_file(metadata_path: Path) -> Dict[str, Any]: return {} except (yaml.YAMLError, json.JSONDecodeError, IOError) as e: print(f"Warning: Could not parse metadata file {metadata_path}: {e}") - return {} + raise e def load_folder_metadata(folder_path: Path) -> Dict[str, Any]: diff --git a/refresh_gallery.py b/refresh_gallery.py index 546af3b..6e978c2 100755 --- a/refresh_gallery.py +++ b/refresh_gallery.py @@ -12,17 +12,19 @@ def main(): print("Content-Type: text/plain") print("Cache-Control: no-cache") print() # Empty line to end headers - + try: # Call the gallery generation script - result = subprocess.run([ - "python3", - "/work/kschmidt/web/generate_gallery.py" - ], - capture_output=True, - text=True, - timeout=300) # 5 minute timeout - + result = subprocess.run( + [ + "python3", + "/work/kschmidt/web/generate_gallery.py" + ], + capture_output=True, + text=True, + timeout=300, + ) + if result.returncode == 0: print("Gallery refresh successful!") print("\nOutput:") @@ -38,7 +40,7 @@ def main(): if result.stdout: print("\nStandard output:") print(result.stdout) - + except subprocess.TimeoutExpired: print("Gallery refresh timed out after 5 minutes") except Exception as e: diff --git a/templates/gallery.html b/templates/gallery.html index 6de9970..db63f8a 100644 --- a/templates/gallery.html +++ b/templates/gallery.html @@ -41,7 +41,11 @@ {{ item.name }} -
{{ item.name }}