Skip to content

Commit

Permalink
Internal change
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 680f34d06abf808d2dc25ff9b1ed5e223da8962f
  • Loading branch information
Jigsaw authored and copybara-github committed Jan 21, 2025
1 parent 8eb482e commit d722ce8
Show file tree
Hide file tree
Showing 12 changed files with 224 additions and 216 deletions.
44 changes: 22 additions & 22 deletions src/sensemaker_utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,38 +87,38 @@ comment2`
});
describe("groupCommentsByTopic", () => {
it("should group comments by topic and subtopic", () => {
const categorizedComments: Comment[] = [
{
id: "1",
text: "Comment 1",
topics: [
{ name: "Topic 1", subtopics: [{ name: "Subtopic 1.1" }] },
{ name: "Topic 2", subtopics: [{ name: "Subtopic 2.1" }] },
],
},
{
id: "2",
text: "Comment 2",
topics: [
{ name: "Topic 1", subtopics: [{ name: "Subtopic 1.1" }] },
{ name: "Topic 1", subtopics: [{ name: "Subtopic 1.2" }] },
],
},
];
const comment1: Comment = {
id: "1",
text: "Comment 1",
topics: [
{ name: "Topic 1", subtopics: [{ name: "Subtopic 1.1" }] },
{ name: "Topic 2", subtopics: [{ name: "Subtopic 2.1" }] },
],
};
const comment2: Comment = {
id: "2",
text: "Comment 2",
topics: [
{ name: "Topic 1", subtopics: [{ name: "Subtopic 1.1" }] },
{ name: "Topic 1", subtopics: [{ name: "Subtopic 1.2" }] },
],
};

const categorizedComments: Comment[] = [comment1, comment2];

const expectedOutput = {
"Topic 1": {
"Subtopic 1.1": {
"1": "Comment 1",
"2": "Comment 2",
"1": comment1,
"2": comment2,
},
"Subtopic 1.2": {
"2": "Comment 2",
"2": comment2,
},
},
"Topic 2": {
"Subtopic 2.1": {
"1": "Comment 1",
"1": comment1,
},
},
};
Expand Down
6 changes: 3 additions & 3 deletions src/sensemaker_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ export function hydrateCommentRecord(
*/
export function groupCommentsBySubtopic(categorized: Comment[]): {
[topicName: string]: {
[subtopicName: string]: { [commentId: string]: string };
[subtopicName: string]: { [commentId: string]: Comment };
};
} {
const groupedComments: {
[topicName: string]: {
[subtopicName: string]: { [commentId: string]: string };
[subtopicName: string]: { [commentId: string]: Comment };
};
} = {};
for (const comment of categorized) {
Expand All @@ -152,7 +152,7 @@ export function groupCommentsBySubtopic(categorized: Comment[]): {
if (!groupedComments[topic.name][subtopic.name]) {
groupedComments[topic.name][subtopic.name] = {}; // init new subtopic name
}
groupedComments[topic.name][subtopic.name][comment.id] = comment.text;
groupedComments[topic.name][subtopic.name][comment.id] = comment;
}
}
}
Expand Down
68 changes: 21 additions & 47 deletions src/stats_util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@

import {
SummaryStats,
GroupedSummaryStats,
getAgreeProbability,
getGroupInformedConsensus,
getGroupAgreeDifference,
getGroupAgreeProbDifference,
getMinAgreeProb,
} from "./stats_util";
import { Comment } from "./types";
Expand All @@ -27,10 +28,10 @@ const TEST_COMMENTS = [
text: "comment1",
voteTalliesByGroup: {
"0": {
agreeCount: 10,
disagreeCount: 5,
agreeCount: 20,
disagreeCount: 10,
passCount: 0,
totalCount: 15,
totalCount: 30,
},
"1": {
agreeCount: 5,
Expand Down Expand Up @@ -127,7 +128,7 @@ describe("stats utility functions", () => {

it("should get the group agree difference for a given comment and group", () => {
expect(
getGroupAgreeDifference(
getGroupAgreeProbDifference(
{
id: "1",
text: "comment1",
Expand Down Expand Up @@ -155,7 +156,7 @@ describe("stats utility functions", () => {
describe("StatsUtilTest", () => {
it("should get the total number of votes from multiple comments", () => {
const summaryStats = new SummaryStats(TEST_COMMENTS);
expect(summaryStats.voteCount).toEqual(55);
expect(summaryStats.voteCount).toEqual(70);
});

it("SummaryStats should get the total number of comments", () => {
Expand All @@ -182,17 +183,11 @@ describe("StatsUtilTest", () => {
},
];

const expectedTopicStats = [
{
name: "Topic A",
commentCount: 3,
subtopicStats: [
{ name: "Subtopic A.1", commentCount: 2 },
{ name: "Subtopic A.2", commentCount: 1 },
],
},
];
expect(new SummaryStats(comments).getStatsByTopic()).toEqual(expectedTopicStats);
const statsByTopic = new SummaryStats(comments).getStatsByTopic();
expect(statsByTopic[0].commentCount).toEqual(3);
expect(statsByTopic[0]?.subtopicStats?.map((subtopic) => subtopic.commentCount)).toEqual([
2, 1,
]);
});

it("should sort topics by comment count and put 'Other' topics and subtopics last", () => {
Expand Down Expand Up @@ -259,38 +254,15 @@ describe("StatsUtilTest", () => {
},
];

const expectedSortedTopics = [
{
name: "Topic B",
commentCount: 6,
subtopicStats: [
{ name: "Subtopic B.1", commentCount: 4 },
{ name: "Subtopic B.2", commentCount: 2 },
],
},
{
name: "Topic A",
commentCount: 3,
subtopicStats: [
{ name: "Subtopic A.1", commentCount: 2 },
{ name: "Subtopic A.2", commentCount: 1 },
],
},
{
name: "Other",
commentCount: 5,
subtopicStats: [
{ name: "Subtopic Other.1", commentCount: 2 },
{ name: "Other", commentCount: 3 },
],
},
];
expect(new SummaryStats(comments).getStatsByTopic()).toEqual(expectedSortedTopics);
const statsByTopic = new SummaryStats(comments).getStatsByTopic();
expect(statsByTopic.map((topic) => topic.name)).toEqual(["Topic B", "Topic A", "Other"]);
});

it("should get the representative comments for a given group", () => {
const representativeComments = new SummaryStats(TEST_COMMENTS).getRepresentativeComments("0");
expect(representativeComments.length).toEqual(2);
const representativeComments = new GroupedSummaryStats(
TEST_COMMENTS
).getGroupRepresentativeComments("0");
expect(representativeComments.length).toEqual(1);
expect(representativeComments[0].id).toEqual("1");
});

Expand All @@ -299,6 +271,8 @@ describe("StatsUtilTest", () => {
{ id: "1", text: "comment1" },
{ id: "2", text: "comment2" },
];
expect(new SummaryStats(commentsWithoutVotes).getRepresentativeComments("0")).toEqual([]);
expect(
new GroupedSummaryStats(commentsWithoutVotes).getGroupRepresentativeComments("0")
).toEqual([]);
});
});
Loading

0 comments on commit d722ce8

Please sign in to comment.