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
def get_data_list(time_step=60, just_count=True, limit=False): """Returns dictionary: Keys: Time Steps Values: #Tweets in TimeStep""" tweets = bf.query_mongo_get_list(bf.all_tweets) flood_days = {} for tweet in tweets: tweet["created_at"] -= datetime.timedelta(hours=6) # Adjusting for TimeZone this_hour = f.roundTime(tweet["created_at"], roundTo=time_step) if flood_days.has_key(this_hour): flood_days[this_hour].append(tweet) else: flood_days[this_hour] = [tweet] if just_count: for i in flood_days.keys(): flood_days[i] = len(flood_days[i]) return flood_days else: return flood_days