diff --git a/messung/innovation/vorflop_selbst/auswertung.py b/messung/innovation/vorflop_selbst/auswertung.py index 91eb7620..26150a38 100644 --- a/messung/innovation/vorflop_selbst/auswertung.py +++ b/messung/innovation/vorflop_selbst/auswertung.py @@ -79,6 +79,19 @@ def _zahl(x): return "-" if x is None else "%.3f" % x +def preisregel_ok(z, schlupf=1e-9): + """Price rule at fold/call nodes before an all-in (as the motor's `preisregel`): more fold only at real price >= tree price, more call only at real price <= tree price.""" + if list(z["namen"]) != ["fold", "call"] or z.get("preis_real") is None or z.get("preis_baum") is None: + return True + mehr_fold = z["pi_neu"]["fold"] > z["pi_alt"]["fold"] + mehr_call = z["pi_neu"]["call"] > z["pi_alt"]["call"] + if mehr_fold and z["preis_real"] < z["preis_baum"] - schlupf: + return False + if mehr_call and z["preis_real"] > z["preis_baum"] + schlupf: + return False + return True + + def preis_abweichung(z): """True if real and tree call price differ by more than PREIS_HINWEIS (None when a price is missing).""" if z.get("preis_real") is None or z.get("preis_baum") is None: diff --git a/messung/innovation/vorflop_selbst/vorflop_selbst.py b/messung/innovation/vorflop_selbst/vorflop_selbst.py index fcdab8e2..32a6f162 100644 --- a/messung/innovation/vorflop_selbst/vorflop_selbst.py +++ b/messung/innovation/vorflop_selbst/vorflop_selbst.py @@ -146,7 +146,8 @@ def nurallin(roh_pfad, knoten_pfad): zeilen = A.entscheidungszeilen(roh, beschreibung) treu = [z for z in zeilen if z["treu"]] bleibt = [z for z in treu if int(z["key"], 16) in kept] - for name, zs in (("alle treuen", treu), ("nur All-in", bleibt)): + mit_preis = [z for z in bleibt if A.preisregel_ok(z)] + for name, zs in (("alle treuen", treu), ("nur All-in", bleibt), ("+ Preisregel", mit_preis)): c = A.wertzeilen(zs) s = W.summen(c, len(zs), zaehlung["haende"]) if c else None print("%-12s Entscheidungen %3d, Zellen %3d, Wert %s, Erreichbarkeit x R %.4f" % (name, len(zs), len(c), "%+.2f bb/100 [%+.2f; %+.2f]" % (s["wert_bb_pro_100"], s["lo_bb_pro_100"], s["hi_bb_pro_100"]) if s else "-", sum(z["erreich_x_R"] for z in zs))) diff --git a/tests/innovation_vorflop_selbst_spec.py b/tests/innovation_vorflop_selbst_spec.py index b91a053f..92090a41 100644 --- a/tests/innovation_vorflop_selbst_spec.py +++ b/tests/innovation_vorflop_selbst_spec.py @@ -273,6 +273,23 @@ class Archivliste(unittest.TestCase): self.assertNotIn("kennung", m.lower()) +class Preisregel(unittest.TestCase): + def zeile(self, alt, neu, real, baum, namen=("fold", "call")): + return {"namen": list(namen), "pi_alt": dict(zip(namen, alt)), "pi_neu": dict(zip(namen, neu)), "preis_real": real, "preis_baum": baum} + + def test_mehr_fold_nur_bei_echtem_preis_ab_baumpreis(self): + self.assertFalse(A.preisregel_ok(self.zeile([0.2, 0.8], [1.0, 0.0], 0.37, 0.48))) + self.assertTrue(A.preisregel_ok(self.zeile([0.2, 0.8], [1.0, 0.0], 0.48, 0.48))) + self.assertTrue(A.preisregel_ok(self.zeile([0.2, 0.8], [1.0, 0.0], 0.55, 0.48))) + + def test_mehr_call_nur_bei_echtem_preis_bis_baumpreis(self): + self.assertFalse(A.preisregel_ok(self.zeile([0.8, 0.2], [0.2, 0.8], 0.55, 0.48))) + self.assertTrue(A.preisregel_ok(self.zeile([0.8, 0.2], [0.2, 0.8], 0.40, 0.48))) + + def test_nur_an_fold_call_knoten(self): + self.assertTrue(A.preisregel_ok(self.zeile([0.2, 0.3, 0.5], [1.0, 0.0, 0.0], 0.1, 0.9, namen=("fold", "call", "all-in")))) + + class Saaten(unittest.TestCase): def test_saat_a_aus_dem_stand_feld(self): self.assertEqual(A.saat_a("abc123;saat=777;n=1024"), 777)