Update STARGATE_EXPANSION
Browse files- STARGATE_EXPANSION +75 -5
STARGATE_EXPANSION
CHANGED
|
@@ -9,7 +9,7 @@ import json
|
|
| 9 |
import glob
|
| 10 |
from datetime import datetime
|
| 11 |
from typing import List, Dict, Optional, Tuple
|
| 12 |
-
from dataclasses import dataclass
|
| 13 |
import statistics
|
| 14 |
from collections import Counter
|
| 15 |
import matplotlib.pyplot as plt
|
|
@@ -430,37 +430,107 @@ def analyze_sessions_cli():
|
|
| 430 |
help='Generate metrics visualization')
|
| 431 |
parser.add_argument('--trend-report', action='store_true',
|
| 432 |
help='Generate trend report')
|
|
|
|
|
|
|
| 433 |
|
| 434 |
args = parser.parse_args()
|
| 435 |
|
| 436 |
# Load sessions
|
| 437 |
sessions = []
|
| 438 |
for session_file in args.session_files:
|
| 439 |
-
|
| 440 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 441 |
|
| 442 |
analyzer = SessionAnalyzer(sessions)
|
| 443 |
|
| 444 |
if args.trend_report:
|
|
|
|
|
|
|
|
|
|
| 445 |
trends = analyzer.generate_trend_report()
|
| 446 |
-
print("\n=== SESSION TREND REPORT ===")
|
| 447 |
for key, value in trends.items():
|
| 448 |
-
print(f"{key}: {value}")
|
| 449 |
|
| 450 |
if args.wordcloud:
|
|
|
|
| 451 |
all_impressions = []
|
| 452 |
for session in sessions:
|
| 453 |
all_impressions.extend(session['impressions'])
|
| 454 |
|
| 455 |
visualizer = SessionVisualizer()
|
| 456 |
fig = visualizer.generate_impression_wordcloud(all_impressions)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 457 |
plt.show()
|
| 458 |
|
| 459 |
if args.metrics_plot:
|
|
|
|
| 460 |
analyzer.analyze_all_sessions()
|
| 461 |
visualizer = SessionVisualizer()
|
| 462 |
fig = visualizer.plot_session_metrics(analyzer.metrics)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 463 |
plt.show()
|
| 464 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 465 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 466 |
analyze_sessions_cli()
|
|
|
|
| 9 |
import glob
|
| 10 |
from datetime import datetime
|
| 11 |
from typing import List, Dict, Optional, Tuple
|
| 12 |
+
from dataclasses import dataclass, asdict # Added asdict import
|
| 13 |
import statistics
|
| 14 |
from collections import Counter
|
| 15 |
import matplotlib.pyplot as plt
|
|
|
|
| 430 |
help='Generate metrics visualization')
|
| 431 |
parser.add_argument('--trend-report', action='store_true',
|
| 432 |
help='Generate trend report')
|
| 433 |
+
parser.add_argument('--output-dir', default='.',
|
| 434 |
+
help='Output directory for generated files')
|
| 435 |
|
| 436 |
args = parser.parse_args()
|
| 437 |
|
| 438 |
# Load sessions
|
| 439 |
sessions = []
|
| 440 |
for session_file in args.session_files:
|
| 441 |
+
try:
|
| 442 |
+
with open(session_file, 'r') as f:
|
| 443 |
+
sessions.append(json.load(f))
|
| 444 |
+
print(f"✓ Loaded {session_file}")
|
| 445 |
+
except Exception as e:
|
| 446 |
+
print(f"✗ Failed to load {session_file}: {e}")
|
| 447 |
+
|
| 448 |
+
if not sessions:
|
| 449 |
+
print("No valid sessions loaded. Exiting.")
|
| 450 |
+
return
|
| 451 |
|
| 452 |
analyzer = SessionAnalyzer(sessions)
|
| 453 |
|
| 454 |
if args.trend_report:
|
| 455 |
+
print("\n" + "="*50)
|
| 456 |
+
print("SESSION TREND REPORT")
|
| 457 |
+
print("="*50)
|
| 458 |
trends = analyzer.generate_trend_report()
|
|
|
|
| 459 |
for key, value in trends.items():
|
| 460 |
+
print(f"{key.replace('_', ' ').title():<30}: {value:.3f}")
|
| 461 |
|
| 462 |
if args.wordcloud:
|
| 463 |
+
print("\nGenerating word cloud...")
|
| 464 |
all_impressions = []
|
| 465 |
for session in sessions:
|
| 466 |
all_impressions.extend(session['impressions'])
|
| 467 |
|
| 468 |
visualizer = SessionVisualizer()
|
| 469 |
fig = visualizer.generate_impression_wordcloud(all_impressions)
|
| 470 |
+
|
| 471 |
+
output_path = f"{args.output_dir}/wordcloud_{datetime.now().strftime('%Y%m%d_%H%M%S')}.png"
|
| 472 |
+
plt.savefig(output_path, dpi=300, bbox_inches='tight')
|
| 473 |
+
print(f"✓ Word cloud saved to: {output_path}")
|
| 474 |
plt.show()
|
| 475 |
|
| 476 |
if args.metrics_plot:
|
| 477 |
+
print("\nGenerating metrics visualization...")
|
| 478 |
analyzer.analyze_all_sessions()
|
| 479 |
visualizer = SessionVisualizer()
|
| 480 |
fig = visualizer.plot_session_metrics(analyzer.metrics)
|
| 481 |
+
|
| 482 |
+
output_path = f"{args.output_dir}/metrics_{datetime.now().strftime('%Y%m%d_%H%M%S')}.png"
|
| 483 |
+
plt.savefig(output_path, dpi=300, bbox_inches='tight')
|
| 484 |
+
print(f"✓ Metrics plot saved to: {output_path}")
|
| 485 |
plt.show()
|
| 486 |
|
| 487 |
+
# ------------------------------------------------------------------------------------
|
| 488 |
+
# Utility Functions
|
| 489 |
+
# ------------------------------------------------------------------------------------
|
| 490 |
+
|
| 491 |
+
def load_all_sessions(session_dir: str = ".") -> List[Dict]:
|
| 492 |
+
"""Load all session JSON files from a directory"""
|
| 493 |
+
pattern = f"{session_dir}/stargate_session_*.json"
|
| 494 |
+
session_files = glob.glob(pattern)
|
| 495 |
+
sessions = []
|
| 496 |
+
|
| 497 |
+
for session_file in session_files:
|
| 498 |
+
try:
|
| 499 |
+
with open(session_file, 'r') as f:
|
| 500 |
+
sessions.append(json.load(f))
|
| 501 |
+
except Exception as e:
|
| 502 |
+
print(f"Warning: Could not load {session_file}: {e}")
|
| 503 |
+
|
| 504 |
+
return sessions
|
| 505 |
+
|
| 506 |
+
def create_sample_targets():
|
| 507 |
+
"""Create sample targets for testing"""
|
| 508 |
+
db = TargetDatabase("sample_targets.json")
|
| 509 |
+
|
| 510 |
+
sample_targets = [
|
| 511 |
+
("Tokyo_Tower", "coordinate", "Famous Tokyo landmark with distinctive red and white structure"),
|
| 512 |
+
("Mars_Rover", "future", "Current operations of Perseverance rover on Mars surface"),
|
| 513 |
+
("Pyramid_Giza", "symbol", "Great Pyramid of Giza interior chambers"),
|
| 514 |
+
("Deep_Ocean", "coordinate", "Mariana Trench deepest point ecosystem"),
|
| 515 |
+
("Tesla_Lab", "past", "Nikola Tesla's laboratory in Colorado Springs, 1899"),
|
| 516 |
+
("Crop_Circle", "symbol", "Complex crop formation in English countryside"),
|
| 517 |
+
]
|
| 518 |
+
|
| 519 |
+
for identifier, category, description in sample_targets:
|
| 520 |
+
db.add_target(identifier, category, description)
|
| 521 |
+
|
| 522 |
+
print("✓ Sample targets created in sample_targets.json")
|
| 523 |
+
|
| 524 |
if __name__ == "__main__":
|
| 525 |
+
# If no arguments, show help and examples
|
| 526 |
+
if len(sys.argv) == 1:
|
| 527 |
+
print("Stargate Analysis Module")
|
| 528 |
+
print("\nUsage examples:")
|
| 529 |
+
print(" python stargate_analysis.py --session-files session1.json session2.json --trend-report")
|
| 530 |
+
print(" python stargate_analysis.py --session-files *.json --wordcloud --metrics-plot")
|
| 531 |
+
print(" python stargate_analysis.py --session-files recent_session.json --trend-report --output-dir ./reports")
|
| 532 |
+
print("\nTo create sample targets:")
|
| 533 |
+
print(" python -c \"from stargate_analysis import create_sample_targets; create_sample_targets()\"")
|
| 534 |
+
sys.exit(1)
|
| 535 |
+
|
| 536 |
analyze_sessions_cli()
|