Skip to content

Commit 9734714

Browse files
[UserStatistics] Add recent semantic domain column (#4022)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: Danny Rorabaugh <[email protected]>
1 parent 42495b8 commit 9734714

File tree

7 files changed

+81
-3
lines changed

7 files changed

+81
-3
lines changed

Backend.Tests/Services/StatisticsServiceTests.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,5 +189,43 @@ public void GetSemanticDomainUserCountsTestDomMatchesUser()
189189
var result = _statsService.GetSemanticDomainUserCounts(ProjId).Result;
190190
Assert.That(result.Find(uc => uc.Id == user.Id)!.WordCount, Is.EqualTo(wordCount));
191191
}
192+
193+
[Test]
194+
public void GetSemanticDomainUserCountsTestRecentDomain()
195+
{
196+
var user = _userRepo.Create(GetUserWithProjId()).Result!;
197+
198+
var olderDomain = new SemanticDomain
199+
{
200+
Id = "1.1.1",
201+
Name = "Older Domain",
202+
Created = "2023-01-01T10:00:00Z",
203+
UserId = user.Id
204+
};
205+
var newerDomain = new SemanticDomain
206+
{
207+
Id = "2.2.2",
208+
Name = "Newer Domain",
209+
Created = "2023-12-31T10:00:00Z",
210+
UserId = user.Id
211+
};
212+
var anonDomain = new SemanticDomain
213+
{
214+
Id = "3.3.3",
215+
Name = "Unknown Domain"
216+
};
217+
218+
var word1 = GetWordWithDomain();
219+
word1.Senses[0].SemanticDomains = [anonDomain, newerDomain];
220+
_wordRepo.AddFrontier(word1);
221+
222+
var word2 = GetWordWithDomain();
223+
word2.Senses[0].SemanticDomains = [olderDomain];
224+
_wordRepo.AddFrontier(word2);
225+
226+
var result = _statsService.GetSemanticDomainUserCounts(ProjId).Result;
227+
var userCount = result.Find(uc => uc.Id == user.Id);
228+
Assert.That(userCount?.RecentDomain, Is.EqualTo(newerDomain).UsingPropertiesComparer());
229+
}
192230
}
193231
}

Backend/Models/Statistics.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class SemanticDomainUserCount
2222
public HashSet<string> DomainSet { get; set; }
2323
public int DomainCount { get; set; }
2424
public int WordCount { get; set; }
25+
public SemanticDomain? RecentDomain { get; set; }
2526

2627
public SemanticDomainUserCount()
2728
{

Backend/Services/StatisticsService.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,18 @@ public async Task<List<SemanticDomainUserCount>> GetSemanticDomainUserCounts(str
349349
}
350350
// update WordCount
351351
domainUserValue.WordCount++;
352+
353+
// update RecentDomain if this domain has a more recent timestamp
354+
if (!string.IsNullOrEmpty(sd.Created))
355+
{
356+
if (domainUserValue.RecentDomain is null ||
357+
sd.Created.ParseModernPastDateTimePermissivelyWithException().CompareTo(
358+
domainUserValue.RecentDomain.Created
359+
.ParseModernPastDateTimePermissivelyWithException()) > 0)
360+
{
361+
domainUserValue.RecentDomain = sd.Clone();
362+
}
363+
}
352364
}
353365
}
354366
}

public/locales/en/translation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@
587587
"domainName": "Domain Name:",
588588
"username": "Username:",
589589
"domainCount": "Domains:",
590+
"recentDomain": "Most Recent Domain:",
590591
"senseCount": "Words:"
591592
},
592593
"axisLabel": {

src/api/models/semantic-domain-user-count.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
* Do not edit the class manually.
1313
*/
1414

15+
import { SemanticDomain } from "./semantic-domain";
16+
1517
/**
1618
*
1719
* @export
@@ -48,4 +50,10 @@ export interface SemanticDomainUserCount {
4850
* @memberof SemanticDomainUserCount
4951
*/
5052
wordCount?: number;
53+
/**
54+
*
55+
* @type {SemanticDomain}
56+
* @memberof SemanticDomainUserCount
57+
*/
58+
recentDomain?: SemanticDomain;
5159
}

src/components/Statistics/TableCells.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { TableCell, Typography } from "@mui/material";
2-
import { ReactElement } from "react";
2+
import { ReactElement, ReactNode } from "react";
33
import { useTranslation } from "react-i18next";
44

55
export function HeadCell(props: { titleId: string }): ReactElement {
@@ -12,10 +12,16 @@ export function HeadCell(props: { titleId: string }): ReactElement {
1212
);
1313
}
1414

15-
export function Cell(props: { text?: string | number | null }): ReactElement {
15+
interface CellProps {
16+
body?: ReactNode;
17+
text?: string | number | null;
18+
}
19+
20+
export function Cell(props: CellProps): ReactElement {
21+
const { body, text } = props;
1622
return (
1723
<TableCell sx={{ borderBottomStyle: "dotted", borderBottomWidth: 1 }}>
18-
<Typography variant="body1">{props.text}</Typography>
24+
{body ? body : <Typography variant="body1">{text}</Typography>}
1925
</TableCell>
2026
);
2127
}

src/components/Statistics/UserStatistics.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { SemanticDomainUserCount } from "api/models";
1212
import { getSemanticDomainUserCount } from "backend";
1313
import * as LocalStorage from "backend/localStorage";
1414
import { Cell, HeadCell } from "components/Statistics/TableCells";
15+
import DomainChip from "components/WordCard/DomainChip";
1516

1617
export default function UserStatistics(): ReactElement {
1718
const [domainUserCountList, setDomainUserCountList] = useState<
@@ -40,6 +41,7 @@ export default function UserStatistics(): ReactElement {
4041
<TableHead>
4142
<TableRow>
4243
<HeadCell titleId={"statistics.column.username"} />
44+
<HeadCell titleId={"statistics.column.recentDomain"} />
4345
<HeadCell titleId={"statistics.column.domainCount"} />
4446
<HeadCell titleId={"statistics.column.senseCount"} />
4547
</TableRow>
@@ -48,6 +50,16 @@ export default function UserStatistics(): ReactElement {
4850
{domainUserCountList.map((t) => (
4951
<TableRow key={t.id}>
5052
<Cell text={t.username} />
53+
<Cell
54+
body={
55+
t.recentDomain ? (
56+
<DomainChip
57+
domain={{ ...t.recentDomain, userId: undefined }}
58+
provenance
59+
/>
60+
) : null
61+
}
62+
/>
5163
<Cell text={t.domainCount} />
5264
<Cell text={t.wordCount} />
5365
</TableRow>

0 commit comments

Comments
 (0)