conversation.py 文件源码

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

项目:facebook-message-analysis 作者: szheng17 项目源码 文件源码
def damped_n_messages(self, dt_max, alpha):
        """
        Computes the sum of damped message counts before a reference datetime,
        where each damped 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:
            damped_n_messages_total: A float equal to the sum of damped message
                counts before dt_max. The contribution of a message is
                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:
            # dt_max occurs before all messages
            return 0
        damped_message_count = lambda x: self.exp_damped_day_difference(dt_max, x.timestamp, alpha)
        damped_n_messages_total = filtered.sum_conversation_message_statistic(damped_message_count)
        return damped_n_messages_total
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号