Exemplo n.º 1
0
    def calculate_early_send_time(self):
        if self.friend_df is None:
            self.friend_df = pd.read_csv(self.FRIEND_DETAIL_LIST_FILE_NAME)
        if not self.has_clean_data:
            self.get_useful_info_from_json()
        try:
            day_begin_time = self.mood_data_df['time_stamp'].apply(lambda x: get_standard_time_from_mktime2(x))
            day_time_stamp = self.mood_data_df['time_stamp']
            time_diff = day_time_stamp - day_begin_time
            self.mood_data_df['early_time'] = time_diff
            early_mood_time = self.mood_data_df.loc[self.mood_data_df['early_time'] < 60 * 60 * 5]
            has_cmt = False
            if not early_mood_time.empty:
                early_mood_time2 = early_mood_time.loc[early_mood_time['cmt_total_num'] > 1]
                if not early_mood_time2.empty:
                    early_mood_time = early_mood_time2
                    has_cmt = True

            early_mood_time.sort_values(by='early_time', ascending=False, inplace=True)
            earliest_mood = early_mood_time.head(1)
            self.user_info.early_mood_date = earliest_mood['time'].values[0]
            self.user_info.early_mood_time = int(earliest_mood['early_time'].values[0] // (60 * 60))
            self.user_info.early_mood_content = earliest_mood['content'].values[0]
            if has_cmt:
                early_cmt_df = self.av.clean_cmt_df(early_mood_time)
                cmt_friend = early_cmt_df.head(1)
                self.user_info.early_mood_friend = cmt_friend['comment_name'].values[0]
                self.user_info.early_mood_cmt = cmt_friend['comment_content'].values[0]
            if len(self.user_info.early_mood_content) > 20:
                self.user_info.early_mood_content = self.user_info.early_mood_content[:20] + "..."
        except BaseException as e:
            self.format_error(e, "failed to analysis send mood early time")
Exemplo n.º 2
0
    def calculate_send_time(self):
        """
        计算每条说说的发送时间
        分为以下五种类型:
        0.0点-3点
        1.3-6
        2.6点-9点
        3.9-12
        4.12点-15
        5.15-18
        6.18-21
        7.21-24
        :return:
        """
        if self.friend_df is None:
            self.friend_df = pd.read_csv(self.FRIEND_DETAIL_LIST_FILE_NAME)
        if not self.has_clean_data:
            self.get_useful_info_from_json()
        try:
            day_begin_time = self.mood_data_df['time_stamp'].apply(
                lambda x: get_standard_time_from_mktime2(x))
            day_time_stamp = self.mood_data_df['time_stamp']
            time_diff = day_time_stamp - day_begin_time
            # 3个小时的时间差
            time_step = 60 * 60 * 3
            time_state = time_diff.apply(lambda x: x // time_step)
            time_state_df = pd.DataFrame(time_state)
            time_state_df['count'] = 1

            time_state_df = time_state_df.groupby(
                by='time_stamp').sum().reset_index()
            temp = max(time_state_df['count'].values)
            most_state = time_state_df.loc[time_state_df['count'] == temp,
                                           'time_stamp'].values[0]
            # 判断是否是夜猫子
            is_night = (time_state_df.loc[time_state_df['time_stamp'] == 0,
                                          'count'].values[0] /
                        time_state_df['count'].sum()) > 0.1
            self.mood_data_df['time_state'] = time_state
            self.time_step_df = pd.DataFrame(time_state)
            if self.debug:
                print('send time:', self.mood_data_df.shape)
            self.user_info.most_time_state = most_state
            self.user_info.is_night = int(is_night)
        except BaseException as e:
            self.format_error(e, "Failed to analysis send mood time")
            self.user_info.most_time_state = 0
            self.user_info.is_night = 0