Skip to content

Commit

Permalink
Minimal rename of internal_id_int to row
Browse files Browse the repository at this point in the history
  • Loading branch information
qwhelan committed Jun 7, 2024
1 parent 554b06d commit 569c3de
Show file tree
Hide file tree
Showing 16 changed files with 194 additions and 178 deletions.
10 changes: 6 additions & 4 deletions src/rp2/abstract_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(
asset: str,
transaction_type: str,
spot_price: RP2Decimal,
internal_id: Optional[int] = None,
row: Optional[int] = None,
unique_id: Optional[str] = None,
notes: Optional[str] = None,
) -> None:
Expand All @@ -39,7 +39,9 @@ def __init__(
self.__timestamp: datetime = configuration.type_check_timestamp_from_string("timestamp", timestamp)
self.__transaction_type: TransactionType = TransactionType.type_check_from_string("transaction_type", transaction_type)
self.__spot_price: RP2Decimal = configuration.type_check_positive_decimal("spot_price", spot_price)
self.__internal_id: int = configuration.type_check_internal_id("internal_id", internal_id) if internal_id is not None else id(self)
# TODO: the fallback case does not semantically match "row", make non-optional # pylint: disable=fixme
self.__row: int = configuration.type_check_internal_id("row", row) if row is not None else id(self)
self.__internal_id: int = self.__row
self.__unique_id: str = configuration.type_check_string_or_integer("unique_id", unique_id) if unique_id is not None else ""
self.__notes = configuration.type_check_string("notes", notes) if notes else ""

Expand Down Expand Up @@ -87,8 +89,8 @@ def internal_id(self) -> str:
return str(self.__internal_id)

@property
def internal_id_int(self) -> int:
return self.__internal_id
def row(self) -> int:
return self.__row

@property
def timestamp(self) -> datetime:
Expand Down
4 changes: 2 additions & 2 deletions src/rp2/in_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ def __init__(
fiat_in_no_fee: Optional[RP2Decimal] = None,
fiat_in_with_fee: Optional[RP2Decimal] = None,
fiat_fee: Optional[RP2Decimal] = None,
internal_id: Optional[int] = None,
row: Optional[int] = None,
unique_id: Optional[str] = None,
notes: Optional[str] = None,
) -> None:
super().__init__(configuration, timestamp, asset, transaction_type, spot_price, internal_id, unique_id, notes)
super().__init__(configuration, timestamp, asset, transaction_type, spot_price, row, unique_id, notes)

self.__exchange: str = configuration.type_check_exchange("exchange", exchange)
self.__holder: str = configuration.type_check_holder("holder", holder)
Expand Down
4 changes: 2 additions & 2 deletions src/rp2/intra_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(
spot_price: Optional[RP2Decimal],
crypto_sent: RP2Decimal,
crypto_received: RP2Decimal,
internal_id: Optional[int] = None,
row: Optional[int] = None,
unique_id: Optional[str] = None,
notes: Optional[str] = None,
) -> None:
Expand All @@ -52,7 +52,7 @@ def __init__(
raise RP2ValueError(
f"crypto_fee is non-zero ({self.__crypto_fee}) but spot_price is empty or zero: {timestamp} {asset} {crypto_sent} {unique_id} "
)
super().__init__(configuration, timestamp, asset, "MOVE", spot_price, internal_id, unique_id, notes)
super().__init__(configuration, timestamp, asset, "MOVE", spot_price, row, unique_id, notes)

self.__from_exchange: str = configuration.type_check_exchange("from_exchange", from_exchange)
self.__from_holder: str = configuration.type_check_holder("from_holder", from_holder)
Expand Down
6 changes: 3 additions & 3 deletions src/rp2/ods_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def _create_and_process_transaction(
fiat_in_no_fee=transaction.fiat_in_no_fee,
fiat_in_with_fee=transaction.fiat_in_with_fee,
fiat_fee=transaction.fiat_fee,
internal_id=internal_id,
row=internal_id,
unique_id=transaction.unique_id,
notes=notes,
)
Expand All @@ -207,7 +207,7 @@ def _create_and_process_transaction(
spot_price=transaction.spot_price,
crypto_out_no_fee=ZERO,
crypto_fee=transaction.crypto_fee,
internal_id=artificial_internal_id,
row=artificial_internal_id,
unique_id=transaction.unique_id,
notes=(
f"Artificial transaction modeling the crypto fee of {transaction.crypto_fee} {transaction.asset} "
Expand Down Expand Up @@ -243,7 +243,7 @@ def _process_constructor_argument_pack(
internal_id: int,
class_name: str,
) -> Dict[str, Any]:
argument_pack.update({"configuration": configuration, "internal_id": internal_id})
argument_pack.update({"configuration": configuration, "row": internal_id})
numeric_parameters: List[str] = _get_decimal_constructor_argument_names(class_name)
for numeric_parameter in numeric_parameters:
if numeric_parameter in argument_pack:
Expand Down
4 changes: 2 additions & 2 deletions src/rp2/out_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ def __init__(
crypto_out_with_fee: Optional[RP2Decimal] = None,
fiat_out_no_fee: Optional[RP2Decimal] = None,
fiat_fee: Optional[RP2Decimal] = None,
internal_id: Optional[int] = None,
row: Optional[int] = None,
unique_id: Optional[str] = None,
notes: Optional[str] = None,
) -> None:
super().__init__(configuration, timestamp, asset, transaction_type, spot_price, internal_id, unique_id, notes)
super().__init__(configuration, timestamp, asset, transaction_type, spot_price, row, unique_id, notes)

self.__exchange: str = configuration.type_check_exchange("exchange", exchange)
self.__holder: str = configuration.type_check_holder("holder", holder)
Expand Down
2 changes: 1 addition & 1 deletion src/rp2/plugin/accounting_method/hifo.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ def lot_candidates_order(self) -> AcquiredLotCandidatesOrder:
return AcquiredLotCandidatesOrder.OLDER_TO_NEWER

def heap_key(self, lot: InTransaction) -> AcquiredLotHeapSortKey:
return AcquiredLotHeapSortKey(-lot.spot_price, lot.timestamp.timestamp(), lot.internal_id_int)
return AcquiredLotHeapSortKey(-lot.spot_price, lot.timestamp.timestamp(), lot.row)
2 changes: 1 addition & 1 deletion src/rp2/plugin/accounting_method/lifo.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ def lot_candidates_order(self) -> AcquiredLotCandidatesOrder:
return AcquiredLotCandidatesOrder.NEWER_TO_OLDER

def heap_key(self, lot: InTransaction) -> AcquiredLotHeapSortKey:
return AcquiredLotHeapSortKey(ZERO, -lot.timestamp.timestamp(), -lot.internal_id_int)
return AcquiredLotHeapSortKey(ZERO, -lot.timestamp.timestamp(), -lot.row)
12 changes: 6 additions & 6 deletions tests/test_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_easy_negative_case(self) -> None:
fiat_fee=RP2Decimal("20"),
fiat_in_no_fee=RP2Decimal("3000.2"),
fiat_in_with_fee=RP2Decimal("3020.2"),
internal_id=30,
row=30,
)
in_transaction_set.add_entry(transaction1)

Expand All @@ -73,7 +73,7 @@ def test_easy_negative_case(self) -> None:
RP2Decimal("4.0000"),
crypto_fee=RP2Decimal("0.0002"),
fiat_out_no_fee=RP2Decimal("4000.0"),
internal_id=31,
row=31,
)
out_transaction_set.add_entry(transaction2)

Expand Down Expand Up @@ -106,7 +106,7 @@ def test_hard_negative_case(self) -> None:
fiat_fee=RP2Decimal("20"),
fiat_in_no_fee=RP2Decimal("3000.2"),
fiat_in_with_fee=RP2Decimal("3020.2"),
internal_id=30,
row=30,
)
in_transaction_set.add_entry(transaction1)

Expand All @@ -121,7 +121,7 @@ def test_hard_negative_case(self) -> None:
RP2Decimal("4.0000"),
crypto_fee=RP2Decimal("0.0002"),
fiat_out_no_fee=RP2Decimal("6000.0"),
internal_id=31,
row=31,
)
out_transaction_set.add_entry(transaction2)

Expand All @@ -137,7 +137,7 @@ def test_hard_negative_case(self) -> None:
fiat_fee=RP2Decimal("20"),
fiat_in_no_fee=RP2Decimal("3000.2"),
fiat_in_with_fee=RP2Decimal("3020.2"),
internal_id=32,
row=32,
)
in_transaction_set.add_entry(transaction3)

Expand All @@ -152,7 +152,7 @@ def test_hard_negative_case(self) -> None:
RP2Decimal("2.0000"),
crypto_fee=RP2Decimal("0.0002"),
fiat_out_no_fee=RP2Decimal("2000.0"),
internal_id=33,
row=33,
)
out_transaction_set.add_entry(transaction4)

Expand Down
14 changes: 7 additions & 7 deletions tests/test_gain_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def setUp(self) -> None:
fiat_fee=RP2Decimal("20"),
fiat_in_no_fee=RP2Decimal("20002"),
fiat_in_with_fee=RP2Decimal("20022"),
internal_id=10,
row=10,
)
self._in_buy2 = InTransaction(
self._configuration,
Expand All @@ -59,7 +59,7 @@ def setUp(self) -> None:
RP2Decimal("10500"),
RP2Decimal("0.8"),
fiat_fee=RP2Decimal("10"),
internal_id=11,
row=11,
)
self._in_buy3 = InTransaction(
self._configuration,
Expand All @@ -71,7 +71,7 @@ def setUp(self) -> None:
RP2Decimal("1300"),
RP2Decimal("1.5"),
fiat_fee=RP2Decimal("20"),
internal_id=12,
row=12,
)
self._in_interest = InTransaction(
self._configuration,
Expand All @@ -83,7 +83,7 @@ def setUp(self) -> None:
RP2Decimal("11000"),
RP2Decimal("0.1"),
fiat_fee=RP2Decimal("0"),
internal_id=14,
row=14,
)
self._out: OutTransaction = OutTransaction(
self._configuration,
Expand All @@ -95,7 +95,7 @@ def setUp(self) -> None:
RP2Decimal("12000"),
RP2Decimal("0.2"),
RP2Decimal("0"),
internal_id=20,
row=20,
)
self._intra: IntraTransaction = IntraTransaction(
self._configuration,
Expand All @@ -108,7 +108,7 @@ def setUp(self) -> None:
RP2Decimal("12500.0"),
RP2Decimal("0.4"),
RP2Decimal("0.39"),
internal_id=30,
row=30,
)

def test_good_interest_gain_loss(self) -> None:
Expand Down Expand Up @@ -313,7 +313,7 @@ def test_bad_gain_loss(self) -> None:
RP2Decimal("1300"),
RP2Decimal("1.5"),
fiat_fee=RP2Decimal("20"),
internal_id=11,
row=11,
)
GainLoss(self._configuration, RP2Decimal("0.1"), self._out, in_transaction)

Expand Down
28 changes: 14 additions & 14 deletions tests/test_gain_loss_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def _initialize_transactions(cls, asset: str) -> None:
RP2Decimal("11000"),
RP2Decimal("1"),
fiat_fee=RP2Decimal("100.00"),
internal_id=4,
row=4,
)
cls._in2[asset] = InTransaction(
cls._configuration,
Expand All @@ -104,7 +104,7 @@ def _initialize_transactions(cls, asset: str) -> None:
RP2Decimal("12000.0"),
RP2Decimal("2.0"),
fiat_fee=RP2Decimal("0"),
internal_id=3,
row=3,
)
cls._in6[asset] = InTransaction(
cls._configuration,
Expand All @@ -116,7 +116,7 @@ def _initialize_transactions(cls, asset: str) -> None:
RP2Decimal("13000.0"),
RP2Decimal("3"),
fiat_fee=RP2Decimal("0"),
internal_id=7,
row=7,
)
cls._in5[asset] = InTransaction(
cls._configuration,
Expand All @@ -128,7 +128,7 @@ def _initialize_transactions(cls, asset: str) -> None:
RP2Decimal("14000.0"),
RP2Decimal("4.0"),
fiat_fee=RP2Decimal("400"),
internal_id=6,
row=6,
)
cls._in4[asset] = InTransaction(
cls._configuration,
Expand All @@ -140,7 +140,7 @@ def _initialize_transactions(cls, asset: str) -> None:
RP2Decimal("15000.0"),
RP2Decimal("5.0"),
fiat_fee=RP2Decimal("500"),
internal_id=5,
row=5,
)
cls._out15[asset] = OutTransaction(
cls._configuration,
Expand All @@ -152,7 +152,7 @@ def _initialize_transactions(cls, asset: str) -> None:
RP2Decimal("11200.0"),
RP2Decimal("0.2"),
RP2Decimal("0"),
internal_id=16,
row=16,
)
cls._out14[asset] = OutTransaction(
cls._configuration,
Expand All @@ -164,7 +164,7 @@ def _initialize_transactions(cls, asset: str) -> None:
RP2Decimal("12200.0"),
RP2Decimal("1.0"),
RP2Decimal("0"),
internal_id=15,
row=15,
)
cls._out16[asset] = OutTransaction(
cls._configuration,
Expand All @@ -176,7 +176,7 @@ def _initialize_transactions(cls, asset: str) -> None:
RP2Decimal("14200.00"),
RP2Decimal("5.0"),
RP2Decimal("0"),
internal_id=17,
row=17,
)
cls._out12[asset] = OutTransaction(
cls._configuration,
Expand All @@ -188,7 +188,7 @@ def _initialize_transactions(cls, asset: str) -> None:
RP2Decimal("14300"),
RP2Decimal("3.79"),
RP2Decimal("0"),
internal_id=13,
row=13,
)
cls._out13[asset] = OutTransaction(
cls._configuration,
Expand All @@ -200,7 +200,7 @@ def _initialize_transactions(cls, asset: str) -> None:
RP2Decimal("20200.00"),
RP2Decimal("2"),
RP2Decimal("0.01"),
internal_id=14,
row=14,
)
cls._intra25[asset] = IntraTransaction(
cls._configuration,
Expand All @@ -213,7 +213,7 @@ def _initialize_transactions(cls, asset: str) -> None:
RP2Decimal("11400.0"),
RP2Decimal("0.1"),
RP2Decimal("0.09"),
internal_id=26,
row=26,
)
cls._intra24[asset] = IntraTransaction(
cls._configuration,
Expand All @@ -226,7 +226,7 @@ def _initialize_transactions(cls, asset: str) -> None:
RP2Decimal("14400.0"),
RP2Decimal("0.2"),
RP2Decimal("0.18"),
internal_id=25,
row=25,
)
cls._intra22[asset] = IntraTransaction(
cls._configuration,
Expand All @@ -239,7 +239,7 @@ def _initialize_transactions(cls, asset: str) -> None:
RP2Decimal("21400.0"),
RP2Decimal("0.5"),
RP2Decimal("0.46"),
internal_id=23,
row=23,
)
cls._gain_loss_set[asset] = GainLossSet(cls._configuration, asset)
if asset == "B1":
Expand Down Expand Up @@ -388,7 +388,7 @@ def test_bad_gain_loss_set(self) -> None:
RP2Decimal("12000.0"),
RP2Decimal("2.0"),
fiat_fee=RP2Decimal("0"),
internal_id=3,
row=3,
)
gain_loss_set.add_entry(GainLoss(self._configuration, RP2Decimal("0.2"), out15, in3))
gain_loss_set.add_entry(GainLoss(self._configuration, RP2Decimal("0.2"), out15, in_transaction_test))
Expand Down
Loading

0 comments on commit 569c3de

Please sign in to comment.