Skip to content

Commit

Permalink
Fix error in argumentPriorityHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
sofvanh committed Jan 8, 2025
1 parent d800536 commit 8f4a4c0
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions backend/src/analysis/argumentPriorityHandler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Score } from "../.shared/types";
import { analyzeVotes } from "./voteAnalyzer";
import { getArgumentScores } from "./argumentScoreHandler";
import { ReactionForGraph, getReactionsForGraph} from "../db/operations/reactionOperations";
import { ReactionForGraph, getReactionsForGraph } from "../db/operations/reactionOperations";
import { getArgumentIdsByGraphId } from "../db/operations/argumentOperations";

interface ArgumentPriority {
Expand Down Expand Up @@ -30,6 +30,7 @@ async function getUniquenessScores(userId: string, graphId: string): Promise<Map
}
}

// TODO Update this now that consensus or fragmentation can be undefined
export async function getArgumentPriorities(graphId: string, userId: string): Promise<ArgumentPriority[]> {
const argumentIds = await getArgumentIdsByGraphId(graphId);
const argumentPriorityMap = new Map<string, number>();
Expand All @@ -39,14 +40,14 @@ export async function getArgumentPriorities(graphId: string, userId: string): Pr
const userReactedMap = new Map<string, boolean>(
reactions.filter(reaction => reaction.userId === userId).map(reaction => [reaction.argumentId, true])
);

// Get priority for arguments with scores (consensus, fragmentation, clarity)
const argumentScores: Map<string, Score> = await getArgumentScores(graphId);
const uniquenessScores: Map<string, number> = await getUniquenessScores(userId, graphId);

for (const [argumentId, score] of argumentScores) {
const uniquenessScore = uniquenessScores.get(argumentId) ?? 1;
const priority = (1 + 50 * score.consensus + 50 * score.fragmentation) * (score.clarity ** 2) * (uniquenessScore ** 2);
const priority = (1 + 50 * (score.consensus ?? 0) + 50 * (score.fragmentation ?? 0)) * (score.clarity ** 2) * (uniquenessScore ** 2);
argumentPriorityMap.set(argumentId, priority);
}

Expand All @@ -64,5 +65,5 @@ export async function getArgumentPriorities(graphId: string, userId: string): Pr

// Sort arguments by priority and return
return Array.from(argumentPriorityMap, ([argumentId, priority]) => ({ argumentId, priority }))
.sort((a, b) => b.priority - a.priority);
.sort((a, b) => b.priority - a.priority);
}

0 comments on commit 8f4a4c0

Please sign in to comment.