Mark phase 84 wet-aftereffect in progress.
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
using HSchool.Content;
|
||||
|
||||
namespace HSchool.Ai.Tests;
|
||||
|
||||
public class LessonMarkCouplingTests
|
||||
{
|
||||
private static readonly BehaviorDef Rules = new()
|
||||
{
|
||||
DefName = "Behavior",
|
||||
LessonMarkThresholds = BehaviorDef.DefaultLessonMarkThresholds,
|
||||
LessonMarkMax = 40,
|
||||
LessonNoTextbookFactor = 0.5f,
|
||||
LessonWhisperSkillFactor = 0.4f,
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void WhisperFactor_WorsensMarkVsQuiet()
|
||||
{
|
||||
var quiet = LessonLearning.Mark(
|
||||
LessonLearning.Quality(1f, 0, 100f, 1f, textbookFactor: 1f),
|
||||
Rules);
|
||||
var whisper = LessonLearning.Mark(
|
||||
LessonLearning.Quality(1f, 0, 100f, 1f, textbookFactor: Rules.LessonWhisperSkillFactor),
|
||||
Rules);
|
||||
|
||||
Assert.True(quiet > whisper);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NoTextbook_WorsensMarkVsWithTextbook()
|
||||
{
|
||||
var withBook = LessonLearning.Mark(
|
||||
LessonLearning.Quality(1f, 0, 100f, 1f, textbookFactor: 1f),
|
||||
Rules);
|
||||
var without = LessonLearning.Mark(
|
||||
LessonLearning.Quality(1f, 0, 100f, 1f, textbookFactor: Rules.LessonNoTextbookFactor),
|
||||
Rules);
|
||||
|
||||
Assert.True(withBook > without);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Hunger_WorsensMarkVsFull()
|
||||
{
|
||||
var full = LessonLearning.Mark(LessonLearning.Quality(1f, 0, 100f, 1f, 1f), Rules);
|
||||
var hungry = LessonLearning.Mark(LessonLearning.Quality(0.2f, 0, 100f, 1f, 1f), Rules);
|
||||
|
||||
Assert.True(full > hungry);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Cold_WorsensMarkVsWarm()
|
||||
{
|
||||
var warm = LessonLearning.Mark(LessonLearning.Quality(1f, 0, 100f, warmth: 1f, textbookFactor: 1f), Rules);
|
||||
var cold = LessonLearning.Mark(LessonLearning.Quality(1f, 0, 100f, warmth: 0.2f, textbookFactor: 1f), Rules);
|
||||
|
||||
Assert.True(warm > cold);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WeakTeacher_WorsensMarkVsStrong()
|
||||
{
|
||||
var strong = LessonLearning.Mark(LessonLearning.Quality(1f, 0, teacherSkill: 100f, 1f, 1f), Rules);
|
||||
var weak = LessonLearning.Mark(LessonLearning.Quality(1f, 0, teacherSkill: 10f, 1f, 1f), Rules);
|
||||
|
||||
Assert.True(strong > weak);
|
||||
}
|
||||
}
|
||||
@@ -45,6 +45,18 @@ public class GradebookApiTests(AppHostFixture fixture)
|
||||
new { subject = "Mathematics", status = "present", period = 1 },
|
||||
TestContext.Current.CancellationToken);
|
||||
Assert.Equal(HttpStatusCode.NotFound, attendancePut.StatusCode);
|
||||
|
||||
using var summonPost = await client.PostAsJsonAsync(
|
||||
$"/api/schools/{school.Id}/people/{personId}/summon",
|
||||
new { reason = "mark", value = 2 },
|
||||
TestContext.Current.CancellationToken);
|
||||
Assert.Equal(HttpStatusCode.NotFound, summonPost.StatusCode);
|
||||
|
||||
using var summonForMark = await client.PostAsJsonAsync(
|
||||
$"/api/schools/{school.Id}/people/{personId}/summon-for-mark",
|
||||
new { value = 2 },
|
||||
TestContext.Current.CancellationToken);
|
||||
Assert.Equal(HttpStatusCode.NotFound, summonForMark.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -46,6 +46,12 @@ public class EventDefTests
|
||||
Assert.True(catalog.Events.ContainsKey("LessonCancelled"));
|
||||
Assert.Equal(EventTriggers.LessonNoTeacher, catalog.Events["LessonCancelled"].Trigger);
|
||||
Assert.Equal("Урок без учителя", catalog.Label("ru", catalog.Events["LessonCancelled"]));
|
||||
|
||||
Assert.True(catalog.Events.ContainsKey("PoorGradeTrail"));
|
||||
Assert.Equal(EventSeverities.Info, catalog.Events["PoorGradeTrail"].Severity);
|
||||
Assert.Equal(EventTriggers.PoorGradeTrail, catalog.Events["PoorGradeTrail"].Trigger);
|
||||
Assert.Equal("Слабый учебный след у ученика", catalog.Label("ru", catalog.Events["PoorGradeTrail"]));
|
||||
Assert.Equal("A pupil has a weak grade trail", catalog.Label("en", catalog.Events["PoorGradeTrail"]));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
using HSchool.Content;
|
||||
|
||||
namespace HSchool.Content.Tests;
|
||||
|
||||
public class GradeTrailBehaviorTests
|
||||
{
|
||||
private readonly CatalogLoader _loader = new();
|
||||
|
||||
[Fact]
|
||||
public void VanillaCore_LoadsGradeTrailFields()
|
||||
{
|
||||
var catalog = LoadVanilla();
|
||||
Assert.NotNull(catalog.BehaviorRules);
|
||||
Assert.Equal(0.95f, catalog.BehaviorRules.LessonDressMarkFactor);
|
||||
Assert.Equal(2.5f, catalog.BehaviorRules.PoorMarkTrailMaxAverage);
|
||||
Assert.Equal(3, catalog.BehaviorRules.PoorMarkTrailMinMarks);
|
||||
Assert.Equal(2, catalog.BehaviorRules.TruancyTrailMinCount);
|
||||
Assert.Equal(0.35f, catalog.BehaviorRules.GradeTrailSummonChance);
|
||||
Assert.Contains("truancy", catalog.BehaviorRules.OffenseMemoryKinds);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DressFactorAboveOne_FailsTheCatalog()
|
||||
{
|
||||
var documents = PackDocuments.FromDirectory(
|
||||
CatalogLoader.CorePackId,
|
||||
Path.Combine(AppContext.BaseDirectory, "vanilla"))
|
||||
.Append(PackDocuments.Def(
|
||||
CatalogLoader.CorePackId,
|
||||
"behavior",
|
||||
"bad-dress",
|
||||
"""{ "defName": "Behavior", "lessonDressMarkFactor": 1.5 }"""))
|
||||
.ToList();
|
||||
|
||||
var ex = Assert.Throws<ContentLoadException>(() => _loader.Load([CatalogLoader.CorePackId], documents));
|
||||
Assert.Contains("lessonDressMarkFactor", ex.Message, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
private DefCatalog LoadVanilla()
|
||||
{
|
||||
var root = Path.Combine(AppContext.BaseDirectory, "vanilla");
|
||||
return _loader.Load([CatalogLoader.CorePackId], PackDocuments.FromDirectory(CatalogLoader.CorePackId, root));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
using HSchool.Content;
|
||||
using HSchool.People;
|
||||
|
||||
namespace HSchool.People.Tests;
|
||||
|
||||
public class GradeTrailTests
|
||||
{
|
||||
private static readonly BehaviorDef Rules = new()
|
||||
{
|
||||
DefName = "Behavior",
|
||||
LessonMarkMax = 40,
|
||||
AttendanceMax = 40,
|
||||
PoorMarkTrailMaxAverage = 2.5f,
|
||||
PoorMarkTrailMinMarks = 3,
|
||||
TruancyTrailMinCount = 2,
|
||||
OffenseMemoryMax = 5,
|
||||
OffenseMemoryKinds = BehaviorDef.DefaultOffenseMemoryKinds,
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void ThreeTwos_IsPoorMarks()
|
||||
{
|
||||
var person = Blank("p1");
|
||||
var t0 = new DateTime(2012, 4, 3, 9, 0, 0, DateTimeKind.Utc);
|
||||
Assert.True(LessonMarkMemory.Record(person, "Mathematics", 2, t0, 1, Rules));
|
||||
Assert.True(LessonMarkMemory.Record(person, "Mathematics", 2, t0.AddHours(1), 2, Rules));
|
||||
Assert.True(LessonMarkMemory.Record(person, "Literature", 2, t0.AddHours(2), 3, Rules));
|
||||
|
||||
Assert.True(GradeTrail.HasPoorMarks(person, Rules));
|
||||
Assert.True(GradeTrail.IsPoor(person, Rules));
|
||||
Assert.Equal(2f, GradeTrail.AverageMark(person));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TwoTruancies_IsTruancyTrail_IllnessDoesNotCount()
|
||||
{
|
||||
var person = Blank("p1");
|
||||
var t0 = new DateTime(2012, 4, 3, 9, 0, 0, DateTimeKind.Utc);
|
||||
Assert.True(AttendanceMemory.Record(
|
||||
person, "Mathematics", AttendanceStatuses.Absent, t0, 1, Rules, AbsenceReasons.Truancy));
|
||||
Assert.True(AttendanceMemory.Record(
|
||||
person, "Literature", AttendanceStatuses.Absent, t0.AddHours(1), 2, Rules, AbsenceReasons.Illness));
|
||||
Assert.False(GradeTrail.HasTruancyTrail(person, Rules));
|
||||
|
||||
Assert.True(AttendanceMemory.Record(
|
||||
person, "History", AttendanceStatuses.Absent, t0.AddHours(2), 3, Rules, AbsenceReasons.Truancy));
|
||||
Assert.True(GradeTrail.HasTruancyTrail(person, Rules));
|
||||
Assert.Equal(2, GradeTrail.TruancyCount(person));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Illness_DoesNotCountAsSummonOffense()
|
||||
{
|
||||
Assert.False(GradeTrail.CountsAsSummonOffense(AbsenceReasons.Illness));
|
||||
Assert.True(GradeTrail.CountsAsSummonOffense(AbsenceReasons.Truancy));
|
||||
Assert.True(GradeTrail.CountsAsSummonOffense(null));
|
||||
}
|
||||
|
||||
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),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,242 @@
|
||||
using Arch.Core;
|
||||
using HSchool.Ai;
|
||||
using HSchool.Content;
|
||||
using HSchool.People;
|
||||
using HSchool.Schedule;
|
||||
|
||||
namespace HSchool.Simulation.Tests;
|
||||
|
||||
public class GradeTrailCouplingTests
|
||||
{
|
||||
private static readonly DateTime TuesdayMorning = new(2012, 4, 3, 6, 0, 0, DateTimeKind.Utc);
|
||||
private static readonly DateTime LessonStart = new(2012, 4, 3, 8, 30, 0, DateTimeKind.Utc);
|
||||
|
||||
[Fact]
|
||||
public void WhisperOnLesson_MarkWorseThanQuiet()
|
||||
{
|
||||
var quiet = RunMathMark(whisper: false);
|
||||
var whispered = RunMathMark(whisper: true);
|
||||
Assert.True(quiet > whispered);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NoTextbook_MarkWorseThanWithTextbook()
|
||||
{
|
||||
var withBook = RunMathMark(whisper: false, textbook: true);
|
||||
var without = RunMathMark(whisper: false, textbook: false);
|
||||
Assert.True(withBook > without);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PoorMarkTrail_EmitsNotice()
|
||||
{
|
||||
var (school, _, pupilId, _) = StaffedMath();
|
||||
using (school)
|
||||
{
|
||||
var rules = school.Catalog!.BehaviorRules!;
|
||||
var person = school.Roster!.People.First(row => row.Id == pupilId);
|
||||
var t0 = LessonStart;
|
||||
Assert.True(LessonMarkMemory.Record(person, "Mathematics", 2, t0, 1, rules));
|
||||
Assert.True(LessonMarkMemory.Record(person, "Literature", 2, t0.AddHours(1), 2, rules));
|
||||
Assert.True(LessonMarkMemory.Record(person, "History", 2, t0.AddHours(2), 3, rules));
|
||||
|
||||
school.DrainWorldEvents();
|
||||
GradeTrailSystem.AfterMark(school, person);
|
||||
|
||||
Assert.Contains(
|
||||
school.DrainWorldEvents(),
|
||||
row => row.Trigger.Equals(EventTriggers.PoorGradeTrail, StringComparison.Ordinal)
|
||||
&& row.PersonKey.Equals(pupilId, StringComparison.Ordinal));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IllnessAbsent_DoesNotAddTruancyOffense()
|
||||
{
|
||||
var (school, _, pupilId, _) = StaffedMath();
|
||||
using (school)
|
||||
{
|
||||
var person = school.Roster!.People.First(row => row.Id == pupilId);
|
||||
person.Offenses = null;
|
||||
GradeTrailSystem.AfterAbsent(school, person, AbsenceReasons.Illness);
|
||||
Assert.True(person.Offenses is null || person.Offenses.Count == 0);
|
||||
|
||||
GradeTrailSystem.AfterAbsent(school, person, AbsenceReasons.Truancy);
|
||||
Assert.NotNull(person.Offenses);
|
||||
Assert.Contains(person.Offenses!, row => row.Kind == OffenseKinds.Truancy);
|
||||
}
|
||||
}
|
||||
|
||||
private static int RunMathMark(bool whisper, bool textbook = true)
|
||||
{
|
||||
var (school, room, pupilId, teacherId) = StaffedMath();
|
||||
using (school)
|
||||
{
|
||||
AdvanceTo(school, LessonStart);
|
||||
school.ResetDayLog();
|
||||
var pupil = school.Roster!.People.First(row => row.Id == pupilId);
|
||||
pupil.LessonMarks = null;
|
||||
|
||||
SetPlace(school, pupilId, room);
|
||||
SetPlace(school, teacherId, room);
|
||||
SetSkill(school, teacherId, "Mathematics", 100f);
|
||||
SetNeed(school, pupilId, "Hunger", 1f);
|
||||
SetNeed(school, pupilId, "Warmth", 1f);
|
||||
if (textbook)
|
||||
{
|
||||
PlaceTextbook(school, pupilId, "Mathematics");
|
||||
}
|
||||
else
|
||||
{
|
||||
ClearTextbooks(school, pupilId);
|
||||
}
|
||||
|
||||
if (whisper)
|
||||
{
|
||||
var partner = school.Roster!.Classes
|
||||
.SelectMany(row => row.PupilIds)
|
||||
.First(id => id != pupilId);
|
||||
SetPlace(school, partner, room);
|
||||
PlaceTextbook(school, partner, "Mathematics");
|
||||
Assert.True(school.TryStartAction(pupilId, TalkActions.Whisper));
|
||||
}
|
||||
|
||||
LessonLearningSystem.Apply(school, 45);
|
||||
var mark = MarkOf(school, pupilId);
|
||||
Assert.NotNull(mark);
|
||||
return mark!.Value;
|
||||
}
|
||||
}
|
||||
|
||||
private static LessonMarkRecord? MarkOf(School school, string pupilId) =>
|
||||
school.Roster!.People.First(row => row.Id == pupilId).LessonMarks?.LastOrDefault();
|
||||
|
||||
private static (School School, string Homeroom, string PupilId, string TeacherId) StaffedMath()
|
||||
{
|
||||
var (catalog, map) = Vanilla();
|
||||
var roster = RosterGenerator.Generate(catalog, map, schoolSeed: 1, "Russia", TuesdayMorning);
|
||||
var pool = ApplicantPool.Create(catalog, roster, schoolSeed: 1, "Russia", TuesdayMorning);
|
||||
var hired = Staffing.Hire(catalog, map, roster, pool, pool.Applicants[0].Person.Id, Staffing.TeacherPosition, 1_000_000f);
|
||||
Assert.Equal(StaffingError.None, hired.Error);
|
||||
roster = hired.Roster;
|
||||
pool = hired.Pool;
|
||||
var hiredId = roster.People.First(person => person.IsStaff).Id;
|
||||
var schoolClass = roster.Classes.First(row =>
|
||||
row.RoomId is "classroom-101" or "classroom-102" or "classroom-103" or "classroom-104");
|
||||
var school = School.Create(1, "Стык", TuesdayMorning, catalog, map);
|
||||
school.InstallPeople(roster, seed: 1, "Russia", pool);
|
||||
school.SetTimetable(new Timetable(
|
||||
[new LessonPlacement(schoolClass.Id, "Mathematics", hiredId, schoolClass.RoomId, Day: 1, Period: 1)],
|
||||
[]));
|
||||
school.ConfigurePresence(weekDays: 5, maxDecisionsPerTick: 10_000);
|
||||
var pupil = schoolClass.PupilIds
|
||||
.Select(id => school.Roster!.People.First(person => person.Id == id))
|
||||
.First(person => !person.Traits.Contains("Lazy"));
|
||||
return (school, schoolClass.RoomId, pupil.Id, hiredId);
|
||||
}
|
||||
|
||||
private static void PlaceTextbook(School school, string personId, string subject, string location = ItemLocations.Bag)
|
||||
{
|
||||
var person = school.Roster!.People.First(row => row.Id.Equals(personId, StringComparison.Ordinal));
|
||||
if (person.Items is not IList<InventoryItem> items || items.IsReadOnly)
|
||||
{
|
||||
throw new InvalidOperationException($"Cannot mutate items for {personId}.");
|
||||
}
|
||||
|
||||
ClearTextbooks(school, personId);
|
||||
items.Add(new InventoryItem("Textbook", Color: null, Condition: 1f, location, subject));
|
||||
}
|
||||
|
||||
private static void ClearTextbooks(School school, string personId)
|
||||
{
|
||||
var person = school.Roster!.People.First(row => row.Id.Equals(personId, StringComparison.Ordinal));
|
||||
if (person.Items is not IList<InventoryItem> items || items.IsReadOnly)
|
||||
{
|
||||
throw new InvalidOperationException($"Cannot mutate items for {personId}.");
|
||||
}
|
||||
|
||||
for (var i = items.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (items[i].Subject is not null)
|
||||
{
|
||||
items.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void AdvanceTo(School school, DateTime until)
|
||||
{
|
||||
while (school.Clock.Time < until)
|
||||
{
|
||||
school.Tick(0.2d, 5d);
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetPlace(School school, string personId, string node, string[]? path = null, float remaining = 0f)
|
||||
{
|
||||
TalkCircleSystem.Interrupt(school, personId);
|
||||
school.TalkCircleByPerson.Remove(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))
|
||||
{
|
||||
presence = new Presence(node, remaining, node, HeadingHome: false, path ?? []);
|
||||
activity = PersonActivity.Idle;
|
||||
intent = Intent.None;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void SetSkill(School school, string personId, string skill, float value)
|
||||
{
|
||||
var query = new QueryDescription().WithAll<PersonIdentity, PersonSkills>();
|
||||
school.World.Query(
|
||||
in query,
|
||||
(ref PersonIdentity identity, ref PersonSkills skills) =>
|
||||
{
|
||||
if (identity.Id.Equals(personId, StringComparison.Ordinal))
|
||||
{
|
||||
skills.Values[skill] = value;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void SetNeed(School school, string personId, string need, float value)
|
||||
{
|
||||
var query = new QueryDescription().WithAll<PersonIdentity, PersonNeeds>();
|
||||
school.World.Query(
|
||||
in query,
|
||||
(ref PersonIdentity identity, ref PersonNeeds needs) =>
|
||||
{
|
||||
if (identity.Id.Equals(personId, StringComparison.Ordinal))
|
||||
{
|
||||
needs.Values[need] = value;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static (DefCatalog Catalog, MapLayout Map) Vanilla()
|
||||
{
|
||||
var root = Path.Combine(AppContext.BaseDirectory, "vanilla");
|
||||
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;
|
||||
}
|
||||
|
||||
var relative = Path.GetRelativePath(root, path).Replace('\\', '/');
|
||||
documents.Add(new ContentDocument(CatalogLoader.CorePackId, relative, 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