From d402a135ae6d5a58868ee85e58efaf23326734f8 Mon Sep 17 00:00:00 2001 From: "IGNY8 VPS (Salman)" Date: Tue, 23 Dec 2025 07:32:49 +0000 Subject: [PATCH] Add Chart.js visualization templates for token reports - Copy token_usage.html from remote commit e041cb8e - Copy ai_cost_analysis.html from remote commit e041cb8e - Provides interactive visualizations for token analytics - Charts show: usage trends, cost breakdowns, model comparisons - Completes Phase D token analytics implementation --- .../admin/reports/ai_cost_analysis.html | 349 ++++++++++++++++++ .../templates/admin/reports/token_usage.html | 218 +++++++++++ 2 files changed, 567 insertions(+) create mode 100644 backend/igny8_core/templates/admin/reports/ai_cost_analysis.html create mode 100644 backend/igny8_core/templates/admin/reports/token_usage.html diff --git a/backend/igny8_core/templates/admin/reports/ai_cost_analysis.html b/backend/igny8_core/templates/admin/reports/ai_cost_analysis.html new file mode 100644 index 00000000..62980e45 --- /dev/null +++ b/backend/igny8_core/templates/admin/reports/ai_cost_analysis.html @@ -0,0 +1,349 @@ +{% extends "admin/base_site.html" %} +{% load static %} + +{% block content %} +
+ +
+
+

AI Cost Analysis

+

Comprehensive cost breakdown with model pricing and predictions

+
+
+
+ + +
+
+
+ + +
+
+

Total Cost

+

${{ total_cost|floatformat:2 }}

+

{{ total_calls }} API calls

+
+
+

Avg Cost/Call

+

${{ avg_cost_per_call|floatformat:4 }}

+
+
+

Projected Monthly

+

${{ projected_monthly|floatformat:2 }}

+

Based on last 7 days

+
+
+

Efficiency Score

+

{{ efficiency_score }}%

+

Successful cost ratio

+
+
+

Wasted Cost

+

${{ failed_cost|floatformat:2 }}

+

{{ wasted_percentage|floatformat:1 }}% of total

+
+
+ + +
+

Daily Cost & Volume Trends

+ +
+ + +
+

Model Cost Comparison & Efficiency

+
+ + + + + + + + + + + + + + {% for model in cost_by_model %} + + + + + + + + + + {% endfor %} + +
ModelTotal Cost% of TotalAPI CallsAvg CostTotal TokensCost/1K Tokens
+ + {{ model.model|default:"Unknown" }} + + + ${{ model.total_cost|floatformat:2 }} + + {{ model.cost_percentage|floatformat:1 }}% +
+
+
+
+ {{ model.call_count }} + + ${{ model.avg_cost|floatformat:4 }} + + {{ model.total_tokens|floatformat:0 }} + + ${{ model.cost_per_1k_tokens|floatformat:4 }} +
+
+
+ + +
+ +
+

Top Spenders (By Account)

+
+ + + + + + + + + + {% for account in cost_by_account %} + + + + + + {% endfor %} + +
AccountCostCalls
+ + {{ account.account__name|default:"Unknown" }} + + + ${{ account.total_cost|floatformat:2 }} + + {{ account.call_count }} +
+
+
+ + +
+

Cost by Function/Operation

+
+ + + + + + + + + + {% for func in cost_by_function %} + + + + + + {% endfor %} + +
FunctionCostCalls
+ {{ func.function|default:"Unknown" }} + + ${{ func.total_cost|floatformat:2 }} + + {{ func.call_count }} +
+
+
+
+ + + {% if anomalies %} +
+
+
+ + + +
+
+

Cost Anomalies Detected

+

The following API calls had unusually high costs (>3x average):

+
+ + + + + + + + + + + + + {% for anomaly in anomalies %} + + + + + + + + + {% endfor %} + +
ModelFunctionAccountCostTokensDate
{{ anomaly.model }}{{ anomaly.function }}{{ anomaly.account__name }}${{ anomaly.cost|floatformat:2 }}{{ anomaly.tokens|floatformat:0 }}{{ anomaly.created_at|date:"M d, H:i" }}
+
+
+
+
+ {% endif %} + + +
+

Peak Cost Hours

+
+ + + + + + + + + + + {% for hour in hourly_cost %} + + + + + + + {% endfor %} + +
Hour of DayTotal CostAPI CallsActivity Level
+ {{ hour.hour|floatformat:0 }}:00 - {{ hour.hour|add:1|floatformat:0 }}:00 + + ${{ hour.total_cost|floatformat:2 }} + + {{ hour.call_count }} + +
+ {% widthratio hour.total_cost total_cost 100 as percentage %} +
+
+
+
+
+
+ + + +{% endblock %} diff --git a/backend/igny8_core/templates/admin/reports/token_usage.html b/backend/igny8_core/templates/admin/reports/token_usage.html new file mode 100644 index 00000000..692952fc --- /dev/null +++ b/backend/igny8_core/templates/admin/reports/token_usage.html @@ -0,0 +1,218 @@ +{% extends "admin/base_site.html" %} +{% load static %} + +{% block content %} +
+ +
+
+

Token Usage Report

+

Multi-dimensional token consumption analytics

+
+
+
+ + +
+
+
+ + +
+
+

Total Tokens

+

{{ total_tokens|floatformat:0 }}

+

{{ total_calls }} API calls

+
+
+

Avg Tokens/Call

+

{{ avg_tokens_per_call|floatformat:0 }}

+
+
+

Success Rate

+

{{ success_rate }}%

+

{{ successful_tokens|floatformat:0 }} tokens

+
+
+

Total Cost

+

${{ total_cost|floatformat:2 }}

+

${{ cost_per_1k_tokens|floatformat:4 }} per 1K

+
+
+ + +
+

Token Usage Trends

+ +
+ + +
+ +
+

Token Usage by Model

+
+ + + + + + + + + + + {% for item in token_by_model %} + + + + + + + {% endfor %} + +
ModelTokensCallsCost
{{ item.model|default:"Unknown" }}{{ item.total_tokens|floatformat:0 }}{{ item.call_count }}${{ item.total_cost|floatformat:2 }}
+
+
+ + +
+

Token Usage by Function

+
+ + + + + + + + + + {% for item in token_by_function %} + + + + + + {% endfor %} + +
FunctionTokensCalls
{{ item.function|default:"Unknown" }}{{ item.total_tokens|floatformat:0 }}{{ item.call_count }}
+
+
+
+ + +
+

Top Token Consumers (By Account)

+
+ + + + + + + + + + + + {% for consumer in token_by_account %} + + + + + + + + {% endfor %} + +
AccountTotal TokensAPI CallsTotal CostAvg Tokens
+ + {{ consumer.account__name|default:"Unknown Account" }} + + {{ consumer.total_tokens|floatformat:0 }}{{ consumer.call_count }}${{ consumer.total_cost|floatformat:2 }} + {% widthratio consumer.total_tokens consumer.call_count 1 %} +
+
+
+ + +
+

Efficiency Metrics

+
+
+

Successful Tokens

+

{{ successful_tokens|floatformat:0 }}

+
+
+
+
+
+

Wasted Tokens

+

{{ wasted_tokens|floatformat:0 }}

+

From failed requests

+
+
+

Hourly Peak Usage

+

+ {% for hour in hourly_usage %} + {% if forloop.first or hour.token_count > hourly_usage.0.token_count %} + {{ hour.hour|floatformat:0 }}:00 + {% endif %} + {% endfor %} +

+

Most active hour

+
+
+
+
+ + + +{% endblock %}