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

Gym module created #185

Merged
merged 11 commits into from
Aug 8, 2024
Merged

Gym module created #185

merged 11 commits into from
Aug 8, 2024

Conversation

csidarous
Copy link
Contributor

Created Gym module to scrape data of all the gym counts and returns as a dictionary.

@tianyizheng02
Copy link
Contributor

Tests are failing because of formatting issues with black. Please check out the contributing guidelines for installing and running the dev tools we use. Ideally you should be using pre-commit to check for spacing issues, formatting issues, etc. prior to committing your code.

Copy link
Contributor

@tianyizheng02 tianyizheng02 left a 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

pittapi/gym.py Outdated Show resolved Hide resolved
@Steven-Jarmell
Copy link
Contributor

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:
Copy link
Contributor

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()

Copy link
Contributor

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
Comment on lines 48 to 85
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"]
Copy link
Contributor

@Steven-Jarmell Steven-Jarmell Jul 6, 2024

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.

Copy link
Contributor

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

import responses
from pittapi import gym

GYM_URL = "https://connect2concepts.com/connect2/?type=bar&key=17c2cbcb-ec92-4178-a5f5-c4860330aea0"
Copy link
Contributor

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

tests/gym_test.py Outdated Show resolved Hide resolved
pittapi/gym.py Outdated
GYM_URL = "https://connect2concepts.com/connect2/?type=bar&key=17c2cbcb-ec92-4178-a5f5-c4860330aea0"


def fetch_gym_info() -> dict:
Copy link
Contributor

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

@tianyizheng02
Copy link
Contributor

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

@csidarous
Copy link
Contributor Author

csidarous commented Jul 10, 2024

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.

Copy link
Contributor

@Steven-Jarmell Steven-Jarmell left a 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

pittapi/gym.py Outdated Show resolved Hide resolved
pittapi/gym.py Outdated Show resolved Hide resolved
pittapi/gym.py Outdated Show resolved Hide resolved
pittapi/gym.py Outdated Show resolved Hide resolved
pittapi/gym.py Outdated Show resolved Hide resolved
pittapi/gym.py Outdated Show resolved Hide resolved
pittapi/gym.py Outdated Show resolved Hide resolved
pittapi/gym.py Outdated Show resolved Hide resolved
pittapi/gym.py Outdated Show resolved Hide resolved
@Steven-Jarmell
Copy link
Contributor

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.

@Steven-Jarmell
Copy link
Contributor

Also considering that there are 8 commits, once Tianyi is satisfied, let's rebase and squash them into one commit.

pittapi/gym.py Outdated Show resolved Hide resolved
pittapi/gym.py Outdated Show resolved Hide resolved
@tianyizheng02
Copy link
Contributor

Name                  Stmts   Miss Branch BrPart  Cover   Missing
-----------------------------------------------------------------
...
pittapi/gym.py           40      0     10      0   100%

Nice, 100% coverage 👍

pittapi/gym.py Outdated Show resolved Hide resolved
@tianyizheng02 tianyizheng02 merged commit 966b603 into pittcsc:dev Aug 8, 2024
4 checks passed
@tianyizheng02
Copy link
Contributor

Thanks for all your work, @csidarous!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants