UNPKG

near-protocol-rewards

Version:

A transparent, metric-based rewards system for NEAR projects

76 lines (75 loc) 2.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Validator = void 0; const errors_1 = require("../types/errors"); class Validator { validateMetrics(metrics) { const errors = []; const warnings = []; // Basic validation if (!metrics) { errors.push({ code: errors_1.ErrorCode.VALIDATION_ERROR, message: "No metrics provided", }); return { isValid: false, errors, warnings, timestamp: Date.now(), metadata: { source: "github", validationType: "data" }, }; } // Validate commit metrics if (metrics.commits.count < 0) { errors.push({ code: errors_1.ErrorCode.VALIDATION_ERROR, message: "Invalid commit count", }); } // Validate PR metrics if (metrics.pullRequests.merged < 0) { errors.push({ code: errors_1.ErrorCode.VALIDATION_ERROR, message: "Invalid PR count", }); } // Validate review metrics if (metrics.reviews.count < 0) { errors.push({ code: errors_1.ErrorCode.VALIDATION_ERROR, message: "Invalid review count", }); } // Validate issue metrics if (metrics.issues.closed < 0) { errors.push({ code: errors_1.ErrorCode.VALIDATION_ERROR, message: "Invalid issue count", }); } return { isValid: errors.length === 0, errors, warnings, timestamp: Date.now(), metadata: { source: "github", validationType: "data", }, }; } calculateVelocityPenalty(metrics) { const totalActivity = metrics.commits.count + metrics.pullRequests.merged + metrics.reviews.count + metrics.issues.closed; // No penalty if activity is reasonable if (totalActivity <= 100) { return 1; } // Apply penalty for excessive activity return Math.max(0.5, 100 / totalActivity); } } exports.Validator = Validator;