-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathMetrics.swift
71 lines (57 loc) · 1.7 KB
/
Metrics.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
// Metrics.swift
// Lockdown
//
// Created by Oleg Dreyman on 28.09.2020.
// Copyright © 2020 Confirmed Inc. All rights reserved.
//
import Foundation
func getDayMetrics() -> Int {
return defaults.integer(forKey: kDayMetrics)
}
func getDayMetricsString(commas: Bool = false) -> String {
return metricsToString(metric: getDayMetrics(), commas: commas)
}
func getWeekMetrics() -> Int {
return defaults.integer(forKey: kWeekMetrics)
}
func getWeekMetricsString() -> String {
return metricsToString(metric: getWeekMetrics())
}
func getTotalMetrics() -> Int {
return defaults.integer(forKey: kTotalMetrics)
}
func getTotalMetricsString() -> String {
return metricsToString(metric: getTotalMetrics())
}
func getTotalEnabledMetrics() -> Int {
return defaults.integer(forKey: kTotalEnabledMetrics)
}
func getTotalEnabledString() -> String {
return metricsToString(metric: getTotalEnabledMetrics())
}
func getTotalDisabledMetrics() -> Int {
return defaults.integer(forKey: kTotalDisabledMetrics)
}
func getTotalDisabledString() -> String {
return metricsToString(metric: getTotalDisabledMetrics())
}
func metricsToString(metric : Int, commas: Bool = false) -> String {
if (commas) {
let commasFormatter = NumberFormatter()
commasFormatter.numberStyle = .decimal
guard let formattedNumber = commasFormatter.string(from: NSNumber(value: metric)) else { return "\(metric)" }
return formattedNumber
}
if metric < 1000 {
return "\(metric)"
}
else if metric < 1000000 {
return "\(Int(metric / 1000))k"
}
else {
return "\(String(format: "%.2f", (Double(metric) / Double(1000000))))m"
}
}
enum Metrics {
}