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

Leaderboard for #midnight, #midnight 2-fer #51

Open
FS18Edelweiss opened this issue Feb 19, 2018 · 9 comments
Open

Leaderboard for #midnight, #midnight 2-fer #51

FS18Edelweiss opened this issue Feb 19, 2018 · 9 comments
Labels
enhancement good first issue help wanted Help wanted - can you take this on?

Comments

@FS18Edelweiss
Copy link

For the PaulRevere Midnight Rider Pointless Prize, I would like to see a leaderboard to see how many riders have claimed this distinction using the #midnight and its variations.
Thanks, Kate

@hozn
Copy link
Contributor

hozn commented Feb 19, 2018

Ok, is this just based on the hashtag or are there rules about when the ride happens, etc.? (I.e. if there are specific rules we can just code those into the query and not rely on the hashtag.)

@FS18Edelweiss
Copy link
Author

FS18Edelweiss commented Feb 19, 2018 via email

@hozn
Copy link
Contributor

hozn commented Feb 19, 2018

Ok, just to further clarify, this can be the only ride of the day? Meaning that you can only do one window (23:30-23:59) or the other (00:00-00:29) in a single day?

@FS18Edelweiss
Copy link
Author

FS18Edelweiss commented Feb 19, 2018 via email

@hozn
Copy link
Contributor

hozn commented Feb 19, 2018

Ok, I think this makes sense. So the 2fer is only for people who do two consequtive sleaze rides, one at 11:30-midnight window and the other at midnight-12:30 window.

@FS18Edelweiss
Copy link
Author

FS18Edelweiss commented Feb 19, 2018 via email

@hozn
Copy link
Contributor

hozn commented Feb 20, 2018

Ok, just commenting as a note-to-self. Here's the sql (or one way to do it) to get all rides which are the only rides of the day.

SELECT r.id, r.name, r.athlete_id, r.start_date, date_add(r.start_date, interval r.elapsed_time second) as end_date, date(r.start_date)
FROM rides r
left join rides r2 on r2.id != r.id and date(r2.start_date) = date(r.start_date) and r2.athlete_id = r.athlete_id
where r2.id is null

From this we'll want to select the rides where hours and minutes fall into the designated time windows to know if those rides qualify.

We will use elapsed time to determine when the ride ended. This means leaving the garmin running until 12:01 and then hitting stop will disqualify the ride, even if not moving.

@FS18Edelweiss , the part that may be hard to write a query for in MySQL (or maybe will just be slow) will be the "2-fer" award. Though I might be over-thinking it and it won't be so bad :)

BTW, there is an already-existing solution that uses the hashtags:

https://freezingsaddles.org/pointless/hashtag/midnight

(Just replace "mignight" at the end with whichever hashtag.)

@hozn
Copy link
Contributor

hozn commented Mar 4, 2018

More notes-to-self as I put this together.

Here's a query to get rides beteen 11:30-11:59pm:

select * 
from (SELECT r.id, r.name, r.athlete_id, r.start_date, date_add(r.start_date, interval r.elapsed_time second) as end_date, date(r.start_date)
FROM rides r
left join rides r2 on r2.id != r.id and date(r2.start_date) = date(r.start_date) and r2.athlete_id = r.athlete_id
where r2.id is null) day1_ride
where HOUR(day1_ride.start_date) = 23 AND MINUTE(day1_ride.start_date) >= 30 AND HOUR(day1_ride.end_date) = 23

And here's a stab at the full thing without any group-by/sums:

SELECT
    *
FROM
    (SELECT * FROM (SELECT r.id, r.name, r.athlete_id, r.start_date, DATE_ADD(r.start_date, INTERVAL r.elapsed_time SECOND) AS end_date, DATE(r.start_date) 
                    FROM rides r LEFT JOIN rides r2 ON r2.id != r.id AND DATE(r2.start_date) = DATE(r.start_date) AND r2.athlete_id = r.athlete_id
                    WHERE r2.id IS NULL
    ) day1_ride WHERE HOUR(day1_ride.start_date) = 23 AND MINUTE(day1_ride.start_date) >= 30 AND HOUR(day1_ride.end_date) = 23) day1_midnight, 
    (SELECT * FROM (SELECT r.id, r.name, r.athlete_id, r.start_date, DATE_ADD(r.start_date, INTERVAL r.elapsed_time SECOND) AS end_date, DATE(r.start_date) 
                    FROM rides r LEFT JOIN rides r2 ON r2.id != r.id AND DATE(r2.start_date) = DATE(r.start_date) AND r2.athlete_id = r.athlete_id
                    WHERE r2.id IS NULL
    ) day2_ride WHERE HOUR(day2_ride.start_date) = 0 AND HOUR(day2_ride.end_date) = 0 AND MINUTE(day2_ride.start_date) < 30) day2_midnight
   
WHERE day2_midnight.athlete_id = day1_midnight.athlete_id AND DATE(day2_midnight.start_date) = DATE_ADD(DATE(day1_midnight.start_date), INTERVAL 1 DAY)  

So, amost done -- just need to now group by & count rides.

@FS18Edelweiss
Copy link
Author

FS18Edelweiss commented Mar 4, 2018 via email

@obscurerichard obscurerichard added enhancement good first issue help wanted Help wanted - can you take this on? labels Jan 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement good first issue help wanted Help wanted - can you take this on?
Projects
None yet
Development

No branches or pull requests

3 participants