Final code before I make it concurrent

This commit is contained in:
David Alasow 2018-01-19 15:45:43 +01:00
parent 282201c2fd
commit 31c9b86ac6
1 changed files with 17 additions and 11 deletions

28
main.go
View File

@ -14,6 +14,7 @@ import (
"strconv"
"strings"
"time"
"github.com/agext/levenshtein"
)
//Anime is AniDB structure
@ -43,7 +44,8 @@ type AnimeRes struct {
}
type CompareAni struct {
Title string
AnidbTitle string
MeikanTitle string
AnidbID int
MeikanID int
}
@ -147,7 +149,9 @@ func checkResults(r Result, anime Anime, highest int, c chan int) {
total += 12
}
}
if meikan.Title == anime.Title {
score := levenshtein.Match(meikan.Title, anime.Title, nil)
//fmt.Print(score)
if score > 0.95 {
total += 50
}
if meikan.Episodes == anime.Episodes {
@ -192,7 +196,7 @@ func main() {
check (err)
animes := parseCsv("/home/trac/coding/compareID/1.-Main-data.csv")
count := len(animes)
bar := pb.StartNew(count)
bar := pb.StartNew(count - 1)
var matched, notMatched int
for i := 1; i < len(animes); i++ {
anime := animes[i]
@ -231,16 +235,17 @@ func main() {
highest, hI := <-c, <-c
//highest, hI := checkResults(result, anime, 0)
if highest < 100 {
fmt.Printf("Found no match for %s\n", anime.Title)
_, err := f.WriteString(strconv.Itoa(anime.ID) + " null\n")
check(err)
/*if len(result.Anime) > 0 {
fmt.Println(highest)
fmt.Printf("Title: %s, Episodes: %d, Type: %s, ID: %d, StartDate: %s, EndDate: %s\n", anime.Title, anime.Episodes, anime.Type, anime.ID, anime.StartDate, anime.EndDate)
fmt.Printf("Title: %s, Episodes: %d, Type: %s, ID: %d, StartDate: %s, EndDate: %s\n", result.Anime[hI].Title, result.Anime[hI].Episodes, result.Anime[hI].Type, result.Anime[hI].ID, result.Anime[hI].StartDate, result.Anime[hI].EndDate)
if len(result.Anime) > 0 {
fmt.Printf("Found no match for %s (Best result: %s)\n", anime.Title, result.Anime[hI].Title)
//fmt.Println(highest)
//fmt.Printf("Title: %s, Episodes: %d, Type: %s, ID: %d, StartDate: %s, EndDate: %s\n", anime.Title, anime.Episodes, anime.Type, anime.ID, anime.StartDate, anime.EndDate)
//fmt.Printf("Title: %s, Episodes: %d, Type: %s, ID: %d, StartDate: %s, EndDate: %s\n", result.Anime[hI].Title, result.Anime[hI].Episodes, result.Anime[hI].Type, result.Anime[hI].ID, result.Anime[hI].StartDate, result.Anime[hI].EndDate)
} else {
fmt.Printf("Found no match for %s\n", anime.Title)
fmt.Println("No search results returned")
}*/
}
notMatched++
} else {
@ -250,7 +255,8 @@ func main() {
fmt.Printf("Matched %s -> %s\n", anime.Title, result.Anime[hI].Title)*/
//fmt.Printf("Title: %s, Episodes: %d, Type: %s, ID: %d, StartDate: %s, EndDate: %s\n", result.Anime[hI].Title, result.Anime[hI].Episodes, result.Anime[hI].Type, result.Anime[hI].ID, result.Anime[hI].StartDate, result.Anime[hI].EndDate)
a := CompareAni{
Title: anime.Title,
AnidbTitle: anime.Title,
MeikanTitle: result.Anime[hI].Title,
AnidbID: anime.ID,
MeikanID: result.Anime[hI].ID,
}
@ -260,7 +266,7 @@ func main() {
bar.Increment()
//fmt.Printf("ID: %d, Type: %s, Episodes: %d, Title: %s\n", a.Id, a.Type, a.Episodes, a.Title)
}
resJson, err := json.Marshal(resultCompare)
resJson, err := json.MarshalIndent(resultCompare, "", "\t")
check(err)
jsonfile := []byte(resJson)
err = ioutil.WriteFile("./result.json", jsonfile, 0644)