dvilasuero HF Staff commited on
Commit
f272cc4
Β·
verified Β·
1 Parent(s): b83dd5c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -1
app.py CHANGED
@@ -67,6 +67,50 @@ import pandas as pd
67
  import os
68
 
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
 
71
  def progress_bar_chart() -> alt.Chart:
72
  source_dataset, _ = obtain_source_target_datasets()
@@ -77,7 +121,7 @@ def progress_bar_chart() -> alt.Chart:
77
 
78
  # Create a DataFrame for the progress bar data.
79
  progress_data = pd.DataFrame({
80
- 'status': ['Completed', 'Pending'],
81
  'percentage': [percentage_complete, 100 - percentage_complete],
82
  'actual': [pending_records, annotated_records]
83
  })
 
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
72
+ source_dataset, _ = obtain_source_target_datasets()
73
+ total_records = int(os.getenv("TARGET_RECORDS")) # This should be the total number of records you want to annotate.
74
+ annotated_records = len(source_dataset) # This is the number of records already annotated.
75
+ pending_records = total_records - annotated_records # Calculate the pending records.
76
+
77
+ # Prepare data for the gauge chart
78
+ gauge_data = pd.DataFrame({
79
+ 'category': ['Annotated', 'Remaining'],
80
+ 'value': [annotated_records, pending_records]
81
+ })
82
+
83
+ # The background of the gauge
84
+ base = alt.Chart(pd.DataFrame({'value': [total_records], 'category': ['Total']})).mark_bar(
85
+ color='#e0e0e0', size=40
86
+ ).encode(
87
+ alt.X('value:Q', scale=alt.Scale(domain=[0, total_records]), title='Record Count'),
88
+ alt.Y('category:N', axis=alt.Axis(title=''))
89
+ )
90
+
91
+ # The value part of the gauge
92
+ value_bar = alt.Chart(gauge_data).mark_bar(size=40).encode(
93
+ alt.X('value:Q'),
94
+ alt.Y('category:N', axis=alt.Axis(title='')),
95
+ alt.Color('category:N', scale=alt.Scale(domain=['Annotated', 'Remaining'], range=['#28a745', '#dcdcdc']))
96
+ )
97
+
98
+ # Combine the bars to create a gauge effect
99
+ chart = alt.layer(base, value_bar).properties(
100
+ title='Progress Towards Goal',
101
+ width=700,
102
+ height=100
103
+ )
104
+
105
+ # Add a text label for the current value
106
+ text = alt.Chart(pd.DataFrame({'value': [annotated_records + pending_records/2], 'text': [f'{annotated_records} / {total_records}']})).mark_text(
107
+ align='center', baseline='middle', fontSize=16, fontWeight='bold', dy=-30
108
+ ).encode(
109
+ x='value:Q',
110
+ text='text:N'
111
+ )
112
+
113
+ return (chart + text)
114
 
115
  def progress_bar_chart() -> alt.Chart:
116
  source_dataset, _ = obtain_source_target_datasets()
 
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
  })