async def test_tfloatinst_constructors(connection, expected_tfloatinst):
    params = TFloatInst(expected_tfloatinst)
    await connection.execute('INSERT INTO tbl_tfloatinst (temp) VALUES ($1)',
                             params)
    result = await connection.fetchval(
        'SELECT temp FROM tbl_tfloatinst WHERE temp=$1', params, column=0)
    assert result == TFloatInst(expected_tfloatinst)
def test_tfloatseq_accessors(cursor, expected_tfloatseqseteq):
    assert TFloatSeq(expected_tfloatseqseteq).tempSubtype() == 'Sequence'
    # assert TFloatSeq(expected_tfloatseqseteq).getValues == [floatrange(10.0, 30.0, upper_inc=True)]
    assert TFloatSeq(expected_tfloatseqseteq).startValue == 10.0
    assert TFloatSeq(expected_tfloatseqseteq).endValue == 30.0
    assert TFloatSeq(expected_tfloatseqseteq).minValue == 10.0
    assert TFloatSeq(expected_tfloatseqseteq).maxValue == 30.0
    assert TFloatSeq(expected_tfloatseqseteq).valueRange == floatrange(
        10.0, 30.0, upper_inc=True)
    assert TFloatSeq(expected_tfloatseqseteq).getTime == PeriodSet(
        '{[2019-09-01 00:00:00+01, 2019-09-03 00:00:00+01]}')
    assert TFloatSeq(expected_tfloatseqseteq).duration == timedelta(2)
    assert TFloatSeq(expected_tfloatseqseteq).timespan == timedelta(2)
    assert TFloatSeq(expected_tfloatseqseteq).period == Period(
        '[2019-09-01 00:00:00+01, 2019-09-03 00:00:00+01]')
    assert TFloatSeq(expected_tfloatseqseteq).numInstants == 3
    assert TFloatSeq(expected_tfloatseqseteq).startInstant == TFloatInst(
        '10.0@2019-09-01 00:00:00+01')
    assert TFloatSeq(expected_tfloatseqseteq).endInstant == TFloatInst(
        '30.0@2019-09-03 00:00:00+01')
    assert TFloatSeq(expected_tfloatseqseteq).instantN(2) == TFloatInst(
        '20.0@2019-09-02 00:00:00+01')
    assert TFloatSeq(expected_tfloatseqseteq).instants == \
           [TFloatInst('10.0@2019-09-01 00:00:00+01'), TFloatInst('20.0@2019-09-02 00:00:00+01'),
            TFloatInst('30.0@2019-09-03 00:00:00+01')]
    assert TFloatSeq(expected_tfloatseqseteq).numTimestamps == 3
    assert TFloatSeq(expected_tfloatseqseteq).startTimestamp == parse(
        '2019-09-01 00:00:00+01')
    assert TFloatSeq(expected_tfloatseqseteq).endTimestamp == parse(
        '2019-09-03 00:00:00+01')
    assert TFloatSeq(expected_tfloatseqseteq).timestampN(2) == parse(
        '2019-09-02 00:00:00+01')
    assert TFloatSeq(expected_tfloatseqseteq).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 TFloatSeq(expected_tfloatseqseteq).intersectsTimestamp(
        parse('2019-09-01 00:00:00+01')) == True
    assert TFloatSeq(expected_tfloatseqseteq).intersectsTimestamp(
        parse('2019-09-04 00:00:00+01')) == False
    assert TFloatSeq(expected_tfloatseqseteq).intersectsTimestampSet(
        TimestampSet(
            '{2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01}')) == True
    assert TFloatSeq(expected_tfloatseqseteq).intersectsTimestampSet(
        TimestampSet(
            '{2019-09-04 00:00:00+01, 2019-09-05 00:00:00+01}')) == False
    assert TFloatSeq(expected_tfloatseqseteq).intersectsPeriod(
        Period('[2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]')) == True
    assert TFloatSeq(expected_tfloatseqseteq).intersectsPeriod(
        Period('[2019-09-04 00:00:00+01, 2019-09-05 00:00:00+01]')) == False
    assert TFloatSeq(expected_tfloatseqseteq).intersectsPeriodSet(
        PeriodSet(
            '{[2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]}')) == True
    assert TFloatSeq(expected_tfloatseqseteq).intersectsPeriodSet(
        PeriodSet(
            '{[2019-09-04 00:00:00+01, 2019-09-05 00:00:00+01]}')) == False
    [10.0, parse('2019-09-08 00:00:00+01')],
])
async def test_tfloatinst_constructors(connection, expected_tfloatinst):
    params = TFloatInst(expected_tfloatinst)
    await connection.execute('INSERT INTO tbl_tfloatinst (temp) VALUES ($1)',
                             params)
    result = await connection.fetchval(
        'SELECT temp FROM tbl_tfloatinst WHERE temp=$1', params, column=0)
    assert result == TFloatInst(expected_tfloatinst)


@pytest.mark.parametrize('expected_tfloatinstset', [
    '{10.0@2019-09-01 00:00:00+01, 20.0@2019-09-02 00:00:00+01, 10.0@2019-09-03 00:00:00+01}',
    ('10.0@2019-09-01 00:00:00+01', '20.0@2019-09-02 00:00:00+01',
     '10.0@2019-09-03 00:00:00+01'),
    (TFloatInst('10.0@2019-09-01 00:00:00+01'),
     TFloatInst('20.0@2019-09-02 00:00:00+01'),
     TFloatInst('10.0@2019-09-03 00:00:00+01')),
    [
        '10.0@2019-09-01 00:00:00+01', '20.0@2019-09-02 00:00:00+01',
        '10.0@2019-09-03 00:00:00+01'
    ],
    [
        TFloatInst('10.0@2019-09-01 00:00:00+01'),
        TFloatInst('20.0@2019-09-02 00:00:00+01'),
        TFloatInst('10.0@2019-09-03 00:00:00+01')
    ],
])
async def test_tfloatinstseq_constructor(connection, expected_tfloatinstset):
    if isinstance(expected_tfloatinstset, tuple):
        params = TFloatInstSet(*expected_tfloatinstset)
    '10.0@2019-09-01 00:00:00+01',
    ('10.0', '2019-09-08 00:00:00+01'),
    ['10.0', '2019-09-08 00:00:00+01'],
    (10.0, parse('2019-09-08 00:00:00+01')),
    [10.0, parse('2019-09-08 00:00:00+01')],
])
async def test_tfloatinst_constructors(connection, expected_tfloatinst):
    params = TFloatInst(expected_tfloatinst)
    await connection.execute('INSERT INTO tbl_tfloatinst (temp) VALUES ($1)', params)
    result = await connection.fetchval('SELECT temp FROM tbl_tfloatinst WHERE temp=$1', params, column=0)
    assert result == TFloatInst(expected_tfloatinst)

@pytest.mark.parametrize('expected_tfloati', [
    '{10.0@2019-09-01 00:00:00+01, 20.0@2019-09-02 00:00:00+01, 10.0@2019-09-03 00:00:00+01}',
    ('10.0@2019-09-01 00:00:00+01', '20.0@2019-09-02 00:00:00+01', '10.0@2019-09-03 00:00:00+01'),
    (TFloatInst('10.0@2019-09-01 00:00:00+01'), TFloatInst('20.0@2019-09-02 00:00:00+01'),
     TFloatInst('10.0@2019-09-03 00:00:00+01')),
    ['10.0@2019-09-01 00:00:00+01', '20.0@2019-09-02 00:00:00+01', '10.0@2019-09-03 00:00:00+01'],
    [TFloatInst('10.0@2019-09-01 00:00:00+01'), TFloatInst('20.0@2019-09-02 00:00:00+01'),
     TFloatInst('10.0@2019-09-03 00:00:00+01')],
])
async def test_tfloati_constructor(connection, expected_tfloati):
    if isinstance(expected_tfloati, tuple):
        params = TFloatI(*expected_tfloati)
    else:
        params = TFloatI(expected_tfloati)
    await connection.execute('INSERT INTO tbl_tfloati (temp) VALUES ($1)', params)
    result = await connection.fetchval('SELECT temp FROM tbl_tfloati WHERE temp=$1', params)
    if isinstance(expected_tfloati, tuple):
        assert result == TFloatI(*expected_tfloati)
    else:
示例#5
0
def test_tfloatinst_accessors(cursor, expected_tfloatinst):
    assert TFloatInst(expected_tfloatinst).duration() == 'Instant'
    assert TFloatInst(expected_tfloatinst).getValue == 10.0
    assert TFloatInst(expected_tfloatinst).getValues == [
        floatrange(10.0, 10.0, upper_inc=True)
    ]
    assert TFloatInst(expected_tfloatinst).startValue == 10.0
    assert TFloatInst(expected_tfloatinst).endValue == 10.0
    assert TFloatInst(expected_tfloatinst).minValue == 10.0
    assert TFloatInst(expected_tfloatinst).maxValue == 10.0
    assert TFloatInst(expected_tfloatinst).valueRange == floatrange(
        10.0, 10.0, upper_inc=True)
    assert TFloatInst(expected_tfloatinst).getTimestamp == parse(
        '2019-09-01 00:00:00+01')
    assert TFloatInst(expected_tfloatinst).getTime == PeriodSet(
        '{[2019-09-01 00:00:00+01, 2019-09-01 00:00:00+01]}')
    assert TFloatInst(expected_tfloatinst).timespan == timedelta(0)
    assert TFloatInst(expected_tfloatinst).period == Period(
        '[2019-09-01 00:00:00+01, 2019-09-01 00:00:00+01]')
    assert TFloatInst(expected_tfloatinst).numInstants == 1
    assert TFloatInst(expected_tfloatinst).startInstant == TFloatInst(
        '10.0@2019-09-01 00:00:00+01')
    assert TFloatInst(expected_tfloatinst).endInstant == TFloatInst(
        '10.0@2019-09-01 00:00:00+01')
    assert TFloatInst(expected_tfloatinst).instantN(1) == TFloatInst(
        '10.0@2019-09-01 00:00:00+01')
    assert TFloatInst(expected_tfloatinst).instants == [
        TFloatInst('10.0@2019-09-01 00:00:00+01')
    ]
    assert TFloatInst(expected_tfloatinst).numTimestamps == 1
    assert TFloatInst(expected_tfloatinst).startTimestamp == parse(
        '2019-09-01 00:00:00+01')
    assert TFloatInst(expected_tfloatinst).endTimestamp == parse(
        '2019-09-01 00:00:00+01')
    assert TFloatInst(expected_tfloatinst).timestampN(1) == parse(
        '2019-09-01 00:00:00+01')
    assert TFloatInst(expected_tfloatinst).timestamps == [
        parse('2019-09-01 00:00:00+01')
    ]
    assert TFloatInst(expected_tfloatinst).intersectsTimestamp(
        parse('2019-09-01 00:00:00+01')) == True
    assert TFloatInst(expected_tfloatinst).intersectsTimestamp(
        parse('2019-09-02 00:00:00+01')) == False
    assert TFloatInst(expected_tfloatinst).intersectsTimestampset(
        TimestampSet(
            '{2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01}')) == True
    assert TFloatInst(expected_tfloatinst).intersectsTimestampset(
        TimestampSet(
            '{2019-09-02 00:00:00+01, 2019-09-03 00:00:00+01}')) == False
    assert TFloatInst(expected_tfloatinst).intersectsPeriod(
        Period('[2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]')) == True
    assert TFloatInst(expected_tfloatinst).intersectsPeriod(
        Period('(2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]')) == False
    assert TFloatInst(expected_tfloatinst).intersectsPeriod(
        Period('[2019-09-02 00:00:00+01, 2019-09-03 00:00:00+01]')) == False
    assert TFloatInst(expected_tfloatinst).intersectsPeriodset(
        PeriodSet(
            '{[2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]}')) == True
    assert TFloatInst(expected_tfloatinst).intersectsPeriodset(
        PeriodSet(
            '{(2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]}')) == False
    assert TFloatInst(expected_tfloatinst).intersectsPeriodset(
        PeriodSet(
            '{[2019-09-02 00:00:00+01, 2019-09-03 00:00:00+01]}')) == False
示例#6
0
def test_tfloatinst_constructors(cursor, expected_tfloatinst):
    params = [TFloatInst(expected_tfloatinst)]
    cursor.execute('INSERT INTO tbl_tfloatinst (temp) VALUES (%s)', params)
    cursor.execute('SELECT temp FROM tbl_tfloatinst WHERE temp=%s', params)
    result = cursor.fetchone()[0]
    assert result == TFloatInst(expected_tfloatinst)
示例#7
0
from datetime import datetime, timedelta
from dateutil.parser import parse
from mobilitydb.time import TimestampSet, Period, PeriodSet
from mobilitydb.main import TFloat, TFloatInst, TFloatI, TFloatSeq, TFloatS

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

print("\nConstructors for TFloatI")
ti = TFloatI('{10@2019-09-08, 20@2019-09-09, 20@2019-09-10}')
print(ti)
ti = TFloatI('10@2019-09-08', '20@2019-09-09', '20@2019-09-10')
print(ti)
ti = TFloatI(['10@2019-09-08', '20@2019-09-09', '20@2019-09-10'])
print(ti)
t1 = TFloatInst('10@2019-09-08')
t2 = TFloatInst('20@2019-09-09')
t3 = TFloatInst('20@2019-09-10')
ti = TFloatI(t1, t2, t3)
print(ti)
ti = TFloatI([t1, t2, t3])
print(ti)

print("\nConstructors for TFloatSeq")
seq = TFloatSeq('[10@2019-09-08, 20@2019-09-09, 20@2019-09-10]')