From 8a571786647999d9e1281d068622af9fcfb3fa22 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Fri, 9 Mar 2018 13:42:45 +0100 Subject: [PATCH] Added check for diff ignores --- pages/editor/mal.go | 46 ++++++++++++++++++++----------- pages/editor/mal.pixy | 2 +- utils/HashStrings.go | 7 +++++ utils/animediff/CanonicalTitle.go | 9 ++++-- utils/animediff/Genres.go | 9 ++++-- utils/animediff/Interface.go | 3 +- utils/animediff/JapaneseTitle.go | 9 ++++-- utils/animediff/LongerSynopsis.go | 22 --------------- utils/animediff/Synopsis.go | 27 ++++++++++++++++++ 9 files changed, 88 insertions(+), 46 deletions(-) delete mode 100644 utils/animediff/LongerSynopsis.go create mode 100644 utils/animediff/Synopsis.go diff --git a/pages/editor/mal.go b/pages/editor/mal.go index 93030233..670f53b2 100644 --- a/pages/editor/mal.go +++ b/pages/editor/mal.go @@ -62,26 +62,38 @@ func CompareMAL(ctx *aero.Context) string { // Canonical title if anime.Title.Canonical != malAnime.Title { - differences = append(differences, &animediff.CanonicalTitle{ - TitleA: anime.Title.Canonical, - TitleB: 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 { - differences = append(differences, &animediff.JapaneseTitle{ - TitleA: anime.Title.Japanese, - TitleB: 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{ - SynopsisA: anime.Summary, - SynopsisB: malAnime.Synopsis, - }) + 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 @@ -89,10 +101,12 @@ func CompareMAL(ctx *aero.Context) string { hashB := utils.HashStringsNoOrder(malAnime.Genres) if hashA != hashB { - differences = append(differences, &animediff.Genres{ - GenresA: anime.Genres, - GenresB: malAnime.Genres, - }) + 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 diff --git a/pages/editor/mal.pixy b/pages/editor/mal.pixy index b15eb169..1bd81725 100644 --- a/pages/editor/mal.pixy +++ b/pages/editor/mal.pixy @@ -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() diff --git a/utils/HashStrings.go b/utils/HashStrings.go index 38a958b3..69a3e806 100644 --- a/utils/HashStrings.go +++ b/utils/HashStrings.go @@ -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) diff --git a/utils/animediff/CanonicalTitle.go b/utils/animediff/CanonicalTitle.go index 0a1bdc04..dcbd9c9a 100644 --- a/utils/animediff/CanonicalTitle.go +++ b/utils/animediff/CanonicalTitle.go @@ -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" } diff --git a/utils/animediff/Genres.go b/utils/animediff/Genres.go index 8c5eef1e..76ef97dc 100644 --- a/utils/animediff/Genres.go +++ b/utils/animediff/Genres.go @@ -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" } diff --git a/utils/animediff/Interface.go b/utils/animediff/Interface.go index 0c884955..87c65d8e 100644 --- a/utils/animediff/Interface.go +++ b/utils/animediff/Interface.go @@ -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 } diff --git a/utils/animediff/JapaneseTitle.go b/utils/animediff/JapaneseTitle.go index 4b439db5..22cb5133 100644 --- a/utils/animediff/JapaneseTitle.go +++ b/utils/animediff/JapaneseTitle.go @@ -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" } diff --git a/utils/animediff/LongerSynopsis.go b/utils/animediff/LongerSynopsis.go deleted file mode 100644 index 49a9cd6c..00000000 --- a/utils/animediff/LongerSynopsis.go +++ /dev/null @@ -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 -} diff --git a/utils/animediff/Synopsis.go b/utils/animediff/Synopsis.go new file mode 100644 index 00000000..a4395bd8 --- /dev/null +++ b/utils/animediff/Synopsis.go @@ -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 +}