Spaces:
Runtime error
Runtime error
Commit
β’
006da70
1
Parent(s):
1f73bb6
Update app.py
Browse files
app.py
CHANGED
@@ -78,6 +78,10 @@ import altair as alt
|
|
78 |
import pandas as pd
|
79 |
import os
|
80 |
|
|
|
|
|
|
|
|
|
81 |
def progress_bar_chart() -> alt.Chart:
|
82 |
source_dataset, _ = obtain_source_target_datasets()
|
83 |
total_records = int(os.getenv("TARGET_RECORDS")) # The total goal of records.
|
@@ -88,36 +92,39 @@ def progress_bar_chart() -> alt.Chart:
|
|
88 |
# Create a DataFrame for the progress bar data.
|
89 |
progress_data = pd.DataFrame({
|
90 |
'status': ['Completed', 'Pending'],
|
91 |
-
'percentage': [percentage_complete, 100 - percentage_complete]
|
92 |
-
|
93 |
-
|
94 |
-
# Create a DataFrame for the label.
|
95 |
-
label_data = pd.DataFrame({
|
96 |
-
'status': ['Label'],
|
97 |
-
'percentage': [50], # Centered label
|
98 |
-
'label': [f'{pending_records} Remaining / {total_records} Total']
|
99 |
})
|
100 |
|
101 |
# Create the progress bar chart.
|
102 |
progress_bar = alt.Chart(progress_data).mark_bar(size=40).encode(
|
103 |
-
x=alt.X('percentage:Q', axis=alt.Axis(title='Completion Percentage', format='%')
|
104 |
-
color=alt.Color('status:N', scale=alt.Scale(domain=['Completed', 'Pending'], range=['#28a745', '#dcdcdc']))
|
|
|
105 |
)
|
106 |
|
107 |
-
# Create the annotation text
|
108 |
-
|
109 |
-
|
110 |
-
|
|
|
|
|
|
|
111 |
)
|
112 |
|
113 |
-
#
|
114 |
-
|
|
|
|
|
|
|
|
|
115 |
title='Progress Towards Goal',
|
116 |
width=800,
|
117 |
height=150
|
118 |
)
|
119 |
|
120 |
-
return
|
|
|
121 |
|
122 |
|
123 |
|
|
|
78 |
import pandas as pd
|
79 |
import os
|
80 |
|
81 |
+
import altair as alt
|
82 |
+
import pandas as pd
|
83 |
+
import os
|
84 |
+
|
85 |
def progress_bar_chart() -> alt.Chart:
|
86 |
source_dataset, _ = obtain_source_target_datasets()
|
87 |
total_records = int(os.getenv("TARGET_RECORDS")) # The total goal of records.
|
|
|
92 |
# Create a DataFrame for the progress bar data.
|
93 |
progress_data = pd.DataFrame({
|
94 |
'status': ['Completed', 'Pending'],
|
95 |
+
'percentage': [percentage_complete, 100 - percentage_complete],
|
96 |
+
'actual': [annotated_records, pending_records]
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
})
|
98 |
|
99 |
# Create the progress bar chart.
|
100 |
progress_bar = alt.Chart(progress_data).mark_bar(size=40).encode(
|
101 |
+
x=alt.X('percentage:Q', axis=alt.Axis(title='Completion Percentage', format='%')),
|
102 |
+
color=alt.Color('status:N', scale=alt.Scale(domain=['Completed', 'Pending'], range=['#28a745', '#dcdcdc'])),
|
103 |
+
tooltip=['status', 'actual']
|
104 |
)
|
105 |
|
106 |
+
# Create the annotation text.
|
107 |
+
text = progress_data.iloc[0]['actual'] # Get the 'Completed' actual number.
|
108 |
+
label_text = alt.Chart(pd.DataFrame({'x_pos': [percentage_complete / 2], 'text': [f'{text} Completed']})).mark_text(
|
109 |
+
align='center', dy=-10, fontSize=16, fontWeight='bold', color='white'
|
110 |
+
).encode(
|
111 |
+
x='x_pos:Q',
|
112 |
+
text='text:N'
|
113 |
)
|
114 |
|
115 |
+
# Remove the unnecessary axis lines and ticks.
|
116 |
+
progress_bar = progress_bar.configure_axis(
|
117 |
+
grid=False
|
118 |
+
).configure_view(
|
119 |
+
strokeWidth=0
|
120 |
+
).properties(
|
121 |
title='Progress Towards Goal',
|
122 |
width=800,
|
123 |
height=150
|
124 |
)
|
125 |
|
126 |
+
return (progress_bar + label_text)
|
127 |
+
|
128 |
|
129 |
|
130 |
|