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 %} + +

Dashboard Overview

- -
-

Timer Functions

-
- -
-
-
- - - -
-
-

Total Timer Functions

-

{{ stats.total_timer_functions }}

-
+ +
+ +
+
+

Total Functions

+
+ + + +
- - -
-
-
- - - -
-
-

Active Timer Functions

-

{{ stats.active_timer_functions }}

-
-
-
- - -
-
-
- - - -
-
-

Timer Invocations

-

{{ stats.timer_invocations }}

-
-
-
- - -
-
-
- - - -
-
-

Success Rate

-
-

{{ stats.timer_success_rate }}%

-

({{ stats.timer_successful_invocations }}/{{ - stats.timer_invocations }})

-
-
-
-
- - -
-
-
- - - -
-
-

Failed Invocations

-

{{ stats.timer_failed_invocations }}

-
-
-
- - -
-
-
- - - -
-
-

Avg. Execution Time

-

- {{ "%.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) +

-
- -
-

HTTP Functions

-
- -
-
-
- - - -
-
-

Total HTTP Functions

-

{{ stats.total_http_functions }}

-
+ +
+
+

Total Invocations

+
+ + +
+
+

{{ stats.timer_invocations + stats.http_invocations }}

+

All time

+
+
- -
-
-
- - - -
-
-

Public HTTP Functions

-

{{ stats.public_http_functions }}

-
+ +
+
+

Overall Success Rate

+
+ + +
+ {% set total_invocations = stats.timer_invocations + stats.http_invocations %} + {% set total_success = stats.timer_successful_invocations + stats.http_successful_invocations %} + {% set success_rate = (total_success / total_invocations * 100)|round(1) if total_invocations > 0 else 0 %} +
+

{{ success_rate }}%

+

+ {{ total_success }}/{{ total_invocations }} +

+
+
- -
-
-
- - - -
-
-

HTTP Invocations

-

{{ stats.http_invocations }}

-
+ +
+
+

Avg Execution Time

+
+ + +
- - -
-
-
- - - -
-
-

Success Rate

-
-

{{ stats.http_success_rate }}%

-

({{ stats.http_successful_invocations }}/{{ - stats.http_invocations }})

-
-
-
-
- - -
-
-
- - - -
-
-

Failed Invocations

-

{{ stats.http_failed_invocations }}

-
-
-
- - -
-
-
- - - -
-
-

Avg. Execution Time

-

- {{ "%.2f"|format(stats.avg_http_execution_time|default(0)) }}s -

-
-
+ {% set avg_time = ((stats.avg_timer_execution_time or 0) + (stats.avg_http_execution_time or 0)) / 2 %} +
+

{{ "%.2f"|format(avg_time) }}s

-
- -
-

24-Hour Invocation Distribution

-
- - - - - - - {% set max_count = namespace(value=1) %} - {% for hour in hour_distribution %} - {% if hour.count > max_count.value %} - {% set max_count.value = hour.count %} - {% endif %} - {% endfor %} - - - {% for hour in hour_distribution %} - {% set x = 40 + (hour.hour * 14) %} - {% set height = (hour.count / max_count.value) * 160 %} - {% set y = 180 - height %} - - {{ hour.hour }}:00 - {{ hour.count }} invocations - - {% endfor %} - - - {% for h in [0, 6, 12, 18, 23] %} - {{ h - }}h - {% endfor %} - +
+ +
+

24-Hour Activity

+
+
- -
-

7-Day Success Rate Trend

-
- - - - - - - - {% set path = namespace(d='M') %} - {% for day in success_trend %} - {% set x = 380 - (loop.index0 * 48) %} - {% set y = 180 - (day.success_rate * 1.6) %} - {% if loop.first %} - {% set path.d = path.d ~ x ~ "," ~ y %} - {% else %} - {% set path.d = path.d ~ " L" ~ x ~ "," ~ y %} - {% endif %} - {% endfor %} - - - - - {% for day in success_trend %} - {% set x = 380 - (loop.index0 * 48) %} - {% set y = 180 - (day.success_rate * 1.6) %} - - {{ day.day_name }}: {{ day.success_rate }}% success rate - - - - {{ day.day_name - }} - {% endfor %} - - - {% for percent in [0, 25, 50, 75, 100] %} - {{ - percent }}% - {% endfor %} - + +
+

Top Functions

+
+ {% for func in top_functions %} +
+
+
+
+ {{ func.name }} +
+ {{ func.invocation_count }} calls +
+ {% else %} +

No functions found.

+ {% endfor %} +
+
+

Success Trend (7 Days)

+
+ +
- -
-
-
-

Last Activity

-
- {% if stats.last_timer_invocation %} -

- 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 %} -
-
-
- - View Timer Functions - + +
+
+

Recent Activity

+
- View HTTP Functions - + class="text-sm text-indigo-600 hover:text-indigo-800 font-medium">View HTTP + | + View Timers
+
+ + + + + + + + + + + + {% for activity in recent_activity %} + + + + + + + + {% else %} + + + + {% endfor %} + +
+ FunctionType + + Status + DurationTime +
{{ 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. +
+
+ + {% endblock %} \ No newline at end of file