def _extract_url_params(request): params = dict() start_time = request.GET.get('start_time', '') end_time = request.GET.get('end_time', '') if start_time and end_time: params['start_time'] = start_time params['end_time'] = end_time else: #默认显示最近7天的日期 end_date = dateutil.get_today() start_date = dateutil.get_previous_date(end_date, 6) #获取7天前日期 params['start_time'] = start_date + ' 00:00:00' params['end_time'] = end_date + ' 23:59:59' status_str = request.GET.get('order_status', '') if status_str: params['order_status'] = status_str params['repeat_buy'] = int(request.GET.get('repeat_buy', '-1')) params['buyer_source'] = int(request.GET.get('buyer_source', '-1')) discount_type = request.GET.get('discount_type', '') if discount_type: params['discount_type'] = discount_type return params
def get(request): """ 显示经营概况的页面 """ #默认显示最近7天的日期 end_date = dateutil.get_today() start_date = dateutil.get_previous_date(end_date, 6) #获取7天前日期 webapp_id = request.user_profile.webapp_id (today_value, yesterday_value, increase_sign, increase_percent) = get_latest_brand_value(webapp_id) c = RequestContext( request, { 'first_nav_name': FIRST_NAV, 'app_name': 'stats', 'second_navs': export.get_stats_second_navs(request), 'second_nav_name': export.STATS_MANAGEMENT_SECOND_NAV, 'start_date': start_date, 'end_date': end_date, #'is_valid_for_bv': is_valid_for_brandvalue(request.user.username), # TODO: 需要清除html中的代码 'is_valid_for_bv': True, # 全部开启 # 当日微品牌价值数据 'brand_value': format(today_value, ','), 'value_sign': increase_sign, 'increase_percent': increase_percent, # 相比昨天增长(下降)百分比 'bv_diff': abs(today_value - yesterday_value), # 品牌价值差值 }) return render_to_response('manage/manage_summary.html', c)
def _count_visit_yestoday_daily_pv_uv(webapp_id): # 已无用 yestoday = dateutil.get_previous_date('today', 1) yestoday_records = PageVisitDailyStatistics.objects.filter( webapp_id=webapp_id, data_date=yestoday) if yestoday_records.count() > 0: return #对昨天的pv和uv进行统计 count_visit_daily_pv_uv(webapp_id, yestoday)
def get_date_range(request): """ 获取时间范围,如果没有start_date和end_date参数,则默认显示最近7天的日期 """ start_date = request.GET.get('start_date', None) end_date = request.GET.get('end_date', None) if not end_date: #默认显示最近7天的日期 end_date = dateutil.get_today() if not start_date: start_date = dateutil.get_previous_date(end_date, 6) #获取7天前日期 return get_date_range_for_data(request, start_date, end_date)
def get(request): """ 显示营销活动分析的页面 """ #默认显示最近7天的日期 end_date = dateutil.get_today() start_date = dateutil.get_previous_date(end_date, 6) #获取7天前日期 c = RequestContext( request, { 'first_nav_name': FIRST_NAV, 'second_navs': export.get_stats_second_navs(request), 'second_nav_name': export.STATS_MEMBER_SECOND_NAV, 'third_nav_name': export.MEMBER_SUMMARY_NAV, 'start_date': start_date, 'end_date': end_date, }) return render_to_response('member/member_summary.html', c)
def get(request): """ 显示商品概况页面 """ #默认显示最近7天的日期 end_date = dateutil.get_today() start_date = dateutil.get_previous_date(end_date, 6) #获取7天前日期 c = RequestContext( request, { 'first_nav_name': FIRST_NAV, 'app_name': 'stats', 'second_navs': export.get_stats_second_navs(request), 'second_nav_name': export.STATS_SALES_SECOND_NAV, 'third_nav_name': export.PRODUCT_SUMMARY_NAV, 'start_date': start_date, 'end_date': end_date, }) return render_to_response('sales/product_summary.html', c)
def step_impl(context, user): start_date = None end_date = None if context.date_dict: start_date = context.date_dict['start_date'] end_date = context.date_dict['end_date'] start_date = bdd_util.get_date_str(start_date) end_date = bdd_util.get_date_str(end_date) else: today = dateutil.get_today() start_date = dateutil.get_previous_date(today, 6) end_date = today start_time = start_date + ' 00:00:00' end_time = end_date + ' 23:59:59' url = '/stats/api/order_summary/?start_time=%s&end_time=%s' % (start_time, end_time) response = context.client.get(url) bdd_util.assert_api_call_success(response) result = json.loads(response.content) context.stats_data = result['data']
def get_messages(request): response = JsonResponse() response.code = 200 response.data = JsonResponse() response.data.items = [] mpuser = get_system_user_binded_mpuser(request.user) if mpuser is None: return response.get_response() #获取当前页数 cur_page = int(request.GET.get('page', '1')) #获取每页个数 count = int(request.GET.get('count', COUNT_PER_PAGE)) is_debug = (request.GET.get('dbg', '0') == '1') is_collected = request.GET.get('is_collected', '') search_content = request.GET.get('search_content', '') if is_collected: collected_message_ids = CollectMessage.get_message_ids(request.user) ordering = 'FIELD(`id`, %s)' % ','.join( str(id) for id in collected_message_ids) messages = Message.objects.filter(id__in=collected_message_ids).extra( select={'ordering': ordering}, order_by=('ordering', )) elif search_content: data_before_tow_days = dateutil.get_previous_date('today', 2) messages = Message.objects.belong_to(request.user_profile.webapp_id, mpuser, search_content) else: messages = [] pageinfo, messages = paginate(messages, cur_page, count, query_string=request.META['QUERY_STRING']) webapp_id = request.user_profile.webapp_id for message in messages: weixin_user = message.session.weixin_user one_session = JsonResponse() one_session.id = message.id one_session.session_id = message.session.id one_session.sender_fake_id = weixin_user.fake_id one_session.sender_username = weixin_user.username one_session.sender_name = weixin_user.nickname_for_html if weixin_user.weixin_user_icon: one_session.weixin_user_icon = weixin_user.weixin_user_icon if len( weixin_user.weixin_user_icon.strip()) > 0 else DEFAULT_ICON else: one_session.weixin_user_icon = DEFAULT_ICON one_session.content = emotion.change_emotion_to_img(message.content) one_session.is_active = True if datetime.now( ) < message.created_at + timedelta( hours=EXPIRED_TIME) and datetime.now( ) > message.created_at else False if is_collected: one_session.is_active = False try: collect_message = CollectMessage.objects.get( message_id=message.id) one_session.created_at = __format_datetime( collect_message.created_at) except: one_session.created_at = __format_datetime(message.created_at) else: one_session.created_at = __format_datetime(message.created_at) one_session.message_id = message.id one_session.is_collected = CollectMessage.is_collected(message.id) one_session.message_type = message.message_type one_session.pic_url = message.pic_url one_session.audio_url = message.audio_url one_session.for_collected = is_collected one_session.hidden_a = True if message.message_type == IMAGE: one_session.content = message.pic_url if message.message_type == VOICE: one_session.content = message.audio_url one_session.is_subscribed = is_subscribed(weixin_user) try: account = SocialAccount.objects.get(webapp_id=webapp_id, openid=weixin_user.username) member = MemberHasSocialAccount.objects.filter( account=account)[0].member #member = session2member[session.weixin_user_id] if member: one_session.member_id = member.id one_session.member_remarks_name = member.remarks_name if member.user_icon and len(member.user_icon.strip()) > 0: one_session.weixin_user_icon = member.user_icon if member.username_for_html: one_session.sender_name = member.username_for_html except: notify_message = u"设置会话信息失败, weixin_user_openid:{}, cause:\n{}".format( session.weixin_user_id, unicode_full_stack()) watchdog_notice(notify_message) continue response.data.items.append(one_session) response.data.page_info = __package_pageinfo(pageinfo) return response.get_response()
def analysis_message(request, args): """ 统计微信消息数据:接收消息数、发送消息数、互动人数、互动次数 @param request 无用,为了兼容 @param args dict类型 """ #MessageAnalysis print 'start service analysis_message {}'.format( datetime.now().strftime('%Y-%m-%d %H:%M:%S')) mpuser2user = _get_mpuser2user() previous_date = get_previous_date('today', 0) start_date = previous_date + ' 00:00:00' end_date = previous_date + ' 23:59:59' print 'analysis messages from {} to {}'.format(start_date, end_date) messages = Message.objects.filter(weixin_created_at__gte=start_date, weixin_created_at__lte=end_date) statistics = {} analysised_fans = [] for message in messages: try: owner_id = mpuser2user[message.mpuser_id].owner_id except: print 'get owner_id exception for message {}'.format(message.id) continue analysis_date = message.weixin_created_at.strftime("%Y-%m-%d") statistic_key = str(owner_id) + '_' + analysis_date if not statistics.has_key(statistic_key): statistics[statistic_key] = { 'receive_count': 0, 'send_count': 0, 'interaction_user_count': 0 } date_statistic = statistics[statistic_key] fans_username = message.from_weixin_user_username if message.is_reply: date_statistic['send_count'] += 1 else: date_statistic['receive_count'] += 1 if fans_username not in analysised_fans: date_statistic['interaction_user_count'] += 1 analysised_fans.append(fans_username) for key in statistics: date_statistic = statistics[key] date_statistic['interaction_count'] = date_statistic[ 'send_count'] + date_statistic['receive_count'] try: key_items = key.split('_') MessageAnalysis.objects.filter(owner_id=key_items[0], date_time=previous_date).delete() MessageAnalysis.objects.create( owner_id=key_items[0], receive_count=date_statistic['receive_count'], send_count=date_statistic['send_count'], interaction_user_count=date_statistic[ 'interaction_user_count'], interaction_count=date_statistic['interaction_count'], date_time=key_items[1]) except: pass print statistics return "OK"