Пример #1
0
def analyze_satoshi_dice():
    """ 
    Analyzes the snippet of the bitcoin network around the time that
    SatoshiDice was announced. There is a hard date for its launch.
    """
    g_before = graphgen.get_graph_slice(_START_SATOSHI_DICE,
                                        _LAUNCH_SATOSHI_DICE)
    g_after = graphgen.get_graph_slice(_START_SATOSHI_DICE, _END_SATOSHI_DICE)
    before_lcc = graphtools.get_lcc_from_graph(g_before)
    after_lcc = graphtools.get_lcc_from_graph(g_after)
    print len(before_lcc), len(after_lcc)
    '''
    before_in = g_before.in_degree()
    before_in_values = sorted(set(before_in.values()))
    before_in_hist = [before_in.values().count(x)/float(len(g_before.nodes())) for x in before_in_values]
    after_in = g_after.in_degree()
    after_in_values = sorted(set(after_in.values()))
    after_in_hist = [after_in.values().count(x)/float(len(g_after.nodes())) for x in after_in_values]

    plt.loglog(before_in_values, before_in_hist, 'bo', label='In-degree before SatoshiDICE announced')
    plt.loglog(after_in_values, after_in_hist, 'ro', label='In-degree after SatoshiDICE announced')
    plt.legend(loc=1)
    plt.xlabel('Degree')
    plt.ylabel('Fraction of nodes')
    plt.title('In-degree 1 week before and after SatoshiDICE announced')
    plt.show()
    
    before_out = g_before.out_degree()
    before_out_values = sorted(set(before_out.values()))
    before_out_hist = [before_out.values().count(x)/float(len(g_before.nodes())) for x in before_out_values]
    after_out = g_after.out_degree()
    after_out_values = sorted(set(after_out.values()))
    after_out_hist = [after_out.values().count(x)/float(len(g_after.nodes())) for x in after_out_values]

    plt.loglog(before_out_values, before_out_hist, 'bo', label='Out-degree before SatoshiDICE announced')
    plt.loglog(after_out_values, after_out_hist, 'ro', label='Out-degree after SatoshiDICE announced')
    plt.legend(loc=1)
    plt.xlabel('Degree')
    plt.ylabel('Fraction of nodes')
    plt.title('Out-degree 1 week before and after SatoshiDICE announced')
    plt.show()
    '''

    #Can't use k-core with MultiDiGraph
    '''
    g_before.remove_edges_from(g_before.selfloop_edges())
    g_after.remove_edges_from(g_after.selfloop_edges())
    print len(graphtools.get_k_core_from_graph(g_before).nodes())
    print len(graphtools.get_k_core_from_graph(g_after).nodes())
    '''

    #before_node_max_in = graphtools.get_node_max_in_degree(g_before)
    #after_node_max_in = graphtools.get_node_max_in_degree(g_after)
    #print before_node_max_in, after_node_max_in
    #print sorted(g_before.in_degree().iteritems(), key=operator.itemgetter(1))
    #print sorted(g_after.in_degree().iteritems(), key=operator.itemgetter(1))
    #print len(g_after.edges('25', data=True))
    #print nx.get_edge_attributes(g_after, 'transaction_key')
    #print g_after.in_degree(after_node_max_in)
    #new_nodes = set(g_after.in_degree())-set(g_before.in_degree())
    #print len(new_nodes)
    #new_nodes_degrees = {k: g_after.in_degree()[k] for k in new_nodes}
    #print sorted(new_nodes_degrees.iteritems(), key=operator.itemgetter(1))

    time_period = graphgen._days[graphgen._days.index(_START_SATOSHI_DICE /
                                                      graphgen._HMS):graphgen.
                                 _days.index(_END_SATOSHI_DICE /
                                             graphgen._HMS)]
    transactions_per_day = []
    for day in time_period:
        daystart = graphtools.string_to_datetime(str(day) + '000000')
        dayend = graphtools.string_to_datetime(str(day) + '235959')
        transactions = []
        for n, nbrs in g_after.adjacency_iter():
            for nbr, edict in nbrs.items():
                for eattr in edict.values():
                    timestamp = graphtools.string_to_datetime(eattr['date'])
                    if (timestamp >= daystart and timestamp <= dayend):
                        transactions.append(1)
        transactions_per_day.append(len(transactions))
    print time_period
    print transactions_per_day
    time_period = [
        graphtools.string_to_datetime(str(time)) for time in time_period
    ]
    dates = matplotlib.dates.date2num(time_period)
    plt.plot(time_period, transactions_per_day, 'b-')
    plt.xlabel('Date')
    plt.ylabel('Number of transactions')
    plt.title(
        'Number of transactions 1 week before and after SatoshiDICE announced')
    plt.show()
Пример #2
0
lccs = []
largest_scc = []

for start, end in slices:
    g = cv_from_btc(start * _HMS, end * _HMS)
    if len(g) == 0:
        continue
    stamp = str(start) + '_' + str(end)
    
    tags_over_time.user_transaction_frequency(g, 'model_' + stamp)
    tags_over_time.user_buy_frequency(g, 'model_' + stamp)
    tags_over_time.user_sell_frequency(g, 'model_' + stamp)
  
    undir_g = nx.Graph(g.copy())
    avg_clust.append(nx.average_clustering(undir_g))
    lccs.append(len(graphtools.get_lcc_from_graph(g)))
    largest_scc.append(len(graphtools.get_sccs_from_graph(g)[0]))
    
    dates.append(start) # hack for now to save time...
    
    print 'finished %s tag over time' % i
    i += 1

utils.save_lists(dates, avg_clust, stamp='model_avg_clust')
utils.save_lists(dates, lccs, stamp='model_lccs')
utils.save_lists(dates, largest_scc, stamp='model_largest_scc')



'''
_HMS = graphgen._HMS
Пример #3
0
def analyze_satoshi_dice():
    """ 
    Analyzes the snippet of the bitcoin network around the time that
    SatoshiDice was announced. There is a hard date for its launch.
    """
    g_before = graphgen.get_graph_slice(_START_SATOSHI_DICE, _LAUNCH_SATOSHI_DICE)
    g_after = graphgen.get_graph_slice(_START_SATOSHI_DICE, _END_SATOSHI_DICE)
    before_lcc = graphtools.get_lcc_from_graph(g_before)
    after_lcc = graphtools.get_lcc_from_graph(g_after)
    print len(before_lcc), len(after_lcc)
    '''
    before_in = g_before.in_degree()
    before_in_values = sorted(set(before_in.values()))
    before_in_hist = [before_in.values().count(x)/float(len(g_before.nodes())) for x in before_in_values]
    after_in = g_after.in_degree()
    after_in_values = sorted(set(after_in.values()))
    after_in_hist = [after_in.values().count(x)/float(len(g_after.nodes())) for x in after_in_values]

    plt.loglog(before_in_values, before_in_hist, 'bo', label='In-degree before SatoshiDICE announced')
    plt.loglog(after_in_values, after_in_hist, 'ro', label='In-degree after SatoshiDICE announced')
    plt.legend(loc=1)
    plt.xlabel('Degree')
    plt.ylabel('Fraction of nodes')
    plt.title('In-degree 1 week before and after SatoshiDICE announced')
    plt.show()
    
    before_out = g_before.out_degree()
    before_out_values = sorted(set(before_out.values()))
    before_out_hist = [before_out.values().count(x)/float(len(g_before.nodes())) for x in before_out_values]
    after_out = g_after.out_degree()
    after_out_values = sorted(set(after_out.values()))
    after_out_hist = [after_out.values().count(x)/float(len(g_after.nodes())) for x in after_out_values]

    plt.loglog(before_out_values, before_out_hist, 'bo', label='Out-degree before SatoshiDICE announced')
    plt.loglog(after_out_values, after_out_hist, 'ro', label='Out-degree after SatoshiDICE announced')
    plt.legend(loc=1)
    plt.xlabel('Degree')
    plt.ylabel('Fraction of nodes')
    plt.title('Out-degree 1 week before and after SatoshiDICE announced')
    plt.show()
    '''

    #Can't use k-core with MultiDiGraph
    '''
    g_before.remove_edges_from(g_before.selfloop_edges())
    g_after.remove_edges_from(g_after.selfloop_edges())
    print len(graphtools.get_k_core_from_graph(g_before).nodes())
    print len(graphtools.get_k_core_from_graph(g_after).nodes())
    '''

    #before_node_max_in = graphtools.get_node_max_in_degree(g_before)
    #after_node_max_in = graphtools.get_node_max_in_degree(g_after)
    #print before_node_max_in, after_node_max_in
    #print sorted(g_before.in_degree().iteritems(), key=operator.itemgetter(1))
    #print sorted(g_after.in_degree().iteritems(), key=operator.itemgetter(1))
    #print len(g_after.edges('25', data=True))
    #print nx.get_edge_attributes(g_after, 'transaction_key')
    #print g_after.in_degree(after_node_max_in)
    #new_nodes = set(g_after.in_degree())-set(g_before.in_degree())
    #print len(new_nodes)
    #new_nodes_degrees = {k: g_after.in_degree()[k] for k in new_nodes}
    #print sorted(new_nodes_degrees.iteritems(), key=operator.itemgetter(1))

    time_period = graphgen._days[graphgen._days.index(_START_SATOSHI_DICE/graphgen._HMS):graphgen._days.index(_END_SATOSHI_DICE/graphgen._HMS)]
    transactions_per_day = []
    for day in time_period:
        daystart = graphtools.string_to_datetime(str(day) + '000000')
        dayend = graphtools.string_to_datetime(str(day) + '235959')
        transactions = []
        for n, nbrs in g_after.adjacency_iter():
            for nbr, edict in nbrs.items():
                for eattr in edict.values():
                    timestamp = graphtools.string_to_datetime(eattr['date'])
                    if (timestamp >= daystart and timestamp <= dayend):
                        transactions.append(1)
        transactions_per_day.append(len(transactions))
    print time_period
    print transactions_per_day
    time_period = [graphtools.string_to_datetime(str(time)) for time in time_period]
    dates = matplotlib.dates.date2num(time_period)
    plt.plot(time_period, transactions_per_day, 'b-')
    plt.xlabel('Date')
    plt.ylabel('Number of transactions')
    plt.title('Number of transactions 1 week before and after SatoshiDICE announced')
    plt.show()