-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudySet.cs
More file actions
226 lines (183 loc) · 5.81 KB
/
StudySet.cs
File metadata and controls
226 lines (183 loc) · 5.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
using System.Linq.Expressions;
using System.Reflection;
using System;
using System.IO;
public class StudySet : Directory
{
private Dictionary<string, string> _studyItems;
private List<string> _mastered;
private List<string> _stillLearning;
private List<string> _unkown;
private bool _answerWithTerm;
public StudySet(string name, string parentId)
: base(name, parentId)
{
_studyItems = new Dictionary<string, string>();
_mastered = new List<string>();
_stillLearning = new List<string>();
_unkown = new List<string>();
_answerWithTerm = true;
}
public void AddTerm(string term, string definition)
{
_studyItems.Add(term, definition);
_unkown.Add(term);
return;
}
public void RemoveTerm(int index)
{
List<string> keysList = new List<string>(_studyItems.Keys);
string term = keysList[index];
_studyItems.Remove(term);
UncatagorizeTerm(term);
return;
}
public string GetTermDefinition(string term)
{
return _studyItems[term];
}
public void DisplayTerms(int startingIndex)
{
int i = startingIndex;
foreach(KeyValuePair<string, string> term in _studyItems)
{
Console.WriteLine($"\n{i}. {term.Key}: {term.Value}");
i++;
}
}
public void UploadNotes()
{
Console.WriteLine("INSTRUCTIONS:");
Console.WriteLine("1. place txt file in /uploads directory.");
Console.WriteLine("2. File must contain ';' seperated values (TERM;DEFINITION)");
Console.WriteLine("3. Upload notes and enter full name for file (e.g. 1.3-flashcards.txt)");
Console.WriteLine("\nUse '1.3-flashcards.txt' to test it out!");
Console.Write("Filename: ");
string filename = Console.ReadLine()!;
string currentDirectory = System.IO.Directory.GetCurrentDirectory();
string relativePath = $"upload/{filename}";
string filePath = Path.Combine(currentDirectory, relativePath);
using (StreamReader reader = new StreamReader(filePath))
{
string content = reader.ReadToEnd();
string[] fileEntries = content.Split('\n');
foreach(string entry in fileEntries)
{
if (entry.Contains(";"))
{
try
{
string[] splitTerms = entry.Split(';');
_studyItems.Add(splitTerms[0], splitTerms[1]);
_unkown.Add(splitTerms[0]);
}
catch (ArgumentException)
{
continue;
}
}
}
}
Console.WriteLine("Load complete.");
}
public string UncatagorizeTerm(string term)
{
string category = "";
if (_unkown.Contains(term))
{
_unkown.Remove(term);
category = "unknown";
}
else if (_stillLearning.Contains(term))
{
_stillLearning.Remove(term);
category = "stillLearning";
}
else if (_mastered.Contains(term))
{
_mastered.Remove(term);
category = "mastered";
}
return category;
}
public void UpdateTermClassifactions(Dictionary<string, bool> termResults)
{
foreach(KeyValuePair<string, bool> result in termResults)
{
string previousCategory = UncatagorizeTerm(result.Key);
if (result.Value == true)
{
if (previousCategory == "unknown")
{
_stillLearning.Add(result.Key);
}
else if (previousCategory == "stillLearning" || previousCategory == "mastered")
{
_mastered.Add(result.Key);
}
}
else if (result.Value == false)
{
if (previousCategory == "unknown")
{
_unkown.Add(result.Key);
}
else
{
_stillLearning.Add(result.Key);
}
}
}
}
public (List<string>, List<string>, List<string>) GetClassifications()
{
return (_unkown, _stillLearning, _mastered);
}
public List<int> GetClassificationSizes()
{
List<int> sizes = new List<int>{_mastered.Count, _stillLearning.Count, _unkown.Count};
return sizes;
}
public bool GetStudySetting()
{
return _answerWithTerm;
}
public void UpdateStudySetting(bool setting)
{
_answerWithTerm = setting;
return;
}
public List<string> GetRandomTerms(int quantity=3)
{
ICollection<string> dictKeys = _studyItems.Keys;
List<string> keys = new List<string>(dictKeys.ToList());
List<string> terms = new List<string>();
for(int i=0; i < quantity; i++)
{
if (keys.Count < 1)
{
keys = dictKeys.ToList();
}
Random random = new Random();
int index = random.Next(keys.Count);
terms.Add(keys[index]);
keys.RemoveAt(index);
}
return terms;
}
public void DisplayClassification()
{
Console.WriteLine("\nUnknown:");
Console.WriteLine(string.Join(" | ", _unkown));
Console.WriteLine("\nStill Learning:");
Console.WriteLine(string.Join(" | ", _stillLearning));
Console.WriteLine("\nMastered:");
Console.WriteLine(string.Join(" | ", _mastered));
return;
}
public int GetTermCount()
{
ICollection<string> dictKeys = _studyItems.Keys;
return dictKeys.Count;
}
}