当前位置: 首页>>代码示例>>Python>>正文


Python QuerySetStats.time_series方法代码示例

本文整理汇总了Python中qsstats.QuerySetStats.time_series方法的典型用法代码示例。如果您正苦于以下问题:Python QuerySetStats.time_series方法的具体用法?Python QuerySetStats.time_series怎么用?Python QuerySetStats.time_series使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在qsstats.QuerySetStats的用法示例。


在下文中一共展示了QuerySetStats.time_series方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_time_series_weeks

# 需要导入模块: from qsstats import QuerySetStats [as 别名]
# 或者: from qsstats.QuerySetStats import time_series [as 别名]
    def test_time_series_weeks(self):
        day = datetime.date(year=2013, month=4, day=5)

        u = User.objects.create_user('user', '[email protected]')
        u.date_joined = day
        u.save()

        qs = User.objects.all()
        qss = QuerySetStats(qs, 'date_joined')
        qss.time_series(day - datetime.timedelta(days=30), day, interval='weeks')
开发者ID:PetrDlouhy,项目名称:django-qsstats-magic,代码行数:12,代码来源:tests.py

示例2: graph

# 需要导入模块: from qsstats import QuerySetStats [as 别名]
# 或者: from qsstats.QuerySetStats import time_series [as 别名]
def graph(request):
    start = datetime.datetime(2013, 11, 21, 00, 00).date()
    end = datetime.datetime.now().date()
    users = User.objects.all()
    qsstats = QuerySetStats(users, date_field='last_login', aggregate=Count('id'))
    values = qsstats.time_series(start , end , interval='days' )

    staff = User.objects.all().filter(is_staff = '1').count()
    other = User.objects.all().count() - staff
    type_of_user = [['Суперпользователи',staff],['Пользователи',other]]
    start = datetime.datetime(2013, 12, 3, 00, 00).date()
    answer = Answer.objects.all()
    qsstats2 = QuerySetStats(answer, date_field='date', aggregate=Count('id'))
    ans = qsstats2.time_series(start,end, interval="days")
    return render(request,'graph.html', { 'ans':ans , 'users': values , 'type' : type_of_user })
开发者ID:MaxMyalkin,项目名称:AskMyalkin,代码行数:17,代码来源:views.py

示例3: get_registrations

# 需要导入模块: from qsstats import QuerySetStats [as 别名]
# 或者: from qsstats.QuerySetStats import time_series [as 别名]
    def get_registrations(self, interval, days, graph_key, select_box_value):
        """ Returns an array with new users count per interval."""
        try:
            conf_data = DashboardStats.objects.get(graph_key=graph_key)
            model_name = get_model(conf_data.model_app_name, conf_data.model_name)
            kwargs = {}
            for i in conf_data.criteria.all():
                # fixed mapping value passed info kwargs
                if i.criteria_fix_mapping:
                    for key in i.criteria_fix_mapping:
                       # value => i.criteria_fix_mapping[key]
                        kwargs[key] = i.criteria_fix_mapping[key]

                # dynamic mapping value passed info kwargs
                if i.dynamic_criteria_field_name and select_box_value:
                    kwargs[i.dynamic_criteria_field_name] = select_box_value

            aggregate = None
            if conf_data.type_operation_field_name and conf_data.operation_field_name:
                operation={'Sum': Sum(conf_data.operation_field_name),
                        'Avg':Avg(conf_data.operation_field_name),
                        'StdDev':StdDev(conf_data.operation_field_name),
                        'Max':Max(conf_data.operation_field_name),
                        'Min':Min(conf_data.operation_field_name),
                        'Variance':Variance(conf_data.operation_field_name),
                        }
                aggregate=operation[conf_data.type_operation_field_name]

            stats = QuerySetStats(model_name.objects.filter(**kwargs),
                                      conf_data.date_field_name, aggregate)
            #stats = QuerySetStats(User.objects.filter(is_active=True), 'date_joined')
            today = now()
            if days == 24:
                begin = today - timedelta(hours=days - 1)
                return stats.time_series(begin, today + timedelta(hours=1), interval)

            begin = today - timedelta(days=days - 1)
            return stats.time_series(begin, today + timedelta(days=1), interval)
        except:
            User = get_user_model()
            stats = QuerySetStats(
                User.objects.filter(is_active=True), 'date_joined')
            today = now()
            if days == 24:
                begin = today - timedelta(hours=days - 1)
                return stats.time_series(begin, today + timedelta(hours=1), interval)
            begin = today - timedelta(days=days - 1)
            return stats.time_series(begin, today + timedelta(days=1), interval)
开发者ID:EasonYi,项目名称:django-admin-tools-stats,代码行数:50,代码来源:modules.py

示例4: process_hourly_activity

# 需要导入模块: from qsstats import QuerySetStats [as 别名]
# 或者: from qsstats.QuerySetStats import time_series [as 别名]
def process_hourly_activity(user, start, end, modelclass):
    if modelclass == AdRecord:
        qs = modelclass.objects.filter(_user_id=user.id, date__range=(start, end))
    else:
        qs = modelclass.objects.filter(user=user, date__range=(start, end))
    if not qs:
        return {}
    qss = QuerySetStats(qs, 'date')
    start_date = start.date()
    end_date = end.date()
    if start_date == end_date:
        end_date = start_date + timedelta(days=1)
    timeseries = qss.time_series(
                        start_date, end=end_date, interval='hours', date_field='date')
    activities = {}
    for t in timeseries:
        if t[1]:
            d = t[0]
            activity = get_hourly_activity(user, start_date, d.hour)
            if modelclass == AdRecord:
                for r in qs.filter(date__hour=d.hour):
                    activity.adrecords.add(r)
            elif modelclass == FBSponsored:
                for r in qs.filter(date__hour=d.hour):
                    activity.fbsponsored.add(r)
            elif modelclass == FBAd:
                for r in qs.filter(date__hour=d.hour):
                    activity.fbads.add(r)
            activity.adtotal = activity.adrecords.count()
            activity.fbadtotal = activity.fbads.count()
            activity.fbsptotal = activity.fbsponsored.count()
            activity.save()
            activities[d] = activity    
    return activities
开发者ID:valuesandvalue,项目名称:valuesandvalue,代码行数:36,代码来源:activity.py

示例5: assertTimeSeriesWorks

# 需要导入模块: from qsstats import QuerySetStats [as 别名]
# 或者: from qsstats.QuerySetStats import time_series [as 别名]
 def assertTimeSeriesWorks(self, today):
     seven_days_ago = today - datetime.timedelta(days=7)
     for j in range(1,8):
         for i in range(0,j):
             u = User.objects.create_user('p-%s-%s' % (j, i), 'p%s-%[email protected]' % (j, i))
             u.date_joined = today - datetime.timedelta(days=i)
             u.save()
     qs = User.objects.all()
     qss = QuerySetStats(qs, 'date_joined')
     time_series = qss.time_series(seven_days_ago, today)
     self.assertEqual([t[1] for t in time_series], [0, 1, 2, 3, 4, 5, 6, 7])
开发者ID:CfABrigadePhiladelphia,项目名称:Wikidelphia,代码行数:13,代码来源:tests.py

示例6: test

# 需要导入模块: from qsstats import QuerySetStats [as 别名]
# 或者: from qsstats.QuerySetStats import time_series [as 别名]
def test(request):
    """Just test page."""
    template_name = 'runstat/test.html'
    #
    start_date = datetime.strptime('2016-05-01', '%Y-%m-%d').date()
    end_date = datetime.strptime('2016-05-31', '%Y-%m-%d').date()
    qs = GroupPost.objects.all()
    qss = QuerySetStats(qs, date_field='created_time')
    values = qss.time_series(start_date, end_date, interval='days')

    return render(request, template_name, {'values': values})
开发者ID:dimadvk,项目名称:runstat,代码行数:13,代码来源:views.py

示例7: get_registrations

# 需要导入模块: from qsstats import QuerySetStats [as 别名]
# 或者: from qsstats.QuerySetStats import time_series [as 别名]
    def get_registrations(self, interval, days, graph_key, select_box_value):
        """ Returns an array with new users count per interval."""
        try:
            conf_data = DashboardStats.objects.get(graph_key=graph_key)
            model_name = get_model(
                conf_data.model_app_name, conf_data.model_name)
            kwargs = {}

            for i in conf_data.criteria.all():
                # fixed mapping value passed info kwargs
                if i.criteria_fix_mapping:
                    for key in i.criteria_fix_mapping:
                        # value => i.criteria_fix_mapping[key]
                        kwargs[key] = i.criteria_fix_mapping[key]

                # dynamic mapping value passed info kwargs
                if i.dynamic_criteria_field_name and select_box_value:
                    kwargs[i.dynamic_criteria_field_name] = select_box_value

            stats = QuerySetStats(model_name.objects.filter(**kwargs),
                                  conf_data.date_field_name)
            #stats = QuerySetStats(User.objects.filter(is_active=True), 'date_joined')
            today = now()
            if days == 24:
                begin = today - timedelta(hours=days - 1)
                return stats.time_series(begin, today + timedelta(hours=1), interval)

            begin = today - timedelta(days=days - 1)
            return stats.time_series(begin, today + timedelta(days=1), interval)
        except:
            stats = QuerySetStats(
                User.objects.filter(is_active=True), 'date_joined')
            today = now()
            if days == 24:
                begin = today - timedelta(hours=days - 1)
                return stats.time_series(begin, today + timedelta(hours=1), interval)
            begin = today - timedelta(days=days - 1)
            return stats.time_series(begin, today + timedelta(days=1), interval)
开发者ID:MVReddy,项目名称:django-admin-tools-stats,代码行数:40,代码来源:modules.py

示例8: get_models_data

# 需要导入模块: from qsstats import QuerySetStats [as 别名]
# 或者: from qsstats.QuerySetStats import time_series [as 别名]
    def get_models_data(self, querysets):
        """ querysets = {model: (queryset, time_field)} """
        for model_type, (queryset, time_field) in querysets.iteritems():
            qss = QuerySetStats(queryset, time_field)

            data = qss.time_series(self.startdate, self.enddate)

            counts = [d[1] for d in data]
            qss.last_week = sum(counts[-7:])
            qss.last_month = sum(counts[-30:])

            self.day_captions = [t[0].day for t in data]

            setattr(self, model_type+'_qss', qss)
            setattr(self, model_type+'_values', counts)
开发者ID:mikpanko,项目名称:grakon,代码行数:17,代码来源:dashboard.py

示例9: time_series

# 需要导入模块: from qsstats import QuerySetStats [as 别名]
# 或者: from qsstats.QuerySetStats import time_series [as 别名]
def time_series(queryset, date_field, interval, func=None, agg=None, annotate_field=None):
    if agg in (None, "daily"):
        qsstats = QuerySetStats(queryset, date_field, func)
        return qsstats.time_series(*interval)
    else:
        # Custom aggregation was set (weekly/monthly/yearly)
        agg_by = agg[:-2]

        # We need to set the range dynamically
        interval_filter = {date_field + "__gte": interval[0], date_field + "__lte": interval[1]}

        # Slightly raw-ish SQL query using extra

        truncate_date = connections[queryset.db].ops.date_trunc_sql(agg_by, date_field)
        if not annotate_field:
            # By default we always annotate by dates, counting all the
            # records recovered for the given dates
            annotate_field = date_field
            result = (
                queryset.extra(select={agg_by: truncate_date})
                .values_list(agg_by)
                .annotate(Count(annotate_field))
                .filter(**interval_filter)
                .order_by(agg_by)
            )
        else:
            # We do a Sum by annotation field, we are assuming if the
            # annotation is not by dates it will be a field which type can be
            # added, like prices for example.
            result = (
                queryset.extra(select={agg_by: truncate_date})
                .values_list(agg_by)
                .annotate(Sum(annotate_field))
                .filter(**interval_filter)
                .order_by(agg_by)
            )

        return fill_missing_dates_with_zeros(result, agg_by, interval)
开发者ID:sideeffects,项目名称:stats_core,代码行数:40,代码来源:time_series.py

示例10: response_timeseries

# 需要导入模块: from qsstats import QuerySetStats [as 别名]
# 或者: from qsstats.QuerySetStats import time_series [as 别名]
 def response_timeseries(self):
     """
     Returns a list of timeseries from the responses.
     """
     qss = QuerySetStats(self.all(), "created")
     return qss.time_series(timezone.now() - timedelta(days=7), timezone.now())
开发者ID:DistrictDataLabs,项目名称:topicmaps,代码行数:8,代码来源:managers.py

示例11: get_data

# 需要导入模块: from qsstats import QuerySetStats [as 别名]
# 或者: from qsstats.QuerySetStats import time_series [as 别名]
 def get_data(self, interval, days):
     """ Returns an array with new users count per interval """
     stats = QuerySetStats(self.queryset, self.date_field, aggregate=self.aggregate)
     today = now()
     begin = today - timedelta(days=days - 1)
     return stats.time_series(begin, today + timedelta(days=1), interval)
开发者ID:kmike,项目名称:django-admin-user-stats,代码行数:8,代码来源:base_modules.py

示例12: get_scan_per_day

# 需要导入模块: from qsstats import QuerySetStats [as 别名]
# 或者: from qsstats.QuerySetStats import time_series [as 别名]
def get_scan_per_day(start_date, end_date):
    scan_qsstats = QuerySetStats(Scan.objects.all(),
                                 date_field='start',)
    scan_values = scan_qsstats.time_series(start_date, end_date, interval='days')
    return format_date(scan_values)
开发者ID:andresriancho,项目名称:w3af-webui,代码行数:7,代码来源:views.py

示例13: time_series

# 需要导入模块: from qsstats import QuerySetStats [as 别名]
# 或者: from qsstats.QuerySetStats import time_series [as 别名]
def time_series(queryset, date_field, interval, func=None):
    qsstats = QuerySetStats(queryset, date_field, func)
    return qsstats.time_series(*interval)
开发者ID:mwolff44,项目名称:pyfreebilling,代码行数:5,代码来源:utils.py

示例14: get_data

# 需要导入模块: from qsstats import QuerySetStats [as 别名]
# 或者: from qsstats.QuerySetStats import time_series [as 别名]
 def get_data(self, interval, days):
     """ Returns an array with new users count per interval """
     stats = QuerySetStats(self.queryset, self.date_field)
     today = datetime.date.today()
     begin = today - datetime.timedelta(days=days-1)
     return stats.time_series(begin, today, interval)
开发者ID:Mohajji,项目名称:pyfreebilling,代码行数:8,代码来源:base_modules.py

示例15: get_registrations

# 需要导入模块: from qsstats import QuerySetStats [as 别名]
# 或者: from qsstats.QuerySetStats import time_series [as 别名]
 def get_registrations(self, interval, days):
     """ Returns an array with new users count per interval """
     stats = QuerySetStats(User.objects.filter(is_active=True), 'date_joined')
     today = datetime.today()
     begin = today - timedelta(days=days-1)
     return stats.time_series(begin, today+timedelta(days=1), interval)
开发者ID:filterfoundry,项目名称:django-admin-user-stats,代码行数:8,代码来源:modules.py


注:本文中的qsstats.QuerySetStats.time_series方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。