test_collection.py 2.66 KB
Newer Older
matthmey's avatar
matthmey committed
1
2
'''MIT License

matthmey's avatar
matthmey committed
3
4
Copyright (c) 2019, Swiss Federal Institute of Technology (ETH Zurich), Matthias Meyer

matthmey's avatar
matthmey committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.'''

matthmey's avatar
matthmey committed
24
25
import stuett
from pathlib import Path
matthmey's avatar
matthmey committed
26
import pandas as pd
matthmey's avatar
matthmey committed
27
28
29
30
31
32
33
34
35
36
37
38
39

test_data_dir = Path(__file__).absolute().parent.joinpath("..", "data")
stuett.global_config.set_setting("user_dir", test_data_dir.joinpath("user_dir/"))


def test_collector():
    filename = Path(test_data_dir).joinpath(
        "timeseries", "MH30_temperature_rock_2017.csv"
    )

    node = stuett.data.CsvSource(filename)
    minmax_rate2 = stuett.data.MinMaxDownsampling(rate=2, dim="time")

matthmey's avatar
matthmey committed
40
    print("creating delayed node")
matthmey's avatar
matthmey committed
41
42
    x = node(delayed=True)

matthmey's avatar
matthmey committed
43
44
    print("downsampled delayed node")
    downsampled = minmax_rate2(x, delayed=True)
matthmey's avatar
matthmey committed
45

matthmey's avatar
matthmey committed
46
47
48
    print("DataCollector node")
    data_paths = [x, downsampled]
    granularities = [stuett.to_timedelta(180, "s"), stuett.to_timedelta(2, "d")]
matthmey's avatar
matthmey committed
49
50
    collector_node = stuett.data.DataCollector(data_paths, granularities)

matthmey's avatar
matthmey committed
51
52
    print("Instatiating DataCollector node")
    request = {"start_time": "2017-08-01", "end_time": "2017-08-02"}
matthmey's avatar
matthmey committed
53
54
55
    path = collector_node(request=request)
    # print(type(path))

matthmey's avatar
matthmey committed
56
    print("Configuration node")
matthmey's avatar
matthmey committed
57
58
59

    import dask

matthmey's avatar
matthmey committed
60
    dsk, dsk_keys = dask.base._extract_graph_and_keys([path])
61
    print(dict(dsk))
matthmey's avatar
matthmey committed
62

matthmey's avatar
matthmey committed
63
    path = stuett.core.configuration(path, request)
matthmey's avatar
matthmey committed
64
65
66
67
68

    dsk, dsk_keys = dask.base._extract_graph_and_keys([path])
    print(dsk)

    print(type(path))
matthmey's avatar
matthmey committed
69
    print("executing delayed node")
matthmey's avatar
matthmey committed
70
71
72
73
74
75
76
    print(path.compute())

    # request = {'start_time':'2017-08-01 10:01:00', 'end_time':'2017-08-01 10:02:00'}
    # path = collector_node(request=request)
    # path = stuett.core.configuration(path,request)
    # print(path.compute())

matthmey's avatar
matthmey committed
77
78

test_collector()