conversation.py 文件源码

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

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

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

        Returns:
            month_to_message_statistic: A dict mapping a string of the form
                'YYYY-MM' representing a month between the month of the first
                message and the month of the last message to the sum of the
                values of message_statistic over all messages in self.messages
                from that month.
        """
        start_dt = self.messages[0].timestamp
        end_dt = self.messages[-1].timestamp
        start_date_month_start = datetime(start_dt.year, start_dt.month, 1)
        end_date_month_start = datetime(end_dt.year, end_dt.month, 1)
        dt_month_range = rrule(MONTHLY, dtstart=start_date_month_start,
                               until=end_date_month_start)
        month_range = [dt.date() for dt in dt_month_range]
        month_to_message_statistic = {dt.strftime(self.MONTH_FORMAT): 0 for dt in month_range}
        for message in self.messages:
            month_str = message.timestamp.strftime(self.MONTH_FORMAT)
            month_to_message_statistic[month_str] += message_statistic(message)
        return month_to_message_statistic
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号