Mac-App: "Was spielen" mit Tischen je Format, "Formate im Vergleich"

A card per format with its table count under the plan tiles (unmeasured
formats are marked), the table tile shows the sum. Results show bb/100
per format with its 95 % span on a shared axis and the verdict, Practice
and Live separately.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-30 10:43:23 +01:00
co-authored by Claude Opus 5.5
parent 9f67abbd64
commit 83a31b3831
10 changed files with 373 additions and 16 deletions
+1
View File
@@ -55,6 +55,7 @@ struct ErgebnisAnsicht: View {
Text("\(u) Hände ohne bekannten Modus zählen hier nicht mit.").font(.caption2).foregroundStyle(.tertiary)
}
kennzahlen(k)
if gewaehlt != .archiv { FormatVergleich(kurven: k) }
Picker("", selection: $teil) {
ForEach(Teil.allCases.filter { gewaehlt != .archiv || ($0 != .stapel && $0 != .sitzungen) }, id: \.self) { Text($0.rawValue) }
}
+84
View File
@@ -0,0 +1,84 @@
import CockpitKern
import SwiftUI
/// Welches Format läuft am besten: bb/100 je Format mit 95-%-Spanne als Balken auf einer
/// gemeinsamen Achse, darüber das Urteil - nur wenn die Spannen es tragen.
struct FormatVergleich: View {
var kurven: Kurven?
var body: some View {
let zeilen = kurven?.jeFormat ?? []
if !zeilen.isEmpty {
VStack(alignment: .leading, spacing: 8) {
HStack(alignment: .firstTextBaseline) {
Text("Formate im Vergleich").font(.caption.weight(.semibold)).foregroundStyle(.secondary)
Spacer()
Text("bb/100 · 95 %").font(.caption2).foregroundStyle(.tertiary)
}
if let u = kurven?.bestesFormat { urteil(u) }
let achse = Self.achse(zeilen)
ForEach(zeilen) { z in
FormatBalken(zeile: z, achse: achse)
}
}
.padding(10)
.background(.white.opacity(0.05), in: RoundedRectangle(cornerRadius: 14))
}
}
private func urteil(_ u: FormatUrteil) -> some View {
let sieger = u.format.flatMap(SpielFormat.init(rawValue:))
return VStack(alignment: .leading, spacing: 1) {
Label(sieger.map { "\($0.name) liegt vorn" } ?? "Noch kein Urteil",
systemImage: sieger == nil ? "hourglass" : "rosette")
.font(.callout.weight(.semibold))
.foregroundStyle(sieger == nil ? Color.secondary : .green)
Text(u.grund).font(.caption2).foregroundStyle(.tertiary).fixedSize(horizontal: false, vertical: true)
}
}
/// Gemeinsame Achse über alle Spannen und Werte, mit der Null darin.
static func achse(_ z: [FormatZeile]) -> ClosedRange<Double> {
let werte: [Double] = z.flatMap { [$0.unten, $0.oben, $0.bb100].compactMap { $0 } } + [0.0]
let lo = werte.min() ?? -1, hi = werte.max() ?? 1
return lo == hi ? (lo - 1)...(hi + 1) : lo...hi
}
}
private struct FormatBalken: View {
var zeile: FormatZeile
var achse: ClosedRange<Double>
private var format: SpielFormat? { SpielFormat(rawValue: zeile.format) }
var body: some View {
VStack(alignment: .leading, spacing: 3) {
HStack(spacing: 6) {
Image(systemName: format?.symbol ?? "questionmark.circle").font(.caption).foregroundStyle(.secondary).frame(width: 16)
Text(zeile.name).font(.caption.weight(.semibold))
Text("\(zeile.haende) Hände").font(.caption2).foregroundStyle(.tertiary)
Spacer()
Text(Format.vorzeichen(zeile.bb100, stellen: 1)).font(.caption.weight(.semibold).monospacedDigit())
.foregroundStyle(Farben.ergebnis(zeile.bb100))
}
GeometryReader { g in
let x = { (v: Double) in g.size.width * (v - achse.lowerBound) / (achse.upperBound - achse.lowerBound) }
ZStack(alignment: .leading) {
Capsule().fill(.quaternary).frame(height: 4)
Rectangle().fill(.secondary.opacity(0.6)).frame(width: 1, height: 12).offset(x: x(0))
if let u = zeile.unten, let o = zeile.oben {
Capsule().fill(Farben.ergebnis(zeile.bb100).opacity(0.35))
.frame(width: max(2, x(o) - x(u)), height: 8).offset(x: x(u))
}
if let b = zeile.bb100 {
Circle().fill(Farben.ergebnis(b)).frame(width: 8, height: 8).offset(x: x(b) - 4)
}
}
.frame(maxHeight: .infinity)
}
.frame(height: 12)
.help(zeile.unten.map { u in "95 %: \(Format.zahl(u, stellen: 0)) bis \(Format.zahl(zeile.oben, stellen: 0)) bb/100" }
?? "zu wenig Hände für eine Spanne")
}
}
}
+73
View File
@@ -0,0 +1,73 @@
import CockpitKern
import SwiftUI
/// Was gespielt wird: je Format eine Karte mit Tischzahl. Mehrere Formate gleichzeitig; die Summe
/// ist die Tischzahl. Ein Format, dessen Lobby-Weg nicht gemessen ist, lässt sich wählen - der
/// Läufer öffnet dort aber nichts und sagt es (lesen/formate.py).
struct FormatWahl: View {
@Environment(Cockpit.self) private var cockpit
private let spalten = [GridItem(.flexible(), spacing: 6), GridItem(.flexible(), spacing: 6)]
var body: some View {
let w = cockpit.wahl
let gemessen = cockpit.ansicht.kopf?.spielplan?.gemessen ?? w.gemessen
VStack(alignment: .leading, spacing: 6) {
HStack(alignment: .firstTextBaseline) {
Text("Was spielen").font(.caption2.weight(.medium)).foregroundStyle(.secondary)
Spacer()
Text(zusammen(w)).font(.caption2).foregroundStyle(.secondary).monospacedDigit()
}
LazyVGrid(columns: spalten, spacing: 6) {
ForEach(SpielFormat.allCases) { f in
FormatKarte(format: f, anzahl: w.anzahl(f), gemessen: gemessen.contains(f),
voll: w.tische >= Spielplan.hoechstens) { cockpit.wahl.setzen(f, $0) }
}
}
}
}
private func zusammen(_ w: Spielplan) -> String {
w.tische == 0 ? "nichts gewählt" : "\(w.tische) Tisch\(w.tische == 1 ? "" : "e") zusammen"
}
}
private struct FormatKarte: View {
var format: SpielFormat
var anzahl: Int
var gemessen: Bool
var voll: Bool
var setzen: (Int) -> Void
private var an: Bool { anzahl > 0 }
var body: some View {
HStack(spacing: 6) {
Image(systemName: format.symbol)
.font(.system(size: 13, weight: .semibold))
.foregroundStyle(an ? Color.accentColor : .secondary)
.frame(width: 18)
VStack(alignment: .leading, spacing: 0) {
Text(format.name).font(.caption.weight(.semibold)).lineLimit(1).minimumScaleFactor(0.8)
if !gemessen {
Text("ungemessen").font(.system(size: 9.5)).foregroundStyle(.orange).lineLimit(1)
}
}
Spacer(minLength: 2)
if an {
Button { setzen(anzahl - 1) } label: { Image(systemName: "minus").frame(width: 16, height: 18) }
Text("\(anzahl)").font(.system(.callout, design: .rounded).weight(.semibold)).monospacedDigit()
.frame(minWidth: 12).contentTransition(.numericText())
}
Button { setzen(anzahl + 1) } label: { Image(systemName: "plus").frame(width: 16, height: 18) }
.disabled(voll)
}
.buttonStyle(.borderless)
.padding(.horizontal, 8).frame(height: 38)
.background(an ? Color.accentColor.opacity(0.14) : Color.white.opacity(0.05), in: RoundedRectangle(cornerRadius: 10))
.overlay(RoundedRectangle(cornerRadius: 10)
.strokeBorder(an ? Color.accentColor.opacity(0.5) : .clear, lineWidth: 1))
.animation(.snappy, value: anzahl)
.help(gemessen ? "\(format.name): \(anzahl) Tisch\(anzahl == 1 ? "" : "e")"
: "\(format.name): der Weg in der Lobby ist noch nicht gemessen - der Läufer öffnet hier nichts")
}
}
+5 -11
View File
@@ -62,17 +62,11 @@ struct PlanKacheln: View {
let w = cockpit.wahl
HStack(spacing: 8) {
Kachel(titel: "Tische") {
HStack(spacing: 0) {
Button { cockpit.wahl.tische -= 1 } label: { Image(systemName: "minus").frame(width: 24, height: 24) }
.disabled(w.tische <= 1)
Text(w.tischeBis.map { "\(w.tische)–\($0)" } ?? "\(w.tische)")
.font(.system(size: w.tischeBis == nil ? 24 : 20, weight: .semibold, design: .rounded)).monospacedDigit()
.frame(maxWidth: .infinity).contentTransition(.numericText())
Button { cockpit.wahl.tische += 1 } label: { Image(systemName: "plus").frame(width: 24, height: 24) }
.disabled(w.tische >= Spielplan.hoechstens)
}
.buttonStyle(.borderless)
.animation(.snappy, value: w.tische)
// die Zahl je Format steht darunter in "Was spielen" - hier die Summe
Text(w.tischeBis.map { "\(w.tische)–\($0)" } ?? "\(w.tische)")
.font(.system(size: w.tischeBis == nil ? 24 : 20, weight: .semibold, design: .rounded)).monospacedDigit()
.frame(maxWidth: .infinity, alignment: .leading).contentTransition(.numericText())
.animation(.snappy, value: w.tische)
} fuss: {
Text(cockpit.laeuft == true ? "\(cockpit.ansicht.kopf?.tischeOffen ?? 0) offen" : "füllt der Läufer auf")
}
+1
View File
@@ -204,6 +204,7 @@ struct Kopfzeile: View {
ModusSchalter()
if cockpit.liveFragen { LiveFrage().transition(.move(edge: .top).combined(with: .opacity)) }
PlanKacheln()
FormatWahl()
if cockpit.planOffen { PlanEditor().transition(.move(edge: .top).combined(with: .opacity)) }
PhaseBand()
HStack(alignment: .firstTextBaseline, spacing: 8) {
+66
View File
@@ -0,0 +1,66 @@
import Foundation
/// Was an einem Tisch gespielt wird - wie lesen/formate.py. Nicht der Modus (Übung/Live).
public enum SpielFormat: String, CaseIterable, Sendable, Identifiable {
case cash, aof, bombpot, turnier, kpoker, vip, freeroll
public var id: String { rawValue }
public var name: String {
switch self {
case .cash: "Cash"
case .aof: "All-In or Fold"
case .bombpot: "Bomb Pot"
case .turnier: "Turnier"
case .kpoker: "K-Poker"
case .vip: "VIP Arena"
case .freeroll: "Freerolls"
}
}
public var symbol: String {
switch self {
case .cash: "circle.circle"
case .aof: "bolt.fill"
case .bombpot: "flame.fill"
case .turnier: "trophy.fill"
case .kpoker: "keyboard"
case .vip: "crown.fill"
case .freeroll: "gift.fill"
}
}
}
/// Eine Zeile des Vergleichs je Format (wachstum.je_format): bb/100 mit 95-%-Spanne.
public struct FormatZeile: Decodable, Equatable, Sendable, Identifiable {
public var format: String
public var name: String
public var haende: Int
public var nettoBB: Double?
public var bb100: Double?
public var unten: Double?
public var oben: Double?
public var id: String { format }
enum CodingKeys: String, CodingKey { case format, name, haende, nettoBB = "netto_bb", bb100, unten, oben }
public init(from d: Decoder) throws {
let c = try d.container(keyedBy: CodingKeys.self)
format = c.text(.format) ?? "unbekannt"; name = c.text(.name) ?? format
haende = c.zahl(.haende).map { Int($0) } ?? 0; nettoBB = c.zahl(.nettoBB)
bb100 = c.zahl(.bb100); unten = c.zahl(.unten); oben = c.zahl(.oben)
}
}
/// Welches Format vorn liegt - nur wenn die Spannen es tragen (betrieb/statistik.bestes_format).
public struct FormatUrteil: Decodable, Equatable, Sendable {
public var format: String?
public var grund: String
enum CodingKeys: String, CodingKey { case format, grund }
public init(from d: Decoder) throws {
let c = try d.container(keyedBy: CodingKeys.self)
format = c.text(.format); grund = c.text(.grund) ?? ""
}
}
+37 -4
View File
@@ -10,7 +10,15 @@ public struct Spielplan: Equatable, Sendable, Decodable {
public static let standard = Spielplan(modus: .uebung, tische: 1, budget: nil)
public var modus: Modus
public var tische: Int { didSet { tische = Self.klemmen(tische); tischeBis = Self.spanne(tische, tischeBis) } }
/// Tische je Format (betrieb/spielplan.py `formate`); ohne Eintrag 0.
public private(set) var formate: [SpielFormat: Int]
/// Welche Formate der Läufer öffnen kann (kopf.spielplan.formate_liste) - nur vom Server, nie gesendet.
public var gemessen: Set<SpielFormat> = [.cash]
/// Alle Tische zusammen. Setzen ändert Cash (die anderen Formate bleiben).
public var tische: Int {
get { formate.values.reduce(0, +) }
set { setzen(.cash, newValue - (tische - anzahl(.cash))) }
}
public var budget: Double?
/// Eingabe einheitlich für Lobby und Tisch: mit Maus oder ohne (hand/eingabe.py).
public var maus: Bool
@@ -25,15 +33,30 @@ public struct Spielplan: Equatable, Sendable, Decodable {
public init(modus: Modus, tische: Int, budget: Double?, maus: Bool = true) {
self.modus = modus
self.tische = Self.klemmen(tische)
self.formate = [.cash: Self.klemmen(tische)]
self.budget = budget.flatMap { $0 > 0 ? $0 : nil }
self.maus = maus
}
private static func klemmen(_ n: Int) -> Int { max(1, min(hoechstens, n)) }
public func anzahl(_ f: SpielFormat) -> Int { formate[f] ?? 0 }
/// Tische eines Formats: nicht unter 0, die Summe nicht über `hoechstens`.
public mutating func setzen(_ f: SpielFormat, _ n: Int) {
let andere = tische - anzahl(f)
let neu = max(0, min(n, Self.hoechstens - andere))
formate[f] = neu > 0 ? neu : nil
tischeBis = Self.spanne(tische, tischeBis)
}
private static func spanne(_ von: Int, _ bis: Int?) -> Int? { bis.flatMap { $0 > von ? min($0, hoechstens) : nil } }
enum CodingKeys: String, CodingKey { case modus, tische, budget, maus, zeiger, tischeBis = "tische_bis", zeitplan, geld }
enum CodingKeys: String, CodingKey {
case modus, tische, budget, maus, zeiger, tischeBis = "tische_bis", zeitplan, geld, formate
case formateListe = "formate_liste"
}
private struct FormatInfo: Decodable { var format: String; var gemessen: Bool }
public init(from d: Decoder) throws {
let c = try d.container(keyedBy: CodingKeys.self)
@@ -46,11 +69,21 @@ public struct Spielplan: Equatable, Sendable, Decodable {
zeiger = c.wahr(.zeiger)
zeitplan = ((try? c.decodeIfPresent(Zeitplan.self, forKey: .zeitplan)) ?? nil) ?? .ohne
geld = ((try? c.decodeIfPresent(Geldplan.self, forKey: .geld)) ?? nil) ?? Geldplan()
if let roh = (try? c.decodeIfPresent([String: Double].self, forKey: .formate)) ?? nil {
formate = [:]
for f in SpielFormat.allCases { if let n = roh[f.rawValue] { setzen(f, Int(n)) } }
}
if let liste = (try? c.decodeIfPresent([FormatInfo].self, forKey: .formateListe)) ?? nil {
gemessen = Set(liste.filter(\.gemessen).compactMap { SpielFormat(rawValue: $0.format) })
}
}
/// Für POST /api/steuern {aktion: "spielplan_setzen", daten}. Budget nur im Live-Modus.
public var daten: [String: Any] {
var d: [String: Any] = ["modus": modus.rawValue, "tische": tische, "maus": maus]
var d: [String: Any] = ["modus": modus.rawValue, "tische": max(1, tische), "maus": maus]
if Set(formate.keys) != [.cash] { // nur Cash ist die Vorgabe und bleibt weg
d["formate"] = Dictionary(uniqueKeysWithValues: formate.map { ($0.key.rawValue, $0.value) })
}
if live, let budget { d["budget"] = budget }
if let tischeBis { d["tische_bis"] = tischeBis }
if zeiger { d["zeiger"] = true }
+6 -1
View File
@@ -117,10 +117,13 @@ public struct Kurven: Decodable, Equatable, Sendable {
public var rechnet = false
/// Je Modus: ab wann gezaehlt wird (Statistik zurueckgesetzt), nil = ab Anfang.
public var nullpunkt: Double?
/// Vergleich je Format (Cash, AoF, ...) und ob eines mit 95 % vorn liegt.
public var jeFormat: [FormatZeile] = []
public var bestesFormat: FormatUrteil?
enum CodingKeys: String, CodingKey {
case leer, ergebnisKurve = "ergebnis_kurve", bb100, jeStunde = "je_stunde", verteilung, summe, grundlage, rechnet
case nullpunkt
case nullpunkt, jeFormat = "je_format", bestesFormat = "bestes_format"
}
public init(from d: Decoder) throws {
@@ -130,6 +133,8 @@ public struct Kurven: Decodable, Equatable, Sendable {
summe = try? c.decodeIfPresent(Summe.self, forKey: .summe); grundlage = c.text(.grundlage)
rechnet = c.wahr(.rechnet)
nullpunkt = c.zahl(.nullpunkt)
jeFormat = c.objekte(.jeFormat)
bestesFormat = try? c.decodeIfPresent(FormatUrteil.self, forKey: .bestesFormat)
}
}
+90
View File
@@ -0,0 +1,90 @@
import CockpitKern
import Testing
@Suite("Formate im Spielplan: Tische je Format, wie betrieb/spielplan.py")
struct FormateSpec {
@Test("ein neuer Plan ist Cash mit seiner Tischzahl")
func neu() {
let p = Spielplan(modus: .uebung, tische: 3, budget: nil)
#expect(p.formate == [.cash: 3])
#expect(p.tische == 3)
}
@Test("je Format setzen; die Summe ist die Tischzahl")
func setzen() {
var p = Spielplan(modus: .echt, tische: 2, budget: 100)
p.setzen(.aof, 1)
p.setzen(.bombpot, 2)
#expect(p.formate == [.cash: 2, .aof: 1, .bombpot: 2])
#expect(p.tische == 5)
p.setzen(.cash, 0)
#expect(p.formate == [.aof: 1, .bombpot: 2])
#expect(p.anzahl(.cash) == 0)
}
@Test("die Summe bleibt unter hoechstens")
func grenze() {
var p = Spielplan(modus: .uebung, tische: 10, budget: nil)
p.setzen(.aof, 9)
#expect(p.anzahl(.aof) == Spielplan.hoechstens - 10)
#expect(p.tische == Spielplan.hoechstens)
p.setzen(.aof, -3)
#expect(p.anzahl(.aof) == 0)
}
@Test("an den Läufer: formate und eine Tischzahl von mindestens 1")
func daten() {
var p = Spielplan(modus: .uebung, tische: 1, budget: nil)
p.setzen(.aof, 2)
#expect(p.daten["formate"] as? [String: Int] == ["cash": 1, "aof": 2])
#expect(p.daten["tische"] as? Int == 3)
p.setzen(.cash, 0); p.setzen(.aof, 0)
#expect(p.daten["formate"] as? [String: Int] == [:])
#expect(p.daten["tische"] as? Int == 1)
#expect(Spielplan(modus: .uebung, tische: 2, budget: nil).daten["formate"] == nil) // nur Cash: Vorgabe
}
@Test("vom Server: formate und welche Formate gemessen sind")
func gelesen() {
let p = Hilfen.spielplan(#"""
{"modus":"echt","tische":3,"formate":{"cash":2,"aof":1,"erfunden":4},
"formate_liste":[{"format":"cash","name":"Cash","gemessen":true},{"format":"aof","name":"All-In or Fold","gemessen":false}]}
"""#)
#expect(p?.formate == [.cash: 2, .aof: 1])
#expect(p?.gemessen == [.cash])
}
@Test("ein alter Plan ohne formate ist Cash")
func alt() {
#expect(Hilfen.spielplan(#"{"modus":"uebung","tische":2}"#)?.formate == [.cash: 2])
}
@Test("Namen und Reihenfolge wie lesen/formate.py")
func namen() {
#expect(SpielFormat.allCases.map(\.rawValue) == ["cash", "aof", "bombpot", "turnier", "kpoker", "vip", "freeroll"])
#expect(SpielFormat.aof.name == "All-In or Fold")
}
}
@Suite("Vergleich je Format in den Ergebnissen (wachstum.je_format, bestes_format)")
struct FormatVergleichSpec {
@Test("je Format mit Spanne, das Urteil mit Grund")
func vergleich() {
let k = Hilfen.kurven(#"""
{"je_format":[{"format":"aof","name":"All-In or Fold","haende":40,"netto_bb":420,"bb100":1050.0,"unten":900.0,"oben":1200.0},
{"format":"cash","name":"Cash","haende":40,"netto_bb":-80,"bb100":-200.0,"unten":-260.0,"oben":-140.0}],
"bestes_format":{"format":"aof","grund":"aof liegt mit 95 % Sicherheit vorn"}}
"""#)
#expect(k?.jeFormat.map(\.format) == ["aof", "cash"])
#expect(k?.jeFormat.first?.unten == 900)
#expect(k?.bestesFormat?.format == "aof")
#expect(k?.bestesFormat?.grund.contains("95") == true)
}
@Test("ohne Urteil: format nil, Grund bleibt")
func ohneUrteil() {
let k = Hilfen.kurven(#"{"je_format":[],"bestes_format":{"format":null,"grund":"zu wenig Hände für ein Urteil"}}"#)
#expect(k?.bestesFormat?.format == nil)
#expect(k?.bestesFormat?.grund == "zu wenig Hände für ein Urteil")
}
}
+10
View File
@@ -10,6 +10,16 @@ enum Hilfen {
return try? String(contentsOf: url, encoding: .utf8)
}
/// Ein Spielplan, wie ihn kopf.spielplan schickt.
static func spielplan(_ json: String) -> Spielplan? {
try? JSONDecoder().decode(Spielplan.self, from: Data(json.utf8))
}
/// Kurven eines Modus (wachstum.je_modus.uebung), so dekodiert wie in der App.
static func kurven(_ json: String) -> Kurven? {
try? JSONDecoder().decode(Kurven.self, from: Data(json.utf8))
}
/// Ein `modus`-Objekt der Ansicht, so dekodiert wie in der App.
static func modus(_ json: String) -> TischModus? {
try? JSONDecoder().decode(TischModus.self, from: Data(json.utf8))