Skip to content

Commit

Permalink
Populate missing unit
Browse files Browse the repository at this point in the history
  • Loading branch information
TLCFEM committed Dec 14, 2024
1 parent 910e9b7 commit df817bf
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 28 deletions.
2 changes: 2 additions & 0 deletions src/mb/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ async def download_single_random_waveform(normalised: bool = False):
endpoint="/waveform/jackpot",
time_interval=interval,
waveform=record.tolist(),
processed_data_unit="cm/s/s",
)


Expand Down Expand Up @@ -229,6 +230,7 @@ def _populate_waveform(result: Record):
endpoint="/waveform",
time_interval=interval,
waveform=record.tolist(),
processed_data_unit="cm/s/s",
)

return ListRecordResponse(
Expand Down
5 changes: 4 additions & 1 deletion src/mb/app/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ def process_record_local(result: Record, process_config: ProcessConfig):
)

record = ProcessedResponse(
**result.model_dump(), endpoint="/process", process_config=process_config
**result.model_dump(),
endpoint="/process",
process_config=process_config,
processed_data_unit="cm/s/s",
)

time_interval, waveform = result.to_waveform(
Expand Down
7 changes: 3 additions & 4 deletions src/mb/app/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,11 @@ def normalise(cls, values):
return values

def filter(self, window, up_ratio: int = 1):
new_waveform: np.ndarray = apply_filter(
window * up_ratio, zero_stuff(up_ratio, self.waveform)
)
self.time_interval /= up_ratio
# noinspection PyTypeChecker
self.waveform = new_waveform.tolist()
self.waveform = apply_filter(
window * up_ratio, zero_stuff(up_ratio, self.waveform)
).tolist()

def to_spectrum(self):
if self.time_interval is None or self.waveform is None:
Expand Down
46 changes: 23 additions & 23 deletions src/mb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,26 +164,25 @@ async def download(
async with anyio.create_task_group() as tg:
for r in record:
tg.start_soon(self.download, r)
else:
record_id: str = record.id if isinstance(record, MBRecord) else record

async with self.semaphore:
result = await self.client.post("/waveform", json=[str(record_id)])
self.current_download_size += 1
if result.status_code != HTTPStatus.OK:
self.print(
f"Fail to download file [green]{record_id}[/]. "
f"[[red]{self.current_download_size}/{self.download_size}[/]]."
)
else:
self.download_pool.append(MBRecord(**result.json()["records"][0]))
self.print(
f"Successfully downloaded file [green]{record_id}[/]. "
f"[[red]{self.current_download_size}/{self.download_size}[/]]."
)

return

record_id: str = record.id if isinstance(record, MBRecord) else record

async with self.semaphore:
result = await self.client.post("/waveform", json=[str(record_id)])
self.current_download_size += 1
if result.status_code != HTTPStatus.OK:
self.print(
f"Fail to download file [green]{record_id}[/]. "
f"[[red]{self.current_download_size}/{self.download_size}[/]]."
)
return

self.download_pool.append(MBRecord(**result.json()["records"][0]))
self.print(
f"Successfully downloaded file [green]{record_id}[/]. "
f"[[red]{self.current_download_size}/{self.download_size}[/]]."
)
return self

async def upload(
self,
Expand Down Expand Up @@ -259,7 +258,9 @@ async def jackpot(self) -> MBRecord | None:
async def search(self, query: QueryConfig | dict) -> list[MBRecord] | None:
result = await self.client.post(
"/query",
json=query.model_dump() if isinstance(query, QueryConfig) else query,
json=query.model_dump(exclude_none=True)
if isinstance(query, QueryConfig)
else query,
)
if result.status_code != HTTPStatus.OK:
self.print("[red]Failed to perform query.[/]")
Expand Down Expand Up @@ -289,11 +290,10 @@ async def status(self):


async def main():
async with MBClient("http://localhost:8000", "test", "password") as client:
async with MBClient("http://170.64.176.26:8000") as client:
results = await client.search(QueryConfig())
await client.download(results)
fig: Figure = None # type: ignore
for result in client:
for result in await client.download(results):
fig = result.plot_spectrum(fig)
fig.legend()
fig.tight_layout()
Expand Down

0 comments on commit df817bf

Please sign in to comment.