Add metadata (WIP)
This commit is contained in:
+1
-7
@@ -3,17 +3,11 @@
|
||||
|
||||
# Folder-level metadata that applies to all plots in this folder
|
||||
title: "Analysis Results"
|
||||
description: "Comprehensive analysis of ttbar events in Run 2 data"
|
||||
description: "ttbar"
|
||||
experiment: "CMS"
|
||||
dataset: "Run2_2016_nano_v9"
|
||||
analysis_type: "ttbar_analysis"
|
||||
|
||||
# Author information
|
||||
author:
|
||||
name: "Klaus Schmidt"
|
||||
email: "kschmidt@example.com"
|
||||
institution: "Example University"
|
||||
|
||||
# Analysis parameters that apply to all plots in this folder
|
||||
parameters:
|
||||
luminosity: "35.9 fb^-1"
|
||||
|
||||
+16
-12
@@ -31,7 +31,7 @@ def load_metadata_file(metadata_path: Path) -> Dict[str, Any]:
|
||||
"""
|
||||
if not metadata_path.exists():
|
||||
return {}
|
||||
|
||||
|
||||
try:
|
||||
with metadata_path.open('r', encoding='utf-8') as f:
|
||||
suffix_lower = metadata_path.suffix.lower()
|
||||
@@ -63,12 +63,14 @@ def load_folder_metadata(folder_path: Path) -> Dict[str, Any]:
|
||||
metadata_path = folder_path / filename
|
||||
if metadata_path.exists():
|
||||
return load_metadata_file(metadata_path)
|
||||
|
||||
|
||||
return {}
|
||||
|
||||
|
||||
def merge_metadata(parent_metadata: Dict[str, Any],
|
||||
child_metadata: Dict[str, Any]) -> Dict[str, Any]:
|
||||
def merge_metadata(
|
||||
parent_metadata: Dict[str, Any],
|
||||
child_metadata: Dict[str, Any]
|
||||
) -> Dict[str, Any]:
|
||||
"""
|
||||
Merge parent and child metadata, with child values overriding parent
|
||||
values.
|
||||
@@ -85,9 +87,10 @@ def merge_metadata(parent_metadata: Dict[str, Any],
|
||||
return merged
|
||||
|
||||
|
||||
def resolve_metadata_for_plot(plot_path: Path,
|
||||
inherited_metadata: Dict[str, Any]
|
||||
) -> Dict[str, Any]:
|
||||
def resolve_metadata_for_plot(
|
||||
plot_path: Path,
|
||||
inherited_metadata: Dict[str, Any]
|
||||
) -> Dict[str, Any]:
|
||||
"""
|
||||
Resolve metadata for a specific plot by merging inherited metadata
|
||||
with plot-specific metadata.
|
||||
@@ -101,21 +104,22 @@ def resolve_metadata_for_plot(plot_path: Path,
|
||||
"""
|
||||
plot_stem = plot_path.stem
|
||||
plot_dir = plot_path.parent
|
||||
|
||||
|
||||
# Check for plot-specific metadata files
|
||||
for suffix in ['.yaml', '.yml', '.json']:
|
||||
plot_metadata_path = plot_dir / f"{plot_stem}{suffix}"
|
||||
if plot_metadata_path.exists():
|
||||
plot_metadata = load_metadata_file(plot_metadata_path)
|
||||
return merge_metadata(inherited_metadata, plot_metadata)
|
||||
|
||||
|
||||
# No plot-specific metadata found, return inherited metadata
|
||||
return inherited_metadata.copy()
|
||||
|
||||
|
||||
def save_metadata_cache(web_dir: Path,
|
||||
plot_metadata_cache: Dict[str, Dict[str, Any]]
|
||||
) -> None:
|
||||
def save_metadata_cache(
|
||||
web_dir: Path,
|
||||
plot_metadata_cache: Dict[str, Dict[str, Any]]
|
||||
) -> None:
|
||||
"""
|
||||
Save plot metadata cache to meta_cache.json in the web directory.
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
<a href="{{ item.pdf_href }}">
|
||||
<img src="{{ item.png_href }}" alt="{{ item.name }}">
|
||||
</a>
|
||||
<button class="metadata-btn" onclick="event.stopPropagation(); showMetadataPopup(this, '{{ item.name|e }}', {{ item.metadata|default('{}')|tojson }})" title="View metadata">
|
||||
<button class="metadata-btn" onclick="event.stopPropagation(); showMetadataPopup(this, '{{ item.name|e }}', {{ (item.metadata or {})|tojson }})" title="View metadata">
|
||||
⋯
|
||||
</button>
|
||||
<div class="plot-name" title="{{ item.name }}">{{ item.name }}</div>
|
||||
|
||||
Reference in New Issue
Block a user