How to use hivemind - 10 common examples

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_multiple_questions.py View on Github external
from hivemind.hivemind import HivemindIssue, HivemindOption, HivemindOpinion, HivemindState
from helpers.ipfshelpers import IPFS_API
from helpers.hotwallethelpers import get_address_from_wallet
from helpers.hotwallethelpers import get_private_key_from_wallet
from helpers.messagehelpers import sign_message

print('Starting Spellbook integration test: hivemind with multiple questions')
print('----------------------------------------------\n')


questions = ['Which number is bigger?', 'Which number is smaller?']
description = 'Rank the numbers in ascending or descending order depending on the question.'
option_type = 'String'


hivemind_issue = HivemindIssue()
assert isinstance(hivemind_issue, HivemindIssue)

for question_index, question in enumerate(questions):
    print('question %s: %s' % (question_index, question))

    hivemind_issue.add_question(question=question)
    assert hivemind_issue.questions[question_index] == question

print('description:', description)
hivemind_issue.set_description(description=description)
assert hivemind_issue.description == description

print('option_type:', option_type)
hivemind_issue.set_answer_type(answer_type=option_type)
assert hivemind_issue.answer_type == option_type
github ValyrianTech / BitcoinSpellbook / unittests / test_hivemindopinion.py View on Github external
print(hivemind_option.get())
STRING_OPTION1_HASH = hivemind_option.save()
print(STRING_OPTION1_HASH)

hivemind_option.set('fortytwo')
STRING_OPTION2_HASH = hivemind_option.save()

hivemind_state = HivemindState()
hivemind_state.set_hivemind_issue(issue_hash=STRING_ISSUE_HASH)
hivemind_state.add_option(STRING_OPTION1_HASH)
hivemind_state.add_option(STRING_OPTION2_HASH)

STRING_STATE_HASH = hivemind_state.save()

hivemind_issue = HivemindIssue()
hivemind_issue.add_question(question='Choose a number')
hivemind_issue.set_description(description='Choose a number')
hivemind_issue.answer_type = 'Integer'
hivemind_issue.set_constraints({'min_value': 0, 'max_value': 10})
INTEGER_QUESTION_HASH = hivemind_issue.save()

hivemind_option = HivemindOption()
hivemind_option.set_hivemind_issue(INTEGER_QUESTION_HASH)
hivemind_option.set(8)

INTEGER_OPTION1_HASH = hivemind_option.save()

hivemind_option.set(5)
INTEGER_OPTION2_HASH = hivemind_option.save()

hivemind_option.set(6)
github ValyrianTech / BitcoinSpellbook / unittests / test_hivemindissue.py View on Github external
def test_initialization(self):
        assert isinstance(HivemindIssue(), HivemindIssue)
github ValyrianTech / BitcoinSpellbook / integrationtests / integration_test_hivemind_with_restrictions.py View on Github external
from helpers.hotwallethelpers import get_private_key_from_wallet
from helpers.messagehelpers import sign_message

print('Starting Spellbook integration test: hivemind with restrictions')
print('----------------------------------------------\n')


question = 'Which number is bigger?'
description = 'Rank the numbers from high to low'
option_type = 'String'

print('question:', question)
print('description:', description)
print('option_type:', option_type)

hivemind_issue = HivemindIssue()
assert isinstance(hivemind_issue, HivemindIssue)

hivemind_issue.add_question(question=question)
assert hivemind_issue.questions[0] == question

hivemind_issue.set_description(description=description)
assert hivemind_issue.description == description

hivemind_issue.set_answer_type(answer_type=option_type)
assert hivemind_issue.answer_type == option_type

hivemind_issue.set_tags(tags='mycompanyhash')
assert hivemind_issue.tags == 'mycompanyhash'

restrictions = {'addresses': [get_address_from_wallet(account=0, index=0), get_address_from_wallet(account=0, index=1)],
                'options_per_address': 10}
github ValyrianTech / BitcoinSpellbook / integrationtests / integration_test_hivemind.py View on Github external
print('\n\n###############################')
print('#Hivemind issue               #')
print('###############################')

question0 = 'Which number is bigger?'
question1 = 'Which number is smaller?'
description = 'Rank the numbers from high to low'
answer_type = 'String'

print('question0:', question0)
print('question1:', question1)
print('description:', description)
print('answer_type:', answer_type)

print('Test initialization')
hivemind_issue = HivemindIssue()
assert isinstance(hivemind_issue, HivemindIssue)

print('Test adding main question')
hivemind_issue.add_question(question=question0)
assert hivemind_issue.questions[0] == question0

print('Test adding second question')
hivemind_issue.add_question(question=question1)
assert hivemind_issue.questions[1] == question1

print('Test if an existing question can not be added twice')
hivemind_issue.add_question(question=question0)
assert len(hivemind_issue.questions) == 2

print('Test only a string or unicode can be added as a question')
hivemind_issue.add_question(question=1)
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

hivemind

Decentralized deep learning in PyTorch

MIT
Latest version published 1 year ago

Package Health Score

56 / 100
Full package analysis

Similar packages