Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
SWF-17 fix logical error leading to bad utilization score
  • Loading branch information
ahm11003 committed Apr 17, 2019
1 parent 3e7ddcd commit 8e8dec7
Showing 1 changed file with 12 additions and 28 deletions.
Expand Up @@ -20,10 +20,10 @@ class WellnessInterfaceController: WKInterfaceController {
var paymentScore: Int = 0

@IBOutlet weak var image: WKInterfaceImage!

override func awake(withContext context: Any?) {
super.awake(withContext: context)

if let context = context as? [String: [Account]], let accts = context["accts"] {
accounts = accts
}
Expand All @@ -36,14 +36,13 @@ class WellnessInterfaceController: WKInterfaceController {
self.transactionDict.updateValue(self.transactions, forKey: "transactions")
}
}*/

calculateUtilization()
countAccounts()
calculateWellness()

image.setImageNamed("scores")
image.startAnimatingWithImages(in: NSRange(location: 1, length: wellnessScore ?? 0), duration: 1.5, repeatCount: 1)

}

override func willActivate() {
Expand All @@ -55,41 +54,26 @@ class WellnessInterfaceController: WKInterfaceController {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}

private func calculateUtilization() {
var totalBalance: Double = 0
var totalCredit: Double = 0

accounts.forEach {
totalCredit += $0.availCredit
totalCredit += $0.creditLimit
totalBalance += $0.curBalance
}

let util = round(((totalBalance)/(totalCredit)) * 100)

switch util {
case 0...10:
utilizationScore = 100
case 11...20:
utilizationScore = Int(round((100 - util) * 0.9))
case 21...30:
utilizationScore = Int(round((100 - util) * 0.85))
case 31...60:
utilizationScore = Int(round((100 - util) * 0.725))
case 61...90:
utilizationScore = Int(round((100 - util) * 0.6))
default:
utilizationScore = 1
}

utilizationScore = Int((totalBalance / totalCredit) * 100)
}

private func countAccounts() {
var count: Int = 0

for _ in 0..<accounts.count {
count += 1
}

switch count {
case 2...3:
accountScore = 50
Expand All @@ -101,14 +85,14 @@ class WellnessInterfaceController: WKInterfaceController {
accountScore = 25
}
}

private func calculateWellness() {
let m1 = Double(utilizationScore) * 0.50
let m2 = Double(accountScore) * 0.20
let m3 = Double(paymentScore) * 0.30
wellnessScore = Int(round(m1 + m2 + m3))
}

/*private func calculatePaymentsMissed() {
var lateCount: Int = 0
for index in 0..<accounts.count {
Expand Down

0 comments on commit 8e8dec7

Please sign in to comment.