Skip to content
Permalink
8e8dec7049
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
116 lines (96 sloc) 3.55 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 accountScore: Int = 0
var utilizationScore: Int = 0
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
}
/*for index in 0..<accounts.count{
FetchData.fetchTransactionsFor(accountAlias: accounts[index].accountAlias) { transactions, error in
guard error == nil else {
NSLog("Error retrieving transactions for account.")
return
}
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() {
// 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
accounts.forEach {
totalCredit += $0.creditLimit
totalBalance += $0.curBalance
}
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
case 3...4:
accountScore = 75
case 5...10:
accountScore = 100
default:
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 {
if let alias = selectedAccount?.accountAlias {
FetchData.fetchTransactionsFor(accountAlias: alias) { transactions, error in
guard error == nil else {
NSLog("Error retrieving transactions for account.")
return
}
self.transactionDict.updateValue(transactions, forKey: "transactions")
self.pushController(withName: "Transactions", context: self.transactionDict)
}
}
}
}*/
@IBAction func moreButtonTapped() {
presentController(withNames: ["UtilizationScore", "AccountScore", "PaymentScore"], contexts: [utilizationScore, accountScore, paymentScore])
}
}