mirror of
https://gitlab.cern.ch/wotsubo/PSBoardDataBase.git
synced 2025-06-08 05:55:42 +09:00
new: fix & add dispatch_table
This commit is contained in:
parent
ecbb3daa14
commit
cb6e50b7dc
3 changed files with 82 additions and 15 deletions
|
@ -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
|
||||
|
|
|
@ -40,7 +40,8 @@ CREATE TABLE qaqc_dispatch (
|
|||
source_place TEXT NOT NULL,
|
||||
destination TEXT NOT NULL,
|
||||
time DATETIME,
|
||||
FOREIGN KEY("qaqc_campaign_id") REFERENCES "qaqc_campaigns"("id")
|
||||
FOREIGN KEY("qaqc_campaign_id") REFERENCES "qaqc_campaigns"("id"),
|
||||
FOREIGN KEY("psb_id") REFERENCES "ps_boards"("id")
|
||||
);
|
||||
|
||||
CREATE TABLE qaqc_campaigns (
|
||||
|
|
|
@ -5,24 +5,36 @@ using CSV, DataFrames
|
|||
true || include("../src/PSBoardDataBase.jl")
|
||||
|
||||
@testset "PSBoardDataBase" begin
|
||||
dbpath = tempname()
|
||||
db = PSBoardDataBase.create_database(dbpath)
|
||||
@info "" db
|
||||
@testset "prepare dataframe" begin
|
||||
@test PSBoardDataBase.prepare_dispatch_table(
|
||||
CSV.read("input/PS board QAQC Data Base - 出荷.csv", DataFrame),
|
||||
) isa DataFrame
|
||||
end
|
||||
|
||||
@test PSBoardDataBase.insert_qaqc_campaign_id(db) |> isnothing
|
||||
@test PSBoardDataBase.insert_qaqc_positions(db) |> isnothing
|
||||
@testset "full integrated test" begin
|
||||
dbpath = tempname()
|
||||
db = PSBoardDataBase.create_database(dbpath)
|
||||
@info "" db
|
||||
|
||||
single_result_df =
|
||||
CSV.read("input/PS board QAQC Data Base - 本番1回試験・追加検証試験.csv", DataFrame)
|
||||
runlist_table = CSV.read("input/PS board QAQC Data Base - RUNLIST.csv", DataFrame)
|
||||
@test PSBoardDataBase.insert_qaqc_campaign_id(db) |> isnothing
|
||||
@test PSBoardDataBase.insert_qaqc_positions(db) |> isnothing
|
||||
|
||||
@test PSBoardDataBase.prepare_single_result_df(single_result_df) isa DataFrame
|
||||
single_result_df =
|
||||
CSV.read("input/PS board QAQC Data Base - 本番1回試験・追加検証試験.csv", DataFrame)
|
||||
runlist_table = CSV.read("input/PS board QAQC Data Base - RUNLIST.csv", DataFrame)
|
||||
|
||||
@test PSBoardDataBase.add_psboard_ids(db, single_result_df) |> isnothing
|
||||
@test PSBoardDataBase.add_qaqc_runlist(db, runlist_table) |> isnothing
|
||||
@test PSBoardDataBase.prepare_single_result_df(single_result_df) isa DataFrame
|
||||
|
||||
@test PSBoardDataBase.add_qaqc_single_result(db, single_result_df, runlist_table) |>
|
||||
isnothing
|
||||
@test PSBoardDataBase.add_psboard_ids(db, single_result_df) |> isnothing
|
||||
@test PSBoardDataBase.add_qaqc_runlist(db, runlist_table) |> isnothing
|
||||
|
||||
run(`sqlitebrowser $dbpath`)
|
||||
@test PSBoardDataBase.add_qaqc_single_result(db, single_result_df, runlist_table) |>
|
||||
isnothing
|
||||
|
||||
dispatch_table = CSV.read("input/PS board QAQC Data Base - 出荷.csv", DataFrame)
|
||||
|
||||
@test PSBoardDataBase.add_qaqcdispatch(db, dispatch_table) |> isnothing
|
||||
|
||||
run(`sqlitebrowser $dbpath`)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue