Skip to content

Commit e1bb4f4

Browse files
committed
More code style improvements
1 parent 52fca69 commit e1bb4f4

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

src/Vocup/IO/Vhf1Format2.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,11 @@ private async ValueTask ReadResults(Book book, string fileName, string vhrCode,
186186
for (int i = 0; i < book.Words.Count; i++)
187187
{
188188
Word word = book.Words[i];
189+
190+
// Same practice history for all synonyms. Using the same references is fine as they are immutable.
189191
var motherTonguePracticeHistory = GeneratePracticeHistory(results[i].stateNumber, results[i].date, book.PracticeMode != PracticeMode.AskForForeignLang);
190192
var foreignLanguagePracticeHistory = GeneratePracticeHistory(results[i].stateNumber, results[i].date, book.PracticeMode != PracticeMode.AskForMotherTongue);
193+
191194
foreach (Synonym motherTongue in word.MotherTongue)
192195
{
193196
motherTongue.Practices.AddRange(motherTonguePracticeHistory);

src/Vocup/ViewModels/SynonymViewModel.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,36 +31,36 @@ public SynonymViewModel(WordViewModel parent, Synonym synonym)
3131
private static double GetPracticeState(IReadOnlyCollection<Practice> practices)
3232
{
3333
// Zipf's law weighted average for the last 5 practices
34-
int lastN = 5;
34+
int maxPracticesToConsider = 5;
3535

36-
double values = 0.0, weights = 0.0;
37-
int counter = 1;
36+
double weightedSum = 0.0, sumOfWeights = 0.0;
37+
int practicePosition = 1;
3838

39-
foreach (Practice practice in practices.Reverse().Take(lastN))
39+
foreach (Practice practice in practices.Reverse().Take(maxPracticesToConsider))
4040
{
41-
double weight = 1.0 / counter;
41+
double weight = 1.0 / practicePosition;
4242
double result = practice.Result switch
4343
{
4444
PracticeResult2.Correct => 1.0,
4545
PracticeResult2.PartlyCorrect => 0.5,
4646
PracticeResult2.Wrong => 0.0,
4747
_ => throw new ArgumentOutOfRangeException(null, practice.Result, "Invalid practice result")
4848
};
49-
values += result * weight;
50-
weights += weight;
51-
counter++;
49+
weightedSum += result * weight;
50+
sumOfWeights += weight;
51+
practicePosition++;
5252
}
5353

54-
if (counter == 1)
54+
if (practicePosition == 1)
5555
return -1.0; // No practices
5656

57-
for (; counter <= lastN; counter++)
57+
for (; practicePosition <= maxPracticesToConsider; practicePosition++)
5858
{
5959
// Assume 0.0 for missing practices
60-
weights += 1.0 / counter;
60+
sumOfWeights += 1.0 / practicePosition;
6161
}
6262

63-
return values / weights;
63+
return weightedSum / sumOfWeights;
6464
}
6565

6666
public void Dispose()

0 commit comments

Comments
 (0)