diff --git a/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/MonumentDB.scala b/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/MonumentDB.scala index 8ea84f1a..c7dbfb02 100644 --- a/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/MonumentDB.scala +++ b/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/MonumentDB.scala @@ -5,7 +5,7 @@ import java.time.{ZoneOffset, ZonedDateTime} import org.scalawiki.dto.markup.Table import org.scalawiki.wlx.dto.{AdmDivision, Contest, Monument} import org.scalawiki.wlx.query.MonumentQuery -import org.scalawiki.wlx.stat.PerPlaceStat +import org.scalawiki.wlx.stat.rating.PerPlaceStat class MonumentDB( val contest: Contest, diff --git a/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/dto/Contest.scala b/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/dto/Contest.scala index f039bc38..c49ad5a5 100644 --- a/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/dto/Contest.scala +++ b/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/dto/Contest.scala @@ -8,7 +8,7 @@ import com.typesafe.config.{ ConfigParseOptions, ConfigResolveOptions } -import org.scalawiki.wlx.stat.RateConfig +import org.scalawiki.wlx.stat.rating.RateConfig import scala.util.Try diff --git a/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/StatParams.scala b/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/StatParams.scala index 9b13e166..1d57b13a 100644 --- a/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/StatParams.scala +++ b/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/StatParams.scala @@ -1,5 +1,7 @@ package org.scalawiki.wlx.stat +import org.scalawiki.wlx.stat.rating.RateConfig + import java.time.ZonedDateTime case class StatConfig( @@ -124,7 +126,7 @@ object StatParams { exceptRegions = conf.exceptRegions.getOrElse(Nil), cities = conf.cities.getOrElse(Nil), exceptCities = conf.exceptCities.getOrElse(Nil), - rateConfig = RateConfig(conf), + rateConfig = rating.RateConfig(conf), gallery = conf.gallery.getOrElse(false), fillLists = conf.fillLists.getOrElse(false), wrongIds = conf.wrongIds.getOrElse(false), diff --git a/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/RateRanges.scala b/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/rating/RateRanges.scala similarity index 98% rename from scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/RateRanges.scala rename to scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/rating/RateRanges.scala index 77c49501..c4010d3b 100644 --- a/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/RateRanges.scala +++ b/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/rating/RateRanges.scala @@ -1,4 +1,4 @@ -package org.scalawiki.wlx.stat +package org.scalawiki.wlx.stat.rating import com.typesafe.config.Config diff --git a/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/Rater.scala b/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/rating/Rater.scala similarity index 96% rename from scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/Rater.scala rename to scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/rating/Rater.scala index d91f21c4..c162d22c 100644 --- a/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/Rater.scala +++ b/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/rating/Rater.scala @@ -1,9 +1,10 @@ -package org.scalawiki.wlx.stat +package org.scalawiki.wlx.stat.rating import com.typesafe.config.Config import org.scalawiki.MwBot import org.scalawiki.wlx.ImageDB import org.scalawiki.wlx.stat.reports.RateInputDistribution +import org.scalawiki.wlx.stat.{ContestStat, StatParams} import scala.collection.mutable import scala.util.Try @@ -69,23 +70,23 @@ object Rater { stat.contest.config.map(fromConfig(stat, _)).getOrElse { val config = stat.contest.rateConfig - val raters = Seq(new NumberOfMonuments(stat, config.baseRate)) ++ + val raters = Seq(NumberOfMonuments(stat, config.baseRate)) ++ config.newAuthorObjectRating .map(r => - new NewlyPicturedPerAuthorBonus( + NewlyPicturedPerAuthorBonus( stat, config.newObjectRating.getOrElse(1), r ) ) .orElse( - config.newObjectRating.map(new NewlyPicturedBonus(stat, _)) + config.newObjectRating.map(NewlyPicturedBonus(stat, _)) ) if (raters.tail.isEmpty) { raters.head } else { - new RateSum(stat, raters) + RateSum(stat, raters) } } } @@ -93,14 +94,14 @@ object Rater { def fromConfig(stat: ContestStat, config: Config): Rater = { val rateCfg = config.getConfig(s"rates.${stat.contest.year}") val raters = Seq( - new NumberOfMonuments( + NumberOfMonuments( stat, Try(rateCfg.getDouble("base-rate")).toOption.getOrElse(1) ) ) ++ (if (rateCfg.hasPath("number-of-authors-bonus")) { Seq( - new NumberOfAuthorsBonus( + NumberOfAuthorsBonus( stat, RateRanges(rateCfg.getConfig("number-of-authors-bonus")) ) @@ -108,7 +109,7 @@ object Rater { } else Nil) ++ (if (rateCfg.hasPath("number-of-images-bonus")) { Seq( - new NumberOfImagesInPlaceBonus( + NumberOfImagesInPlaceBonus( stat, RateRanges(rateCfg.getConfig("number-of-images-bonus")) ) @@ -124,7 +125,8 @@ object Rater { } } -case class NumberOfMonuments(stat: ContestStat, baseRate: Double) extends Rater { +case class NumberOfMonuments(stat: ContestStat, baseRate: Double) + extends Rater { val monumentIds = stat.monumentDb.map(_.ids).getOrElse(Set.empty) override def rate(monumentId: String, author: String): Double = { @@ -158,7 +160,7 @@ case class NewlyPicturedBonus(stat: ContestStat, newlyPicturedRate: Double) } case class NewlyPicturedPerAuthorBonus( - val stat: ContestStat, + stat: ContestStat, newlyPicturedRate: Double, newlyPicturedPerAuthorRate: Double ) extends Rater { @@ -469,8 +471,8 @@ case class RateSum(stat: ContestStat, raters: Seq[Rater]) extends Rater { } override def explain(monumentId: String, author: String): String = { - val disqulifiedRater = raters.find(_.disqualify(monumentId, author)) - disqulifiedRater.fold( + val disqualifiedRater = raters.find(_.disqualify(monumentId, author)) + disqualifiedRater.fold( s"Rating = ${raters.map(_.rate(monumentId, author)).sum}, is a sum of: " + raters .map(_.explain(monumentId, author)) .mkString(", ") diff --git a/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/reports/AuthorMonuments.scala b/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/reports/AuthorMonuments.scala index 71203d7f..f996d93b 100644 --- a/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/reports/AuthorMonuments.scala +++ b/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/reports/AuthorMonuments.scala @@ -4,6 +4,7 @@ import org.scalawiki.MwBot import org.scalawiki.dto.markup.Table import org.scalawiki.wlx.ImageDB import org.scalawiki.wlx.stat._ +import org.scalawiki.wlx.stat.rating.{NumberOfImagesInPlaceBonus, RateSum, Rater} class AuthorMonuments( val stat: ContestStat, diff --git a/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/reports/Output.scala b/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/reports/Output.scala index d20c11e0..231d8470 100644 --- a/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/reports/Output.scala +++ b/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/reports/Output.scala @@ -3,7 +3,8 @@ package org.scalawiki.wlx.stat.reports import org.scalawiki.MwBot import org.scalawiki.dto.Image import org.scalawiki.wlx.dto.Contest -import org.scalawiki.wlx.stat.{ContestStat, RateSum, Rater} +import org.scalawiki.wlx.stat.rating.{RateSum, Rater} +import org.scalawiki.wlx.stat.ContestStat import org.scalawiki.wlx.{ImageDB, MonumentDB} import scala.concurrent.ExecutionContext diff --git a/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/reports/ReporterRegistry.scala b/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/reports/ReporterRegistry.scala index b227c439..9ff26b31 100644 --- a/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/reports/ReporterRegistry.scala +++ b/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/reports/ReporterRegistry.scala @@ -2,7 +2,8 @@ package org.scalawiki.wlx.stat.reports import org.scalawiki.MwBot import org.scalawiki.dto.markup.Table -import org.scalawiki.wlx.stat.{ContestStat, Rater, StatConfig, Stats} +import org.scalawiki.wlx.stat.rating.Rater +import org.scalawiki.wlx.stat.{ContestStat, StatConfig, Stats} import org.scalawiki.wlx.{ImageDB, ImageFiller, MonumentDB} import scala.concurrent.ExecutionContext diff --git a/scalawiki-wlx/src/test/scala/org/scalawiki/wlx/stat/AuthorsMonumentsSpec.scala b/scalawiki-wlx/src/test/scala/org/scalawiki/wlx/stat/AuthorsMonumentsSpec.scala index 89fe3e62..9a2cbb2d 100644 --- a/scalawiki-wlx/src/test/scala/org/scalawiki/wlx/stat/AuthorsMonumentsSpec.scala +++ b/scalawiki-wlx/src/test/scala/org/scalawiki/wlx/stat/AuthorsMonumentsSpec.scala @@ -4,6 +4,7 @@ import org.scalawiki.dto.Image import org.scalawiki.dto.markup.Table import org.scalawiki.wlx.dto._ import org.scalawiki.wlx.dto.lists.ListConfig._ +import org.scalawiki.wlx.stat.rating.RateConfig import org.scalawiki.wlx.stat.reports.AuthorMonuments import org.scalawiki.wlx.{ImageDB, MonumentDB} import org.specs2.mutable.Specification diff --git a/scalawiki-wlx/src/test/scala/org/scalawiki/wlx/stat/NumberOfAuthorsBonusSpec.scala b/scalawiki-wlx/src/test/scala/org/scalawiki/wlx/stat/NumberOfAuthorsBonusSpec.scala index 584a1792..231cb3f2 100644 --- a/scalawiki-wlx/src/test/scala/org/scalawiki/wlx/stat/NumberOfAuthorsBonusSpec.scala +++ b/scalawiki-wlx/src/test/scala/org/scalawiki/wlx/stat/NumberOfAuthorsBonusSpec.scala @@ -4,6 +4,7 @@ import com.typesafe.config.ConfigFactory import org.scalawiki.dto.Image import org.scalawiki.wlx.{ImageDB, MonumentDB} import org.scalawiki.wlx.dto.{Contest, ContestType, Country, Monument} +import org.scalawiki.wlx.stat.rating.NumberOfAuthorsBonus import org.specs2.mutable.Specification class NumberOfAuthorsBonusSpec extends Specification { diff --git a/scalawiki-wlx/src/test/scala/org/scalawiki/wlx/stat/StatParamsSpec.scala b/scalawiki-wlx/src/test/scala/org/scalawiki/wlx/stat/StatParamsSpec.scala index 786ce84b..d32f15bf 100644 --- a/scalawiki-wlx/src/test/scala/org/scalawiki/wlx/stat/StatParamsSpec.scala +++ b/scalawiki-wlx/src/test/scala/org/scalawiki/wlx/stat/StatParamsSpec.scala @@ -1,7 +1,8 @@ package org.scalawiki.wlx.stat -import java.time.ZonedDateTime +import org.scalawiki.wlx.stat.rating.RateConfig +import java.time.ZonedDateTime import org.specs2.mutable.Specification class StatParamsSpec extends Specification { diff --git a/scalawiki-wlx/src/test/scala/org/scalawiki/wlx/stat/RaterSpec.scala b/scalawiki-wlx/src/test/scala/org/scalawiki/wlx/stat/rating/RaterSpec.scala similarity index 97% rename from scalawiki-wlx/src/test/scala/org/scalawiki/wlx/stat/RaterSpec.scala rename to scalawiki-wlx/src/test/scala/org/scalawiki/wlx/stat/rating/RaterSpec.scala index b09c7a51..f67edb66 100644 --- a/scalawiki-wlx/src/test/scala/org/scalawiki/wlx/stat/RaterSpec.scala +++ b/scalawiki-wlx/src/test/scala/org/scalawiki/wlx/stat/rating/RaterSpec.scala @@ -1,9 +1,9 @@ -package org.scalawiki.wlx.stat +package org.scalawiki.wlx.stat.rating import com.typesafe.config.ConfigFactory import org.scalawiki.wlx.dto.ContestType.{WLE, WLM} import org.scalawiki.wlx.dto.{Contest, ContestType, Country} -import org.scalawiki.wlx.stat.RaterSpec.loadRater +import org.scalawiki.wlx.stat.ContestStat import org.scalawiki.wlx.{ImageDB, MonumentDB} import org.specs2.mutable.Specification