mirror of
https://codeberg.org/pluja/kycnot.me
synced 2025-08-18 19:17:46 -04:00
massive update
This commit is contained in:
parent
6decdcb4fb
commit
c64ea21904
46 changed files with 5663 additions and 834 deletions
|
@ -1,56 +1,52 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"math"
|
||||
"strings"
|
||||
|
||||
"pluja.dev/kycnot.me/database"
|
||||
"pluja.dev/kycnot.me/ent"
|
||||
"pluja.dev/kycnot.me/ent/schema"
|
||||
)
|
||||
|
||||
func ComputeScore(s *ent.Service) int {
|
||||
func ComputeScore(s *database.Service) string {
|
||||
const (
|
||||
goodRating = 1
|
||||
warningRating = 2
|
||||
badRating = 3
|
||||
maxTosPenalty = 2
|
||||
baseScore = 10
|
||||
maxScore = 10
|
||||
baseScore = 100
|
||||
goodRating = 0
|
||||
warningRating = 10
|
||||
badRating = 20
|
||||
maxScore = 100
|
||||
minScore = 0
|
||||
bonusLow = 0.25
|
||||
bonusMedium = 0.75
|
||||
bonusHigh = 1.5
|
||||
bonusLow = 15
|
||||
bonusMedium = 20
|
||||
bonusHigh = 25
|
||||
)
|
||||
|
||||
attributes := strings.Split(s.Attributes, ",")
|
||||
grade := float64(baseScore)
|
||||
|
||||
// Attribute Ratings
|
||||
for _, attr := range attributes {
|
||||
a := database.ServiceAttributes.GetAttribute(attr)
|
||||
switch a.Rating {
|
||||
case goodRating:
|
||||
grade += bonusLow
|
||||
case warningRating:
|
||||
grade -= bonusMedium
|
||||
case badRating:
|
||||
for _, attr := range s.Expand["attributes"] {
|
||||
switch attr.Rating {
|
||||
case "warn":
|
||||
grade -= bonusLow
|
||||
case "bad":
|
||||
grade -= bonusHigh
|
||||
}
|
||||
}
|
||||
|
||||
// Tos Highlights Penalty
|
||||
if s.TosHighlights == nil {
|
||||
s.TosHighlights = &[]schema.TosHighlight{}
|
||||
if s.TosReviews == nil {
|
||||
s.TosReviews = []database.TosReview{}
|
||||
}
|
||||
nTosH := len(*s.TosHighlights)
|
||||
nTosPenalty := float64(nTosH) * bonusMedium // Each 2 TOS highlights, decrease the score by 1
|
||||
if nTosPenalty > maxTosPenalty {
|
||||
nTosPenalty = maxTosPenalty
|
||||
|
||||
trPenalty := 0
|
||||
for _, tr := range s.TosReviews {
|
||||
if tr.Warning {
|
||||
trPenalty -= 2
|
||||
}
|
||||
}
|
||||
grade -= nTosPenalty
|
||||
|
||||
if trPenalty > bonusHigh {
|
||||
trPenalty = bonusHigh
|
||||
}
|
||||
grade += float64(trPenalty)
|
||||
|
||||
// Cash/Monero Bonus
|
||||
if s.Cash || s.Xmr {
|
||||
|
@ -59,36 +55,51 @@ func ComputeScore(s *ent.Service) int {
|
|||
|
||||
// KYC Level Adjustment
|
||||
switch s.KycLevel {
|
||||
case 0:
|
||||
grade += bonusMedium
|
||||
case 1:
|
||||
grade += bonusLow
|
||||
grade -= 5
|
||||
case 2:
|
||||
grade -= bonusMedium
|
||||
grade -= 10
|
||||
case 3:
|
||||
grade -= bonusHigh
|
||||
grade -= 15
|
||||
}
|
||||
|
||||
// TODO: Manage bonuses
|
||||
// P2P/OpenSource Bonus
|
||||
if strings.Contains(s.Attributes, database.AttributeP2P) || strings.Contains(s.Attributes, database.AttributeOpenSource) {
|
||||
/*if strings.Contains(s.Attributes, database.AttributeP2P) || strings.Contains(s.Attributes, database.AttributeOpenSource) {
|
||||
grade += bonusLow
|
||||
}
|
||||
}*/
|
||||
|
||||
// Tor URL Bonus
|
||||
if len(s.OnionUrls) > 0 && s.OnionUrls[0] != "" {
|
||||
grade += bonusLow
|
||||
if len(s.OnionUrls) == 0 || s.OnionUrls[0] == "" {
|
||||
grade -= bonusLow
|
||||
}
|
||||
|
||||
// Normalize the grade to be within 0-10 bounds
|
||||
grade = math.Min(maxScore, math.Max(minScore, grade))
|
||||
|
||||
log.Printf("Grade: %.0f", grade)
|
||||
return int(math.Round(grade))
|
||||
switch {
|
||||
case grade >= 95:
|
||||
return "A"
|
||||
case grade >= 85:
|
||||
return "A"
|
||||
case grade >= 75:
|
||||
return "B"
|
||||
case grade >= 65:
|
||||
return "B"
|
||||
case grade >= 55:
|
||||
return "C"
|
||||
case grade >= 45:
|
||||
return "C"
|
||||
case grade >= 35:
|
||||
return "D"
|
||||
default:
|
||||
return "F"
|
||||
}
|
||||
}
|
||||
|
||||
func UpdateScore(s *ent.Service) error {
|
||||
/*func UpdateScore(s *ent.Service) error {
|
||||
score := ComputeScore(s)
|
||||
ctx := context.Background()
|
||||
_, err := database.Client.Service.UpdateOneID(s.ID).SetScore(score).Save(ctx)
|
||||
return err
|
||||
}
|
||||
}*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue