Skip to content

Commit eeca531

Browse files
authored
Support dataset module for iotdb in ainode (#15686)
1 parent fb86a96 commit eeca531

File tree

5 files changed

+479
-0
lines changed

5 files changed

+479
-0
lines changed

iotdb-core/ainode/ainode/core/config.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ def __init__(self):
5252
# log directory
5353
self._ain_logs_dir: str = AINODE_LOG_DIR
5454

55+
# cache size for ingress dataloader (MB)
56+
self._ain_data_cache_size = 50
57+
5558
# Directory to save models
5659
self._ain_models_dir = AINODE_MODELS_DIR
5760

@@ -94,6 +97,12 @@ def get_build_info(self) -> str:
9497
def set_build_info(self, build_info: str) -> None:
9598
self._build_info = build_info
9699

100+
def get_ain_data_storage_cache_size(self) -> int:
101+
return self._ain_data_cache_size
102+
103+
def set_ain_data_cache_size(self, ain_data_cache_size: int) -> None:
104+
self._ain_data_cache_size = ain_data_cache_size
105+
97106
def set_version_info(self, version_info: str) -> None:
98107
self._version_info = version_info
99108

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
#
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
#
18+
from torch.utils.data import Dataset
19+
20+
from ainode.core.ingress.iotdb import IoTDBTableModelDataset, IoTDBTreeModelDataset
21+
from ainode.core.util.decorator import singleton
22+
23+
24+
class BasicDatabaseDataset(Dataset):
25+
def __init__(self, ip: str, port: int):
26+
self.ip = ip
27+
self.port = port
28+
29+
30+
class BasicDatabaseForecastDataset(BasicDatabaseDataset):
31+
def __init__(self, ip: str, port: int, input_len: int, output_len: int):
32+
super().__init__(ip, port)
33+
self.input_len = input_len
34+
self.output_len = output_len
35+
36+
37+
def register_dataset(key: str, dataset: Dataset):
38+
DatasetFactory().register(key, dataset)
39+
40+
41+
@singleton
42+
class DatasetFactory(object):
43+
44+
def __init__(self):
45+
self.dataset_list = {
46+
"iotdb.table": IoTDBTableModelDataset,
47+
"iotdb.tree": IoTDBTreeModelDataset,
48+
}
49+
50+
def register(self, key: str, dataset: Dataset):
51+
if key not in self.dataset_list:
52+
self.dataset_list[key] = dataset
53+
else:
54+
raise KeyError(f"Dataset {key} already exists")
55+
56+
def deregister(self, key: str):
57+
del self.dataset_list[key]
58+
59+
def get_dataset(self, key: str):
60+
if key not in self.dataset_list.keys():
61+
raise KeyError(f"Dataset {key} does not exist")
62+
return self.dataset_list[key]

0 commit comments

Comments
 (0)