Пример #1
0
def schedule_report_statistics(self):
    """
    定时任务
    :param self:
    :return:
    """
    logger.info(
        '[SCHEDULE_START] ------ schedule_report_statistics(%s) -----' % self.request.id)
    task_set = RedisCache.smembers(KEY_CACHE_REPORT_ECHARTS_CONDITION)
    for task in task_set:
        try:
            if isinstance(task, bytes):
                task = task.decode('utf-8')
            task_name, cond_json = task.split('%')
            eval(task_name).delay(**json.loads(cond_json))
            logger.info('%s has start.' % task_name)
        except Exception:
            logger.error('[SCHEDULE_ERROR] request_id: %s, task_str: %s, \ntraceback: %s' % (
                self.request.id, task, traceback.format_exc()))

    logger.info(
        '[SCHEDULE_END] ----- schedule_report_statistics(%s) -----' % self.request.id)
Пример #2
0
 async def post(self):
     r_dict = {'code': 0}
     try:
         pageNum = int(self.get_i_argument('pageNum', 1))
         member_cid = self.get_i_argument('member_cid', None)
         if not member_cid:
             r_dict['code'] = 1001
             return r_dict
         if pageNum == 1:
             exclude_list = []
             RedisCache.delete('%s_film_recommend' % member_cid)
         else:
             exclude_list = RedisCache.smembers('%s_film_recommend' %
                                                member_cid)
             if isinstance(exclude_list, (list, set)):
                 exclude_list = list(exclude_list)
         size = int(self.get_i_argument('size', 10))
         filter_dict = {
             'db_mark': {
                 '$ne': ''
             },
             'release_time': {
                 '$ne': ''
             },
             'oid': {
                 '$nin': exclude_list
             }
         }
         match = MatchStage(filter_dict)
         sample = SampleStage(size)
         films = await Films.aggregate([match, sample]).to_list(None)
         new_films = []
         id_list = []
         for film in films:
             id_list.append(str(film.id))
             new_films.append({
                 'id':
                 str(film.id),
                 'name':
                 film.name,
                 'pic_url':
                 film.pic_url,
                 'db_mark':
                 film.db_mark,
                 'actor':
                 film.actor,
                 'label':
                 api_utils.get_show_source_label(film),
                 'source_nums':
                 len(film.download),
                 'release_time':
                 film.release_time.strftime('%Y-%m-%d'),
                 'articulation':
                 api_utils.get_show_source_articulation(film),
                 'recommend_info':
                 film.recommend_info
                 if film.recommend_info else '这部神片值得一看。',
                 's_type':
                 'film',
                 'stage_photo': [k['img_url'] for k in film.stage_photo
                                 ][0:4] if film.stage_photo else []
             })
         r_dict['films'] = new_films
         if id_list:
             RedisCache.sadd('%s_film_recommend' % member_cid, id_list)
         r_dict['code'] = 1000
         print('recommend')
         print(r_dict)
     except Exception:
         logger.error(traceback.format_exc())
     return r_dict
Пример #3
0
                                    'title': province.title.replace('省', '').replace('市', ''),
                                    'correct': 0,
                                    'total': 0
                                }
                            t_province_dict[province.post_code]['correct'] += correct
                            t_province_dict[province.post_code]['total'] += total
                            t_province_dict['data'] = round(t_province_dict[province.post_code]['correct'] /
                                                            t_province_dict[province.post_code][
                                                                'total'] * 100 if
                                                            t_province_dict[province.post_code][
                                                                'total'] > 0 else 0, 2)

                            if t_province_dict[province.post_code].get('city_list') is None:
                                t_province_dict[province.post_code]['city_list'] = []
                            t_province_dict[province.post_code]['city_list'].append({
                                'code': city_stat.id,
                                'title': city.title,
                                'correct': correct,
                                'total': total,
                                'data': round(correct / total * 100 if total > 0 else 0, 2)
                            })
            except StopIteration:
                break

        if t_province_dict:
            province_dict.update(t_province_dict)


if __name__ == '__main__':
    print(RedisCache.smembers(KEY_CACHE_REPORT_ECHARTS_CONDITION))