""" Plugin Analytics CLI Commands for AITBC Commands for plugin analytics and usage tracking """ import click import json import requests from datetime import datetime from typing import Dict, Any, List, Optional @click.group() def plugin_analytics(): """Plugin analytics management commands""" pass @plugin_analytics.command() @click.option('--plugin-id', help='Specific plugin ID') @click.option('--days', type=int, default=30, help='Number of days to analyze') @click.option('--test-mode', is_flag=True, help='Run in test mode') def dashboard(plugin_id, days, test_mode): """View plugin analytics dashboard""" try: if test_mode: click.echo("📊 Plugin Analytics Dashboard (test mode)") click.echo("📈 Total Plugins: 156") click.echo("📥 Total Downloads: 45,678") click.echo("⭐ Average Rating: 4.2/5.0") click.echo("📅 Period: Last 30 days") return # Get analytics from service config = get_config() params = {"days": days} if plugin_id: params["plugin_id"] = plugin_id response = requests.get( f"{config.coordinator_url}/api/v1/analytics/dashboard", params=params, headers={"Authorization": f"Bearer {config.api_key}"}, timeout=30 ) if response.status_code == 200: dashboard = response.json() click.echo("📊 Plugin Analytics Dashboard") click.echo(f"📈 Total Plugins: {dashboard.get('total_plugins', 0)}") click.echo(f"📥 Total Downloads: {dashboard.get('total_downloads', 0)}") click.echo(f"⭐ Average Rating: {dashboard.get('avg_rating', 0)}/5.0") click.echo(f"📅 Period: Last {days} days") else: click.echo(f"❌ Failed to get dashboard: {response.text}", err=True) except Exception as e: click.echo(f"❌ Error getting dashboard: {str(e)}", err=True) # Helper function to get config def get_config(): """Get CLI configuration""" try: from .config import get_config return get_config() except ImportError: # Fallback for testing from types import SimpleNamespace return SimpleNamespace( coordinator_url="http://localhost:8016", api_key="test-api-key" ) if __name__ == "__main__": plugin_analytics()