Merge branch 'phase/80-nurse-health-ui'
This commit is contained in:
@@ -346,6 +346,71 @@ public class DecisionPlannerTests
|
||||
Assert.Equal(DecisionPlanner.DutyLessonWeight, peckishLesson.Intent.Weight);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LowSocialWeight_MakesChatLessAttractiveThanControl()
|
||||
{
|
||||
var (catalog, map, walks) = World();
|
||||
var corridor = map.Rooms.First(room => room.Def == "Corridor").Id;
|
||||
var needs = new Dictionary<string, float>(StringComparer.Ordinal)
|
||||
{
|
||||
["Toilet"] = 1f,
|
||||
["Hunger"] = 1f,
|
||||
["Social"] = 0.4f,
|
||||
["Sleep"] = 1f,
|
||||
};
|
||||
|
||||
var healthy = DecisionPlanner.Decide(
|
||||
catalog,
|
||||
map,
|
||||
walks,
|
||||
new ActorState(
|
||||
corridor,
|
||||
null,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
corridor,
|
||||
needs,
|
||||
Intent.None,
|
||||
SocialWeightFactor: 1f),
|
||||
(_, _) => 0);
|
||||
var sick = DecisionPlanner.Decide(
|
||||
catalog,
|
||||
map,
|
||||
walks,
|
||||
new ActorState(
|
||||
corridor,
|
||||
null,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
corridor,
|
||||
needs,
|
||||
Intent.None,
|
||||
SocialWeightFactor: 0.15f),
|
||||
(_, _) => 0);
|
||||
|
||||
var chatWeight = catalog.Actions[TalkActions.Chat].Weight;
|
||||
Assert.True(chatWeight * 0.15f < chatWeight);
|
||||
if (healthy.Intent.ActionId == TalkActions.Chat)
|
||||
{
|
||||
Assert.True(
|
||||
sick.Intent.ActionId != TalkActions.Chat
|
||||
|| sick.Intent.Weight < healthy.Intent.Weight);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Control did not pick Chat — still assert the scaled candidate loses to other leisure.
|
||||
Assert.True(sick.Intent.ActionId != TalkActions.Chat || sick.Intent.Weight <= chatWeight * 0.15f + 1e-3f);
|
||||
}
|
||||
}
|
||||
|
||||
private static Decision Decide(
|
||||
DefCatalog catalog,
|
||||
MapLayout map,
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
using HSchool.Content;
|
||||
using HSchool.People;
|
||||
|
||||
namespace HSchool.People.Tests;
|
||||
|
||||
public class NurseTendAndTalkWeightTests
|
||||
{
|
||||
private static readonly DateTime Now = new(2012, 4, 3, 10, 0, 0, DateTimeKind.Utc);
|
||||
|
||||
[Fact]
|
||||
public void Tend_WithMedicine_DropsSeverityFasterThanNaturalTick()
|
||||
{
|
||||
var catalog = LoadVanilla();
|
||||
var tended = Blank("a");
|
||||
var control = Blank("b");
|
||||
Onset(tended, "CommonCold", 0.55f);
|
||||
Onset(control, "CommonCold", 0.55f);
|
||||
|
||||
Assert.True(DiseaseEffects.Tend(
|
||||
tended,
|
||||
peopleSeed: 7,
|
||||
dayNumber: 100,
|
||||
gameMinutes: 24 * 60,
|
||||
catalog,
|
||||
medicineSkill: 90f,
|
||||
Now));
|
||||
Assert.True(HealthConditions.Tick(
|
||||
control,
|
||||
peopleSeed: 7,
|
||||
dayNumber: 100,
|
||||
gameMinutes: 24 * 60,
|
||||
catalog,
|
||||
Now));
|
||||
|
||||
Assert.True(tended.Conditions![0].Severity < control.Conditions![0].Severity);
|
||||
Assert.True(tended.Conditions[0].Progress > control.Conditions[0].Progress);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HeavySymptom_TalkWeightBelowHealthyControl()
|
||||
{
|
||||
var catalog = LoadVanilla();
|
||||
var sick = Blank("s");
|
||||
var healthy = Blank("h");
|
||||
Onset(sick, "Influenza", 0.8f);
|
||||
|
||||
var sickFactor = DiseaseEffects.TalkWeightFactor(sick, catalog, Now);
|
||||
var healthyFactor = DiseaseEffects.TalkWeightFactor(healthy, catalog, Now);
|
||||
Assert.Equal(1f, healthyFactor);
|
||||
Assert.True(sickFactor < 0.3f);
|
||||
Assert.True(sickFactor < healthyFactor);
|
||||
}
|
||||
|
||||
private static void Onset(Person person, string defName, float severity) =>
|
||||
HealthConditions.Add(
|
||||
person,
|
||||
new HealthCondition
|
||||
{
|
||||
DefName = defName,
|
||||
Severity = severity,
|
||||
Progress = 0.1f,
|
||||
Source = "test",
|
||||
StartedAt = Now.AddDays(-3),
|
||||
});
|
||||
|
||||
private static Person Blank(string id)
|
||||
{
|
||||
var cases = new CaseTable
|
||||
{
|
||||
Nom = id,
|
||||
Gen = id,
|
||||
Dat = id,
|
||||
Acc = id,
|
||||
Ins = id,
|
||||
Pre = id,
|
||||
};
|
||||
return new Person
|
||||
{
|
||||
Id = id,
|
||||
FamilyId = "f",
|
||||
Female = false,
|
||||
BirthDate = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc),
|
||||
Name = new PersonName(id, id, id, cases, cases, cases),
|
||||
IsStudent = true,
|
||||
IsStaff = false,
|
||||
IsParent = false,
|
||||
Numbers = new Dictionary<string, int>(StringComparer.Ordinal),
|
||||
Choices = new Dictionary<string, string>(StringComparer.Ordinal),
|
||||
Skills = new Dictionary<string, int>(StringComparer.Ordinal),
|
||||
Traits = [],
|
||||
Needs = new Dictionary<string, float>(StringComparer.Ordinal),
|
||||
Opinions = new Dictionary<string, int>(StringComparer.Ordinal),
|
||||
};
|
||||
}
|
||||
|
||||
private static DefCatalog LoadVanilla()
|
||||
{
|
||||
var root = Path.Combine(AppContext.BaseDirectory, "vanilla");
|
||||
var documents = PackDocuments.FromDirectory(CatalogLoader.CorePackId, root).ToList();
|
||||
return new CatalogLoader().Load([CatalogLoader.CorePackId], documents);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
using HSchool.Content;
|
||||
using HSchool.People;
|
||||
using HSchool.Server.Api;
|
||||
using HSchool.Server.Game;
|
||||
using HSchool.Simulation;
|
||||
|
||||
namespace HSchool.Server.Tests;
|
||||
|
||||
public class PersonCardReaderHealthTests
|
||||
{
|
||||
private static readonly DateTime Start = new(2012, 4, 3, 9, 0, 0, DateTimeKind.Utc);
|
||||
|
||||
[Fact]
|
||||
public void Card_ShowsActiveHealthConditions()
|
||||
{
|
||||
var (catalog, map) = Vanilla();
|
||||
var roster = RosterGenerator.Generate(catalog, map, schoolSeed: 80, "Russia", Start);
|
||||
var pupil = roster.People.First(person => person.IsStudent && !person.IsParent);
|
||||
HealthConditions.Add(
|
||||
pupil,
|
||||
new HealthCondition
|
||||
{
|
||||
DefName = "Influenza",
|
||||
Severity = 0.5f,
|
||||
Progress = 0.2f,
|
||||
Source = "test",
|
||||
StartedAt = Start.AddDays(-3),
|
||||
});
|
||||
|
||||
var school = School.Create(80, "HealthCard", Start, catalog, map);
|
||||
using (school)
|
||||
{
|
||||
school.InstallPeople(roster, 80, "Russia", ApplicantPool.Empty);
|
||||
var card = PersonCardReader.Read(school, pupil.Id, "ru");
|
||||
Assert.NotNull(card);
|
||||
Assert.NotNull(card!.HealthConditions);
|
||||
var row = Assert.Single(card.HealthConditions!);
|
||||
Assert.Equal("Influenza", row.DefName);
|
||||
Assert.Equal("Грипп", row.Label);
|
||||
Assert.Equal(0.5f, row.Severity);
|
||||
Assert.Equal(0.2f, row.Progress);
|
||||
Assert.Equal("Высокая температура, мало сил на разговоры", row.Effect);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HealthyCard_HasEmptyHealthConditions()
|
||||
{
|
||||
var (catalog, map) = Vanilla();
|
||||
var roster = RosterGenerator.Generate(catalog, map, schoolSeed: 80, "Russia", Start);
|
||||
var pupil = roster.People.First(person =>
|
||||
person.IsStudent && (person.Conditions is null || person.Conditions.Count == 0));
|
||||
var school = School.Create(81, "HealthEmpty", Start, catalog, map);
|
||||
using (school)
|
||||
{
|
||||
school.InstallPeople(roster, 81, "Russia", ApplicantPool.Empty);
|
||||
var card = PersonCardReader.Read(school, pupil.Id, "en");
|
||||
Assert.NotNull(card);
|
||||
Assert.NotNull(card!.HealthConditions);
|
||||
Assert.Empty(card.HealthConditions!);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WorkerCommands_HaveNoHealOrTendIntent()
|
||||
{
|
||||
var names = typeof(WorkerCommand).GetNestedTypes()
|
||||
.Select(type => type.Name)
|
||||
.ToArray();
|
||||
Assert.DoesNotContain(names, name => name.Contains("Heal", StringComparison.OrdinalIgnoreCase));
|
||||
Assert.DoesNotContain(names, name => name.Contains("Tend", StringComparison.OrdinalIgnoreCase));
|
||||
Assert.DoesNotContain(names, name => name.Contains("Cure", StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
private static (DefCatalog Catalog, MapLayout Map) Vanilla()
|
||||
{
|
||||
var root = Path.Combine(AppContext.BaseDirectory, "vanilla");
|
||||
Assert.True(Directory.Exists(root), $"Vanilla pack missing at {root}.");
|
||||
var documents = new List<ContentDocument>();
|
||||
foreach (var path in Directory.EnumerateFiles(root, "*.*", SearchOption.AllDirectories))
|
||||
{
|
||||
if (!path.EndsWith(".jsonc", StringComparison.OrdinalIgnoreCase)
|
||||
&& !path.EndsWith(".json", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
documents.Add(new ContentDocument(
|
||||
CatalogLoader.CorePackId,
|
||||
Path.GetRelativePath(root, path).Replace('\\', '/'),
|
||||
File.ReadAllText(path)));
|
||||
}
|
||||
|
||||
var catalog = new CatalogLoader().Load([CatalogLoader.CorePackId], documents);
|
||||
var map = CatalogLoader.LastDefaultMap([CatalogLoader.CorePackId], documents);
|
||||
Assert.NotNull(map);
|
||||
return (catalog, map);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
using Arch.Core;
|
||||
using HSchool.Ai;
|
||||
using HSchool.Content;
|
||||
using HSchool.People;
|
||||
using HSchool.Schedule;
|
||||
|
||||
namespace HSchool.Simulation.Tests;
|
||||
|
||||
public class NurseCareSimulationTests
|
||||
{
|
||||
private static readonly DateTime TuesdayMorning = new(2012, 4, 3, 8, 0, 0, DateTimeKind.Utc);
|
||||
|
||||
[Fact]
|
||||
public void NurseInOffice_SeverityFallsFasterThanUntendedControl()
|
||||
{
|
||||
using var tended = OpenWithNurse();
|
||||
using var control = OpenWithNurse();
|
||||
var tendedPupil = MakeSick(tended, severity: 0.6f);
|
||||
var controlPupil = MakeSick(control, severity: 0.6f);
|
||||
SetMedicine(tended, 80);
|
||||
SetMedicine(control, 80);
|
||||
|
||||
PlaceAt(tended, tendedPupil.Id, "medical-office");
|
||||
PlaceAt(control, controlPupil.Id, "classroom-101");
|
||||
PlaceNurseAt(tended, "medical-office");
|
||||
PlaceNurseAt(control, "classroom-101");
|
||||
|
||||
// Enqueue + admit so tend applies to the co-located patient.
|
||||
NurseCareSystem.Apply(tended, gameMinutes: 0);
|
||||
Assert.True(NurseCareSystem.IsVisiting(tended, tendedPupil.Id));
|
||||
NurseCareSystem.Apply(tended, gameMinutes: 24 * 60);
|
||||
|
||||
Assert.True(HealthConditions.Tick(
|
||||
controlPupil,
|
||||
control.PeopleSeed,
|
||||
DateOnly.FromDateTime(control.Clock.Time).DayNumber,
|
||||
gameMinutes: 24 * 60,
|
||||
control.Catalog,
|
||||
control.Clock.Time));
|
||||
|
||||
Assert.True(tendedPupil.Conditions![0].Severity < controlPupil.Conditions![0].Severity);
|
||||
Assert.True(tendedPupil.Conditions[0].Progress > controlPupil.Conditions[0].Progress);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SkipEmpty_ClearsNurseVisitQueue()
|
||||
{
|
||||
using var school = OpenWithNurse();
|
||||
var pupil = MakeSick(school, severity: 0.7f);
|
||||
NurseCareSystem.Apply(school, gameMinutes: 0);
|
||||
Assert.True(NurseCareSystem.IsVisiting(school, pupil.Id));
|
||||
Assert.NotEmpty(school.NurseVisits);
|
||||
|
||||
ClearCampus(school);
|
||||
school.Clock.JumpTo(new DateTime(2012, 4, 3, 20, 0, 0, DateTimeKind.Utc));
|
||||
var result = school.TrySkipEmpty();
|
||||
Assert.Equal(SkipEmptyError.None, result.Error);
|
||||
Assert.Empty(school.NurseVisits);
|
||||
Assert.False(NurseCareSystem.IsVisiting(school, pupil.Id));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WithoutNurse_DoesNotEnqueue()
|
||||
{
|
||||
using var school = OpenStaffedNoNurse();
|
||||
var pupil = MakeSick(school, severity: 0.7f);
|
||||
NurseCareSystem.Apply(school, gameMinutes: 0);
|
||||
Assert.False(NurseCareSystem.IsVisiting(school, pupil.Id));
|
||||
Assert.Empty(school.NurseVisits);
|
||||
}
|
||||
|
||||
private static Person MakeSick(School school, float severity)
|
||||
{
|
||||
var pupil = school.Roster!.People.First(person => person.IsStudent && !person.IsParent);
|
||||
HealthConditions.Add(
|
||||
pupil,
|
||||
new HealthCondition
|
||||
{
|
||||
DefName = "CommonCold",
|
||||
Severity = severity,
|
||||
Progress = 0.1f,
|
||||
Source = "test",
|
||||
StartedAt = TuesdayMorning.AddDays(-2),
|
||||
});
|
||||
return pupil;
|
||||
}
|
||||
|
||||
private static void SetMedicine(School school, int medicine)
|
||||
{
|
||||
var nurse = school.Roster!.People.First(person =>
|
||||
person.IsStaff && Staffing.NursePosition.Equals(person.Position, StringComparison.Ordinal));
|
||||
((Dictionary<string, int>)nurse.Skills)[NurseCare.MedicineSkill] = medicine;
|
||||
var query = new QueryDescription().WithAll<PersonIdentity, PersonSkills>();
|
||||
school.World.Query(in query, (ref PersonIdentity identity, ref PersonSkills skills) =>
|
||||
{
|
||||
if (identity.Id.Equals(nurse.Id, StringComparison.Ordinal))
|
||||
{
|
||||
skills.Values[NurseCare.MedicineSkill] = medicine;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void PlaceNurseAt(School school, string nodeId)
|
||||
{
|
||||
var nurseId = NurseCare.NurseId(school.Roster!)!;
|
||||
PlaceAt(school, nurseId, nodeId);
|
||||
}
|
||||
|
||||
private static void PlaceAt(School school, string personId, string? nodeId)
|
||||
{
|
||||
TalkCircleSystem.Interrupt(school, personId);
|
||||
var query = new QueryDescription().WithAll<PersonIdentity, Presence, PersonActivity, Intent>();
|
||||
school.World.Query(
|
||||
in query,
|
||||
(ref PersonIdentity identity, ref Presence presence, ref PersonActivity activity, ref Intent intent) =>
|
||||
{
|
||||
if (!identity.Id.Equals(personId, StringComparison.Ordinal))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
presence = nodeId is null ? Presence.OffCampus : new Presence(nodeId, 0f, nodeId, false, []);
|
||||
activity = PersonActivity.Idle;
|
||||
intent = Intent.None;
|
||||
});
|
||||
}
|
||||
|
||||
private static void ClearCampus(School school)
|
||||
{
|
||||
var query = new QueryDescription().WithAll<PersonIdentity, Presence, PersonActivity, Intent>();
|
||||
school.World.Query(
|
||||
in query,
|
||||
(ref PersonIdentity _, ref Presence presence, ref PersonActivity activity, ref Intent intent) =>
|
||||
{
|
||||
presence = Presence.OffCampus;
|
||||
activity = PersonActivity.Idle;
|
||||
intent = Intent.None;
|
||||
});
|
||||
}
|
||||
|
||||
private static School OpenWithNurse()
|
||||
{
|
||||
var school = OpenStaffedNoNurse();
|
||||
HireNurse(school);
|
||||
return school;
|
||||
}
|
||||
|
||||
private static void HireNurse(School school)
|
||||
{
|
||||
const float cap = 100_000f;
|
||||
var pool = school.Applicants!;
|
||||
var applicantId = pool.Applicants[0].Person.Id;
|
||||
var hired = Staffing.Hire(
|
||||
school.Catalog!,
|
||||
school.Map!,
|
||||
school.Roster!,
|
||||
pool,
|
||||
applicantId,
|
||||
Staffing.NursePosition,
|
||||
cap);
|
||||
Assert.Equal(StaffingError.None, hired.Error);
|
||||
school.ApplyStaffing(hired.Roster, hired.Pool);
|
||||
Assert.NotNull(NurseCare.NurseId(school.Roster!));
|
||||
}
|
||||
|
||||
private static School OpenStaffedNoNurse()
|
||||
{
|
||||
var (catalog, map) = Vanilla();
|
||||
var roster = RosterGenerator.Generate(catalog, map, schoolSeed: 80, "Russia", TuesdayMorning);
|
||||
var pool = ApplicantPool.Create(catalog, roster, 80, "Russia", TuesdayMorning);
|
||||
var school = School.Create(80, "NurseCare", TuesdayMorning, catalog, map);
|
||||
school.InstallPeople(roster, 80, "Russia", pool);
|
||||
var schoolClass = roster.Classes.First(row => row.RoomId == "classroom-101");
|
||||
school.SetTimetable(new Timetable(
|
||||
[
|
||||
new LessonPlacement(schoolClass.Id, "Mathematics", "t1", schoolClass.RoomId, Day: 1, Period: 1),
|
||||
],
|
||||
[]));
|
||||
school.Clock.JumpTo(TuesdayMorning);
|
||||
return school;
|
||||
}
|
||||
|
||||
private static (DefCatalog Catalog, MapLayout Map) Vanilla()
|
||||
{
|
||||
var root = Path.Combine(AppContext.BaseDirectory, "vanilla");
|
||||
Assert.True(Directory.Exists(root), $"Vanilla pack missing at {root}.");
|
||||
var documents = new List<ContentDocument>();
|
||||
foreach (var path in Directory.EnumerateFiles(root, "*.*", SearchOption.AllDirectories))
|
||||
{
|
||||
if (!path.EndsWith(".jsonc", StringComparison.OrdinalIgnoreCase)
|
||||
&& !path.EndsWith(".json", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
documents.Add(new ContentDocument(
|
||||
CatalogLoader.CorePackId,
|
||||
Path.GetRelativePath(root, path).Replace('\\', '/'),
|
||||
File.ReadAllText(path)));
|
||||
}
|
||||
|
||||
var catalog = new CatalogLoader().Load([CatalogLoader.CorePackId], documents);
|
||||
var map = CatalogLoader.LastDefaultMap([CatalogLoader.CorePackId], documents);
|
||||
Assert.NotNull(map);
|
||||
return (catalog, map);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user