def new_entity_count(cls, start_time, end_time=datetime.now(), category_id=None, neo_category_id=None, group=None): ##返回的数据格式:[{'count':12,'timestamp':"2012-01"}],date可能不存在 _hd1 = Entity.objects.filter(created_time__range=(start_time, end_time)) _hd1 = _hd1.filter(weight__gte=0) if category_id != None: _hd1.filter(category__id=int(category_id)) if neo_category_id != None: _hd1.filter(neo_category__id=int(neo_category_id)) if group == None: count = _hd1.count() d = {'count': count} return [d] else: group = group.lower() df = date_format("created_time", group) _hd1 = _hd1.extra(select = {"timestamp" : df}).values("timestamp")\ .annotate(count = Count('created_time')) result = list(_hd1.all()) if group == "week": result = week_reformat(result) return result
def new_poke_count(cls, start_time, end_time=datetime.now(), group=None): _hd1 = PokeModel.objects.filter(created_time__range=(start_time, end_time)) if group == None: count = _hd1.count() d = {"count": count} return [d] else: group = group.lower() df = date_format("created_time", group) _hd1 = _hd1.extra(select = {"timestamp" : df})\ .values("timestamp").annotate(count = Count("created_time")) result = list(_hd1.all()) if group == "week": result = week_reformat(result) return result
def new_tag_count(cls, start_time, end_time=datetime.now(), creator_id=None, group=None): _hd1 = ETagModel.objects.filter(created_time__range=(start_time, end_time)) if creator_id != None: _hd1 = _hd1.filter(user__id=creator_id) if group == None: count = _hd1.count() d = {"count": count} return [d] else: group = group.lower() df = date_format("created_time", group) _hd1 = _hd1.extra(select = {"timestamp" : df}).values("timestamp")\ .annotate(count = Count('created_time')) result = list(_hd1.all()) if group == "week": result = week_reformat(result) return result