dvilasuero HF Staff commited on
Commit
1f73bb6
Β·
verified Β·
1 Parent(s): 5f2c2db

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -21
app.py CHANGED
@@ -74,6 +74,10 @@ 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.
@@ -81,46 +85,43 @@ def progress_bar_chart() -> alt.Chart:
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
  )
119
 
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.
 
74
  import pandas as pd
75
  import os
76
 
77
+ 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.
 
85
  pending_records = total_records - annotated_records # Calculate the pending records.
86
  percentage_complete = annotated_records / total_records * 100 # The percentage of completion.
87
 
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='%'), scale=alt.Scale(domain=(0, 100))),
104
+ color=alt.Color('status:N', scale=alt.Scale(domain=['Completed', 'Pending'], range=['#28a745', '#dcdcdc']))
105
  )
106
 
107
+ # Create the annotation text for the label.
108
+ label_text = alt.Chart(label_data).mark_text(align='center', dx=0, dy=5, fontSize=16, fontWeight='bold').encode(
 
 
 
109
  x='percentage:Q',
110
+ text='label:N'
111
  )
112
 
113
+ # Combine the bar and the label.
114
+ chart = (progress_bar + label_text).properties(
 
 
 
 
 
 
 
 
 
115
  title='Progress Towards Goal',
116
+ width=800,
117
+ height=150
118
  )
119
 
120
  return chart
121
 
122
 
123
 
124
+
125
  def donut_chart() -> alt.Chart:
126
  """
127
  This function returns a donut chart with the number of annotated and pending records.