@Override
  public Measure calculate(FormulaData data, FormulaContext context) {

    Double criticalCount = MeasureUtils.getValue(data.getMeasure(FortifyMetrics.CFPO), null);
    Double highCount = MeasureUtils.getValue(data.getMeasure(FortifyMetrics.HFPO), null);
    Double mediumCount = MeasureUtils.getValue(data.getMeasure(FortifyMetrics.MFPO), null);
    Double lowCount = MeasureUtils.getValue(data.getMeasure(FortifyMetrics.LFPO), null);

    if (criticalCount != null && highCount != null && mediumCount != null && lowCount != null) {
      Double securityRatingLevel;
      if (criticalCount > 0) {
        securityRatingLevel = SecurityRatingFormula.BLOCKER_SECURITY_RATING_LEVEL;
      } else if (highCount > 0) {
        securityRatingLevel = SecurityRatingFormula.CRITICAL_SECURITY_RATING_LEVEL;
      } else if (mediumCount > 0) {
        securityRatingLevel = SecurityRatingFormula.MAJOR_SECURITY_RATING_LEVEL;
      } else if (lowCount > 0) {
        securityRatingLevel = SecurityRatingFormula.MINOR_SECURITY_RATING_LEVEL;
      } else {
        securityRatingLevel = SecurityRatingFormula.DEFAULT_SECURITY_RATING_LEVEL;
      }

      return new Measure(context.getTargetMetric(), securityRatingLevel);
    }
    return null;
  }
  @Override
  public Measure calculate(FormulaData data, FormulaContext context) {
    double sum = 0.0;
    double count = 0.0;
    boolean hasValue = false;

    for (FormulaData child : data.getChildren()) {
      Measure measure = child.getMeasure(context.getTargetMetric());
      Measure weightingMeasure = child.getMeasure(weightingMetric);
      if (MeasureUtils.haveValues(measure, weightingMeasure)) {
        sum += measure.getValue() * weightingMeasure.getValue();
        count += weightingMeasure.getValue();
        hasValue = true;
      }
    }

    if (!hasValue && !zeroIfNoValues) {
      return null;
    }

    double result = (Double.doubleToRawLongBits(count) == 0L) ? 0.0 : (sum / count);
    return new Measure(context.getTargetMetric(), result);
  }