How to use the hivemind.hivemind.HivemindOption function in hivemind

To help you get started, we’ve selected a few hivemind examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ValyrianTech / BitcoinSpellbook / integrationtests / integration_test_hivemind.py View on Github external
print('Change log:')
pprint(hivemind_state.change_log(max_depth=0))

print('Test initial options is an empty list')
assert hivemind_state.options == []


print('\n\n###############################')
print('#Hivemind option              #')
print('###############################')

option_hashes = {}
option_values = ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Eleven']
for i, option_value in enumerate(option_values):
    print('\nadding option %s: %s' % (i+1, option_value))
    option = HivemindOption()
    option.set_hivemind_issue(hivemind_issue_hash=hivemind_issue_hash)
    option.answer_type = answer_type
    option.set(value=option_value)
    option_hashes[option_value] = option.save()
    print('saved with ipfs hash %s' % option.multihash())

    address = get_address_from_wallet(account=0, index=0)
    message = '/ipfs/%s' % option.multihash()
    private_key = get_private_key_from_wallet(account=0, index=0)[address]

    signature = sign_message(message=message, private_key=private_key)

    try:
        # note there is a restriction on the maximum number of options per address: 10
        hivemind_state.add_option(option_hash=option.multihash(), address=address, signature=signature)
        assert hivemind_state.options[i] == option.multihash()
github ValyrianTech / BitcoinSpellbook / integrationtests / integration_test_hivemind_multiple_questions.py View on Github external
print('')

print('')
hivemind_hash = hivemind_issue.save()
print('Hivemind hash:', hivemind_hash)

hivemind_state = HivemindState()
hivemind_state.set_hivemind_issue(issue_hash=hivemind_hash)

assert hivemind_state.options == []

option_hashes = {}
option_values = ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten']
for option_value in option_values:
    print('adding option %s' % option_value)
    option = HivemindOption()
    option.set_hivemind_issue(hivemind_issue_hash=hivemind_hash)
    option.answer_type = option_type
    option.set(value=option_value)
    option_hashes[option_value] = option.save()
    print('saved with ipfs hash %s' % option.multihash())

    hivemind_state.add_option(option_hash=option.multihash())
    print('')

print('All options:')
print(hivemind_state.options)
assert len(hivemind_state.options) == len(option_values)

print('')
hivemind_state_hash = hivemind_state.save()
print('Hivemind state hash:', hivemind_state_hash)
github ValyrianTech / BitcoinSpellbook / unittests / test_hivemindoption.py View on Github external
def test_initializing_with_option_hash(self):
        option = HivemindOption()
        print(option.__dict__)
        option.set_hivemind_issue(hivemind_issue_hash=STRING_QUESTION_HASH)
        option.set('42')
        print(option.__dict__)

        option_hash = option.save()
        print(option_hash)

        option2 = HivemindOption(multihash=option_hash)
        assert option2.hivemind_issue_hash == option.hivemind_issue_hash
        assert option2.value == option.value
        assert option2.answer_type == option.answer_type
github ValyrianTech / BitcoinSpellbook / unittests / test_hivemindoption.py View on Github external
def test_initializing_with_option_hash(self):
        option = HivemindOption()
        print(option.__dict__)
        option.set_hivemind_issue(hivemind_issue_hash=STRING_QUESTION_HASH)
        option.set('42')
        print(option.__dict__)

        option_hash = option.save()
        print(option_hash)

        option2 = HivemindOption(multihash=option_hash)
        assert option2.hivemind_issue_hash == option.hivemind_issue_hash
        assert option2.value == option.value
        assert option2.answer_type == option.answer_type
github ValyrianTech / BitcoinSpellbook / unittests / test_hivemindoption.py View on Github external
def test_is_valid_integer_option(self, value, expected):
        option = HivemindOption()
        option.set_hivemind_issue(hivemind_issue_hash=INTEGER_QUESTION_HASH)
        option.value = value
        assert option.is_valid_integer_option() is expected
github ValyrianTech / BitcoinSpellbook / unittests / test_hivemindopinion.py View on Github external
print('\nAuto_completing using opinion as MAX value')
        opinion.auto_complete = 'MAX'
        for option_hash in opinion.ranking():
            print(HivemindOption(multihash=option_hash).value, option_hash)
        assert opinion.ranking() == [INTEGER_OPTION5_HASH, INTEGER_OPTION2_HASH, INTEGER_OPTION3_HASH]

        print('\nAuto_completing using opinion as MIN value')
        opinion.auto_complete = 'MIN'
        for option_hash in opinion.ranking():
            print(HivemindOption(multihash=option_hash).value, option_hash)
        assert opinion.ranking() == [INTEGER_OPTION3_HASH, INTEGER_OPTION4_HASH, INTEGER_OPTION1_HASH]

        print('\nAuto_completing using opinion as CLOSEST value if 2 other options are equally close, the order of adding them to the hivemind is used')
        opinion.auto_complete = 'CLOSEST'
        for option_hash in opinion.ranking():
            print(HivemindOption(multihash=option_hash).value, option_hash)
        assert opinion.ranking() == [INTEGER_OPTION3_HASH, INTEGER_OPTION2_HASH, INTEGER_OPTION4_HASH, INTEGER_OPTION1_HASH, INTEGER_OPTION5_HASH]

        print('\nAuto_completing using opinion as CLOSEST value with preference for higher values if equally close')
        opinion.auto_complete = 'CLOSEST_HIGH'
        for option_hash in opinion.ranking():
            print(HivemindOption(multihash=option_hash).value, option_hash)
        assert opinion.ranking() == [INTEGER_OPTION3_HASH, INTEGER_OPTION4_HASH, INTEGER_OPTION2_HASH, INTEGER_OPTION1_HASH, INTEGER_OPTION5_HASH]

        print('\nAuto_completing using opinion as CLOSEST value with preference for lower values if equally close')
        opinion.auto_complete = 'CLOSEST_LOW'
        for option_hash in opinion.ranking():
            print(HivemindOption(multihash=option_hash).value, option_hash)
        assert opinion.ranking() == [INTEGER_OPTION3_HASH, INTEGER_OPTION2_HASH, INTEGER_OPTION4_HASH, INTEGER_OPTION5_HASH, INTEGER_OPTION1_HASH]
github ValyrianTech / BitcoinSpellbook / unittests / test_hivemindoption.py View on Github external
def test_is_valid_float_option(self, value, expected):
        option = HivemindOption()
        option.set_hivemind_issue(hivemind_issue_hash=FLOAT_QUESTION_HASH)
        option.value = value
        assert option.is_valid_float_option() is expected
github ValyrianTech / BitcoinSpellbook / unittests / test_hivemindoption.py View on Github external
def test_initialization(self):
        option = HivemindOption()
        assert isinstance(option, HivemindOption)
github ValyrianTech / BitcoinSpellbook / hivemind / hivemind.py View on Github external
def options_info(self):
        """
        Get detailed information about the options as a formatted string

        :return: A string containing all information about the options
        """
        ret = "Options"
        ret += "\n======="
        for i, option_hash in enumerate(self.options):
            ret += '\nOption %s:' % (i + 1)
            option = HivemindOption(multihash=option_hash)
            ret += '\n' + option.info()
            ret += '\n'

        return ret
github ValyrianTech / BitcoinSpellbook / hivemind / hivemind.py View on Github external
def get_options(self, question_index=0):
        """
        Get the list of Options as sorted by the hivemind

        :return: A list of Option objects sorted by highest score
        """
        return [HivemindOption(multihash=option[0]) for option in sorted(self.results[question_index].items(), key=lambda x: x[1]['score'], reverse=True)]

hivemind

Decentralized deep learning in PyTorch

MIT
Latest version published 1 year ago

Package Health Score

62 / 100
Full package analysis

Similar packages