From a4c29aa495bf76a50fc7e637138275249c960f0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frederik=20Hvilsh=C3=B8j?= <93145535+frederik-encord@users.noreply.github.com> Date: Wed, 5 Jul 2023 19:22:15 +0200 Subject: [PATCH] fix: annotator statistics dont crash if all scores are zero (#543) --- .../app/common/components/annotator_statistics.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/encord_active/app/common/components/annotator_statistics.py b/src/encord_active/app/common/components/annotator_statistics.py index 5534e0738..4d34fca8a 100644 --- a/src/encord_active/app/common/components/annotator_statistics.py +++ b/src/encord_active/app/common/components/annotator_statistics.py @@ -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( "
Distribution of annotations
", 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"]) @@ -32,14 +37,12 @@ def render_annotator_properties(df: DataFrame[MetricSchema]): "
Detailed annotator statistics
", 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)