Beispiel #1
0
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
Beispiel #2
0
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
Beispiel #3
0
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
Beispiel #4
0
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
Beispiel #5
0
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