started to disentangle
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter
|
||||
import pandas as pd
|
||||
|
||||
from singletons import grids, lib, PGroup
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.post("/tables/{pgroup}/append")
|
||||
def append(pgroup: PGroup, row: dict[str, Any]):
|
||||
now = datetime.now()
|
||||
|
||||
df = pd.DataFrame(row, index=[now])
|
||||
lib.append(pgroup, df)
|
||||
|
||||
now = str(now) # nicegui converts datetime to str
|
||||
row = {"index": now, **row} # setdefault would not force index to be the first column
|
||||
|
||||
res = []
|
||||
for grid in grids[pgroup]:
|
||||
grid.append(row)
|
||||
res.append(grid.options)
|
||||
|
||||
return res
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
from collections import defaultdict
|
||||
from typing import Annotated
|
||||
|
||||
import arcticdb as adb
|
||||
from fastapi import Path
|
||||
|
||||
from registry import Registry
|
||||
|
||||
|
||||
PGroup = Annotated[str, Path(pattern=r"^p\d{5}$")]
|
||||
|
||||
|
||||
uri = "lmdb://adb"
|
||||
ac = adb.Arctic(uri)
|
||||
|
||||
lib = ac.get_library(
|
||||
"stand",
|
||||
create_if_missing=True,
|
||||
library_options=adb.LibraryOptions(dynamic_schema=True)
|
||||
)
|
||||
|
||||
|
||||
grids = defaultdict(Registry)
|
||||
|
||||
|
||||
|
||||
@@ -1,44 +1,26 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from collections import defaultdict
|
||||
from datetime import datetime
|
||||
from typing import Annotated, Any
|
||||
|
||||
import arcticdb as adb
|
||||
import pandas as pd
|
||||
from fastapi import APIRouter, Path
|
||||
from nicegui import app, ui
|
||||
|
||||
from api import router as api_router
|
||||
|
||||
from auth.login import router as login_router
|
||||
from auth.logout import logout
|
||||
from auth.mw import AuthMiddleware
|
||||
from auth.secret import get_secret
|
||||
|
||||
from aggridx import aggridx
|
||||
from registry import Registry
|
||||
from singletons import grids, lib, PGroup
|
||||
|
||||
|
||||
app.include_router(login_router)
|
||||
app.add_middleware(AuthMiddleware)
|
||||
|
||||
|
||||
PGroup = Annotated[str, Path(pattern=r"^p\d{5}$")]
|
||||
|
||||
|
||||
uri = "lmdb://adb"
|
||||
ac = adb.Arctic(uri)
|
||||
|
||||
lib = ac.get_library(
|
||||
"stand",
|
||||
create_if_missing=True,
|
||||
library_options=adb.LibraryOptions(dynamic_schema=True)
|
||||
)
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
grids = defaultdict(Registry)
|
||||
|
||||
|
||||
OPTIONS = {
|
||||
":getRowId": "(params) => params.data.index", # set row ID to index column
|
||||
"context": {"pgroup": None},
|
||||
@@ -145,25 +127,8 @@ def table_deny(pgroup):
|
||||
ui.label(f"access to {pgroup} denied").classes("text-2xl")
|
||||
|
||||
|
||||
@router.post("/tables/{pgroup}/append")
|
||||
def append(pgroup: PGroup, row: dict[str, Any]):
|
||||
now = datetime.now()
|
||||
|
||||
df = pd.DataFrame(row, index=[now])
|
||||
lib.append(pgroup, df)
|
||||
|
||||
now = str(now) # nicegui converts datetime to str
|
||||
row = {"index": now, **row} # setdefault would not force index to be the first column
|
||||
|
||||
res = []
|
||||
for grid in grids[pgroup]:
|
||||
grid.append(row)
|
||||
res.append(grid.options)
|
||||
|
||||
return res
|
||||
|
||||
|
||||
app.include_router(router)
|
||||
app.include_router(api_router)
|
||||
|
||||
ui.run(
|
||||
title="stand",
|
||||
|
||||
Reference in New Issue
Block a user