Initial tag system
Cette révision appartient à :
Parent
9b69de4965
révision
938bd27e3b
5 fichiers modifiés avec 37 ajouts et 7 suppressions
11
models/tag.go
Fichier normal
11
models/tag.go
Fichier normal
|
@ -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"`
|
||||
}
|
|
@ -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"`
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Référencer dans un nouveau ticket