Skip to content

Commit

Permalink
fix: annotator statistics dont crash if all scores are zero (#543)
Browse files Browse the repository at this point in the history
  • Loading branch information
frederik-encord authored Jul 5, 2023
1 parent bfb88dc commit a4c29aa
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/encord_active/app/common/components/annotator_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@
def render_annotator_properties(df: DataFrame[MetricSchema]):
annotators = get_annotator_level_info(df)
if len(annotators) == 0:
st.warning("Found no annotators")
return

left_col, right_col = st.columns([2, 2])
annotators_df = pd.DataFrame(list(annotators.values()))
total_annotations = annotators_df["total_annotations"].sum()
if not total_annotations:
st.warning("No annotations to show")
return

left_col, right_col = st.columns([2, 2])
# 1. Pie Chart
left_col.markdown(
"<h5 style='text-align: center; color: black;'>Distribution of annotations</h1>", unsafe_allow_html=True
)
annotators_df = pd.DataFrame(list(annotators.values()))

fig = px.pie(annotators_df, values="total_annotations", names="name", hover_data=["mean_score"])

Expand All @@ -32,14 +37,12 @@ def render_annotator_properties(df: DataFrame[MetricSchema]):
"<h5 style='text-align: center; color: black;'>Detailed annotator statistics</h1>", unsafe_allow_html=True
)

total_annotations = annotators_df["total_annotations"].sum()
total_mean_score = (annotators_df["mean_score"] * annotators_df["total_annotations"]).sum() / total_annotations

info = AnnotatorInfo(name="all", total_annotations=total_annotations, mean_score=total_mean_score)
annotators_df = pd.concat([annotators_df, pd.Series(info).to_frame().T], ignore_index=True)

deviation = (annotators_df["mean_score"] - total_mean_score) / total_mean_score * 100
annotators_df["deviation"] = deviation
annotators_df["deviation"] = (annotators_df["mean_score"] - total_mean_score) / (total_mean_score or 1) * 100

right_col.dataframe(annotators_df.style.pipe(make_pretty), use_container_width=True)

Expand Down

0 comments on commit a4c29aa

Please sign in to comment.