Browse files

Refactoring.

  • Loading branch information...
1 parent 5d9e0f5 commit d861734cfeb8c28826bc5808532119b32d31d6ef @danielkorzekwa committed Feb 24, 2012
View
5 src/main/scala/dk/tennis/compare/ATPTennisMatchBulkCompare.scala
@@ -4,12 +4,11 @@ import scala.io.Source
import org.apache.commons.io.FileUtils._
import java.io.File
import scala.collection.JavaConversions._
-import dk.atp.api.AtpWorldTourApi._
-import SurfaceEnum._
+import dk.atp.api.facts.AtpFactsApi._
+import dk.atp.api.domain.SurfaceEnum._
import dk.tennisprob.TennisProbCalc.MatchTypeEnum._
import java.util.Date
import domain._
-import dk.atp.api.AtpWorldTourApiImpl
import org.apache.commons.math.util._
import dk.atp.api.tournament.TournamentAtpApi._
import scala.collection.immutable.TreeMap
View
8 src/main/scala/dk/tennis/compare/ATPTennisMatchCompare.scala
@@ -1,16 +1,16 @@
package dk.tennis.compare
import dk.atp.api._
-import dk.atp.api.AtpWorldTourApi._
-import SurfaceEnum._
+import dk.atp.api.facts.AtpFactsApi._
+import dk.atp.api.domain.SurfaceEnum._
import dk.tennisprob.TennisProbCalc.MatchTypeEnum._
import dk.tennisprob._
import java.util.Date
import org.joda.time.DateTime
import dk.atp.api.tournament.TournamentAtpApi._
-import ATPMatchesLoader._
import ATPTennisMatchCompare._
import java.util.Date
+import dk.atp.api.domain._
/**
* Calculates probability of winning a tennis match by player A against player B. For instance Roger Federer vs Novak Djokovic
@@ -82,7 +82,7 @@ class ATPTennisMatchCompare(atpMatchLoader: ATPMatchesLoader, discountFactor: Do
TimestampedDouble(m.tournament.tournamentTime, m.matchFacts.playerAFacts.totalServicePointsLostPct) ::
TimestampedDouble(m.tournament.tournamentTime, m.matchFacts.playerBFacts.totalServicePointsLostPct) :: Nil
}.filter(tsValue => !tsValue.value.isNaN())
-
+
val winOnReturnProb = avgDiscount(timestampedWinOnReturnPct)
winOnReturnProb
}
View
2 src/main/scala/dk/tennis/compare/CachedATPMatchesLoader.scala
@@ -3,7 +3,7 @@ package dk.tennis.compare
import dk.atp.api.tournament.TournamentAtpApi
import scala.collection.mutable.Map
import dk.atp.api.ATPMatchesLoader
-import dk.atp.api.ATPMatchesLoader._
+import dk.atp.api.domain._
class CachedATPMatchesLoader(atpMatchesLoader: ATPMatchesLoader) extends ATPMatchesLoader {
View
4 src/main/scala/dk/tennis/compare/TennisMatchCompare.scala
@@ -1,7 +1,7 @@
package dk.tennis.compare
-import dk.atp.api.AtpWorldTourApi._
-import SurfaceEnum._
+import dk.atp.api.facts.AtpFactsApi._
+import dk.atp.api.domain.SurfaceEnum._
import dk.tennisprob.TennisProbCalc.MatchTypeEnum._
import java.util.Date
View
4 src/main/scala/dk/tennis/compare/domain/MarketProb.scala
@@ -1,9 +1,9 @@
package dk.tennis.compare.domain
import java.text.SimpleDateFormat
-import dk.atp.api.AtpWorldTourApi._
-import SurfaceEnum._
import dk.tennisprob.TennisProbCalc.MatchTypeEnum._
+import dk.atp.api.domain._
+import SurfaceEnum._
/**@param runnerProbs[selectionId, probability]*/
case class MarketProb(market: Market, runnerProbs: Map[Long, Double], surface: SurfaceEnum, matchType: MatchTypeEnum) {
View
5,377 src/test/resources/atp_historical_data/match_data_2010_2011.csv
5,377 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
21 src/test/scala/dk/tennis/compare/ATPTennisMatchBulkCompareTest.scala
@@ -4,26 +4,21 @@ import org.junit._
import Assert._
import java.io._
import scala.io._
-import dk.atp.api.AtpWorldTourApi._
-import SurfaceEnum._
+import dk.atp.api.facts.AtpFactsApi._
+import dk.atp.api.domain.SurfaceEnum._
import dk.tennisprob.TennisProbCalc.MatchTypeEnum._
import scala.collection.mutable.ListBuffer
-import dk.atp.api.AtpWorldTourApiImpl
+import dk.atp.api.facts.GenericAtpFactsApi
import dk.atp.api._
import dk.atp.api.tournament._
import tournament.TournamentAtpApi._
-import dk.atp.api.AtpWorldTourApi._
-import SurfaceEnum._
+import dk.atp.api.facts.GenericAtpFactsApi._
import dk.tennisprob.TennisProbCalc.MatchTypeEnum._
import domain._
import ATPTennisMatchBulkCompareTest._
object ATPTennisMatchBulkCompareTest {
-
- private var tournamentApi: GenericTournamentAtpApi = new GenericTournamentAtpApi(5000)
- private val genericATPMatchesLoader = new GenericATPMatchesLoader(tournamentApi)
- private val atpMatchesLoader = new CachedATPMatchesLoader(genericATPMatchesLoader)
-
+ private val atpMatchesLoader = CSVATPMatchesLoader.fromCSVFile("./src/test/resources/atp_historical_data/match_data_2010_2011.csv")
}
class ATPTennisMatchBulkCompareTest {
@@ -40,7 +35,7 @@ class ATPTennisMatchBulkCompareTest {
new File(tennisProbFile).delete()
}
- @Test @Ignore def single_market {
+ @Test def single_market {
def progress(marketNumber: Int): Unit = {}
@@ -50,8 +45,8 @@ class ATPTennisMatchBulkCompareTest {
assertEquals(3, probSource.getLines().size)
assertEquals("event_id,full_description,scheduled_off,selection_id,selection,probability, surface, match_type", probSource.reset().getLine(1))
- assertEquals("100270800,Group A/Brisbane International 2011/Mens Tournament/First Round Matches/Dolgopolov v Andreev,2011-01-03 05:45:00.000,2263582,Igor Andreev,0.3434,HARD,THREE_SET_MATCH", probSource.reset().getLine(2))
- assertEquals("100270800,Group A/Brisbane International 2011/Mens Tournament/First Round Matches/Dolgopolov v Andreev,2011-01-03 05:45:00.000,4720522,Alexandr Dolgopolov,0.6566,HARD,THREE_SET_MATCH", probSource.reset().getLine(3))
+ assertEquals("100270800,Group A/Brisbane International 2011/Mens Tournament/First Round Matches/Dolgopolov v Andreev,2011-01-03 05:45:00.000,2263582,Igor Andreev,0.3604,HARD,THREE_SET_MATCH", probSource.reset().getLine(2))
+ assertEquals("100270800,Group A/Brisbane International 2011/Mens Tournament/First Round Matches/Dolgopolov v Andreev,2011-01-03 05:45:00.000,4720522,Alexandr Dolgopolov,0.6396,HARD,THREE_SET_MATCH", probSource.reset().getLine(3))
}
View
17 src/test/scala/dk/tennis/compare/ATPTennisMatchCompareTest.scala
@@ -2,28 +2,27 @@ package dk.tennis.compare
import org.junit._
import Assert._
-import dk.atp.api.AtpWorldTourApi._
-import SurfaceEnum._
+import dk.atp.api.facts.AtpFactsApi._
+import dk.atp.api.domain.SurfaceEnum._
import dk.tennisprob.TennisProbCalc.MatchTypeEnum._
-import dk.atp.api.AtpWorldTourApiImpl
import dk.atp.api.tournament.GenericTournamentAtpApi
import org.joda.time.DateTime
import ATPTennisMatchCompareTest._
import dk.atp.api._
import dk.atp.api.tournament._
object ATPTennisMatchCompareTest {
- private var tournamentApi: GenericTournamentAtpApi = new GenericTournamentAtpApi(10000)
- private val genericATPMatchesLoader = new GenericATPMatchesLoader(tournamentApi)
- private val atpMatchesLoader = new CachedATPMatchesLoader(genericATPMatchesLoader)
+
+ private val atpMatchesLoader = CSVATPMatchesLoader.fromCSVFile("./src/test/resources/atp_historical_data/match_data_2010_2011.csv")
+
}
class ATPTennisMatchCompareTest {
private val matchCompare = new ATPTennisMatchCompare(atpMatchesLoader)
- val marketTime2012 = new DateTime().withYear(2012).toDate()
- val marketTime2011 = new DateTime().withYear(2011).toDate()
+ val marketTime2012 = new DateTime(0).withYear(2012).toDate()
+ val marketTime2011 = new DateTime(0).withYear(2011).toDate()
@Test def matchProb_Roger_Federer_vs_Milos_Raonic {
@@ -36,7 +35,7 @@ class ATPTennisMatchCompareTest {
assertEquals(0.907, matchCompare.matchProb(playerAFullName, playerBFullName, CLAY, FIVE_SET_MATCH, marketTime2012), 0.001)
assertEquals(0.797, matchCompare.matchProb(playerAFullName, playerBFullName, GRASS, THREE_SET_MATCH, marketTime2012), 0.001)
- assertEquals(0.817, matchCompare.matchProb(playerAFullName, playerBFullName, HARD, THREE_SET_MATCH, marketTime2012), 0.001)
+ assertEquals(0.8735, matchCompare.matchProb(playerAFullName, playerBFullName, HARD, THREE_SET_MATCH, marketTime2012), 0.001)
}

0 comments on commit d861734

Please sign in to comment.