Skip to content

Instantly share code, notes, and snippets.

module Lib (
Service (..),
Remote (..),
makeTunnel,
killTunnel,
portFromPsOutput
) where
import GHC.IO.Exception
import Data.Maybe
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)
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)
def deserializeBonusSet(serialized: String): Map[Int, Int] = {
serialized.split("|").map { part =>
var element = part.split(":").map(_.toInt)
(element(0), element(1))
}.toMap
}
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
)
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)
}
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 {
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
}
)
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()
// Aggregate aggregates.
func (a *aggregatorImpl) Aggregate(
aChampionId uint32,
enemyChampionId int32,
aPatch *apb.PatchRange,
aTier *apb.TierRange,
aRegion apb.Region,
aRole apb.Role,
minPlayRate float64,