public static Rating valueOf(int index) { return stream(Rating.values()) .filter(r -> r.getIndex() == index) .findFirst() .orElseThrow(() -> new IllegalArgumentException(format("Unknown value '%s'", index))); }
void setLeakValue(ComponentDto component, String metricKey, Rating variation) { setLeakValue(component, metricKey, (double) variation.getIndex()); }
void setValue(ComponentDto component, String metricKey, Rating value) { changeCell(component, metricKey, m -> { Double initialValue = m.getValue(); if (initialValue != null && Double.compare(initialValue, (double) value.getIndex()) == 0) { return false; } m.setData(value.name()); m.setValue((double) value.getIndex()); Double initialVariation = m.getVariation(); if (initialValue != null && initialVariation != null) { double leakInitialValue = initialValue - initialVariation; m.setVariation(value.getIndex() - leakInitialValue); } return true; }); }
private void computeAndSaveMeasures(Component component, Path<Counter> path) { if (!periodHolder.hasPeriod()) { return; } initRatingsToA(path); processIssues(component, path); path.current().newRatingValueByMetric.entrySet() .stream() .filter(entry -> entry.getValue().isSet()) .forEach( entry -> measureRepository.add( component, metricsByKey.get(entry.getKey()), newMeasureBuilder().setVariation(entry.getValue().getValue().getIndex()).createNoValue())); addToParent(path); }
@Test public void verify_value_comparison_for_rating_metric() { Predicate<Measure> underTest = BestValueOptimization.from(createMetric(Metric.MetricType.RATING, A.getIndex()), FILE_COMPONENT); assertThat(underTest.test(newMeasureBuilder().create(A.getIndex()))).isTrue(); assertThat(underTest.test(newMeasureBuilder().setVariation((double) A.getIndex()).createNoValue())).isTrue(); assertThat(underTest.test(newMeasureBuilder().create(B.getIndex()))).isFalse(); assertThat(underTest.test(newMeasureBuilder().setVariation((double) B.getIndex()).createNoValue())).isFalse(); }
private void computeAndSaveMeasures(Component component, Path<Counter> path) { processIssues(component, path); path.current().ratingValueByMetric.forEach((key, value) -> { Rating rating = value.getValue(); measureRepository.add(component, metricsByKey.get(key), newMeasureBuilder().create(rating.getIndex(), rating.name())); }); if (!path.isRoot()) { path.parent().add(path.current()); } }
private void addMaintainabilityRatingMeasure(Component component, double density) { Rating rating = ratingSettings.getDebtRatingGrid().getRatingForDensity(density); measureRepository.add(component, maintainabilityRatingMetric, newMeasureBuilder().create(rating.getIndex(), rating.name())); }
private static Measure createRatingMeasure(Rating rating) { return newMeasureBuilder().create(rating.getIndex(), rating.name()); }
private static Measure createMaintainabilityRatingMeasure(Rating rating) { return newMeasureBuilder().create(rating.getIndex(), rating.name()); }
private void verifyAddedRawMeasureOnLeakPeriod(int componentRef, String metricKey, Rating rating) { MeasureAssert.assertThat(measureRepository.getAddedRawMeasure(componentRef, metricKey)) .hasVariation(rating.getIndex()); }
private void assertNewMaintainability(int componentRef, Rating expectedVariation) { assertThat(measureRepository.getAddedRawMeasure(componentRef, NEW_MAINTAINABILITY_RATING_KEY)).hasVariation(expectedVariation.getIndex()); }
private void assertThatRatingMeasureHasLeakValue(ComponentDto component, Rating expectedValue) { LiveMeasureDto measure = db.getDbClient().liveMeasureDao().selectMeasure(db.getSession(), component.uuid(), ratingMetric.getKey()).get(); assertThat(measure.getComponentUuid()).isEqualTo(component.uuid()); assertThat(measure.getProjectUuid()).isEqualTo(component.projectUuid()); assertThat(measure.getMetricId()).isEqualTo(ratingMetric.getId()); assertThat(measure.getVariation()).isEqualTo((double) expectedValue.getIndex()); }
private LiveMeasureDto assertThatRatingMeasureHasValue(ComponentDto component, Rating expectedRating) { LiveMeasureDto measure = db.getDbClient().liveMeasureDao().selectMeasure(db.getSession(), component.uuid(), ratingMetric.getKey()).get(); assertThat(measure.getComponentUuid()).isEqualTo(component.uuid()); assertThat(measure.getProjectUuid()).isEqualTo(component.projectUuid()); assertThat(measure.getMetricId()).isEqualTo(ratingMetric.getId()); assertThat(measure.getValue()).isEqualTo(expectedRating.getIndex()); assertThat(measure.getDataAsString()).isEqualTo(expectedRating.name()); return measure; }
private void verifyAddedRawMeasure(int componentRef, String metricKey, Rating rating) { assertThat(toEntries(measureRepository.getAddedRawMeasures(componentRef))).contains(entryOf(metricKey, newMeasureBuilder().create(rating.getIndex(), rating.name()))); }
private void verifyAddedRawMeasure(int componentRef, String metricKey, Rating rating) { assertThat(toEntries(measureRepository.getAddedRawMeasures(componentRef))).contains(entryOf(metricKey, newMeasureBuilder().create(rating.getIndex(), rating.name()))); }
@Test public void variation_is_refreshed_when_rating_value_is_changed() { markProjectAsAnalyzed(project); // value is: // B on last analysis // D on beginning of leak period --> variation is -2 db.measures().insertLiveMeasure(project, ratingMetric, m -> m.setValue((double) Rating.B.getIndex()).setData("B").setVariation(-2.0)); // new value is C, so variation on leak period is D to C = -1 List<QGChangeEvent> result = run(file1, newRatingConstantFormula(Rating.C)); LiveMeasureDto measure = assertThatRatingMeasureHasValue(project, Rating.C); assertThat(measure.getVariation()).isEqualTo(-1.0); assertThatProjectChanged(result, project); }
@Test public void variation_does_not_change_if_rating_value_does_not_change() { markProjectAsAnalyzed(project); // value is: // B on last analysis // D on beginning of leak period --> variation is -2 db.measures().insertLiveMeasure(project, ratingMetric, m -> m.setValue((double) Rating.B.getIndex()).setData("B").setVariation(-2.0)); // new value is still B, so variation on leak period is still -2 List<QGChangeEvent> result = run(file1, newRatingConstantFormula(Rating.B)); LiveMeasureDto measure = assertThatRatingMeasureHasValue(project, Rating.B); assertThat(measure.getVariation()).isEqualTo(-2.0); assertThatProjectChanged(result, project); }
private void computeAndSaveNewDebtRatioMeasure(Component component, Path<Counter> path) { if (!newLinesRepository.newLinesAvailable()) { return; } double density = computeDensity(path.current()); double newDebtRatio = 100.0 * density; double newMaintainability = ratingSettings.getDebtRatingGrid().getRatingForDensity(density).getIndex(); long newDevelopmentCost = path.current().getDevCost().getValue(); measureRepository.add(component, this.newDevelopmentCostMetric, newMeasureBuilder().setVariation(newDevelopmentCost).createNoValue()); measureRepository.add(component, this.newDebtRatioMetric, newMeasureBuilder().setVariation(newDebtRatio).createNoValue()); measureRepository.add(component, this.newMaintainabilityRatingMetric, newMeasureBuilder().setVariation(newMaintainability).createNoValue()); }
@Test @UseDataProvider("ratings") public void rating_measure(Rating rating, Color color) { ComponentDto project = db.components().insertPublicProject(); userSession.registerComponents(project); MetricDto metric = db.measures().insertMetric(m -> m.setKey(SQALE_RATING_KEY).setValueType(RATING.name())); db.measures().insertLiveMeasure(project, metric, m -> m.setValue((double) rating.getIndex()).setData(rating.name())); TestResponse response = ws.newRequest() .setParam("project", project.getKey()) .setParam("metric", metric.getKey()) .execute(); checkSvg(response, "maintainability", rating.name(), color); // Second call with If-None-Match must return 304 checkWithIfNoneMatchHeader(project, metric, response); }