marcenacp commited on
Commit
cb308b8
·
1 Parent(s): fe3ba5f

Deploy (see actual commits on https://github.com/mlcommons/croissant).

Browse files
Files changed (1) hide show
  1. views/overview.py +31 -9
views/overview.py CHANGED
@@ -27,6 +27,21 @@ be displayed on this page. Once you are ready, you can download the dataset by c
27
  the export button in the upper right corner."""
28
 
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  def render_overview():
31
  metadata: Metadata = st.session_state[Metadata]
32
  col1, col2 = st.columns([1, 1], gap="medium")
@@ -52,15 +67,22 @@ def render_overview():
52
  args=(MetadataEvent.DESCRIPTION, metadata, key),
53
  )
54
  st.divider()
55
- left, middle, right = st.columns([1, 1, 1])
56
- fields = [
57
- field
58
- for field, value in dataclasses.asdict(metadata).items()
59
- if value and field not in _NON_RELEVANT_METADATA
60
- ]
61
- left.metric("Number of metadata", len(fields))
62
- middle.metric("Number of resources", len(metadata.distribution))
63
- right.metric("Number of RecordSets", len(metadata.record_sets))
 
 
 
 
 
 
 
64
  with col2:
65
  user_started_editing = metadata.record_sets or metadata.distribution
66
  if user_started_editing:
 
27
  the export button in the upper right corner."""
28
 
29
 
30
+ def _relevant_fields(class_or_instance: type):
31
+ if isinstance(class_or_instance, type):
32
+ return [
33
+ field.name
34
+ for field in dataclasses.fields(class_or_instance)
35
+ if field not in _NON_RELEVANT_METADATA
36
+ ]
37
+ else:
38
+ return [
39
+ field
40
+ for field, value in dataclasses.asdict(class_or_instance).items()
41
+ if value and field not in _NON_RELEVANT_METADATA
42
+ ]
43
+
44
+
45
  def render_overview():
46
  metadata: Metadata = st.session_state[Metadata]
47
  col1, col2 = st.columns([1, 1], gap="medium")
 
67
  args=(MetadataEvent.DESCRIPTION, metadata, key),
68
  )
69
  st.divider()
70
+ col_a, col_b, col_c, col_d = st.columns([1, 1, 1, 1])
71
+ fields = len(_relevant_fields(metadata))
72
+ metadata_weight = len(_relevant_fields(Metadata))
73
+ completion = int(
74
+ (
75
+ fields
76
+ + (metadata_weight if metadata.distribution else 0)
77
+ + (metadata_weight if metadata.record_sets else 0)
78
+ )
79
+ * 100
80
+ / (3 * metadata_weight)
81
+ )
82
+ col_a.metric("Completion", f"{completion}%")
83
+ col_b.metric("Number of metadata", fields)
84
+ col_c.metric("Number of resources", len(metadata.distribution))
85
+ col_d.metric("Number of RecordSets", len(metadata.record_sets))
86
  with col2:
87
  user_started_editing = metadata.record_sets or metadata.distribution
88
  if user_started_editing: