Analytics API Reference
analytics.serializers
Serializers for the analytics application.
Provides data structures for financial reports, budget alerts, dashboard summaries, and categorical spending breakdowns.
BudgetAlertSerializer
Bases: ModelSerializer
Serializer for budget category limit alerts.
Computes visual cues like progress percentage, status color (green/orange/red), and human-readable alert messages.
Source code in analytics/serializers.py
Meta
get_alert_message(obj)
Generate a human-readable notification message for the budget status.
Returns:
| Name | Type | Description |
|---|---|---|
str |
Warning message or None. |
Source code in analytics/serializers.py
get_progress_percentage(obj)
Calculate spending as a percentage of the limit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
BudgetCategoryLimit
|
The limit instance. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
Percentage value rounded to 2 decimal places. |
Source code in analytics/serializers.py
get_status_color(obj)
Determine the visual status color based on consumption.
- 100%+ -> red
- 90%-100% -> orange
- <90% -> green
Returns:
| Name | Type | Description |
|---|---|---|
str |
Color code. |
Source code in analytics/serializers.py
CategorySpendingSerializer
Bases: Serializer
Data structure for category-level spending breakdown.
Used primarily for pie charts and data visualization.
Source code in analytics/serializers.py
DashboardSummarySerializer
Bases: Serializer
Serializer for the main dashboard home page.
Aggregates balance, monthly income/expenses, and lists recent transactions and budget warnings.
Source code in analytics/serializers.py
get_budget_warnings(obj)
Identify budgets that are at or near their limit.
Returns:
| Name | Type | Description |
|---|---|---|
list |
List of warning strings. |
Source code in analytics/serializers.py
get_recent_transactions(obj)
Fetch the 5 most recent transactions for the user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
dict
|
Context object containing 'user'. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
List of serialized transactions. |
Source code in analytics/serializers.py
TransactionReportSerializer
Bases: ModelSerializer
Simplified serializer for transaction data within analytical reports.
Source code in analytics/serializers.py
analytics.views
Views for the analytics application.
Provides endpoints for tracking budget status alerts, generating spending reports with charts, and retrieving dashboard summaries.
BudgetStatusView
Bases: APIView
Retrieves the status of all budget category limits for the current month.
Returns a list of alerts including spending progress and warning messages.
Source code in analytics/views.py
get(request)
Handle GET requests for budget alerts.
Returns:
| Name | Type | Description |
|---|---|---|
Response |
List of budget status alerts. |
Source code in analytics/views.py
DashboardHomeView
Bases: APIView
Provides a consolidated summary for the user's dashboard.
Includes balance, monthly income/expense totals, and recent activity.
Source code in analytics/views.py
get(request)
Handle GET requests for dashboard data.
Returns:
| Name | Type | Description |
|---|---|---|
Response |
Aggregated dashboard summary. |
Source code in analytics/views.py
ReportsAnalyticsView
Bases: APIView
Generates detailed spending analytics for a specific date range.
Provides data suitable for pie charts (category distribution) and bar charts (income vs expense).
Source code in analytics/views.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
get(request)
Return category spending breakdown and income vs expense totals.
Query parameters
start_date (str): Start of the date range (YYYY-MM-DD). Defaults to first of current month. end_date (str): End of the date range (YYYY-MM-DD). Defaults to today.
Returns:
| Name | Type | Description |
|---|---|---|
Response |
Analytics data including pie chart and bar chart aggregates. |