/// <summary> /// Tries to get the pool ids split by positive and negative dice /// </summary> /// <param name="context"></param> /// <param name="pool"></param> /// <param name="poolIds"></param> /// <returns></returns> public static async Task <(int positiveId, int negativeId)?> GetPoolIds(this ProbabilityContext context, Pool pool) { var poolIds = ( positiveId : await context.GetPoolIdByName(pool.GetFilteredPoolName(DieExtensions.PositiveDice)) ?? 0, negativeId : await context.GetPoolIdByName(pool.GetFilteredPoolName(DieExtensions.NegativeDice)) ?? 0 ); return(poolIds.positiveId > 0 && poolIds.negativeId > 0 ? poolIds : null); }
/// <summary> /// Gets the dice and quantity for a given pool id /// </summary> /// <param name="context"></param> /// <param name="poolId"></param> /// <returns></returns> public static Task <List <PoolDie> > GetPoolDice(this ProbabilityContext context, int poolId) => context.GetPoolDice((poolId, -1));
/// <summary> /// Gets the dice and quantity for a given set of pool ids /// </summary> /// <param name="context"></param> /// <param name="poolIds"></param> /// <returns></returns> public static Task <List <PoolDie> > GetPoolDice(this ProbabilityContext context, (int positiveId, int negativeId) poolIds) =>
/// <summary> /// Gets a list of PoolCombinationStatistics for a set of pool ids /// </summary> /// <param name="context"></param> /// <param name="poolIds"></param> /// <returns></returns> public static Task <List <PoolCombinationStatistic> > GetPoolStatistics(this ProbabilityContext context, (int positiveId, int negativeId) poolIds) =>
/// <summary> /// Returns a set of PoolResults for a given pool id /// </summary> /// <param name="context"></param> /// <param name="poolId"></param> /// <returns></returns> public static Task <List <PoolResult> > GetPoolResults(this ProbabilityContext context, int poolId) => context.PoolResults.AsQueryable().Where(w => w.PoolId == poolId).Include(i => i.PoolResultSymbols).ToListAsync();
/// <summary> /// Tries to find the pool id from a given name /// </summary> /// <param name="context"></param> /// <param name="poolName"></param> /// <returns></returns> public static async Task <int?> GetPoolIdByName(this ProbabilityContext context, string poolName) => await context.Pools.AsQueryable().Where(w => w.Name == poolName).Select(s => s.PoolId).FirstOrDefaultAsync();
/// <summary> /// Returns the id for the pool with the matching dice, this is the hard way /// </summary> /// <param name="searchForPool"></param> /// <returns></returns> public static async Task <int?> GetPoolId(this ProbabilityContext context, List <PoolDie> searchForPool) => await searchForPool.Select(die => context.PoolDice.AsQueryable().Where(w => w.DieId == die.DieId && w.Quantity == die.Quantity && w.Pool.PoolDice.Count == searchForPool.Count) .Select(s => s.PoolId)).Aggregate((result, next) => result.Intersect(next)).FirstOrDefaultAsync();
public DataService(ProbabilityContext context) => Context = context;