Search in sources :

Example 1 with PercentCompletenessFunctionInput

use of com.linkedin.thirdeye.completeness.checker.PercentCompletenessFunctionInput in project pinot by linkedin.

the class DataCompletenessResource method getPercentCompleteness.

@GET
@Path(value = "/percent-completeness")
@Produces(MediaType.APPLICATION_JSON)
public double getPercentCompleteness(String payload) {
    PercentCompletenessFunctionInput input = PercentCompletenessFunctionInput.fromJson(payload);
    DataCompletenessAlgorithmName algorithm = input.getAlgorithm();
    List<Long> baselineCounts = input.getBaselineCounts();
    Long currentCount = input.getCurrentCount();
    double percentCompleteness = 0;
    double baselineTotalCount = 0;
    if (CollectionUtils.isNotEmpty(baselineCounts)) {
        switch(algorithm) {
            case WO4W_AVERAGE:
            default:
                for (Long baseline : baselineCounts) {
                    baselineTotalCount = baselineTotalCount + baseline;
                }
                baselineTotalCount = baselineTotalCount / baselineCounts.size();
                break;
        }
    }
    if (baselineTotalCount != 0) {
        percentCompleteness = new Double(currentCount * 100) / baselineTotalCount;
    }
    if (baselineTotalCount == 0 && currentCount != 0) {
        percentCompleteness = 100;
    }
    return percentCompleteness;
}
Also used : PercentCompletenessFunctionInput(com.linkedin.thirdeye.completeness.checker.PercentCompletenessFunctionInput) DataCompletenessAlgorithmName(com.linkedin.thirdeye.completeness.checker.DataCompletenessConstants.DataCompletenessAlgorithmName) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

DataCompletenessAlgorithmName (com.linkedin.thirdeye.completeness.checker.DataCompletenessConstants.DataCompletenessAlgorithmName)1 PercentCompletenessFunctionInput (com.linkedin.thirdeye.completeness.checker.PercentCompletenessFunctionInput)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1