added stats page

This commit is contained in:
2020-12-14 23:21:19 +11:00
parent 4691e50811
commit 24210d365c
3 changed files with 44 additions and 0 deletions

28
main.py
View File

@@ -399,6 +399,34 @@ def book(id):
book_s = book_schema.dump(book) book_s = book_schema.dump(book)
return render_template("book.html", b=book, books=book_s, book_form=book_form, author_list=author_list, genre_list=genre_list, alert=alert, message=message, n=book_form.notes, poss_series_list=ListOfSeriesWithMissingBooks() ) return render_template("book.html", b=book, books=book_s, book_form=book_form, author_list=author_list, genre_list=genre_list, alert=alert, message=message, n=book_form.notes, poss_series_list=ListOfSeriesWithMissingBooks() )
def GetCount( what, where ):
st="select count(id) as count from book where "
res=db.engine.execute( st + where )
rtn={}
for row in res:
rtn['stat']=what
rtn['value']=row['count']
return rtn
@app.route("/stats", methods=["GET"])
def stats():
stats=[]
stats.append( GetCount( "Num physical Books in DB", "id not in ( select sub_book_id from book_sub_book_link )" ) )
stats.append( GetCount( "Num physical Books owned (aka books on shelf)", "owned=(select id from owned where name = 'Currently Owned') and id not in ( select sub_book_id from book_sub_book_link )" ) )
stats.append( GetCount( "Num physical Books on Wish List", "owned=(select id from owned where name='On Wish List') and id not in ( select sub_book_id from book_sub_book_link )" ) )
stats.append( GetCount( "Num physical Books sold", "owned=(select id from owned where name='Sold') and id not in ( select sub_book_id from book_sub_book_link )" ) )
stats.append( GetCount( "Num all Books in DB", "id>0" ) )
stats.append( GetCount( "Num all Books owned", "owned in (select id from owned where name='Currently Owned')" ) )
stats.append( GetCount( "Num all Books on wish list", "owned in (select id from owned where name='On Wish List')" ) )
stats.append( GetCount( "Num all Books sold", "owned=(select id from owned where name='Sold')" ) )
stats.append( GetCount( "Num all owned Books unrated", "rating in (select id from rating where name in ('N/A', 'Undefined')) and owned = (select id from owned where name='Currently Owned')" ) )
stats.append( GetCount( "Num all Books unrated", "rating in (select id from rating where name in ('N/A', 'Undefined'))" ) )
return render_template("stats.html", stats=stats )
@app.route("/", methods=["GET"]) @app.route("/", methods=["GET"])
def main_page(): def main_page():
return render_template("base.html") return render_template("base.html")

View File

@@ -26,6 +26,7 @@
<div class="dropdown-menu" aria-labelledby="BookMenu"> <div class="dropdown-menu" aria-labelledby="BookMenu">
<a class="dropdown-item" href="{{url_for('books')}}">Create</a> <a class="dropdown-item" href="{{url_for('books')}}">Create</a>
<a class="dropdown-item" href="{{url_for('books')}}">Show All</a> <a class="dropdown-item" href="{{url_for('books')}}">Show All</a>
<a class="dropdown-item" href="{{url_for('stats')}}">Show Stats</a>
</div> </div>
</div class="nav-item dropdown"> </div class="nav-item dropdown">
<div class="nav-item dropdown"> <div class="nav-item dropdown">

15
templates/stats.html Normal file
View File

@@ -0,0 +1,15 @@
{% extends "base.html" %}
{% block main_content %}
<h3>Stats</h3>
<table id="stats_table" class="table table-striped table-sm" data-toolbar="#toolbar" data-search="true">
<thead>
<tr class="thead-light"><th>Statistic</th><th>Value</th></tr>
</thead>
<tbody>
{% for s in stats %}
<tr><td>{{s.stat}}</td><td>{{s.value}}</tr>
{% endfor %}
</tbody>
</table>
{% endblock main_content %}