-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from apromessi/ariana-refactor
Refactor #1: Create new files for constants and utils
- Loading branch information
Showing
10 changed files
with
264 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from decimal import Decimal | ||
|
||
ROUNDING_TOLERANCE = Decimal("0.000001") | ||
|
||
|
||
def get_rounding_difference(attributions): | ||
""" | ||
Get the difference of the total of the attributions from 1, which is | ||
expected to occur due to finite precision. If the difference exceeds the | ||
expected error tolerance, an error is signaled. | ||
""" | ||
total = _get_attributions_total(attributions) | ||
difference = total - Decimal("1") | ||
assert abs(difference) <= ROUNDING_TOLERANCE | ||
return difference | ||
|
||
|
||
def correct_rounding_error(attributions, incoming_attribution): | ||
"""Due to finite precision, the Decimal module will round up or down | ||
on the last decimal place. This could result in the aggregate value not | ||
quite totaling to 1. This corrects that total by either adding or | ||
subtracting the difference from the incoming attribution (by convention). | ||
""" | ||
difference = get_rounding_difference(attributions) | ||
attributions[incoming_attribution.email] -= difference | ||
|
||
|
||
def assert_attributions_normalized(attributions): | ||
assert _get_attributions_total(attributions) == Decimal("1") | ||
|
||
|
||
def _get_attributions_total(attributions): | ||
return sum(attributions.values()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import os | ||
|
||
ABE_ROOT = './abe' | ||
PAYOUTS_DIR = os.path.join(ABE_ROOT, 'payouts') | ||
PAYMENTS_DIR = os.path.join(ABE_ROOT, 'payments') | ||
NONATTRIBUTABLE_PAYMENTS_DIR = os.path.join( | ||
ABE_ROOT, 'payments', 'nonattributable' | ||
) | ||
|
||
TRANSACTIONS_FILE = os.path.join(ABE_ROOT, 'transactions.txt') | ||
DEBTS_FILE = os.path.join(ABE_ROOT, 'debts.txt') | ||
ADVANCES_FILE = os.path.join(ABE_ROOT, 'advances.txt') | ||
UNPAYABLE_CONTRIBUTORS_FILE = os.path.join(ABE_ROOT, 'unpayable_contributors.txt') | ||
ITEMIZED_PAYMENTS_FILE = os.path.join(ABE_ROOT, 'itemized_payments.txt') | ||
PRICE_FILE = os.path.join(ABE_ROOT, 'price.txt') | ||
VALUATION_FILE = os.path.join(ABE_ROOT, 'valuation.txt') | ||
ATTRIBUTIONS_FILE = 'attributions.txt' | ||
INSTRUMENTS_FILE = 'instruments.txt' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import subprocess | ||
|
||
def get_git_revision_short_hash() -> str: | ||
"""From https://stackoverflow.com/a/21901260""" | ||
return ( | ||
subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']) | ||
.decode('ascii') | ||
.strip() | ||
) |
Oops, something went wrong.