psboard-qaqc-analysis/analysis.jl

69 lines
1.3 KiB
Julia
Raw Permalink Normal View History

2024-07-27 17:58:35 +09:00
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)