Skip to content

Commit

Permalink
Lint fixes, fix opm query comments and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
obscurerichard committed Feb 4, 2024
1 parent 7d1c8c5 commit 39d98dc
Show file tree
Hide file tree
Showing 17 changed files with 89 additions and 111 deletions.
4 changes: 0 additions & 4 deletions freezing/web/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import os
import os.path

from flask import Flask, session, g

from freezing.model import init_model, meta
Expand All @@ -25,7 +22,6 @@
alt_scoring,
tribes,
)
from freezing.web.utils import auth

# Register our blueprints

Expand Down
3 changes: 1 addition & 2 deletions freezing/web/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from instagram import InstagramAPIError, InstagramClientError

from polyline.codec import PolylineCodec

from sqlalchemy import and_
from geoalchemy import WKTSpatialElement
Expand All @@ -30,7 +29,7 @@
Team,
)

from freezing.web import app, config
from freezing.web import config
from freezing.web.autolog import log
from freezing.web.exc import (
InvalidAuthorizationToken,
Expand Down
5 changes: 1 addition & 4 deletions freezing/web/utils/dates.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import pytz

from datetime import datetime
from dateutil import parser as date_parser

from freezing.web import app, config
from freezing.web import config


def parse_competition_timestamp(ts):
Expand Down
2 changes: 0 additions & 2 deletions freezing/web/utils/genericboard.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import decimal
import os
import enum
from datetime import datetime
from typing import List, Dict, Any, Tuple

import yaml

from marshmallow import fields
from marshmallow_enum import EnumField

from freezing.model import meta
from freezing.model.msg import BaseSchema, BaseMessage
Expand Down
2 changes: 0 additions & 2 deletions freezing/web/utils/gviz_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
class DataTableException(Exception):
"""The general exception object thrown by DataTable."""

pass


class DataTableJSONEncoder(json.JSONEncoder):
"""JSON encoder that handles date/time/datetime objects correctly."""
Expand Down
1 change: 0 additions & 1 deletion freezing/web/utils/hashboard.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import decimal
import os
from typing import List

Expand Down
2 changes: 1 addition & 1 deletion freezing/web/utils/insta.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import shutil

from instagram.client import InstagramAPI
from freezing.web import app, exc
from freezing.web import exc
from freezing.web.config import config

THUMBNAIL_DIMS = (150, 150)
Expand Down
1 change: 0 additions & 1 deletion freezing/web/utils/wktutils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import re
from decimal import Decimal
from collections import namedtuple

_point_rx = re.compile("^POINT\((.+)\)$")
Expand Down
6 changes: 2 additions & 4 deletions freezing/web/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@
import json

import arrow
import geojson
from flask import Blueprint, jsonify, request
import pytz
from sqlalchemy import text
from stravalib import unithelper as uh

from freezing.model import meta
from freezing.model.orm import RidePhoto, Ride, RideTrack, Athlete

from freezing.web import app, config
from freezing.web import config
from freezing.web.autolog import log
from freezing.web.serialize import RidePhotoSchema
from freezing.web.utils import auth, dates
from freezing.web.utils import auth
from freezing.web.utils.wktutils import parse_linestring

blueprint = Blueprint("api", __name__)
Expand Down
2 changes: 1 addition & 1 deletion freezing/web/views/chartdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from collections import defaultdict
from datetime import datetime, timedelta

from flask import current_app, request, Blueprint, jsonify
from flask import current_app, Blueprint, jsonify

from sqlalchemy import text
from dateutil import rrule
Expand Down
2 changes: 0 additions & 2 deletions freezing/web/views/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
@author: hans
"""

from datetime import timedelta

from flask import (
render_template,
redirect,
Expand Down
2 changes: 1 addition & 1 deletion freezing/web/views/people.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import date, timedelta
from datetime import timedelta
from datetime import datetime

from flask import render_template, Blueprint, abort
Expand Down
7 changes: 2 additions & 5 deletions freezing/web/views/photos.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import math
from datetime import date, timedelta
from datetime import datetime

from flask import render_template, Blueprint, app, send_file, request
from sqlalchemy import text
from flask import render_template, Blueprint, send_file, request

from freezing.model import meta
from freezing.model.orm import Team, Athlete, RidePhoto, Ride
from freezing.model.orm import RidePhoto, Ride

from freezing.web import config
from freezing.web.utils import insta
Expand Down
8 changes: 3 additions & 5 deletions freezing/web/views/pointless.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import os
import operator
from datetime import date, datetime, timezone
from datetime import datetime, timezone
from collections import defaultdict
import re

from flask import render_template, Blueprint, abort, redirect, url_for
from flask import render_template, Blueprint, abort
from sqlalchemy import text
import yaml

from freezing.model import meta
from freezing.web.config import config
Expand Down Expand Up @@ -280,7 +278,7 @@ def ross_hill_loop():
@blueprint.route("/coffeeride")
def coffeeride():
year = datetime.now().year
tdata = _get_hashtag_tdata("coffeeride".format(year), "coffeeride", 2)
tdata = _get_hashtag_tdata("coffeeride{}".format(year), "coffeeride", 2)
return render_template(
"pointless/coffeeride.html", data={"tdata": tdata, "year": year}
)
Expand Down
148 changes: 74 additions & 74 deletions freezing/web/views/shared_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,113 +8,113 @@
def team_sleaze_query():
return text(
"""
select T.id, T.name as team_name, count(*) as num_sleaze_days
from daily_scores D
join lbd_athletes A on A.id = D.athlete_id
join teams T on T.id = A.team_id
where D.distance >= 1 and D.distance < 2
group by T.id, T.name
order by num_sleaze_days desc
;
"""
select T.id, T.name as team_name, count(*) as num_sleaze_days
from daily_scores D
join lbd_athletes A on A.id = D.athlete_id
join teams T on T.id = A.team_id
where D.distance >= 1 and D.distance < 2
group by T.id, T.name
order by num_sleaze_days desc
;
"""
)


def indiv_sleaze_query():
return text(
"""
select D.athlete_id, A.display_name as athlete_name, count(*) as num_sleaze_days
from daily_scores D
join lbd_athletes A on A.id = D.athlete_id
where D.distance >= 1 and D.distance < 2
group by D.athlete_id, athlete_name
order by num_sleaze_days desc
;
"""
select D.athlete_id, A.display_name as athlete_name, count(*) as num_sleaze_days
from daily_scores D
join lbd_athletes A on A.id = D.athlete_id
where D.distance >= 1 and D.distance < 2
group by D.athlete_id, athlete_name
order by num_sleaze_days desc
;
"""
)


def indiv_freeze_query():
return text(
"""
select athlete_id, athlete_name, SUM(max_daily_freeze_points) as freeze_points_total
from (
select athlete_id, athlete_name, ride_date, MAX(freeze_points) as max_daily_freeze_points
from (
select R.athlete_id, A.display_name as athlete_name, date(R.start_date) as ride_date, (11*(ATAN((R.distance+4)-2*PI())+1.4)-2.66)*(1.2+ATAN((32-W.ride_temp_start)/5)) as freeze_points
from rides R
join ride_weather W on W.ride_id = R.id
join lbd_athletes A on A.id = R.athlete_id
) FP
group by athlete_id, athlete_name, ride_date
) FPMax
group by athlete_id, athlete_name
order by freeze_points_total desc
;
"""
select athlete_id, athlete_name, SUM(max_daily_freeze_points) as freeze_points_total
from (
select athlete_id, athlete_name, ride_date, MAX(freeze_points) as max_daily_freeze_points
from (
select R.athlete_id, A.display_name as athlete_name, date(R.start_date) as ride_date, (11*(ATAN((R.distance+4)-2*PI())+1.4)-2.66)*(1.2+ATAN((32-W.ride_temp_start)/5)) as freeze_points
from rides R
join ride_weather W on W.ride_id = R.id
join lbd_athletes A on A.id = R.athlete_id
) FP
group by athlete_id, athlete_name, ride_date
) FPMax
group by athlete_id, athlete_name
order by freeze_points_total desc
;
"""
)


def indiv_segment_query(join_miles=False):
if join_miles:
return text(
"""
select aa.id, aa.athlete_name, aa.segment_rides, bb.dist from (select A.id, A.display_name as athlete_name, count(E.id) as segment_rides
from lbd_athletes A
join rides R on R.athlete_id = A.id
join ride_efforts E on E.ride_id = R.id
where E.segment_id = :segment_id
group by A.id, A.display_name) aa
join
(select athlete_id, sum(distance) as dist from rides R group by athlete_id) bb
on aa.id = bb.athlete_id
order by aa.segment_rides desc;
"""
select aa.id, aa.athlete_name, aa.segment_rides, bb.dist from (select A.id, A.display_name as athlete_name, count(E.id) as segment_rides
from lbd_athletes A
join rides R on R.athlete_id = A.id
join ride_efforts E on E.ride_id = R.id
where E.segment_id = :segment_id
group by A.id, A.display_name) aa
join
(select athlete_id, sum(distance) as dist from rides R group by athlete_id) bb
on aa.id = bb.athlete_id
order by aa.segment_rides desc;
"""
)
else:
return text(
"""
select A.id, A.display_name as athlete_name, count(E.id) as segment_rides
from lbd_athletes A
join rides R on R.athlete_id = A.id
join ride_efforts E on E.ride_id = R.id
where E.segment_id = :segment_id
group by A.id, A.display_name
order by segment_rides desc
;
"""
select A.id, A.display_name as athlete_name, count(E.id) as segment_rides
from lbd_athletes A
join rides R on R.athlete_id = A.id
join ride_efforts E on E.ride_id = R.id
where E.segment_id = :segment_id
group by A.id, A.display_name
order by segment_rides desc
;
"""
)


def team_segment_query():
return text(
"""
select T.id, T.name as team_name, count(E.id) as segment_rides
from rides R
join lbd_athletes A on A.id = R.athlete_id
join teams T on T.id = A.team_id
join ride_efforts E on E.ride_id = R.id
where E.segment_id = :segment_id and T.leaderboard_exclude=0
group by T.id, T.name
order by segment_rides desc
;
"""
select T.id, T.name as team_name, count(E.id) as segment_rides
from rides R
join lbd_athletes A on A.id = R.athlete_id
join teams T on T.id = A.team_id
join ride_efforts E on E.ride_id = R.id
where E.segment_id = :segment_id and T.leaderboard_exclude=0
group by T.id, T.name
order by segment_rides desc
;
"""
)


def team_leaderboard_query():
return text(
"""
select
T.id as team_id,
T.name as team_name,
sum(DS.points) as total_score,
sum(DS.distance) as total_distance
from
daily_scores DS join teams T on T.id = DS.team_id
where not T.leaderboard_exclude
group by T.id, T.name
order by total_score desc
;
"""
select
T.id as team_id,
T.name as team_name,
sum(DS.points) as total_score,
sum(DS.distance) as total_distance
from
daily_scores DS join teams T on T.id = DS.team_id
where not T.leaderboard_exclude
group by T.id, T.name
order by total_score desc
;
"""
)
4 changes: 2 additions & 2 deletions leaderboards/opmdays.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Michigander - You call THAT a snow day?! - Prize
description: |
<p>Riders who have ridden on the most offcial OPM snow days, or if no snow days are declared, on Michigan Day (Monday, January 18th). Ties to be broken by total mileage.</p>
<!-- <p>Current official snow days: None</p> -->
<p>Current official snow days: Jan 16</p>
<p>Current official snow days: Tuesday, January 16th</p>
fields:
- name: athlete_id
visible: false
Expand All @@ -26,7 +26,7 @@ query: |
2024 had an OPM snow day on Jan 16, so disable this for now.
where date(R.start_date) in (makedate(year(now()), 18))
/*
*/
where date(R.start_date) in ('2024-01-16')
group by athlete_id, athlete_name
order by days desc, distance desc;
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ SQLAlchemy==1.3.24
# Thanks https://stackoverflow.com/a/77214086/424301 - Flask did not pin Werkzeug dep
Werkzeug==3.0.1
arrow==0.15.5
autoflake==2.2.1
beautifulsoup4==4.8.2
colorlog==4.1.0
envparse==0.2.0
Expand Down

0 comments on commit 39d98dc

Please sign in to comment.