Skip to content
Permalink
ddbc228b52
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
77 lines (63 sloc) 2.5 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 transactions: [Transaction] = []
var transactionDict: [String: [Transaction]] = [:]
var wellnessScore: Int?
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 ?? 0), duration: 1.5, repeatCount: 1)
}
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}
override func didDeactivate() {
// 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
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)
}
}
}