MilesCranmer commited on
Commit
89fd807
·
unverified ·
1 Parent(s): a206d6a

refactor(gui): fix issues with big refactor

Browse files
Files changed (1) hide show
  1. gui/app.py +21 -13
gui/app.py CHANGED
@@ -206,10 +206,9 @@ class Results:
206
  )
207
 
208
 
209
- def flatten_attributes(component_group, absolute_name: str, d=None) -> OrderedDict:
210
- if d is None:
211
- d = OrderedDict()
212
-
213
  if not hasattr(component_group, "__dict__"):
214
  return d
215
 
@@ -218,14 +217,14 @@ def flatten_attributes(component_group, absolute_name: str, d=None) -> OrderedDi
218
  if name.startswith("_"):
219
  # Private attribute
220
  continue
221
- elif elem in component_group.__dict__.values():
222
  # Don't duplicate any tiems
223
  continue
224
  elif isinstance(elem, Component):
225
  # Only add components to dict
226
  d[new_absolute_name] = elem
227
  else:
228
- d = flatten_attributes(elem, new_absolute_name, d=d)
229
 
230
  return d
231
 
@@ -250,26 +249,35 @@ class AppInterface:
250
  show_progress=False,
251
  )
252
 
 
253
  self.run.click(
254
- create_processing_function(self, ignore=["df", "predictions_plot"]),
255
- inputs=list(flatten_attributes(self, "interface").values()),
 
 
 
 
256
  outputs=[self.results.df, self.results.predictions_plot],
257
  show_progress=True,
258
  )
259
 
260
 
 
 
 
 
261
  def create_processing_function(interface: AppInterface, ignore=[]):
262
- d = flatten_attributes(interface, "interface")
263
- keys = [k.split(".")[-1] for k in d.keys()]
264
- keys = [k for k in keys if k not in ignore]
265
  _, idx, counts = np.unique(keys, return_index=True, return_counts=True)
266
  if np.any(counts > 1):
267
  raise AssertionError("Bad keys: " + ",".join(np.array(keys)[idx[counts > 1]]))
268
 
269
- def f(components):
270
  n = len(components)
271
  assert n == len(keys)
272
- return processing(**{keys[i]: components[i] for i in range(n)})
 
273
 
274
  return f
275
 
 
206
  )
207
 
208
 
209
+ def flatten_attributes(
210
+ component_group, absolute_name: str, d: OrderedDict
211
+ ) -> OrderedDict:
 
212
  if not hasattr(component_group, "__dict__"):
213
  return d
214
 
 
217
  if name.startswith("_"):
218
  # Private attribute
219
  continue
220
+ elif elem in d.values():
221
  # Don't duplicate any tiems
222
  continue
223
  elif isinstance(elem, Component):
224
  # Only add components to dict
225
  d[new_absolute_name] = elem
226
  else:
227
+ flatten_attributes(elem, new_absolute_name, d)
228
 
229
  return d
230
 
 
249
  show_progress=False,
250
  )
251
 
252
+ ignore = ["df", "predictions_plot"]
253
  self.run.click(
254
+ create_processing_function(self, ignore=ignore),
255
+ inputs=[
256
+ v
257
+ for k, v in flatten_attributes(self, "interface", OrderedDict()).items()
258
+ if last_part(k) not in ignore
259
+ ],
260
  outputs=[self.results.df, self.results.predictions_plot],
261
  show_progress=True,
262
  )
263
 
264
 
265
+ def last_part(k: str) -> str:
266
+ return k.split(".")[-1]
267
+
268
+
269
  def create_processing_function(interface: AppInterface, ignore=[]):
270
+ d = flatten_attributes(interface, "interface", OrderedDict())
271
+ keys = [k for k in map(last_part, d.keys()) if k not in ignore]
 
272
  _, idx, counts = np.unique(keys, return_index=True, return_counts=True)
273
  if np.any(counts > 1):
274
  raise AssertionError("Bad keys: " + ",".join(np.array(keys)[idx[counts > 1]]))
275
 
276
+ def f(*components):
277
  n = len(components)
278
  assert n == len(keys)
279
+ for output in processing(**{keys[i]: components[i] for i in range(n)}):
280
+ yield output
281
 
282
  return f
283