Added check for diff ignores

This commit is contained in:
Eduard Urbach 2018-03-09 13:42:45 +01:00
parent c95355383e
commit 8a57178664
9 changed files with 88 additions and 46 deletions

View File

@ -62,38 +62,52 @@ func CompareMAL(ctx *aero.Context) string {
// Canonical title
if anime.Title.Canonical != malAnime.Title {
hash := utils.HashString(malAnime.Title)
if !arn.IsAnimeDifferenceIgnored(anime.ID, "mal", malAnime.ID, "CanonicalTitle", hash) {
differences = append(differences, &animediff.CanonicalTitle{
TitleA: anime.Title.Canonical,
TitleB: malAnime.Title,
})
}
}
// Japanese title
if anime.Title.Japanese != malAnime.JapaneseTitle {
hash := utils.HashString(malAnime.JapaneseTitle)
if !arn.IsAnimeDifferenceIgnored(anime.ID, "mal", malAnime.ID, "JapaneseTitle", hash) {
differences = append(differences, &animediff.JapaneseTitle{
TitleA: anime.Title.Japanese,
TitleB: malAnime.JapaneseTitle,
})
}
}
// Synopsis
if len(anime.Summary) < len(malAnime.Synopsis) {
differences = append(differences, &animediff.ShorterSynopsis{
hash := utils.HashString(malAnime.Synopsis)
if !arn.IsAnimeDifferenceIgnored(anime.ID, "mal", malAnime.ID, "Synopsis", hash) {
differences = append(differences, &animediff.Synopsis{
SynopsisA: anime.Summary,
SynopsisB: malAnime.Synopsis,
})
}
}
// Compare genres
hashA := utils.HashStringsNoOrder(anime.Genres)
hashB := utils.HashStringsNoOrder(malAnime.Genres)
if hashA != hashB {
if !arn.IsAnimeDifferenceIgnored(anime.ID, "mal", malAnime.ID, "Genres", hashB) {
differences = append(differences, &animediff.Genres{
GenresA: anime.Genres,
GenresB: malAnime.Genres,
})
}
}
// Add if there were any differences
if len(differences) > 0 {

View File

@ -23,7 +23,7 @@ component CompareMAL(comparisons []*utils.MALComparison, url string, user *arn.U
.data-comparison-differences
each difference in comparison.Differences
.data-comparison-difference
.data-comparison-difference-title= difference.String()
.data-comparison-difference-title= difference.Explanation()
.data-comparison-difference-details
.data-comparison-difference-detail= difference.DetailsA()

View File

@ -2,6 +2,13 @@ package utils
import "github.com/OneOfOne/xxhash"
// HashString returns a hash of the string.
func HashString(item string) uint64 {
h := xxhash.NewS64(0)
h.Write([]byte(item))
return h.Sum64()
}
// HashStringsNoOrder returns a hash of the string slice contents, ignoring order.
func HashStringsNoOrder(items []string) uint64 {
sum := uint64(0)

View File

@ -6,8 +6,13 @@ type CanonicalTitle struct {
TitleB string
}
// String returns the description.
func (diff *CanonicalTitle) String() string {
// Type returns the diff type.
func (diff *CanonicalTitle) Type() string {
return "CanonicalTitle"
}
// Explanation returns the description.
func (diff *CanonicalTitle) Explanation() string {
return "Canonical titles are different"
}

View File

@ -8,8 +8,13 @@ type Genres struct {
GenresB []string
}
// String returns the description.
func (diff *Genres) String() string {
// Type returns the diff type.
func (diff *Genres) Type() string {
return "Genres"
}
// Explanation returns the description.
func (diff *Genres) Explanation() string {
return "Genres are different"
}

View File

@ -2,7 +2,8 @@ package animediff
// Difference describes a difference between two anime.
type Difference interface {
String() string
Type() string
Explanation() string
DetailsA() string
DetailsB() string
}

View File

@ -6,8 +6,13 @@ type JapaneseTitle struct {
TitleB string
}
// String returns the description.
func (diff *JapaneseTitle) String() string {
// Type returns the diff type.
func (diff *JapaneseTitle) Type() string {
return "JapaneseTitle"
}
// Explanation returns the description.
func (diff *JapaneseTitle) Explanation() string {
return "Japanese titles are different"
}

View File

@ -1,22 +0,0 @@
package animediff
// ShorterSynopsis describes differing Japanese titles.
type ShorterSynopsis struct {
SynopsisA string
SynopsisB string
}
// String returns the description.
func (diff *ShorterSynopsis) String() string {
return "Synopsis is shorter"
}
// DetailsA shows the details for the first anime.
func (diff *ShorterSynopsis) DetailsA() string {
return diff.SynopsisA
}
// DetailsB shows the details for the second anime.
func (diff *ShorterSynopsis) DetailsB() string {
return diff.SynopsisB
}

View File

@ -0,0 +1,27 @@
package animediff
// Synopsis describes differing synopsis.
type Synopsis struct {
SynopsisA string
SynopsisB string
}
// Type returns the diff type.
func (diff *Synopsis) Type() string {
return "Synopsis"
}
// Explanation returns the description.
func (diff *Synopsis) Explanation() string {
return "Synopsis is shorter"
}
// DetailsA shows the details for the first anime.
func (diff *Synopsis) DetailsA() string {
return diff.SynopsisA
}
// DetailsB shows the details for the second anime.
func (diff *Synopsis) DetailsB() string {
return diff.SynopsisB
}