Skip to content

Commit

Permalink
Fix "Files previewed per day" number
Browse files Browse the repository at this point in the history
If no previews had been generated yet, the app displayed an incorrect number caused by division by zero.
  • Loading branch information
samuelmeuli committed Apr 19, 2020
1 parent 213c00c commit d4a0cb5
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Glance/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class ViewController: NSViewController {
let extensionCounts = stats.getExtensionCounts()

let nrPreviews = stats.getTotalCount()
let averagePreviewsPerDay = lround(Double(nrPreviews) / Double(stats.getDateCounts().count))
let averagePreviewsPerDay = nrPreviews == 0
? 0
: lround(Double(nrPreviews) / Double(stats.getDateCounts().count))
let mostPopularExtension = extensionCounts.max { a, b in a.value < b.value }

totalStatsValueLabel.stringValue = String(nrPreviews)
Expand Down

0 comments on commit d4a0cb5

Please sign in to comment.