Skip to content

Commit 1e2c0ad

Browse files
committed
fix progress reporting in lenex import
1 parent 6b720f8 commit 1e2c0ad

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

importer/lenex_importer.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,6 @@ func ImportLenexFile(file string, meeting string, exclude []int, include []int,
189189
}
190190
stats.Created.Results++
191191
stats.Imported.Results++
192-
// progress unit: result processed
193-
atomic.AddInt64(&processedItems64, 1)
194192
}
195193
}
196194

@@ -250,7 +248,6 @@ func ImportLenexFile(file string, meeting string, exclude []int, include []int,
250248
}
251249
stats.Created.Results++
252250
stats.Imported.Results++
253-
atomic.AddInt64(&processedItems64, 1)
254251
}
255252
}
256253

@@ -284,7 +281,6 @@ func ImportLenexFile(file string, meeting string, exclude []int, include []int,
284281
}
285282
stats.Created.Results++
286283
stats.Imported.Results++
287-
atomic.AddInt64(&processedItems64, 1)
288284
}
289285
}
290286

@@ -317,6 +313,9 @@ func ImportLenexFile(file string, meeting string, exclude []int, include []int,
317313
fmt.Printf("[ %c ] > id: %s, type: %s, reason: %s\n", cs, disqualification.Identifier, disqualification.Type, disqualification.Reason)
318314
}
319315
}
316+
317+
// progress unit: result processed (count once per result)
318+
atomic.AddInt64(&processedItems64, 1)
320319
}
321320

322321
return nil
@@ -349,8 +348,9 @@ func ImportLenexFile(file string, meeting string, exclude []int, include []int,
349348

350349
totalItems := totalEvents + totalAgeGroups + totalHeats + totalTeams + totalAthletes + totalEntries + totalResults
351350
processedItems := 0
352-
// initialize atomic counter with already processed units
353-
processedItems64 = int64(processedItems)
351+
// atomic counter tracks athlete-related work units only (entries + results)
352+
processedItems64 = 0
353+
athleteWorkTotal := totalEntries + totalResults
354354

355355
progress(20, fmt.Sprintf("Starting import with %d total items to process", totalItems))
356356

@@ -583,8 +583,17 @@ func ImportLenexFile(file string, meeting string, exclude []int, include []int,
583583
return
584584
}
585585
// progress after athlete finished
586-
progressPct := 20 + (float64(atomic.LoadInt64(&processedItems64))/float64(totalItems))*80
587-
progress(progressPct, fmt.Sprintf("Processing athletes: %d / %d", atomic.LoadInt64(&processedItems64), totalItems))
586+
units := atomic.LoadInt64(&processedItems64)
587+
var progressPct float64
588+
if athleteWorkTotal > 0 {
589+
progressPct = 20 + (float64(units)/float64(athleteWorkTotal))*75
590+
} else {
591+
progressPct = 20
592+
}
593+
if progressPct > 95 {
594+
progressPct = 95
595+
}
596+
progress(progressPct, fmt.Sprintf("Processing athletes: %d / %d", units, athleteWorkTotal))
588597
}(athlete)
589598
}
590599
// wait for team athletes to finish before moving to next team

0 commit comments

Comments
 (0)