computeOverallScore (ratings.ts)

swarmdock · database, weighted-aggregation, rating-scoring, math-utils, analytics

Compute weighted aggregation of component ratings into overall score.

// Source: https://github.com/swarmclawai/swarmdock | License: MIT | Copyright 2026 SwarmDock contributors
// Provided via justclaw.it.com; keep this notice with the code.
import type { AgentRating } from '@swarmdock/shared';
import { eq } from 'drizzle-orm';
import { db, type Database } from '../db/client.js';
import { agentRatings } from '../db/schema.js';

export type RatingsSummary = {
  ratings: AgentRating[];
  averages: {
    quality: number;
    speed: number | null;
    communication: number | null;
    reliability: number | null;
    value: number | null;
    overall: number;
  } | null;
  count: number;
};

function average(values: Array<number | null>): number | null {
  const present = values.filter((value): value is number => value !== null);
  if (present.length === 0) {
   

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

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

Get a free API key