def get_pv_rpt_by_day(conditions): #TODO: add search filters to pipline date_start = conditions.get('date_start') date_end = conditions.get('date_end') pipeline = [ {"$project": { "day":"$day", "uid": "$uid", "pc":{"$cond": [{"$eq": ["$type", "1"]}, 1, 0]}, "sc":{"$cond": [{"$eq": ["$type", "2"]}, 1, 0]} } }, { "$group": { "_id": { "day": "$day", "uid": "$uid" }, "pc": {"$sum": "$pc"}, "sc": {"$sum": "$sc"} } }, { "$group": { "_id": "$_id.day", "pc": {"$sum": "$pc"}, "sc": {"$sum": "$sc"}, "uc": {"$sum": 1} } } ] rst = Trace._get_collection().aggregate(pipeline) return rst.get('result')
def get_pv_rpt_by_day(conditions): #TODO: add search filters to pipline date_start = conditions.get('date_start') date_end = conditions.get('date_end') pipeline = [{ "$project": { "day": "$day", "uid": "$uid", "pc": { "$cond": [{ "$eq": ["$type", "1"] }, 1, 0] }, "sc": { "$cond": [{ "$eq": ["$type", "2"] }, 1, 0] } } }, { "$group": { "_id": { "day": "$day", "uid": "$uid" }, "pc": { "$sum": "$pc" }, "sc": { "$sum": "$sc" } } }, { "$group": { "_id": "$_id.day", "pc": { "$sum": "$pc" }, "sc": { "$sum": "$sc" }, "uc": { "$sum": 1 } } }] rst = Trace._get_collection().aggregate(pipeline) return rst.get('result')
def api_trace(request): from integration.models import Trace import datetime trc = Trace() trc.type = request.GET.get("type", "0") trc.func_name = request.GET.get("fn", "") trc.func_content = request.GET.get("fc", "") trc.cookie_id = request.COOKIES.get("sessionid", None) trc.uid = request.COOKIES.get("uid", None) trc.req_referer = request.META.get("HTTP_REFERER", None) trc.agent = request.META.get("HTTP_USER_AGENT", None) trc.req_url = request.build_absolute_uri() trc.day = datetime.datetime.now().strftime("%Y%m%d") if request.META.has_key("HTTP_X_FORWARDED_FOR"): trc.ip = request.META["HTTP_X_FORWARDED_FOR"] else: trc.ip = request.META.get("REMOTE_ADDR", None) if request.user and request.user.is_authenticated(): trc.user_id = str(request.user.pk) try: trc.save() except Exception: pass return HttpResponseJson("")
def api_trace(request): from integration.models import Trace import datetime trc = Trace() trc.type = request.GET.get('type', '0') trc.func_name = request.GET.get('fn', '') trc.func_content = request.GET.get('fc', '') trc.cookie_id = request.COOKIES.get('sessionid', None) trc.uid = request.COOKIES.get('uid', None) trc.req_referer = request.META.get('HTTP_REFERER', None) trc.agent = request.META.get('HTTP_USER_AGENT', None) trc.req_url = request.build_absolute_uri() trc.day = datetime.datetime.now().strftime('%Y%m%d') if request.META.has_key('HTTP_X_FORWARDED_FOR'): trc.ip = request.META['HTTP_X_FORWARDED_FOR'] else: trc.ip = request.META.get('REMOTE_ADDR', None) if request.user and request.user.is_authenticated(): trc.user_id = str(request.user.pk) try: trc.save() except Exception: pass return HttpResponseJson('')