use of org.asqatasun.entity.statistics.ThemeStatistics in project Asqatasun by Asqatasun.
the class ThemeStatisticsDAOImpl method findThemeStatisticsByWebResource.
/**
* {@inheritDoc}
* */
@Override
public ThemeStatistics findThemeStatisticsByWebResource(Theme theme, WebResourceStatistics wrStats) {
StringBuilder builder = new StringBuilder();
builder.append(" SELECT ts FROM ");
builder.append(getEntityClass().getName());
builder.append(" as ts");
builder.append(" WHERE ");
builder.append(" ts.webResourceStatistics= :wrStats").append(" and ");
builder.append(" ts.theme= :theme");
Query query = entityManager.createQuery(builder.toString());
query.setParameter("wrStats", wrStats);
query.setParameter("theme", theme);
try {
return (ThemeStatistics) query.getSingleResult();
} catch (NoResultException e) {
return null;
}
}
use of org.asqatasun.entity.statistics.ThemeStatistics in project Asqatasun by Asqatasun.
the class AnalyserImpl method computeAuditStatisticsFromPrList.
/**
* To avoid multiple count requests to the db, the audits statistics are
* computing by iterating through the ProcessResult list. The criterion
* statistics and the theme statistics are collected on the fly while
* parsing the collection of ProcessResult
*
* @param wrStatistics
* @return
*/
private WebResourceStatistics computeAuditStatisticsFromPrList(WebResourceStatistics wrStatistics) {
int nbOfPassed = 0;
int nbOfFailed = 0;
int nbOfNmi = 0;
int nbOfNa = 0;
int nbOfDetected = 0;
int nbOfSuspected = 0;
int nbOfNt = 0;
for (ProcessResult pr : netResultList) {
TestSolution prResult = (TestSolution) pr.getValue();
switch(prResult) {
case PASSED:
nbOfPassed++;
break;
case FAILED:
nbOfFailed++;
break;
case NOT_APPLICABLE:
nbOfNa++;
break;
case NEED_MORE_INFO:
case DETECTED:
case SUSPECTED_FAILED:
case SUSPECTED_PASSED:
nbOfNmi++;
break;
case NOT_TESTED:
nbOfNt++;
break;
}
addResultToCriterionCounterMap(prResult, pr.getTest().getCriterion());
addResultToThemeCounterMap(prResult, pr.getTest().getCriterion().getTheme());
}
// code couldn't have been adapted, all theses values are set to -1
if (nbOfFailed + nbOfNa + nbOfNmi + nbOfPassed + nbOfDetected + nbOfSuspected == 0) {
nbOfFailed = nbOfNa = nbOfNmi = nbOfPassed = nbOfSuspected = nbOfDetected = -1;
}
wrStatistics.setNbOfFailed(nbOfFailed);
wrStatistics.setNbOfInvalidTest(nbOfFailed);
wrStatistics.setNbOfPassed(nbOfPassed);
wrStatistics.setNbOfNmi(nbOfNmi);
wrStatistics.setNbOfNa(nbOfNa);
wrStatistics.setNbOfDetected(nbOfDetected);
wrStatistics.setNbOfSuspected(nbOfSuspected);
wrStatistics.setNbOfNotTested(nbOfNt);
setWeightedResult(wrStatistics);
// criterionStatistics to the current webResourceStatistics
for (CriterionStatistics cs : csMap.values()) {
computeCriterionResult(cs);
wrStatistics.addCriterionStatistics(cs);
}
// Link each themeStatistics to the current webResourceStatistics
for (ThemeStatistics ts : tsMap.values()) {
wrStatistics.addThemeStatistics(ts);
}
wrStatistics.setAudit(audit);
return wrStatistics;
}
use of org.asqatasun.entity.statistics.ThemeStatistics in project Asqatasun by Asqatasun.
the class AnalyserImpl method addResultToThemeCounterMap.
/**
*
* @param testSolution
* @param criterion
*/
private void addResultToThemeCounterMap(TestSolution testSolution, Theme theme) {
if (tsMap == null) {
tsMap = new HashMap();
}
if (tsMap.containsKey(theme)) {
ThemeStatistics ts = tsMap.get(theme);
incrementThemeCounterFromTestSolution(ts, testSolution);
} else {
ThemeStatistics ts = themeStatisticsDataService.create();
ts.setTheme(theme);
incrementThemeCounterFromTestSolution(ts, testSolution);
tsMap.put(theme, ts);
}
}
use of org.asqatasun.entity.statistics.ThemeStatistics in project Asqatasun by Asqatasun.
the class AnalyserImpl method computeThemeStatisticsFromDb.
/**
*
* @param wrStatistics
* @return
*/
private WebResourceStatistics computeThemeStatisticsFromDb(WebResourceStatistics wrStatistics) {
for (Theme theme : themeMap.keySet()) {
ThemeStatistics themeStatistics = themeStatisticsDataService.create();
themeStatistics.setTheme(theme);
int nbOfFailed = themeStatisticsDataService.getResultCountByResultTypeAndTheme(webResource, TestSolution.FAILED, theme).intValue();
themeStatistics.setNbOfFailed(nbOfFailed);
int nbOfPassed = themeStatisticsDataService.getResultCountByResultTypeAndTheme(webResource, TestSolution.PASSED, theme).intValue();
themeStatistics.setNbOfPassed(nbOfPassed);
int nbOfNa = themeStatisticsDataService.getResultCountByResultTypeAndTheme(webResource, TestSolution.NOT_APPLICABLE, theme).intValue();
themeStatistics.setNbOfNa(nbOfNa);
int nbOfNmi = themeStatisticsDataService.getResultCountByResultTypeAndTheme(webResource, TestSolution.NEED_MORE_INFO, theme).intValue();
nbOfNmi += themeStatisticsDataService.getResultCountByResultTypeAndTheme(webResource, TestSolution.SUSPECTED_FAILED, theme).intValue();
nbOfNmi += themeStatisticsDataService.getResultCountByResultTypeAndTheme(webResource, TestSolution.SUSPECTED_PASSED, theme).intValue();
themeStatistics.setNbOfNmi(nbOfNmi);
int themeTestListSize = themeMap.get(theme);
themeStatistics.setNbOfNotTested(themeTestListSize * nbOfWr - nbOfFailed - nbOfNa - nbOfNmi - nbOfPassed);
wrStatistics.addThemeStatistics(themeStatistics);
}
return wrStatistics;
}
use of org.asqatasun.entity.statistics.ThemeStatistics in project Asqatasun by Asqatasun.
the class WebResourceStatisticsDataServiceImpl method createWebResourceStatisticsForManualAudit.
@Override
public WebResourceStatistics createWebResourceStatisticsForManualAudit(Audit audit, WebResource webResource, List<ProcessResult> netResultList) {
boolean isNewWebRs = false;
WebResourceStatistics wrStats = ((WebResourceStatisticsDAO) entityDao).findWebResourceStatisticsByWebResource(webResource, true);
if (wrStats == null) {
wrStats = this.create();
isNewWebRs = true;
}
Map<Criterion, CriterionStatistics> csMap = new HashMap<>();
Map<Theme, ThemeStatistics> tsMap = new HashMap<>();
// Map<Theme, List<ProcessResult>> mapProcessResultBytheme = new HashMap<Theme, List<ProcessResult>>();
int nbOfPassed = 0;
int nbOfFailed = 0;
int nbOfNmi = 0;
int nbOfNa = 0;
int nbOfDetected = 0;
int nbOfSuspected = 0;
int nbOfNt = 0;
for (ProcessResult pr : netResultList) {
// l'audit est manual
if (pr.getManualValue() != null) {
TestSolution prResult = (TestSolution) pr.getManualValue();
switch(prResult) {
case PASSED:
nbOfPassed++;
break;
case FAILED:
nbOfFailed++;
break;
case NOT_APPLICABLE:
nbOfNa++;
break;
case NEED_MORE_INFO:
case DETECTED:
case SUSPECTED_FAILED:
case SUSPECTED_PASSED:
nbOfNmi++;
break;
case NOT_TESTED:
nbOfNt++;
break;
}
addResultToCriterionCounterMap(prResult, pr.getTest().getCriterion(), wrStats, csMap);
addResultToThemeCounterMap(prResult, pr.getTest().getCriterion().getTheme(), wrStats, tsMap);
} else {
addResultToCriterionCounterMap(TestSolution.NOT_TESTED, pr.getTest().getCriterion(), wrStats, csMap);
addResultToThemeCounterMap(TestSolution.NOT_TESTED, pr.getTest().getCriterion().getTheme(), wrStats, tsMap);
nbOfNt++;
}
}
wrStats.setNbOfFailed(wrStats.getNbOfFailed() + nbOfFailed);
wrStats.setNbOfInvalidTest(wrStats.getNbOfInvalidTest() + nbOfFailed);
wrStats.setNbOfPassed(wrStats.getNbOfPassed() + nbOfPassed);
wrStats.setNbOfNmi(wrStats.getNbOfNmi() + nbOfNmi);
wrStats.setNbOfNa(wrStats.getNbOfNa() + nbOfNa);
wrStats.setNbOfDetected(wrStats.getNbOfDetected() + nbOfDetected);
wrStats.setNbOfSuspected(wrStats.getNbOfSuspected() + nbOfSuspected);
wrStats.setNbOfNotTested(wrStats.getNbOfNotTested() + nbOfNt);
setWeightedResult(wrStats, webResource);
wrStats.setHttpStatusCode(getHttpStatusCodeByWebResource(webResource.getId()));
wrStats = computeMark(wrStats);
wrStats = computeRawMark(wrStats);
wrStats = computeNumberOfFailedOccurrences(wrStats, webResource, true);
wrStats.setAudit(audit);
wrStats.setWebResource(webResource);
wrStats.setIsManualAuditStatistics(1);
// criterionStatistics to the current webResourceStatistics
if (isNewWebRs) {
for (CriterionStatistics cs : csMap.values()) {
computeCriterionResult(cs);
wrStats.addCriterionStatistics(cs);
}
// Link each themeStatistics to the current webResourceStatistics
for (ThemeStatistics ts : tsMap.values()) {
wrStats.addThemeStatistics(ts);
}
} else {
//recuperer les Crtiterion à partir de wrstat et id_criterion pour MAJ
for (CriterionStatistics css : csMap.values()) {
CriterionStatistics criterionStatisticsFromMap = csMap.get(css.getCriterion());
CriterionStatistics criterionStatisticsDb = criterionStatisticsDAO.findCriterionStatisticsByWebResource(css.getCriterion(), wrStats);
if (criterionStatisticsDb == null) {
criterionStatisticsDb = criterionStatisticsDataService.create();
criterionStatisticsDb.setWebResourceStatistics(wrStats);
criterionStatisticsDb.setCriterion(css.getCriterion());
}
populateCriterionStatistics(criterionStatisticsDb, criterionStatisticsFromMap);
computeCriterionResult(criterionStatisticsDb);
criterionStatisticsDAO.saveOrUpdate(criterionStatisticsDb);
}
for (ThemeStatistics ts : tsMap.values()) {
ThemeStatistics themeStatisticsFromMap = tsMap.get(ts.getTheme());
ThemeStatistics themeStatisticsDb = themeStatisticsDAO.findThemeStatisticsByWebResource(ts.getTheme(), wrStats);
if (themeStatisticsDb == null) {
themeStatisticsDb = themeStatisticsDataService.create();
themeStatisticsDb.setWebResourceStatistics(wrStats);
themeStatisticsDb.setTheme(ts.getTheme());
}
populateThemeStatistics(themeStatisticsDb, themeStatisticsFromMap);
themeStatisticsDAO.saveOrUpdate(themeStatisticsDb);
}
}
this.saveOrUpdate(wrStats);
return wrStats;
}
Aggregations