EnergyVenom commited on
Commit
e7ea433
·
verified ·
1 Parent(s): fc7b34c

Deploy 662c276: try offered values first

Browse files
coworker/platform/discovery.py CHANGED
@@ -163,13 +163,22 @@ CANDIDATES = 6 # values a test tries for one key before it gives up
163
  def candidates(discovered: dict | None, overrides: dict | None, learned: dict | None = None,
164
  screens: dict | None = None) -> dict[str, dict[str, list[str]]]:
165
  """{area: {key: [values to try, in order]}}: the admin's own value, then the one Fusion last accepted for this test
166
- user, then the pod's records (most used first), then the choices its screens' lists offer this user. A value Fusion
167
- refuses in a test (not in the user's list) makes the test try the next one."""
 
 
 
 
 
 
 
 
 
168
  out: dict[str, dict[str, list[str]]] = {}
169
- for src in (overrides, learned, discovered, screens):
170
  for area, keys in (src or {}).items():
171
  for k, vals in (keys or {}).items():
172
- vals = vals if isinstance(vals, list) else [vals]
173
  have = out.setdefault(str(area).upper(), {}).setdefault(k, [])
174
  for v in vals:
175
  if v not in (None, "") and str(v) not in have and len(have) < CANDIDATES:
 
163
  def candidates(discovered: dict | None, overrides: dict | None, learned: dict | None = None,
164
  screens: dict | None = None) -> dict[str, dict[str, list[str]]]:
165
  """{area: {key: [values to try, in order]}}: the admin's own value, then the one Fusion last accepted for this test
166
+ user, then what this user is offered: the pod's records its screens' lists also offer (most used first), the lists'
167
+ other choices, and last the other records (often other users' business units or methods, refused for this one).
168
+ A value Fusion refuses in a test (not in the user's list) makes the test try the next one."""
169
+ def values(v) -> list:
170
+ return v if isinstance(v, list) else [v]
171
+ offered, others = {}, {}
172
+ for area, keys in (discovered or {}).items():
173
+ for k, vals in (keys or {}).items():
174
+ listed = {str(x) for x in values(((screens or {}).get(area) or {}).get(k) or [])}
175
+ offered.setdefault(area, {})[k] = [v for v in values(vals) if str(v) in listed]
176
+ others.setdefault(area, {})[k] = [v for v in values(vals) if str(v) not in listed]
177
  out: dict[str, dict[str, list[str]]] = {}
178
+ for src in (overrides, learned, offered, screens, others):
179
  for area, keys in (src or {}).items():
180
  for k, vals in (keys or {}).items():
181
+ vals = values(vals)
182
  have = out.setdefault(str(area).upper(), {}).setdefault(k, [])
183
  for v in vals:
184
  if v not in (None, "") and str(v) not in have and len(have) < CANDIDATES:
coworker/tests/test_pod_test_values.py CHANGED
@@ -26,9 +26,13 @@ class TestPodTestValues(unittest.TestCase):
26
 
27
  def test_values_are_tried_in_order_without_repeats(self):
28
  c = discovery.candidates({"AR": {"business_unit": ["Rec 1", "Shared"]}}, {"AR": {"business_unit": "Mine"}},
29
- {"AR": {"business_unit": "Worked"}}, {"AR": {"business_unit": ["Shared", "Screen 1"], "ledger": ["L1"]}})
30
- self.assertEqual(c["AR"]["business_unit"], ["Mine", "Worked", "Rec 1", "Shared", "Screen 1"])
 
31
  self.assertEqual(c["AR"]["ledger"], ["L1"])
 
 
 
32
  self.assertEqual(discovery.merged_test_data({"AR": {"business_unit": ["Rec 1"]}}, {}, {"AR": {"business_unit": "Worked"}}),
33
  {"AR": {"business_unit": "Worked"}})
34
 
 
26
 
27
  def test_values_are_tried_in_order_without_repeats(self):
28
  c = discovery.candidates({"AR": {"business_unit": ["Rec 1", "Shared"]}}, {"AR": {"business_unit": "Mine"}},
29
+ {"AR": {"business_unit": "Worked"}}, {"AR": {"business_unit": ["Screen 1", "Shared"], "ledger": ["L1"]}})
30
+ # what this user is offered comes before other records: the record the lists also offer, the lists, other records
31
+ self.assertEqual(c["AR"]["business_unit"], ["Mine", "Worked", "Shared", "Screen 1", "Rec 1"])
32
  self.assertEqual(c["AR"]["ledger"], ["L1"])
33
+ many = discovery.candidates({"AR": {"receipt_method": [f"Rec {i}" for i in range(8)]}}, {}, {},
34
+ {"AR": {"receipt_method": ["Offered"]}})
35
+ self.assertEqual(many["AR"]["receipt_method"][0], "Offered") # not crowded out by the records
36
  self.assertEqual(discovery.merged_test_data({"AR": {"business_unit": ["Rec 1"]}}, {}, {"AR": {"business_unit": "Worked"}}),
37
  {"AR": {"business_unit": "Worked"}})
38
 
docs/DISCOVERY.md CHANGED
@@ -43,8 +43,9 @@ Test steps use them as `{{pod.<area>.<key>}}`, for example `{{pod.ap.supplier}}`
43
  -> `journal_source`), and so does each catalog key it names ("Procurement BU" is also `business_unit`). They are
44
  kept apart from the screen inventories (the AI sees labels only), and the AI may use every key the pod has.
45
  - **Several values per key, tried in order.** A step whose value is one pod placeholder tries the pod's values in
46
- turn until Fusion accepts one: the admin's own, the one Fusion last accepted, the records' (most used first), then
47
- the screens' choices (`FUSION_TESTDATA_CANDIDATES`). Fusion refuses a value by marking the field in error, opening
 
48
  its search window, or an error message (a business unit whose ledger has no open period); the next value is typed
49
  over it. The value that worked is used for the rest of the test and remembered for the pod
50
  (`FPT_TESTDATA_USED` -> `test_data_learned`), so the next run starts with it.
 
43
  -> `journal_source`), and so does each catalog key it names ("Procurement BU" is also `business_unit`). They are
44
  kept apart from the screen inventories (the AI sees labels only), and the AI may use every key the pod has.
45
  - **Several values per key, tried in order.** A step whose value is one pod placeholder tries the pod's values in
46
+ turn until Fusion accepts one: the admin's own, the one Fusion last accepted, then what this user is offered (the
47
+ records' values its screens' lists also offer, most used first, then the lists' other choices), and last the other
48
+ records' values, often other users' business units (`FUSION_TESTDATA_CANDIDATES`, at most 6 per key). Fusion refuses a value by marking the field in error, opening
49
  its search window, or an error message (a business unit whose ledger has no open period); the next value is typed
50
  over it. The value that worked is used for the rest of the test and remembered for the pod
51
  (`FPT_TESTDATA_USED` -> `test_data_learned`), so the next run starts with it.