mirror of
https://gitlab.cern.ch/wotsubo/psboard-qaqc-analysis.git
synced 2024-12-04 21:11:07 +09:00
68 lines
1.3 KiB
Julia
68 lines
1.3 KiB
Julia
using CSV
|
|
using DataFrames
|
|
using GLMakie
|
|
|
|
"""
|
|
mapping to unique numbers
|
|
"""
|
|
function unique_num(v)
|
|
uniques = unique(v)
|
|
mapping = Dict(uniques .=> eachindex(uniques))
|
|
map(v) do x
|
|
mapping[x]
|
|
end
|
|
end
|
|
|
|
df = CSV.read("ps_all.csv", DataFrame)
|
|
dropmissing!(df, :position)
|
|
|
|
gdf = groupby(df, :position)
|
|
|
|
df_stacked = let
|
|
preheaders = [:qspip, :recov, :power, :clock]
|
|
postheaders = map(preheaders) do sym
|
|
Symbol("n" * string(sym))
|
|
end
|
|
df = combine(
|
|
gdf,
|
|
preheaders .=> (v -> count(v .!= 1)) .=> postheaders,
|
|
)
|
|
|
|
stack(df, postheaders)
|
|
end
|
|
|
|
transform!(
|
|
df_stacked,
|
|
:position => unique_num => :position_id,
|
|
)
|
|
transform!(
|
|
df_stacked,
|
|
:variable => unique_num => :variable_id,
|
|
)
|
|
|
|
colors = Makie.wong_colors()
|
|
fig = Figure()
|
|
ax = Axis(
|
|
fig[1, 1],
|
|
title = "failed ones",
|
|
xlabel = "position",
|
|
xticks = (df_stacked.position_id, df_stacked.position),
|
|
xticklabelrotation = π / 3,
|
|
ylabel = "counts",
|
|
)
|
|
barplot!(
|
|
ax,
|
|
df_stacked.position_id,
|
|
df_stacked.value,
|
|
stack = df_stacked.variable_id,
|
|
color = colors[df_stacked.variable_id |> collect],
|
|
)
|
|
|
|
Legend(
|
|
fig[1, 2],
|
|
[PolyElement(polycolor = colors[i]) for i in df_stacked.variable_id |> unique],
|
|
df_stacked.variable |> unique,
|
|
"entries",
|
|
)
|
|
|
|
save("failed_reasons.png", fig)
|