baddaysim: office and office-sweep verbs
--silence ID@S repeats, --scale and --pull load the cause, --max and --every as the pain box. The pain box verbs and their output are unchanged. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
2ea2f4e92c
commit
f600f57259
2 changed files with 77 additions and 3 deletions
|
|
@ -16,16 +16,28 @@ public static class Program
|
|||
baddaysim run --seed N --body [options] the same run on the Ymir ragdoll, with the hand-out time
|
||||
baddaysim sweep --seed N --count M [options] seeds N..N+M-1, break-time summary
|
||||
|
||||
baddaysim office --seed N [office options] the office: stressors fill the stress bar, one run
|
||||
baddaysim office-sweep --seed N --count M [office options]
|
||||
|
||||
options (all numbers, seconds unless noted):
|
||||
--intensity X box intensity 0..1 (default 0.8)
|
||||
--pull X objective pull 0..1 (default 0.5)
|
||||
--disable-at S box switches off at S (default never)
|
||||
--max S give up after S (default 120)
|
||||
--every S timeline sample interval (default 1)
|
||||
|
||||
office options:
|
||||
--silence ID@S silence stressor ID from S seconds (repeatable; ids: printer, ceiling-light, desk-phone, desktop-interrupt)
|
||||
--scale X every stressor's intensity times X (default 1)
|
||||
--pull X objective pull 0..1 (default 0.6)
|
||||
--max S give up after S (default 180)
|
||||
--every S timeline sample interval (default 1)
|
||||
""";
|
||||
|
||||
private const string Title = "Synaptic Induction Chamber (the pain box)";
|
||||
|
||||
private static readonly string OfficeTitle = $"Bad day at the office, rung 3 (stress = 1 - resolve, \"{StressResult.StressBarLabel}\")";
|
||||
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
try { return Execute(args, Console.Out); }
|
||||
|
|
@ -39,10 +51,12 @@ public static class Program
|
|||
|
||||
public static int Execute(string[] args, System.IO.TextWriter output)
|
||||
{
|
||||
if (args.Length == 0 || (args[0] != "run" && args[0] != "sweep")) throw new ArgumentException("expected 'run' or 'sweep'");
|
||||
if (args.Length == 0 || (args[0] != "run" && args[0] != "sweep" && args[0] != "office" && args[0] != "office-sweep"))
|
||||
throw new ArgumentException("expected 'run', 'sweep', 'office' or 'office-sweep'");
|
||||
var opts = ParseOptions(args);
|
||||
ulong seed = opts.TryGetValue("seed", out var s) ? ulong.Parse(s, CultureInfo.InvariantCulture)
|
||||
: throw new ArgumentException("--seed is required");
|
||||
if (args[0].StartsWith("office")) return ExecuteOffice(args[0] == "office-sweep", seed, opts, output);
|
||||
var p = new PainBoxParameters
|
||||
{
|
||||
BoxIntensity = Num(opts, "intensity", 0.8),
|
||||
|
|
@ -82,6 +96,45 @@ public static class Program
|
|||
return 0;
|
||||
}
|
||||
|
||||
private static int ExecuteOffice(bool sweep, ulong seed, Dictionary<string, string> opts, System.IO.TextWriter output)
|
||||
{
|
||||
if (opts.ContainsKey("body")) throw new ArgumentException("--body applies to run");
|
||||
var defaults = new StressParameters();
|
||||
var p = defaults with
|
||||
{
|
||||
Cause = (defaults.Cause with { ObjectivePull = Num(opts, "pull", defaults.Cause.ObjectivePull) }).Scaled(Num(opts, "scale", 1.0)),
|
||||
MaxSeconds = Num(opts, "max", defaults.MaxSeconds),
|
||||
SampleEverySeconds = Num(opts, "every", defaults.SampleEverySeconds),
|
||||
};
|
||||
var silences = new List<SilenceCommand>();
|
||||
if (opts.TryGetValue("silence", out var list))
|
||||
{
|
||||
foreach (var item in list.Split(','))
|
||||
{
|
||||
int at = item.LastIndexOf('@');
|
||||
if (at <= 0) throw new ArgumentException($"--silence wants ID@SECONDS, got '{item}'");
|
||||
silences.Add(new SilenceCommand(item[..at], double.Parse(item[(at + 1)..], CultureInfo.InvariantCulture)));
|
||||
}
|
||||
}
|
||||
|
||||
if (!sweep)
|
||||
{
|
||||
var r = StressSimulation.Run(p, seed, silences);
|
||||
output.WriteLine(OfficeTitle);
|
||||
output.Write(r.Render());
|
||||
output.WriteLine(r.Summary());
|
||||
return 0;
|
||||
}
|
||||
|
||||
int count = (int)Num(opts, "count", 20);
|
||||
var summary = StressSweep.Run(p, seed, count, silences);
|
||||
foreach (var r in summary.Results) output.WriteLine(r.Summary());
|
||||
output.WriteLine($"runs {summary.Runs}: broke {summary.Broke}, endured {summary.Endured}; " +
|
||||
$"time to break min/median/max ms: {Fmt(summary.MinBreakMs)}/{Fmt(summary.MedianBreakMs)}/{Fmt(summary.MaxBreakMs)}; " +
|
||||
$"min resolve of endured runs: {(summary.MinEnduredResolve?.ToString("F3", CultureInfo.InvariantCulture) ?? "-")}");
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static string Fmt(long? v) => v?.ToString(CultureInfo.InvariantCulture) ?? "-";
|
||||
|
||||
private static double Num(Dictionary<string, string> o, string key, double fallback) =>
|
||||
|
|
@ -94,7 +147,8 @@ public static class Program
|
|||
{
|
||||
if (args[i] == "--body") { o["body"] = ""; i++; continue; } // the one flag
|
||||
if (!args[i].StartsWith("--") || i + 1 >= args.Length) throw new ArgumentException($"bad option near '{args[i]}'");
|
||||
o[args[i][2..]] = args[i + 1];
|
||||
// --silence repeats; its values are joined, since a stressor id holds no comma.
|
||||
o[args[i][2..]] = args[i] == "--silence" && o.TryGetValue("silence", out var prior) ? prior + "," + args[i + 1] : args[i + 1];
|
||||
i += 2;
|
||||
}
|
||||
return o;
|
||||
|
|
|
|||
|
|
@ -418,9 +418,29 @@ public static class Program
|
|||
Check(Hash("run", "--seed", "1") == "a3a800612f1e610deb8c648ea74a0a3e2f4639541a46d92af0d1bcfbdd8cfb45", "run --seed 1 changed");
|
||||
Check(Hash("sweep", "--seed", "1", "--count", "20") == "2cc88f9ffbbf301b8264c0be600edb34b21a3b572f927ed96ea49eda20dc73db", "sweep --seed 1 --count 20 changed");
|
||||
}),
|
||||
|
||||
("office CLI: office runs a timeline with the stress label, --silence repeats, office-sweep summarises", () =>
|
||||
{
|
||||
string Run(params string[] a) { var w = new StringWriter(); BadDay.Cli.Program.Execute(a, w); return w.ToString(); }
|
||||
var plain = Run("office", "--seed", "1");
|
||||
Check(plain == Run("office", "--seed", "1"), "office output differs between runs");
|
||||
Check(plain.Contains("lost composure") && plain.Contains("time_ms kind audio visual interrupt load arousal resolve stress goal"), "no label or header");
|
||||
Check(plain.Contains("will broke at"), "seed 1 should break at the default settings");
|
||||
var quiet = Run("office", "--seed", "1", "--silence", "printer@0", "--silence", "desk-phone@0");
|
||||
Check(quiet.Split('\n').Count(l => l.Contains(" Silenced ")) == 2, "two --silence options should give two Silenced rows");
|
||||
Check(Run("office", "--seed", "1", "--scale", "0").Contains("endured to 180000 ms"), "--scale 0 should be a quiet office");
|
||||
Check(Run("office", "--seed", "1", "--pull", "1").Contains("endured"), "--pull 1 never drains");
|
||||
Check(Run("office-sweep", "--seed", "1", "--count", "5").Contains("min resolve of endured runs:"), "no sweep summary");
|
||||
foreach (var bad in new[] { new[] { "office" }, new[] { "office", "--seed", "1", "--silence", "printer" }, new[] { "office", "--seed", "1", "--silence", "nope@1" }, new[] { "office", "--seed", "1", "--body" } })
|
||||
{
|
||||
bool threw = false;
|
||||
try { Run(bad); } catch (ArgumentException) { threw = true; }
|
||||
Check(threw, $"'{string.Join(' ', bad)}' should be rejected");
|
||||
}
|
||||
}),
|
||||
};
|
||||
|
||||
private static readonly Quat[] Pose = { Quat.Identity };
|
||||
private static readonly Quat[] Pose ={ Quat.Identity };
|
||||
private static readonly float[] Point = new float[1], Strengths = new float[1];
|
||||
private static readonly Quat[] Targets = new Quat[1];
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue