Skip to content

Commit

Permalink
Merge pull request #134 from q-rapids/develop
Browse files Browse the repository at this point in the history
Release v1.2
  • Loading branch information
alejandravv authored Mar 20, 2020
2 parents 174c782 + 80852fd commit 3199828
Show file tree
Hide file tree
Showing 74 changed files with 2,563 additions and 391 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apply plugin: 'jacoco'
apply plugin: 'org.asciidoctor.convert'

group = 'com.upc.gessi.qrapids'
version = '1.1.1'
version = '1.2'
sourceCompatibility = 1.8

war {
Expand Down Expand Up @@ -78,7 +78,7 @@ dependencies {
compile('org.elasticsearch.client:transport:5.6.3')
compile('org.elasticsearch:elasticsearch:5.6.3')
compile('org.elasticsearch.client:elasticsearch-rest-high-level-client:5.6.3')
compile files('libs/qrapids-qma-elastic-0.16.jar')
compile files('libs/qrapids-qma-elastic-0.18.jar')

//API QR Generator
compile files('libs/qrapids-qr_generator-0.2.jar')
Expand Down
2 changes: 1 addition & 1 deletion docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
= Q-Rapids Dashboard API REST Documentation
v1.1.1, {docdate}
v1.2, {docdate}
:toc: left

:sectnums:
Expand Down
184 changes: 125 additions & 59 deletions docs/asciidoc/index.html

Large diffs are not rendered by default.

Binary file not shown.
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ sonar.projectKey=q-rapids_qrapids-dashboard

sonar.projectName=qrapids-dashboard

sonar.projectVersion=1.1.1
sonar.projectVersion=1.2

sonar.sources=src/main/java
sonar.tests=src/test/java
Expand Down
54 changes: 52 additions & 2 deletions src/main/java/com/upc/gessi/qrapids/QrapidsApplication.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package com.upc.gessi.qrapids;

import com.upc.gessi.qrapids.app.domain.controllers.MetricsController;
import com.upc.gessi.qrapids.app.domain.controllers.QualityFactorsController;
import com.upc.gessi.qrapids.app.domain.controllers.StrategicIndicatorsController;
import com.upc.gessi.qrapids.app.domain.models.MetricCategory;
import com.upc.gessi.qrapids.app.domain.models.QFCategory;
import com.upc.gessi.qrapids.app.domain.models.SICategory;
import com.upc.gessi.qrapids.app.presentation.rest.services.Alerts;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -12,6 +17,11 @@
import org.springframework.context.annotation.Bean;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@SpringBootApplication
public class QrapidsApplication extends SpringBootServletInitializer {

Expand All @@ -26,9 +36,49 @@ public BCryptPasswordEncoder bCryptPasswordEncoder() {
}

public static void main(String[] args) {
// Commented fetch function for avoid automatic add elasticsearch information to local SQL database.

ConfigurableApplicationContext context = SpringApplication.run(QrapidsApplication.class, args);
/*

// Check the categories in the SQL database and if they are empty create the default ones
List<SICategory> siCategoryList = context.getBean(StrategicIndicatorsController.class).getStrategicIndicatorCategories();
List<QFCategory> factorCategoryList = context.getBean(QualityFactorsController.class).getFactorCategories();
List<MetricCategory> metricCategoryList = context.getBean(MetricsController.class).getMetricCategories();
try {
// Declare default categories
List<Map<String, String>> categories = new ArrayList<>();
Map<String,String> cat1 = new HashMap<>();
cat1.put("color", "#00ff00");
cat1.put("name", "Good");
cat1.put("upperThreshold", "100");
categories.add(cat1);
Map<String,String> cat2 = new HashMap<>();
cat2.put("color", "#ff8000");
cat2.put("name", "Normal");
cat2.put("upperThreshold", "67");
categories.add(cat2);
Map<String,String> cat3 = new HashMap<>();
cat3.put("color", "#ff0000");
cat3.put("name", "Bad");
cat3.put("upperThreshold", "33");
categories.add(cat3);

// Save Strategic Indicator categories
if (siCategoryList.size() == 0) {
context.getBean(StrategicIndicatorsController.class).newStrategicIndicatorCategories(categories);
}
// Save Factor categories
if (factorCategoryList.size() == 0){
context.getBean(QualityFactorsController.class).newFactorCategories(categories);
}
// Save Metric categories
if (metricCategoryList.size() == 0) {
context.getBean(MetricsController.class).newMetricCategories(categories);
}
} catch (Exception e) {
Logger logger = LoggerFactory.getLogger(Alerts.class);
logger.error(e.getMessage(), e);
}
/* Commented fetch function for avoid automatically add elasticsearch information to local SQL database.
try {
context.getBean(StrategicIndicatorsController.class).fetchStrategicIndicators();
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public void init() throws Exception {

// Quality Factor
routes.add( new Route( "Quality Factor - Current Chart", "/QualityFactor/CurrentChart") );
routes.add( new Route( "Quality Factor - Current Stacked", "/QualityFactor/CurrentStacked") );
routes.add( new Route( "Quality Factor - Current Table", "/QualityFactor/CurrentTable") );

routes.add( new Route( "Quality Factor - Historic Table", "/QualityFactor/HistoricTable") );
Expand All @@ -62,7 +63,9 @@ public void init() throws Exception {

// Detailed Strategic Indicators
routes.add( new Route( "Detailed Strategic Indicators - Current Chart", "/DetailedStrategicIndicators/CurrentChart") );
routes.add( new Route( "Detailed Strategic Indicators - Current Stacked", "/DetailedStrategicIndicators/CurrentStacked") );
routes.add( new Route( "Detailed Strategic Indicators - Current Table", "/DetailedStrategicIndicators/CurrentTable") );

routes.add( new Route( "Detailed Strategic Indicators - Historic Table", "/DetailedStrategicIndicators/HistoricTable") );
routes.add( new Route( "Detailed Strategic Indicators - Historic Chart", "/DetailedStrategicIndicators/HistoricChart") );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,24 @@ public List<DTOSIAssessment> dtoAssessmentSItoDTOSIAssessment(List<DTOCategorySI
}
return categories;
}

public float assesSI_weighted(List<Float> factorsAssessment, List<Float> weights) {
try {
float total = 0.f;
float result =0.f;

for (int i = 0; i < factorsAssessment.size(); i++) {
total += ((weights.get(i)/100)*factorsAssessment.get(i));
}
if (total>0)
result = total/1; // sum of weights always is 1 = 100%

return result;

} catch (Exception e) {
Logger logger = LoggerFactory.getLogger(AssesSI.class);
logger.error(e.getMessage(), e);
return 0.f;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ private void getAndBuildDTOStrategicIndicatorEvaluation(List<DTOStrategicIndicat
si.getName(),
si.getDescription(),
Pair.of(value, strategicIndicatorsController.getLabel(value)),
"",
strategicIndicatorsController.getCategories(),
l.getKey(), "Dashboard Assessment",
si.getId(),
Expand All @@ -604,6 +605,7 @@ private void getAndBuildDTOStrategicIndicatorEvaluationWithBayesianNetwork(List<
si.getName(),
si.getDescription(),
Pair.of(value, strategicIndicatorsController.getLabel(value)),
"",
assessment, m.getKey(),
"Dashboard Assessment",
si.getId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
import DTOs.Relations.SourceRelationDTO;
import DTOs.Relations.TargetRelationDTO;
import com.upc.gessi.qrapids.app.config.QMAConnection;
import com.upc.gessi.qrapids.app.domain.controllers.QualityFactorsController;
import com.upc.gessi.qrapids.app.domain.controllers.StrategicIndicatorsController;
import com.upc.gessi.qrapids.app.domain.exceptions.CategoriesException;
import com.upc.gessi.qrapids.app.presentation.rest.dto.DTOMetric;
import com.upc.gessi.qrapids.app.presentation.rest.dto.DTOQualityFactor;
import com.upc.gessi.qrapids.app.presentation.rest.dto.DTOStrategicIndicatorEvaluation;
import com.upc.gessi.qrapids.app.presentation.rest.dto.relations.DTORelationsFactor;
import com.upc.gessi.qrapids.app.presentation.rest.dto.relations.DTORelationsMetric;
import com.upc.gessi.qrapids.app.presentation.rest.dto.relations.DTORelationsSI;
Expand All @@ -29,6 +34,9 @@ public class QMARelations {
@Autowired
private StrategicIndicatorsController strategicIndicatorsController;

@Autowired
private QualityFactorsController qualityFactorsController;

private static final String SI_TYPE = "strategic_indicators";
private static final String FACTORS_TYPE = "factors";
private static final String METRICS_TYPE = "metrics";
Expand Down Expand Up @@ -60,18 +68,21 @@ private double[] convertFloatListToDoubleArray(List<Float> floatList) {
return doubleArray;
}

public List<DTORelationsSI> getRelations (String prj, LocalDate date) throws IOException {
public List<DTORelationsSI> getRelations (String prj, LocalDate date) throws IOException, CategoriesException, ArithmeticException {
qmacon.initConnexion();
List<RelationDTO> relationDTOS;
// get relations from elasticsearch
if (date == null)
relationDTOS = Relations.getRelations(prj);
else
relationDTOS = Relations.getRelations(prj, date);

return RelationDTOToDTORelationSI(relationDTOS);
// get current evaluations for SI and Quality Factors
List<DTOStrategicIndicatorEvaluation> siEval = strategicIndicatorsController.getAllStrategicIndicatorsCurrentEvaluation(prj);
List<DTOQualityFactor> qfEval = qualityFactorsController.getAllFactorsWithMetricsCurrentEvaluation(prj);
return RelationDTOToDTORelationSI(relationDTOS, siEval, qfEval);
}

private List<DTORelationsSI> RelationDTOToDTORelationSI (List<RelationDTO> relationDTOS) {
private List<DTORelationsSI> RelationDTOToDTORelationSI (List<RelationDTO> relationDTOS, List<DTOStrategicIndicatorEvaluation> siEval, List<DTOQualityFactor> qfEval) throws ArithmeticException {
Map<String, DTORelationsSI> strategicIndicatorsMap = new HashMap<>();
Map<String, DTORelationsFactor> factorsMap = new HashMap<>();
Map<String, DTORelationsMetric> metricsMap = new HashMap<>();
Expand All @@ -81,22 +92,60 @@ private List<DTORelationsSI> RelationDTOToDTORelationSI (List<RelationDTO> relat
SourceRelationDTO source = relation.getSource();
TargetRelationDTO target = relation.getTarget();
if (target.getType().equals(FACTORS_TYPE) && source.getType().equals(METRICS_TYPE)) {
buildFactorMetricRelation(factorsMap, metricsMap, weight, source, target);
buildFactorMetricRelation(factorsMap, metricsMap, weight, source, target, qfEval);
}
else if (target.getType().equals(SI_TYPE) && source.getType().equals(FACTORS_TYPE)) {
buildSIFactorRelation(strategicIndicatorsMap, factorsMap, weight, source, target);
buildSIFactorRelation(strategicIndicatorsMap, factorsMap, weight, source, target, siEval, qfEval);
}
}

return new ArrayList<>(strategicIndicatorsMap.values());
List<DTORelationsSI> result = new ArrayList<>(strategicIndicatorsMap.values());
for (DTORelationsSI si : result) {
for (DTORelationsFactor f : si.getFactors()) {
// Define weight & weightedValue for factors legacy cases (0 & 1)
float w = Float.parseFloat(f.getWeight());
if (w == 0f || w == 1f) {
float nFactors = si.getFactors().size();
w = 1/nFactors;
f.setWeight(String.valueOf(w));
f.setWeightedValue(String.valueOf(Float.parseFloat(f.getAssessmentValue()) * Float.parseFloat(f.getWeight())));
} else if (w == -1) { // Define weightedValue for factor with BN case (-1)
f.setWeightedValue(String.valueOf(Float.parseFloat(f.getAssessmentValue()) * 1/si.getFactors().size()));
}
float sum = sumMetricsWeights(f.getMetrics());
for (DTORelationsMetric m : f.getMetrics()) {
// Define weight percentage & weightedValue for metrics
if (sum != 0) {
m.setWeight(String.valueOf((Float.parseFloat(m.getWeight())/sum)));
m.setWeightedValue(String.valueOf(Float.parseFloat(m.getAssessmentValue())*Float.parseFloat(m.getWeight())));
} else {
throw new ArithmeticException("/ by 0: sum of metrics weights is zero.");
}
}
}
}
return result;
}

private void buildSIFactorRelation(Map<String, DTORelationsSI> strategicIndicatorsMap, Map<String, DTORelationsFactor> factorsMap, String weight, SourceRelationDTO source, TargetRelationDTO target) {
private float sumMetricsWeights(List<DTORelationsMetric> metrics) {
float totalWeight = 0f;
for (int i = 0; i < metrics.size(); i++){
totalWeight += Float.parseFloat(metrics.get(i).getWeight());
}
return totalWeight;
}

private void buildSIFactorRelation(Map<String, DTORelationsSI> strategicIndicatorsMap, Map<String, DTORelationsFactor> factorsMap, String weight, SourceRelationDTO source, TargetRelationDTO target, List<DTOStrategicIndicatorEvaluation> siEval, List<DTOQualityFactor> qfEval) {
DTORelationsSI strategicIndicator;
DTOStrategicIndicatorEvaluation thisSI = siEval.stream()
.filter(si -> target.getID().equals(si.getId()))
.findAny()
.orElse(null);
if (strategicIndicatorsMap.containsKey(target.getID())) {
strategicIndicator = strategicIndicatorsMap.get(target.getID());
} else {
strategicIndicator = new DTORelationsSI(target.getID());
strategicIndicator.setName(thisSI.getName());
strategicIndicatorsMap.put(target.getID(), strategicIndicator);
}
strategicIndicator.setValue(target.getValue());
Expand All @@ -106,8 +155,7 @@ private void buildSIFactorRelation(Map<String, DTORelationsSI> strategicIndicato
String valueDescription = StrategicIndicatorsController.buildDescriptiveLabelAndValue(Pair.of(value, label));
strategicIndicator.setValueDescription(valueDescription);
strategicIndicator.setColor(strategicIndicatorsController.getColorFromLabel(label));
}
catch (NumberFormatException nfe) {
} catch (NumberFormatException nfe) {
String label = strategicIndicator.getValue();
Float value = strategicIndicatorsController.getValueFromLabel(label);
String valueDescription = StrategicIndicatorsController.buildDescriptiveLabelAndValue(Pair.of(value, label));
Expand All @@ -116,36 +164,61 @@ private void buildSIFactorRelation(Map<String, DTORelationsSI> strategicIndicato
}

DTORelationsFactor factor;
DTOQualityFactor thisFactor = qfEval.stream()
.filter(qf -> source.getID().equals(qf.getId()))
.findAny()
.orElse(null);
if (factorsMap.containsKey(source.getID())) {
factor = factorsMap.get(source.getID());
} else {
factor = new DTORelationsFactor(source.getID());
factor.setName(thisFactor.getName());
factorsMap.put(source.getID(), factor);
}
factor.setWeight(weight);
factor.setValue(source.getValue());
// Special cases
if (Float.parseFloat(weight) == 0f || Float.parseFloat(weight) == 1f || Float.parseFloat(weight) == -1f) {
factor.setWeight(weight);
factor.setWeightedValue(source.getValue());
factor.setAssessmentValue(source.getValue());
} else {
factor.setWeight(weight);
factor.setWeightedValue(source.getValue());
factor.setAssessmentValue(String.valueOf(Float.parseFloat(source.getValue())/Float.parseFloat(weight)));
}

strategicIndicator.setFactor(new DTORelationsFactor(factor));
}

private void buildFactorMetricRelation(Map<String, DTORelationsFactor> factorsMap, Map<String, DTORelationsMetric> metricsMap, String weight, SourceRelationDTO source, TargetRelationDTO target) {
private void buildFactorMetricRelation(Map<String, DTORelationsFactor> factorsMap, Map<String, DTORelationsMetric> metricsMap, String weight, SourceRelationDTO source, TargetRelationDTO target, List<DTOQualityFactor> qfEval) {
DTORelationsFactor factor;
DTOQualityFactor thisFactor = qfEval.stream()
.filter(qf -> target.getID().equals(qf.getId()))
.findAny()
.orElse(null);
if (factorsMap.containsKey(target.getID())) {
factor = factorsMap.get(target.getID());
} else {
factor = new DTORelationsFactor(target.getID());
factor.setName(thisFactor.getName());
factorsMap.put(target.getID(), factor);
}

DTORelationsMetric metric;
List<DTOMetric> metrics = thisFactor.getMetrics();
DTOMetric thisMetric = metrics.stream()
.filter(m -> source.getID().equals(m.getId()))
.findAny()
.orElse(null);
if (metricsMap.containsKey(source.getID())) {
metric = metricsMap.get(source.getID());
} else {
metric = new DTORelationsMetric(source.getID());
metric.setName(thisMetric.getName());
metricsMap.put(source.getID(), metric);
}
metric.setWeight(weight);
metric.setValue(source.getValue());
metric.setWeightedValue(source.getValue());
metric.setAssessmentValue(thisMetric.getValue().toString());

factor.setMetric(new DTORelationsMetric(metric));
}
Expand Down
Loading

0 comments on commit 3199828

Please sign in to comment.