Skip to content
Permalink
d170909c3e
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
65 lines (53 sloc) 2.09 KB
//
// WellnessInterfaceController.swift
// SynchronyFinancial WatchKit Extension
//
// Created by Alan Maynard on 1/14/19.
// Copyright © 2019 Alan Maynard. All rights reserved.
//
import WatchKit
import Foundation
class WellnessInterfaceController: WKInterfaceController {
var accounts: [Account] = []
var wellnessScore: Int = 0
var utilizationScore: Int = 0
var previousUtil: 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
}
calculateUtilization()
calculateWellness()
image.setImageNamed("scores")
image.startAnimatingWithImages(in: NSRange(location: 1, length: wellnessScore), duration: 1.5, repeatCount: 1)
}
private func calculateUtilization() {
var totalBalance: Double = 0
var totalCredit: Double = 0
var previous: Double = 0
accounts.forEach {
totalCredit += $0.creditLimit
totalBalance += $0.curBalance
previous += Double(arc4random_uniform(UInt32($0.creditLimit)))
}
utilizationScore = Int((totalBalance / totalCredit) * 100)
previousUtil = Int((previous / totalCredit) * 100)
}
private func calculateWellness() {
let m1 = Double(utilizationScore) * 0.50
wellnessScore = Int(round(m1))
}
@IBAction func moreButtonTapped() {
if accounts.count > 1 {
let pages = ["UtilizationScore", "UtilizationTrend", "AvgUtilization", "HealthyAccts"]
let contexts: [Any] = [utilizationScore, [utilizationScore, previousUtil], 35.5, 7]
presentController(withNames: pages, contexts: contexts)
} else {
let pages = ["UtilizationScore", "UtilizationTrend", "LastPayment"]
let contexts: [Any] = [utilizationScore, [utilizationScore, previousUtil], [10.00, 125.00]]
presentController(withNames: pages, contexts: contexts)
}
}
}