Files
pokerfreak-shell/mac/Sources/CockpitKern/Wachstum.swift
T

148 lines
5.5 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import Foundation
public struct KurvenPunkt: Decodable, Equatable, Sendable {
public var t: Double?
public var bb: Double?
enum CodingKeys: String, CodingKey { case t, bb }
public init(from d: Decoder) throws {
let c = try d.container(keyedBy: CodingKeys.self)
t = c.zahl(.t); bb = c.zahl(.bb)
}
}
public struct StakeZeile: Decodable, Equatable, Sendable, Identifiable {
public var stake: String
public var haende: Int?
public var bb100: Double?
public var unten: Double?
public var oben: Double?
public var id: String { stake }
enum CodingKeys: String, CodingKey { case stake, haende, bb100, unten, oben }
public init(from d: Decoder) throws {
let c = try d.container(keyedBy: CodingKeys.self)
stake = c.text(.stake) ?? "?"; haende = c.zahl(.haende).map { Int($0) }; bb100 = c.zahl(.bb100)
unten = c.zahl(.unten); oben = c.zahl(.oben)
}
}
public struct Sitzung: Decodable, Equatable, Sendable, Identifiable {
public var raum: String?
public var von: Double?
public var bis: Double?
public var haende: Int?
public var nettoBB: Double?
public var bb100: Double?
public var id: String { "\(raum ?? "")|\(von ?? 0)" }
enum CodingKeys: String, CodingKey { case raum, von, bis, haende, nettoBB = "netto_bb", bb100 }
public init(from d: Decoder) throws {
let c = try d.container(keyedBy: CodingKeys.self)
raum = c.text(.raum); von = c.zahl(.von); bis = c.zahl(.bis); haende = c.zahl(.haende).map { Int($0) }
nettoBB = c.zahl(.nettoBB); bb100 = c.zahl(.bb100)
}
}
public struct Stunde: Decodable, Equatable, Sendable {
public var stunde: Double?
public var haende: Int?
enum CodingKeys: String, CodingKey { case stunde, haende }
public init(from d: Decoder) throws {
let c = try d.container(keyedBy: CodingKeys.self)
stunde = c.zahl(.stunde); haende = c.zahl(.haende).map { Int($0) }
}
}
public struct Klasse: Decodable, Equatable, Sendable {
public var von: Double?
public var bis: Double?
public var anzahl: Int?
enum CodingKeys: String, CodingKey { case von, bis, anzahl }
public init(from d: Decoder) throws {
let c = try d.container(keyedBy: CodingKeys.self)
von = c.zahl(.von); bis = c.zahl(.bis); anzahl = c.zahl(.anzahl).map { Int($0) }
}
/// "< −50", "−50…−20", "≥ 50"
public var beschriftung: String {
switch (von, bis) {
case (nil, let b?): return "< \(Format.auto(b))"
case (let v?, nil): return "≥ \(Format.auto(v))"
case (let v?, let b?): return "\(Format.auto(v))…\(Format.auto(b))"
default: return "?"
}
}
}
public struct Summe: Decodable, Equatable, Sendable {
public var haende: Int?
public var nettoBB: Double?
public var gewonnen: Int?
public var verloren: Int?
enum CodingKeys: String, CodingKey { case haende, nettoBB = "netto_bb", gewonnen, verloren }
public init(from d: Decoder) throws {
let c = try d.container(keyedBy: CodingKeys.self)
haende = c.zahl(.haende).map { Int($0) }; nettoBB = c.zahl(.nettoBB)
gewonnen = c.zahl(.gewonnen).map { Int($0) }; verloren = c.zahl(.verloren).map { Int($0) }
}
}
public struct Stapel: Decodable, Equatable, Sendable, Identifiable {
public struct Punkt: Decodable, Equatable, Sendable {
public var t: Double?
public var stack: Double?
enum CodingKeys: String, CodingKey { case t, stack }
public init(from d: Decoder) throws {
let c = try d.container(keyedBy: CodingKeys.self)
t = c.zahl(.t); stack = c.zahl(.stack)
}
}
public var raum: String
public var punkte: [Punkt]
public var id: String { raum }
enum CodingKeys: String, CodingKey { case raum, punkte }
public init(from d: Decoder) throws {
let c = try d.container(keyedBy: CodingKeys.self)
raum = c.text(.raum) ?? "?"; punkte = c.objekte(.punkte)
}
}
/// Die Kurven einer Grundlage - eigene Haende oder der ganze Bestand.
public struct Kurven: Decodable, Equatable, Sendable {
public var leer: String?
public var ergebnisKurve: [KurvenPunkt] = []
public var bb100: [StakeZeile] = []
public var jeStunde: [Stunde] = []
public var verteilung: [Klasse] = []
public var summe: Summe?
public var grundlage: String?
public var rechnet = false
enum CodingKeys: String, CodingKey {
case leer, ergebnisKurve = "ergebnis_kurve", bb100, jeStunde = "je_stunde", verteilung, summe, grundlage, rechnet
}
public init(from d: Decoder) throws {
let c = try d.container(keyedBy: CodingKeys.self)
leer = c.text(.leer); ergebnisKurve = c.objekte(.ergebnisKurve); bb100 = c.objekte(.bb100)
jeStunde = c.objekte(.jeStunde); verteilung = c.objekte(.verteilung)
summe = try? c.decodeIfPresent(Summe.self, forKey: .summe); grundlage = c.text(.grundlage)
rechnet = c.wahr(.rechnet)
}
}
public struct Wachstum: Decodable, Equatable, Sendable {
public var eigene: Kurven
public var bestand: Kurven?
public var stapel: [Stapel] = []
public var sitzungen: [Sitzung] = []
public var leer: String? { eigene.leer }
enum CodingKeys: String, CodingKey { case bestand, stapel, sitzungen }
public init(from d: Decoder) throws {
eigene = try Kurven(from: d)
let c = try d.container(keyedBy: CodingKeys.self)
bestand = try? c.decodeIfPresent(Kurven.self, forKey: .bestand)
stapel = c.objekte(.stapel); sitzungen = c.objekte(.sitzungen)
}
}