conversation.py 文件源码

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

项目:facebook-message-analysis 作者: szheng17 项目源码 文件源码
def get_date_to_message_statistic(self, message_statistic):
        """
        Maps each date between the date of the first message and the date of
        the last message, inclusive, to the sum of the values of a message
        statistic over all messages from that date. 

        Args:
            message_statistic: A function mapping a Message object to an int or
                a float.

        Returns:
            date_to_message_statistic: A dict mapping a date object between the
                date of the first message and the date of the last message to
                the sum of the values of message_statistic over all messages in
                self.messages from that date.
        """
        start_date = self.messages[0].timestamp.date()
        end_date = self.messages[-1].timestamp.date()
        date_range = [dt.date() for dt in rrule(DAILY, dtstart=start_date, until=end_date)]
        date_to_message_statistic = {d: 0 for d in date_range}
        for message in self.messages:
            date_to_message_statistic[message.timestamp.date()] += message_statistic(message)
        return date_to_message_statistic
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号