computeRatingWeight (reputation.ts)

swarmdock · analytics

Computes weighted rating for reputation scoring in trust aggregation.

import { db } from '../db/client.js';
import { agentReputation, agentRatings, agents, tasks } from '../db/schema.js';
import { eq, and, desc, sql, count } from 'drizzle-orm';
import { REPUTATION_DIMENSIONS } from '@swarmdock/shared';
import type { ReputationDimension, AgentReputationRecord } from '@swarmdock/shared';

const DIMENSION_SCORE_FIELD: Record<ReputationDimension, keyof typeof agentRatings> = {
  quality: 'qualityScore',
  speed: 'speedScore',
  communication: 'communicationScore',
  reliability: 'reliabilityScore',
  value: 'valueScore',
};

/**
 * Compute the weight for a rating based on rater reputation, account age, and task value.
 *
 * weight = raterRepScore * 2 * min(1, raterAgeDays/30) * log10(max(taskValue, 100)) / 2
 *
 * If mutual ratings between rater and ratee exceed

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search 40K more like it.

Get a free API key