Commit 5f729aa3 by Harsh Shah

Culture Fit, Requirement Fit algorithm implementation

parent feacaaa7
......@@ -31,4 +31,10 @@ public class AssessmentCriteriaAnswer extends BaseAssessmentCriteriaAnswer
{
return (criteriaType == null ? true : (getAssessmentCriteria() != null && (getAssessmentCriteria().getCriteriaType() == criteriaType))); //Should bypass condition if input param is null
}
//Currently we have a yes/no. We'll also have a select from (via a dropdown) in future - but still, there'll be one correct answer.
public boolean isCorrectAnswer()
{
return isTrue(getAnswer());
}
}
\ No newline at end of file
......@@ -37,6 +37,8 @@ public class ColorCode extends AbstractEnumerated
private transient Integer ColorRank;
private transient Integer RatingScore;
private ColorCode (String name, String value, String description, boolean disabled)
{
super (name, value, description, disabled);
......@@ -47,6 +49,11 @@ public class ColorCode extends AbstractEnumerated
return ColorRank;
}
public Integer getRatingScore()
{
return RatingScore;
}
public static final Comparator COMPARE_BY_POSITION = new CompareEnumByPosition (allColorCodes);
......@@ -115,8 +122,11 @@ public class ColorCode extends AbstractEnumerated
public static void defineAdditionalData ()
{
RED.ColorRank = 3;
RED.RatingScore = 0;
AMBER.ColorRank = 2;
AMBER.RatingScore = 5;
GREEN.ColorRank = 1;
GREEN.RatingScore = 10;
}
......@@ -145,6 +155,7 @@ public class ColorCode extends AbstractEnumerated
Map attribs = new HashMap ();
attribs.put ("ColorRank", ArrayFormatter.toObject(getColorRank()));
attribs.put ("RatingScore", ArrayFormatter.toObject(getRatingScore()));
return attribs;
}
......
......@@ -4,10 +4,11 @@
<CONSTANT package="performa.orm.types" name="ColorCode">
<DATA name="ColorRank" type="Integer"/>
<DATA name="RatingScore" type="Integer"/>
<VALUE name="RED" value="RED" description="Red" ColorRank="3"/>
<VALUE name="AMBER" value="AMBER" description="Amber" ColorRank="2"/>
<VALUE name="GREEN" value="GREEN" description="Green" ColorRank="1"/>
<VALUE name="RED" value="RED" description="Red" ColorRank="3" RatingScore="0"/>
<VALUE name="AMBER" value="AMBER" description="Amber" ColorRank="2" RatingScore="5"/>
<VALUE name="GREEN" value="GREEN" description="Green" ColorRank="1" RatingScore="10"/>
</CONSTANT>
</ROOT>
\ No newline at end of file
......@@ -39,6 +39,8 @@ public class Importance extends AbstractEnumerated
private transient boolean ConsiderForAssessment;
private transient Integer WeightingScore;
private Importance (String name, String value, String description, boolean disabled)
{
super (name, value, description, disabled);
......@@ -49,6 +51,11 @@ public class Importance extends AbstractEnumerated
return ConsiderForAssessment;
}
public Integer getWeightingScore()
{
return WeightingScore;
}
public static final Comparator COMPARE_BY_POSITION = new CompareEnumByPosition (allImportances);
......@@ -117,9 +124,13 @@ public class Importance extends AbstractEnumerated
public static void defineAdditionalData ()
{
NOT_APPLICABLE.ConsiderForAssessment = false;
NOT_APPLICABLE.WeightingScore = 0;
DESIRABLE.ConsiderForAssessment = true;
DESIRABLE.WeightingScore = 2;
HIGHLY_DESIRABLE.ConsiderForAssessment = true;
HIGHLY_DESIRABLE.WeightingScore = 5;
ESSENTIAL.ConsiderForAssessment = true;
ESSENTIAL.WeightingScore = 10;
}
......@@ -148,6 +159,7 @@ public class Importance extends AbstractEnumerated
Map attribs = new HashMap ();
attribs.put ("ConsiderForAssessment", ArrayFormatter.toObject(getConsiderForAssessment()));
attribs.put ("WeightingScore", ArrayFormatter.toObject(getWeightingScore()));
return attribs;
}
......
......@@ -4,11 +4,12 @@
<CONSTANT package="performa.orm.types" name="Importance">
<DATA name="ConsiderForAssessment" type="boolean" />
<DATA name="WeightingScore" type="Integer"/>
<VALUE name="NOT_APPLICABLE" description="Not Applicable" ConsiderForAssessment="false"/>
<VALUE name="DESIRABLE" description="Desirable" ConsiderForAssessment="true"/>
<VALUE name="HIGHLY_DESIRABLE" description="Highly Desirable" ConsiderForAssessment="true"/>
<VALUE name="ESSENTIAL" description="Essential" ConsiderForAssessment="true"/>
<VALUE name="NOT_APPLICABLE" description="Not Applicable" ConsiderForAssessment="false" WeightingScore="0"/>
<VALUE name="DESIRABLE" description="Desirable" ConsiderForAssessment="true" WeightingScore="2"/>
<VALUE name="HIGHLY_DESIRABLE" description="Highly Desirable" ConsiderForAssessment="true" WeightingScore="5"/>
<VALUE name="ESSENTIAL" description="Essential" ConsiderForAssessment="true" WeightingScore="10"/>
</CONSTANT>
</ROOT>
\ No newline at end of file
......@@ -6,7 +6,7 @@ import oneit.objstore.*;
import oneit.objstore.rdbms.filters.*;
import oneit.utils.*;
import oneit.utils.filter.Filter;
import oneit.utils.math.Statistics;
import oneit.utils.math.*;
import oneit.utils.parsers.FieldException;
import performa.orm.*;
import performa.orm.types.*;
......@@ -157,4 +157,137 @@ public class AnalysisEngine
LogMgr.log(JobApplication.LOG, LogLevel.PROCESSING1, "AnalysisEngine --> analyseAnswers completed");
}
public static Map<CultureClass, Long> getCultureFit(Set<CultureCriteriaAnswer> cultureCriteriaAnswers)
{
LogMgr.log(JobApplication.LOG, LogLevel.PROCESSING1, "AnalysisEngine --> getCultureFit called");
//Preloading data
CultureCriteriaAnswer.pipesCultureCriteriaAnswer(cultureCriteriaAnswers).toSelectedQuestion().toNarratives().toCultureElementRating().uniqueVals();
CultureCriteriaAnswer.pipesCultureCriteriaAnswer(cultureCriteriaAnswers).toCultureCriteria().toCultureElementRating().toCultureElement().uniqueVals();
Map<CultureClass, Integer> scoreMap = new HashMap();
Map<CultureClass, Integer> maxScoreMap = new HashMap();
for(CultureClass cultureClass : CultureClass.getCultureClassArray())
{
scoreMap.put(cultureClass, 0);
maxScoreMap.put(cultureClass, 0);
}
for(CultureCriteriaAnswer answer : cultureCriteriaAnswers)
{
CultureCriteria criteria = answer.getCultureCriteria();
if(criteria != null && criteria.getImportance() != null && criteria.getImportance() != Importance.NOT_APPLICABLE)
{
CultureElementRating rating = criteria.getCultureElementRating();
if(rating != null && rating.getCultureElement() != null && rating.getCultureElement().getCultureClass() != null)
{
CultureElement element = rating.getCultureElement();
CultureClass cultureClass = element.getCultureClass();
CultureElementQuestion question = answer.getSelectedQuestion();
Integer weightingScore = criteria.getImportance().getWeightingScore();
Integer ratingScore = 0;
if(question != null)
{
Filter narrativeFilter = CultureNarrative.SearchByAll().andCultureElementRating(new EqualsFilter(rating));
CultureNarrative narrative = (CultureNarrative) question.pipelineCultureElementQuestion().toNarratives(narrativeFilter).val();
if(narrative != null && narrative.getColorCode() != null)
{
ratingScore = narrative.getColorCode().getRatingScore();
}
}
int score = (weightingScore * ratingScore);
int maxScore = (weightingScore * ColorCode.GREEN.getRatingScore());
scoreMap.put(cultureClass, (scoreMap.get(cultureClass) + score));
maxScoreMap.put(cultureClass, (maxScoreMap.get(cultureClass) + maxScore));
}
}
}
Map<CultureClass, Long> cultureFitMap = getFinalFitMap(scoreMap, maxScoreMap);
LogMgr.log(JobApplication.LOG, LogLevel.PROCESSING1, "AnalysisEngine --> getCultureFit completed");
return cultureFitMap;
}
private static <T> Map<T, Long> getFinalFitMap(Map<T, Integer> scoreMap, Map<T, Integer> maxScoreMap)
{
Map<T, Long> fitMap = new HashMap();
int totalScore = 0;
int totalMaxScore = 0;
for(T key : scoreMap.keySet())
{
int score = scoreMap.get(key);
int maxScore = maxScoreMap.get(key);
LogMgr.log(JobApplication.LOG, LogLevel.DEBUG1, "getCultureFit score for ", key, " ", score, " max:", maxScore);
totalScore += score;
totalMaxScore += maxScore;
if(maxScore != 0) //To prevent divide by zero
{
fitMap.put(key, Math.round(NullArith.divide(score, maxScore) * 100));
}
else
{
fitMap.put(key, 0L);
}
}
if(totalMaxScore != 0)
{
fitMap.put(null, Math.round(NullArith.divide(totalScore, totalMaxScore) * 100)); //Using NULL key for final total
}
else
{
fitMap.put(null, 0L); //Using NULL key for final total
}
return fitMap;
}
public static Map<Importance, Long> getRequirementFit(Set<AssessmentCriteriaAnswer> assessmentCriteriaAnswers)
{
LogMgr.log(JobApplication.LOG, LogLevel.PROCESSING1, "AnalysisEngine --> getRequirementFit called");
Map<Importance, Integer> scoreMap = new HashMap();
Map<Importance, Integer> maxScoreMap = new HashMap();
for(Importance importance : Importance.getImportanceArray())
{
if(importance.getWeightingScore() > 0) //Skiping NOT_APPLICABLE
{
scoreMap.put(importance, 0);
maxScoreMap.put(importance, 0);
}
}
for(AssessmentCriteriaAnswer answer : assessmentCriteriaAnswers)
{
if(answer.getAssessmentCriteria() != null && answer.getAssessmentCriteria().getImportance() != null)
{
Importance importance = answer.getAssessmentCriteria().getImportance();
int maxScore = importance.getWeightingScore();
int score = answer.isCorrectAnswer() ? maxScore : 0;
scoreMap.put(importance, (scoreMap.get(importance) + score));
maxScoreMap.put(importance, (maxScoreMap.get(importance) + maxScore));
}
}
Map<Importance, Long> requirementFitMap = getFinalFitMap(scoreMap, maxScoreMap);
LogMgr.log(JobApplication.LOG, LogLevel.PROCESSING1, "AnalysisEngine --> getRequirementFit completed");
return requirementFitMap;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment