second reducer sweep of success
This commit is contained in:
@@ -78,6 +78,13 @@ def merge_object_reducer(current_value: Any, incoming_value: Any) -> Any:
|
|||||||
return current_value | incoming_value
|
return current_value | incoming_value
|
||||||
|
|
||||||
|
|
||||||
|
def add_reducer(current_value: Any, incoming_value: Any) -> Any:
|
||||||
|
"""Add numeric incoming values into a numeric state path."""
|
||||||
|
if current_value is None:
|
||||||
|
return incoming_value
|
||||||
|
return current_value + incoming_value
|
||||||
|
|
||||||
|
|
||||||
def set_union_reducer(current_value: Any, incoming_value: Any) -> Any:
|
def set_union_reducer(current_value: Any, incoming_value: Any) -> Any:
|
||||||
"""Merge list values while preserving stable first-seen order."""
|
"""Merge list values while preserving stable first-seen order."""
|
||||||
if current_value is None:
|
if current_value is None:
|
||||||
@@ -126,6 +133,13 @@ DEFAULT_REDUCER_DEFINITIONS: Mapping[str, ReducerDefinition] = {
|
|||||||
),
|
),
|
||||||
fn=merge_object_reducer,
|
fn=merge_object_reducer,
|
||||||
),
|
),
|
||||||
|
"wf.std.add": ReducerDefinition(
|
||||||
|
spec=ReducerSpec(
|
||||||
|
name="wf.std.add",
|
||||||
|
description="Add numeric incoming values into a numeric state path.",
|
||||||
|
),
|
||||||
|
fn=add_reducer,
|
||||||
|
),
|
||||||
"wf.std.set_union": ReducerDefinition(
|
"wf.std.set_union": ReducerDefinition(
|
||||||
spec=ReducerSpec(
|
spec=ReducerSpec(
|
||||||
name="wf.std.set_union",
|
name="wf.std.set_union",
|
||||||
|
|||||||
@@ -138,6 +138,19 @@ def test_max_reducer_keeps_larger_value() -> None:
|
|||||||
assert state["best_score"] == 9
|
assert state["best_score"] == 9
|
||||||
|
|
||||||
|
|
||||||
|
def test_add_reducer_sums_numeric_values() -> None:
|
||||||
|
workflow = _workflow(
|
||||||
|
fields={
|
||||||
|
"count": StateField(reducer=ReducerRef(name="wf.std.add"), type="integer")
|
||||||
|
}
|
||||||
|
)
|
||||||
|
state = {"count": 7}
|
||||||
|
|
||||||
|
write_state_value(workflow, state, "state.count", 5)
|
||||||
|
|
||||||
|
assert state["count"] == 12
|
||||||
|
|
||||||
|
|
||||||
def test_reducer_definition_can_wrap_plain_two_arg_callable() -> None:
|
def test_reducer_definition_can_wrap_plain_two_arg_callable() -> None:
|
||||||
definition = ReducerDefinition(
|
definition = ReducerDefinition(
|
||||||
spec=ReducerSpec(name="test.add"),
|
spec=ReducerSpec(name="test.add"),
|
||||||
|
|||||||
@@ -249,7 +249,8 @@ def post_roll_router(
|
|||||||
|
|
||||||
@node(name="main")
|
@node(name="main")
|
||||||
def tick(state: Countdown) -> Countdown:
|
def tick(state: Countdown) -> Countdown:
|
||||||
return Countdown(countdown=state.countdown - 1)
|
"""Emit a countdown delta because State.countdown uses the add reducer."""
|
||||||
|
return Countdown(countdown=-1)
|
||||||
|
|
||||||
|
|
||||||
@node(outcomes=("tick", END))
|
@node(outcomes=("tick", END))
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ Constraints:
|
|||||||
try to use builtin wf_authoring.ops
|
try to use builtin wf_authoring.ops
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from itertools import islice
|
||||||
|
import json
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
@@ -70,10 +72,13 @@ def test():
|
|||||||
)
|
)
|
||||||
assert d.status == RunStatus.COMPLETED, "oops"
|
assert d.status == RunStatus.COMPLETED, "oops"
|
||||||
state = State.model_validate(d.state)
|
state = State.model_validate(d.state)
|
||||||
assert any(i["name"] in context["pool"]["n_240"] for i in state.storage), (
|
assert any(
|
||||||
"pity logic failed"
|
i["name"] in context["pool"]["n_240"]
|
||||||
)
|
for i in islice(state.storage, 120 - (240 - 135))
|
||||||
|
), "pity logic failed"
|
||||||
pprint(state.storage)
|
pprint(state.storage)
|
||||||
|
# pprint(gacha.compile().edges)
|
||||||
|
# pprint(gacha.compile().nodes)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user