Created
June 9, 2016 05:53
-
-
Save yashk/c808389c56102d6c3984ed9569cabe11 to your computer and use it in GitHub Desktop.
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
Customer Id, Item Id, Transaction Date, Transaction Amount | |
Cust_1, Item_1, 2016/01/01, 100 | |
Cust_4, Item_1, 2016/01/01, 50 | |
Cust_2, Item_1, 2016/01/15, 100 | |
Cust_2, Item_1, 2016/01/31, 200 | |
Cust_3, Item_1, 2016/01/10, 150 | |
Cust_3, Item_1, 2016/02/10, 150 | |
Cust_1, Item_1, 2016/02/15, 500 | |
Cust_4, Item_1, 2016/02/15, 500 | |
Cust_4, Item_1, 2016/02/01, 50 | |
Repeated Customers | |
Input: | |
Item Set: {Item_1 ..} | |
Date Ranges: | |
Date Range 1: 2016/01/01 TO 2016/01/31 | |
Date Range 2: 2016/02/01 TO 2016/02/20 | |
Output: | |
Cust_Id, Item_Id, Visit_Cnt, Total_Txn_Value | |
Cust_4, Item_1, 3, 600 | |
Cust_1, Item_1, 2, 600 | |
Cust_3, Item_1, 2, 300 | |
Cust_4, Item_2, 3, 600 | |
Cust_1, Item_2, 2, 600 | |
Cust_3, Item_2, 2, 300 | |
Grouping customer by Customer Id, | |
map(){ | |
if(belongs(range) && belongs(item_set){ | |
Cust_id_date,<record_value> | |
} | |
} | |
reduce(<cust_id>,List<<records>>){ | |
String currentItem=""; | |
Date currentDate=""; | |
long noOfPurchaces=0; | |
int totalTxnValue=0; | |
for(Record record:records){ | |
currentItem = record.Item_id; | |
currentDate = record.Date; | |
if(belogsTo(currentDate,rangeOne)){ | |
doesBelongRangeOne=true; | |
} | |
if(belogsTo(currentDate,rangeTwo)){ | |
doesBelongRangeTwo=true; | |
} | |
noOfPurchaces ++; | |
totalTxnValue += record.txnAmount; | |
if(doesBelongRangeTwo && doesBelongRangeOne){ | |
output_record() | |
} | |
} | |
} | |
Top N | |
100 | |
10 | |
1000 | |
Global | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment