Rijgersberg commited on
Commit
f3379af
β€’
1 Parent(s): 09bfa0e

Remove old top5 designations and make N configurable (with default 50)

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -234,15 +234,15 @@ def render_hub_user_link(hub_id):
234
  return f'<a target="_blank" href="{link}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">{hub_id}</a>'
235
 
236
 
237
- def obtain_top_5_users(user_ids_annotations: Dict[str, int]) -> pd.DataFrame:
238
  """
239
- This function returns the top 5 users with the most annotations.
240
 
241
  Args:
242
  user_ids_annotations: A dictionary with the user ids as the key and the number of annotations as the value.
243
 
244
  Returns:
245
- A pandas dataframe with the top 5 users with the most annotations.
246
  """
247
 
248
  dataframe = pd.DataFrame(
@@ -250,7 +250,7 @@ def obtain_top_5_users(user_ids_annotations: Dict[str, int]) -> pd.DataFrame:
250
  )
251
  dataframe[NAME] = dataframe[NAME].apply(render_hub_user_link)
252
  dataframe = dataframe.sort_values(by=NUMBER_ANNOTATIONS, ascending=False)
253
- return dataframe.head(50)
254
 
255
 
256
  def fetch_data() -> None:
@@ -260,7 +260,7 @@ def fetch_data() -> None:
260
 
261
  print(f"Starting to fetch data: {datetime.datetime.now()}")
262
 
263
- global source_dataset, target_dataset, user_ids_annotations, annotated, remaining, percentage_completed, top5_dataframe
264
  source_dataset, target_dataset = obtain_source_target_datasets()
265
  user_ids_annotations = get_user_annotations_dictionary(target_dataset)
266
 
@@ -274,8 +274,8 @@ def fetch_data() -> None:
274
  print(f"Data fetched: {datetime.datetime.now()}")
275
 
276
 
277
- def get_top5() -> pd.DataFrame:
278
- return obtain_top_5_users(user_ids_annotations)
279
 
280
 
281
  def main() -> None:
@@ -368,7 +368,7 @@ def main() -> None:
368
  kpi_chart, inputs=[], outputs=[kpi_hall_plot], every=update_interval_charts
369
  )
370
 
371
- top5_df_plot = gr.Dataframe(
372
  headers=[NAME, NUMBER_ANNOTATIONS],
373
  datatype=[
374
  "markdown",
@@ -379,7 +379,7 @@ def main() -> None:
379
  interactive=False,
380
  every=update_interval,
381
  )
382
- demo.load(get_top5, None, [top5_df_plot], every=update_interval_charts)
383
 
384
  # Launch the Gradio interface
385
  demo.launch()
 
234
  return f'<a target="_blank" href="{link}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">{hub_id}</a>'
235
 
236
 
237
+ def obtain_top_users(user_ids_annotations: Dict[str, int], N: int = 50) -> pd.DataFrame:
238
  """
239
+ This function returns the top N users with the most annotations.
240
 
241
  Args:
242
  user_ids_annotations: A dictionary with the user ids as the key and the number of annotations as the value.
243
 
244
  Returns:
245
+ A pandas dataframe with the top N users with the most annotations.
246
  """
247
 
248
  dataframe = pd.DataFrame(
 
250
  )
251
  dataframe[NAME] = dataframe[NAME].apply(render_hub_user_link)
252
  dataframe = dataframe.sort_values(by=NUMBER_ANNOTATIONS, ascending=False)
253
+ return dataframe.head(N)
254
 
255
 
256
  def fetch_data() -> None:
 
260
 
261
  print(f"Starting to fetch data: {datetime.datetime.now()}")
262
 
263
+ global source_dataset, target_dataset, user_ids_annotations, annotated, remaining, percentage_completed, top_dataframe
264
  source_dataset, target_dataset = obtain_source_target_datasets()
265
  user_ids_annotations = get_user_annotations_dictionary(target_dataset)
266
 
 
274
  print(f"Data fetched: {datetime.datetime.now()}")
275
 
276
 
277
+ def get_top(N = 50) -> pd.DataFrame:
278
+ return obtain_top_users(user_ids_annotations, N=N)
279
 
280
 
281
  def main() -> None:
 
368
  kpi_chart, inputs=[], outputs=[kpi_hall_plot], every=update_interval_charts
369
  )
370
 
371
+ top_df_plot = gr.Dataframe(
372
  headers=[NAME, NUMBER_ANNOTATIONS],
373
  datatype=[
374
  "markdown",
 
379
  interactive=False,
380
  every=update_interval,
381
  )
382
+ demo.load(get_top, None, [top_df_plot], every=update_interval_charts)
383
 
384
  # Launch the Gradio interface
385
  demo.launch()