Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Initial tag system

Cette révision appartient à :
akuma06 2017-07-22 01:14:16 +02:00
Parent f14bdeec6b
révision 742dfa84fd
4 fichiers modifiés avec 32 ajouts et 4 suppressions

11
models/tag.go Fichier normal
Voir le fichier

@ -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"`
}

Voir le fichier

@ -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"`

Voir le fichier

@ -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
}

Voir le fichier

@ -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)
}