Skip to content

Commit e10ec1d

Browse files
partial stubs for Datasources and a small portion of Time and Styling
1 parent 6e40860 commit e10ec1d

5 files changed

Lines changed: 176 additions & 29 deletions

File tree

oshconnect/datasource/__init__.py

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,14 @@
1-
def isDefined(v):
1+
from enum import Enum
2+
3+
4+
def is_defined(v):
25
return v is not None
36

4-
def randomUUID():
5-
return str(v)
67

7-
class Mode(enum):
8+
class Mode(Enum):
89
REPLAY = "replay"
910
BATCH = "batch"
1011
REAL_TIME = "realTime"
1112

12-
DATASOURCE_DATA_TOPIC = 'datasource-data-'
13-
batchsize = 1
14-
15-
16-
class DataSourceWorker:
17-
def __init__(self,dataSourceHandlers):
18-
self.dataSourceHandlers = dataSourceHandlers
19-
2013
class DataSourceHandler:
21-
def __init__(self,context,topic,broadcastChannel,values,version,properties,initialized):
22-
self.context = any
23-
self.topic = any
24-
self.broadcastChannel = any
25-
self.values = []
26-
self.values = 0
27-
self.properties = batchsize
28-
self.initialized = False
29-
30-
31-
def handleIsInit(self,eventData, resp):
32-
dsId = eventData.dsId
33-
resp.data = self.dataSourceHandlers(dsId).isInitalized()
34-
self.postMessage(resp)
35-
36-
37-
14+
datasources
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
from uuid import uuid4
2+
3+
from oshconnect.datasource import Mode
4+
5+
6+
class DataSource:
7+
8+
def __init__(self, name: str, mode: Mode, properties: dict):
9+
self._id = f'datasource-{uuid4()}'
10+
self.name = name
11+
self.mode = mode
12+
self.properties = properties
13+
14+
def get_id(self) -> str:
15+
return self._id
16+
17+
def get_name(self):
18+
pass
19+
20+
def create_process(self):
21+
pass
22+
23+
def terminate_process(self):
24+
pass
25+
26+
# Might not be necessary
27+
def subscribe(self):
28+
pass
29+
30+
def update_properties(self, properties: dict):
31+
# TODO: need to stop in progress sub-processes and restart
32+
self.properties = properties
33+
34+
def initialize(self):
35+
pass
36+
37+
def connect(self):
38+
pass
39+
40+
def disconnect(self):
41+
pass
42+
43+
def reset(self):
44+
pass
45+
46+
def get_status(self):
47+
pass
48+
49+
50+
class DatasourceHandler:
51+
datasource_map: dict[str, DataSource]
52+
53+
def __init__(self):
54+
self.datasource_map = {}
55+
56+
def add_datasource(self, datasource: DataSource):
57+
self.datasource_map[datasource.get_id()] = datasource
58+
59+
def initialize_ds(self, datasource_id: str, properties: dict):
60+
ds = self.datasource_map.get(datasource_id)
61+
ds.initialize()
62+
63+
def initialize_all(self):
64+
# list comp is faster than for loop
65+
[ds.initialize() for ds in self.datasource_map.values()]
66+
67+
def connect_ds(self, datasource_id: str):
68+
ds = self.datasource_map.get(datasource_id)
69+
ds.connect()
70+
71+
def connect_all(self):
72+
[ds.connect() for ds in self.datasource_map.values()]
73+
74+
def disconnect_ds(self, datasource_id: str):
75+
ds = self.datasource_map.get(datasource_id)
76+
ds.disconnect()
77+
78+
def disconnect_all(self):
79+
[ds.disconnect() for ds in self.datasource_map.values()]

oshconnect/datasource/handler.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from abc import ABC, abstractmethod
2+
3+
4+
# Might not be necessary due to differences in this implementation die to actual multiprocessing
5+
class DataSourceHandler(ABC):
6+
def __init__(self):
7+
self.context = None
8+
self.topic = None
9+
self.broadcast_channel = None
10+
self.values = []
11+
self.version = 0
12+
self.properties = {
13+
"batchsize": 1
14+
}
15+
self._initialized = False
16+
self.datasource_id = None
17+
18+
@abstractmethod
19+
def create_context(self, properties: dict):
20+
pass
21+
22+
async def init(self, datasource_id: str, properties: dict, topics: list[str]):
23+
self.datasource_id = datasource_id
24+
self.properties.update(properties)
25+
self.topic = self.set_topics(topics)
26+
# Context doesn't really have to exist in python
27+
self.context = self.create_context(properties)
28+
self.context.on_change_status = self.on_change_status()
29+
self.context.handle_data = self.handle_data()
30+
await self.context.init(self.properties)
31+
self._initialized = True
32+
33+
# TODO: topics may not be necessary
34+
def set_topics(self, topics):
35+
_topic = topics.data
36+
if self.topic == _topic:
37+
return
38+
return
39+
40+
def on_change_status(self):
41+
pass
42+
43+
def handle_data(self):
44+
pass
45+
46+
def flush(self):
47+
pass
48+
49+
def connect(self):
50+
pass
51+
52+
def disconnect(self):
53+
pass
54+
55+
def is_initialized(self):
56+
return self._initialized
57+
58+
def is_connected(self):
59+
pass

oshconnect/styling/__init__.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from abc import ABC
2+
from typing import Callable
3+
4+
from pydantic import BaseModel
5+
6+
7+
class VisualizationDataLayer(BaseModel):
8+
"""
9+
Represents the data portion of a particular visualization as well as its state information.
10+
"""
11+
12+
name: str
13+
description: str
14+
datasource_id: list[str]
15+
visible: bool
16+
timestamp: float
17+
_get_timestamp: Callable
18+
on_left_click: Callable
19+
on_right_click: Callable
20+
on_hover: Callable
21+
_id: str
22+
_type: str
23+
_filter: dict
24+
_datasources_to_fn: Callable
25+
_no_datasources_fn: Callable

oshconnect/timemanagement/timemanagement.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,10 @@ def get_buffer_time(self):
107107

108108
def _compute_time_range(self):
109109
pass
110+
111+
112+
class Synchronizer:
113+
_buffer: any
114+
115+
def synchronize(self, systems: list):
116+
pass

0 commit comments

Comments
 (0)