-
Notifications
You must be signed in to change notification settings - Fork 308
Experiment with a 'estimated payment for next week' value #3878
Comments
Here's the output: |
Script used: from gratipay import wireup
db = wireup.db(wireup.env())
teams = db.all("""
SELECT t.*::teams
FROM teams t
""")
print("Team,Average over 5 weeks,Last Week,Estimated")
for t in teams:
estimated = t.get_upcoming_payment()
last_week = db.one("""
SELECT COALESCE(SUM(amount), 0)
FROM payments
WHERE team = %s
AND direction = 'to-team'
AND payday = (SELECT id FROM paydays ORDER BY id DESC LIMIT 1)
""", (t.slug, ))
average_5_wks = db.one("""
SELECT ROUND(COALESCE(SUM(amount), 0) / 5, 2) AS avg
FROM payments
WHERE team = %s
AND direction = 'to-team'
AND payday >= 240
""", (t.slug, ))
print(",".join([t.name, str(last_week), str(average_5_wks), str(estimated)])) |
Now that gratipay/inside.gratipay.com#440 is done, I'm going to get values from there |
My aim here is to compare the estimated and actual values and try to see if there are reasons for deviation that can be factored (are predictable) into the formula used. Once we're down to a case where all the reasons are the kind that we can't predict (payments cancelled, new payments setup, cards failing for the first time), this should be ready for review. |
|
^ A lot of the expected values are lower than the actuals because of users who had a Gratipay balance that hasn't been withdrawn. There are two reasons that I'm not taking this into account while calculating the estimated payment:
|
!m @rohitpaulk On my radar ... |
Alright, @rohitpaulk, can you help me understand the implications of this analysis? Does this impact #3876 somehow? |
I'm not seeing an obvious commit on #3876 that implements the estimation algorithm, for example. |
@whit537 - Code for the estimation is present at #3873. def get_upcoming_payment(self):
return self.db.one("""
SELECT COALESCE(SUM(amount + due), 0)
FROM current_payment_instructions cpi
JOIN participants p ON cpi.participant = p.username
WHERE team = %(slug)s
AND is_funded -- Check whether the payment is funded
AND ( -- Check whether the user will hit the minimum charge
SELECT SUM(amount + due)
FROM current_payment_instructions cpi2
WHERE cpi2.participant = p.username
AND cpi2.is_funded
) >= %(mcharge)s
""", {'slug': self.slug, 'mcharge': MINIMUM_CHARGE}) |
What was the resolution here? |
I created this as a prerequisite for #3873, which has now been merged. |
I guess we might circle back here as part of #3992 |
Reticketed from #3873 (comment)
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: