Spaces:
Runtime error
Runtime error
Commit
β’
5f2c2db
1
Parent(s):
abb2057
Update app.py
Browse files
app.py
CHANGED
@@ -70,39 +70,49 @@ import altair as alt
|
|
70 |
import pandas as pd
|
71 |
import os
|
72 |
|
|
|
|
|
|
|
|
|
73 |
def progress_bar_chart() -> alt.Chart:
|
74 |
source_dataset, _ = obtain_source_target_datasets()
|
75 |
-
total_records = int(os.getenv("TARGET_RECORDS")) #
|
76 |
-
annotated_records = len(source_dataset) #
|
77 |
pending_records = total_records - annotated_records # Calculate the pending records.
|
78 |
percentage_complete = annotated_records / total_records * 100 # The percentage of completion.
|
79 |
|
80 |
-
#
|
81 |
progress_data = pd.DataFrame({
|
82 |
-
'category': ['
|
83 |
-
'percentage': [percentage_complete]
|
84 |
-
})
|
85 |
-
|
86 |
-
# Create a DataFrame for the annotation label.
|
87 |
-
annotation_label = pd.DataFrame({
|
88 |
-
'category': ['Pending'],
|
89 |
-
'percentage': [percentage_complete],
|
90 |
-
'label': [f'{pending_records} / {annotated_records}']
|
91 |
})
|
92 |
|
93 |
# Create the progress bar chart.
|
94 |
-
progress_bar = alt.Chart(progress_data).mark_bar(
|
95 |
-
x=alt.X('percentage:Q', axis=alt.Axis(title='Completion Percentage', format='%'), scale=alt.Scale(domain=(0, 100)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
)
|
97 |
|
98 |
-
#
|
99 |
-
|
100 |
-
|
101 |
-
text
|
|
|
|
|
|
|
102 |
)
|
103 |
|
104 |
-
# Combine the
|
105 |
-
chart = (progress_bar +
|
106 |
title='Progress Towards Goal',
|
107 |
width=700
|
108 |
)
|
@@ -110,6 +120,7 @@ def progress_bar_chart() -> alt.Chart:
|
|
110 |
return chart
|
111 |
|
112 |
|
|
|
113 |
def donut_chart() -> alt.Chart:
|
114 |
"""
|
115 |
This function returns a donut chart with the number of annotated and pending records.
|
|
|
70 |
import pandas as pd
|
71 |
import os
|
72 |
|
73 |
+
import altair as alt
|
74 |
+
import pandas as pd
|
75 |
+
import os
|
76 |
+
|
77 |
def progress_bar_chart() -> alt.Chart:
|
78 |
source_dataset, _ = obtain_source_target_datasets()
|
79 |
+
total_records = int(os.getenv("TARGET_RECORDS")) # The total goal of records.
|
80 |
+
annotated_records = len(source_dataset) # The number of records already annotated.
|
81 |
pending_records = total_records - annotated_records # Calculate the pending records.
|
82 |
percentage_complete = annotated_records / total_records * 100 # The percentage of completion.
|
83 |
|
84 |
+
# Data for the progress bar chart.
|
85 |
progress_data = pd.DataFrame({
|
86 |
+
'category': ['Completed', 'Pending'],
|
87 |
+
'percentage': [percentage_complete, 100 - percentage_complete]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
})
|
89 |
|
90 |
# Create the progress bar chart.
|
91 |
+
progress_bar = alt.Chart(progress_data).mark_bar(size=40).encode(
|
92 |
+
x=alt.X('percentage:Q', axis=alt.Axis(title='Completion Percentage', format='%'), scale=alt.Scale(domain=(0, 100))),
|
93 |
+
color=alt.Color('category:N', scale=alt.Scale(domain=['Completed', 'Pending'], range=['#85C1E9', '#F1948A']))
|
94 |
+
)
|
95 |
+
|
96 |
+
# Create the annotation text for the completed part.
|
97 |
+
completed_text = alt.Chart(pd.DataFrame({
|
98 |
+
'percentage': [percentage_complete / 2],
|
99 |
+
'text': [f'{annotated_records} Completed']
|
100 |
+
})).mark_text(align='left', dx=5, fontSize=12, fontWeight='bold').encode(
|
101 |
+
x='percentage:Q',
|
102 |
+
text='text:N'
|
103 |
)
|
104 |
|
105 |
+
# Create the annotation text for the pending part.
|
106 |
+
pending_text = alt.Chart(pd.DataFrame({
|
107 |
+
'percentage': [percentage_complete + (100 - percentage_complete) / 2],
|
108 |
+
'text': [f'{pending_records} Pending']
|
109 |
+
})).mark_text(align='left', dx=5, fontSize=12, fontWeight='bold').encode(
|
110 |
+
x='percentage:Q',
|
111 |
+
text='text:N'
|
112 |
)
|
113 |
|
114 |
+
# Combine the bar and the texts.
|
115 |
+
chart = (progress_bar + completed_text + pending_text).properties(
|
116 |
title='Progress Towards Goal',
|
117 |
width=700
|
118 |
)
|
|
|
120 |
return chart
|
121 |
|
122 |
|
123 |
+
|
124 |
def donut_chart() -> alt.Chart:
|
125 |
"""
|
126 |
This function returns a donut chart with the number of annotated and pending records.
|