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:
2026-04-04 21:55:44 -04:00
parent 4dcd9e5aab
commit f400813667
39 changed files with 1896 additions and 93 deletions
+10
View File
@@ -0,0 +1,10 @@
using Core.Entities;
namespace Core.Models;
/// <summary>
/// Groups parsed occurrences by event definition and optional section school level from headers
/// (e.g. "Prepared Speech - HS" vs "Prepared Speech - MS"). The same <see cref="EventDefinition"/>
/// can appear in multiple groups.
/// </summary>
public readonly record struct EventOccurrenceParseGroup(EventDefinition EventDefinition, SchoolLevel? SectionSchoolLevel);
+4 -4
View File
@@ -9,11 +9,11 @@ namespace Core.Models;
public class EventOccurrenceParseResult
{
/// <summary>
/// Dictionary of parsed event occurrences, keyed by EventDefinition.
/// For special events (GeneralSchedule, MeetTheCandidates, ChapterOfficerMeeting, VotingDelegateMeeting, SocialGathering),
/// the EventDefinition key will be the static instance.
/// Parsed occurrences keyed by event definition and optional section MS/HS from schedule headers.
/// Special events use <see cref="EventOccurrenceParseGroup.EventDefinition"/> static instances with
/// <see cref="EventOccurrenceParseGroup.SectionSchoolLevel"/> typically null.
/// </summary>
public IDictionary<EventDefinition, List<EventOccurrence>> Occurrences { get; set; } = new Dictionary<EventDefinition, List<EventOccurrence>>();
public IDictionary<EventOccurrenceParseGroup, List<EventOccurrence>> Occurrences { get; set; } = new Dictionary<EventOccurrenceParseGroup, List<EventOccurrence>>();
/// <summary>
/// List of parsing errors (critical issues that prevented parsing).
+10 -8
View File
@@ -1,4 +1,4 @@
using System.Text.RegularExpressions;
using System.Text.RegularExpressions;
using Core.Entities;
using Core.Models;
using EventOccurrenceParsers = Core.Parsers.EventOccurrence;
@@ -12,7 +12,7 @@ namespace Core.Parsers;
/// </summary>
public class EventOccurrenceParserResult
{
public IDictionary<EventDefinition, List<Entities.EventOccurrence>> Occurrences { get; set; } = new Dictionary<EventDefinition, List<Entities.EventOccurrence>>();
public IDictionary<EventOccurrenceParseGroup, List<Entities.EventOccurrence>> Occurrences { get; set; } = new Dictionary<EventOccurrenceParseGroup, List<Entities.EventOccurrence>>();
public List<ParsingIssue> Issues { get; set; } = new();
public List<string> SkippedSectionHeaders { get; set; } = new();
public int SkippedEventCount { get; set; }
@@ -296,12 +296,14 @@ public class EventOccurrenceParser
Location = location
};
if (!occurrences.ContainsKey(eventDefinition))
occurrences.Add(eventDefinition, []);
occurrences[eventDefinition].Add(eventOccurrence);
// Reset section level when we successfully parse an occurrence (means we're in a valid section)
currentSectionLevel = null;
var groupKey = new EventOccurrenceParseGroup(eventDefinition, currentSectionLevel);
if (!occurrences.TryGetValue(groupKey, out var groupList))
{
groupList = [];
occurrences[groupKey] = groupList;
}
groupList.Add(eventOccurrence);
}
return result;
@@ -65,7 +65,8 @@ public class EventOccurrenceParserService : IEventOccurrenceParserService
// Convert parsed occurrences to result format, handling special event types
foreach (var kvp in parsedOccurrences)
{
var eventDefinition = kvp.Key;
var group = kvp.Key;
var eventDefinition = group.EventDefinition;
var occurrences = kvp.Value;
// Check if this is a special event type (not stored in database)
@@ -90,8 +91,7 @@ public class EventOccurrenceParserService : IEventOccurrenceParserService
};
}
// Add to result with the special EventDefinition as key
result.Occurrences[eventDefinition] = occurrences;
result.Occurrences[group] = occurrences;
}
else
{
@@ -102,7 +102,7 @@ public class EventOccurrenceParserService : IEventOccurrenceParserService
occurrence.SpecialEventType = null;
}
result.Occurrences[eventDefinition] = occurrences;
result.Occurrences[group] = occurrences;
}
}