BEFORE: /opt/aitbc/cli/ ├── aitbc_cli/ # Python package (box in a box) │ ├── commands/ │ ├── main.py │ └── ... ├── setup.py AFTER: /opt/aitbc/cli/ # Flat structure ├── commands/ # Direct access ├── main.py # Direct access ├── auth/ ├── config/ ├── core/ ├── models/ ├── utils/ ├── plugins.py └── setup.py CHANGES MADE: - Moved all files from aitbc_cli/ to cli/ root - Fixed all relative imports (from . to absolute imports) - Updated setup.py entry point: aitbc_cli.main → main - Added CLI directory to Python path in entry script - Simplified deployment.py to remove dependency on deleted core.deployment - Fixed import paths in all command files - Recreated virtual environment with new structure BENEFITS: - Eliminated 'box in a box' nesting - Simpler directory structure - Direct access to all modules - Cleaner imports - Easier maintenance and development - CLI works with both 'python main.py' and 'aitbc' commands
74 lines
2.4 KiB
Python
Executable File
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()
|