improve WoT: daily decay and higher interaction divisor

This commit is contained in:
keyan 2022-03-31 11:31:37 -05:00
parent 46a2ac37eb
commit 9b3fa8d844
2 changed files with 10 additions and 6 deletions

1
.gitignore vendored
View File

@ -18,6 +18,7 @@
# misc # misc
.DS_Store .DS_Store
*.pem *.pem
db.sql
# debug # debug
npm-debug.log* npm-debug.log*

View File

@ -148,7 +148,8 @@ async function getGraph (models) {
from ( from (
select id, json_agg(json_build_object('node', oid, 'trust', trust)) as hops select id, json_agg(json_build_object('node', oid, 'trust', trust)) as hops
from ( from (
select "ItemAct"."userId" as id, "Item"."userId" as oid, least(${MAX_TRUST}, count(*)/10.0) as trust select "ItemAct"."userId" as id, "Item"."userId" as oid, least(${MAX_TRUST},
sum(POWER(.99, EXTRACT(DAY FROM (NOW_UTC() - "ItemAct".created_at))))/42.0) as trust
from "ItemAct" from "ItemAct"
join "Item" on "itemId" = "Item".id and "ItemAct"."userId" <> "Item"."userId" join "Item" on "itemId" = "Item".id and "ItemAct"."userId" <> "Item"."userId"
where "ItemAct".act = 'VOTE' group by "ItemAct"."userId", "Item"."userId" where "ItemAct".act = 'VOTE' group by "ItemAct"."userId", "Item"."userId"
@ -167,11 +168,13 @@ async function storeTrust (models, nodeTrust) {
} }
// update the trust of each user in graph // update the trust of each user in graph
await models.$executeRaw( await models.$transaction([
`UPDATE users models.$executeRaw`UPDATE users SET trust = 0`,
SET trust = g.trust models.$executeRaw(
FROM (values ${values}) g(id, trust) `UPDATE users
WHERE users.id = g.id`) SET trust = g.trust
FROM (values ${values}) g(id, trust)
WHERE users.id = g.id`)])
} }
module.exports = { trust } module.exports = { trust }