Skip to content

Commit

Permalink
Merge pull request #57 from questionlp/develop
Browse files Browse the repository at this point in the history
Add new locations and shows reports, migrate from Black to Ruff for linting/formatting
  • Loading branch information
questionlp authored Feb 7, 2025
2 parents 2f99c12 + e8f9fdd commit b2d6b2c
Show file tree
Hide file tree
Showing 81 changed files with 694 additions and 16 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Changes

## 3.1.0

### Application Changes

- Adding new reports
- Locations
- Show Locations: Home vs Away
- Shows
- Lightning Round All Panelists Answering the Same Number of Questions Correct
- Shows with a Guest Host and a Guest Scorekeeper

### Development Changes

- Upgrade pytest from 8.3.3 to 8.3.4
- Upgrade ruff from 0.7.4 to 0.9.4
- Remove black from required development packages as part of migrating entirely to Ruff
- Ran `ruff format` to format Python code files using the Ruff 2025 Style Guide

## 3.0.5

### Component Changes
Expand Down
1 change: 1 addition & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# vim: set noai syntax=python ts=4 sw=4:
"""Core Application for Wait Wait Reports."""

from flask import Flask

from app import config, utility
Expand Down
1 change: 1 addition & 0 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# vim: set noai syntax=python ts=4 sw=4:
# pylint: disable=R1731
"""Configuration Loading and Parsing for Wait Wait Reports."""

import json
from pathlib import Path
from typing import Any
Expand Down
1 change: 0 additions & 1 deletion app/dicts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# vim: set noai syntax=python ts=4 sw=4:
"""Shared Dictionaries for Wait Wait Reports."""


RANK_MAP: dict[str, str] = {
"1": "First",
"1t": "First Tied",
Expand Down
1 change: 1 addition & 0 deletions app/errors/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# vim: set noai syntax=python ts=4 sw=4:
"""Error Handlers Module for Wait Wait Reports."""

from typing import Literal

from flask import render_template
Expand Down
1 change: 1 addition & 0 deletions app/guests/redirects.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# vim: set noai syntax=python ts=4 sw=4:
"""Guests Redirect Routes for Wait Wait Reports."""

from flask import Blueprint, Response, url_for

from app.utility import redirect_url
Expand Down
1 change: 1 addition & 0 deletions app/guests/reports/best_of_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# vim: set noai syntax=python ts=4 sw=4:
"""WWDTM Guest Best Of Only Appearances Report Functions."""

from mysql.connector.connection import MySQLConnection
from mysql.connector.pooling import PooledMySQLConnection

Expand Down
1 change: 1 addition & 0 deletions app/guests/reports/most_appearances.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# vim: set noai syntax=python ts=4 sw=4:
"""WWDTM Guest Most Appearances Report Functions."""

from mysql.connector.connection import MySQLConnection
from mysql.connector.pooling import PooledMySQLConnection

Expand Down
1 change: 1 addition & 0 deletions app/guests/reports/scores.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# vim: set noai syntax=python ts=4 sw=4:
"""WWDTM Guest Scores Report Functions."""

from typing import Any

from mysql.connector.connection import MySQLConnection
Expand Down
1 change: 1 addition & 0 deletions app/guests/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# vim: set noai syntax=python ts=4 sw=4:
"""Guests Routes for Wait Wait Reports."""

import mysql.connector
from flask import Blueprint, current_app, render_template

Expand Down
1 change: 1 addition & 0 deletions app/hosts/redirects.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# vim: set noai syntax=python ts=4 sw=4:
"""Hosts Redirect Routes for Wait Wait Reports."""

from flask import Blueprint, Response, url_for

from app.utility import redirect_url
Expand Down
1 change: 1 addition & 0 deletions app/hosts/reports/appearances.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# vim: set noai syntax=python ts=4 sw=4:
"""WWDTM Hosts Appearances Report Functions."""

from typing import Any

from mysql.connector.connection import MySQLConnection
Expand Down
1 change: 1 addition & 0 deletions app/hosts/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# vim: set noai syntax=python ts=4 sw=4:
"""Hosts Routes for Wait Wait Reports."""

import mysql.connector
from flask import Blueprint, current_app, render_template

Expand Down
1 change: 1 addition & 0 deletions app/locations/redirects.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# vim: set noai syntax=python ts=4 sw=4:
"""Locations Redirect Routes for Wait Wait Reports."""

from flask import Blueprint, Response, url_for

from app.utility import redirect_url
Expand Down
1 change: 1 addition & 0 deletions app/locations/reports/average_scores.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# vim: set noai syntax=python ts=4 sw=4:
"""WWDTM Location Score Breakdown Report Functions."""

from decimal import Decimal
from typing import Any

Expand Down
74 changes: 74 additions & 0 deletions app/locations/reports/home_vs_away.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Copyright (c) 2018-2025 Linh Pham
# reports.wwdt.me is released under the terms of the Apache License 2.0
# SPDX-License-Identifier: Apache-2.0
#
# vim: set noai syntax=python ts=4 sw=4:
"""WWDTM Location Home vs Away Report Functions."""

from mysql.connector.connection import MySQLConnection
from mysql.connector.pooling import PooledMySQLConnection


def retrieve_location_home_vs_away(
database_connection: MySQLConnection | PooledMySQLConnection,
) -> list[dict[str, int]] | None:
"""Retrieve counts of home versus away shows broken down by year."""
if not database_connection.is_connected():
database_connection.reconnect()

query = """
SELECT DISTINCT YEAR(showdate) FROM ww_shows
ORDER BY YEAR(showdate) ASC;
"""
cursor = database_connection.cursor(dictionary=False)
cursor.execute(query)
results = cursor.fetchall()

if not results:
return None

years = [year[0] for year in results]

counts = []
for year in years:
query = """
SELECT (
SELECT COUNT(s.showid)
FROM ww_shows s
JOIN ww_showlocationmap lm ON lm.showid = s.showid
JOIN ww_locations l ON l.locationid = lm.locationid
WHERE YEAR(s.showdate) = %s
AND s.bestof = 0
AND s.repeatshowid IS NULL
AND l.city = 'Chicago'
AND l.state = 'IL'
) AS 'home', (
SELECT COUNT(s.showid)
FROM ww_shows s
JOIN ww_showlocationmap lm ON lm.showid = s.showid
JOIN ww_locations l ON l.locationid = lm.locationid
WHERE YEAR(s.showdate) = %s
AND s.bestof = 0
AND s.repeatshowid IS NULL
AND l.city <> 'Chicago'
AND l.state <> 'IL'
) AS 'away';
"""
cursor = database_connection.cursor(dictionary=True)
cursor.execute(
query,
(
year,
year,
),
)
result = cursor.fetchone()

if not result:
counts.append({"year": year, "home": None, "away": None})
else:
counts.append(
{"year": year, "home": result["home"], "away": result["away"]}
)

return counts
12 changes: 12 additions & 0 deletions app/locations/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
#
# vim: set noai syntax=python ts=4 sw=4:
"""Locations Routes for Wait Wait Reports."""

import mysql.connector
from flask import Blueprint, current_app, render_template

from .reports.average_scores import retrieve_average_scores_by_location
from .reports.home_vs_away import retrieve_location_home_vs_away

blueprint = Blueprint("locations", __name__, template_folder="templates")

Expand All @@ -30,3 +32,13 @@ def average_scores_by_location() -> str:
return render_template(
"locations/average-scores-by-location.html", locations=_locations
)


@blueprint.route("/home-vs-away")
def home_vs_away() -> str:
"""View: Show Locations: Home vs Away."""
_database_connection = mysql.connector.connect(**current_app.config["database"])
_show_counts = retrieve_location_home_vs_away(
database_connection=_database_connection
)
return render_template("locations/home-vs-away.html", show_counts=_show_counts)
13 changes: 13 additions & 0 deletions app/locations/templates/locations/_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ <h3 class="title">
Fill-in-the-Blank format.
</p>
</div>
</li>
<li class="list-group-item">
<h3 class="title">
<a href="{{ url_for('locations.home_vs_away') }}">Home vs Away</a>
</h3>
<div class="description">
<p>
This report provides a count of shows recorded at home (any venue
or studio located in Chicago, Illinois) and away, broken down by
year.
</p>
</div>
</li>
</ul>
</div>
</div>
Expand Down
64 changes: 64 additions & 0 deletions app/locations/templates/locations/home-vs-away.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{% extends "base.html" %}
{% set page_title = "Show Locations: Home vs Away" %}
{% block title %}{{ page_title }} | Locations{% endblock %}

{% block content %}
<nav aria-label="breadcrumb" id="nav-breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{ url_for('locations.index') }}">Locations</a></li>
<li class="breadcrumb-item active" aria-current="page">{{ page_title }}</li>
</ol>
</nav>

<div id="intro" class="mb-5">
<h2>{{ page_title }}</h2>
<p>
This report provides a count of shows recorded at home (any venue or studio
located in Chicago, Illinois) and away, broken down by year.
</p>
</div>

{% if show_counts %}
<div class="row">
<div class="col-auto">
<div class="table-responsive">
<table class="table table-bordered table-hover report">
<colgroup>
<col class="date year">
<col class="count">
<col class="count">
</colgroup>
<thead>
<tr>
<th scope="col">Year</th>
<th scope="col">Home</th>
<th scope="col">Away</th>
</tr>
</thead>
<tbody>
{% for count in show_counts %}
<tr>
<td>{{ count["year"] }}</td>
<td>{{ count["home"] }}</td>
<td>{{ count["away"] }}</td>
</tr>
{% endfor %}
</tbody>
<tfoot>
<tr>
<th scope="col">Year</th>
<th scope="col">Home</th>
<th scope="col">Away</th>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
{% else %}
<div class="alert alert-info my-5" role="alert">
<i class="bi bi-info-circle pe-1"></i> Data for <b>{{ page_title }}</b> is currently unavailable.
</div>
{% endif %}

{% endblock content %}
1 change: 1 addition & 0 deletions app/main/redirects.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# vim: set noai syntax=python ts=4 sw=4:
"""Main Redirect Routes for Wait Wait Reports."""

from flask import Blueprint, Response, url_for

from app.utility import redirect_url
Expand Down
1 change: 1 addition & 0 deletions app/main/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# vim: set noai syntax=python ts=4 sw=4:
"""Main Routes for Wait Wait Reports."""

from pathlib import Path

from flask import Blueprint, Response, render_template, send_file
Expand Down
1 change: 1 addition & 0 deletions app/panelists/redirects.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# vim: set noai syntax=python ts=4 sw=4:
"""Panelists Redirect Routes for Wait Wait Reports."""

from flask import Blueprint, Response, url_for

from app.utility import redirect_url
Expand Down
1 change: 1 addition & 0 deletions app/panelists/reports/aggregate_scores.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# vim: set noai syntax=python ts=4 sw=4:
"""WWDTM Panelist Aggregate Scores Report Functions."""

from decimal import Decimal
from typing import Any

Expand Down
1 change: 1 addition & 0 deletions app/panelists/reports/appearances.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# vim: set noai syntax=python ts=4 sw=4:
"""WWDTM Panelist Appearances Report Functions."""

from typing import Any

from mysql.connector.connection import MySQLConnection
Expand Down
1 change: 1 addition & 0 deletions app/panelists/reports/appearances_by_year.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# vim: set noai syntax=python ts=4 sw=4:
"""WWDTM Panelist Appearances by Year Report Functions."""

from typing import Any

from mysql.connector.connection import MySQLConnection
Expand Down
1 change: 1 addition & 0 deletions app/panelists/reports/average_scores_by_year.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# vim: set noai syntax=python ts=4 sw=4:
"""WWDTM Panelists Average Scores Report Functions."""

from decimal import Decimal

from flask import current_app
Expand Down
1 change: 1 addition & 0 deletions app/panelists/reports/bluff_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# vim: set noai syntax=python ts=4 sw=4:
"""WWDTM Panelist Bluff the Listener Statistics Report Functions."""

from typing import Any

from mysql.connector.connection import MySQLConnection
Expand Down
1 change: 1 addition & 0 deletions app/panelists/reports/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# vim: set noai syntax=python ts=4 sw=4:
"""WWDTM Common Panelist Report Functions."""

from typing import Any

from mysql.connector.connection import MySQLConnection
Expand Down
Loading

0 comments on commit b2d6b2c

Please sign in to comment.