fix(progress): Now calculating progress correctly

This commit is contained in:
datalore 2024-10-03 13:20:25 +02:00
parent 44c663c54f
commit 1514bdb3fe

11
main.go
View File

@ -20,8 +20,8 @@ type Config struct {
UseTxtWrite bool UseTxtWrite bool
} }
func calculateProgress(start, end, step, index int64) float32 { func calculateProgress(start, end, index int64) float32 {
steps := (end - start) / step steps := (end - start)
current := index - start current := index - start
if current == 0 { if current == 0 {
return 0 return 0
@ -103,9 +103,10 @@ func generatePrimesCPU(upperLimit int64, primes []int64, numRoutines int, progre
fmt.Printf("Calculating with %d routines\n\n", numRoutines) fmt.Printf("Calculating with %d routines\n\n", numRoutines)
for i := (primes[len(primes) - 1] + 2); i <= upperLimit; i += 2 { continueFrom := primes[len(primes) - 1] + 2
for i := continueFrom; i <= upperLimit; i += 2 {
select { select {
case progress <- calculateProgress(6, upperLimit, 1, i): case progress <- calculateProgress(continueFrom, upperLimit, i):
default: default:
} }
@ -147,7 +148,7 @@ func calculatePrimeParts(number int64, primes []int64) []int64 {
for i := int64(len(primes) - 1); i >= 0; i-- { for i := int64(len(primes) - 1); i >= 0; i-- {
select { select {
case progress <- 1.0 - calculateProgress(0, int64(len(primes) - 1), 1, i): case progress <- 1.0 - calculateProgress(0, int64(len(primes) - 1), i):
default: default:
} }
flooredDiv := number / primes[i] flooredDiv := number / primes[i]