stats
This commit is contained in:
parent
f3e6c165f4
commit
8010bbd750
4 changed files with 32 additions and 5 deletions
|
@ -6,7 +6,7 @@ import sqlalchemy
|
|||
from alembic import command
|
||||
from alembic.config import Config
|
||||
from dateutil import tz
|
||||
from sqlalchemy import func
|
||||
from sqlalchemy import func, select
|
||||
from sqlalchemy.orm import Session, joinedload
|
||||
from sqlalchemy_utils import database_exists
|
||||
|
||||
|
@ -25,7 +25,7 @@ def run_db_migrations(script_location: str, db_url: str) -> None:
|
|||
alembic_cfg.set_main_option('sqlalchemy.url', db_url)
|
||||
|
||||
if not database_exists(db_url):
|
||||
logger.debug(f"'{db_url}' does not exist. Running normal migration to create db and tables." )
|
||||
logger.debug(f"'{db_url}' does not exist. Running normal migration to create db and tables.")
|
||||
command.upgrade(alembic_cfg, 'head')
|
||||
elif database_exists(db_url):
|
||||
logger.debug(f"'{db_url}' exists.")
|
||||
|
@ -94,7 +94,7 @@ class GiveawayHelper:
|
|||
@classmethod
|
||||
def get(cls):
|
||||
with Session(engine) as session:
|
||||
return session.query(TableGiveaway).options(joinedload('steam_item'))\
|
||||
return session.query(TableGiveaway).options(joinedload('steam_item')) \
|
||||
.order_by(TableGiveaway.giveaway_ended_at.desc()).all()
|
||||
|
||||
@classmethod
|
||||
|
@ -102,9 +102,20 @@ class GiveawayHelper:
|
|||
with Session(engine) as session:
|
||||
paginated_giveaways = paginate_sqlalchemy.SqlalchemyOrmPage(session.query(TableGiveaway)
|
||||
.options(joinedload('steam_item'))
|
||||
.order_by(TableGiveaway.giveaway_ended_at.desc()), page=page)
|
||||
.order_by(
|
||||
TableGiveaway.giveaway_ended_at.desc()), page=page)
|
||||
return paginated_giveaways
|
||||
|
||||
@classmethod
|
||||
def total_giveaways(cls):
|
||||
with Session(engine) as session:
|
||||
return session.execute(select(func.count(TableGiveaway.giveaway_id))).scalar_one()
|
||||
|
||||
@classmethod
|
||||
def total_entered(cls):
|
||||
with Session(engine) as session:
|
||||
return session.query(TableGiveaway).filter_by(entered=True).count()
|
||||
|
||||
@classmethod
|
||||
def unix_timestamp_to_utc_datetime(cls, timestamp):
|
||||
return datetime.utcfromtimestamp(timestamp)
|
||||
|
@ -164,4 +175,4 @@ class GiveawayHelper:
|
|||
entered=entered,
|
||||
game_entries=giveaway.game_entries)
|
||||
session.merge(g)
|
||||
session.commit()
|
||||
session.commit()
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
<strong><nav>
|
||||
<ul class="menu">
|
||||
<li><a href="{{ url_for('config') }}">Config</a></li>
|
||||
<li><a href="{{ url_for('stats') }}">Stats</a></li>
|
||||
<li><a href="{{ url_for('log_info') }}">Info Logs</a></li>
|
||||
<li><a href="{{ url_for('log_debug') }}">Debug Logs</a></li>
|
||||
<li><a href="{{ url_for('db_giveaways') }}">Giveaways</a></li>
|
||||
|
|
9
src/web/templates/stats.html
Normal file
9
src/web/templates/stats.html
Normal file
|
@ -0,0 +1,9 @@
|
|||
{% extends 'base.html' %}
|
||||
|
||||
{% block title %} {{name}} Steamgifts Bot Configuration {% endblock %}
|
||||
{% block content %}
|
||||
<ul>
|
||||
<li>Total Giveaways Considered: {{totals}}</li>
|
||||
<li>Giveaways Entered: {{entered}}</li>
|
||||
</ul>
|
||||
{% endblock %}
|
|
@ -70,6 +70,12 @@ class WebServerThread(threading.Thread):
|
|||
def db_giveaways(page):
|
||||
return render_template('giveaways.html', name=self.prefix, data=GiveawayHelper.paginate(page=page))
|
||||
|
||||
@app.route(f"{self.app_root}stats")
|
||||
def stats():
|
||||
totals = GiveawayHelper.total_giveaways()
|
||||
entered = GiveawayHelper.total_entered()
|
||||
return render_template('stats.html', name=self.prefix, totals=totals, entered=entered)
|
||||
|
||||
if self.enabled:
|
||||
logger.info("Webserver Enabled. Running")
|
||||
if self.ssl:
|
||||
|
|
Loading…
Reference in a new issue