-
-
Notifications
You must be signed in to change notification settings - Fork 515
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
base: main
Are you sure you want to change the base?
Fix children served with kits calculation #5027
Conversation
@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. |
Ah ok, I didn't realize there was a general 1 kit per child rule. I will refactor this then. |
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) |
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 |
"unless the kit item has a different quantity per individual on it " |
Where does the "quantity per individual" value come from for a kit? I don't see something like that on the |
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. |
Ah I see, thanks for the clarification. I get it now. |
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 theItem.disposable
scope logic.2. Fix it using only Active Record. Pro: Reuse theitem.disposable
logic so everything is dry. Con: For thesum
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 ofItem.disposable
changes in the future), but if option 1 is preferred I can refactor this using SQL.Type of change
How Has This Been Tested?
Modified this report service spec.