make WoT source configurable, remove logging, prevent negative ranks

This commit is contained in:
keyan 2022-01-18 11:13:55 -06:00
parent cdfe973a65
commit 129ec89b68
2 changed files with 3 additions and 7 deletions

View File

@ -688,7 +688,7 @@ const LEFT_JOIN_SATS =
/* NOTE: because many items will have the same rank, we need to tie break with a unique field so pagination works */ /* NOTE: because many items will have the same rank, we need to tie break with a unique field so pagination works */
function timedOrderBySats (num) { function timedOrderBySats (num) {
return `ORDER BY ((x.sats-1)/POWER(EXTRACT(EPOCH FROM ($${num} - "Item".created_at))/3600+2, 1.5) + return `ORDER BY (GREATEST(x.sats-1, 0)/POWER(EXTRACT(EPOCH FROM ($${num} - "Item".created_at))/3600+2, 1.5) +
(x.boost)/POWER(EXTRACT(EPOCH FROM ($${num} - "Item".created_at))/3600+2, 5)) DESC NULLS LAST, "Item".id DESC` (x.boost)/POWER(EXTRACT(EPOCH FROM ($${num} - "Item".created_at))/3600+2, 5)) DESC NULLS LAST, "Item".id DESC`
} }

View File

@ -2,7 +2,8 @@ function trust ({ boss, models }) {
return async function () { return async function () {
console.log('doing trust') console.log('doing trust')
const graph = await getGraph(models) const graph = await getGraph(models)
const trust = await trustGivenGraph(graph, 624) const user = await models.user.findUnique({ where: { name: process.env.WOT_SOURCE || 'k00b' } })
const trust = await trustGivenGraph(graph, user.id)
await storeTrust(models, trust) await storeTrust(models, trust)
console.log('done doing trust') console.log('done doing trust')
} }
@ -50,7 +51,6 @@ function boundedTrust (probs) {
function trustGivenPaths (paths) { function trustGivenPaths (paths) {
const trust = {} const trust = {}
for (const [node, npaths] of Object.entries(paths)) { for (const [node, npaths] of Object.entries(paths)) {
console.log(Object.values(npaths))
trust[node] = boundedTrust(Object.values(npaths)) trust[node] = boundedTrust(Object.values(npaths))
} }
return trust return trust
@ -73,7 +73,6 @@ function trustGivenGraph (graph, start) {
// while we have nodes to visit // while we have nodes to visit
while (queue.length > 0) { while (queue.length > 0) {
const node = queue.shift() const node = queue.shift()
console.log('visiting', node)
if (depth[node] === MAX_DEPTH) break if (depth[node] === MAX_DEPTH) break
if (!graph[node]) { if (!graph[node]) {
@ -84,7 +83,6 @@ function trustGivenGraph (graph, start) {
// for all of this nodes outbound edges // for all of this nodes outbound edges
for (let i = 0; i < graph[node].length; i++) { for (let i = 0; i < graph[node].length; i++) {
const { node: sibling, trust } = graph[node][i] const { node: sibling, trust } = graph[node][i]
console.log('sibling', sibling)
let explore = false let explore = false
// for all existing paths to this node // for all existing paths to this node
@ -130,7 +128,6 @@ function trustGivenGraph (graph, start) {
if (!explore) continue if (!explore) continue
depth[sibling] = depth[node] + 1 depth[sibling] = depth[node] + 1
queue.push(sibling) queue.push(sibling)
console.log('queuing', sibling)
} }
} }
@ -158,7 +155,6 @@ async function getGraph (models) {
) a ) a
group by id group by id
) b` ) b`
console.log(graph)
return graph return graph
} }