Exemplo n.º 1
0
def test_in_daterange(data):
    metadata = data["ch4"]["metadata"]
    data = data["ch4"]["data"]

    d = Datasource()
    d._uuid = "test-id-123"
    d.add_data(metadata=metadata, data=data, data_type="timeseries")
    d.save()

    expected_keys = [
        "data/uuid/test-id-123/v1/2014-01-30-11:12:30+00:00_2014-11-30-11:23:30+00:00",
        "data/uuid/test-id-123/v1/2015-01-30-11:12:30+00:00_2015-11-30-11:23:30+00:00",
        "data/uuid/test-id-123/v1/2016-04-02-06:52:30+00:00_2016-11-02-12:54:30+00:00",
        "data/uuid/test-id-123/v1/2017-02-18-06:36:30+00:00_2017-12-18-15:41:30+00:00",
        "data/uuid/test-id-123/v1/2018-02-18-15:42:30+00:00_2018-12-18-15:42:30+00:00",
        "data/uuid/test-id-123/v1/2019-02-03-17:38:30+00:00_2019-12-09-10:47:30+00:00",
        "data/uuid/test-id-123/v1/2020-02-01-18:08:30+00:00_2020-12-01-22:31:30+00:00",
    ]

    assert d.data_keys() == expected_keys

    start = pd.Timestamp("2014-1-1")
    end = pd.Timestamp("2014-2-1")
    daterange = create_daterange_str(start=start, end=end)

    dated_keys = d.keys_in_daterange_str(daterange=daterange)

    assert dated_keys[0].split(
        "/")[-1] == "2014-01-30-11:12:30+00:00_2014-11-30-11:23:30+00:00"
Exemplo n.º 2
0
def test_versioning(data):
    # Take head of data
    # Then add the full data, check versioning works correctly
    metadata = {"foo": "bar"}

    d = Datasource()
    # Fix the UUID for the tests
    d._uuid = "4b91f73e-3d57-47e4-aa13-cb28c35d3b3d"

    ch4_data = data["ch4"]["data"]

    v1 = ch4_data.head(20)
    v2 = ch4_data.head(30)
    v3 = ch4_data.head(40)

    d.add_data(metadata=metadata, data=v1, data_type="timeseries")

    d.save()

    d.add_data(metadata=metadata, data=v2, data_type="timeseries")

    d.save()

    d.add_data(metadata=metadata, data=v3, data_type="timeseries")

    d.save()

    keys = d.versions()

    assert keys["v1"]["keys"] == {
        "2014-01-30-11:12:30+00:00_2014-11-30-11:23:30+00:00":
        "data/uuid/4b91f73e-3d57-47e4-aa13-cb28c35d3b3d/v1/2014-01-30-11:12:30+00:00_2014-11-30-11:23:30+00:00",
        "2015-01-30-11:12:30+00:00_2015-01-30-11:19:30+00:00":
        "data/uuid/4b91f73e-3d57-47e4-aa13-cb28c35d3b3d/v1/2015-01-30-11:12:30+00:00_2015-01-30-11:19:30+00:00",
    }
    assert keys["v2"]["keys"] == {
        "2014-01-30-11:12:30+00:00_2014-11-30-11:23:30+00:00":
        "data/uuid/4b91f73e-3d57-47e4-aa13-cb28c35d3b3d/v2/2014-01-30-11:12:30+00:00_2014-11-30-11:23:30+00:00",
        "2015-01-30-11:12:30+00:00_2015-01-30-11:19:30+00:00":
        "data/uuid/4b91f73e-3d57-47e4-aa13-cb28c35d3b3d/v2/2015-01-30-11:12:30+00:00_2015-01-30-11:19:30+00:00",
        "2015-01-30-11:12:30+00:00_2015-11-30-11:17:30+00:00":
        "data/uuid/4b91f73e-3d57-47e4-aa13-cb28c35d3b3d/v2/2015-01-30-11:12:30+00:00_2015-11-30-11:17:30+00:00",
    }
    assert keys["v3"]["keys"] == {
        "2014-01-30-11:12:30+00:00_2014-11-30-11:23:30+00:00":
        "data/uuid/4b91f73e-3d57-47e4-aa13-cb28c35d3b3d/v3/2014-01-30-11:12:30+00:00_2014-11-30-11:23:30+00:00",
        "2015-01-30-11:12:30+00:00_2015-01-30-11:19:30+00:00":
        "data/uuid/4b91f73e-3d57-47e4-aa13-cb28c35d3b3d/v3/2015-01-30-11:12:30+00:00_2015-01-30-11:19:30+00:00",
        "2015-01-30-11:12:30+00:00_2015-11-30-11:17:30+00:00":
        "data/uuid/4b91f73e-3d57-47e4-aa13-cb28c35d3b3d/v3/2015-01-30-11:12:30+00:00_2015-11-30-11:17:30+00:00",
        "2015-01-30-11:12:30+00:00_2015-11-30-11:23:30+00:00":
        "data/uuid/4b91f73e-3d57-47e4-aa13-cb28c35d3b3d/v3/2015-01-30-11:12:30+00:00_2015-11-30-11:23:30+00:00",
        "2016-04-02-06:52:30+00:00_2016-04-02-06:55:30+00:00":
        "data/uuid/4b91f73e-3d57-47e4-aa13-cb28c35d3b3d/v3/2016-04-02-06:52:30+00:00_2016-04-02-06:55:30+00:00",
    }

    assert keys["v3"]["keys"] == keys["latest"]["keys"]