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