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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -25
app.py CHANGED
@@ -62,10 +62,6 @@ def get_user_annotations_dictionary(
62
 
63
  return output
64
 
65
- import altair as alt
66
- import pandas as pd
67
- import os
68
-
69
 
70
  def gauge_chart() -> alt.Chart:
71
  # Assuming obtain_source_target_datasets() returns a tuple where the first item is the dataset
@@ -112,47 +108,47 @@ def gauge_chart() -> alt.Chart:
112
 
113
  return (chart + text)
114
 
 
115
  def progress_bar_chart() -> alt.Chart:
116
  source_dataset, _ = obtain_source_target_datasets()
117
  total_records = int(os.getenv("TARGET_RECORDS")) # The total goal of records.
118
  annotated_records = len(source_dataset) # The number of records already annotated.
119
- pending_records = total_records - annotated_records # Calculate the pending records.
120
  percentage_complete = annotated_records / total_records * 100 # The percentage of completion.
121
 
122
  # Create a DataFrame for the progress bar data.
123
  progress_data = pd.DataFrame({
124
- 'status': ['Pending','Completed'],
125
  'percentage': [percentage_complete, 100 - percentage_complete],
126
- 'actual': [pending_records, annotated_records]
127
  })
128
 
129
  # Create the progress bar chart.
130
- progress_bar = alt.Chart(progress_data).mark_bar(size=40).encode(
131
- x=alt.X('percentage:Q', axis=alt.Axis(title='Completion Percentage', format='%')),
132
- color=alt.Color('status:N', scale=alt.Scale(domain=['Pending','Completed'], range=['#28a745', '#dcdcdc'])),
133
  tooltip=['status', 'actual']
 
 
 
 
134
  )
135
 
136
- # Create the annotation text.
137
- text = progress_data.iloc[0]['actual'] # Get the 'Completed' actual number.
138
- label_text = alt.Chart(pd.DataFrame({'x_pos': [percentage_complete / 2], 'text': [f'{text} Completed']})).mark_text(
139
- align='center', dy=-10, fontSize=16, fontWeight='bold', color='white'
140
- ).encode(
141
- x='x_pos:Q',
142
- text='text:N'
143
  )
144
 
145
- # Combine the bar and the label into a layered chart.
146
- chart = alt.layer(progress_bar, label_text).properties(
147
- title='Progress Towards Goal',
148
- width=800,
149
- height=150
150
  )
151
 
152
- # Configure the whole chart instead of individual elements.
153
- chart = chart.configure_axis(grid=False).configure_view(strokeWidth=0)
154
 
155
- return chart
156
 
157
 
158
 
 
62
 
63
  return output
64
 
 
 
 
 
65
 
66
  def gauge_chart() -> alt.Chart:
67
  # Assuming obtain_source_target_datasets() returns a tuple where the first item is the dataset
 
108
 
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