package paysim; import java.math.BigDecimal; import java.text.DecimalFormat; import java.util.ArrayList; public class AggregateParamFileCreator { /* * ALGORITHM * * FOR EACH TYPE * FOR EACH DAY * FOR EACH HOUR * AGGRECORD = GETAGGRECORD(TYPE, DAY, HOUR, TRANSACTIONLIST) * STORE(AGGRECORD) * END * END * END * */ public ArrayList generateAggregateParamFile(ArrayList transactionList){ ArrayList actions = new ArrayList(); ArrayList aggrTransRecord = new ArrayList(); actions.add("CASH_IN"); actions.add("CASH_OUT"); actions.add("DEBIT"); actions.add("DEPOSIT"); actions.add("PAYMENT"); actions.add("TRANSFER"); for(int i=0; i<6; i++){ for(int j=0; j<31; j++){ for(int h = 0; h<24; h++){ int day = j; int hour = h; AggregateTransactionRecord tempRecord = getAggregateRecord((short)(i+1), day, hour, transactionList); if(tempRecord != null){ //System.out.println("\n\nTempRecordGenerated\n" + tempRecord.toString() + ""); aggrTransRecord.add(tempRecord); } } } } java.util.Collections.sort(aggrTransRecord); return aggrTransRecord; } public ArrayList reformat(ArrayList list){ ArrayList reformedList = new ArrayList(); ArrayList tempList = new ArrayList(); for(int i=0; i(); AggregateTransactionRecord temp = list.get(i); tempList.add(temp); int counter = i+1; //Get all records looking alike temp while(counter 1){ AggregateTransactionRecord compacted = compactAggrRecord(tempList); reformedList.add(compacted); }else{ reformedList.add(temp); } } return reformedList; } private AggregateTransactionRecord compactAggrRecord(ArrayList recordList){ AggregateTransactionRecord compacted = new AggregateTransactionRecord(); DecimalFormat df = new DecimalFormat("#.##"); long hour = 0; long month = 0; long day = 0; double count = 0; double sum = 0; double avg = 0; double std = 0; double type = 0; hour = Long.parseLong(recordList.get(0).gettHour()); month = Long.parseLong(recordList.get(0).getMonth()); day = Long.parseLong(recordList.get(0).gettDay()); type = Double.parseDouble(recordList.get(0).getType()); //Getting the total count for(int i=0; i getRandomTransaction(){ Client c = new Client(); ArrayList transactionList = new ArrayList(); Transaction temp = new Transaction((long)1, c, (short)1, (double)1348, "CASH_IN"); temp.setDay(1); temp.setHour(3); transactionList.add(temp); temp = new Transaction((long)1, c, (short)1, (double)1848, "CASH_IN"); temp.setDay(2); temp.setHour(5); transactionList.add(temp); temp = new Transaction((long)1, c, (short)1, (double)1248, "CASH_IN"); temp.setDay(2); temp.setHour(5); transactionList.add(temp); temp = new Transaction((long)1, c, (short)1, (double)7848, "CASH_IN"); temp.setDay(1); temp.setHour(3); transactionList.add(temp); temp = new Transaction((long)1, c, (short)1, (double)2348, "CASH_IN"); temp.setDay(1); temp.setHour(3); transactionList.add(temp); temp = new Transaction((long)1, c, (short)1, (double)6348, "CASH_IN"); temp.setDay(1); temp.setHour(3); transactionList.add(temp); temp = new Transaction((long)1, c, (short)2, (double)3912, "CASH_OUT"); temp.setDay(1); temp.setHour(3); transactionList.add(temp); temp = new Transaction((long)1, c, (short)2, (double)13431, "CASH_OUT"); temp.setDay(1); temp.setHour(3); transactionList.add(temp); temp = new Transaction((long)1, c, (short)2, (double)3731, "CASH_OUT"); temp.setDay(1); temp.setHour(3); transactionList.add(temp); temp = new Transaction((long)1, c, (short)2, (double)9731, "CASH_OUT"); temp.setDay(2); temp.setHour(7); transactionList.add(temp); temp = new Transaction((long)1, c, (short)2, (double)13731, "CASH_OUT"); temp.setDay(2); temp.setHour(7); transactionList.add(temp); temp = new Transaction((long)1, c, (short)2, (double)6731, "CASH_OUT"); temp.setDay(2); temp.setHour(7); transactionList.add(temp); temp = new Transaction((long)1, c, (short)2, (double)11731, "CASH_OUT"); temp.setDay(2); temp.setHour(6); transactionList.add(temp); temp = new Transaction((long)1, c, (short)2, (double)3731, "CASH_OUT"); temp.setDay(2); temp.setHour(6); transactionList.add(temp); temp = new Transaction((long)1, c, (short)2, (double)1731, "CASH_OUT"); temp.setDay(2); temp.setHour(6); transactionList.add(temp); temp = new Transaction((long)1, c, (short)4, (double)2348, "DEPOSIT"); temp.setDay(6); temp.setHour(4); transactionList.add(temp); temp = new Transaction((long)1, c, (short)4, (double)5731, "DEPOSIT"); temp.setDay(6); temp.setHour(4); transactionList.add(temp); temp = new Transaction((long)1, c, (short)4, (double)15731, "DEPOSIT"); temp.setDay(6); temp.setHour(4); transactionList.add(temp); return transactionList; } public AggregateTransactionRecord getAggregateRecord(short type, int day, int hour, ArrayList transactionList){ ArrayList subsetTransList = new ArrayList(); AggregateTransactionRecord recordToReturn = new AggregateTransactionRecord(); for(int i=0; i 0){ double sum = getTotalAmount(subsetTransList); int count = subsetTransList.size(); double average = getDoublePrecision(2, (( sum / (double)count ))); double tstd = getStdv(subsetTransList, average); recordToReturn.setType(String.valueOf(type)); recordToReturn.settSum(String.valueOf(sum)); recordToReturn.settCount(String.valueOf(count)); recordToReturn.settAvg(String.valueOf(getDoublePrecision(2, average))); recordToReturn.settStd(String.valueOf(getDoublePrecision(2, tstd))); recordToReturn.setMonth(String.valueOf(10)); recordToReturn.settDay(String.valueOf(day)); recordToReturn.settHour(String.valueOf(hour)); return recordToReturn; }else{ return null; } } private double getDoublePrecision(int precision, double d){ try { Double toBeTruncated = new Double(d); Double truncatedDouble=new BigDecimal(toBeTruncated). setScale(precision, BigDecimal.ROUND_HALF_UP). doubleValue(); return truncatedDouble; } catch (Exception e) { return 0; } } public static double getStdv(ArrayList list, double average){ DecimalFormat df = new DecimalFormat("#.##"); double stdv = 0; double squaredMeanSum = 0; //For each number, subtract the mean and square the result for(int i=0; i transactionList){ double amount = 0; for(Transaction t: transactionList){ amount += t.getAmount(); } return amount; } }