Files
tianxuan/analysis/views/dashboard.py
T

64 lines
2.1 KiB
Python

"""Dashboard views: home, run list, run detail, run status."""
from django.shortcuts import render, get_object_or_404
from django.http import JsonResponse
from analysis.models import AnalysisRun
def dashboard(request):
"""Home page: recent runs overview."""
runs = AnalysisRun.objects.all()[:20]
return render(request, 'analysis/dashboard.html', {'runs': runs})
def run_list(request):
"""List all analysis runs with pagination and optional ?type= filter."""
run_type_filter = request.GET.get('type')
page = int(request.GET.get('page', 1))
per_page = 20
qs = AnalysisRun.objects.all()
if run_type_filter in dict(AnalysisRun.RUN_TYPE_CHOICES):
qs = qs.filter(run_type=run_type_filter)
total = qs.count()
runs = qs[(page - 1) * per_page: page * per_page]
return render(request, 'analysis/run_list.html', {
'runs': runs,
'page': page,
'total_pages': (total + per_page - 1) // per_page if total else 1,
'current_type': run_type_filter or '',
})
def run_detail(request, display_id):
"""Details for a single analysis run."""
run = get_object_or_404(AnalysisRun, display_id=display_id)
clusters = run.clusters.all().order_by('-size')
return render(request, 'analysis/run_detail.html', {
'run': run,
'clusters': clusters,
})
def run_status_api(request, display_id):
"""Return current run status as JSON."""
run = get_object_or_404(AnalysisRun, display_id=display_id)
return JsonResponse({
'id': run.display_id,
'status': run.status,
'entity_count': run.entity_count,
'cluster_count': run.cluster_count,
'error_message': run.error_message,
'progress_pct': run.progress_pct,
'progress_msg': run.progress_msg,
'run_log': run.run_log[-2000:], # last 2000 chars
'llm_thinking': run.llm_thinking[-50000:] if run.llm_thinking else '',
'tool_calls': run.tool_calls_json,
})
def start_analysis(request):
"""Placeholder: API endpoint to trigger analysis via MCP."""
return JsonResponse({'status': 'not_implemented', 'message': 'Use MCP tools to trigger analysis'})