marcenacp commited on
Commit
c439062
1 Parent(s): cb308b8

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

Browse files
Files changed (2) hide show
  1. views/overview.py +4 -1
  2. views/source.py +8 -2
views/overview.py CHANGED
@@ -32,7 +32,7 @@ def _relevant_fields(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 [
@@ -71,6 +71,9 @@ def render_overview():
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)
 
32
  return [
33
  field.name
34
  for field in dataclasses.fields(class_or_instance)
35
+ if field.name not in _NON_RELEVANT_METADATA
36
  ]
37
  else:
38
  return [
 
71
  fields = len(_relevant_fields(metadata))
72
  metadata_weight = len(_relevant_fields(Metadata))
73
  completion = int(
74
+ # Formula for the completion:
75
+ # - Resources and RecordSets count as much as Metadata.
76
+ # - Metadata is the percentage of filled fields.
77
  (
78
  fields
79
  + (metadata_weight if metadata.distribution else 0)
views/source.py CHANGED
@@ -118,11 +118,14 @@ def render_source(
118
  index = (
119
  possible_sources.index(source.uid) if source.uid in possible_sources else None
120
  )
 
 
 
121
  key = f"{prefix}-source"
122
  col1.selectbox(
123
  needed_field("Source"),
124
  index=index,
125
- options=[s for s in possible_sources if not s.startswith(record_set.name)],
126
  key=key,
127
  on_change=handle_field_change,
128
  args=(FieldEvent.SOURCE, field, key),
@@ -264,11 +267,14 @@ def render_references(
264
  if references.uid in possible_sources
265
  else None
266
  )
 
 
 
267
  key = f"{key}-reference"
268
  col1.selectbox(
269
  "Reference",
270
  index=index,
271
- options=[s for s in possible_sources if not s.startswith(record_set.name)],
272
  key=key,
273
  on_change=handle_field_change,
274
  args=(FieldEvent.REFERENCE, field, key),
 
118
  index = (
119
  possible_sources.index(source.uid) if source.uid in possible_sources else None
120
  )
121
+ options = [s for s in possible_sources if not s.startswith(record_set.name)]
122
+ if index and (index < 0 or index >= len(options)):
123
+ index = None
124
  key = f"{prefix}-source"
125
  col1.selectbox(
126
  needed_field("Source"),
127
  index=index,
128
+ options=options,
129
  key=key,
130
  on_change=handle_field_change,
131
  args=(FieldEvent.SOURCE, field, key),
 
267
  if references.uid in possible_sources
268
  else None
269
  )
270
+ options = [s for s in possible_sources if not s.startswith(record_set.name)]
271
+ if index and (index < 0 or index >= len(options)):
272
+ index = None
273
  key = f"{key}-reference"
274
  col1.selectbox(
275
  "Reference",
276
  index=index,
277
+ options=options,
278
  key=key,
279
  on_change=handle_field_change,
280
  args=(FieldEvent.REFERENCE, field, key),