Improve look of anayltics page (home)
This commit is contained in:
@@ -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)
|
||||
success_trend=success_trend,
|
||||
top_functions=top_functions,
|
||||
recent_activity=recent_activity)
|
||||
Reference in New Issue
Block a user