diff --git a/src/mb/app/main.py b/src/mb/app/main.py index 0678a0d..7d2e71e 100644 --- a/src/mb/app/main.py +++ b/src/mb/app/main.py @@ -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", ) @@ -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( diff --git a/src/mb/app/process.py b/src/mb/app/process.py index dc0bb07..12899b4 100644 --- a/src/mb/app/process.py +++ b/src/mb/app/process.py @@ -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( diff --git a/src/mb/app/response.py b/src/mb/app/response.py index 7bbe30a..bc771c9 100644 --- a/src/mb/app/response.py +++ b/src/mb/app/response.py @@ -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: diff --git a/src/mb/client.py b/src/mb/client.py index 4696aaa..dd83f6a 100644 --- a/src/mb/client.py +++ b/src/mb/client.py @@ -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, @@ -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.[/]") @@ -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()