當前位置: 首頁>>代碼示例>>Python>>正文


Python models.StdDev方法代碼示例

本文整理匯總了Python中django.db.models.StdDev方法的典型用法代碼示例。如果您正苦於以下問題:Python models.StdDev方法的具體用法?Python models.StdDev怎麽用?Python models.StdDev使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.db.models的用法示例。


在下文中一共展示了models.StdDev方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: handle

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import StdDev [as 別名]
def handle(self, *args, **options):
        cutoff_date = datetime.date.today() - datetime.timedelta(days=(30 * MONTHS))
        counts = User.objects.filter(date_joined__gt=cutoff_date)
        counts = counts.annotate(follow_count=Count('following')).order_by('follow_count')

        avg = counts.aggregate(Avg('follow_count'))['follow_count__avg']

        print
        print 'Following counts for users who signed up in the last {} months'.format(MONTHS)
        print '----------------'
        print 'Average: {:.3} per user'.format(avg)

        try:
            std_dev = counts.aggregate(StdDev('follow_count'))['follow_count__stddev']
            print 'StdDev:  {:.3}'.format(std_dev)
        except DatabaseError:
            print "(can't get standard deviation with SQLite)"
        counts = counts.values_list('follow_count', flat=True)
        print 'Median: {}'.format(percentile(counts, 0.5))
        print 
開發者ID:canvasnetworks,項目名稱:canvas,代碼行數:22,代碼來源:average_following.py

示例2: all_aggregations

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import StdDev [as 別名]
def all_aggregations(queryset, key):
    """ Performs all available aggregations on a queryset """
    return queryset.filter(**{key + '__isnull': False}).aggregate(
        min=Min(key),
        avg=Avg(key),
        max=Max(key),
        std=StdDev(key),
        count=Count(key),
        sum=Sum(key),
    ) 
開發者ID:seanbell,項目名稱:opensurfaces,代碼行數:12,代碼來源:utils.py

示例3: fetch_and_calculate

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import StdDev [as 別名]
def fetch_and_calculate(self, with_arr = False):
        ## REQUIRES PSQL SETTINGS TO HAVE MORE MEMORY
        # sudo nano /etc/postgresql/9.3/main/postgresql.conf
        # shared_buffers = 2GB
        # work_mem = 100MB
        # temp_buffers = 500MB
        # sudo /etc/init.d/postgresql restart
        ds_with_key = {}
        if with_arr:
            ds = list(Distance.objects.filter(structure__in=self.structures).exclude(gns_pair__contains='8x').exclude(gns_pair__contains='12x').exclude(gns_pair__contains='23x').exclude(gns_pair__contains='34x').exclude(gns_pair__contains='45x') \
                            .values('gns_pair') \
                            .annotate(mean = Avg('distance'), std = StdDev('distance'), c = Count('distance'), dis = Count('distance'),arr=ArrayAgg('distance'),arr2=ArrayAgg('structure__pdb_code__index'),arr3=ArrayAgg('gns_pair')).values_list('gns_pair','mean','std','c','dis','arr','arr2','arr3').filter(c__gte=int(0.8*len(self.structures))))
            for i,d in enumerate(ds):
                ds[i] = list(ds[i])
                ds[i][3] = d[2]/d[1]
                ds_with_key[d[0]] = ds[i]
        else:
            ds = list(Distance.objects.filter(structure__in=self.structures).exclude(gns_pair__contains='8x').exclude(gns_pair__contains='12x').exclude(gns_pair__contains='23x').exclude(gns_pair__contains='34x').exclude(gns_pair__contains='45x') \
                            .values('gns_pair') \
                            .annotate(mean = Avg('distance'), std = StdDev('distance'), c = Count('distance')).values_list('gns_pair','mean','std','c').filter(c__gte=int(len(self.structures)*0.8)))
            for i,d in enumerate(ds):
                ds[i] += (d[2]/d[1],)
                ds_with_key[d[0]] = ds[i]
        # # print(ds.query)
        # print(ds[1])
        # Assume that dispersion is always 4
        if len(self.structures)>1:
            stats_sorted = sorted(ds, key=lambda k: -k[3])
        else:
            stats_sorted = sorted(ds, key=lambda k: -k[1])
        #print(ds[1])

        self.stats_key = ds_with_key
        self.stats = stats_sorted 
開發者ID:protwis,項目名稱:protwis,代碼行數:36,代碼來源:distances.py

示例4: test_aggregation

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import StdDev [as 別名]
def test_aggregation(self):
        """
        #19360: Raise NotImplementedError when aggregating on date/time fields.
        """
        for aggregate in (Sum, Avg, Variance, StdDev):
            with self.assertRaises(NotImplementedError):
                Item.objects.all().aggregate(aggregate('time'))
            with self.assertRaises(NotImplementedError):
                Item.objects.all().aggregate(aggregate('date'))
            with self.assertRaises(NotImplementedError):
                Item.objects.all().aggregate(aggregate('last_modified'))
            with self.assertRaises(NotImplementedError):
                Item.objects.all().aggregate(
                    **{'complex': aggregate('last_modified') + aggregate('last_modified')}
                ) 
開發者ID:denisenkom,項目名稱:django-sqlserver,代碼行數:17,代碼來源:tests.py

示例5: test_aggregation

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import StdDev [as 別名]
def test_aggregation(self):
        """
        Raise NotImplementedError when aggregating on date/time fields (#19360).
        """
        for aggregate in (Sum, Avg, Variance, StdDev):
            with self.assertRaises(NotSupportedError):
                Item.objects.all().aggregate(aggregate('time'))
            with self.assertRaises(NotSupportedError):
                Item.objects.all().aggregate(aggregate('date'))
            with self.assertRaises(NotSupportedError):
                Item.objects.all().aggregate(aggregate('last_modified'))
            with self.assertRaises(NotSupportedError):
                Item.objects.all().aggregate(
                    **{'complex': aggregate('last_modified') + aggregate('last_modified')}
                ) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:17,代碼來源:tests.py

示例6: drop_report

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import StdDev [as 別名]
def drop_report(qs, **kwargs):
    report_data = {}

    # Get querysets for each possible drop type
    drops = get_drop_querysets(qs)
    report_data['summary'] = get_report_summary(drops, qs.count(), **kwargs)

    # Clear time statistics, if supported by the qs model
    if hasattr(qs.model, 'clear_time'):
        successful_runs = qs.filter(
            Q(success=True) | Q(level__dungeon__category=Dungeon.CATEGORY_RIFT_OF_WORLDS_BEASTS)
        )

        if successful_runs.count():
            clear_time_aggs = successful_runs.aggregate(
                std_dev=StdDev(Extract(F('clear_time'), lookup_name='epoch')),
                avg=Avg('clear_time'),
                min=Min('clear_time'),
                max=Max('clear_time'),
            )

            # Use +/- 3 std deviations of clear time avg as bounds for time range in case of extreme outliers skewing chart scale
            min_time = round_timedelta(
                max(clear_time_aggs['min'], clear_time_aggs['avg'] - timedelta(seconds=clear_time_aggs['std_dev'] * 3)),
                CLEAR_TIME_BIN_WIDTH,
                direction='down',
            )
            max_time = round_timedelta(
                min(clear_time_aggs['max'], clear_time_aggs['avg'] + timedelta(seconds=clear_time_aggs['std_dev'] * 3)),
                CLEAR_TIME_BIN_WIDTH,
                direction='up',
            )
            bins = [min_time + CLEAR_TIME_BIN_WIDTH * x for x in range(0, int((max_time - min_time) / CLEAR_TIME_BIN_WIDTH))]

            # Histogram generates on entire qs, not just successful runs.
            report_data['clear_time'] = {
                'min': str(clear_time_aggs['min']),
                'max': str(clear_time_aggs['max']),
                'avg': str(clear_time_aggs['avg']),
                'chart': {
                    'type': 'histogram',
                    'width': 5,
                    'data': histogram(qs, 'clear_time', bins, slice_on='success'),
                }
            }

    # Individual drop details
    for key, qs in drops.items():
        if DROP_TYPES[key]:
            report_data[key] = DROP_TYPES[key](qs, qs.count(), **kwargs)

    return report_data 
開發者ID:PeteAndersen,項目名稱:swarfarm,代碼行數:54,代碼來源:generate.py


注:本文中的django.db.models.StdDev方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。