diff --git a/stand/adb.py b/stand/adb.py index ba4d7ae..afdad38 100644 --- a/stand/adb.py +++ b/stand/adb.py @@ -1,4 +1,5 @@ import arcticdb as adb +import pandas as pd class ArcticDB(adb.Arctic): @@ -6,13 +7,35 @@ class ArcticDB(adb.Arctic): exceptions = adb.exceptions def get(self, name): - return self.get_library( + return ArcticLibrary(self.get_library( name, create_if_missing=True, library_options=adb.LibraryOptions( dynamic_schema=True ) - ) + )) + + + +class ArcticLibrary: + + def __init__(self, lib): + self.lib = lib + + def __getattr__(self, name): + return getattr(self.lib, name) + + + def get_data(self, *args, **kwargs): + try: + df = self.lib.read(*args, **kwargs).data + except adb.exceptions.NoSuchVersionException: + df = pd.DataFrame() + + df.index = df.index.view("int64") # adb supports update only for timeseries indexes + df.index.name = "run" + + return df diff --git a/stand/api.py b/stand/api.py index 5f94b2d..5c57c3c 100644 --- a/stand/api.py +++ b/stand/api.py @@ -14,13 +14,7 @@ router = APIRouter() @router.get("/pgroups/{pgroup}") def get_pgroup(beamline: Beamline, pgroup: PGroup, orient: str = None): - try: - df = adb.get(beamline).read(pgroup).data - except adb.exceptions.NoSuchVersionException: - df = pd.DataFrame() - - df.index = df.index.view("int64") # adb supports update only for timeseries indexes - df.index.name = "run" + df = adb.get(beamline).get_data(pgroup) content = df.to_json(orient=orient) return Response(content=content, media_type="application/json") diff --git a/stand/table.py b/stand/table.py index f4612eb..1fe3a01 100644 --- a/stand/table.py +++ b/stand/table.py @@ -51,13 +51,7 @@ def table_show(pgroup, beamline): # btn.icon = "sym_o_left_panel_close" if ld.value else "sym_o_left_panel_open" # btn = ui.button(icon="sym_o_left_panel_open", on_click=cb).props("flat dense") - try: - df = adb.get(beamline).read(pgroup).data - except adb.exceptions.NoSuchVersionException: - df = pd.DataFrame() - - df.index = df.index.view("int64") # adb supports update only for timeseries indexes - df.index.name = "run" + df = adb.get(beamline).get_data(pgroup) df = df.reset_index() options = OPTIONS.copy()