Enhance event occurrence parsing with school level filtering

This commit introduces a new SchoolLevel enum and updates the EventOccurrenceParser to filter event occurrences based on the specified school level (Middle School or High School). The EventOccurrenceParseResult and EventOccurrenceParserResult classes have been updated to track skipped section headers and counts for both school levels. Additionally, the EventOccurrenceParserService has been modified to read the school level from configuration, and the UI has been updated to allow users to select the school level for event imports. This enhancement improves the accuracy of event parsing and provides better user feedback on skipped occurrences.
This commit is contained in:
2026-01-09 09:39:00 -05:00
parent ea1a4a04ad
commit 8183c0200d
7 changed files with 270 additions and 27 deletions
+34 -4
View File
@@ -4,6 +4,7 @@ using Core.Entities;
using Core.Models;
using Core.Parsers;
using Microsoft.Extensions.Configuration;
using SchoolLevel = Core.Models.SchoolLevel;
namespace Core.Services;
@@ -13,9 +14,11 @@ namespace Core.Services;
/// </summary>
public class EventOccurrenceParserService : IEventOccurrenceParserService
{
private readonly IConfiguration? _configuration;
public EventOccurrenceParserService(IConfiguration? configuration = null)
{
// Configuration parameter kept for backward compatibility but not used
_configuration = configuration;
}
/// <inheritdoc/>
@@ -38,8 +41,22 @@ public class EventOccurrenceParserService : IEventOccurrenceParserService
File.WriteAllText(tempFile, text, Encoding.UTF8);
var fileInfo = new FileInfo(tempFile);
// Use the existing EventOccurrenceParser
var parser = new EventOccurrenceParser(fileInfo, events);
// Read SchoolLevel from configuration
SchoolLevel? schoolLevel = null;
if (_configuration != null)
{
var schoolLevelStr = _configuration.GetSection("ChapterSettings:SchoolLevel").Get<string>();
if (!string.IsNullOrWhiteSpace(schoolLevelStr))
{
if (Enum.TryParse<SchoolLevel>(schoolLevelStr, ignoreCase: true, out var parsed))
{
schoolLevel = parsed;
}
}
}
// Use the existing EventOccurrenceParser with school level
var parser = new EventOccurrenceParser(fileInfo, events, schoolLevel);
var parserResult = parser.Parse();
// Copy occurrences from parser result
@@ -92,8 +109,21 @@ public class EventOccurrenceParserService : IEventOccurrenceParserService
// Copy parsing issues from parser result
result.Issues.AddRange(parserResult.Issues);
// Copy skipped HS section headers from parser result
// Copy skipped section headers from parser result
result.SkippedHSSectionHeaders.AddRange(parserResult.SkippedHSSectionHeaders);
result.SkippedMSSectionHeaders.AddRange(parserResult.SkippedMSSectionHeaders);
result.SkippedMSEventCount = parserResult.SkippedMSEventCount;
result.SkippedHSEventCount = parserResult.SkippedHSEventCount;
// Add informational messages about skipped events
if (parserResult.SkippedMSEventCount > 0)
{
result.Warnings.Add($"Skipped {parserResult.SkippedMSEventCount} Middle School (MS) event occurrence(s) based on school level setting");
}
if (parserResult.SkippedHSEventCount > 0)
{
result.Warnings.Add($"Skipped {parserResult.SkippedHSEventCount} High School (HS) event occurrence(s) based on school level setting");
}
// Validate locations and add warnings for problematic ones
ValidateLocations(result);