added adb lib wrapper class to centralize some recurring operations

This commit is contained in:
2026-06-03 09:34:47 +02:00
parent 5235d69768
commit c64a9c31fb
3 changed files with 27 additions and 16 deletions
+25 -2
View File
@@ -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
+1 -7
View File
@@ -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")
+1 -7
View File
@@ -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()