new: fix & add dispatch_table

This commit is contained in:
Wataru Otsubo 2024-09-12 21:36:13 +09:00 committed by qwjyh
parent ecbb3daa14
commit cb6e50b7dc
3 changed files with 82 additions and 15 deletions

View file

@ -277,3 +277,57 @@ function add_qaqc_single_result(
nothing
end
function prepare_dispatch_table(raw_dispatch_table::DataFrame)::DataFrame
df = copy(raw_dispatch_table, copycols = true)
transform!(
df,
[Symbol("Column$i") for i in 2:ncol(df)] => ByRow((s...) -> join(s |> skipmissing)) => :comment,
)
select!(df, [1, ncol(df)])
rename!(df, [:psboard_id, :comment])
transform!(
df,
:psboard_id => (vs -> accumulate(vs; init = 0) do x, y
ispsbid = startswith("PS")
if ispsbid(y)
x
else
match(r"(\d+)", y) |> first
end
end) => :campaign_id,
)
transform!(
df,
:psboard_id =>
ByRow(s -> startswith("PS")(s) ? parse(Int64, s[3:end]) : missing) =>
:psboard_id,
)
dropmissing!(df, :psboard_id)
df
end
function add_qaqcdispatch(db::SQLite.DB, dispatch_table::DataFrame)
dispatch_table = prepare_dispatch_table(dispatch_table)
# TODO: provide datetime
stmt = DBInterface.prepare(
db,
sql"""
INSERT INTO qaqc_dispatch(qaqc_campaign_id, psb_id, source_place, destination, time)
VALUES (:campaign_id, :psboard_id, "KEK", "GND", NULL)
""",
)
DBInterface.executemany(
stmt,
(
campaign_id = dispatch_table.campaign_id,
psboard_id = dispatch_table.psboard_id,
)
)
nothing
end