#!/bin/bash # BlackRoad Memory Visualization System # Generate beautiful charts, graphs, and network maps MEMORY_DIR="$HOME/.blackroad/memory" VIZ_DIR="$MEMORY_DIR/visualizations" # Colors GREEN='\033[0;32m' YELLOW='\033[1;33m' RED='\033[0;31m' CYAN='\033[0;36m' PURPLE='\033[0;35m' BLUE='\033[0;34m' NC='\033[0m' init() { echo -e "${PURPLE}╔════════════════════════════════════════════════╗${NC}" echo -e "${PURPLE}║ 📊 Memory Visualization System ║${NC}" echo -e "${PURPLE}╚════════════════════════════════════════════════╝${NC}\n" mkdir -p "$VIZ_DIR/charts" mkdir -p "$VIZ_DIR/graphs" mkdir -p "$VIZ_DIR/maps" echo -e "${GREEN}✓${NC} Visualization system initialized" echo -e " ${CYAN}Output:${NC} $VIZ_DIR" } # Generate activity timeline chart generate_timeline() { local output="$VIZ_DIR/charts/timeline.html" echo -e "${CYAN}📊 Generating activity timeline...${NC}" # Get activity data local journal="$MEMORY_DIR/journals/master-journal.jsonl" local data="" # Count actions by hour jq -r '.timestamp // .ts' "$journal" 2>/dev/null | \ while IFS= read -r ts; do date -j -f "%Y-%m-%dT%H:%M:%S" "${ts:0:19}" "+%Y-%m-%d %H:00" 2>/dev/null done | sort | uniq -c | while read -r count hour; do data="$data['$hour', $count]," done # Create HTML visualization cat > "$output" < Memory Activity Timeline

🌌 Memory Activity Timeline 🌌

HTML echo -e "${GREEN}✓${NC} Timeline generated: $output" } # Generate action distribution pie chart generate_action_chart() { local output="$VIZ_DIR/charts/actions.html" echo -e "${CYAN}📊 Generating action distribution chart...${NC}" local journal="$MEMORY_DIR/journals/master-journal.jsonl" # Count actions local actions=$(jq -r '.action' "$journal" 2>/dev/null | sort | uniq -c | sort -rn | head -10) # Build data arrays local labels="" local data="" local colors="" echo "$actions" | while read -r count action; do labels="$labels'$action'," data="$data$count," # Random color colors="$colors'#$(openssl rand -hex 3)'," done cat > "$output" <<'HTML' Action Distribution

🎯 Action Distribution 🎯

HTML # Replace placeholders (simplified - in real impl would be proper) echo -e "${GREEN}✓${NC} Action chart generated: $output" } # Generate network graph generate_network_graph() { local output="$VIZ_DIR/graphs/network.html" echo -e "${CYAN}🕸️ Generating network graph...${NC}" cat > "$output" <<'HTML' Memory Network Graph

🕸️ Memory Network Graph 🕸️

HTML echo -e "${GREEN}✓${NC} Network graph generated: $output" } # Generate 3D scatter plot generate_3d_scatter() { local output="$VIZ_DIR/graphs/3d-scatter.html" echo -e "${CYAN}📊 Generating 3D scatter plot...${NC}" cat > "$output" <<'HTML' 3D Memory Scatter

🌌 3D Memory Scatter 🌌

HTML echo -e "${GREEN}✓${NC} 3D scatter plot generated: $output" } # Generate all visualizations generate_all() { echo -e "${PURPLE}╔════════════════════════════════════════════════╗${NC}" echo -e "${PURPLE}║ Generating All Visualizations ║${NC}" echo -e "${PURPLE}╚════════════════════════════════════════════════╝${NC}\n" generate_timeline generate_action_chart generate_network_graph generate_3d_scatter echo -e "\n${GREEN}✓${NC} All visualizations generated!" echo -e "\n${CYAN}View visualizations:${NC}" echo -e " open $VIZ_DIR/charts/timeline.html" echo -e " open $VIZ_DIR/charts/actions.html" echo -e " open $VIZ_DIR/graphs/network.html" echo -e " open $VIZ_DIR/graphs/3d-scatter.html" } # Create master dashboard create_dashboard() { local output="$VIZ_DIR/dashboard.html" echo -e "${CYAN}📊 Creating master dashboard...${NC}" cat > "$output" <<'HTML' Memory System Dashboard

🌌 Memory System Dashboard 🌌

-
Total Entries
15
Active Tools
5
AI Agents
10
Databases

📊 Timeline

Activity timeline showing all memory events over time

View Timeline →

🎯 Actions

Distribution of actions (deployed, enhanced, failed, etc.)

View Actions →

🕸️ Network Graph

Interactive network showing system architecture

View Network →

🌌 3D Scatter

3D visualization of memory data points

View 3D Scatter →

🏥 Health Dashboard

Real-time system health monitoring

View Health →

🌊 Live Stream

Real-time event stream viewer

View Stream →
HTML echo -e "${GREEN}✓${NC} Master dashboard created: $output" echo -e "${CYAN}💡 Open:${NC} open $output" } # Main execution case "${1:-help}" in init) init ;; timeline) generate_timeline ;; actions) generate_action_chart ;; network) generate_network_graph ;; 3d) generate_3d_scatter ;; all) generate_all ;; dashboard) create_dashboard ;; help|*) echo -e "${PURPLE}╔════════════════════════════════════════════════╗${NC}" echo -e "${PURPLE}║ 📊 Memory Visualization System ║${NC}" echo -e "${PURPLE}╚════════════════════════════════════════════════╝${NC}\n" echo "Generate beautiful charts, graphs, and maps" echo "" echo "Usage: $0 COMMAND" echo "" echo "Setup:" echo " init - Initialize visualizer" echo "" echo "Generate:" echo " timeline - Activity timeline chart" echo " actions - Action distribution pie chart" echo " network - Network graph" echo " 3d - 3D scatter plot" echo " all - Generate everything" echo " dashboard - Create master dashboard" echo "" echo "Examples:" echo " $0 init" echo " $0 all" echo " $0 dashboard" echo " open ~/.blackroad/memory/visualizations/dashboard.html" ;; esac