forked from apache/incubator-kie-drools
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit for drools-scorecards.
- Loading branch information
1 parent
36237bb
commit 11dfdd1
Showing
34 changed files
with
3,669 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
36 changes: 36 additions & 0 deletions
36
drools-scorecards/src/main/java/org/drools/scorecards/BaselineScore.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2012 JBoss Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.drools.scorecards; | ||
|
||
import java.io.Serializable; | ||
|
||
public class BaselineScore extends InitialScore implements Serializable { | ||
protected String characteristic; | ||
|
||
public BaselineScore(String scorecardName, String characteristic, double score) { | ||
super(scorecardName, score); | ||
this.characteristic = characteristic; | ||
} | ||
|
||
public String getCharacteristic() { | ||
return characteristic; | ||
} | ||
|
||
public void setCharacteristic(String characteristic) { | ||
this.characteristic = characteristic; | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
drools-scorecards/src/main/java/org/drools/scorecards/DroolsScorecard.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
* Copyright 2012 JBoss Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.drools.scorecards; | ||
|
||
import java.io.Serializable; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.TreeMap; | ||
|
||
public class DroolsScorecard implements Serializable { | ||
double calculatedScore; | ||
List<String> reasonCodes = new ArrayList<String>(); | ||
Map<String, Double> baselineScoreMap = new HashMap<String, Double>(); | ||
private int reasonCodeAlgorithm; | ||
public static int REASON_CODE_ALGORITHM_POINTSABOVE = 1; | ||
public static int REASON_CODE_ALGORITHM_POINTSBELOW = -1; | ||
|
||
public int getReasonCodeAlgorithm() { | ||
return reasonCodeAlgorithm; | ||
} | ||
|
||
public void setReasonCodeAlgorithm(int reasonCodeAlgorithm) { | ||
this.reasonCodeAlgorithm = reasonCodeAlgorithm; | ||
} | ||
|
||
public void setBaselineScore(String characteristic, int baselineScore){ | ||
baselineScoreMap.put(characteristic, (double)baselineScore); | ||
} | ||
|
||
public void setBaselineScore(String characteristic, double baselineScore){ | ||
baselineScoreMap.put(characteristic, baselineScore); | ||
} | ||
|
||
public double getCalculatedScore() { | ||
return calculatedScore; | ||
} | ||
|
||
public void setCalculatedScore(double calculatedScore) { | ||
this.calculatedScore = calculatedScore; | ||
} | ||
|
||
public void sortReasonCodes() { | ||
|
||
} | ||
|
||
// public void addPartialScore(int partialScore) { | ||
// this.calculatedScore += partialScore; | ||
// } | ||
// | ||
// public void setInitialScore(int initialScore) { | ||
// this.calculatedScore = initialScore; | ||
// } | ||
|
||
public void setInitialScore(double initialScore) { | ||
this.calculatedScore = initialScore; | ||
} | ||
|
||
// public void addPartialScore(double partialScore) { | ||
// this.calculatedScore += partialScore; | ||
// } | ||
// | ||
// public void addPartialScore(String field, double partialScore, String reasonCode) { | ||
// this.calculatedScore += partialScore; | ||
// reasonCodes.add(reasonCode); | ||
// } | ||
|
||
// public void addReasonCode(String reasonCode){ | ||
// reasonCodes.add(reasonCode); | ||
// } | ||
// | ||
public List<String> getReasonCodes() { | ||
return Collections.unmodifiableList(reasonCodes); | ||
} | ||
|
||
public void setReasonCodes(List<String> reasonCodes) { | ||
this.reasonCodes = reasonCodes; | ||
} | ||
|
||
public void sortReasonCodes(List<PartialScore> partialScores) { | ||
TreeMap<Double, String> distanceMap = new TreeMap<Double, String>(); | ||
for (PartialScore partialScore : partialScores ){ | ||
if (baselineScoreMap.get(partialScore.getCharacteristic()) != null ) { | ||
double baseline = baselineScoreMap.get(partialScore.getCharacteristic()); | ||
double distance = 0; | ||
if (getReasonCodeAlgorithm() == REASON_CODE_ALGORITHM_POINTSABOVE) { | ||
distance = (baseline - partialScore.getScore())+partialScore.getPosition(); | ||
distanceMap.put(distance, partialScore.getReasoncode()); | ||
} else if (getReasonCodeAlgorithm() == REASON_CODE_ALGORITHM_POINTSBELOW){ | ||
distance = (partialScore.getScore()-baseline)+partialScore.getPosition(); | ||
distanceMap.put(distance, partialScore.getReasoncode()); | ||
} | ||
} | ||
} | ||
|
||
for ( Double distance : distanceMap.descendingKeySet()) { | ||
System.out.println(distance+" "+distanceMap.get(distance)); | ||
} | ||
} | ||
public DroolsScorecard() { | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
drools-scorecards/src/main/java/org/drools/scorecards/InitialScore.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2012 JBoss Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.drools.scorecards; | ||
|
||
import java.io.Serializable; | ||
|
||
public class InitialScore implements Serializable { | ||
protected String scorecardName; | ||
protected double score; | ||
|
||
public String getScorecardName() { | ||
return scorecardName; | ||
} | ||
|
||
public void setScorecardName(String scorecardName) { | ||
this.scorecardName = scorecardName; | ||
} | ||
|
||
public double getScore() { | ||
return score; | ||
} | ||
|
||
public void setScore(double score) { | ||
this.score = score; | ||
} | ||
|
||
public InitialScore(String scorecardName, double score) { | ||
|
||
this.scorecardName = scorecardName; | ||
this.score = score; | ||
} | ||
|
||
public InitialScore() { | ||
|
||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
drools-scorecards/src/main/java/org/drools/scorecards/PartialScore.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2012 JBoss Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.drools.scorecards; | ||
|
||
import java.io.Serializable; | ||
|
||
public class PartialScore extends BaselineScore implements Serializable { | ||
protected String reasoncode; | ||
protected int position; | ||
|
||
public PartialScore(String scorecardName, String characteristic, double score, String reasoncode, int position) { | ||
super(scorecardName, characteristic, score); | ||
this.reasoncode = reasoncode; | ||
this.position = position; | ||
} | ||
|
||
public PartialScore(String scorecardName, String characteristic, double score) { | ||
super(scorecardName, characteristic, score); | ||
this.scorecardName = scorecardName; | ||
this.characteristic = characteristic; | ||
this.score = score; | ||
} | ||
|
||
public int getPosition() { | ||
return position; | ||
} | ||
|
||
public String getReasoncode() { | ||
return reasoncode; | ||
} | ||
|
||
public void setReasoncode(String reasoncode) { | ||
this.reasoncode = reasoncode; | ||
} | ||
} |
Oops, something went wrong.