コード例 #1
0
async def test_tintinst_constructors(connection, expected_tintinst):
    params = TIntInst(expected_tintinst)
    await connection.execute('INSERT INTO tbl_tintinst (temp) VALUES ($1)',
                             params)
    result = await connection.fetchval(
        'SELECT temp FROM tbl_tintinst WHERE temp=$1', params, column=0)
    assert result == TIntInst(expected_tintinst)
コード例 #2
0
def test_tintseq_accessors(cursor, expected_tintseq):
    assert TIntSeq(expected_tintseq).tempSubtype() == 'Sequence'
    assert TIntSeq(expected_tintseq).getValues == [10, 20, 30]
    assert TIntSeq(expected_tintseq).startValue == 10
    assert TIntSeq(expected_tintseq).endValue == 30
    assert TIntSeq(expected_tintseq).minValue == 10
    assert TIntSeq(expected_tintseq).maxValue == 30
    assert TIntSeq(expected_tintseq).valueRange == intrange(10,
                                                            30,
                                                            upper_inc=True)
    assert TIntSeq(expected_tintseq).getTime == PeriodSet(
        '{[2019-09-01 00:00:00+01, 2019-09-03 00:00:00+01]}')
    assert TIntSeq(expected_tintseq).duration == timedelta(2)
    assert TIntSeq(expected_tintseq).timespan == timedelta(2)
    assert TIntSeq(expected_tintseq).period == Period(
        '[2019-09-01 00:00:00+01, 2019-09-03 00:00:00+01]')
    assert TIntSeq(expected_tintseq).numInstants == 3
    assert TIntSeq(expected_tintseq).startInstant == TIntInst(
        '10@2019-09-01 00:00:00+01')
    assert TIntSeq(expected_tintseq).endInstant == TIntInst(
        '30@2019-09-03 00:00:00+01')
    assert TIntSeq(expected_tintseq).instantN(2) == TIntInst(
        '20@2019-09-02 00:00:00+01')
    assert TIntSeq(expected_tintseq).instants == \
           [TIntInst('10@2019-09-01 00:00:00+01'), TIntInst('20@2019-09-02 00:00:00+01'),
            TIntInst('30@2019-09-03 00:00:00+01')]
    assert TIntSeq(expected_tintseq).numTimestamps == 3
    assert TIntSeq(expected_tintseq).startTimestamp == parse(
        '2019-09-01 00:00:00+01')
    assert TIntSeq(expected_tintseq).endTimestamp == parse(
        '2019-09-03 00:00:00+01')
    assert TIntSeq(expected_tintseq).timestampN(2) == parse(
        '2019-09-02 00:00:00+01')
    assert TIntSeq(expected_tintseq).timestamps == [
        parse('2019-09-01 00:00:00+01'),
        parse('2019-09-02 00:00:00+01'),
        parse('2019-09-03 00:00:00+01')
    ]
    assert TIntSeq(expected_tintseq).intersectsTimestamp(
        parse('2019-09-01 00:00:00+01')) == True
    assert TIntSeq(expected_tintseq).intersectsTimestamp(
        parse('2019-09-04 00:00:00+01')) == False
    assert TIntSeq(expected_tintseq).intersectsTimestampSet(
        TimestampSet(
            '{2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01}')) == True
    assert TIntSeq(expected_tintseq).intersectsTimestampSet(
        TimestampSet(
            '{2019-09-04 00:00:00+01, 2019-09-05 00:00:00+01}')) == False
    assert TIntSeq(expected_tintseq).intersectsPeriod(
        Period('[2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]')) == True
    assert TIntSeq(expected_tintseq).intersectsPeriod(
        Period('[2019-09-04 00:00:00+01, 2019-09-05 00:00:00+01]')) == False
    assert TIntSeq(expected_tintseq).intersectsPeriodSet(
        PeriodSet(
            '{[2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]}')) == True
    assert TIntSeq(expected_tintseq).intersectsPeriodSet(
        PeriodSet(
            '{[2019-09-04 00:00:00+01, 2019-09-05 00:00:00+01]}')) == False
コード例 #3
0
ファイル: tint.py プロジェクト: chaitan94/python-mobilitydb
from datetime import datetime, timedelta
from dateutil.parser import parse
from spans.types import intrange
from mobilitydb.time import TimestampSet, Period, PeriodSet
from mobilitydb.main import TIntInst, TIntI, TIntSeq, TIntS


print("\nConstructors for TFloatInst")
inst = TIntInst('10@2019-09-08')
print(inst)
inst = TIntInst('10', '2019-09-08')
print(inst)
t = parse('2019-09-08')
inst = TIntInst(10, t)
print(inst)

print("\nConstructors for TIntI")
ti = TIntI('{10@2019-09-08, 20@2019-09-09, 20@2019-09-10}')
print(ti)
ti = TIntI('10@2019-09-08', '20@2019-09-09', '20@2019-09-10')
print(ti)
ti = TIntI(['10@2019-09-08', '20@2019-09-09', '20@2019-09-10'])
print(ti)
t1 = TIntInst('10@2019-09-08')
t2 = TIntInst('20@2019-09-09')
t3 = TIntInst('20@2019-09-10')
ti = TIntI(t1, t2, t3)
print(ti)
ti = TIntI([t1, t2, t3])
print(ti)
コード例 #4
0
    [10, parse('2019-09-08 00:00:00+01')],
])
async def test_tintinst_constructors(connection, expected_tintinst):
    params = TIntInst(expected_tintinst)
    await connection.execute('INSERT INTO tbl_tintinst (temp) VALUES ($1)',
                             params)
    result = await connection.fetchval(
        'SELECT temp FROM tbl_tintinst WHERE temp=$1', params, column=0)
    assert result == TIntInst(expected_tintinst)


@pytest.mark.parametrize('expected_tintinstset', [
    '{10@2019-09-01 00:00:00+01, 20@2019-09-02 00:00:00+01, 10@2019-09-03 00:00:00+01}',
    ('10@2019-09-01 00:00:00+01', '20@2019-09-02 00:00:00+01',
     '10@2019-09-03 00:00:00+01'),
    (TIntInst('10@2019-09-01 00:00:00+01'),
     TIntInst('20@2019-09-02 00:00:00+01'),
     TIntInst('10@2019-09-03 00:00:00+01')),
    [
        '10@2019-09-01 00:00:00+01', '20@2019-09-02 00:00:00+01',
        '10@2019-09-03 00:00:00+01'
    ],
    [
        TIntInst('10@2019-09-01 00:00:00+01'),
        TIntInst('20@2019-09-02 00:00:00+01'),
        TIntInst('10@2019-09-03 00:00:00+01')
    ],
])
async def test_tintinstset_constructor(connection, expected_tintinstset):
    if isinstance(expected_tintinstset, tuple):
        params = TIntInstSet(*expected_tintinstset)
コード例 #5
0
def test_tintinst_accessors(cursor, expected_tintinst):
    assert TIntInst(expected_tintinst).tempSubtype() == 'Instant'
    assert TIntInst(expected_tintinst).getValue == 10
    assert TIntInst(expected_tintinst).getValues == [10]
    assert TIntInst(expected_tintinst).startValue == 10
    assert TIntInst(expected_tintinst).endValue == 10
    assert TIntInst(expected_tintinst).minValue == 10
    assert TIntInst(expected_tintinst).maxValue == 10
    assert TIntInst(expected_tintinst).valueRange == intrange(10,
                                                              10,
                                                              upper_inc=True)
    assert TIntInst(expected_tintinst).getTimestamp == parse(
        '2019-09-01 00:00:00+01')
    assert TIntInst(expected_tintinst).getTime == PeriodSet(
        '{[2019-09-01 00:00:00+01, 2019-09-01 00:00:00+01]}')
    assert TIntInst(expected_tintinst).duration == timedelta(0)
    assert TIntInst(expected_tintinst).timespan == timedelta(0)
    assert TIntInst(expected_tintinst).period == Period(
        '[2019-09-01 00:00:00+01, 2019-09-01 00:00:00+01]')
    assert TIntInst(expected_tintinst).numInstants == 1
    assert TIntInst(expected_tintinst).startInstant == TIntInst(
        '10@2019-09-01 00:00:00+01')
    assert TIntInst(expected_tintinst).endInstant == TIntInst(
        '10@2019-09-01 00:00:00+01')
    assert TIntInst(expected_tintinst).instantN(1) == TIntInst(
        '10@2019-09-01 00:00:00+01')
    assert TIntInst(expected_tintinst).instants == [
        TIntInst('10@2019-09-01 00:00:00+01')
    ]
    assert TIntInst(expected_tintinst).numTimestamps == 1
    assert TIntInst(expected_tintinst).startTimestamp == parse(
        '2019-09-01 00:00:00+01')
    assert TIntInst(expected_tintinst).endTimestamp == parse(
        '2019-09-01 00:00:00+01')
    assert TIntInst(expected_tintinst).timestampN(1) == parse(
        '2019-09-01 00:00:00+01')
    assert TIntInst(expected_tintinst).timestamps == [
        parse('2019-09-01 00:00:00+01')
    ]
    assert TIntInst(expected_tintinst).intersectsTimestamp(
        parse('2019-09-01 00:00:00+01')) == True
    assert TIntInst(expected_tintinst).intersectsTimestamp(
        parse('2019-09-02 00:00:00+01')) == False
    assert TIntInst(expected_tintinst).intersectsTimestampSet(
        TimestampSet(
            '{2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01}')) == True
    assert TIntInst(expected_tintinst).intersectsTimestampSet(
        TimestampSet(
            '{2019-09-02 00:00:00+01, 2019-09-03 00:00:00+01}')) == False
    assert TIntInst(expected_tintinst).intersectsPeriod(
        Period('[2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]')) == True
    assert TIntInst(expected_tintinst).intersectsPeriod(
        Period('(2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]')) == False
    assert TIntInst(expected_tintinst).intersectsPeriod(
        Period('[2019-09-02 00:00:00+01, 2019-09-03 00:00:00+01]')) == False
    assert TIntInst(expected_tintinst).intersectsPeriodSet(
        PeriodSet(
            '{[2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]}')) == True
    assert TIntInst(expected_tintinst).intersectsPeriodSet(
        PeriodSet(
            '{(2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]}')) == False
    assert TIntInst(expected_tintinst).intersectsPeriodSet(
        PeriodSet(
            '{[2019-09-02 00:00:00+01, 2019-09-03 00:00:00+01]}')) == False
コード例 #6
0
def test_tintinst_constructors(cursor, expected_tintinst):
    params = [TIntInst(expected_tintinst)]
    cursor.execute('INSERT INTO tbl_tintinst (temp) VALUES (%s)', params)
    cursor.execute('SELECT temp FROM tbl_tintinst WHERE temp=%s', params)
    result = cursor.fetchone()[0]
    assert result == TIntInst(expected_tintinst)
コード例 #7
0
    assert TIntInst(expected_tintinst).intersectsPeriod(
        Period('(2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]')) == False
    assert TIntInst(expected_tintinst).intersectsPeriod(
        Period('[2019-09-02 00:00:00+01, 2019-09-03 00:00:00+01]')) == False
    assert TIntInst(expected_tintinst).intersectsPeriodSet(
        PeriodSet('{[2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]}')) == True
    assert TIntInst(expected_tintinst).intersectsPeriodSet(
        PeriodSet('{(2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]}')) == False
    assert TIntInst(expected_tintinst).intersectsPeriodSet(
        PeriodSet('{[2019-09-02 00:00:00+01, 2019-09-03 00:00:00+01]}')) == False


@pytest.mark.parametrize('expected_tintinstset', [
    '{10@2019-09-01 00:00:00+01, 20@2019-09-02 00:00:00+01, 10@2019-09-03 00:00:00+01}',
    ('10@2019-09-01 00:00:00+01', '20@2019-09-02 00:00:00+01', '10@2019-09-03 00:00:00+01'),
    (TIntInst('10@2019-09-01 00:00:00+01'), TIntInst('20@2019-09-02 00:00:00+01'),
     TIntInst('10@2019-09-03 00:00:00+01')),
    ['10@2019-09-01 00:00:00+01', '20@2019-09-02 00:00:00+01', '10@2019-09-03 00:00:00+01'],
    [TIntInst('10@2019-09-01 00:00:00+01'), TIntInst('20@2019-09-02 00:00:00+01'),
     TIntInst('10@2019-09-03 00:00:00+01')],
])
def test_tintinstset_constructor(cursor, expected_tintinstset):
    if isinstance(expected_tintinstset, tuple):
        params = [TIntInstSet(*expected_tintinstset)]
    else:
        params = [TIntInstSet(expected_tintinstset)]
    cursor.execute('INSERT INTO tbl_tintinstset (temp) VALUES (%s)', params)
    cursor.execute('SELECT temp FROM tbl_tintinstset WHERE temp=%s', params)
    result = cursor.fetchone()[0]
    if isinstance(expected_tintinstset, tuple):
        assert result == TIntInstSet(*expected_tintinstset)