コード例 #1
0
 def add_tag_coherence(paths):
     if not paths:
         return
     for path in paths:
         path.node.tag_coherence = compute_tag_coherence(
             t.label for t in path.node.tags)
         add_tag_coherence(path.paths)
コード例 #2
0
 def add_tag_coherence(paths):
     if not paths:
         return
     for path in paths:
         path['node']['tag_coherence'] = compute_tag_coherence(
             path['node']['tags'])
         add_tag_coherence(path['paths'])
コード例 #3
0
 def get(self, currency, address):
     """
     Returns the associated entity for a given address
     """
     check_inputs(address=address, currency=currency)  # abort if fails
     entity = addressesDAO.get_address_entity(currency, address)
     if entity:
         entity['tags'] = entitiesDAO.list_entity_tags(currency,
                                                       entity['entity'])
         entity['tag_coherence'] = compute_tag_coherence(entity['tags'])
         return entity
     abort(404, "Address {} not found in currency {}".format(address,
                                                             currency))
コード例 #4
0
 def get(self, currency, entity):
     """
     Returns details and optionally tags of a specific entity
     """
     check_inputs(currency=currency, entity=entity)
     entity_stats = entitiesDAO.get_entity(currency, entity)
     if entity_stats:
         entity_stats['tags'] = entitiesDAO.\
             list_entity_tags(currency, entity_stats['entity'])
         entity_stats['tag_coherence'] = compute_tag_coherence(
             entity_stats['tags'])
         return entity_stats
     abort(404,
           "Entity {} not found in currency {}".format(entity, currency))
コード例 #5
0
def get_entity_with_tags(currency, entity):
    result = get_entity(currency, entity)
    tags = list_entity_tags(currency, result.entity)
    return EntityWithTags(entity=result.entity,
                          first_tx=result.first_tx,
                          last_tx=result.last_tx,
                          no_addresses=result.no_addresses,
                          no_incoming_txs=result.no_incoming_txs,
                          no_outgoing_txs=result.no_outgoing_txs,
                          total_received=result.total_received,
                          total_spent=result.total_spent,
                          in_degree=result.in_degree,
                          out_degree=result.out_degree,
                          balance=result.balance,
                          tags=tags,
                          tag_coherence=compute_tag_coherence(tag.label
                                                              for tag in tags))
コード例 #6
0
def test_compute_tag_coherence():
    tags = []
    assert compute_tag_coherence(tags) is None

    def to_tags(labels):
        return [{'label': label} for label in labels]

    tags = to_tags(['foo'])
    assert compute_tag_coherence(tags) == 1

    tags = to_tags(['foo', 'foo'])
    assert compute_tag_coherence(tags) == 1

    tags = to_tags(['foo', 'foo', 'foo'])
    assert compute_tag_coherence(tags) == 1

    tags = to_tags(['foo', 'bar'])
    assert compute_tag_coherence(tags) == 0

    tags = to_tags(['foo', 'bar', '42'])
    assert compute_tag_coherence(tags) == 0

    tags = to_tags(['foo', 'foobar'])
    assert round(compute_tag_coherence(tags), 3) == 0.667

    tags = to_tags(['tide', 'diet'])
    assert round(compute_tag_coherence(tags), 3) == 0.375

    tags = to_tags(['foo', 'foo', 'bar'])
    assert compute_tag_coherence(tags) == 0.5

    tags = to_tags(['foo', 'foo', 'foo', 'bar'])
    assert compute_tag_coherence(tags) == 0.75

    tags = to_tags(['foo', 'foo', 'foo', 'foo', 'bar'])
    assert round(compute_tag_coherence(tags), 3) == 0.857

    tags = to_tags(['tide', 'tide', 'diet'])
    assert round(compute_tag_coherence(tags), 3) == 0.688