Skip to content

Commit

Permalink
Order streak by competition as well (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
campos20 authored Sep 30, 2024
1 parent 0085516 commit fa07efd
Showing 1 changed file with 44 additions and 10 deletions.
54 changes: 44 additions & 10 deletions misc/python/statistics/longest_success_streak.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
from misc.python.model.competitor import Competitor as Comp
from misc.python.util.database_util import get_database_connection
from misc.python.util.event_util import get_current_events
from misc.python.util.html_util import (get_competition_html_link,
get_competitor_html_link)
from misc.python.util.html_util import (
get_competition_html_link,
get_competitor_html_link,
)
from misc.python.util.log_util import log
from misc.python.util.statistics_api_util import create_statistics

Expand Down Expand Up @@ -45,7 +47,9 @@ def __init__(self, wca_id, name, country):
eventId = %(event_id)s
order by
start_date,
rt.`rank`"""
competitionId,
rt.`rank`
"""


def longest_streaks():
Expand All @@ -54,10 +58,12 @@ def longest_streaks():

out = {}
out["title"] = title
out["explanation"] = (
"If two competitions start on the same day, the one with the lower competition ID is considered to be the first one."
)
out["groupName"] = "Results"
out["displayMode"] = "SELECTOR"
headers = ["Streak", "Person",
"Country", "Streak Start", "Streak End"]
headers = ["Streak", "Person", "Country", "Streak Start", "Streak End"]
out["statistics"] = []

log.info("Get database connection")
Expand All @@ -72,7 +78,17 @@ def longest_streaks():

cursor.execute(query, {"event_id": event_id})

for wca_id, person_name, country_id, competition_id, v1, v2, v3, v4, v5 in cursor:
for (
wca_id,
person_name,
country_id,
competition_id,
v1,
v2,
v3,
v4,
v5,
) in cursor:

competitor = Competitor(wca_id, person_name, country_id)

Expand Down Expand Up @@ -108,14 +124,32 @@ def longest_streaks():
current = competitor.count

link = get_competitor_html_link(competitor.wca_id, competitor.name)
table.append([streak, link, competitor.country,
get_competition_html_link(competitor.max_range_start), "-" if streak == current else get_competition_html_link(competitor.max_range_end)])
table.append(
[
streak,
link,
competitor.country,
get_competition_html_link(competitor.max_range_start),
(
"-"
if streak == current
else get_competition_html_link(competitor.max_range_end)
),
]
)

count += 1
prev = streak

out["statistics"].append({"keys": [event.name], "content": table,
"headers": headers, "showPositions": True, "positionTieBreakerIndex": 0})
out["statistics"].append(
{
"keys": [event.name],
"content": table,
"headers": headers,
"showPositions": True,
"positionTieBreakerIndex": 0,
}
)
cnx.close()

return out
Expand Down

0 comments on commit fa07efd

Please sign in to comment.