Created
November 2, 2017 16:57
-
-
Save asowers1/5810670b4731a2644b5439d27747e772 to your computer and use it in GitHub Desktop.
Explores the effectiveness of NotificationMessages and their corresponding payment fulfillment dates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
At ----, we aim to find the best messaging that will motivate the patient to engage with us. | |
You have two lists of data: | |
A list of bill notification messages sent to patients. | |
Each message has the following properties: patient_id, channel_type, timestamp | |
channel_type can be "text", "email", "paper mail", or another channels for contacting patients. | |
A list of payments that ---- received from patients. | |
Each message has the following properties: patient_id, payment_amount, timestamp | |
Each list is stored in memory in a list or array data structure. | |
Your goal is to produce output that allows us to see which channel type is most effective at driving payments. | |
*/ | |
import Foundation | |
enum ChannelType: String { | |
case text | |
case email | |
case paperMail | |
} | |
struct NotificationMessage { | |
let billId: Int | |
let patientId: Int | |
let channelType: ChannelType | |
let timestamp: Int | |
} | |
struct Payment { | |
let billId: Int | |
let patientId: Int | |
let paymentAmount: Double | |
let timestamp: Int | |
} | |
var notificationMessages: [NotificationMessage] = [ | |
NotificationMessage(billId: 0, patientId: 0, channelType: .text, timestamp: 0), | |
NotificationMessage(billId: 0, patientId: 0, channelType: .email, timestamp: 1), | |
NotificationMessage(billId: 0, patientId: 0, channelType: .email, timestamp: 2), | |
NotificationMessage(billId: 1, patientId: 0, channelType: .text, timestamp: 0), | |
NotificationMessage(billId: 2, patientId: 1, channelType: .text, timestamp: 0), | |
NotificationMessage(billId: 3, patientId: 1, channelType: .text, timestamp: 0), | |
NotificationMessage(billId: 4, patientId: 1, channelType: .paperMail, timestamp: 3) | |
] | |
var payments: [Payment] = [ | |
Payment(billId: 0, patientId: 0, paymentAmount: 500.0, timestamp: 2), | |
Payment(billId: 1, patientId: 0, paymentAmount: 900.0, timestamp: 0), | |
Payment(billId: 2, patientId: 1, paymentAmount: 200.0, timestamp: 3), | |
Payment(billId: 3, patientId: 1, paymentAmount: 900.0, timestamp: 1), | |
Payment(billId: 4, patientId: 1, paymentAmount: 400.0, timestamp: 9) | |
] | |
var mostEffective: ChannelType = .text | |
let paymentMap: [Int: Payment] = payments.reduce([Int: Payment]()) { (dict, payment) -> [Int: Payment] in | |
var dict = dict | |
dict[payment.billId] = payment | |
return dict | |
} | |
var highestTextDiff = 0 | |
var highestEmailDiff = 0 | |
var highestMailDiff = 0 | |
for nm in notificationMessages { | |
guard let payment: Payment = paymentMap[nm.billId] else { break } | |
let paymentTS = payment.timestamp + 1 | |
let nmTS = nm.timestamp + 1 | |
switch nm.channelType { | |
case .text: | |
let textDiff = paymentTS - nmTS | |
if highestTextDiff < textDiff { | |
highestTextDiff = textDiff | |
} | |
case .email: | |
let emailDiff = paymentTS - nmTS | |
if highestEmailDiff < emailDiff { | |
highestEmailDiff = emailDiff | |
} | |
case .paperMail: | |
let mailDiff = paymentTS - nmTS | |
if highestMailDiff < mailDiff { | |
highestMailDiff = mailDiff | |
} | |
} | |
} | |
let days: [String: Int] = ["text": highestTextDiff, "email": highestEmailDiff, "mail": highestMailDiff] | |
days.forEach { | |
print("\($0.0): \($0.1)") | |
} | |
let counts: [Int: ChannelType] = [highestTextDiff: .text, highestEmailDiff: .email, highestMailDiff: .paperMail] | |
var lowest = counts.first!.0 | |
for count in counts { | |
if count.0 < lowest { | |
lowest = count.0 | |
} | |
} | |
print("the most effective method is :\(counts[lowest]!) because it has the fewest number of day differences between NotificaitonMessage posting and Payment fulfillment.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment