Skip to content
Permalink
9303329f97
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
137 lines (114 sloc) 4.24 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)
self.pushController(withName: "UtilizationScore", context: utilizationScore)
}
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
for index in 0..<accounts.count {
totalBalance += accounts[index].curBalance
totalCredit += accounts[index].creditLimit
}
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
}
}
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)
}
}
}
}*/
override func contextForSegue(withIdentifier segueIdentifier: String) -> Any? {
if segueIdentifier == "UtilizationScore" {
return utilizationScore
}
return nil
}
}