Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
SWF-17 metric calculations
- modified `Account` object model to contain `lastPayment` value to drive the last payment metric
- modified our account fetch to retrieve this value from the servers
- remove unused `Account` properties
- finished implementation for new wellness metrics
  • Loading branch information
ahm11003 committed Apr 23, 2019
1 parent 433ebac commit 17dd1df
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 30 deletions.
Expand Up @@ -431,7 +431,7 @@
<label width="1" alignment="center" text="Last Payment" textAlignment="center" id="s3f-G9-0Lf">
<fontDescription key="font" type="boldSystem" pointSize="16"/>
</label>
<button width="1" alignment="center" verticalAlignment="bottom" title="Button" id="enb-nR-7wM">
<button width="1" alignment="center" verticalAlignment="bottom" title="Details" id="enb-nR-7wM">
<connections>
<action selector="showDetails" destination="mId-Ii-HO4" id="4pt-Zo-nOe"/>
</connections>
Expand Down Expand Up @@ -465,7 +465,7 @@
<fontDescription key="font" type="boldSystem" pointSize="16"/>
</label>
<imageView width="1" height="93" alignment="center" verticalAlignment="center" contentMode="scaleAspectFit" id="JDC-go-3sn"/>
<button width="1" alignment="left" verticalAlignment="bottom" title="Button" id="JxL-nb-z6E">
<button width="1" alignment="left" verticalAlignment="bottom" title="Details" id="JxL-nb-z6E">
<connections>
<action selector="showDetails" destination="WY4-SK-U7W" id="Hie-sR-PE3"/>
</connections>
Expand Down Expand Up @@ -496,12 +496,12 @@
<color key="textColor" red="0.55326947770000001" green="0.94338613010000005" blue="0.18923908389999999" alpha="1" colorSpace="calibratedRGB"/>
<fontDescription key="font" type="system" weight="heavy" pointSize="55"/>
</label>
<label width="0.5" height="1" alignment="right" text="Accounts with Good or better Utilization" textAlignment="center" numberOfLines="5" id="W6T-4E-azA">
<label width="0.5" height="1" alignment="right" text="Accounts with 30% or lower Utilization" textAlignment="center" numberOfLines="5" id="W6T-4E-azA">
<fontDescription key="font" type="system" pointSize="12"/>
</label>
</items>
</group>
<button width="1" alignment="left" verticalAlignment="bottom" title="Button" id="HTc-Qj-xOt">
<button width="1" alignment="left" verticalAlignment="bottom" title="Details" id="HTc-Qj-xOt">
<connections>
<action selector="showDetails" destination="uKU-6b-2xO" id="OWF-LN-TCt"/>
</connections>
Expand Down
Expand Up @@ -59,8 +59,10 @@ class FetchData {
let minPaymentDue = Double(minPayDueString),
let statementBalString = $0.dictionaryValue["statement_bal"]?.string,
let statementBalance = Double(statementBalString),
let lastPmtString = $0.dictionaryValue["last_payment_amount"]?.string,
let lastPayment = Double(lastPmtString),
let accountName = $0.dictionaryValue["cc_program_name"]?.string {
let inAccount = Account(accountAlias, creditLimit, last4, paymentDueDate, currentBalance, availableCredit, minPaymentDue, statementBalance, accountName)
let inAccount = Account(accountAlias, creditLimit, last4, paymentDueDate, currentBalance, availableCredit, minPaymentDue, statementBalance, accountName, lastPayment)
accountList.append(inAccount)
}
}
Expand Down
Expand Up @@ -15,17 +15,13 @@ class LastPaymentInterfaceController: WKInterfaceController {

override func awake(withContext context: Any?) {
super.awake(withContext: context)
// Configure interface objects here.
}

override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}
guard let data = context as? [Any], data.count == 2, let last = data[0] as? Double, let rate = data[1] as? Int else {
NSLog("Error getting utilization data from wellness.")
return
}

override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
valueLabel.setText(String(format: "$%.2f", last))
descriptionLabel.setText("At this rate*, 0% utilization reached in \(rate) month(s).")
}

@IBAction func showDetails() {
Expand Down
Expand Up @@ -30,7 +30,7 @@ class UtilizationTrendInterfaceController: WKInterfaceController {
override func didAppear() {
// This method is called when watch view controller is about to be visible to user
super.didAppear()
animate(withDuration: 1.5) {
animate(withDuration: 1.0) {
self.trendImage.setAlpha(1.0)
self.trendLabel.setAlpha(1.0)
}
Expand Down
Expand Up @@ -14,6 +14,10 @@ class WellnessInterfaceController: WKInterfaceController {
var wellnessScore: Int = 0
var utilizationScore: Int = 0
var previousUtil: Int = 0
var lastpayment = 0.0
var lastPmtMetric = 0
var avgUtilization = 0.0
var healthyCount = 0

@IBOutlet weak var image: WKInterfaceImage!

Expand All @@ -35,15 +39,28 @@ class WellnessInterfaceController: WKInterfaceController {
var totalBalance: Double = 0
var totalCredit: Double = 0
var previous: Double = 0
var average = 0.0

accounts.forEach {
totalCredit += $0.creditLimit
totalBalance += $0.curBalance
let util = $0.curBalance / $0.creditLimit
if util <= 0.3 {
healthyCount += 1
}
average += util
previous += Double(arc4random_uniform(UInt32($0.creditLimit)))
}

avgUtilization = average / Double(accounts.count)
utilizationScore = Int((totalBalance / totalCredit) * 100)
previousUtil = Int((previous / totalCredit) * 100)

if accounts.count == 1 {
lastpayment = accounts[0].lastPayment
let rate = Float(accounts[0].curBalance / lastpayment).rounded(.up)
lastPmtMetric = Int(rate)
}
}

private func calculateWellness() {
Expand All @@ -54,11 +71,11 @@ class WellnessInterfaceController: WKInterfaceController {
@IBAction func moreButtonTapped() {
if accounts.count > 1 {
let pages = ["UtilizationScore", "UtilizationTrend", "AvgUtilization", "HealthyAccts"]
let contexts: [Any] = [utilizationScore, [utilizationScore, previousUtil], 35.5, 7]
let contexts: [Any] = [utilizationScore, [utilizationScore, previousUtil], avgUtilization, healthyCount]
presentController(withNames: pages, contexts: contexts)
} else {
let pages = ["UtilizationScore", "UtilizationTrend", "LastPayment"]
let contexts: [Any] = [utilizationScore, [utilizationScore, previousUtil], [10.00, 125.00]]
let contexts: [Any] = [utilizationScore, [utilizationScore, previousUtil], [lastpayment, lastPmtMetric]]
presentController(withNames: pages, contexts: contexts)
}
}
Expand Down
9 changes: 3 additions & 6 deletions SynchronyFinancial/SynchronyFinancial/Account.swift
Expand Up @@ -13,26 +13,23 @@ class Account: NSObject {
var last4: String
//var transactions: [Transaction]
var paymentDueDate: Date
//var cycleEndDate: Date
var curBalance: Double
var availCredit: Double
//var balance: Double
var minPayDue: Double
var statementBal: Double
var accountName: String
var lastPayment: Double

init(_ accountAlias: String, _ creditLimit: Double, _ last4: String, _ paymentDueDate: Date, _ curBalance: Double, _ availCredit: Double, _ minPayDue: Double, _ statementBal: Double, _ accountName: String) {
init(_ accountAlias: String, _ creditLimit: Double, _ last4: String, _ paymentDueDate: Date, _ curBalance: Double, _ availCredit: Double, _ minPayDue: Double, _ statementBal: Double, _ accountName: String, _ last: Double) {
self.accountAlias = accountAlias
self.creditLimit = creditLimit
self.last4 = last4
//self.transactions = transactions
//self.balance = transactions.map { $0.amount }.reduce(0.0, +)
self.paymentDueDate = paymentDueDate
//self.cycleEndDate = cycleEndDate
self.curBalance = curBalance
self.minPayDue = minPayDue
self.availCredit = availCredit
self.statementBal = statementBal
self.accountName = accountName
self.lastPayment = last
}
}
12 changes: 6 additions & 6 deletions SynchronyFinancial/SynchronyFinancial/Defaults.swift
Expand Up @@ -26,7 +26,7 @@ final class Defaults {
static let UTIL = "Credit utilization is the ratio of credit used compared to total credit. Ideally, this value should be 30% or below."
static let UTIL_TRENDS = "Lowering your utilization over time can help reduce the amount of interest accrued on your accounts."
static let AVG_UTIL = "Average Utilization shows the mean credit utilization across all of your CareCredit accounts"
static let LAST_PAYMENT = "Making monthly payments at this rate (excluding interests), you can eliminate your balance in the noted time period."
static let LAST_PAYMENT = "Making monthly payments at this rate (excluding interest), you can eliminate your balance in the noted time period."
static let HEALTHY_ACCTS = "Healthy accounts shows how many of your CareCredit accounts stand with a utilization at 30% or below."

static let careCreditDateFormatter: DateFormatter = {
Expand All @@ -47,13 +47,13 @@ final class Defaults {
"mobile_longitude": 0.0],
"password": "Test12test",
"scope": "default",
"username": "hhgregg2088"]
"username": "carecredit"]
}()

// this header is used for multi-account and fetch banks resources
static var headerForMulti: [String: Any] = {
return ["header": defaultHeader,
"username": "hhgregg2088"]
"username": "carecredit"]
}()

static var headerForTransaction: [String: Any] = {
Expand All @@ -72,7 +72,7 @@ final class Defaults {
"header": defaultHeader,
"scope_indicator": "B",
"start_date": start_date,
"username": "hhgregg2088"]
"username": "carecredit"]
}()

static var headerForCancelPmt: [String: Any] = {
Expand All @@ -90,7 +90,7 @@ final class Defaults {
"scope_indicator": "B",
"payment_confirmation_number": pmt_confirmation,
"payment_id": payment_id,
"username": "hhgregg2088"]
"username": "carecredit"]
}()

static var headerForPmt: [String: Any] = {
Expand All @@ -106,6 +106,6 @@ final class Defaults {
"payment_amount": 123.45,
"payment_amount_type": "CBL",
"scheduled_payment_post_date": "20190306",
"username": "hhgregg2088"]
"username": "carecredit"]
}()
}

0 comments on commit 17dd1df

Please sign in to comment.