Added option to add top parameter to view e.g. top 20 or top 50.
This commit is contained in:
@@ -41,14 +41,20 @@ def overall_dashboard():
|
|||||||
view_type = request.args.get("view", "daily")
|
view_type = request.args.get("view", "daily")
|
||||||
is_image_mode = request.args.get("image") == "true"
|
is_image_mode = request.args.get("image") == "true"
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Get the 'top' parameter, default to 10, and ensure it's an integer
|
||||||
|
top_n = int(request.args.get('top', 10))
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
top_n = 10 # Fallback to 10 if the value is invalid
|
||||||
|
|
||||||
if view_type == "weekly":
|
if view_type == "weekly":
|
||||||
tickers, start, end = get_overall_weekly_summary()
|
tickers, start, end = get_overall_weekly_summary(limit=top_n)
|
||||||
date_string = f"{start.strftime('%b %d')} - {end.strftime('%b %d, %Y')}"
|
date_string = f"{start.strftime('%b %d')} - {end.strftime('%b %d, %Y')}"
|
||||||
subtitle = "All Subreddits - Top 10 Weekly"
|
subtitle = f"All Subreddits - Top {top_n} Weekly"
|
||||||
else: # Default to daily
|
else: # Default to daily
|
||||||
tickers = get_overall_daily_summary()
|
tickers = get_overall_daily_summary(limit=top_n)
|
||||||
date_string = datetime.now(timezone.utc).strftime("%Y-%m-%d")
|
date_string = datetime.now(timezone.utc).strftime("%Y-%m-%d")
|
||||||
subtitle = "All Subreddits - Top 10 Daily"
|
subtitle = f"All Subreddits - Top {top_n} Daily"
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"dashboard_view.html",
|
"dashboard_view.html",
|
||||||
@@ -69,16 +75,21 @@ def subreddit_dashboard(name):
|
|||||||
view_type = request.args.get("view", "daily")
|
view_type = request.args.get("view", "daily")
|
||||||
is_image_mode = request.args.get("image") == "true"
|
is_image_mode = request.args.get("image") == "true"
|
||||||
|
|
||||||
|
try:
|
||||||
|
top_n = int(request.args.get('top', 10))
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
top_n = 10
|
||||||
|
|
||||||
if view_type == "weekly":
|
if view_type == "weekly":
|
||||||
today = datetime.now(timezone.utc)
|
today = datetime.now(timezone.utc)
|
||||||
target_date = today - timedelta(days=7)
|
target_date = today - timedelta(days=7)
|
||||||
tickers, start, end = get_weekly_summary_for_subreddit(name, target_date)
|
tickers, start, end = get_weekly_summary_for_subreddit(name, target_date, limit=top_n)
|
||||||
date_string = f"{start.strftime('%b %d')} - {end.strftime('%b %d, %Y')}"
|
date_string = f"{start.strftime('%b %d')} - {end.strftime('%b %d, %Y')}"
|
||||||
subtitle = f"r/{name} - Top 10 Weekly"
|
subtitle = f"r/{name} - Top {top_n} Weekly"
|
||||||
else: # Default to daily
|
else: # Default to daily
|
||||||
tickers = get_daily_summary_for_subreddit(name)
|
tickers = get_daily_summary_for_subreddit(name, limit=top_n)
|
||||||
date_string = datetime.now(timezone.utc).strftime("%Y-%m-%d")
|
date_string = datetime.now(timezone.utc).strftime("%Y-%m-%d")
|
||||||
subtitle = f"r/{name} - Top 10 Daily"
|
subtitle = f"r/{name} - Top {top_n} Daily"
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"dashboard_view.html",
|
"dashboard_view.html",
|
||||||
|
@@ -238,7 +238,7 @@ def get_week_start_end(for_date):
|
|||||||
return start_of_week, end_of_week
|
return start_of_week, end_of_week
|
||||||
|
|
||||||
|
|
||||||
def get_overall_daily_summary():
|
def get_overall_daily_summary(limit=10):
|
||||||
"""Gets the top tickers across all subreddits from the LAST 24 HOURS."""
|
"""Gets the top tickers across all subreddits from the LAST 24 HOURS."""
|
||||||
conn = get_db_connection()
|
conn = get_db_connection()
|
||||||
one_day_ago = datetime.now(timezone.utc) - timedelta(days=1)
|
one_day_ago = datetime.now(timezone.utc) - timedelta(days=1)
|
||||||
@@ -250,14 +250,14 @@ def get_overall_daily_summary():
|
|||||||
FROM mentions m JOIN tickers t ON m.ticker_id = t.id
|
FROM mentions m JOIN tickers t ON m.ticker_id = t.id
|
||||||
WHERE m.mention_timestamp >= ?
|
WHERE m.mention_timestamp >= ?
|
||||||
GROUP BY t.symbol, t.market_cap, t.closing_price
|
GROUP BY t.symbol, t.market_cap, t.closing_price
|
||||||
ORDER BY total_mentions DESC LIMIT 10;
|
ORDER BY total_mentions DESC LIMIT ?;
|
||||||
"""
|
"""
|
||||||
results = conn.execute(query, (one_day_ago_timestamp,)).fetchall()
|
results = conn.execute(query, (one_day_ago_timestamp, limit)).fetchall()
|
||||||
conn.close()
|
conn.close()
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
def get_overall_weekly_summary():
|
def get_overall_weekly_summary(limit=10):
|
||||||
"""Gets the top tickers across all subreddits for LAST WEEK (Mon-Sun)."""
|
"""Gets the top tickers across all subreddits for LAST WEEK (Mon-Sun)."""
|
||||||
conn = get_db_connection()
|
conn = get_db_connection()
|
||||||
today = datetime.now(timezone.utc)
|
today = datetime.now(timezone.utc)
|
||||||
@@ -272,14 +272,14 @@ def get_overall_weekly_summary():
|
|||||||
FROM mentions m JOIN tickers t ON m.ticker_id = t.id
|
FROM mentions m JOIN tickers t ON m.ticker_id = t.id
|
||||||
WHERE m.mention_timestamp BETWEEN ? AND ?
|
WHERE m.mention_timestamp BETWEEN ? AND ?
|
||||||
GROUP BY t.symbol, t.market_cap, t.closing_price
|
GROUP BY t.symbol, t.market_cap, t.closing_price
|
||||||
ORDER BY total_mentions DESC LIMIT 10;
|
ORDER BY total_mentions DESC LIMIT ?;
|
||||||
"""
|
"""
|
||||||
results = conn.execute(query, (start_timestamp, end_timestamp)).fetchall()
|
results = conn.execute(query, (start_timestamp, end_timestamp, limit)).fetchall()
|
||||||
conn.close()
|
conn.close()
|
||||||
return results, start_of_week, end_of_week
|
return results, start_of_week, end_of_week
|
||||||
|
|
||||||
|
|
||||||
def get_daily_summary_for_subreddit(subreddit_name):
|
def get_daily_summary_for_subreddit(subreddit_name, limit=10):
|
||||||
"""Gets a summary for a subreddit's DAILY view (last 24 hours)."""
|
"""Gets a summary for a subreddit's DAILY view (last 24 hours)."""
|
||||||
conn = get_db_connection()
|
conn = get_db_connection()
|
||||||
one_day_ago = datetime.now(timezone.utc) - timedelta(days=1)
|
one_day_ago = datetime.now(timezone.utc) - timedelta(days=1)
|
||||||
@@ -291,14 +291,14 @@ def get_daily_summary_for_subreddit(subreddit_name):
|
|||||||
FROM mentions m JOIN tickers t ON m.ticker_id = t.id JOIN subreddits s ON m.subreddit_id = s.id
|
FROM mentions m JOIN tickers t ON m.ticker_id = t.id JOIN subreddits s ON m.subreddit_id = s.id
|
||||||
WHERE LOWER(s.name) = LOWER(?) AND m.mention_timestamp >= ?
|
WHERE LOWER(s.name) = LOWER(?) AND m.mention_timestamp >= ?
|
||||||
GROUP BY t.symbol, t.market_cap, t.closing_price
|
GROUP BY t.symbol, t.market_cap, t.closing_price
|
||||||
ORDER BY total_mentions DESC LIMIT 10;
|
ORDER BY total_mentions DESC LIMIT ?;
|
||||||
"""
|
"""
|
||||||
results = conn.execute(query, (subreddit_name, one_day_ago_timestamp)).fetchall()
|
results = conn.execute(query, (subreddit_name, one_day_ago_timestamp, limit)).fetchall()
|
||||||
conn.close()
|
conn.close()
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
def get_weekly_summary_for_subreddit(subreddit_name, for_date):
|
def get_weekly_summary_for_subreddit(subreddit_name, for_date, limit=10):
|
||||||
"""Gets a summary for a subreddit's WEEKLY view (for a specific week)."""
|
"""Gets a summary for a subreddit's WEEKLY view (for a specific week)."""
|
||||||
conn = get_db_connection()
|
conn = get_db_connection()
|
||||||
start_of_week, end_of_week = get_week_start_end(for_date)
|
start_of_week, end_of_week = get_week_start_end(for_date)
|
||||||
@@ -311,10 +311,10 @@ def get_weekly_summary_for_subreddit(subreddit_name, for_date):
|
|||||||
FROM mentions m JOIN tickers t ON m.ticker_id = t.id JOIN subreddits s ON m.subreddit_id = s.id
|
FROM mentions m JOIN tickers t ON m.ticker_id = t.id JOIN subreddits s ON m.subreddit_id = s.id
|
||||||
WHERE LOWER(s.name) = LOWER(?) AND m.mention_timestamp BETWEEN ? AND ?
|
WHERE LOWER(s.name) = LOWER(?) AND m.mention_timestamp BETWEEN ? AND ?
|
||||||
GROUP BY t.symbol, t.market_cap, t.closing_price
|
GROUP BY t.symbol, t.market_cap, t.closing_price
|
||||||
ORDER BY total_mentions DESC LIMIT 10;
|
ORDER BY total_mentions DESC LIMIT ?;
|
||||||
"""
|
"""
|
||||||
results = conn.execute(
|
results = conn.execute(
|
||||||
query, (subreddit_name, start_timestamp, end_timestamp)
|
query, (subreddit_name, start_timestamp, end_timestamp, limit)
|
||||||
).fetchall()
|
).fetchall()
|
||||||
conn.close()
|
conn.close()
|
||||||
return results, start_of_week, end_of_week
|
return results, start_of_week, end_of_week
|
||||||
|
Reference in New Issue
Block a user