Skip to content

Commit

Permalink
Added Utilization score calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Duarte committed Mar 28, 2019
1 parent c212e13 commit 83e5766
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ class AccountNumberInterfaceController: WKInterfaceController {
@IBOutlet weak var image4: WKInterfaceImage!
override func awake(withContext context: Any?) {
super.awake(withContext: context)

//get plist data to generate Account number metric
var plistValues = PlistUtil.readPlist(for: .account)
let accountNum = plistValues.count
print(accountNum)
}

override func didAppear() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import Foundation

class UtilizationInterfaceController: WKInterfaceController {
var didAnimate: Bool = false
var util: Int?
var util: Double = 0
var score: Int = 0

@IBOutlet weak var image3: WKInterfaceImage!

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

Expand All @@ -23,13 +23,27 @@ class UtilizationInterfaceController: WKInterfaceController {
let balance = plistValues[0][0]
let credit = plistValues[0][1] > 0 ? plistValues[0][1] : 1

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

override func didAppear() {
if !didAnimate {
image3.setImageNamed("scores")
image3.startAnimatingWithImages(in: NSRange(location: 1, length: util ?? 0), duration: 1.5, repeatCount: 1)
image3.startAnimatingWithImages(in: NSRange(location: 1, length: score ), duration: 1.5, repeatCount: 1)
didAnimate = true
}
}
Expand Down

0 comments on commit 83e5766

Please sign in to comment.