Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

run Gittip 89 #2029

Closed
chadwhitacre opened this issue Feb 13, 2014 · 26 comments
Closed

run Gittip 89 #2029

chadwhitacre opened this issue Feb 13, 2014 · 26 comments

Comments

@chadwhitacre
Copy link
Contributor

88

@clone1018
Copy link
Contributor

Thanks for reminding me it's Thursday Chad. +1

@chadwhitacre
Copy link
Contributor Author

:-)

@chadwhitacre
Copy link
Contributor Author

I've marked these two users as suspicious:

@chadwhitacre
Copy link
Contributor Author

@chadwhitacre
Copy link
Contributor Author

Reviewed 56 accounts.

@chadwhitacre
Copy link
Contributor Author

Droplet spun up and updated. Taking a backup ...

@chadwhitacre
Copy link
Contributor Author

Backup verified.

@chadwhitacre
Copy link
Contributor Author

Script started, parent shell kill 6ed.

@chadwhitacre
Copy link
Contributor Author

Script ran for {age} (2:35:51.452689).

@chadwhitacre
Copy link
Contributor Author

Blog post tumbled on Tumblr.

Tweet tweeted on Twitter.

@chadwhitacre
Copy link
Contributor Author

Log downloaded.

@chadwhitacre
Copy link
Contributor Author

Droplet destroyed.

@chadwhitacre
Copy link
Contributor Author

Dang it! MassPay is off by a penny again. :-/

@chadwhitacre
Copy link
Contributor Author

I've used binary search to find the bad amount amongst the 30 in the MassPay CSV for today. The process is:

  1. Commit all three files into my local git repo for masspay.
  2. Edit todays *.input.csv file.
  3. Rerun ./bin/masspay.py -o
  4. Click "Make Changes" in the PayPal UI.
  5. Upload the new *.paypal.csv file.
  6. Click "Review."
  7. GOTO 2

The bad amount is 26.26. We compute a net of 25.74 and a fee of 0.52, but PayPal computes a fee of 0.51 on 25.74.

@chadwhitacre
Copy link
Contributor Author

Last time we dealt with something like this was #1673 (per comment in code). See also #1958, which we worked around but didn't get to the bottom of.

@chadwhitacre
Copy link
Contributor Author

$ ./env/bin/python test.py
26.24 0.51 25.73 26.24
26.25 0.51 25.74 26.25
26.26 0.51 25.75 26.26
26.27 0.52 25.75 26.26
26.28 0.52 25.76 26.28
26.29 0.52 25.77 26.29
$
#!/usr/bin/python
from __future__ import division

from decimal import Decimal as D


def round_(d):
    return d.quantize(D('0.01'))


for i in range(2624, 2630):
    amount = D(str(i / 100))
    fee = amount - round_(amount / D('1.02'))
    base = amount - fee
    check = round_(base * D('1.02'))
    print amount, fee, base, check

@chadwhitacre
Copy link
Contributor Author

The third column is the number we upload to PayPal.
The second column is the fee we expect PayPal to upcharge us.

26.24 0.51 25.73 26.24
26.25 0.51 25.74 26.25
26.26 0.51 25.75 26.26
26.27 0.52 25.75 26.26
26.28 0.52 25.76 26.28
26.29 0.52 25.77 26.29

In this case we're trying to hit 26.27, and we're uploading 25.74.

@chadwhitacre
Copy link
Contributor Author

We're trying to hit 26.27, which we compute as 25.75, which does hit the special-case we added in #1673.

@chadwhitacre
Copy link
Contributor Author

Okay! So the number we want to upload is 25.75. Why don't we?

@chadwhitacre
Copy link
Contributor Author

Why is the special-casing wrong in this case? Why is this case not, in fact, special? And why did we think it was?

@chadwhitacre
Copy link
Contributor Author

We have two special cases: .25 and .75. The math is opposite in the .75 case, but we treat it just like the .25 case.

@chadwhitacre
Copy link
Contributor Author

Every 50th one, there is no rounding error.

@chadwhitacre
Copy link
Contributor Author

I'm doing something wrong.

@chadwhitacre
Copy link
Contributor Author

Okay, bottom line is if it's 0.75 we don't need to adjust. Giving up on the math. :-(

@chadwhitacre
Copy link
Contributor Author

Here's where my test.py ended up:

#!/usr/bin/python
from __future__ import division

from decimal import Decimal as D


def round_(d):
    return d.quantize(D('0.01'))


#for i in range(2624, 2630):
for i in range(0, 3000):
    amount = D(str(i / 100))
    fee = amount - round_(amount / D('1.02'))
    precise_fee = amount - amount / D('1.02')
    base = amount - fee
    check = round_(base * D('1.02'))

    cents = str(base)[-2:]

    try:
        if cents == '25':
            assert check - amount == D('0.01')
        if cents == '75':
            assert check - amount == D('-0.01')
    except AssertionError:
        print "NOPE"

    print "trying to hit  ", str(amount).rjust(5)
    print "guessing fee is", str(precise_fee)[:7].rjust(8)
    print "so uploading   ", str(base).rjust(5)
    print "right?         ", str(check).rjust(5)

    print

@chadwhitacre
Copy link
Contributor Author

Masspay done for 30 participants. Escrow rebalanced.

This was referenced Mar 27, 2014
This was referenced Apr 18, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants