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

View File

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

View File

@ -2,6 +2,13 @@ package utils
import "github.com/OneOfOne/xxhash" 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. // HashStringsNoOrder returns a hash of the string slice contents, ignoring order.
func HashStringsNoOrder(items []string) uint64 { func HashStringsNoOrder(items []string) uint64 {
sum := uint64(0) sum := uint64(0)

View File

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

View File

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

View File

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

View File

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