Created
February 15, 2012 00:05
-
-
Save devth/1831851 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def getRecommendedProducts = { | |
| val featureRatings = productFeatureComparison.getFeatureRatings | |
| val compared = productFeatureComparison.getProductComparedRatings | |
| // Loop the products being compared | |
| compared groupBy { case (pid, comparedRatings: ComparedRatings) => | |
| // Run a comparison on all of feature ratings against this compared product. | |
| val groups = featureRatings groupBy { case (p) => | |
| val (key: String, fr: ProductFeatureComparison.FeatureRating) = (p.getKey, p.getValue) | |
| if (comparedRatings.getRatings.containsKey(key)) { | |
| val ratingToCompare: Rating = comparedRatings.getRatings()(key) | |
| // Compare rating and flip the result when orientation is negative | |
| val c = fr.getRating.compareTo(ratingToCompare) * | |
| (if (fr.getPriority().getOrientation() == FeaturePriority.Orientation.NEGATIVE) | |
| -1 else 1) | |
| c match { | |
| case -1 => Worse | |
| case 0 => Similar | |
| case 1 => Better | |
| case _ => "None" | |
| } | |
| } else { | |
| "None" | |
| } | |
| } | |
| // Determine counts | |
| val counts = List(Better, Similar, Worse) map { t => | |
| (t, groups.get(t).map(_.size).getOrElse(0)) } toMap | |
| val total = counts.values.reduce(_+_) | |
| if (debug) { | |
| log.debug("compared " + total + " for " + pid) | |
| log.debug("better count " + counts(Better)) | |
| log.debug("similar count " + counts(Similar)) | |
| log.debug("worse count " + counts(Worse) + "\n") | |
| } | |
| // - If 25% are better and less than 10% are Worse it's "Better". | |
| // - Otherwise it's Similar. | |
| if (counts(Better) > (total * .25) && | |
| counts(Worse) < (total * .1)) { | |
| Better | |
| } else { | |
| Similar | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment