diff --git a/models/tag.go b/models/tag.go new file mode 100644 index 00000000..0cf84658 --- /dev/null +++ b/models/tag.go @@ -0,0 +1,11 @@ +package models + +// Tag model for a torrent vote system +type Tag struct { + TorrentID uint `gorm:"column:torrent_id"` + UserID uint `gorm:"column:user_id"` + Tag string `gorm:"column:tag"` + Type string `gorm:"column:type"` + Weight float64 `gorm:"column:weight"` + Accepted bool `gorm:"column:accepted"` +} diff --git a/models/torrent.go b/models/torrent.go index 4b6dc8dc..3ef6fbed 100644 --- a/models/torrent.go +++ b/models/torrent.go @@ -53,7 +53,7 @@ type Torrent struct { Filesize int64 `gorm:"column:filesize"` Description string `gorm:"column:description"` WebsiteLink string `gorm:"column:website_link"` - AnidbID string `gorm:"column:anidb_id"` + DbID string `gorm:"column:db_id"` Trackers string `gorm:"column:trackers"` // Indicates the language of the torrent's content (eg. subs, dubs, raws, manga TLs) Language string `gorm:"column:language"` @@ -63,6 +63,7 @@ type Torrent struct { OldUploader string `gorm:"-"` // ??????? OldComments []OldComment `gorm:"ForeignKey:torrent_id"` Comments []Comment `gorm:"ForeignKey:torrent_id"` + Tags []Tag `gorm:"-"` Scrape *Scrape `gorm:"AssociationForeignKey:ID;ForeignKey:torrent_id"` FileList []File `gorm:"ForeignKey:torrent_id"` Languages []string `gorm:"-"` // This is parsed when retrieved from db @@ -84,7 +85,7 @@ type TorrentJSON struct { Comments []CommentJSON `json:"comments"` SubCategory string `json:"sub_category"` Category string `json:"category"` - AnidbID string `json:"anidb_id"` + DbID string `json:"db_id"` UploaderID uint `json:"uploader_id"` UploaderName template.HTML `json:"uploader_name"` OldUploader template.HTML `json:"uploader_old"` diff --git a/models/user.go b/models/user.go index 4bf3e249..0a3da3f1 100644 --- a/models/user.go +++ b/models/user.go @@ -12,6 +12,8 @@ import ( "errors" + "math" + "github.com/NyaaPantsu/nyaa/config" "github.com/NyaaPantsu/nyaa/utils/crypto" ) @@ -45,6 +47,7 @@ type User struct { Mascot string `gorm:"column:mascot"` MascotURL string `gorm:"column:mascot_url"` UserSettings string `gorm:"column:settings"` + Pantsu float64 `gorm:"column:pantsu"` // TODO: move this to PublicUser Followers []User // Don't work `gorm:"foreignkey:user_id;associationforeignkey:follower_id;many2many:user_follows"` @@ -390,3 +393,16 @@ func (u *User) Filter() *User { u.Torrents = torrents return u } + +// IncreasePantsu is a function that uses the formula to increase the Pantsu points of a user +func (u *User) IncreasePantsu() { + if u.Pantsu <= 0 { + u.Pantsu = 1 // Pantsu points should never be less or equal to 0. This would trigger a division by 0 + } + u.Pantsu = u.Pantsu * (1 + 1/(math.Pow(math.Log(u.Pantsu+1), 5))) // First votes substancially increases the vote, further it increase slowly +} + +// DecreasePantsu is a function that uses the formula to decrease the Pantsu points of a user +func (u *User) DecreasePantsu() { + u.Pantsu = 0.8 * u.Pantsu // You lose 20% of your pantsu points each wrong vote +} diff --git a/templates/template_test.go b/templates/template_test.go index a020968f..af9f52e6 100644 --- a/templates/template_test.go +++ b/templates/template_test.go @@ -43,7 +43,7 @@ func TestTemplates(t *testing.T) { type ContextTest map[string]func(jet.VarMap) jet.VarMap func walkDirTest(dir string, t *testing.T) { - fakeUser := &models.User{1, "test", "test", "test", 1, time.Now(), time.Now(), "test", time.Now(), "en", "test", "test", "test", "test", []models.User{}, []models.User{}, "test", []models.Torrent{}, []models.Notification{}, 1, models.UserSettings{}} + fakeUser := &models.User{1, "test", "test", "test", 1, time.Now(), time.Now(), "test", time.Now(), "en", "test", "test", "test", "test", 0, []models.User{}, []models.User{}, "test", []models.Torrent{}, []models.Notification{}, 1, models.UserSettings{}} fakeComment := &models.Comment{1, 1, 1, "test", time.Now(), time.Now(), nil, &models.Torrent{}, fakeUser} fakeScrapeData := &models.Scrape{1, 0, 0, 10, time.Now()} fakeFile := &models.File{1, 1, "l12:somefile.mp4e", 3} diff --git a/utils/publicSettings/publicSettings_test.go b/utils/publicSettings/publicSettings_test.go index d1eed9d4..c070e4b1 100644 --- a/utils/publicSettings/publicSettings_test.go +++ b/utils/publicSettings/publicSettings_test.go @@ -6,7 +6,6 @@ import ( "github.com/nicksnyder/go-i18n/i18n" "golang.org/x/text/language" - "golang.org/x/text/language/display" "fmt" @@ -46,7 +45,7 @@ func TestLanguages(t *testing.T) { if displayLang.String() == "und" { t.Errorf("Couldn't find the language display for the language %s", displayLang.String()) } - n := display.Tags(displayLang) + //n := display.Tags(displayLang) tags := i18n.LanguageTags() for _, languageTag := range tags { @@ -55,8 +54,11 @@ func TestLanguages(t *testing.T) { if lang.String() == "und" { t.Errorf("Couldn't find the language root for the language %s", languageTag) } - fmt.Printf("Name of the language natively: %s\n", strings.Title(display.Self.Name(lang))) - fmt.Printf("Name of the language in %s: %s\n", displayLang.String(), n.Name(lang)) + for _, t := range strings.Split(languageTag, ", ") { + fmt.Printf("UPDATE torrents SET language='%s' WHERE language='%s';\n", lang, t) + } + //fmt.Printf("Name of the language natively: %s\n", strings.Title(display.Self.Name(lang))) + //fmt.Printf("Name of the language in %s: %s\n", displayLang.String(), n.Name(lang)) } }