From d5a456707fb51d396d1209fcf452a75b5ebd7f1c Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 20 Nov 2026 00:57:38 +0100 Subject: [PATCH] Office setting and cause as separate data: named emitters, stressor schedules, office sense nerve Setting holds the emitters and no schedule; Cause holds the stressors, the objective pull and the sense nerve (threshold 0.05, no sensitisation, no conduction delay) and no geometry. The test runner takes a name filter so the office tests run without the minutes-long body tests. Co-Authored-By: Claude Sonnet 5.5 --- src/BadDay.Core/Cause.cs | 72 +++++++++++++++++++++++++++++++++++ src/BadDay.Core/Setting.cs | 28 ++++++++++++++ tests/BadDay.Tests/Program.cs | 29 ++++++++++++-- 3 files changed, 126 insertions(+), 3 deletions(-) create mode 100644 src/BadDay.Core/Cause.cs create mode 100644 src/BadDay.Core/Setting.cs diff --git a/src/BadDay.Core/Cause.cs b/src/BadDay.Core/Cause.cs new file mode 100644 index 0000000..a281b15 --- /dev/null +++ b/src/BadDay.Core/Cause.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Lodur; + +namespace BadDay.Core; + +/// +/// One recurring source of load: when it starts, how it rises, how often it comes back, how long it lasts and how +/// hard, on one emitter of the . Times are seconds; a null period is a single burst. +/// +public sealed record Stressor( + string Id, string EmitterId, + double OnsetSeconds, double RampSeconds, double? PeriodSeconds, double DurationSeconds, + double Intensity, double Jitter) +{ + /// + /// The intensity at , in whole ticks so the burst edges never wander with float error: + /// zero before the onset and outside a burst, else Intensity rising over the ramp, scaled by (1 + Jitter * draw). + /// + public double Value(long tick, double tickSeconds, double draw) + { + long t = tick - Ticks(OnsetSeconds, tickSeconds); + if (t < 0) return 0.0; + long phase = PeriodSeconds is { } p ? t % Math.Max(1, Ticks(p, tickSeconds)) : t; + if (phase >= Ticks(DurationSeconds, tickSeconds)) return 0.0; + long ramp = Ticks(RampSeconds, tickSeconds); + double rise = ramp > 0 ? Math.Min(1.0, (double)phase / ramp) : 1.0; + return Math.Max(0.0, Intensity * rise * (1.0 + Jitter * draw)); + } + + private static long Ticks(double seconds, double tickSeconds) => (long)Math.Round(seconds / tickSeconds); +} + +/// +/// What goes wrong: the stressors, the objective's pull, and the sense nerve the character hears and sees them +/// with. It holds no geometry (that is the 's). Code defaults, not persisted. +/// +public sealed record Cause(IReadOnlyList Stressors, double ObjectivePull, NerveParameters Senses) +{ + /// + /// The office's sense nerve: threshold 0.05, no sensitisation, no conduction delay. The office's break near + /// 90 s at pull 0.6 holds only with these; Lodur's NerveParameters defaults break at about 100 s. + /// + public static NerveParameters OfficeSenses { get; } = new() + { + Threshold = 0.05, + SensitisationGrowth = 0.0, + ConductionDelaySeconds = 0.0, + }; + + /// + /// The office's sensory-load cause [P]: printer audio 5 s on, every 8 s for 1 s at 0.25; ceiling light 15 s + /// every 11 s for 2 s at 0.2; desk phone 25 s every 14 s for 3 s at 0.35; desktop interrupt 75 s every 20 s for + /// 1 s at 0.3; pull 0.6. The chatty neighbour and the stand-up crowd wait for coworkers (rung 6). + /// + public static Cause Office { get; } = new(new[] + { + new Stressor("printer", "printer", 5.0, 0.0, 8.0, 1.0, 0.25, 0.1), + new Stressor("ceiling-light", "ceiling-light", 15.0, 0.0, 11.0, 2.0, 0.2, 0.1), + new Stressor("desk-phone", "desk-phone", 25.0, 0.0, 14.0, 3.0, 0.35, 0.1), + new Stressor("desktop-interrupt", "desktop", 75.0, 0.0, 20.0, 1.0, 0.3, 0.1), + }, 0.6, OfficeSenses); + + /// Every stressor's intensity times . + public Cause Scaled(double factor) => this with + { + Stressors = Stressors.Select(s => s with { Intensity = s.Intensity * factor }).ToArray(), + }; + + public Cause Without(string stressorId) => this with { Stressors = Stressors.Where(s => s.Id != stressorId).ToArray() }; +} diff --git a/src/BadDay.Core/Setting.cs b/src/BadDay.Core/Setting.cs new file mode 100644 index 0000000..cd9f4fb --- /dev/null +++ b/src/BadDay.Core/Setting.cs @@ -0,0 +1,28 @@ +using System.Collections.Generic; +using Lodur; + +namespace BadDay.Core; + +/// One of the setting's point sources: an id the cause refers to, and a Lodur (channel, position, radius). +public sealed record NamedEmitter(string Id, Emitter Emitter); + +/// +/// Where a bad day happens: the named emitters and where they sit. It holds no schedule; what the emitters do over +/// time is the 's. Code defaults for now, not persisted (follow-up office-scenario-as-content). +/// Every number is a placeholder. +/// +public sealed record Setting(IReadOnlyList Emitters) +{ + /// + /// The office: a printer and a desk phone (audio), a ceiling light (visual) and the desktop's notifications + /// (interrupt). Each sits at the origin, where the head is held, with a radius that reaches it in full: the + /// placement is a placeholder until the client puts real positions in. + /// + public static Setting Office { get; } = new(new[] + { + new NamedEmitter("printer", new Emitter(Channel.Audio, 0f, 0f, 0f, 10f)), + new NamedEmitter("ceiling-light", new Emitter(Channel.Visual, 0f, 0f, 0f, 10f)), + new NamedEmitter("desk-phone", new Emitter(Channel.Audio, 0f, 0f, 0f, 10f)), + new NamedEmitter("desktop", new Emitter(Channel.Interrupt, 0f, 0f, 0f, 10f)), + }); +} diff --git a/tests/BadDay.Tests/Program.cs b/tests/BadDay.Tests/Program.cs index 268e270..079decb 100644 --- a/tests/BadDay.Tests/Program.cs +++ b/tests/BadDay.Tests/Program.cs @@ -260,6 +260,27 @@ public static class Program try { Run("run"); } catch (ArgumentException) { threw = true; } Check(threw, "missing --seed should be rejected"); }), + + ("office: a stressor is silent before its onset, on for its duration, and back every period", () => + { + var printer = Cause.Office.Stressors.Single(s => s.Id == "printer"); // 5 s on, 8 s period, 1 s long, 0.25 + double V(double seconds) => printer.Value((long)Math.Round(seconds * 100), 0.01, 0.0); + Check(V(4.99) == 0.0 && V(5.0) == 0.25 && V(5.99) == 0.25 && V(6.0) == 0.0, "first burst is not [5 s, 6 s)"); + Check(V(12.99) == 0.0 && V(13.0) == 0.25 && V(13.99) == 0.25 && V(14.0) == 0.0, "second burst is not [13 s, 14 s)"); + var once = printer with { PeriodSeconds = null }; + Check(once.Value(1300, 0.01, 0.0) == 0.0 && once.Value(500, 0.01, 0.0) == 0.25, "a stressor with no period repeated"); + var ramped = printer with { RampSeconds = 0.5 }; + Check(ramped.Value(525, 0.01, 0.0) == 0.125 && ramped.Value(560, 0.01, 0.0) == 0.25, "the ramp does not rise over its seconds"); + }), + + ("office: the setting holds the emitters and no schedule, the cause refers to them by id", () => + { + var ids = Setting.Office.Emitters.Select(e => e.Id).ToHashSet(); + Check(Cause.Office.Stressors.All(s => ids.Contains(s.EmitterId)), "a stressor names an emitter the setting lacks"); + Check(Setting.Office.Emitters.All(e => e.Emitter.Intensity == 0.0), "the setting carries an intensity"); + Check(Cause.Office.Senses.Threshold == 0.05 && Cause.Office.Senses.SensitisationGrowth == 0.0 && Cause.Office.Senses.ConductionDelaySeconds == 0.0, + "the office does not pass its own sense parameters"); + }), }; private static int Tick(long ms) => (int)Math.Round(ms * Hz / 1000.0); @@ -281,15 +302,17 @@ public static class Program return Math.Sqrt(sum / (to - from - 1)); } - public static int Main() + /// Runs every test; with an argument, only the tests whose name contains it (the body tests take minutes). + public static int Main(string[] args) { int failed = 0; - foreach (var (name, body) in Tests) + var tests = args.Length > 0 ? Tests.Where(t => t.Name.Contains(args[0])).ToArray() : Tests; + foreach (var (name, body) in tests) { try { body(); Console.WriteLine($"PASS {name}"); } catch (Exception e) { failed++; Console.WriteLine($"FAIL {name}: {e.Message}"); } } - Console.WriteLine($"{Tests.Length - failed}/{Tests.Length} passed"); + Console.WriteLine($"{tests.Length - failed}/{tests.Length} passed"); return failed == 0 ? 0 : 1; }