コード例 #1
0
def reciprocity_per_time_step(time_step=60*60):
	"""Plots the reciprocity of all tweets in the UMG for a given time slice."""
	ranges = t.get_range()
	first_tweet = ranges[0]
	last_tweet  = ranges[(len(ranges)-1)]
	start_index = first_tweet
	to_graph = []
	x_vals = []
	while start_index < last_tweet:
		last_index   =  start_index + datetime.timedelta(seconds=time_step)
		x_vals.append(f.roundTime(start_index,60*60))
		print str(start_index)
		tweets = bf.get_tweets_between(start_index, last_index)
		print "Tweets found:", len(tweets), "Making Graph"
		graph = um.user_mentions_graph(tweets)
		reciprocity = f.get_graph_reciprocity(graph)
		to_graph.append(reciprocity)

		start_index += datetime.timedelta(seconds=time_step)

	plt.plot(x_vals,to_graph)
	locs, labels = plt.xticks()
	plt.setp(labels, rotation=90)
	plt.title('Reciprocity by Hour')
	plt.xlabel('Date')
	plt.ylabel('Reciprocity')
	plt.show()

	return to_graph
コード例 #2
0
		this_data = bf.query_mongo_get_list(query, limit=1)
		print this_data['user']['screen_name'],'&', "{0:.4f}".format(bc[node]), '\\\\'
	return bc

if __name__ == '__main__':
	"""First, get only geo_tagged_tweets"""
	geo_tagged_user_mentions = bf.query_mongo_get_list(bf.only_geo_tagged)
	print "Geo_Tagged found:", len(geo_tagged_user_mentions), "Making Graph..."
	umg_geo = user_mentions_graph(geo_tagged_user_mentions)
	print 'Users',len(umg_geo.nodes())
	# connected_components = nx.weakly_connected_component_subgraphs(umg_geo)
	# print "Number of Connected Components:", len(connected_components)
	# for subgraph in connected_components[0:5]:
	# 	print "Component has", len(subgraph.nodes())
	# #f.draw_network_plt(connected_components[1])
	print '\nreciprocity, weighted:',   f.get_graph_reciprocity(umg_geo)
	print 'reciprocity, unweighted:', f.get_graph_reciprocity(umg_geo, weighted=False)
	#print f.reciprocity_by_degree(umg_geo, 'in')

	print "self loops:"
	f.print_top_self_loops(umg_geo, size=10)


	"""geo_tagged_plus: All users who interact with geo_tagged users"""
	geo_tagged_plus = bf.get_all_users_who_interact_with(umg_geo.nodes())
	print "Geo_Tagged_Plus found:", len(geo_tagged_plus)
	umg_geo_plus = user_mentions_graph(geo_tagged_plus)
	print 'Users:',len(umg_geo_plus.nodes())

	f.print_top_self_loops(umg_geo_plus, size=10)
	#print '\nreciprocity, weighted:',   f.get_graph_reciprocity(umg_geo_plus)