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

limited schedules #301

Merged
merged 8 commits into from
Jul 23, 2022
Merged

limited schedules #301

merged 8 commits into from
Jul 23, 2022

Conversation

arrington7
Copy link
Collaborator

No description provided.

@gitpod-io
Copy link

gitpod-io bot commented Jul 21, 2022

@ghost
Copy link

ghost commented Jul 21, 2022

👇 Click on the image for a new way to code review
  • Make big changes easier — review code in small groups of related files

  • Know where to start — see the whole change at a glance

  • Take a code tour — explore the change with an interactive tour

  • Make comments and review — all fully sync’ed with github

    Try it now!

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map Legend

Copy link
Collaborator

@vingkan vingkan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad you could open this pull request, @eeerie!

I left comments on next steps, let me know if you have any questions. Hopefully you can work on some of these before our next meeting.

@@ -59,7 +59,7 @@ def test_example():
]
# TODO: Uncomment this assertion and delete the empty list assert
# assert actual == expected
assert actual == []
assert actual == expected


# TODO: Add more test cases for your logic
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are some more test cases that we should add? And how comfortable do you feel writing new test cases based on the example given to you in this file?

Brainstorm in words what test cases you think we should add, then I can comment your plan to let you know if you are missing any important ones or if any cases are not necessary. Then you can go ahead and take that plan to write the tests in Python.

# Maximum number of available slots in a user's schedule for them to be
# eligible for a limited availability match.
self.max_available = max_available
super().__init__(name=GENERATOR_LIMITED_SCHEDULES)

def generate(self, inp: MatchingInput) -> Iterator[Match]:
# TODO: Implement your generator
inp.logger.info("Luke Arrington was here!")

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write now the outline of your code looks like:

  1. Get the users who have limited schedules
  2. Compare limited users to other users, check if their schedules align, and create matches
  3. Return matches (work in progress)

There is a lot going on in step two, so I recommend splitting it up like this:

  1. Get the users who have limited schedules
  2. Compare limited users to other users, collect the schedule times they have in common (save to a dictionary)
  3. Loop through the dictionary to create matches for the users you saved
  4. Return matches

This should also help reduce the deep levels of indentation in your code. Sometimes too much indentation can make it harder to read and follow the code. That might be a clue that the logic is getting too complicated.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! We also improved the indentation issues by using a continue in the loop.

Comment on lines 38 to 42
for l_availability in limited_user.schedule:
for availability in user.schedule:
if (
l_availability == availability
): # if the availabilities in limited user schedule and other user schedule are the same, then we have a match!
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now, I think what you are doing is getting just one time the two users have in common. We want to get all the times they have in common. It should be a small list since one user has limited availability. But, since the parameter max_available can change, we shouldn't assume that it will always be 1.

I would recommend creating a dictionary like common_availability where the key is the set of the two user IDs and the value is a list of the availabilities they have in common. When you go through this loop, you can append the matching availabilities to that list.

matches[
{limited_user.uid, user.uid}
] = Match(
users={limited_user.uid, user.uid}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you are ready to create the matches, you can add the availabilities the two users have in common like this:

# Put this at the top of your file to import the metadata (or add it to the list of types already being imported)
from pipeline.types import MatchMetadata

Match(
  users={uid1, uid2},
  metadata=MatchMetadata(
    generator=GENERATOR_LIMITED_SCHEDULES,
    availability=availability
  )
)

The variable availability should be a list of the matching availabilities between the users, from their schedules.

@vingkan vingkan added enhancement New feature or request pipeline Related to the offline pipelines labels Jul 21, 2022
Copy link
Collaborator

@vingkan vingkan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, Luke! We confirmed that the tests pass and the pipeline passes, so we can merge this.

You can add more test cases in a future pull request.

# compare limited users to all users
for limited_user in limited_availability:
for user in inp.users:
userid_tuple = (limited_user.uid, user.uid)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also a subtle issue here that if both users are limited users, we might create two versions of the same match, one where the first user comes first in the tuple, and one with the opposite order.

This is okay because the matching engine ignores duplicate matches. But we can fix this in the future when you write more test cases.

@arrington7 arrington7 marked this pull request as ready for review July 23, 2022 21:36
@arrington7 arrington7 merged commit 7bb027e into main Jul 23, 2022
@arrington7 arrington7 deleted the la_first_pr branch July 23, 2022 21:37
notedwin pushed a commit that referenced this pull request Jul 29, 2022
* Luke Arrington's first commit.

* compares users and add matches to dict

* added create_matches and test

* completed create function

* completed create matches function

* passed test cases
lwilliams717 pushed a commit that referenced this pull request Aug 9, 2022
* Luke Arrington's first commit.

* compares users and add matches to dict

* added create_matches and test

* completed create function

* completed create matches function

* passed test cases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pipeline Related to the offline pipelines
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants