Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions Backend.Tests/Services/StatisticsServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,5 +189,43 @@ public void GetSemanticDomainUserCountsTestDomMatchesUser()
var result = _statsService.GetSemanticDomainUserCounts(ProjId).Result;
Assert.That(result.Find(uc => uc.Id == user.Id)!.WordCount, Is.EqualTo(wordCount));
}

[Test]
public void GetSemanticDomainUserCountsTestRecentDomain()
{
var user = _userRepo.Create(GetUserWithProjId()).Result!;

var olderDomain = new SemanticDomain
{
Id = "1.1.1",
Name = "Older Domain",
Created = "2023-01-01T10:00:00Z",
UserId = user.Id
};
var newerDomain = new SemanticDomain
{
Id = "2.2.2",
Name = "Newer Domain",
Created = "2023-12-31T10:00:00Z",
UserId = user.Id
};
var anonDomain = new SemanticDomain
{
Id = "3.3.3",
Name = "Unknown Domain"
};

var word1 = GetWordWithDomain();
word1.Senses[0].SemanticDomains = [anonDomain, newerDomain];
_wordRepo.AddFrontier(word1);

var word2 = GetWordWithDomain();
word2.Senses[0].SemanticDomains = [olderDomain];
_wordRepo.AddFrontier(word2);

var result = _statsService.GetSemanticDomainUserCounts(ProjId).Result;
var userCount = result.Find(uc => uc.Id == user.Id);
Assert.That(userCount?.RecentDomain, Is.EqualTo(newerDomain).UsingPropertiesComparer());
}
}
}
1 change: 1 addition & 0 deletions Backend/Models/Statistics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class SemanticDomainUserCount
public HashSet<string> DomainSet { get; set; }
public int DomainCount { get; set; }
public int WordCount { get; set; }
public SemanticDomain? RecentDomain { get; set; }

public SemanticDomainUserCount()
{
Expand Down
12 changes: 12 additions & 0 deletions Backend/Services/StatisticsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,18 @@ public async Task<List<SemanticDomainUserCount>> GetSemanticDomainUserCounts(str
}
// update WordCount
domainUserValue.WordCount++;

// update RecentDomain if this domain has a more recent timestamp
if (!string.IsNullOrEmpty(sd.Created))
{
if (domainUserValue.RecentDomain is null ||
sd.Created.ParseModernPastDateTimePermissivelyWithException().CompareTo(
domainUserValue.RecentDomain.Created
.ParseModernPastDateTimePermissivelyWithException()) > 0)
{
domainUserValue.RecentDomain = sd.Clone();
}
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@
"domainName": "Domain Name:",
"username": "Username:",
"domainCount": "Domains:",
"recentDomain": "Most Recent Domain:",
"senseCount": "Words:"
},
"axisLabel": {
Expand Down
8 changes: 8 additions & 0 deletions src/api/models/semantic-domain-user-count.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
* Do not edit the class manually.
*/

import { SemanticDomain } from "./semantic-domain";

/**
*
* @export
Expand Down Expand Up @@ -48,4 +50,10 @@ export interface SemanticDomainUserCount {
* @memberof SemanticDomainUserCount
*/
wordCount?: number;
/**
*
* @type {SemanticDomain}
* @memberof SemanticDomainUserCount
*/
recentDomain?: SemanticDomain;
}
12 changes: 9 additions & 3 deletions src/components/Statistics/TableCells.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TableCell, Typography } from "@mui/material";
import { ReactElement } from "react";
import { ReactElement, ReactNode } from "react";
import { useTranslation } from "react-i18next";

export function HeadCell(props: { titleId: string }): ReactElement {
Expand All @@ -12,10 +12,16 @@ export function HeadCell(props: { titleId: string }): ReactElement {
);
}

export function Cell(props: { text?: string | number | null }): ReactElement {
interface CellProps {
body?: ReactNode;
text?: string | number | null;
}

export function Cell(props: CellProps): ReactElement {
const { body, text } = props;
return (
<TableCell sx={{ borderBottomStyle: "dotted", borderBottomWidth: 1 }}>
<Typography variant="body1">{props.text}</Typography>
{body ? body : <Typography variant="body1">{text}</Typography>}
</TableCell>
);
}
12 changes: 12 additions & 0 deletions src/components/Statistics/UserStatistics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { SemanticDomainUserCount } from "api/models";
import { getSemanticDomainUserCount } from "backend";
import * as LocalStorage from "backend/localStorage";
import { Cell, HeadCell } from "components/Statistics/TableCells";
import DomainChip from "components/WordCard/DomainChip";

export default function UserStatistics(): ReactElement {
const [domainUserCountList, setDomainUserCountList] = useState<
Expand Down Expand Up @@ -40,6 +41,7 @@ export default function UserStatistics(): ReactElement {
<TableHead>
<TableRow>
<HeadCell titleId={"statistics.column.username"} />
<HeadCell titleId={"statistics.column.recentDomain"} />
<HeadCell titleId={"statistics.column.domainCount"} />
<HeadCell titleId={"statistics.column.senseCount"} />
</TableRow>
Expand All @@ -48,6 +50,16 @@ export default function UserStatistics(): ReactElement {
{domainUserCountList.map((t) => (
<TableRow key={t.id}>
<Cell text={t.username} />
<Cell
body={
t.recentDomain ? (
<DomainChip
domain={{ ...t.recentDomain, userId: undefined }}
provenance
/>
) : null
}
/>
<Cell text={t.domainCount} />
<Cell text={t.wordCount} />
</TableRow>
Expand Down
Loading