class_name BoardReportText extends RefCounted ## Turns a board test's results into plain text lines: the static problems ## and the simulation report (runs, halts, errors, dead ends, tables never ## reached ...). Used by the Test board window and tools/simulate_board.gd. ## BoardTester delegates here. ## True when no run hit an error, a dead end or the action limit. static func is_clean(report: Dictionary) -> bool: return (report["errors"] as Array).is_empty() and (report["dead_ends"] as Array).is_empty() \ and not (report["halted"] as Dictionary).has("Action limit") ## The static problems as text lines (for the CLI's --check and Copy report). static func format_problems(problems: Array, list: int = 40) -> PackedStringArray: var out := PackedStringArray() out.append("Static problems: %d" % problems.size()) for i in mini(list, problems.size()): var problem: Dictionary = problems[i] var where: String = "%s (%s)" % [problem["table"], problem["table_id"]] if str(problem["entry_id"]) != "": where += ", result " + str(problem["entry_id"]) out.append(" %s: %s" % [where, problem["text"]]) if problems.size() > list: out.append(" ... and %d more" % (problems.size() - list)) return out ## The simulation report as text; `list` caps each section's lines. static func format_report(report: Dictionary, list: int = 40, show_sheet: bool = true) -> String: var out := PackedStringArray() var actions: Dictionary = report["actions"] out.append("Runs: %d completed: %d prompts per run: %.1f" % [report["runs"], report["completed"], report["prompts_mean"]]) var halt_parts := PackedStringArray() for reason: String in report["halted"]: halt_parts.append("%s %d" % [reason, report["halted"][reason]]) out.append("Halted: %s" % (", ".join(halt_parts) if not halt_parts.is_empty() else "none")) out.append("Actions: max %d, mean %.1f, p95 %d" % [actions["max"], actions["mean"], actions["p95"]]) var longest: Dictionary = report.get("longest", {}) if not (longest.get("top", []) as Array).is_empty(): var parts := PackedStringArray() for hit: Dictionary in longest["top"]: parts.append("%s %d" % [hit["table"], hit["count"]]) out.append("Longest run (#%d) most-rolled tables: %s" % [longest["run"], ", ".join(parts)]) var track: Dictionary = report.get("track", {}) for name: String in track: var stats: Dictionary = track[name] if int(stats["n"]) == 0: out.append("@%s: never a number" % name) else: out.append("@%s: min %s, mean %.1f, max %s (%d runs)" % [name, Expr.format_value(stats["min"]), stats["sum"] / stats["n"], Expr.format_value(stats["max"]), stats["n"]]) _section(out, "Change / expression errors", report["errors"], list, func(item: Dictionary) -> String: return "%dx %s, result \"%s\": %s" % [item["count"], item["table"], item["entry"], item["text"]]) _section(out, "Dead ends (rolls that stopped)", report["dead_ends"], list, func(item: Dictionary) -> String: return "%dx %s: %s" % [item["count"], item["table"], item["text"]]) _section(out, "Unset variables, missing tables and {= } errors in text", report["unset_markers"], list, func(item: Dictionary) -> String: return "%dx %s, result \"%s\": %s" % [item["count"], item["table"], item["entry"], item["text"]]) var unreached: Array = report["unreached"] out.append("Tables never reached: %d" % unreached.size()) for i in mini(list, unreached.size()): out.append(" " + str(unreached[i])) if unreached.size() > list: out.append(" ... and %d more" % (unreached.size() - list)) _unchosen_lines(out, report["unchosen"], list) if show_sheet: out.append("Sample final sheet%s:" % (" (" + str(report["sample_halted"]) + ")" if str(report["sample_halted"]) != "" else "")) out.append(str(report["sample_sheet"]) if str(report["sample_sheet"]) != "" else " (no sheet card was reached)") return "\n".join(out) ## The "Results never chosen" lines: {table id: [entry texts]}. static func _unchosen_lines(out: PackedStringArray, unchosen: Dictionary, list: int) -> void: var entry_count := 0 for table_id: String in unchosen: entry_count += (unchosen[table_id] as Array).size() out.append("Results never chosen: %d in %d reached cards" % [entry_count, unchosen.size()]) var shown := 0 for table_id: String in unchosen: if shown >= list: out.append(" ... and %d more tables" % (unchosen.size() - shown)) break var items: Array = unchosen[table_id] var names := PackedStringArray() for i in mini(4, items.size()): names.append("\"%s\"" % items[i]) out.append(" %s: %d (%s%s)" % [table_id, items.size(), ", ".join(names), ", ..." if items.size() > 4 else ""]) shown += 1 static func _section(out: PackedStringArray, title: String, items: Array, list: int, fmt: Callable) -> void: out.append("%s: %d" % [title, items.size()]) for i in mini(list, items.size()): out.append(" " + str(fmt.call(items[i]))) if items.size() > list: out.append(" ... and %d more" % (items.size() - list))