Last active
August 29, 2015 14:24
-
-
Save chbatey/c0ada6d4c3d512999102 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 daily(day: Day, requester: ActorRef): Unit = | |
sc.cassandraTable[Double](keyspace, rawtable) | |
.select("temperature").where("wsid = ? AND year = ? AND month = ? AND day = ?", | |
day.wsid, day.year, day.month, day.day) | |
.collectAsync() | |
.map(toDaily(_, day)) pipeTo requester | |
private def toDaily(aggregate: Seq[Double], key: Day): WeatherAggregate = | |
if (aggregate.nonEmpty) { | |
val data = toDailyTemperature(key, StatCounter(aggregate)) | |
self ! data | |
data | |
} else NoDataAvailable(key.wsid, key.year, classOf[DailyTemperature]) // not wanting to return an option to requester | |
private def toDailyTemperature(key: Day, stats: StatCounter): DailyTemperature = | |
DailyTemperature(key.wsid, key.year, key.month, key.day, | |
high = stats.max, low = stats.min, mean = stats.mean, | |
variance = stats.variance, stdev = stats.stdev) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment