-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLesson.cs
More file actions
227 lines (194 loc) · 6.81 KB
/
Copy pathLesson.cs
File metadata and controls
227 lines (194 loc) · 6.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
namespace Tutor.Core.Models;
/// <summary>
/// Represents a lesson in a Course's learning path.
/// A Lesson is a major section of the curriculum that groups related Topics.
///
/// Key distinction:
/// - Lessons belong to the Course structure (the curated learning path)
/// - Lessons reference Concepts from the KnowledgeBase by ID (no duplication)
/// - The hierarchy is: Course -> Lessons -> Topics -> Concepts
/// </summary>
public class Lesson
{
/// <summary>
/// Unique identifier for this lesson.
/// </summary>
public string Id { get; set; } = Guid.NewGuid().ToString();
/// <summary>
/// The title of this lesson.
/// </summary>
public string Title { get; set; } = "";
/// <summary>
/// A brief summary of what this lesson covers.
/// </summary>
public string Summary { get; set; } = "";
/// <summary>
/// The order of this lesson in the course (0-based).
/// </summary>
public int Order { get; set; }
/// <summary>
/// The ID of the CourseStructure this lesson belongs to.
/// </summary>
public string CourseStructureId { get; set; } = "";
/// <summary>
/// The topics contained in this lesson, in learning order.
/// </summary>
public List<LessonTopic> Topics { get; set; } = [];
/// <summary>
/// Optional icon for display in navigation (Bootstrap Icons class name).
/// </summary>
public string? Icon { get; set; }
/// <summary>
/// Optional tags for categorization.
/// </summary>
public List<string> Tags { get; set; } = [];
/// <summary>
/// Estimated duration in minutes.
/// </summary>
public int EstimatedMinutes { get; set; }
/// <summary>
/// When this lesson was created.
/// </summary>
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
/// <summary>
/// When this lesson was last modified.
/// </summary>
public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
/// <summary>
/// Gets the total number of topics in this lesson.
/// </summary>
public int TopicCount => Topics.Count;
/// <summary>
/// Gets the total number of concepts across all topics.
/// </summary>
public int TotalConceptCount => Topics.Sum(t => t.ConceptIds.Count);
/// <summary>
/// Gets all concept IDs in this lesson in order.
/// </summary>
public IEnumerable<string> GetAllConceptIds()
{
return Topics
.OrderBy(t => t.Order)
.SelectMany(t => t.ConceptIds);
}
/// <summary>
/// Hierarchical sections within this lesson/chapter.
/// Sections provide a multi-level TOC structure.
/// </summary>
public List<Section> Sections { get; set; } = [];
/// <summary>
/// Gets total count of all sections (including nested).
/// </summary>
public int GetTotalSectionCount()
{
return Sections.Sum(s => 1 + CountNestedSections(s));
}
private static int CountNestedSections(Section section)
{
return section.Children.Sum(c => 1 + CountNestedSections(c));
}
/// <summary>
/// Finds a section by ID within this lesson.
/// </summary>
public Section? FindSection(string sectionId)
{
foreach (var section in Sections)
{
var found = section.FindSection(sectionId);
if (found != null) return found;
}
return null;
}
/// <summary>
/// Gets all sections flattened in order.
/// </summary>
public IEnumerable<Section> GetAllSectionsFlattened()
{
foreach (var section in Sections.OrderBy(s => s.Order))
{
yield return section;
foreach (var nested in GetNestedSectionsFlattened(section))
{
yield return nested;
}
}
}
private static IEnumerable<Section> GetNestedSectionsFlattened(Section section)
{
foreach (var child in section.Children.OrderBy(c => c.Order))
{
yield return child;
foreach (var nested in GetNestedSectionsFlattened(child))
{
yield return nested;
}
}
}
/// <summary>
/// Generates section numbers for the TOC (1a, 1b, 1a-i, etc.)
/// </summary>
public void GenerateSectionNumbers(int lessonNumber)
{
var letters = "abcdefghijklmnopqrstuvwxyz";
var romanNumerals = new[] { "i", "ii", "iii", "iv", "v", "vi", "vii", "viii", "ix", "x" };
for (int i = 0; i < Sections.Count; i++)
{
var section = Sections[i];
section.Number = $"{lessonNumber}{letters[i % 26]}";
section.Depth = 0;
GenerateChildNumbers(section, romanNumerals);
}
}
private static void GenerateChildNumbers(Section parent, string[] romanNumerals)
{
var greekLetters = "αβγδεζηθικλμνξοπρστυφχψω";
for (int i = 0; i < parent.Children.Count; i++)
{
var child = parent.Children[i];
child.Depth = parent.Depth + 1;
child.Number = child.Depth switch
{
1 => $"{parent.Number}-{romanNumerals[i % romanNumerals.Length]}",
2 => $"{parent.Number}-{greekLetters[i % greekLetters.Length]}",
_ => $"{parent.Number}.{i + 1}"
};
GenerateChildNumbers(child, romanNumerals);
}
}
}
/// <summary>
/// Represents a topic's placement within a lesson.
/// Topics group related concepts and reference them by ID from the KnowledgeBase.
/// </summary>
public class LessonTopic
{
/// <summary>
/// Unique identifier for this topic instance within the lesson.
/// </summary>
public string Id { get; set; } = Guid.NewGuid().ToString();
/// <summary>
/// The title of this topic.
/// </summary>
public string Title { get; set; } = "";
/// <summary>
/// A brief summary of what this topic covers.
/// </summary>
public string Summary { get; set; } = "";
/// <summary>
/// The order of this topic within the lesson (0-based).
/// </summary>
public int Order { get; set; }
/// <summary>
/// IDs of Concepts from the KnowledgeBase, in learning order.
/// These reference existing Concepts - no duplication of data.
/// </summary>
public List<string> ConceptIds { get; set; } = [];
/// <summary>
/// Optional icon for display in navigation.
/// </summary>
public string? Icon { get; set; }
/// <summary>
/// Optional tags for categorization.
/// </summary>
public List<string> Tags { get; set; } = [];
}