Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- Functions for utilization and account (temporary) metrics.
- Added identifiers for wellness score controllers
- Added "transaction_code" values to respective API call and transaction class
  • Loading branch information
Jonathan Duarte committed Apr 11, 2019
1 parent a2f3c9d commit 9303329
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 19 deletions.
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder.WatchKit.Storyboard" version="3.0" toolsVersion="14490.70" targetRuntime="watchKit" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="Qge-pO-HLc">
<document type="com.apple.InterfaceBuilder.WatchKit.Storyboard" version="3.0" toolsVersion="14460.31" targetRuntime="watchKit" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="Qge-pO-HLc">
<device id="watch38" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="watchOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBWatchKitPlugin" version="14490.21"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBWatchKitPlugin" version="14460.16"/>
</dependencies>
<scenes>
<!--root-->
Expand Down Expand Up @@ -70,10 +70,10 @@
</objects>
<point key="canvasLocation" x="23" y="602"/>
</scene>
<!--Account Num Interface Controller-->
<!--AccountScore-->
<scene sceneID="jxS-9m-lB7">
<objects>
<controller id="Mki-ad-UCC" customClass="AccountNumInterfaceController" customModule="SynchronyFinancial_WatchKit_Extension">
<controller identifier="AccountScore" id="Mki-ad-UCC" customClass="AccountNumInterfaceController" customModule="SynchronyFinancial_WatchKit_Extension">
<items>
<label width="1" alignment="left" text="Account Score" textAlignment="center" id="0ed-0W-LKq"/>
<imageView width="1" height="120" alignment="center" verticalAlignment="center" image="scores" contentMode="scaleAspectFit" initiallyAnimated="NO" id="RlX-Hj-mTY"/>
Expand Down Expand Up @@ -309,10 +309,10 @@
</objects>
<point key="canvasLocation" x="1420" y="-229"/>
</scene>
<!--Utilization Interface Controller-->
<!--UtilizationScore-->
<scene sceneID="nMW-YM-Pwh">
<objects>
<controller id="RNe-Ul-1jm" customClass="UtilizationInterfaceController" customModule="SynchronyFinancial_WatchKit_Extension">
<controller identifier="UtilizationScore" id="RNe-Ul-1jm" customClass="UtilizationInterfaceController" customModule="SynchronyFinancial_WatchKit_Extension">
<items>
<label width="1" alignment="left" text="Utilization Score" textAlignment="center" id="Rzj-RR-iat"/>
<imageView width="1" height="120" alignment="center" verticalAlignment="center" image="scores" contentMode="scaleAspectFit" initiallyAnimated="NO" id="MkL-48-J8l"/>
Expand All @@ -325,10 +325,10 @@
</objects>
<point key="canvasLocation" x="613" y="602"/>
</scene>
<!--Consistency Interface Controller-->
<!--PaymentScore-->
<scene sceneID="do4-GS-cad">
<objects>
<controller id="k4M-kn-ZzM" customClass="ConsistencyInterfaceController" customModule="SynchronyFinancial_WatchKit_Extension">
<controller identifier="PaymentScore" id="k4M-kn-ZzM" customClass="ConsistencyInterfaceController" customModule="SynchronyFinancial_WatchKit_Extension">
<items>
<label width="1" height="20" alignment="left" text="Payment Score" textAlignment="center" id="5cf-d7-ssN"/>
<imageView width="1" height="120" alignment="center" verticalAlignment="center" image="scores" contentMode="scaleAspectFit" initiallyAnimated="NO" id="XsN-KK-JY4"/>
Expand Down
Expand Up @@ -20,8 +20,14 @@ class AccountNumInterfaceController: WKInterfaceController {
override func awake(withContext context: Any?) {
super.awake(withContext: context)

if let val: Int = context as? Int {
score = val
}else {
score = 0
}

//Assigns score based on # of accounts
switch accNum {
/*switch accNum {
case 2...3:
score = 50
case 3...4:
Expand All @@ -30,7 +36,7 @@ class AccountNumInterfaceController: WKInterfaceController {
score = 100
default:
score = 25
}
}*/
}

override func didAppear() {
Expand Down
Expand Up @@ -20,7 +20,7 @@ class ConsistencyInterfaceController: WKInterfaceController {
super.awake(withContext: context)

//Assigns a score based on # of late payments
switch latePayments {
/*switch latePayments {
case 1:
score = 80
case 2:
Expand All @@ -29,7 +29,7 @@ class ConsistencyInterfaceController: WKInterfaceController {
score = 25
default:
score = 100
}
}*/
}

override func didAppear() {
Expand Down
Expand Up @@ -92,13 +92,14 @@ class FetchData {
let amountString = $0["transaction_amount"].string,
let amount = Double(amountString),
let confirmationNum = $0["payment_confirmation_number"].string,
let transactionCode = $0["transaction_code"].string,
let paymentIdString = $0["payment_id"].string,
let paymentId = Int(paymentIdString),
let modifiable = $0["is_payment_modifiable"].string {
let type: TransactionType = $0["payment_amount_type"].stringValue == "" ? .purchase : .reimbursement
let isModifiable: Bool = modifiable == "Y" ? true : false

transactions.append(Transaction(type: type, amount: amount, merchantID: desc, date: date, confirmationNum: confirmationNum, paymentId: paymentId, isPending: true, isModifiable: isModifiable))
transactions.append(Transaction(type: type, amount: amount, merchantID: desc, date: date, confirmationNum: confirmationNum, paymentId: paymentId, isPending: true, isModifiable: isModifiable, transactionCode: transactionCode))
}
}

Expand All @@ -107,9 +108,10 @@ class FetchData {
if let desc = $0["description"].string,
let date = Defaults.careCreditDateFormatter.date(from: $0["transaction_date"].stringValue),
let amountString = $0["transaction_amount"].string,
let transactionCode = $0["transaction_code"].string,
let amount = Double(amountString) {
let type: TransactionType = $0["payment_amount_type"].stringValue == "" ? .purchase : .reimbursement
transactions.append(Transaction(type: type, amount: amount, merchantID: desc, date: date, isPending: false))
transactions.append(Transaction(type: type, amount: amount, merchantID: desc, date: date, isPending: false, transactionCode: transactionCode))
}
}
completion(transactions, nil)
Expand Down
Expand Up @@ -52,6 +52,7 @@ class MainMenuInterfaceController: WKInterfaceController {
return acctDict
} else if segueIdentifier == "toWellness" {
// we will probably want to do some setup prior to presenting Wellness
return acctDict
}

return nil
Expand Down
Expand Up @@ -17,9 +17,11 @@ class UtilizationInterfaceController: WKInterfaceController {
@IBOutlet weak var image3: WKInterfaceImage!
override func awake(withContext context: Any?) {
super.awake(withContext: context)

score = context as? Int

// get plist data to generate utilization metric
var plistValues = PlistUtil.readPlist(for: .balance)
/*var plistValues = PlistUtil.readPlist(for: .balance)
let balance = plistValues[0][0]
let credit = plistValues[0][1] > 0 ? plistValues[0][1] : 1
util = round((Double(balance)/Double(credit)) * 100)
Expand All @@ -37,7 +39,7 @@ class UtilizationInterfaceController: WKInterfaceController {
score = Int(round((100 - util) * 0.6))
default:
score = 1
}
}*/
}

override func didAppear() {
Expand Down
Expand Up @@ -11,13 +11,40 @@ 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: 65), duration: 1.5, repeatCount: 1)
image.startAnimatingWithImages(in: NSRange(location: 1, length: wellnessScore ?? 0), duration: 1.5, repeatCount: 1)

self.pushController(withName: "UtilizationScore", context: utilizationScore)
}

override func willActivate() {
Expand All @@ -29,4 +56,82 @@ class WellnessInterfaceController: WKInterfaceController {
// 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
}

}
4 changes: 3 additions & 1 deletion SynchronyFinancial/SynchronyFinancial/Transaction.swift
Expand Up @@ -26,9 +26,10 @@ class Transaction: NSObject {
var paymentId: Int
var isPending: Bool
var isModifiable: Bool
var transactionCode: String

init(type: TransactionType, amount: Double, merchantID: String, date: Date,
confirmationNum: String? = nil, paymentId: Int? = nil, isPending: Bool? = nil, isModifiable: Bool? = nil) {
confirmationNum: String? = nil, paymentId: Int? = nil, isPending: Bool? = nil, isModifiable: Bool? = nil, transactionCode: String) {
self.type = type
self.amount = amount
self.merchantID = merchantID
Expand All @@ -37,5 +38,6 @@ class Transaction: NSObject {
self.paymentId = paymentId ?? 0
self.isPending = isPending ?? false
self.isModifiable = isModifiable ?? false
self.transactionCode = transactionCode
}
}

0 comments on commit 9303329

Please sign in to comment.