risk_propagation.accounts module

Configuration of a dictionary of bank accounts

class risk_propagation.accounts.Accounts(accounts=None)[source]

Bases: MutableMapping[str, Account]

Class containing a dictionary of accounts

__delitem__(key)[source]

Implements deletion of an account

Parameters:

key (str) – the key (label of the account) to delete

Return type:

None

__getitem__(key)[source]

Enables usage of [] to get an account

Parameters:

key (str) – the key (label of the account) to get

Return type:

Account

Returns:

the found account

__init__(accounts=None)[source]

Initializes an Accounts instance

Parameters:

accounts (set[Account] | None) – optional set of accounts to initialise with

__iter__()[source]
Return type:

Iterator[str]

Returns:

an iterator over the class

__len__()[source]
Return type:

int

Returns:

the number of accounts in the instance

__setitem__(key, value)[source]

Enables usage of [] to set an account

Parameters:
  • key (str) – the key (label of the account) to set

  • value (Account) – the account to set

Return type:

None

__str__()[source]
Return type:

str

Returns:

string representation of the accounts, line-separated

encrypt(public_key)[source]

Encrypt all accounts

Parameters:

public_key (DistributedPaillier | Paillier) – public key to use in the encryption

Return type:

None

classmethod from_numpy_array(array, origin, periods)[source]

Class method to create an instance of account from a numpy array

Parameters:
  • array (ndarray[Any, dtype[object_]]) – the numpy array to use in the initialisation with columns “id” (at most 100 unicode characters) and “risk_score” (np.float64)

  • origin (Bank) – the originating bank

  • periods (int) – number of periods z considered in the protocol.

Return type:

Accounts

Returns:

an Accounts instance

Raises:

ValueError – raised when provided array does not contain the correct columns

get_accounts(account_keys=None)[source]

Retrieves all accounts or a subset if account_keys is provided

Parameters:

account_keys (set[str] | None) – optional set of keys to retreive

Return type:

Union[ValuesView[Account], Generator[Account, None, None]]

Returns:

generator of Accounts that are in account_keys