Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add statistics #45

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions argostime/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,25 @@ def webshop_page(shop_id):
show_variance=show_variance
)

@app.route("/stats")
def statistics_page():

offers: List[ProductOffer] = ProductOffer.query.join(
Product).order_by(Product.name).all()

products: List[Product] = Product.query.all()

total_product: int = len(products)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lijkt me een beetje zonde om alle producten in te laden alleen om te kijken hoe lang de lijst is.

Kunnen we niet dit gebruiken: https://docs.sqlalchemy.org/en/20/orm/queryguide/query.html#sqlalchemy.orm.Query.count

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm dat klinkt wel beter, maar misschien ook eens uitzoeken wat de SQLAlchemy v2.0 manier is om dat te doen

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dat lijkt me de nieuwe versie inderdaad

total_offers: int = len(offers)
total_prices_count: int = len(Price.query.all())

return render_template(
"stats.html.jinja",
total_products=total_product,
total_offers=total_offers,
total_prices_count=total_prices_count
)

@app.route("/add_url", methods=['GET'])
def add_url():
"""GET request to allow users to add a URL using a booklet"""
Expand Down
3 changes: 3 additions & 0 deletions argostime/templates/index.html.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@
<p>Voeg pagina's eenvoudig toe met een <a href="https://en.wikipedia.org/wiki/Bookmarklet">bookmarklet</a>! Maak een bladwijzer in uw browser met de onderstaande regel code als URL:</p>
<code>javascript:void(location.href='http://argostime.mrtijn.nl/add_url?url='+location.href)</code>
<p>Op een productpagina van een van de ondersteunde winkels kunt u de bookmark gebruiken om met een klik het product toe te voegen en bekijken op Argostimè!</p>

<h2>Statistieken</h2>
<p>Statistieken kan je vinden op de <a href="/stats">Statistiekenpagina</a>.</p>
{% endblock %}
11 changes: 11 additions & 0 deletions argostime/templates/stats.html.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends "base.html.jinja" %}
{% block title %}Statistieken | Argostimè{% endblock %}
{% block content %}
<h1>Statistieken</h1>
<ul>
<li>Totaal aantal producten: {{ total_products }}</li>
<li>Totaal aantal aanbiedingen van producten: {{ total_offers }}.</li>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ik denk dat voor veel gebruikers niet heel duidelijk zal zijn wat hier precies staat. Het is denk ik niet heel duidelijk wat het verschil tussen de 1e en de 2e is. Het woord "aanbiedingen" heeft ook een dubbele betekenis.

<li>Totaal aantal prijsdatapunten: {{ total_prices_count }}.</li>
</ul>

{% endblock %}