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();
def bookmark_website_detail(request): start_time = request.GET.get('start_time', c.MIN_TIME) end_time = request.GET.get('end_time', c.MAX_TIME) limit = request.GET.get('size', '100') limit = int(limit if limit else 100) if start_time == 'NaN-aN-aN aN:aN:aN': start_time = c.MIN_TIME if end_time == 'NaN-aN-aN aN:aN:aN': end_time = c.MAX_TIME data = get_bookmark_website_detail(start_time, end_time, limit=limit) s = { 'data': data } t = loader.get_template('statistics/bookmark_website_detail_table.html') response = HttpResponse(t.render(Context({'s':s}))) # 缓存一天 now = datetime.datetime.now() expire = now + datetime.timedelta(days=1) response['Expires'] = expire.strftime('%a, %d %b %Y 01:00:00 %Z') return response
def bookmark_website_detail(request): start_time = request.GET.get("start_time", c.MIN_TIME) end_time = request.GET.get("end_time", c.MAX_TIME) limit = request.GET.get("size", "100") limit = int(limit if limit else 100) if start_time == "NaN-aN-aN aN:aN:aN": start_time = c.MIN_TIME if end_time == "NaN-aN-aN aN:aN:aN": end_time = c.MAX_TIME data = get_bookmark_website_detail(start_time, end_time, limit=limit) s = {"data": data} t = loader.get_template("statistics/bookmark_website_detail_table.html") response = HttpResponse(t.render(Context({"s": s}))) # 缓存一天 now = datetime.datetime.now() expire = now + datetime.timedelta(days=1) response["Expires"] = expire.strftime("%a, %d %b %Y 01:00:00 %Z") return response