Skip to content

Commit d0197cd

Browse files
committed
Code cleanup
1 parent 85e1b1c commit d0197cd

File tree

3 files changed

+35
-21
lines changed

3 files changed

+35
-21
lines changed

superannotate/analytics/class_analytics.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
from .common import aggregate_annotations_as_df
2-
1+
import json
2+
import logging
33
from pathlib import Path
4+
5+
import pandas as pd
46
import plotly.express as px
5-
from plotly.subplots import make_subplots
67
import plotly.graph_objects as go
7-
import pandas as pd
8+
from plotly.subplots import make_subplots
89

9-
import json
10-
import logging
10+
from .common import aggregate_annotations_as_df
1111

1212
logger = logging.getLogger("superannotate-python-sdk")
1313

@@ -19,7 +19,7 @@ def class_distribution(export_root, project_names, visualize=False):
1919
:type export_root: Pathlike (str or Path)
2020
:param project_names: list of project names to aggregate through
2121
:type project_names: list of str
22-
:param visulaize: enables class histogram plot
22+
:param visualize: enables class histogram plot
2323
:type visualize: bool
2424
:return: DataFrame on class distribution with columns ["className", "count"]
2525
:rtype: pandas DataFrame
@@ -72,7 +72,7 @@ def attribute_distribution(export_root, project_names, visualize=False):
7272
:type project_names: list of str
7373
:param visulaize: enables attribute histogram plot
7474
:type visualize: bool
75-
:return: DataFrame on attribute distribution with columns ["className", "attributeGroupName", "attributeName", "count"]
75+
:return: DataFrame on attribute distribution with columns ["className", "attributeGroupName", "attributeName", "count"]
7676
:rtype: pandas DataFrame
7777
"""
7878

superannotate/analytics/user_analytics.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import pandas as pd
2-
from tqdm import tqdm
32
import plotly.express as px
43

5-
def image_analytics(annotations_df, visualize = False):
4+
5+
def image_analytics(annotations_df, visualize=False):
66
"""
77
Aggregates image analytics: num instances/annotation time in seconds per image
88
:param annotations_df: pandas DataFrame of project annotations
99
:type annotations_df: pandas.DataFrame
10-
:param visulaize: enables image analytics scatter plot
10+
:param visualize: enables image analytics scatter plot
1111
:type visualize: bool
1212
1313
:return: DataFrame on image analytics with columns ["userEmail", "userRole", "imageName", "annotationTime", "instanceCount"]
@@ -19,16 +19,26 @@ def fix_spent_time(grp: pd.Series) -> pd.Series:
1919
grp_lost_msk = (grp > 600) | (grp.isna())
2020
grp.loc[grp_lost_msk] = grp[~grp_lost_msk].median()
2121
return grp
22-
23-
analytics = {"userEmail": [], "userRole": [], "imageName": [], "annotationTime": [], "instanceCount": [] }
24-
annot_cols = ["imageName", "instanceId", "createdAt", "creatorEmail", "creatorRole"]
25-
annotations_df = annotations_df[annotations_df["creationType"] == "Manual"][annot_cols].drop_duplicates()
22+
23+
analytics = {
24+
"userEmail": [],
25+
"userRole": [],
26+
"imageName": [],
27+
"annotationTime": [],
28+
"instanceCount": []
29+
}
30+
annot_cols = [
31+
"imageName", "instanceId", "createdAt", "creatorEmail", "creatorRole"
32+
]
33+
annotations_df = annotations_df[annotations_df["creationType"] == "Manual"
34+
][annot_cols].drop_duplicates()
2635

2736
for annot, grp in annotations_df.groupby(["creatorEmail", "creatorRole"]):
2837
grp_sorted = grp.sort_values("createdAt")
2938
time_spent = grp_sorted.createdAt.diff().shift(-1).dt.total_seconds()
3039
grp["time_spent"] = fix_spent_time(time_spent)
31-
img_time = grp.groupby("imageName", as_index=False)["time_spent"].agg("sum")
40+
img_time = grp.groupby("imageName",
41+
as_index=False)["time_spent"].agg("sum")
3242
img_n_instance = grp.groupby("imageName")["instanceId"].agg("count")
3343

3444
analytics["imageName"] += img_time.imageName.tolist()
@@ -46,8 +56,12 @@ def fix_spent_time(grp: pd.Series) -> pd.Series:
4656
y="annotationTime",
4757
color="userEmail",
4858
facet_col="userRole",
49-
custom_data = ["imageName"],
50-
labels = {'userEmail': "User Email", "instanceCount": "Number of Instances", "annotationTime": "Annotation time"},
59+
custom_data=["imageName"],
60+
labels={
61+
'userEmail': "User Email",
62+
"instanceCount": "Number of Instances",
63+
"annotationTime": "Annotation time"
64+
},
5165
color_discrete_sequence=px.colors.qualitative.Dark24,
5266
)
5367
fig.for_each_annotation(lambda a: a.update(text=a.text.split("=")[-1]))

tests/analytics/test_class_analytics.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import pytest
21
from pathlib import Path
3-
import superannotate as sa
42

5-
sa.init(Path.home() / ".superannotate" / "config.json")
3+
import pytest
4+
5+
import superannotate as sa
66

77
test_root = Path().resolve() / 'tests'
88

0 commit comments

Comments
 (0)