dvilasuero HF staff commited on
Commit
ead70d9
β€’
1 Parent(s): 731d628

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -31
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")) # The total goal of records.
115
- annotated_records = len(source_dataset) # The number of records already annotated.
116
- percentage_complete = annotated_records / total_records * 100 # The percentage of completion.
117
 
118
- # Create a DataFrame for the progress bar data.
119
  progress_data = pd.DataFrame({
120
- 'status': ['Completed', 'Pending'],
121
- 'percentage': [percentage_complete, 100 - percentage_complete],
122
- 'actual': [annotated_records, total_records - annotated_records]
123
  })
124
 
125
- # Create the progress bar chart.
126
- progress_bar = alt.Chart(progress_data).mark_bar(size=60).encode(
127
- x=alt.X('percentage:Q', scale=alt.Scale(domain=[0, 100]), axis=alt.Axis(title='Completion Percentage', format='%')),
128
- color=alt.Color('status:N', scale=alt.Scale(domain=['Completed', 'Pending'], range=['#28a745', '#dcdcdc'])),
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
- # Remove the unnecessary axis lines and ticks.
137
- chart = progress_bar.configure_axis(
138
- grid=False
139
- ).configure_view(
140
- strokeWidth=0
141
  )
142
 
143
- # Add text labels for completed and pending outside the bar.
144
- text_labels = alt.Chart(progress_data).mark_text(align='left', dx=5, dy=0, fontSize=16, fontWeight='bold').encode(
145
- x=alt.X('percentage:Q', stack='zero'),
146
- text=alt.Text('actual:N'),
147
- color=alt.value('black') # Black text color
148
  )
149
 
150
- return (chart + text_labels)
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
  """