add b2b
This commit is contained in:
parent
ca7415cc0c
commit
6973dc619f
@ -7,7 +7,8 @@ import zmq
|
|||||||
|
|
||||||
from flandre.config import C
|
from flandre.config import C
|
||||||
from flandre.nodes.Node import Node
|
from flandre.nodes.Node import Node
|
||||||
from flandre.utils.Msg import BMMsg, ImageArgMsg, SetSeqMetaMsg, Msg, RfFrameWithMetaMsg, BeamformerMsg, RequestRfFrameMsg, \
|
from flandre.utils.Msg import BMMsg, ImageArgMsg, SetSeqMetaMsg, Msg, RfFrameWithMetaMsg, BeamformerMsg, \
|
||||||
|
RequestRfFrameMsg, \
|
||||||
SeqMetaMsg
|
SeqMetaMsg
|
||||||
from flandre.utils.RfFile import RfSequenceMeta
|
from flandre.utils.RfFile import RfSequenceMeta
|
||||||
from flandre.utils.RfMat import RfMat
|
from flandre.utils.RfMat import RfMat
|
||||||
@ -20,12 +21,12 @@ class Beamformer(Node):
|
|||||||
|
|
||||||
def __init__(self, level=logging.INFO):
|
def __init__(self, level=logging.INFO):
|
||||||
super(Beamformer, self).__init__(level=level)
|
super(Beamformer, self).__init__(level=level)
|
||||||
self.req_muxer_socket: zmq.Socket = None
|
self.muxer_req_socket: zmq.Socket = None
|
||||||
|
|
||||||
def custom_setup(self):
|
def custom_setup(self):
|
||||||
self.req_muxer_socket: zmq.Socket = self.c.ctx.socket(zmq.REQ)
|
self.muxer_req_socket: zmq.Socket = self.c.ctx.socket(zmq.REQ)
|
||||||
self.req_muxer_socket.connect('tcp://localhost:5560')
|
self.muxer_req_socket.connect(C.muxer_rep_socket)
|
||||||
self.c.poller.register(self.req_muxer_socket, zmq.POLLIN)
|
self.c.poller.register(self.muxer_req_socket, zmq.POLLIN)
|
||||||
|
|
||||||
def process(self, data: RfMat, arg: ImageArgMsg):
|
def process(self, data: RfMat, arg: ImageArgMsg):
|
||||||
if data is None:
|
if data is None:
|
||||||
@ -44,12 +45,12 @@ class Beamformer(Node):
|
|||||||
def loop(self):
|
def loop(self):
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
while True:
|
while True:
|
||||||
self.req_muxer_socket.send(b'')
|
self.muxer_req_socket.send(b'')
|
||||||
r = dict(self.c.poller.poll())
|
r = dict(self.c.poller.poll())
|
||||||
if self.c.sub in r:
|
if self.c.sub in r:
|
||||||
msg = self.recv()
|
msg = self.recv()
|
||||||
if self.req_muxer_socket in r:
|
if self.muxer_req_socket in r:
|
||||||
msg:BeamformerMsg = Msg.decode_msg(self.req_muxer_socket.recv())
|
msg: BeamformerMsg = Msg.decode_msg(self.muxer_req_socket.recv())
|
||||||
if msg.value == b'init':
|
if msg.value == b'init':
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
continue
|
continue
|
||||||
|
|||||||
@ -109,6 +109,8 @@ class RfFrameMeta(RfMeta):
|
|||||||
robot_force_pitch: Annotated[int, 'FRY'] = None
|
robot_force_pitch: Annotated[int, 'FRY'] = None
|
||||||
robot_force_yal: Annotated[int, 'FRZ'] = None
|
robot_force_yal: Annotated[int, 'FRZ'] = None
|
||||||
|
|
||||||
|
blake2b: Annotated[str, 'B2B'] = None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class RfSequenceMeta(RfMeta):
|
class RfSequenceMeta(RfMeta):
|
||||||
|
|||||||
@ -1,24 +1,34 @@
|
|||||||
|
import hashlib
|
||||||
import json
|
import json
|
||||||
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import zipfile
|
import zipfile
|
||||||
import zstd
|
import zstd
|
||||||
|
import click
|
||||||
|
|
||||||
TEMP_FOLDER = Path('/mnt/16T/private_dataset/New Folder/temp')
|
TEMP_FOLDER = Path('/mnt/16T/private_dataset/New Folder/temp')
|
||||||
|
|
||||||
|
|
||||||
def folder_to_zip(folder: Path):
|
def folder_to_zip(folder: Path):
|
||||||
|
shutil.rmtree(TEMP_FOLDER)
|
||||||
|
TEMP_FOLDER.mkdir(parents=True, exist_ok=True)
|
||||||
from flandre.utils.RfMeta import RfFrameMeta
|
from flandre.utils.RfMeta import RfFrameMeta
|
||||||
for i, file in enumerate(folder.glob('*')):
|
for i, file in enumerate(folder.glob('*')):
|
||||||
file = Path(file)
|
file = Path(file)
|
||||||
print(i, file, RfFrameMeta.from_path(file).json_str)
|
|
||||||
|
b2b = hashlib.blake2b(file.read_bytes(), digest_size=4).hexdigest()
|
||||||
|
meta = RfFrameMeta.from_path(file)
|
||||||
|
meta.blake2b = b2b
|
||||||
|
print(i, b2b, file, meta.json_str)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
src = file
|
src = file
|
||||||
dst = TEMP_FOLDER / f'{i}.zst'
|
dst = TEMP_FOLDER / f'{i}.zst'
|
||||||
dstj = TEMP_FOLDER / f'{i}.json'
|
dstj = TEMP_FOLDER / f'{i}.json'
|
||||||
|
|
||||||
dstj.write_text(RfFrameMeta.from_path(file).json_str)
|
dstj.write_text(meta.json_str)
|
||||||
|
|
||||||
subprocess.run(['zstd', '-f', src, '-o', dst])
|
subprocess.run(['zstd', '-f', src, '-o', dst])
|
||||||
subprocess.run(['zip', '-0', '-j', '-r', TEMP_FOLDER.parent / f'{folder.name}.zip', TEMP_FOLDER])
|
subprocess.run(['zip', '-0', '-j', '-r', TEMP_FOLDER.parent / f'{folder.name}.zip', TEMP_FOLDER])
|
||||||
@ -29,17 +39,19 @@ def zip_to_bytes(file: Path, name: int):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
pass
|
||||||
|
# cli()
|
||||||
# folder_to_zip(Path('/mnt/16T/private_dataset/us/R1,U=30,M=PWI,S=(256 1502)'))
|
# folder_to_zip(Path('/mnt/16T/private_dataset/us/R1,U=30,M=PWI,S=(256 1502)'))
|
||||||
# r = get(Path('/mnt/16T/private_dataset/New Folder/ST,U=60,M=FMC,S=(256 256 3002).zip'), 3)
|
# r = get(Path('/mnt/16T/private_dataset/New Folder/ST,U=60,M=FMC,S=(256 256 3002).zip'), 3)
|
||||||
# print(r.__len__())
|
# print(r.__len__())
|
||||||
# r = Path('/mnt/16T/private_dataset/New Folder/ST,U=60,M=FMC,S=(256 256 3002)/X=-204.bin').read_bytes()
|
# r = Path('/mnt/16T/private_dataset/New Folder/ST,U=60,M=FMC,S=(256 256 3002)/X=-204.bin').read_bytes()
|
||||||
# print(r.__len__())
|
# print(r.__len__())
|
||||||
p = Path('/mnt/16T/private_dataset/us/R1,U=30,M=PWI,S=(256 1502).zip')
|
# p = Path('/mnt/16T/private_dataset/New Folder/R1,U=90,M=PWI,S=(256 4502)')
|
||||||
# #
|
# #
|
||||||
archive = zipfile.ZipFile(p)
|
# archive = zipfile.ZipFile(p)
|
||||||
for item in archive.infolist():
|
# for item in archive.infolist():
|
||||||
print(int(Path(item.filename).stem))
|
# print(int(Path(item.filename).stem))
|
||||||
print()
|
# print()
|
||||||
# # imgfile = archive.open('img_01.png')
|
# # imgfile = archive.open('img_01.png')
|
||||||
# print(archive.filelist)
|
# print(archive.filelist)
|
||||||
# p2 = archive.open('X=20,Y=395.bin')
|
# p2 = archive.open('X=20,Y=395.bin')
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import dataclasses
|
import dataclasses
|
||||||
|
import hashlib
|
||||||
import inspect
|
import inspect
|
||||||
import sys
|
import sys
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
@ -27,21 +28,22 @@ if __name__ == '__main__':
|
|||||||
# print(inspect.getmembers(ASD))
|
# print(inspect.getmembers(ASD))
|
||||||
# for f in dataclasses.fields(ASD):
|
# for f in dataclasses.fields(ASD):
|
||||||
# print(f.name, f.type)
|
# print(f.name, f.type)
|
||||||
p = Path('asd')
|
# p = Path('asd')
|
||||||
pt = type(p)
|
# pt = type(p)
|
||||||
print(pt)
|
# print(pt)
|
||||||
print(pt.__name__)
|
# print(pt.__name__)
|
||||||
print(type(type(p)))
|
# print(type(type(p)))
|
||||||
match pt:
|
# match pt:
|
||||||
case _x if isinstance(_x, PosixPath):
|
# case _x if isinstance(_x, PosixPath):
|
||||||
print(-2)
|
# print(-2)
|
||||||
case type(__name__='PosixPath'):
|
# case type(__name__='PosixPath'):
|
||||||
print(-1)
|
# print(-1)
|
||||||
case type():
|
# case type():
|
||||||
print(0)
|
# print(0)
|
||||||
case Path():
|
# case Path():
|
||||||
print(1)
|
# print(1)
|
||||||
case PosixPath():
|
# case PosixPath():
|
||||||
print(3)
|
# print(3)
|
||||||
case _:
|
# case _:
|
||||||
print(2)
|
# print(2)
|
||||||
|
print()
|
||||||
|
|||||||
25
tool.py
Normal file
25
tool.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import click
|
||||||
|
|
||||||
|
from flandre.utils.archive import folder_to_zip
|
||||||
|
|
||||||
|
|
||||||
|
@click.group()
|
||||||
|
def cli():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command()
|
||||||
|
@click.argument('folder')
|
||||||
|
def f2z(folder):
|
||||||
|
folder_to_zip(Path(folder))
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command()
|
||||||
|
def dropdb():
|
||||||
|
click.echo('Dropped the database')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
cli()
|
||||||
Loading…
Reference in New Issue
Block a user