dvilasuero HF staff commited on
Commit
2d89a48
1 Parent(s): 05f090f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -24
app.py CHANGED
@@ -64,42 +64,49 @@ def get_user_annotations_dictionary(
64
 
65
 
66
 
67
- def donut_chart() -> alt.Chart:
68
- """
69
- This function returns a donut chart with the number of annotated and pending records.
70
-
71
- Returns:
72
- An altair chart with the donut chart.
73
- """
74
 
 
 
75
  source_dataset, _ = obtain_source_target_datasets()
76
- annotated_records = len(source_dataset)
77
- pending_records = int(os.getenv("TARGET_RECORDS")) - annotated_records
78
-
79
- source = pd.DataFrame(
80
- {
81
- "values": [annotated_records, pending_records],
82
- "category": ["Submitted", "Pending"], # Add a new column for categories
83
- }
84
- )
85
 
 
86
  base = alt.Chart(source).encode(
87
- theta=alt.Theta("values:Q", stack=True),
88
- radius=alt.Radius(
89
- "values", scale=alt.Scale(type="sqrt", zero=True, rangeMin=20)
90
- ),
91
- color=alt.Color("category:N", legend=alt.Legend(title="Category")),
92
  )
93
 
94
- c1 = base.mark_arc(innerRadius=20, stroke="#fff")
 
95
 
96
- c2 = base.mark_text(radiusOffset=10).encode(text="values:Q")
 
 
 
 
 
 
 
97
 
98
- chart = c1 + c2
 
99
 
100
  return chart
101
 
102
 
 
103
  def kpi_chart() -> alt.Chart:
104
  """
105
  This function returns a KPI chart with the total amount of annotators.
 
64
 
65
 
66
 
67
+ import altair as alt
68
+ import pandas as pd
69
+ import os
 
 
 
 
70
 
71
+ def donut_chart() -> alt.Chart:
72
+ # Load your data
73
  source_dataset, _ = obtain_source_target_datasets()
74
+ pending_records = len(source_dataset)
75
+ annotated_records = int(os.getenv("TARGET_RECORDS")) - annotated_records
76
+
77
+ # Prepare data for the donut chart
78
+ source = pd.DataFrame({
79
+ "values": [annotated_records, pending_records],
80
+ "category": ["Submitted", "Pending"],
81
+ "color": ["#28a745", "#dcdcdc"] # Green for submitted, grey for pending
82
+ })
83
 
84
+ # Create the base of the donut chart
85
  base = alt.Chart(source).encode(
86
+ theta=alt.Theta(field="values", type="quantitative", stack=True),
87
+ color=alt.Color(field="color", type="nominal", legend=None), # Use the colors defined in the DataFrame
88
+ tooltip=["category", "values"]
 
 
89
  )
90
 
91
+ # Create the arcs for the donut chart
92
+ arcs = base.mark_arc(innerRadius=100, outerRadius=120, stroke="#fff")
93
 
94
+ # Add text labels in the middle of the donut chart
95
+ text = base.mark_text(radius=140, size=20, align='center').encode(
96
+ text=alt.Text("values:Q"),
97
+ angle=alt.Angle(field="values", type="quantitative", aggregate='sum', stack=True) # Calculate the mid-angle position for the labels
98
+ )
99
+
100
+ # Combine the arcs and text
101
+ chart = arcs + text
102
 
103
+ # Set the chart background to transparent
104
+ chart = chart.configure_view(strokeOpacity=0)
105
 
106
  return chart
107
 
108
 
109
+
110
  def kpi_chart() -> alt.Chart:
111
  """
112
  This function returns a KPI chart with the total amount of annotators.