public async Task <ActionResult> UpdateConnection(AlgoType algoType) { var model = await PoolReader.GetPoolConnection(algoType); if (model == null) { return(ViewMessageModal(new ViewMessageModel(ViewMessageType.Danger, "Error", $"Connection #{algoType} not found"))); } var pools = await PoolReader.GetPools(); return(View("UpdatePoolConnectionModal", new AdminUpdatePoolConnectionModel { AlgoType = model.AlgoType, Host = model.Host, Name = model.Name, Port = model.Port, DefaultDiff = model.DefaultDiff, DefaultPool = model.DefaultPool, FixedDiffSummary = model.FixedDiffSummary, VarDiffHighSummary = model.VarDiffHighSummary, VarDiffLowSummary = model.VarDiffLowSummary, VarDiffMediumSummary = model.VarDiffMediumSummary, Pools = pools.Where(x => x.AlgoType == algoType).OrderBy(x => x.Symbol).ToList() })); }
public async Task <ActionResult> UpdateWorker(int id) { var pools = await PoolReader.GetPools(); var worker = await PoolWorkerReader.AdminGetWorker(User.Identity.GetUserId(), id); var poolconnection = await PoolReader.GetPoolConnection(worker.AlgoType); return(View("UpdateWorkerModal", new AdminPoolWorkerUpdateModel { Id = id, Name = worker.Name, AlgoType = worker.AlgoType, IsAutoSwitch = worker.IsAutoSwitch, Password = worker.Password, TargetDifficulty = worker.TargetDifficulty, DefaultDiff = poolconnection.DefaultDiff, FixedDiffSummary = poolconnection.FixedDiffSummary, VarDiffHighSummary = poolconnection.VarDiffHighSummary, VarDiffLowSummary = poolconnection.VarDiffLowSummary, VarDiffMediumSummary = poolconnection.VarDiffMediumSummary, DifficultyOption = PoolExtensions.TargetDifficultyToOption(worker.TargetDifficulty), TargetPool = worker.TargetPool, Pools = pools.Where(x => x.AlgoType == worker.AlgoType).OrderBy(x => x.Symbol).ToList() })); }
public async Task <ActionResult> UpdateWorkerPool(AlgoType algoType) { var pools = await PoolReader.GetPools(); return(View("UpdateWorkerPoolModal", new AdminUpdateWorkerPoolModel { AlgoType = algoType, Pools = pools.Where(x => x.AlgoType == algoType).OrderBy(x => x.Symbol).ToList() })); }
public async Task <List <PoolListingItemModel> > GetPoolListingItems() { var pools = await PoolReader.GetPools().ConfigureAwait(false); return(pools.Select(x => new PoolListingItemModel { Id = x.Id, Name = $"{x.Symbol} ({x.AlgoType})" }) .OrderBy(x => x.Name) .ToList()); }
public async Task <ActionResult> UpdateWorkerPool(int id) { var pools = await PoolReader.GetPools(); var worker = await PoolWorkerReader.GetWorker(User.Identity.GetUserId(), id); return(View("UpdateWorkerPoolModal", new PoolWorkerUpdatePoolModel { Id = id, Name = worker.Name, AlgoType = worker.AlgoType, TargetPool = worker.TargetPool, Pools = pools.Where(x => x.AlgoType == worker.AlgoType && (x.Status == PoolStatus.OK || x.Status == PoolStatus.Expiring)).OrderBy(x => x.Symbol).ToList() })); }
public async Task <ActionResult> UpdateWorkerPool(PoolWorkerUpdatePoolModel model) { if (!ModelState.IsValid) { var pools = await PoolReader.GetPools(); model.Pools = pools.Where(x => x.AlgoType == model.AlgoType && (x.Status == PoolStatus.OK || x.Status == PoolStatus.Expiring)).OrderBy(x => x.Symbol).ToList(); return(View("UpdateWorkerPoolModal", model)); } var result = await PoolWorkerWriter.UpdateWorkerPool(User.Identity.GetUserId(), model); if (!ModelState.IsWriterResultValid(result)) { return(View("UpdateWorkerPoolModal", model)); } return(CloseModal(result)); }
public async Task <List <FeaturedSlotItemModel> > GetFeaturedPoolSlotItems() { using (var context = DataContextFactory.CreateReadOnlyContext()) { var slotDetail = await context.PaytopiaPayments .AsNoTracking() .Where(x => x.PaytopiaItem.Type == PaytopiaItemType.FeaturedPool && x.Ends > DateTime.UtcNow) .GroupBy(x => x.ReferenceId) .ToListNoLockAsync().ConfigureAwait(false); var pools = await PoolReader.GetPools().ConfigureAwait(false); var results = new List <FeaturedSlotItemModel>(); foreach (var pool in pools.DistinctBy(x => x.Symbol)) { var isActive = false; var slotSummary = string.Empty; var existingSlotDetail = slotDetail.FirstOrDefault(x => x.Key == pool.Id); if (existingSlotDetail != null && existingSlotDetail.Any()) { isActive = existingSlotDetail.Any(x => x.Begins < DateTime.UtcNow.Date && DateTime.UtcNow.Date < x.Ends); slotSummary = string.Join(",", existingSlotDetail.Select(x => $"Week: {x.Begins.WeekOfYear()} ({x.Begins.ToString("dd/MM/yyyy")} - {x.Ends.ToString("dd/MM/yyyy")})")); } var nextFreeSlot = PaytopiaWriter.GetNextFreeSlot(pool.Id, slotDetail.FirstOrDefault(x => x.Key == pool.Id)); results.Add(new FeaturedSlotItemModel { Id = pool.Id, Name = pool.Symbol, IsFeatured = isActive, NextSlotWeek = nextFreeSlot.Begin.WeekOfYear(), NextSlotBegin = nextFreeSlot.Begin, NextSlotEnd = nextFreeSlot.End, SlotSummary = slotSummary }); } return(results); } }
public async Task <MineshaftSummary> GetMineshaftSummary() { var cacheResult = await CacheService.GetOrSetHybridAsync(CacheKey.MineshaftSummary(), TimeSpan.FromSeconds(10), async() => { var poolData = new List <MineshaftSummaryModel>(); using (var context = PoolDataContextFactory.CreateContext()) { poolData = await context.Pool .AsNoTracking() .Where(x => x.IsEnabled) .Select(x => new MineshaftSummaryModel { AlgoType = x.AlgoType, PoolId = x.Id, Symbol = x.Symbol, Name = x.Name, Hashrate = (double?)x.Statistics.Hashrate ?? 0, Luck = (double?)x.Blocks.OrderByDescending(b => b.Height).Take(25).Average(b => b.Luck) ?? 0, BlocksFound = x.Blocks.Count, Miners = (int?)x.UserStatistics.Count(b => b.Hashrate > 0) ?? 0 }).ToListNoLockAsync().ConfigureAwait(false); } var algoPoolData = poolData.GroupBy(x => x.AlgoType) .Select(x => new { AlgoType = x.Key, TopPool = x.OrderByDescending(b => b.Hashrate).FirstOrDefault(), TotalHashrate = (double?)x.Sum(b => b.Hashrate) ?? 0 }); var now = DateTime.UtcNow; var pools = await PoolReader.GetPools().ConfigureAwait(false); var currencies = await CurrencyReader.GetCurrencies().ConfigureAwait(false); var featuredPools = pools.Any(x => x.FeaturedExpires > now) ? pools.Where(x => x.FeaturedExpires > now).Select(x => new FeaturedPool(currencies.FirstOrDefault(c => c.CurrencyId == x.CurrencyId))) : pools.Where(x => x.CurrencyId == 2).Select(x => new FeaturedPool(currencies.FirstOrDefault(c => c.CurrencyId == x.CurrencyId))); var totalHashrate = pools.Sum(x => x.Hashrate); var topPools = poolData.OrderByDescending(x => x.Miners).Take(5).ToList(); var algoInfo = algoPoolData.Select(x => new AlgoTypeInfo { Name = x.AlgoType.ToString(), AlgoType = x.AlgoType, TotalHashrate = x.TotalHashrate, TopPoolSymbol = x.TopPool.Symbol }).ToList(); algoInfo.Insert(0, new AlgoTypeInfo { Name = "All Pools", AlgoType = null, TopPoolSymbol = topPools.FirstOrDefault()?.Symbol, TotalHashrate = totalHashrate }); var model = new MineshaftSummary { TotalPools = pools.Count, TotalHashrate = totalHashrate, AlgoTypes = algoInfo, TopPools = topPools, Featured = featuredPools.ToList() }; return(model); }).ConfigureAwait(false); return(cacheResult); }