|
|
| """
|
| Build GRAIL-Heart Network Explorer
|
| Embeds JSON data directly into HTML for GitHub Pages deployment
|
| """
|
|
|
| import json
|
| import os
|
| from pathlib import Path
|
|
|
| def build_explorer():
|
| """Build the explorer with embedded data for static hosting."""
|
|
|
| base_dir = Path(__file__).parent.parent
|
| cytoscape_dir = base_dir / "outputs" / "cytoscape"
|
| data_dir = cytoscape_dir / "data"
|
|
|
|
|
| all_networks_path = data_dir / "all_networks.json"
|
| if not all_networks_path.exists():
|
| print("❌ Network data not found. Run generate_network_data.py first.")
|
| return False
|
|
|
| with open(all_networks_path, 'r') as f:
|
| network_data = json.load(f)
|
|
|
| print(f"Loaded network data: {len(network_data)} networks")
|
|
|
|
|
| html_path = cytoscape_dir / "grail_heart_explorer.html"
|
| with open(html_path, 'r', encoding='utf-8') as f:
|
| html_content = f.read()
|
|
|
|
|
|
|
| embedded_js = f""" <script>
|
| // Network data - embedded for static hosting (GitHub Pages)
|
| // Generated by scripts/build_explorer.py
|
| const networkData = {json.dumps(network_data, separators=(',', ':'))};
|
|
|
| // No need to fetch - data is embedded
|
| async function loadNetworkData() {{
|
| console.log('Using embedded network data');
|
| return true;
|
| }}
|
|
|
| // Region descriptions
|
| const regionInfo = {{"""
|
|
|
|
|
| import re
|
|
|
|
|
| pattern = r' <script>\s*// Network data.*?// Region descriptions\s*const regionInfo = \{'
|
|
|
| replacement = embedded_js
|
|
|
| embedded_html = re.sub(pattern, replacement, html_content, flags=re.DOTALL)
|
|
|
|
|
| output_path = cytoscape_dir / "grail_heart_explorer_built.html"
|
| with open(output_path, 'w', encoding='utf-8') as f:
|
| f.write(embedded_html)
|
|
|
| print(f"Built explorer saved to: {output_path}")
|
| print(f" File size: {output_path.stat().st_size / 1024:.1f} KB")
|
|
|
|
|
|
|
| gh_pages_path = cytoscape_dir / "index.html"
|
| with open(gh_pages_path, 'w', encoding='utf-8') as f:
|
| f.write(embedded_html)
|
|
|
| print(f"GitHub Pages version saved to: {gh_pages_path}")
|
|
|
| return True
|
|
|
| if __name__ == "__main__":
|
| build_explorer()
|
|
|