def remove_node_by_time(graph: tweet_node, limit_time): start_time = get_first_post_time(graph) end_time = start_time + limit_time q = queue.Queue() q.put(graph) while q.qsize() != 0: node = q.get() children = node.children retweet_children = set(node.retweet_children) reply_children = set(node.reply_children) for child in children.copy(): if child.created_time <= end_time: q.put(child) else: node.children.remove(child) try: retweet_children.remove(child) except KeyError: # Element not found in the list pass try: reply_children.remove(child) except KeyError: # Element not found in the list pass node.retweet_children = list(retweet_children) node.reply_children = list(reply_children) return graph
def get_time_diff_first_post_last_reply(news_graph: tweet_node): first_post_time = get_first_post_time(news_graph) last_reply_time = get_last_reply_by_time(news_graph) if last_reply_time == 0: return 0 else: return last_reply_time - first_post_time
def get_time_diff_first_post_first_reply(news_graph): first_reply_time = get_first_reply_by_time(news_graph) first_post_time = get_first_post_time(news_graph) if first_reply_time == float("inf"): return 0 return first_reply_time - first_post_time
def time_difference_between_first_post_node_with_max_out_degree_macro( prop_graph): max_out_degree_node, max_out_degree = get_max_out_degree_node( prop_graph, RETWEET_EDGE) first_post_time = get_first_post_time(prop_graph) if max_out_degree_node is None: return 0 return max_out_degree_node.created_time - first_post_time
def get_time_diff_first_post_first_retweet(news_graph: tweet_node): first_post_time = get_first_post_time(news_graph) first_retweet_time = get_first_retweet_by_time(news_graph) if first_retweet_time == float("inf"): return 0 return first_retweet_time - first_post_time
def get_time_diff_first_post_last_retweet(news_graph: tweet_node): first_post_time = get_first_post_time(news_graph) last_retweet_time = get_last_retweet_by_time(news_graph) return last_retweet_time - first_post_time