KeywordOptimizerUtil { public static StatsEstimate calculateMean(StatsEstimate min, StatsEstimate max) { Money meanAverageCpc = calculateMean(min.getAverageCpc(), max.getAverageCpc()); Double meanAveragePosition = calculateMean(min.getAveragePosition(), max.getAveragePosition()); Double meanClicks = calculateMean(min.getClicksPerDay(), max.getClicksPerDay()); Double meanImpressions = calculateMean(min.getImpressionsPerDay(), max.getImpressionsPerDay()); Double meanCtr = calculateMean(min.getClickThroughRate(), max.getClickThroughRate()); Money meanTotalCost = calculateMean(min.getTotalCost(), max.getTotalCost()); StatsEstimate mean = new StatsEstimate(); if (meanAverageCpc != null) { mean.setAverageCpc(meanAverageCpc); } if (meanAveragePosition != null) { mean.setAveragePosition(meanAveragePosition); } if (meanClicks != null) { mean.setClicksPerDay(meanClicks.floatValue()); } if (meanImpressions != null) { mean.setImpressionsPerDay(meanImpressions.floatValue()); } if (meanCtr != null) { mean.setClickThroughRate(meanCtr); } if (meanTotalCost != null) { mean.setTotalCost(meanTotalCost); } return mean; }  static StatsEstimate calculateMean(StatsEstimate min, StatsEstimate max); static String toString(Keyword keyword); static String toString(StatsEstimate estimate); static Keyword createKeyword(String text, KeywordMatchType matchType); static Money createMoney(long microAmount); static String format(Double nr); static String format(Money money); static String formatCsv(@Nullable Number number); static List<SearchParameter> toSearchParameters(List<Criterion> criteria); static IdeaEstimate toSearchEstimate(Map<AttributeType, Attribute> attributeData);  }
@Test public void testStatsEstimateMean() { Money lowCpc = new Money(); lowCpc.setMicroAmount(1_000_000L); Money lowTotal = new Money(); lowTotal.setMicroAmount(10_000_000L); StatsEstimate lowEstimate = new StatsEstimate(lowCpc, 3.0, 0.01, 1000.0F, 100_000.0F, lowTotal); Money highCpc = new Money(); highCpc.setMicroAmount(9_000_000L); Money highTotal = new Money(); highTotal.setMicroAmount(90_000_000L); StatsEstimate highEstimate = new StatsEstimate(highCpc, 7.0, 0.09, 9000.0F, 900_000.0F, highTotal); StatsEstimate estimate = KeywordOptimizerUtil.calculateMean(lowEstimate, highEstimate); assertEquals( "Expected average CPC", 5_000_000L, estimate.getAverageCpc().getMicroAmount().longValue()); assertEquals("Expected average position", 5.0, estimate.getAveragePosition(), DOUBLE_ERROR); assertEquals("Expected average click rate", 0.05, estimate.getClickThroughRate(), DOUBLE_ERROR); assertEquals("Expected clicks per day", 5000.0F, estimate.getClicksPerDay(), DOUBLE_ERROR); assertEquals("Expected impressions", 500_000.0F, estimate.getImpressionsPerDay(), DOUBLE_ERROR); assertEquals( "Expected total cost", 50_000_000L, estimate.getTotalCost().getMicroAmount().longValue()); }