def compute( dsconf, community, start, end ): """Compute community reciprocities with 'seconds' resolution.""" c.log( 'Starting' ) reciprocities = collections.defaultdict(float) # Get all messages and replies for 'users' messages = ds.get_messages(dsconf, start, end, community) messages = common.build_msgmap(messages, ds.field('messages','user_id')) replies = common.build_replies(messages, ds.fields('messages')) # Get requested users reciprocities c.log( 'Computing reciprocities ...' ) for (user,user_messages) in messages.iteritems(): # Calculate the sum of reply delays delays_sum = dt.timedelta( 0 ) for reply in replies[user]: if reply[2].total_seconds() >= 0: # Ignore negative delay replies delays_sum += reply[2] # txy component # Calculate reciprocity if not replies[user]: reciprocities[user] = float('inf') else: reciprocities[user] = delays_sum.total_seconds() * 1.0 / \ len( replies[user] ) # Return users reciprocities c.log( 'Finished' ) return reciprocities
def compute( dsconf, community, start, end ): """Compute community out-degrees.""" c.log( 'Starting' ) outdegrees = collections.defaultdict(long) # Get all messages and replies for the community messages = ds.get_messages(dsconf, start, end, community) # Get out-degrees for message in messages: outdegrees[message[ds.field('messages','user_id')]] += 1 # Return the out-degrees c.log( 'Finished' ) return outdegrees
def compute( dsconf, community, start, end ): """Compute community activity.""" c.log( 'Starting' ) activities = collections.defaultdict(float) # Get all messages and replies for the community messages = ds.get_messages(dsconf, start, end, community) messages = common.build_msgmap(messages, ds.field('messages','user_id')) # Get users activities c.log( 'Computing users activity ...' ) for (user,user_messages) in messages.iteritems(): activities[user] = len( user_messages ); # Return users activities c.log( 'Finished' ) return activities
def compute(dsconf, community, start, end): """Compute community in-degrees.""" c.log("Starting") indegrees = collections.defaultdict(long) # Get all messages and replies for the community messages = ds.get_messages(dsconf, start, end, community) messages = common.build_msgmap(messages, ds.field("messages", "id")) # Get in-degrees for (id, message) in messages.iteritems(): if message[0][ds.field("messages", "target_id")] is not None: indegrees[message[0][ds.field("messages", "user_id")]] += 1 # Return the in-degrees c.log("Finished") return indegrees
def compute( dsconf, community, start, end ): """Compute community popularities.""" c.log( 'Starting' ) popularities = collections.defaultdict(float) # Get all messages and replies for the community messages = ds.get_messages(dsconf, start, end, community) messages = common.build_msgmap(messages, ds.field('messages','user_id')) replies = common.build_replies(messages, ds.fields('messages')) # Get requested users popularities c.log( 'Computing users popularities ...' ) for (user,user_messages) in messages.iteritems(): popularities[user] = len( replies[user] ) * 1.0 / \ len( user_messages ) # Return users popularities c.log( 'Finished' ) return popularities
# Test get_user() facility users = ds.get_users( dsconfig ) print 'Got {0} users from datasource.'.format(len(users)) del users # Test get_communities() facility community = None communities = ds.get_communities( dsconfig ) print 'Got {0} community(ies) from datasource.'.format(len(communities)) if len(communities) > 0: community = communities[0][0] del communities # Test get_conversations() facility conversations = ds.get_conversations( dsconfig, community ) print 'Got {0} conversation(s) from datasource for community {1}.' \ .format(len(conversations), community) del conversations # Test get_messages() facility if community is not None: messages = ds.get_messages( dsconfig, start, end, community ) print 'Got {0} messages between {1} and {2} for community {3}.' \ .format(len(messages), start, end, community) del messages else: print 'No comunnities found. Skipping get_counts() test.' # Finished print 'Finished.'