Repository navigation
Query by sport and gender for daily sun articles and videos - #90
Open
AnikDey-exe wants to merge 3 commits into
Open
AnikDey-exe wants to merge 3 commits into
AnikDey-exe wants to merge 3 commits into
Conversation
AnikDey-exe
requested review from
cejiogu and
claiireyu
and
a balanced review from Copilot
and removed request for
Copilot
November 11, 2026 04:11
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Adds
sportandgenderfiltering to the videos and articles GraphQL queries.Neither collection could support this before. Videos had no sport stored at all (it was derived at query time in
types.py), and articles storedsports_typebut no gender. This derives both fields, stores them on new rows, and backfills the existing ones so the queries can filter in Mongo rather than in Python.Changes Made
Query layer
Both arguments are optional on both queries. Filtering happens in the repository as a Mongo query, matching the existing
find_by_sports_type.find_by_sports_typeis kept and delegates to the newfind_recent_filtered, so nothing that called it changes.YoutubeVideoTypegainssportandgender;ArticleTypegainsgender. The existingsportsTypefield on videos is kept as a deprecated alias forsportso current clients keep working. Both resolvers prefer the stored value and fall back to deriving from the title, so rows the backfill could not classify still resolve.Extraction
Articles take their sport from the Daily Sun feed's
tagsand fall back to the headline; gender goes the other way, headline first then tags. That ordering is based on measurement rather than preference: across the 20 articles in the live feed, tags gave the sport for 20/20 and the headline for 19/20, while the headline gave the gender for 19/20 and tags for 18/20. They never disagreed where both resolved.The scraper already fetched that endpoint and discarded
tags, so this costs no extra request.Videos use the title only. The YouTube search endpoint's snippet carries no tags, and fetching them would need a second API call per video for a field the title already supplies.
For sports Cornell fields only one team in, the gender is inferred from the sport. "Cornell Volleyball" and "Cornell Wrestling" are not written with a gender, and that mapping is derived from
SPORT_URLSrather than hardcoded, so adding a team keeps it in step.Three bugs in
extract_sport_from_titleThese had to be fixed before backfilling, or the wrong values would have been written to every row:
Sprint Footballwas classified asFootball. The\bfootball\bpattern sat abovesprint\s+football, so it matched first.LacrosseandRowingreturnedNone, having no patterns at all. Added those plus baseball, softball, tennis, squash, golf, polo, gymnastics, fencing, equestrian, sailing, cross country, track and field, and swimming and diving."ice" in title and "cornell" in titleas a substring check, so any title containing "Service", "Practice" or "Choice" classified as Ice Hockey.Cornell Athletics Community Service DayreturnedIce Hockey. Removed, since\bhockey\balready covers the real cases.Backfill
scripts/backfill_sport_gender.pypopulates both collections from existing titles, re-fetching the Daily Sun feed to recover tags (stored articles match feed entries by slug). Dry run by default:It is idempotent, so it can be re-run after any change to the extraction helpers.
Test Coverage
Manual, against live data. No automated tests, consistent with the rest of this area of the codebase.
Backfill applied to 78 documents, after which:
Re-running then reported
to update: 0, confirming idempotency.Queries executed against that data:
Articles return 4 of 5 because
find_recentapplies a 3-day window, which is existing behaviour.Both scrapers were run with the network mocked. The article scraper produced 20/20 documents with a real sport and 20/20 with a gender, and no
"sports"placeholders. The video scraper resolvedLacrosse/MensandVolleyball/Womens, and correctly returned nulls for a title that names no sport. A video was round-tripped through the service into Mongo and read back with both fields intact.Also verified: the app imports, the GraphQL schema builds, and the existing test suite passes.
Reproduce
Then at http://localhost:8000/graphql:
{ youtubeVideos(sport: "Ice Hockey", gender: "Womens") { title sport gender url } articles(sportsType: "Ice Hockey", gender: "Womens") { title sportsType gender url } }Next Steps
Two videos stay unclassified because their titles name no sport, "Cornell Athletics Visits Meinig Fieldhouse" and "Beyond the Ice: Day in the Life of Jonathan Castagna". They return
sport: nulland appear only in unfiltered results. Worth knowing if a client expects every video to carry a sport.No indexes were added on
sportorgender. At 75 and 5 documents that makes no difference, but they are worth adding if these collections grow.