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)
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"])
def main_page():
return render_template("base.html")