func combine(queries []Query) Sum {
var sum Sum
var wg sync.WaitGroup
sumsChan := make(chan Sum)
// Limit to 10 concurrent requests
limiter := make(chan struct{}, 10)
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
module Lib ( | |
Service (..), | |
Remote (..), | |
makeTunnel, | |
killTunnel, | |
portFromPsOutput | |
) where | |
import GHC.IO.Exception | |
import Data.Maybe |
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
implicit class SafeMap[T](coll: Traversable[T]) { | |
def safelyMap[U](f: T => U): Traversable[U] = { | |
coll.map { el => | |
try { | |
Some(f(el)) | |
} catch { | |
case _ => None | |
} | |
}.filter(_ != None).map(_.get) |
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 deserializeBonusSet(serialized: String): Map[Int, Int] = { | |
serialized.split("|").map { part => | |
var element = part.split(":").map(_.toInt) | |
(element(0), element(1)) | |
}.toMap | |
} |
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
MatchAggregate.Collections( | |
runes = quot.runes | |
.filter(_._2.plays >= minPlayRate) // Ensure minimum play rate is met | |
.map { case (runeSet, subscalars) => | |
MatchAggregate.Collections.RuneSet( | |
runes = deserializeBonusSet(runeSet), | |
pickRate = subscalars.plays, | |
winRate = subscalars.wins, | |
numMatches = subscalars.playCount.toInt | |
) |
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 sequenceMap[S, T](map: Map[S, Future[T]])(implicit ec: ExecutionContext): Future[Map[S, T]] = { | |
Future.sequence(map.map { case (k, fut) => | |
fut.map(v => (k, v)) | |
}).map(_.toMap) | |
} |
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
package io.asuna.lucinda.statistics | |
import org.scalatest._ | |
import org.scalacheck._ | |
import prop._ | |
import scala.collection.immutable._ | |
import io.asuna.proto.enums.Role | |
import io.asuna.proto.match_sum.MatchSum | |
class StatisticsAggregatorSpec extends PropSpec with PropertyChecks with Matchers { |
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 divideScalars[S, T]( | |
divisors: Map[Int, S], scalars: Map[Int, T] | |
)(implicit s: scala.math.Numeric[S], t: scala.math.Numeric[T]): Map[Int, Double] = { | |
val df = divisors.mapValues(x => s.toDouble(x)) | |
scalars.mapValues(x => t.toDouble(x)).transform((k, v) => | |
df.get(k) match { | |
case Some(divisor) if divisor != 0 => v / divisor | |
case None => 0 | |
} | |
) |
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 get(filters: MatchFilters): Future[Option[MatchSum]] = { | |
select | |
.where(_.championId eqs filters.championId) | |
.and(_.enemyId eqs filters.enemyId) | |
.and(_.patch eqs filters.patch) | |
.and(_.tier eqs filters.tier) | |
.and(_.region eqs filters.region.value) | |
.and(_.role eqs filters.role.value) | |
.consistencyLevel_=(ConsistencyLevel.ONE) | |
.one() |
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
// Aggregate aggregates. | |
func (a *aggregatorImpl) Aggregate( | |
aChampionId uint32, | |
enemyChampionId int32, | |
aPatch *apb.PatchRange, | |
aTier *apb.TierRange, | |
aRegion apb.Region, | |
aRole apb.Role, | |
minPlayRate float64, |