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

fix!: rights conservation should allow new brands or dropped brands if sum is empty #3036

Merged
merged 3 commits into from
May 5, 2021

Conversation

katelynsills
Copy link
Contributor

Closes #3033

The rights conservation code previously checked that the brands before and after a proposed allocation were exactly the same. This assumption is wrong, because from a rights allocation perspective, it is ok to include a new brand or drop a brand, as long as the sum is empty.

From the code comments:

  // We cannot assume that all of the brand keys present in
  // leftSumsByBrand are also present in rightSumsByBrand. A empty
  // amount could be introduced or dropped, and this should still be
  // deemed "equal" from the perspective of rights conservation.

  // Thus, we should allow for a brand to be missing from a map, but
  // only if the sum for the brand in the other map is empty.

};

const assertSumsEqualInMap = (mapToIterate, mapToCheck) => {
mapToIterate.keys().forEach(brand => {
Copy link
Member

Choose a reason for hiding this comment

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

If you union the brands, you can do each comparison only once.

Suggested change
mapToIterate.keys().forEach(brand => {
const allBrands = new Set([...mapToIterate.keys(), ...mapToCheck.keys()]);
allBrands.forEach(brand => {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oo, nice!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

huh, looking at this method in isolation though, we don't know if the brand is defined in the left or the right. And to make empty, we need an amount from the other map. The code gets messy because it doesn't have a place to stand. Let me see if I can improve this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, pushed up a version that uses allBrands, but is a little more verbose

@erights erights self-requested a review May 5, 2021 01:57
@katelynsills katelynsills force-pushed the 3033-fix-rights-conservation-check branch from 1fd4873 to 940f33d Compare May 5, 2021 02:41
Copy link
Member

@erights erights left a comment

Choose a reason for hiding this comment

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

LGTM

@katelynsills katelynsills enabled auto-merge (squash) May 5, 2021 21:32
@katelynsills katelynsills merged commit 56c5943 into master May 5, 2021
@katelynsills katelynsills deleted the 3033-fix-rights-conservation-check branch May 5, 2021 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Zoe package: Zoe
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Zoe: reallocating empty amounts for seats that had no prior allocation for the brand
2 participants