re-ordered
This commit is contained in:
+5
-5
@@ -13,19 +13,19 @@ router = APIRouter()
|
||||
|
||||
@router.post("/tables/{pgroup}/append")
|
||||
def append(beamline: Beamline, pgroup: PGroup, run: int, row: dict[str, Any]):
|
||||
timestamp = row.pop("timestamp", None)
|
||||
timestamp = datetime.fromisoformat(timestamp) if timestamp else datetime.now()
|
||||
row = {"timestamp": timestamp, **row} # setdefault would not force timestamp to be the first column
|
||||
lib = adb.get(beamline)
|
||||
|
||||
index = pd.Timestamp(run) # adb supports update only for timeseries indexes
|
||||
index = pd.Index([index], name="run")
|
||||
|
||||
lib = adb.get(beamline)
|
||||
|
||||
run_exists = not lib.read(pgroup, date_range=index, columns=[]).data.index.empty
|
||||
if run_exists:
|
||||
raise HTTPException(409, f"run {run} exists already in {beamline}/{pgroup}")
|
||||
|
||||
timestamp = row.pop("timestamp", None)
|
||||
timestamp = datetime.fromisoformat(timestamp) if timestamp else datetime.now()
|
||||
row = {"timestamp": timestamp, **row} # setdefault would not force timestamp to be the first column
|
||||
|
||||
df = pd.DataFrame(row, index=index)
|
||||
lib.append(pgroup, df)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user