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


Python extras.NumericRange方法代碼示例

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


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

示例1: test_integer_bucket

# 需要導入模塊: from psycopg2 import extras [as 別名]
# 或者: from psycopg2.extras import NumericRange [as 別名]
def test_integer_bucket(self):
        with self.session.begin():
            creator, survey = self._create_blank_survey()
            survey.nodes = [
                models.construct_survey_node(
                    node=models.construct_node(
                        type_constraint='integer',
                        title={'English': 'node'},
                    ),
                    sub_surveys=[
                        models.SubSurvey(
                            buckets=[
                                models.construct_bucket(
                                    bucket_type='integer',
                                    bucket='(1, 2]'
                                ),
                            ],
                        ),
                    ],
                ),
            ]
            self.session.add(creator)

        the_bucket = self.session.query(Bucket).one()
        self.assertEqual(the_bucket.bucket, NumericRange(2, 3, '[)')) 
開發者ID:SEL-Columbia,項目名稱:dokomoforms,代碼行數:27,代碼來源:test_model.py

示例2: test_cast_numbers

# 需要導入模塊: from psycopg2 import extras [as 別名]
# 或者: from psycopg2.extras import NumericRange [as 別名]
def test_cast_numbers(self):
        from psycopg2.extras import NumericRange
        cur = self.conn.cursor()
        for type in ('int4range', 'int8range'):
            cur.execute("select '(10,20)'::%s" % type)
            r = cur.fetchone()[0]
            self.assert_(isinstance(r, NumericRange))
            self.assert_(not r.isempty)
            self.assertEqual(r.lower, 11)
            self.assertEqual(r.upper, 20)
            self.assert_(not r.lower_inf)
            self.assert_(not r.upper_inf)
            self.assert_(r.lower_inc)
            self.assert_(not r.upper_inc)

        cur.execute("select '(10.2,20.6)'::numrange")
        r = cur.fetchone()[0]
        self.assert_(isinstance(r, NumericRange))
        self.assert_(not r.isempty)
        self.assertEqual(r.lower, Decimal('10.2'))
        self.assertEqual(r.upper, Decimal('20.6'))
        self.assert_(not r.lower_inf)
        self.assert_(not r.upper_inf)
        self.assert_(not r.lower_inc)
        self.assert_(not r.upper_inc) 
開發者ID:synthetichealth,項目名稱:syntheticmass,代碼行數:27,代碼來源:test_types_extras.py

示例3: test_all_fields

# 需要導入模塊: from psycopg2 import extras [as 別名]
# 或者: from psycopg2.extras import NumericRange [as 別名]
def test_all_fields(self):
        now = timezone.now()
        instance = RangesModel(
            ints=NumericRange(0, 10),
            bigints=NumericRange(10, 20),
            floats=NumericRange(20, 30),
            timestamps=DateTimeTZRange(now - datetime.timedelta(hours=1), now),
            dates=DateRange(now.date() - datetime.timedelta(days=1), now.date()),
        )
        instance.save()
        loaded = RangesModel.objects.get()
        self.assertEqual(instance.ints, loaded.ints)
        self.assertEqual(instance.bigints, loaded.bigints)
        self.assertEqual(instance.floats, loaded.floats)
        self.assertEqual(instance.timestamps, loaded.timestamps)
        self.assertEqual(instance.dates, loaded.dates) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:18,代碼來源:test_ranges.py

示例4: test_bulk_update

# 需要導入模塊: from psycopg2 import extras [as 別名]
# 或者: from psycopg2.extras import NumericRange [as 別名]
def test_bulk_update(self):
        test_data = [
            (IntegerArrayModel, 'field', [], [1, 2, 3]),
            (NullableIntegerArrayModel, 'field', [1, 2, 3], None),
            (JSONModel, 'field', {'a': 'b'}, {'c': 'd'}),
            (NestedIntegerArrayModel, 'field', [], [[1, 2, 3]]),
            (HStoreModel, 'field', {}, {1: 2}),
            (RangesModel, 'ints', None, NumericRange(lower=1, upper=10)),
            (RangesModel, 'dates', None, DateRange(lower=date.today(), upper=date.today())),
            (OtherTypesArrayModel, 'ips', [], ['1.2.3.4']),
            (OtherTypesArrayModel, 'json', [], [{'a': 'b'}])
        ]
        for Model, field, initial, new in test_data:
            with self.subTest(model=Model, field=field):
                instances = Model.objects.bulk_create(Model(**{field: initial}) for _ in range(20))
                for instance in instances:
                    setattr(instance, field, new)
                Model.objects.bulk_update(instances, [field])
                self.assertSequenceEqual(Model.objects.filter(**{field: new}), instances) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:21,代碼來源:test_bulk_update.py

示例5: test_other_array_types

# 需要導入模塊: from psycopg2 import extras [as 別名]
# 或者: from psycopg2.extras import NumericRange [as 別名]
def test_other_array_types(self):
        instance = OtherTypesArrayModel(
            ips=['192.168.0.1', '::1'],
            uuids=[uuid.uuid4()],
            decimals=[decimal.Decimal(1.25), 1.75],
            tags=[Tag(1), Tag(2), Tag(3)],
            json=[{'a': 1}, {'b': 2}],
            int_ranges=[NumericRange(10, 20), NumericRange(30, 40)],
            bigint_ranges=[
                NumericRange(7000000000, 10000000000),
                NumericRange(50000000000, 70000000000),
            ]
        )
        instance.save()
        loaded = OtherTypesArrayModel.objects.get()
        self.assertEqual(instance.ips, loaded.ips)
        self.assertEqual(instance.uuids, loaded.uuids)
        self.assertEqual(instance.decimals, loaded.decimals)
        self.assertEqual(instance.tags, loaded.tags)
        self.assertEqual(instance.json, loaded.json)
        self.assertEqual(instance.int_ranges, loaded.int_ranges)
        self.assertEqual(instance.bigint_ranges, loaded.bigint_ranges) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:24,代碼來源:test_array.py

示例6: test_float_range

# 需要導入模塊: from psycopg2 import extras [as 別名]
# 或者: from psycopg2.extras import NumericRange [as 別名]
def test_float_range(self):
        qs = PostgresModel.objects.values_list('float_range', flat=True)
        self.assert_tables(qs, PostgresModel)
        # For a strange reason, probably a misconception in psycopg2
        # or a bad name in django.contrib.postgres (less probable),
        # FloatRange returns decimals instead of floats.
        self.assert_query_cached(qs, [
            NumericRange(Decimal('-1000.0'), Decimal('9.87654321')),
            NumericRange(Decimal('0.0'))]) 
開發者ID:noripyt,項目名稱:django-cachalot,代碼行數:11,代碼來源:postgres.py

示例7: get_queryset

# 需要導入模塊: from psycopg2 import extras [as 別名]
# 或者: from psycopg2.extras import NumericRange [as 別名]
def get_queryset(self):
        print("get queryset")
        # Is there no test for figuring if req.user is of AnonymousUser type?
        data = []
        now = datetime.now(pytz.UTC)
        unixnow = calendar.timegm(now.utctimetuple())
        if (not isinstance(self.request.user, AnonymousUser)):
            user = EngageUser.objects.get(user=self.request.user)
            tags_query_set = user.tags.all()
            tag_names = list(map(lambda x: x.name, tags_query_set))
            agenda_items = AgendaItem.objects.filter(tags__name__in=tag_names).filter(
                agenda__meeting_time__contained_by=NumericRange(self.request.data['begin'], self.request.data['end']))
            if agenda_items[0].meeting_time > unixnow:
                meeting_held = False
            else:
                meeting_held = True
        else:
            # return the most recent agenda items for the upcoming meeting,
            # if there is no upcoming meeting, show the last meeting instead
            last_run = Agenda.objects.order_by('-meeting_time')[0]
            if last_run.meeting_time > unixnow:
                meeting_held = False
            else:
                meeting_held = True

            agenda_items = last_run.items.all()

        for ag_item in agenda_items:
            data.append({"item": ag_item, "tag": list(
                ag_item.tags.all()), "meeting_already_held": meeting_held})
        return data 
開發者ID:hackla-engage,項目名稱:engage-backend,代碼行數:33,代碼來源:UserFeed.py

示例8: test_sub_survey_asdict

# 需要導入模塊: from psycopg2 import extras [as 別名]
# 或者: from psycopg2.extras import NumericRange [as 別名]
def test_sub_survey_asdict(self):
        with self.session.begin():
            creator, survey = self._create_blank_survey()
            survey.nodes = [
                models.construct_survey_node(
                    node=models.construct_node(
                        type_constraint='integer',
                        title={'English': 'node'},
                    ),
                    sub_surveys=[
                        models.SubSurvey(
                            buckets=[
                                models.construct_bucket(
                                    bucket_type='integer',
                                    bucket='(1, 2]'
                                ),
                            ],
                        ),
                    ],
                ),
            ]
            self.session.add(creator)

        sub_survey = self.session.query(models.SubSurvey).one()
        self.assertEqual(
            sub_survey._asdict(),
            OrderedDict((
                ('deleted', False),
                ('buckets', [NumericRange(2, 3, '[)')]),
                ('repeatable', False),
                ('nodes', []),
            ))
        ) 
開發者ID:SEL-Columbia,項目名稱:dokomoforms,代碼行數:35,代碼來源:test_model.py

示例9: test_bucket_asdict

# 需要導入模塊: from psycopg2 import extras [as 別名]
# 或者: from psycopg2.extras import NumericRange [as 別名]
def test_bucket_asdict(self):
        with self.session.begin():
            creator, survey = self._create_blank_survey()
            survey.nodes = [
                models.construct_survey_node(
                    node=models.construct_node(
                        type_constraint='integer',
                        title={'English': 'node'},
                    ),
                    sub_surveys=[
                        models.SubSurvey(
                            buckets=[
                                models.construct_bucket(
                                    bucket_type='integer',
                                    bucket='(1, 2]'
                                ),
                            ],
                        ),
                    ],
                ),
            ]
            self.session.add(creator)

        bucket = self.session.query(Bucket).one()
        self.assertEqual(
            bucket._asdict(),
            OrderedDict((
                ('id', bucket.id),
                ('bucket_type', 'integer'),
                ('bucket', NumericRange(2, 3, '[)')),
            ))
        ) 
開發者ID:SEL-Columbia,項目名稱:dokomoforms,代碼行數:34,代碼來源:test_model.py

示例10: test_decimal_bucket

# 需要導入模塊: from psycopg2 import extras [as 別名]
# 或者: from psycopg2.extras import NumericRange [as 別名]
def test_decimal_bucket(self):
        with self.session.begin():
            creator, survey = self._create_blank_survey()
            survey.nodes = [
                models.construct_survey_node(
                    node=models.construct_node(
                        type_constraint='decimal',
                        title={'English': 'node'},
                    ),
                    sub_surveys=[
                        models.SubSurvey(
                            buckets=[
                                models.construct_bucket(
                                    bucket_type='decimal',
                                    bucket='(1.3, 2.3]'
                                ),
                            ],
                        ),
                    ],
                ),
            ]
            self.session.add(creator)

        the_bucket = self.session.query(Bucket).one()
        self.assertEqual(
            the_bucket.bucket,
            NumericRange(Decimal('1.3'), Decimal('2.3'), '(]'),
        ) 
開發者ID:SEL-Columbia,項目名稱:dokomoforms,代碼行數:30,代碼來源:test_model.py

示例11: test_eq_subclass

# 需要導入模塊: from psycopg2 import extras [as 別名]
# 或者: from psycopg2.extras import NumericRange [as 別名]
def test_eq_subclass(self):
        from psycopg2.extras import Range, NumericRange

        class IntRange(NumericRange): pass
        class PositiveIntRange(IntRange): pass

        self.assertEqual(Range(10, 20), IntRange(10, 20))
        self.assertEqual(PositiveIntRange(10, 20), IntRange(10, 20))

    # as the postgres docs describe for the server-side stuff,
    # ordering is rather arbitrary, but will remain stable
    # and consistent. 
開發者ID:synthetichealth,項目名稱:syntheticmass,代碼行數:14,代碼來源:test_types_extras.py

示例12: test_adapt_number_range

# 需要導入模塊: from psycopg2 import extras [as 別名]
# 或者: from psycopg2.extras import NumericRange [as 別名]
def test_adapt_number_range(self):
        from psycopg2.extras import NumericRange
        cur = self.conn.cursor()

        r = NumericRange(empty=True)
        cur.execute("select %s::int4range", (r,))
        r1 = cur.fetchone()[0]
        self.assert_(isinstance(r1, NumericRange))
        self.assert_(r1.isempty)

        r = NumericRange(10, 20)
        cur.execute("select %s::int8range", (r,))
        r1 = cur.fetchone()[0]
        self.assert_(isinstance(r1, NumericRange))
        self.assertEqual(r1.lower, 10)
        self.assertEqual(r1.upper, 20)
        self.assert_(r1.lower_inc)
        self.assert_(not r1.upper_inc)

        r = NumericRange(Decimal('10.2'), Decimal('20.5'), '(]')
        cur.execute("select %s::numrange", (r,))
        r1 = cur.fetchone()[0]
        self.assert_(isinstance(r1, NumericRange))
        self.assertEqual(r1.lower, Decimal('10.2'))
        self.assertEqual(r1.upper, Decimal('20.5'))
        self.assert_(not r1.lower_inc)
        self.assert_(r1.upper_inc) 
開發者ID:synthetichealth,項目名稱:syntheticmass,代碼行數:29,代碼來源:test_types_extras.py

示例13: test_adapt_numeric_range

# 需要導入模塊: from psycopg2 import extras [as 別名]
# 或者: from psycopg2.extras import NumericRange [as 別名]
def test_adapt_numeric_range(self):
        from psycopg2.extras import NumericRange
        cur = self.conn.cursor()

        r = NumericRange(empty=True)
        cur.execute("select %s::int4range", (r,))
        r1 = cur.fetchone()[0]
        self.assert_(isinstance(r1, NumericRange), r1)
        self.assert_(r1.isempty)

        r = NumericRange(10, 20)
        cur.execute("select %s::int8range", (r,))
        r1 = cur.fetchone()[0]
        self.assert_(isinstance(r1, NumericRange))
        self.assertEqual(r1.lower, 10)
        self.assertEqual(r1.upper, 20)
        self.assert_(r1.lower_inc)
        self.assert_(not r1.upper_inc)

        r = NumericRange(Decimal('10.2'), Decimal('20.5'), '(]')
        cur.execute("select %s::numrange", (r,))
        r1 = cur.fetchone()[0]
        self.assert_(isinstance(r1, NumericRange))
        self.assertEqual(r1.lower, Decimal('10.2'))
        self.assertEqual(r1.upper, Decimal('20.5'))
        self.assert_(not r1.lower_inc)
        self.assert_(r1.upper_inc) 
開發者ID:synthetichealth,項目名稱:syntheticmass,代碼行數:29,代碼來源:test_types_extras.py

示例14: test_range_object

# 需要導入模塊: from psycopg2 import extras [as 別名]
# 或者: from psycopg2.extras import NumericRange [as 別名]
def test_range_object(self):
        r = NumericRange(0, 10)
        instance = RangesModel(ints=r)
        instance.save()
        loaded = RangesModel.objects.get()
        self.assertEqual(r, loaded.ints) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:8,代碼來源:test_ranges.py

示例15: test_tuple

# 需要導入模塊: from psycopg2 import extras [as 別名]
# 或者: from psycopg2.extras import NumericRange [as 別名]
def test_tuple(self):
        instance = RangesModel(ints=(0, 10))
        instance.save()
        loaded = RangesModel.objects.get()
        self.assertEqual(NumericRange(0, 10), loaded.ints) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:7,代碼來源:test_ranges.py


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