FabLabKasse.cashPayment.server.helpers package


FabLabKasse.cashPayment.server.helpers.banknote_stack_helper module

helper for stack-based banknote payout systems. see BanknoteStackHelper

class FabLabKasse.cashPayment.server.helpers.banknote_stack_helper.BanknoteStackHelper(accepted_rest)[source]

Bases: object

helper class for stack-based banknote payout systems. Such a system has a stack of banknotes from which the top one can be

  • either paid out to the client (action “payout”)
  • or be irrevocably put away into a cashbox (action “stack”), from where it cannot be retrieved again for payout.

From the programmer’s point of view, this stack is a list of banknotes, from which only the last one (stack.pop()) can be accessed.

This class makes the relevant decisions whether to pay out or stack away the current note. It also offers a matching implementation for FabLabKasse.cashPayment.server.CashServer.getCanPayout()

Parameters:accepted_rest – see FabLabKasse.cashPayment.server.cashServer.CashServer.getCanPayout()

implementation for CashServer.getCanPayout()

get_next_payout_action(payout_stack, requested_payout)[source]

which action should be taken next? (see the documentation for BanknoteStackHelper for more context information)

class FabLabKasse.cashPayment.server.helpers.banknote_stack_helper.BanknoteStackHelperTest(methodName='runTest')[source]

Bases: unittest.case.TestCase

Tests the banknote stack helper class


unittest: calls several integrated functions of banknote stack helper as test with several random numbers

class FabLabKasse.cashPayment.server.helpers.banknote_stack_helper.BanknoteStackHelperTester(accepted_rest)[source]

Bases: FabLabKasse.cashPayment.server.helpers.banknote_stack_helper.BanknoteStackHelper

unittest methods for BanknoteStackHelper

classmethod get_random_payout_parameters(random_generator, payout_stack=None, requested_payout=None)[source]

determine parameters for payout_stack and requested_payout

Parameters:random_generator (random.Random) – RNG instance for calculating pseudorandom test parameters

test one random set of parameters for BanknoteStackHelper.can_payout(), BanknoteStackHelper.get_next_payout_action()

Parameters:random_generator (random.Random) – RNG instance for calculating pseudorandom test parameters
Return type:None
Raise:AssertionError if the test failed

test one random set of parameters for BanknoteStackHelper._forced_stacking_is_helpful()

Parameters:random_generator (random.Random) – RNG instance for calculating pseudorandom test parameters
Return type:None
Raise:AssertionError if the test failed

FabLabKasse.cashPayment.server.helpers.coin_payout_helper module

helper functions for multi-tube coin dispensers

FabLabKasse.cashPayment.server.helpers.coin_payout_helper.get_possible_payout(coins, max_number_of_coins=15)[source]

get possible amount of payout and remaining rest

This implementation returns a lower bound. This means that the theoretical maximum possible amount can be higher (and will be often).

  • coins (list[(int, int)]) – list of tuples (value, count), sorted descending by value. The function still works if a value occurs twice (e.g. if you have a dispenser with two separate tubes for 1€ coins).
  • max_number_of_coins (int) –

    approximate upper limit for the number of coins - this limits the reporting of the maximum possible amount of payout, so that a device won’t say it is able to pay out 50€, if that is only possible with 500x 0,10€ coins.

    Please note that if you limit this too much, the user will be warned that there is not enough change money. Some amount is necessary, especially in cooperation with other devices (e.g. banknotes + coins).


as defined by FabLabKasse.cashPayment.server.getCanPayout()

FabLabKasse.cashPayment.server.helpers.test_coin_payout_helper module

tests for coin_payout_helper

class FabLabKasse.cashPayment.server.helpers.test_coin_payout_helper.CoinPayoutHelperTestcase(methodName='runTest')[source]

Bases: unittest.case.TestCase

Tests for coin_payout_helper

test_get_possible_payout(coins=HypothesisProvided(value=st_coins()), requested_fraction=HypothesisProvided(value=floats(min_value=0, max_value=1)), coin_limit_fraction=HypothesisProvided(value=floats(min_value=0, max_value=1)))[source]

test coin_payout_helper.get_possible_payout() for a given state of available coins

FabLabKasse.cashPayment.server.helpers.test_coin_payout_helper.simulate_payout(coins, requested)[source]

get payout amount for a very simple simulated payout strategy (‘greedy strategy’, just pay out largest coins first, without ‘coin splitting’ to get rid of smaller ones)

  • coins (list[(int, int)]) – see coin_payout_helper.get_possible_payout()
  • requested (int) – requested amount

Module contents