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 children served with kits calculation #5027

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

coalest
Copy link
Collaborator

@coalest coalest commented Feb 19, 2025

Resolves #4915

Description

Fixes the children served with kits in disposable calculation.

Note: The old logic was attempting to count all the kits distributed in a given year with disposable items in them. I refactored it to calculate how many children were served by the disposable items inside the kits in a given year. I think this makes more sense, but it might be unexpected for stakeholders hence this warning.

Regarding the implementation, I saw two possibilities here:
1. Rewrite the query in SQL. Con: We would have to repeat the Item.disposable scope logic.
2. Fix it using only Active Record. Pro: Reuse the item.disposable logic so everything is dry. Con: For the sum logic I am referencing table aliases directly and this might be brittle.

I went with option number 2 to keep things dry (in case the logic of Item.disposable changes in the future), but if option 1 is preferred I can refactor this using SQL.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Modified this report service spec.

@cielf
Copy link
Collaborator

cielf commented Feb 19, 2025

@coalest I haven't dug into your code as yet -- but for clarity it should be based on the number of kits that have disposable items in them -- assuming 1 kit per child unless the kit item has a different quantity per individual on it -- rather than the number of disposable items in the kits (as your note seems to suggest).

I don't know if this will make a big difference 'in the wild', but I can imagine use cases where it would undercount the number of children helped if we count the contents rather than the kits.

@coalest
Copy link
Collaborator Author

coalest commented Feb 19, 2025

Ah ok, I didn't realize there was a general 1 kit per child rule. I will refactor this then.

@cielf
Copy link
Collaborator

cielf commented Feb 19, 2025

Hey @coalest

Running a fairly basic example with 1 kit per child, and 240 kits of 25 size 1 diapers and 2 baby wipes. Assuming 1 kit per child, this would give us 20 extra children per month.

The number of diapers went from 32876 to 38876, as expected.

But the number of children served monthly went from 54 to 113? Something doesn't seem right there.

(Also, if I change the quantity per individual on the kit item from the default to 3, the number of children served monthly doesn't change)

@coalest
Copy link
Collaborator Author

coalest commented Feb 19, 2025

I'll have to take a look at why the monthly average is 3 times higher than it should be.

Also I thought the quantity per individual for kits didnt matter, because we were assuming one kit per child. So i will have to adjust that

@cielf
Copy link
Collaborator

cielf commented Feb 20, 2025

"unless the kit item has a different quantity per individual on it "

@coalest
Copy link
Collaborator Author

coalest commented Feb 20, 2025

Where does the "quantity per individual" value come from for a kit? I don't see something like that on the Kit model, and if it's supposed to come from items in the kit then i don't understand how to calculate it when a kit can have multiple items in it.

@cielf
Copy link
Collaborator

cielf commented Feb 20, 2025

There is an item is created when you create a kit, which represents the kit when you are picking things, and is the thing that is in the line items for the distribution. I'm not positive without looking, but I would think there would be a link to that item in the kit model.

That's what I mean when I say "kit item" above.

@coalest
Copy link
Collaborator Author

coalest commented Feb 20, 2025

Ah I see, thanks for the clarification. I get it now.

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.

Children served not calculated correctly if there are kits
2 participants