conversation.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:facebook-message-analysis 作者: szheng17 项目源码 文件源码
def get_user_to_damped_n_messages(self, dt_max, alpha):
        """
        Maps each user to the number of messages before a reference datetime, 
        where each message count is exponentially damped by a constant times
        the difference between the reference datetime and the datetime of the
        message.

        Args:
            dt_max: A datetime representing the max datetime of messages
                to consider.
            alpha: A nonnegative float representing the damping factor.

        Returns:
            user_to_damped_n_messages: A dict mapping each user in
                self.users_union to the damped number of messages by that user
                before dt_max. The contribution of a message is a float equal
                to exp(-alpha * t), where t is the difference in days between
                dt_max and the datetime of the message.
        """
        if alpha < 0:
            raise ValueError('Must have alpha >= 0')
        try:
            # Only keep messages with datetimes <= dt_max
            filtered = self.filter_by_datetime(end_dt=dt_max)
        except EmptyConversationError:
            # Map all users to 0 if dt_max occurs before all messages
            return self.get_user_to_message_statistic(lambda x: 0)
        damped_message_count = lambda x: self.exp_damped_day_difference(dt_max, x.timestamp, alpha)
        user_to_damped_n_messages = filtered.get_user_to_message_statistic(damped_message_count)
        return user_to_damped_n_messages
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号