Skip to content

Gia/306 wishlist priority suggest allocations - #317

Merged
ND68 merged 8 commits into
mainfrom
gia/306-wishlist-priority-suggest-allocations
Mar 31, 2026
Merged

ND68 merged 8 commits into
mainfrom
gia/306-wishlist-priority-suggest-allocations

Conversation

@giannacastr

Copy link
Copy Markdown
Contributor

Description

Resolves ticket number: #306

Explain what your code changes:
Updated the allocation solver to be take wishlist items into account. Integrated partner wishlist data into the programming model; the solver uses a small incentive weight as a tiebreaker. This ensures that for multiple fair paths, the system naturally favors partners who have been waiting on specific items without compromising overall distribution logic.

List the steps you took to test your code:
I printed the LP model’s math to make sure the wishlist logic actually hit the solver. I tested different edge cases including equal vs. unequal requests and empty wishlists to confirm the 0.001 weight tiebreaker works without overriding the primary allocation logic.

Checklist

  • The ticket is mentioned above
  • The changes fulfill the success criteria of the ticket
  • The changes were self-reviewed
  • A review was requested

@giannacastr
giannacastr requested a review from ND68 March 30, 2026 05:27
@giannacastr giannacastr self-assigned this Mar 30, 2026
@netlify

netlify Bot commented Mar 30, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for hope-for-haiti ready!

Name Link
🔨 Latest commit 4f23876
🔍 Latest deploy log https://app.netlify.com/projects/hope-for-haiti/deploys/69cc3a354a82cd00084b4297
😎 Deploy Preview https://deploy-preview-317--hope-for-haiti.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@greptile-apps

greptile-apps Bot commented Mar 30, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR integrates partner wishlist data into the allocation suggestion LP solver as a soft tiebreaker. When multiple fair allocations exist, partners who have the item on their (unlinked) wishlist are gently preferred via a small 0.001 penalty term on new binary indicator variables w_i_p linked to the existing assignment variables x_i_p.

Key changes:

  • New buildWishlistMatches helper queries Wishlist records by partner and item title to build a match map
  • NormalizedItem type extended with wishlistMatches: Map<number, Map<number, boolean>>
  • fetchItemsForDonorOffer and fetchItemsForGeneralItems refactored from reduce to Promise.all + async map to support awaiting the new wishlist query
  • buildLinearProgram updated to emit additional w_i_p binary variables, a wishlist_link constraint, and negative objective terms for wishlist-matching pairs
  • scripts/seed.ts: unrelated removal of the staffAdmin seed user
  • Tutorial.tsx: minor named-import refactor for Joyride

Areas needing attention:

  • The wishlist lookup uses a case-sensitive exact name match against generalItemTitle. Since Wishlist.name is free-text from partners and GeneralItem.title is admin-controlled, silent mismatches are likely in practice — the incentive would never fire for those pairs.
  • One buildWishlistMatches DB query is issued per item inside Promise.all, creating a burst of N concurrent queries. A single batched query would be more efficient.
  • The staffAdmin seed-user removal appears unrelated to this feature and may break other developers' local permission-boundary testing.

Confidence Score: 4/5

Safe to merge after addressing the case-sensitive wishlist name matching, which will silently prevent the feature from working in most real-world cases.

One P1 issue remains: the case-sensitive name match against partner free-text wishlist entries means the wishlist incentive will silently never apply when casing differs between the wishlist entry and the general item title. The LP formulation itself is sound and all prior review feedback has been addressed. Resolving the case-insensitive filter would raise this to a 5.

src/services/allocationSuggestionService.ts — specifically the buildWishlistMatches query on line 22.

Important Files Changed

Filename Overview
src/services/allocationSuggestionService.ts Core change: adds wishlist-priority tiebreaker to the LP allocation model. P1 issue: case-sensitive name matching against partner free-text wishlists will silently miss valid entries. P2: N+1 concurrent DB query pattern for wishlist lookups.
scripts/seed.ts Removes the staffAdmin seed user and its console.log; unrelated to the wishlist feature and may break local permission-boundary testing for other developers.
src/components/Tutorial.tsx Minor import refactor splitting the default Joyride import into a named import; no functional change.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[suggestForDonorOffer / suggestForGeneralItems] --> B[fetchItemsForDonorOffer / fetchItemsForGeneralItems]
    B --> C[Promise.all over general items]
    C --> D{Has line items and requests?}
    D -- No --> E[return null]
    D -- Yes --> F[buildWishlistMatches DB query per item]
    F --> G[Wishlist.findMany where name = generalItemTitle AND generalItemId IS NULL]
    G --> H[Map lineItemId → Map partnerId → boolean]
    H --> I[NormalizedItem with wishlistMatches]
    I --> J[buildProgramsForItems]
    J --> K[buildProgramForItem]
    K --> L[buildLinearProgram with wishlistMatches]
    L --> M[LP objective: min Σ dev + Σ -0.001·w_i_p]
    L --> N[Constraints: assign_i, balance_p, wishlist_link_i_p: w_i_p ≤ x_i_p]
    L --> O[Binaries: x_i_p, w_i_p]
    M & N & O --> P[AllocationSuggestionProgram with LP string]
Loading

Reviews (2): Last reviewed commit: "fixed indentation" | Re-trigger Greptile

Comment thread src/services/allocationSuggestionService.ts Outdated
Comment thread src/services/allocationSuggestionService.ts Outdated
Comment thread src/services/allocationSuggestionService.ts Outdated
Comment thread src/services/allocationSuggestionService.ts Outdated
giannacastr and others added 4 commits March 30, 2026 01:35
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@giannacastr

Copy link
Copy Markdown
Contributor Author

@greptile review

@ND68 ND68 linked an issue Mar 30, 2026 that may be closed by this pull request

@ND68 ND68 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Implementation works well, nice work

@ND68
ND68 merged commit 72a709c into main Mar 31, 2026
5 checks passed
@ND68
ND68 deleted the gia/306-wishlist-priority-suggest-allocations branch March 31, 2026 21:24
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.

Incorporate Wishlist Priority into Suggest Allocations

2 participants