From 742dfa84fd4a6ee04f02f5c68de9bad873efdda2 Mon Sep 17 00:00:00 2001 From: akuma06 Date: Sat, 22 Jul 2017 01:14:16 +0200 Subject: [PATCH] Initial tag system --- models/tag.go | 11 +++++++++++ models/torrent.go | 5 +++-- models/user.go | 16 ++++++++++++++++ utils/publicSettings/publicSettings_test.go | 4 ++-- 4 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 models/tag.go 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 47c7726b..854174db 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/utils/publicSettings/publicSettings_test.go b/utils/publicSettings/publicSettings_test.go index af9e622d..a7f77947 100644 --- a/utils/publicSettings/publicSettings_test.go +++ b/utils/publicSettings/publicSettings_test.go @@ -42,7 +42,7 @@ func TestLanguages(t *testing.T) { if err != nil { t.Errorf("failed to initialize language translations: %v", err) } - displayLang := language.Make("pt") + displayLang := language.Make(conf.DefaultLanguage) if displayLang.String() == "und" { t.Errorf("Couldn't find the language display for the language %s", displayLang.String()) } @@ -51,7 +51,7 @@ func TestLanguages(t *testing.T) { tags := i18n.LanguageTags() for _, languageTag := range tags { // The matcher will match Swiss German to German. - lang := language.Make(languageTag) + lang := GetParentTag(languageTag) if lang.String() == "und" { t.Errorf("Couldn't find the language root for the language %s", languageTag) }