-
Notifications
You must be signed in to change notification settings - Fork 35
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
Gym module created #185
Gym module created #185
Conversation
Tests are failing because of formatting issues with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add unit tests for this new module
I have a lot of historical data for this stored, feel free to use this URL to access it: https://pitt-gym-tracker.vercel.app/api/gymdata/Baierl%20Rec%20Center |
pittapi/gym.py
Outdated
GYM_URL = "https://connect2concepts.com/connect2/?type=bar&key=17c2cbcb-ec92-4178-a5f5-c4860330aea0" | ||
|
||
|
||
def fetch_gym_info() -> dict: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rename this, it can be misinterpreted as fetching a single gym's information. Let's also call it something like get_all_gyms_info()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also on this line, it'd be nice if the type hint specified the dictionary's key and value types, something like
def function_name() -> dict[some_type, some_type]:
If/when we start using mypy
in this repo for static type checking, this'll be important
pittapi/gym.py
Outdated
def get_baierl_rec_count(): | ||
info = fetch_gym_info() | ||
return info["Baierl Rec Center"] | ||
|
||
|
||
def get_bellfield_fitness_count(): | ||
info = fetch_gym_info() | ||
return info["Bellefield Hall: Fitness Center & Weight Room"] | ||
|
||
|
||
def get_bellfield_court_count(): | ||
info = fetch_gym_info() | ||
return info["Bellefield Hall: Court & Dance Studio"] | ||
|
||
|
||
def get_trees_fitness_count(): | ||
info = fetch_gym_info() | ||
return info["Trees Hall: Fitness Center"] | ||
|
||
|
||
def get_trees_court_count(): | ||
info = fetch_gym_info() | ||
return info["Trees Hall: Courts"] | ||
|
||
|
||
def get_trees_raquetball_court_count(): | ||
info = fetch_gym_info() | ||
return info["Trees Hall: Racquetball Courts & Multipurpose Room"] | ||
|
||
|
||
def get_willaim_pitt_fittness_count(): | ||
info = fetch_gym_info() | ||
return info["William Pitt Union"] | ||
|
||
|
||
def get_sports_dome_count(): | ||
info = fetch_gym_info() | ||
return info["Pitt Sports Dome"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a very scalable way of doing this and produces a lot of unnecessary code. Let's refactor this to have a list of gym names and one method to retrieve one gyms information. Something like this:
GYM_NAMES = ["Baierl Rec Center"... ]
def get_gym_information(gym_name: string) -> Gym:
# Validate that gym_name is in GYM_NAMES
# return info[gym_name]
With something like this, if there is ever a new gym location in the future that Pitt starts collecting data for, adding it to this API would be as simple as adding the name to the list, rather than having to create a brand new method for it.
It would also be a good practice to create a Gym data structure (as shown in the method signature) to store the information for each gym to create a formal model of how to access the data rather than having to print out the object and figure it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^ See courses.py
for how you could create a data structure (namely a NamedTuple
) to store this kind of structured data
tests/gym_test.py
Outdated
import responses | ||
from pittapi import gym | ||
|
||
GYM_URL = "https://connect2concepts.com/connect2/?type=bar&key=17c2cbcb-ec92-4178-a5f5-c4860330aea0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to declare this again, you can simply access it from the gym module :)
gym.GYM_URL
pittapi/gym.py
Outdated
GYM_URL = "https://connect2concepts.com/connect2/?type=bar&key=17c2cbcb-ec92-4178-a5f5-c4860330aea0" | ||
|
||
|
||
def fetch_gym_info() -> dict: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also on this line, it'd be nice if the type hint specified the dictionary's key and value types, something like
def function_name() -> dict[some_type, some_type]:
If/when we start using mypy
in this repo for static type checking, this'll be important
Also, looks like unit tests are failing: > self.assertEqual(gym_info["Baierl Rec Center"], "200")
E AssertionError: '0' != '200'
E - 0
E + 200 You can find more details in the test logs |
Thanks both for your feedback and guidance. I made the requested updates and changed to the Gym module. I will try my best to add more tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small change needed to fix the variable for the list of gym names, then this should be good
Hey @csidarous, the commit message that you just sent has a typo at the beginning. Let's be more careful about this and hold a high bar. |
Also considering that there are 8 commits, once Tianyi is satisfied, let's rebase and squash them into one commit. |
Nice, 100% coverage 👍 |
Thanks for all your work, @csidarous! |
Created Gym module to scrape data of all the gym counts and returns as a dictionary.