diff --git a/routes/home.py b/routes/home.py index 0cc89e4..41c8d10 100644 --- a/routes/home.py +++ b/routes/home.py @@ -1,5 +1,7 @@ from flask import Blueprint, render_template, request from flask_login import login_required, current_user +from flask import Blueprint, render_template, request +from flask_login import login_required, current_user from extensions import db, htmx, environment from jinja2_fragments import render_block @@ -132,12 +134,74 @@ def index(): LIMIT 7 """, [current_user.id, current_user.id]) + # Top 5 Most Invoked Functions + top_functions = db.execute(""" + WITH all_functions AS ( + SELECT + tf.name, + 'Timer' as type, + COUNT(tfi.id) as invocation_count + FROM timer_functions tf + JOIN timer_function_invocations tfi ON tf.id = tfi.timer_function_id + WHERE tf.user_id = %s + GROUP BY tf.name + + UNION ALL + + SELECT + hf.name, + 'HTTP' as type, + COUNT(hfi.id) as invocation_count + FROM http_functions hf + JOIN http_function_invocations hfi ON hf.id = hfi.http_function_id + WHERE hf.user_id = %s + GROUP BY hf.name + ) + SELECT * FROM all_functions + ORDER BY invocation_count DESC + LIMIT 5 + """, [current_user.id, current_user.id]) + + # Recent Activity (Last 10) + recent_activity = db.execute(""" + WITH all_activity AS ( + SELECT + tf.name, + 'Timer' as type, + tfi.status, + tfi.invocation_time, + tfi.execution_time + FROM timer_function_invocations tfi + JOIN timer_functions tf ON tf.id = tfi.timer_function_id + WHERE tf.user_id = %s + + UNION ALL + + SELECT + hf.name, + 'HTTP' as type, + hfi.status, + hfi.invocation_time, + hfi.execution_time + FROM http_function_invocations hfi + JOIN http_functions hf ON hf.id = hfi.http_function_id + WHERE hf.user_id = %s + ) + SELECT * FROM all_activity + ORDER BY invocation_time DESC + LIMIT 10 + """, [current_user.id, current_user.id]) + if htmx: return render_block(environment, 'dashboard/home.html', 'page', stats=stats, hour_distribution=hour_distribution, - success_trend=success_trend) + success_trend=success_trend, + top_functions=top_functions, + recent_activity=recent_activity) return render_template('dashboard/home.html', stats=stats, hour_distribution=hour_distribution, - success_trend=success_trend) \ No newline at end of file + success_trend=success_trend, + top_functions=top_functions, + recent_activity=recent_activity) \ No newline at end of file diff --git a/templates/dashboard/home.html b/templates/dashboard/home.html index 7a07f2a..90b4c7a 100644 --- a/templates/dashboard/home.html +++ b/templates/dashboard/home.html @@ -1,353 +1,260 @@ {% extends 'dashboard.html' %} {% block page %} + +
{{ stats.total_timer_functions }}
-{{ stats.active_timer_functions }}
-{{ stats.timer_invocations }}
-{{ stats.timer_success_rate }}%
-({{ stats.timer_successful_invocations }}/{{ - stats.timer_invocations }})
-{{ stats.timer_failed_invocations }}
-- {{ "%.2f"|format(stats.avg_timer_execution_time|default(0)) }}s -
-{{ stats.total_timer_functions + stats.total_http_functions + }}
++ ({{ stats.total_http_functions }} HTTP, {{ stats.total_timer_functions }} Timer) +
{{ stats.total_http_functions }}
-{{ stats.timer_invocations + stats.http_invocations }}
+All time
+{{ stats.public_http_functions }}
-{{ success_rate }}%
++ {{ total_success }}/{{ total_invocations }} +
+{{ stats.http_invocations }}
-{{ stats.http_success_rate }}%
-({{ stats.http_successful_invocations }}/{{ - stats.http_invocations }})
-{{ stats.http_failed_invocations }}
-- {{ "%.2f"|format(stats.avg_http_execution_time|default(0)) }}s -
-{{ "%.2f"|format(avg_time) }}s
No functions found.
+ {% endfor %} +- Last Timer Invocation: {{ stats.last_timer_invocation.strftime('%Y-%m-%d %H:%M') }} -
- {% endif %} - {% if stats.last_http_invocation %} -- Last HTTP Invocation: {{ stats.last_http_invocation.strftime('%Y-%m-%d %H:%M') }} -
- {% endif %} -| + Function | +Type + | ++ Status | ++ Duration | +Time + | +
|---|---|---|---|---|
| {{ activity.name }} + | ++ + {{ activity.type }} + + | ++ {% if activity.status == 'SUCCESS' %} + Success + {% else %} + {{ + activity.status }} + {% endif %} + | +{{ + "%.2f"|format(activity.execution_time or 0) }}s | +{{ + activity.invocation_time.strftime('%Y-%m-%d %H:%M:%S') }} | +
| No recent activity found. + | +||||