Your question is Test Ancestry Campaign Event Parser. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
In the Ancestry Marketing mobile app, analytics events arrive as pipe-delimited strings. Implement a function that both parses these events and applies business rules to compute the total revenue from valid purchase events.
Each event string has the format:
timestamp|event_type|user_id|campaign|amount
Your task is to process a list of event strings and return the sum of amounts for valid purchase events.
event_type == "purchase" count toward revenue.timestamp or amount is not a valid integer.amount <= 0.(timestamp, user_id). If the same purchase appears multiple times, count it only once.def total_valid_purchase_revenue(events):