Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated calculation algorithm #12

Merged
merged 6 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 63 additions & 23 deletions server/lib/calc-confidence-value.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,70 @@
// constants
const TWEET_WEIGHT = 0.001
const FOLLOWER_WEIGHT = 0.01
const VERIFIED_WEIGHT = 8
const LISTED_WEIGHT = 0.05
const LIKE_WEIGHT = 0.01
const VERIFIED_WEIGHT = 1;

const CUTOFF_PARAMS = {
'followers_count': 100,
'tweet_count': 10,
// 'listed_count': 0,
// 'like_count': 100,
}

const POINTS_PARAMS = {
'followers_count': {
scale: 2.5,
inflectionValue: 1000,
eccentricity: 1,
},
'listed_count': {
scale: 0.5,
inflectionValue: 2,
eccentricity: 1,
},
'tweet_count': {
scale: 0.5,
inflectionValue: 1000,
eccentricity: 1,
},
'like_count': {
scale: 0.5,
inflectionValue: 100,
eccentricity: 1,
},
}

export function calculate(user) {
// calculateConfidenceValue.js
const { followers_count, tweet_count, listed_count, like_count } = user.public_metrics;
const verified = user.verified;
const public_metrics = user.public_metrics;
// const { followers_count, tweet_count, listed_count, like_count } = user.public_metrics;

let confidenceValue = (tweet_count * TWEET_WEIGHT) +
// (like_count * LIKE_WEIGHT) +
// (listed_count * LISTED_WEIGHT) +
(verified ? VERIFIED_WEIGHT : 0);
if (!verified) {
if (followers_count < 150) {
confidenceValue = 0
}
if (listed_count < 20) {
confidenceValue = 0
}
if (like_count < 500) {
confidenceValue = 0
let confidenceValue = 0;

const verified = user.verified;
if (verified) {
// For verified users:
// Add points
confidenceValue += VERIFIED_WEIGHT;
} else {
// For unverified users:
// If any of the cutoff params are below the threshold, return confidenceValue of zero
for (const [key, cutoff] of Object.entries(CUTOFF_PARAMS)) {
const metricValue = public_metrics[key] ?? 0;
if (metricValue < cutoff) {
return confidenceValue;
}
}
}

return confidenceValue;
// Add points based on the user's public metrics
for (const [key, params] of Object.entries(POINTS_PARAMS)) {
const { scale, offset, inflectionValue, eccentricity } = params;
const metricValue = public_metrics[key] ?? 0;

// Use log scaling for the metric value (and inflection value)
const logValue = Math.log10(metricValue);
const logInflectionValue = Math.log10(inflectionValue);

// Logistic curve, e.g. https://www.wolframalpha.com/input?i=plot+y+%3D+2.5+%2F+%281+%2B+exp%28-1+*+%28log10%28x%29-log10%281000%29%29%29%29%2C+0+%3C+x+%3C+2000
const points = scale / (1 + Math.exp(-eccentricity * (logValue - logInflectionValue)));
confidenceValue += points;
}

return Math.round(confidenceValue * 100) / 100;
}
2 changes: 1 addition & 1 deletion server/lib/dispatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fs from 'fs'
const key = JSON.parse(fs.readFileSync(process.env.WALLET, 'utf-8'))

export async function dispatch({ address, username, value }) {
const url = process.env.IRYS_NODE || 'https://node2.irys.xyz'
const url = process.env.IRYS_NODE || 'https://turbo.ardrive.io'
const token = 'arweave'
const irys = new Irys({ url, token, key })
const receipt = await irys.upload('VOUCH', {
Expand Down
53 changes: 40 additions & 13 deletions server/test/confidence-value.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ test('calculate the correct confidence value for a verified user', () => {
public_metrics: {
followers_count: 1045,
tweet_count: 4534,
listed_count: 23
listed_count: 23,
},
verified: true
};
//const expectedValue = Math.floor((4534 * 0.001) + (1045 * 0.02) + (23 * 0.05) + 8.00);
const expectedValue = 12.533999999999999
const expectedValue = 2.96;
const confidenceValue = calculate(userMetrics);
assert.strictEqual(confidenceValue, expectedValue);
});
Expand All @@ -26,8 +25,7 @@ test('calculate the correct confidence value for a non-verified user', () => {
},
verified: false
};
//const expectedValue = Math.floor((4534 * 0.001) + (1045 * 0.02) + (23 * 0.05));
const expectedValue = 4.534;
const expectedValue = 1.96;
const confidenceValue = calculate(userMetrics);
assert.strictEqual(confidenceValue, expectedValue);
});
Expand All @@ -40,13 +38,12 @@ test('calculate the correct confidence value when verified property is missing',
listed_count: 23
}
};
//const expectedValue = Math.floor((4534 * 0.001) + (1045 * 0.02) + (23 * 0.05));
const expectedValue = 4.534;
const expectedValue = 1.96;
const confidenceValue = calculate(userMetrics);
assert.strictEqual(confidenceValue, expectedValue);
});

test('calculate the correct confidence value when some metrics are zero', () => {
test('calculate the correct confidence value when all metrics are zero, but verified', () => {
const userMetrics = {
public_metrics: {
followers_count: 0,
Expand All @@ -55,21 +52,51 @@ test('calculate the correct confidence value when some metrics are zero', () =>
},
verified: true
};
const expectedValue = 8.00;
const expectedValue = 1;
const confidenceValue = calculate(userMetrics);
assert.strictEqual(confidenceValue, expectedValue);
});

test('calculate the correct confidence value when all metrics are zero and user is not verified', () => {
test('calculate the correct confidence value when all metrics are below minimum and user is not verified', () => {
const userMetrics = {
public_metrics: {
followers_count: 0,
tweet_count: 0,
listed_count: 0
followers_count: 99,
tweet_count: 999,
listed_count: 999,
},
verified: false
};
const expectedValue = 0;
const confidenceValue = calculate(userMetrics);
assert.strictEqual(confidenceValue, expectedValue);
});

test('calculate the correct confidence value when all metrics are minimum and user is not verified', () => {
const userMetrics = {
public_metrics: {
followers_count: 200,
tweet_count: 10,
listed_count: 0
},
verified: false
};
const expectedValue = 0.89;
const confidenceValue = calculate(userMetrics);
assert.strictEqual(confidenceValue, expectedValue);
});

test('calculate the correct confidence value when all metrics are very high and verified', () => {
const userMetrics = {
public_metrics: {
followers_count: 99999,
tweet_count: 99999,
listed_count: 999999,
like_count: 99999
},
verified: true
};
const expectedValue = 4.62;
const confidenceValue = calculate(userMetrics);
assert.strictEqual(confidenceValue, expectedValue);
});

Loading