Commit 028f1b0d by Nilu

Input analysis completed

parent 595c3bd1
...@@ -11,8 +11,13 @@ import oneit.servlets.jsp.TableTag; ...@@ -11,8 +11,13 @@ import oneit.servlets.jsp.TableTag;
import oneit.servlets.portability.FileDownloader; import oneit.servlets.portability.FileDownloader;
import oneit.servlets.process.*; import oneit.servlets.process.*;
import oneit.utils.*; import oneit.utils.*;
import oneit.utils.parsers.FieldException;
import oneit.utils.table.*; import oneit.utils.table.*;
import performa.orm.Answer;
import performa.orm.Candidate;
import performa.orm.Question;
import performa.orm.TestInput; import performa.orm.TestInput;
import performa.utils.AnalysisEngine;
/** /**
* *
...@@ -28,10 +33,11 @@ public class TestAnalysisFP extends ORMProcessFormProcessor ...@@ -28,10 +33,11 @@ public class TestAnalysisFP extends ORMProcessFormProcessor
TestInput testInput = (TestInput) process.getAttribute("TestAnalysis"); TestInput testInput = (TestInput) process.getAttribute("TestAnalysis");
ByteArrayOutputStream bos = new ByteArrayOutputStream (); ByteArrayOutputStream bos = new ByteArrayOutputStream ();
byte[] bytes; byte[] bytes;
//TO-DO -> "filecontent" processing
try try
{ {
loadData(testInput, process.getTransaction());
ExcelExporter.ExportAppender excelRenderer = getExportAppender(testInput.getCSV()); ExcelExporter.ExportAppender excelRenderer = getExportAppender(testInput.getCSV());
excelRenderer.export(bos); excelRenderer.export(bos);
bytes = bos.toByteArray(); bytes = bos.toByteArray();
...@@ -73,19 +79,103 @@ public class TestAnalysisFP extends ORMProcessFormProcessor ...@@ -73,19 +79,103 @@ public class TestAnalysisFP extends ORMProcessFormProcessor
return model; return model;
} }
public void loadData(TestInput testInput, ObjectTransaction objTran)
{
BufferedReader bReader = null;
String line = "";
String csvSeparator = ",";
boolean first = true;
List<Candidate> candidates = new ArrayList<>();
List<Answer> answers = new ArrayList<>();
try
{
bReader = new BufferedReader(new InputStreamReader(testInput.getCSV().getInputStream()));
while ((line = bReader.readLine()) != null)
{
String[] values = line.trim().split(csvSeparator);
if(first)
{
for (int i = 1; i < values.length ; i++)
{
Candidate candidate = Candidate.createCandidate(objTran);
candidate.setFirstName(values[i]);
candidate.setTestInput(testInput);
candidates.add(candidate);
}
first = false;
}
else
{
Question question = Question.getQuestionByID(objTran, Long.valueOf(values[0]));
for (int i = 1; i < values.length ; i++)
{
Answer answer = Answer.createAnswer(objTran);
answer.setAnswerNo(Integer.parseInt(values[i]));
answer.setCandidate(candidates.get(i -1));
answer.setQuestion(question);
answers.add(answer);
}
}
}
AnalysisEngine.analyseAnswers(answers.toArray(new Answer[0]), testInput.getLevel());
}
catch (FileNotFoundException ex)
{
LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING2, "UploadCSVFP loadData : FileNotFoundException :" + ex);
throw new NestedException(ex);
}
catch (IOException ex)
{
LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING2, "UploadCSVFP loadData : IOException :" + ex);
throw new NestedException(ex);
}
catch (FieldException ex)
{
LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING2, "UploadCSVFP loadData : FieldException :" + ex);
throw new NestedException(ex);
}
finally
{
try
{
if (bReader != null)
{
bReader.close();
}
}
catch (IOException ex)
{
LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING2, "UploadCSVFP loadData : IOException :" + ex);
throw new NestedException(ex);
}
}
}
@Override @Override
public void validate(ORMProcessState process, SubmissionDetails submission, MultiException exceptions, Map params) throws StorageException public void validate(ORMProcessState process, SubmissionDetails submission, MultiException exceptions, Map params) throws StorageException
{ {
super.validate(process, submission, exceptions, params); super.validate(process, submission, exceptions, params);
TestInput testAnalysis = (TestInput) process.getAttribute("TestAnalysis"); TestInput testInput = (TestInput) process.getAttribute("TestAnalysis");
Debug.assertion(testAnalysis != null, "Test Analysis is null while Processing CSV File."); Debug.assertion(testInput != null, "Test Input is null while Processing CSV File.");
if(testAnalysis.getCSV() != null) if(testInput.getCSV() != null)
{ {
BusinessObjectParser.assertFieldCondition(SUPPORTED_TYPES.contains(testAnalysis.getCSV().getContentType()), testAnalysis, TestInput.FIELD_CSV, "invalid", exceptions, true, submission.getRequest()); BusinessObjectParser.assertFieldCondition(SUPPORTED_TYPES.contains(testInput.getCSV().getContentType()), testInput, TestInput.FIELD_CSV, "invalid", exceptions, true, submission.getRequest());
} }
} }
} }
...@@ -16,4 +16,10 @@ public class Level extends BaseLevel ...@@ -16,4 +16,10 @@ public class Level extends BaseLevel
{ {
return "Level"; return "Level";
} }
@Override
public String getToString()
{
return getLevelDescription();
}
} }
\ No newline at end of file
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
<ATTRIB name="CSV" type="BinaryContent" mandatory="true" attribHelper="BLOBAttributeHelper" attribHelperInstance="BLOBAttributeHelper.INSTANCE" binaryHandler="loggedin"/> <ATTRIB name="CSV" type="BinaryContent" mandatory="true" attribHelper="BLOBAttributeHelper" attribHelperInstance="BLOBAttributeHelper.INSTANCE" binaryHandler="loggedin"/>
<SINGLEREFERENCE name="Level" type="Level"/>
</TABLE> </TABLE>
</BUSINESSCLASS> </BUSINESSCLASS>
......
...@@ -24,7 +24,7 @@ import performa.orm.Level; ...@@ -24,7 +24,7 @@ import performa.orm.Level;
public class AnalysisEngine public class AnalysisEngine
{ {
public void analyseAnswers(Answer[] answers, Level level) public static void analyseAnswers(Answer[] answers, Level level)
{ {
ObjectTransaction objTran = level.getTransaction(); ObjectTransaction objTran = level.getTransaction();
...@@ -70,12 +70,13 @@ public class AnalysisEngine ...@@ -70,12 +70,13 @@ public class AnalysisEngine
FactorScoreResult result = FactorScoreResult.SearchByFactorScore() FactorScoreResult result = FactorScoreResult.SearchByFactorScore()
.andFactor(new EqualsFilter<>(factor)) .andFactor(new EqualsFilter<>(factor))
.andLevel(new EqualsFilter<>(level)) .andLevel(new EqualsFilter<>(level))
.andFromScore(new GreaterThanEqualFilter<>(factorScore)) .andFromScore(new LessThanEqualFilter<>(factorScore))
.andToScore(new LessThanEqualFilter<>(factorScore)) .andToScore(new GreaterThanEqualFilter<>(factorScore))
.search(objTran); .search(objTran);
int score = result.getColorCode().getWeightage();
int score = result != null ? result.getColorCode().getWeightage() : 0;
System.out.println("score :: " + score);
// TODO: calculate normalised score based on importance // TODO: calculate normalised score based on importance
} }
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package performa.utils;
import oneit.objstore.BaseBusinessClass;
import oneit.objstore.ObjectTransaction;
import oneit.objstore.rdbms.filters.ILikeFilter;
import oneit.servlets.jsp.ORMTextSearcher;
import performa.orm.Level;
/**
*
* @author nilu
*/
public class LevelSearcher implements ORMTextSearcher
{
@Override
public BaseBusinessClass[] search(ObjectTransaction tx, String searchTerm)
{
return Level.SearchByAll().andLevelDescription(new ILikeFilter(searchTerm, "%", "%")).search(tx);
}
}
\ No newline at end of file
...@@ -6,5 +6,5 @@ ...@@ -6,5 +6,5 @@
<INHERITS factory="Named" nodename="CoreORMAdmin"/> <INHERITS factory="Named" nodename="CoreORMAdmin"/>
<FORM name="*.testAnalysis" factory="Participant" class="performa.form.TestAnalysisFP"/> <FORM name="*.testAnalysis" factory="Participant" class="performa.form.TestAnalysisFP"/>
</NODE> </NODE>
</OBJECTS> </OBJECTS>
\ No newline at end of file
...@@ -13,4 +13,8 @@ ...@@ -13,4 +13,8 @@
</NODE> </NODE>
<NODE name="StorageMappings::Performa">
<MAP code="TestInput" class="performa.orm.TestInput"/>
</NODE>
</OBJECTS> </OBJECTS>
\ No newline at end of file
...@@ -25,7 +25,14 @@ ...@@ -25,7 +25,14 @@
<%@include file="/editor/header.jsp"%> <%@include file="/editor/header.jsp"%>
<oneit:layout_total widths="<%= new double[] {1, 4, 7} %>" skin="bootstrap"> <style>
.ui-autocomplete-input
{
width: 80%;
}
</style>
<oneit:layout_total widths="<%= new double[] {1, 4, 1, 4, 2} %>" skin="bootstrap">
<oneit:skin tagName="layout_row"> <oneit:skin tagName="layout_row">
<oneit:layout_label width="1"> <oneit:layout_label width="1">
<strong style="line-height: 30px">CSV : </strong> <strong style="line-height: 30px">CSV : </strong>
...@@ -33,8 +40,14 @@ ...@@ -33,8 +40,14 @@
<oneit:layout_field width="1"> <oneit:layout_field width="1">
<oneit:ormInput obj="<%= testInput %>" attributeName="CSV" type="file" class="form-control" required="required" style="padding:4px;" accept=".csv"/> <oneit:ormInput obj="<%= testInput %>" attributeName="CSV" type="file" class="form-control" required="required" style="padding:4px;" accept=".csv"/>
</oneit:layout_field> </oneit:layout_field>
<oneit:layout_label width="1">
<strong style="line-height: 30px">Level : </strong>
</oneit:layout_label>
<oneit:layout_field width="1">
<tagfile:ormsingleasso_autocomplete obj="<%= testInput %>" assocName="Level" searcher="<%= new LevelSearcher() %>"/>
</oneit:layout_field>
<oneit:layout_field width="1"> <oneit:layout_field width="1">
<oneit:button value="Import CSV" name="importCSV" cssClass="btn btn-primary" requestAttribs='<%= CollectionUtils.EMPTY_MAP %>'/> <oneit:button value="Import CSV" name="testAnalysis" cssClass="btn btn-primary" requestAttribs='<%= CollectionUtils.EMPTY_MAP %>'/>
</oneit:layout_field> </oneit:layout_field>
</oneit:skin> </oneit:skin>
</oneit:layout_total> </oneit:layout_total>
......
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