Spaces:
Runtime error
Runtime error
Commit
β’
ead70d9
1
Parent(s):
731d628
Update app.py
Browse files
app.py
CHANGED
@@ -109,51 +109,58 @@ def gauge_chart() -> alt.Chart:
|
|
109 |
return (chart + text)
|
110 |
|
111 |
|
|
|
|
|
|
|
|
|
112 |
def progress_bar_chart() -> alt.Chart:
|
|
|
113 |
source_dataset, _ = obtain_source_target_datasets()
|
114 |
-
total_records = int(os.getenv("TARGET_RECORDS"))
|
115 |
-
annotated_records = len(source_dataset)
|
116 |
-
percentage_complete = annotated_records / total_records * 100
|
117 |
|
118 |
-
#
|
119 |
progress_data = pd.DataFrame({
|
120 |
-
'
|
121 |
-
'
|
122 |
-
'actual': [annotated_records, total_records - annotated_records]
|
123 |
})
|
124 |
|
125 |
-
#
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
tooltip=['status', 'actual']
|
130 |
-
).properties(
|
131 |
-
title='Progress Towards Goal',
|
132 |
-
width=800,
|
133 |
-
height=200 # Increased height for a thicker bar
|
134 |
)
|
135 |
|
136 |
-
#
|
137 |
-
|
138 |
-
|
139 |
-
).configure_view(
|
140 |
-
strokeWidth=0
|
141 |
)
|
142 |
|
143 |
-
#
|
144 |
-
|
145 |
-
|
146 |
-
text=alt.Text('actual:N'),
|
147 |
-
color=alt.value('black') # Black text color
|
148 |
)
|
149 |
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
|
|
155 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
156 |
|
|
|
157 |
|
158 |
def donut_chart() -> alt.Chart:
|
159 |
"""
|
|
|
109 |
return (chart + text)
|
110 |
|
111 |
|
112 |
+
import altair as alt
|
113 |
+
import pandas as pd
|
114 |
+
import os
|
115 |
+
|
116 |
def progress_bar_chart() -> alt.Chart:
|
117 |
+
# Load your data
|
118 |
source_dataset, _ = obtain_source_target_datasets()
|
119 |
+
total_records = int(os.getenv("TARGET_RECORDS"))
|
120 |
+
annotated_records = len(source_dataset)
|
121 |
+
percentage_complete = annotated_records / total_records * 100
|
122 |
|
123 |
+
# Define the data for the bars
|
124 |
progress_data = pd.DataFrame({
|
125 |
+
'category': ['Completed', 'Pending'],
|
126 |
+
'value': [annotated_records, total_records - annotated_records]
|
|
|
127 |
})
|
128 |
|
129 |
+
# Base chart for the progress
|
130 |
+
base = alt.Chart(progress_data).encode(
|
131 |
+
alt.X('value:Q', scale=alt.Scale(domain=[0, total_records]), title='Number of Records'),
|
132 |
+
alt.Y('category:N', title='')
|
|
|
|
|
|
|
|
|
|
|
133 |
)
|
134 |
|
135 |
+
# Colored bar for completion
|
136 |
+
bar = base.mark_bar(size=50, color='#28a745').transform_filter(
|
137 |
+
alt.datum.category == 'Completed'
|
|
|
|
|
138 |
)
|
139 |
|
140 |
+
# Gray bar for pending
|
141 |
+
background = base.mark_bar(size=50, color='#dcdcdc').transform_filter(
|
142 |
+
alt.datum.category == 'Pending'
|
|
|
|
|
143 |
)
|
144 |
|
145 |
+
# Text for the completed records
|
146 |
+
text = base.mark_text(align='left', dx=3, dy=0, fontSize=16, fontWeight='bold', color='black').encode(
|
147 |
+
text='value:Q'
|
148 |
+
).transform_filter(
|
149 |
+
alt.datum.category == 'Completed'
|
150 |
+
)
|
151 |
|
152 |
+
# Combine the charts
|
153 |
+
chart = alt.layer(background, bar, text).resolve_scale(y='independent').properties(
|
154 |
+
width=700,
|
155 |
+
height=400,
|
156 |
+
title='Progress Towards Goal'
|
157 |
+
).configure_view(
|
158 |
+
strokeWidth=0
|
159 |
+
).configure_axis(
|
160 |
+
grid=False
|
161 |
+
)
|
162 |
|
163 |
+
return chart
|
164 |
|
165 |
def donut_chart() -> alt.Chart:
|
166 |
"""
|