Skip to content

Commit

Permalink
Fix broken statistics by adding timestamp on new entries (#2659)
Browse files Browse the repository at this point in the history
Also make words-per-day-per-user more robust
  • Loading branch information
imnasnainaec authored Oct 2, 2023
1 parent 6cd11cc commit bb8d5b6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
33 changes: 18 additions & 15 deletions Backend/Services/StatisticsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,27 +89,30 @@ public async Task<List<WordsPerDayPerUserCount>> GetWordsPerDayPerUserCounts(str
// The created timestamp may not exist for some model
if (!string.IsNullOrEmpty(sd.Created))
{
DateTime tempDate = ParseDateTimePermissivelyWithException(sd.Created);
var userName = userNameIdDictionary.GetValueOrDefault(sd.UserId, "");
// WordsPerDayPerUserCount exist for particular day
if (shortTimeDictionary.ContainsKey(tempDate.ToISO8601TimeFormatDateOnlyString()) &&
!string.IsNullOrEmpty(userName))
{
var chartNode = shortTimeDictionary[tempDate.ToISO8601TimeFormatDateOnlyString()];
chartNode.UserNameCountDictionary[userName] = chartNode
.UserNameCountDictionary.GetValueOrDefault(userName, 0) + 1;
}
// WordsPerDayPerUserCount NOT exist, create one and update to the Dictionary
else
var dateKey = ParseDateTimePermissivelyWithException(sd.Created)
.ToISO8601TimeFormatDateOnlyString();
if (!shortTimeDictionary.ContainsKey(dateKey))
{
var tempBarChartNode = new WordsPerDayPerUserCount(sd.Created);
foreach (User u in projectUsers)
{
tempBarChartNode.UserNameCountDictionary.Add(u.Username, 0);
}
tempBarChartNode.UserNameCountDictionary[userName] = 1;
shortTimeDictionary.Add(
tempBarChartNode.DateTime.ToISO8601TimeFormatDateOnlyString(), tempBarChartNode);
shortTimeDictionary.Add(dateKey, tempBarChartNode);
}

var chartNode = shortTimeDictionary[dateKey];
var username = userNameIdDictionary.GetValueOrDefault(sd.UserId, "?");
// A semantic domain shouldn't usually have `.Created` without a valid `.UserId`;
// this case is a safe-guard to allow a project owner to see statistics even if there's an
// error in the user reckoning (e.g., if a user is removed from the project mid-workshop).
if (!chartNode.UserNameCountDictionary.ContainsKey(username))
{
chartNode.UserNameCountDictionary.Add(username, 1);
}
else
{
chartNode.UserNameCountDictionary[username] += 1;
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/components/DataEntry/DataEntryTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,9 @@ export default function DataEntryTable(
const addNewEntry = async (): Promise<void> => {
const word = newWord(state.newVern);
const lang = analysisLang.bcp47;
word.senses.push(newSense(state.newGloss, lang, props.semanticDomain));
word.senses.push(
newSense(state.newGloss, lang, makeSemDomCurrent(props.semanticDomain))
);
word.note = newNote(state.newNote, lang);
await addNewWord(word, state.newAudioUrls);
};
Expand Down

0 comments on commit bb8d5b6

Please sign in to comment.