-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre01.py
More file actions
53 lines (42 loc) · 1.28 KB
/
pre01.py
File metadata and controls
53 lines (42 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import time
import logging
import fastdb4py as fdb
from pydantic import BaseModel
from python.snaking.src.snaking import Snaking, Role, FdbFilePath, FdbShmName
logging.basicConfig(level=logging.DEBUG)
class Point(fdb.Feature):
x: fdb.F64
y: fdb.F64
z: fdb.F64
class InputModel(BaseModel):
db_path: FdbFilePath
class OutputModel(BaseModel):
shm_name: FdbShmName
def main(input: InputModel) -> OutputModel:
time.sleep(3) # simulate some preprocessing work
db_path = input.db_path
db = fdb.ORM.truncate([
fdb.TableDefn(Point, 99, 'points')
])
ps = db[Point]['points']
for i in range(99):
p = ps[i]
p.x = float(i)
p.y = float(i)
p.z = float(i)
db.save(db_path)
logging.info(f"Database saved at {db_path}")
db = fdb.ORM.load(db_path, from_file=True)
ps = db[Point]['points']
for i in range(99):
p = ps[i]
logging.info(f"Point {i}: x={p.x}, y={p.y}, z={p.z}")
db.share('test-points', close_after=True)
db.close()
return OutputModel(shm_name='test-points')
if __name__ == '__main__':
snaking = Snaking('preprocessor-001', Role.PREPROCESSOR)
snaking.set_in(InputModel)
snaking.set_out(OutputModel)
snaking.set_once(main)
snaking.run()