示例#1
0
def day_report_job(now=None):
    '''day_report created at 23:58:00'''
    
    # 今天
    if not now:
        now = datetime.datetime.now()
    
    today_start = now.replace(hour=0, minute=0, second=0, microsecond=0)
    today_end = now.replace(hour=23, minute=59, second=59, microsecond=0)
    
    user = get_userdata_for_day_report(today_start, today_end);
    bookmark = get_bookmarkdata_for_day_report(today_start, today_end);
    
    bookmark_count = {}
    bookmark_count['percent'], bookmark_count['data'] = get_bookmark_percent_raw_data(today_start, today_end, limit=20)
    bookmark_website = {}
    bookmark_website['data'] = get_bookmark_website(today_start.strftime('%Y-%m-%d %H:%M:%S'), today_end.strftime('%Y-%m-%d %H:%M:%S'), limit=20)
    
    jsondata = {}
    jsondata['user'] = user
    jsondata['bookmark'] = bookmark
    jsondata['bookmark_website'] = bookmark_website
    jsondata['bookmark_count'] = bookmark_count
    
    day_report = Report(type='day', time=now, version=c.report_version, jsondata=anyjson.dumps(jsondata))
    day_report.save();
示例#2
0
def week_report_job(today=None):
    '''week_report created at mon 07:00:00'''
    
    if not today:
        today = datetime.date.today()
    # 双重保证, 不是周一就返回
    if today.isoweekday() != 1:
        return
    # 从上周的周一开始 
    last_mon = today - datetime.timedelta(days=7)
    start_time = datetime.datetime(last_mon.year, last_mon.month, last_mon.day)
    start_time = start_time.replace(hour=0, minute=0, second=0, microsecond=0)
    jsondata_array = Report.objects.filter(type='day', time__gte=start_time, time__lt=today).values('jsondata')
    
    new_user = {}
    new_bookmark = {}
    failed_bookmark = {}
    if jsondata_array:
        count = 1
        for jsondata in jsondata_array:
            data = anyjson.loads(jsondata['jsondata'])
            # 本周每天新增用户
            new_user[count] = data['user']['total'] - data['user']['total_yd']
            # 本周每天新增文章
            new_bookmark[count] = data['bookmark']['total'] - data['bookmark']['total_yd']
            # 本周每天失败文章
            try:
                each_failed_bookmark = data['bookmark']['failed']
            except Exception:
                each_failed_bookmark = []

            failed_bookmark[count] = {'count':len(each_failed_bookmark), 'data': each_failed_bookmark}
            count = count + 1
    end_time = start_time + datetime.timedelta(days=6)
    end_time = end_time.replace(hour=23, minute=59, second=59, microsecond=0)
    
    bookmark_website = {}
    bookmark_website['data'] = get_bookmark_website_detail(start_time.strftime('%Y-%m-%d %H:%M:%S'), \
                                                           end_time.strftime('%Y-%m-%d %H:%M:%S'), limit=100, urls_limit=50)

    add_way_and_platform = {}
    add_way_and_platform['data'] = get_week_report_add_way_and_platform(start_time, end_time);
    
    jsondata = {}
    jsondata['new_user'] = new_user
    jsondata['new_bookmark'] = new_bookmark
    jsondata['failed_bookmark'] = failed_bookmark
    jsondata['bookmark_website'] = bookmark_website
    jsondata['add_way_and_platform'] = add_way_and_platform

    week_report = Report(type='week', time=today, version=c.report_version, jsondata=anyjson.dumps(jsondata))
    week_report.save();