|
package paysim; |
|
|
|
import java.util.ArrayList; |
|
|
|
public class CurrentStepHandler { |
|
|
|
private ArrayList<CurrentStepContainer> stepHandler = new ArrayList<>(); |
|
private ArrayList<CurrentStepContainer> stepCountCombination = new ArrayList<>(); |
|
private ArrayList<String> fileContents = new ArrayList<String>(); |
|
private ArrayList<Integer> stepsThatAreNotAllowed = new ArrayList<Integer>(); |
|
private ArrayList<AggregateTransactionRecord> aggrRecordList = new ArrayList<AggregateTransactionRecord>(); |
|
private double multiplier = 0; |
|
|
|
public CurrentStepHandler(ArrayList<String> fileContents, double mult){ |
|
setFileContents(fileContents); |
|
for(int i=0; i<744; i++){ |
|
CurrentStepContainer container = new CurrentStepContainer(); |
|
container.setCounter(0); |
|
container.setCurrentStep(i); |
|
stepHandler.add(container); |
|
} |
|
|
|
initStepCountCombination(); |
|
modifyWithMultiplier(mult); |
|
this.initAggregateRecordList(); |
|
} |
|
|
|
private void initAggregateRecordList(){ |
|
for(String s: this.fileContents){ |
|
String splitted[] = s.split(","); |
|
AggregateTransactionRecord record = new AggregateTransactionRecord(); |
|
record.setType(splitted[0]); |
|
record.setMonth(splitted[1]); |
|
record.settDay(splitted[2]); |
|
record.settHour(splitted[3]); |
|
record.settCount(splitted[4]); |
|
record.settSum(splitted[5]); |
|
record.settAvg(splitted[6]); |
|
record.settStd(splitted[7]); |
|
this.aggrRecordList.add(record); |
|
} |
|
} |
|
|
|
public AggregateTransactionRecord getRecord(String type, int day, int hour){ |
|
for(AggregateTransactionRecord t: this.aggrRecordList){ |
|
if(t.getType().equals(type) && |
|
t.gettDay().equals(String.valueOf(day)) && |
|
t.gettHour().equals(String.valueOf(hour))){ |
|
return t; |
|
} |
|
} |
|
return null; |
|
} |
|
|
|
private void modifyWithMultiplier(double mult){ |
|
for(int i=0; i<this.stepHandler.size(); i++){ |
|
long newCounter = this.stepHandler.get(i).getCounter(); |
|
newCounter = (long) (newCounter * mult); |
|
this.stepHandler.get(i).setCounter(newCounter); |
|
} |
|
} |
|
|
|
private void initStepCountCombination(){ |
|
for(int i=0; i<stepHandler.size(); i++){ |
|
long count = 0; |
|
long currDay= i/24 + 1; |
|
long currHour = (int) (i - ((currDay - 1) * 24)); |
|
CurrentStepContainer currentContainer = stepHandler.get(i); |
|
boolean isInParamFile = this.isInParamFile(currDay, currHour); |
|
if(isInParamFile){ |
|
int j=0; |
|
for(j=1; j<this.fileContents.size(); j++){ |
|
String line[] = this.fileContents.get(j).split(","); |
|
try { |
|
if(Long.parseLong(line[2]) == currDay && |
|
Long.parseLong(line[3]) == currHour |
|
&& isAction(line[0])){ |
|
count += Long.parseLong(line[4]); |
|
} |
|
} catch (Exception e) { |
|
|
|
continue; |
|
} |
|
} |
|
currentContainer.setCounter(count); |
|
j=0; |
|
} |
|
} |
|
|
|
|
|
for(int i=0; i<this.stepHandler.size(); i++){ |
|
if(this.stepHandler.get(i).getCounter() == 0){ |
|
this.stepHandler.remove(i); |
|
i--; |
|
} |
|
} |
|
|
|
for(CurrentStepContainer cont: stepHandler){ |
|
|
|
} |
|
} |
|
|
|
private void initStepsNotAllowed(){ |
|
int j=0; |
|
for(int i=0; i<744; i++){ |
|
long currDay= i/24 + 1; |
|
long currHour = (int) (i - ((currDay - 1) * 24)); |
|
boolean isInParamFile = this.isInParamFile(currDay, currHour); |
|
|
|
if(!isInParamFile){ |
|
this.stepsThatAreNotAllowed.add(i); |
|
} |
|
|
|
} |
|
} |
|
|
|
public long getNrOfTimesToReduce(long stepNumber){ |
|
for(int i=0; i<this.stepHandler.size(); i++){ |
|
if(this.stepHandler.get(i).getCurrentStep() == stepNumber){ |
|
return this.stepHandler.get(i).getNrReduced(); |
|
} |
|
} |
|
return -1; |
|
} |
|
|
|
public void increaseReduction(long stepNumber){ |
|
for(int i=0; i<744; i++){ |
|
if(this.stepHandler.get(i).getCurrentStep() == stepNumber){ |
|
this.stepHandler.get(i).increment(); |
|
} |
|
} |
|
} |
|
|
|
public void printInfo(){ |
|
long cumulative = 0; |
|
for(int i=0; i<this.stepHandler.size(); i++){ |
|
CurrentStepContainer cont = this.stepHandler.get(i); |
|
cumulative += cont.getCounter(); |
|
} |
|
|
|
} |
|
|
|
public boolean isTransactionsAtStep(long step, PaySim paysim){ |
|
|
|
for(int i=0; i<this.stepsThatAreNotAllowed.size(); i++){ |
|
if(step == this.stepsThatAreNotAllowed.get(i)){ |
|
|
|
return false; |
|
} |
|
} |
|
return true ; |
|
} |
|
|
|
public boolean nrOfRepGreaterThanCount(long step, PaySim paysim){ |
|
|
|
long origCount = 0; |
|
long nrOfRep = 0; |
|
|
|
for(int i=0; i<this.stepCountCombination.size(); i++){ |
|
if(this.stepCountCombination.get(i).getCurrentStep() == step){ |
|
origCount = this.stepCountCombination.get(i).getCounter(); |
|
break; |
|
} |
|
} |
|
|
|
|
|
for(int i=0; i<this.stepHandler.size(); i++){ |
|
if(this.stepHandler.get(i).getCurrentStep() == step){ |
|
nrOfRep = this.stepHandler.get(i).getCounter(); |
|
break; |
|
} |
|
} |
|
|
|
|
|
origCount *= paysim.getMultiplier(); |
|
|
|
if(nrOfRep > origCount){ |
|
stepsThatAreNotAllowed.add((int) step); |
|
|
|
return true; |
|
}else{ |
|
return false; |
|
} |
|
|
|
} |
|
|
|
public void setFileContents(ArrayList<String> contents){ |
|
this.fileContents = contents; |
|
} |
|
|
|
private boolean isInParamFile(long day, long hour){ |
|
for(int i=1; i<this.fileContents.size(); i++){ |
|
String s = this.fileContents.get(i); |
|
String splitted[] = s.split(","); |
|
if(Long.parseLong(splitted[2]) == day && |
|
Long.parseLong(splitted[3]) == hour) |
|
{ |
|
return true; |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
public boolean isAction(String token){ |
|
if(token.equals("CASH_IN") || |
|
token.equals("CASH_OUT") || |
|
token.equals("TRANSFER") || |
|
token.equals("PAYMENT") || |
|
token.equals("DEBIT") || |
|
token.equals("DEPOSIT")) |
|
{ |
|
return true; |
|
} |
|
return false; |
|
} |
|
|
|
public ArrayList<Long> getSteps(long currentStep, long nrOfSteps){ |
|
ArrayList<Long> stepsToBeRepeated = new ArrayList<Long>(); |
|
int stepsGathered = 0; |
|
long index = 0; |
|
while(stepsGathered < nrOfSteps){ |
|
index = index % this.stepHandler.size(); |
|
if(index == 0){ |
|
if(this.isFull(currentStep)){ |
|
return null; |
|
} |
|
} |
|
|
|
CurrentStepContainer gottenOne = this.stepHandler.get((int) index); |
|
if(gottenOne.canBeReduced() |
|
&& gottenOne.getCurrentStep()>= currentStep) |
|
{ |
|
this.stepHandler.get((int) index).increment(); |
|
stepsToBeRepeated.add(gottenOne.getCurrentStep()); |
|
stepsGathered++; |
|
} |
|
index++; |
|
} |
|
return stepsToBeRepeated; |
|
|
|
} |
|
|
|
|
|
public boolean isFull(long currentStep){ |
|
for(int i=0; i<this.stepHandler.size(); i++){ |
|
if(this.stepHandler.get(i).getCurrentStep() >= currentStep){ |
|
if(this.stepHandler.get(i).canBeReduced()){ |
|
|
|
return false; |
|
}else{ |
|
|
|
} |
|
}else{ |
|
|
|
} |
|
} |
|
return true; |
|
} |
|
|
|
|
|
|
|
public void printInfo2(){ |
|
long totalCount = 0; |
|
for(int i=0; i<this.stepHandler.size(); i++){ |
|
|
|
totalCount += this.stepHandler.get(i).getCounter(); |
|
} |
|
|
|
} |
|
|
|
public void convertDeconvert(){ |
|
int currentStep = 50; |
|
|
|
for(CurrentStepContainer cont: this.stepHandler){ |
|
int currDay = (int)(cont.getCurrentStep()/24) + 1; |
|
int currHour = (int) (cont.getCurrentStep() - (( currDay - 1) * 24)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|