Update EventOccurrence parsing to use EventOccurrenceParseGroup for improved data structure
This commit refactors the EventOccurrence parsing logic to utilize the EventOccurrenceParseGroup class, enhancing the organization of parsed occurrences by grouping them based on event definitions and optional section levels. The changes include updates to the EventOccurrenceParseResult, EventOccurrenceParser, and EventOccurrenceParserService to accommodate the new grouping structure. Additionally, tests are modified to reflect these changes, ensuring that the parsing functionality remains intact and accurate. This refactor improves data handling and aligns with the overall architecture of the application.
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
using GoogleSheetsScheduleImport;
|
||||
|
||||
namespace Tests.GoogleSheets;
|
||||
|
||||
[TestFixture]
|
||||
public class GlobalEventDeduplicatorTests
|
||||
{
|
||||
[Test]
|
||||
public void Curfew_same_time_multiple_locations_becomes_one_line_without_location()
|
||||
{
|
||||
var lines = new List<ParsedOccurrenceLine>
|
||||
{
|
||||
new("CURFEW", "April", 9, "11 p.m. - 12:30 a.m.", "Room A", 10, 10, 1),
|
||||
new("CURFEW", "April", 9, "11 p.m. - 12:30 a.m.", "Room B", 10, 10, 2),
|
||||
new("Meeting", "April", 9, "9 a.m. - 10 a.m.", "Room A", 5, 5, 1)
|
||||
};
|
||||
|
||||
var result = GlobalEventDeduplicator.Deduplicate(lines);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(result.Count, Is.EqualTo(2));
|
||||
var curfew = result.Single(l => l.Name.Equals("CURFEW", StringComparison.OrdinalIgnoreCase));
|
||||
Assert.That(curfew.Location, Is.Empty);
|
||||
Assert.That(result.Any(l => l.Name == "Meeting"), Is.True);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using Core.Entities;
|
||||
using GoogleSheetsScheduleImport;
|
||||
|
||||
namespace Tests.GoogleSheets;
|
||||
|
||||
[TestFixture]
|
||||
public class ImportTextEmitterRoundTripTests
|
||||
{
|
||||
[Test]
|
||||
public void EmittedText_Parses_UnderGeneralSchedule()
|
||||
{
|
||||
var sheets = new List<(string SheetTitle, string SectionHeader, List<ParsedOccurrenceLine> Lines)>
|
||||
{
|
||||
("Thursday", "General Schedule", new List<ParsedOccurrenceLine>
|
||||
{
|
||||
new(
|
||||
Name: "Opening Ceremony",
|
||||
Month: "April",
|
||||
Day: 3,
|
||||
TimeRange: "9 a.m. - 10 a.m.",
|
||||
Location: "Main Hall",
|
||||
SourceRowStart: 1,
|
||||
SourceRowEnd: 1,
|
||||
SourceCol: 1)
|
||||
})
|
||||
};
|
||||
|
||||
var text = ImportTextEmitter.Build(sheets);
|
||||
var result = ParserRoundTripValidator.Validate(text, new List<EventDefinition>
|
||||
{
|
||||
EventDefinition.GeneralSchedule
|
||||
});
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(result.IsSuccess, Is.True, string.Join("; ", result.Errors));
|
||||
Assert.That(result.TotalParsed, Is.EqualTo(1));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using Core.Entities;
|
||||
using Core.Models;
|
||||
using GoogleSheetsScheduleImport;
|
||||
|
||||
namespace Tests.GoogleSheets;
|
||||
|
||||
[TestFixture]
|
||||
public class OccurrenceDisplayNameReducerTests
|
||||
{
|
||||
private static EventDefinition Cyber() =>
|
||||
new()
|
||||
{
|
||||
Id = 1,
|
||||
Name = "Cybersecurity",
|
||||
ShortName = "Cyber",
|
||||
Eligibility = "",
|
||||
EventFormat = EventFormat.Team
|
||||
};
|
||||
|
||||
[Test]
|
||||
public void Strips_ms_prefix_and_event_name()
|
||||
{
|
||||
var n = OccurrenceDisplayNameReducer.ReduceForSection(
|
||||
"MS Cybersecurity Semifinals Presentations",
|
||||
Cyber(),
|
||||
SchoolLevel.MiddleSchool);
|
||||
Assert.That(n, Is.EqualTo("Semifinals Presentations"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using Core.Entities;
|
||||
using GoogleSheetsScheduleImport;
|
||||
|
||||
namespace Tests.GoogleSheets;
|
||||
|
||||
[TestFixture]
|
||||
public class OccurrenceEventMatcherTests
|
||||
{
|
||||
private static EventDefinition E(string name, int id) =>
|
||||
new()
|
||||
{
|
||||
Id = id,
|
||||
Name = name,
|
||||
ShortName = name,
|
||||
Eligibility = "",
|
||||
EventFormat = EventFormat.Team
|
||||
};
|
||||
|
||||
[Test]
|
||||
public void Ms_prefix_matches_Biotechnology()
|
||||
{
|
||||
var events = new List<EventDefinition> { E("Biotechnology", 1), E("Biotechnology Design", 2) };
|
||||
var ok = OccurrenceEventMatcher.TryMatch("MS Biotechnology Semifinals Interviews April ...", events, out var evt, out var lvl);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(ok, Is.True);
|
||||
Assert.That(evt!.Name, Is.EqualTo("Biotechnology"));
|
||||
Assert.That(lvl, Is.EqualTo(Core.Models.SchoolLevel.MiddleSchool));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void No_Clear_prefix_goes_unmatched_or_general_bucket()
|
||||
{
|
||||
var events = new List<EventDefinition> { E("Opening Session", 1) };
|
||||
var ok = OccurrenceEventMatcher.TryMatch("Opening Session April 10 9 a.m.", events, out var evt, out var lvl);
|
||||
Assert.That(ok, Is.False);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using GoogleSheetsScheduleImport;
|
||||
|
||||
namespace Tests.GoogleSheets;
|
||||
|
||||
[TestFixture]
|
||||
public class ScheduleGridExtractorTests
|
||||
{
|
||||
[Test]
|
||||
public void Extract_SingleBlock_OneOccurrenceWithEndTimeFromNextSlot()
|
||||
{
|
||||
string?[][] values =
|
||||
[
|
||||
[null, "Main Hall"],
|
||||
["9:00 a.m.", "Opening Ceremony"],
|
||||
["10:00 a.m.", null]
|
||||
];
|
||||
string?[][] bg =
|
||||
[
|
||||
[null, null],
|
||||
[null, null],
|
||||
[null, null]
|
||||
];
|
||||
var grid = new GridSheetModel
|
||||
{
|
||||
SheetTitle = "Day1",
|
||||
Values = values,
|
||||
BackgroundKeys = bg
|
||||
};
|
||||
var warnings = new List<string>();
|
||||
var lines = ScheduleGridExtractor.Extract(grid, "April", 2, warnings);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(lines, Has.Count.EqualTo(1));
|
||||
Assert.That(lines[0].Name, Is.EqualTo("Opening Ceremony"));
|
||||
Assert.That(lines[0].Month, Is.EqualTo("April"));
|
||||
Assert.That(lines[0].Day, Is.EqualTo(2));
|
||||
Assert.That(lines[0].Location, Is.EqualTo("Main Hall"));
|
||||
Assert.That(lines[0].TimeRange, Is.EqualTo("9 a.m. - 10 a.m."));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using GoogleSheetsScheduleImport;
|
||||
|
||||
namespace Tests.GoogleSheets;
|
||||
|
||||
[TestFixture]
|
||||
public class TextNormalizationTests
|
||||
{
|
||||
[Test]
|
||||
public void Collapses_line_separator_and_newlines()
|
||||
{
|
||||
var s = "Banquet Room\u2028E";
|
||||
Assert.That(TextNormalization.ForSheetCell(s), Is.EqualTo("Banquet Room E"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user