Skip to content

Commit

Permalink
Merge pull request #64 from boris/more-stats
Browse files Browse the repository at this point in the history
More stats
  • Loading branch information
boris authored Jan 20, 2024
2 parents 4740ecb + 98d0a63 commit 4fb4c8e
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 30 deletions.
10 changes: 10 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,15 @@ def profile():
.limit(5)
authors_with_most_books = [(row[0], row[1], row[2]) for row in authors_with_most_books_query.all()]

editorials_with_most_books_subquery = db.session.query(Book.id_editorial).filter(Book.id_user == current_user.id).subquery()
editorials_with_most_books_query = db.session.query(func.count(Book.id), Book.id_editorial, Editorial.name)\
.filter(Editorial.id.in_(editorials_with_most_books_subquery))\
.join(Editorial, Book.id_editorial == Editorial.id)\
.group_by(Book.id_editorial)\
.order_by(desc(func.count(Book.id)))\
.limit(5)
editorials_with_most_books = [(row[0], row[1], row[2]) for row in editorials_with_most_books_query.all()]

books_by_country_subquery = db.session.query(Book.id_author).filter(Book.id_user == current_user.id).subquery()
books_by_country_query = db.session.query(Author.country, func.count()).\
filter(Author.id.in_(books_by_country_subquery)).\
Expand All @@ -254,6 +263,7 @@ def profile():
books_unread = books_unread,
books_shared = books_shared,
authors_with_most_books = authors_with_most_books,
editorials_with_most_books = editorials_with_most_books,
books_by_country = books_by_country,
)

Expand Down
90 changes: 60 additions & 30 deletions app/templates/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,38 +41,68 @@ <h2>Estadísticas.</h2>
<br>

<h2>Análisis de Datos.</h2>
<div class="container">
<div class="row">
<div class="col-sm">

<h3>Cantidad de libros por país de autor</h3>
<table class="table is-halfwidth is-stripped">
<tbody>
<tr class="has-background-success-light">
<th>País</th>
<th>Cantidad</th>
</tr>
{% for country, count in books_by_country|sort(attribute='count_1') %}
<tr>
<td><a href="{{ url_for('main.show_country', author_country = country) }}">{{ country }}</a></td>
<td>{{ count }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<h3>Cantidad de libros por país de autor</h3>
<table class="table is-halfwidth is-stripped">
<tbody>
<tr class="has-background-success-light">
<th>País</th>
<th>Cantidad</th>
</tr>
{% for country, count in books_by_country|sort(attribute='count_1') %}
<tr>
<td><a href="{{ url_for('main.show_country', author_country = country) }}">{{ country }}</a></td>
<td>{{ count }}</td>
</tr>
{% endfor %}
</tbody>
</table>

<h3>Autores con más libros</h3>
<table class="table is-halfwidth is-stripped">
<tbody>
<tr class="has-background-success-light">
<th>Autor</th>
<th>Cantidad</th>
</tr>
{% for count, author_id, author in authors_with_most_books|sort(attribute='count_1') %}
<tr>
<td><a href="{{ url_for('main.show_author', author_id = author_id) }}">{{ author }}</a></td>
<td>{{ count }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>


<div class="row">
<div class="col-sm">
<h3>Autores con más libros</h3>
<table class="table is-halfwidth is-stripped">
<tbody>
<tr class="has-background-success-light">
<th>Autor</th>
<th>Cantidad</th>
</tr>
{% for count, author_id, author in authors_with_most_books|sort(attribute='count_1') %}
<tr>
<td><a href="{{ url_for('main.show_author', author_id = author_id) }}">{{ author }}</a></td>
<td>{{ count }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>

<div class="col-sm">
<h3>Editoriales con más libros</h3>
<table class="table is-halfwidth is-stripped">
<tbody>
<tr class="has-background-success-light">
<th>Editorial</th>
<th>Cantidad</th>
</tr>
{% for count, editorial_id, editorial in editorials_with_most_books|sort(attribute='count_1') %}
<tr>
<td><a href="{{ url_for('main.show_editorial', editorial_id = editorial_id) }}">{{ editorial }}</a></td>
<td>{{ count }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>

Expand Down

0 comments on commit 4fb4c8e

Please sign in to comment.