Esempio n. 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
Esempio n. 2
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