Files
aitbc/cli/aitbc_cli/commands/plugin_analytics.py
AITBC System b033923756 chore: normalize file permissions across repository
- Remove executable permissions from configuration files (.editorconfig, .env.example, .gitignore)
- Remove executable permissions from documentation files (README.md, LICENSE, SECURITY.md)
- Remove executable permissions from web assets (HTML, CSS, JS files)
- Remove executable permissions from data files (JSON, SQL, YAML, requirements.txt)
- Remove executable permissions from source code files across all apps
- Add executable permissions to Python
2026-03-08 11:26:18 +01:00

74 lines
2.4 KiB
Python
Executable File

"""
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()