Tried adding concurrency
This commit is contained in:
parent
575da17a19
commit
282201c2fd
16
main.go
16
main.go
@ -121,8 +121,9 @@ func lessType (Type string) (string) {
|
|||||||
return Type
|
return Type
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkResults(r Result, anime Anime, highest int) (high, hI int) {
|
func checkResults(r Result, anime Anime, highest int, c chan int) {
|
||||||
//var re = regexp.MustCompile(`\s\(\d*\)`)
|
//var re = regexp.MustCompile(`\s\(\d*\)`)
|
||||||
|
var hI int
|
||||||
for i := 0;i<len(r.Anime); i++ {
|
for i := 0;i<len(r.Anime); i++ {
|
||||||
var total int
|
var total int
|
||||||
meikan := r.Anime[i]
|
meikan := r.Anime[i]
|
||||||
@ -178,7 +179,9 @@ func checkResults(r Result, anime Anime, highest int) (high, hI int) {
|
|||||||
hI = i
|
hI = i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return highest, hI
|
//return highest, hI
|
||||||
|
c <- highest
|
||||||
|
c <- hI
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -190,6 +193,7 @@ func main() {
|
|||||||
animes := parseCsv("/home/trac/coding/compareID/1.-Main-data.csv")
|
animes := parseCsv("/home/trac/coding/compareID/1.-Main-data.csv")
|
||||||
count := len(animes)
|
count := len(animes)
|
||||||
bar := pb.StartNew(count)
|
bar := pb.StartNew(count)
|
||||||
|
var matched, notMatched int
|
||||||
for i := 1; i < len(animes); i++ {
|
for i := 1; i < len(animes); i++ {
|
||||||
anime := animes[i]
|
anime := animes[i]
|
||||||
anime.Title = strings.Replace(strings.Replace(anime.Title, `\`, `\\`, -1), `"`, `\"`, -1)
|
anime.Title = strings.Replace(strings.Replace(anime.Title, `\`, `\\`, -1), `"`, `\"`, -1)
|
||||||
@ -222,7 +226,10 @@ func main() {
|
|||||||
case "Web":
|
case "Web":
|
||||||
anime.Type = "ONA"
|
anime.Type = "ONA"
|
||||||
}
|
}
|
||||||
highest, hI := checkResults(result, anime, 0)
|
c := make(chan int)
|
||||||
|
go checkResults(result, anime, 0, c)
|
||||||
|
highest, hI := <-c, <-c
|
||||||
|
//highest, hI := checkResults(result, anime, 0)
|
||||||
if highest < 100 {
|
if highest < 100 {
|
||||||
fmt.Printf("Found no match for %s\n", anime.Title)
|
fmt.Printf("Found no match for %s\n", anime.Title)
|
||||||
_, err := f.WriteString(strconv.Itoa(anime.ID) + " null\n")
|
_, err := f.WriteString(strconv.Itoa(anime.ID) + " null\n")
|
||||||
@ -234,6 +241,7 @@ func main() {
|
|||||||
} else {
|
} else {
|
||||||
fmt.Println("No search results returned")
|
fmt.Println("No search results returned")
|
||||||
}*/
|
}*/
|
||||||
|
notMatched++
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
_, err := f.WriteString(strconv.Itoa(anime.ID) + " " + strconv.Itoa(result.Anime[hI].ID) + "\n")
|
_, err := f.WriteString(strconv.Itoa(anime.ID) + " " + strconv.Itoa(result.Anime[hI].ID) + "\n")
|
||||||
@ -246,6 +254,7 @@ func main() {
|
|||||||
AnidbID: anime.ID,
|
AnidbID: anime.ID,
|
||||||
MeikanID: result.Anime[hI].ID,
|
MeikanID: result.Anime[hI].ID,
|
||||||
}
|
}
|
||||||
|
matched++
|
||||||
resultCompare = append(resultCompare, a)
|
resultCompare = append(resultCompare, a)
|
||||||
}
|
}
|
||||||
bar.Increment()
|
bar.Increment()
|
||||||
@ -255,5 +264,6 @@ func main() {
|
|||||||
check(err)
|
check(err)
|
||||||
jsonfile := []byte(resJson)
|
jsonfile := []byte(resJson)
|
||||||
err = ioutil.WriteFile("./result.json", jsonfile, 0644)
|
err = ioutil.WriteFile("./result.json", jsonfile, 0644)
|
||||||
|
fmt.Printf("Matched: %d\nNot Matched: %d\nTotal: %d", matched, notMatched, matched + notMatched)
|
||||||
check(err)
|
check(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user