fijimf / playfij

Experimenting with play framework
2 stars 0 forks source link

Revisit saddle before deploying statistics model #18

Closed fijimf closed 10 years ago

fijimf commented 11 years ago

point id:Long obsDate:LocalDate obsId:Long obsStatId:Long value:Double

statistic id:Long key:String name:String modelId:Long targetObject:String shortFormat:String longFormat:String higherIsBetter:Boolean

model id:Long key:String name;String class:String

trait ComputableModel { def key:String def compute(teamMap:Map[Id, Team], conferenceMap:Map[Team, Map[Season, Conference]], seasons:List[Season], games:List[Game]):Map[Date,Map[Statistic[Long, Double]]]

def season(g:Game, seasons:List[Season]) = { seasons.filter(s=>(!s.from.after(g.date) && !s.to.before(g.date))).headOption }

}

trait WonLostModel { def key = "won-lost"

def compute(teamMap:Map[Id, Team], conferenceMap:Map[Team, Map[Season, Conference]], seasons:List[Season], games:List[Game]) = {
   games.groupBy(g=>season(g,seasons))
   games.sortBy(_.date)

   games.foldLeft((Map.empty[Date,Map[Statistic[Long, Double]],Map.empty[Statistic[Long, Double]]])(accumulate(_,_))

}

def accumulate(g:Game, byDate:Map[Date,Map[Statistic[Long, Double]]], running:Map[Statistic[Long, Double]]): Map[Date,Map[Statistic[Long, Double]]] = {
   running.put(g.winner.id, running
}