Example #1
0
        public IActionResult Chart([FromBody] ChartFilterViewModel filter)
        {
            //var result = this.addresses.GetCreatedAddressesChart(filter);
            var result = this.state.GetAddressesChart(filter.UnitOfTime, filter.Period);

            return(this.Ok(result));
        }
        public IEnumerable<ChartStatsViewModel> Filter<T>(
            ChartFilterViewModel chartFilter,
            Expression<Func<T, ValueExtractionModel>> projection = null,
            Expression<Func<T, bool>> queryFilter = null)
                where T : StampedEntity
        {
            this.ConfirmStartDateValue<T>(chartFilter);

            var query = this.db.Set<T>().AsQueryable();

            if (queryFilter != null)
            {
                query = query.Where(queryFilter);
            }

            var filteredQuery = query.Select(projection ?? (x => new ValueExtractionModel
            {
                Size = 1,
                Timestamp = x.Timestamp
            }));

            var result = filteredQuery
                .GroupBy(x => DateOrderFilter.GetGroupBy(x.Timestamp, chartFilter.UnitOfTime))
                .Select(x => new ChartStatsViewModel
                {
                    StartDate = DateOrderFilter.GetDateTime(x.First().Timestamp, chartFilter.UnitOfTime),
                    UnitOfTime = chartFilter.UnitOfTime,
                    Value = projection == null ? x.Count() : x.Sum(z => z.Size) / x.Count()
                })
                .OrderByDescending(x => x.StartDate)
                .Take(chartFilter.EndPeriod)
                .ToList();

            return result;
        }
        public IActionResult BlockSizeChart([FromBody] ChartFilterViewModel filter)
        {
            //var result = this.blocks.GetBlockSizeStats(filter);
            var result = this.state.GetBlockSizesChart(filter.UnitOfTime, filter.EndPeriod);

            return(this.Ok(result));
        }
Example #4
0
        public IActionResult Chart([FromBody] ChartFilterViewModel filter)
        {
            //var result = this.transactions.GetStats(filter);
            var result = this.state.GetTransactionsChart(filter.UnitOfTime, filter.Period);

            return(this.Ok(result));
        }
        public IEnumerable <ChartStatsViewModel> GetStats(ChartFilterViewModel filter)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            var latestDate = this.db.Transactions
                             .OrderByDescending(x => x.Timestamp)
                             .Select(x => x.Timestamp)
                             .First();

            filter.StartDate = latestDate.ToUnixDate();

            List <ChartStatsViewModel> result = new List <ChartStatsViewModel>();
            var periods = filter.GetPeriodStamps();

            foreach (var endStamp in periods)
            {
                var count = this.db.Transactions
                            .Where(x => x.Timestamp <= latestDate && x.Timestamp >= endStamp)
                            .Count();

                result.Add(new ChartStatsViewModel
                {
                    Value      = (decimal)count,
                    StartDate  = DateOrderFilter.GetDateTime(endStamp, filter.UnitOfTime),
                    UnitOfTime = filter.UnitOfTime
                });

                latestDate = endStamp;
            }

            stopwatch.Stop();
            Log.Information($"{this.GetType().FullName} - GetStats time - " + stopwatch.ElapsedMilliseconds);
            return(result);
        }
Example #6
0
        public IEnumerable <ChartStatsViewModel> GetBlockSizeStats(ChartFilterViewModel filter)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            long latestBlockDate = this.GetLatestTimestamp();

            filter.StartDate = latestBlockDate.ToUnixDate();

            List <ChartStatsViewModel> result = new List <ChartStatsViewModel>();

            foreach (var endStamp in filter.GetPeriodStamps())
            {
                var avgSize = this.db.Blocks
                              .AsNoTracking()
                              .Where(x => x.Timestamp <= latestBlockDate && x.Timestamp >= endStamp)
                              .Average(x => x.Size);

                result.Add(new ChartStatsViewModel
                {
                    Value      = (decimal)avgSize,
                    StartDate  = DateOrderFilter.GetDateTime(endStamp, filter.UnitOfTime),
                    UnitOfTime = filter.UnitOfTime
                });

                latestBlockDate = endStamp;
            }

            stopwatch.Stop();
            Log.Information("GetBlockSizeStats time - " + stopwatch.ElapsedMilliseconds);
            return(result);
        }
Example #7
0
 public IEnumerable <ChartStatsViewModel> GetTransactionsForAddressChart(ChartFilterViewModel filter, string address) =>
 this.Filter <Data.Models.Transactions.Transaction>(
     filter,
     null,
     x =>
     x.Assets.Any(a => a.FromAddress.PublicAddress == address || a.ToAddress.PublicAddress == address) ||
     x.GlobalIncomingAssets.Any(a => a.FromAddress.PublicAddress == address || a.ToAddress.PublicAddress == address) ||
     x.GlobalOutgoingAssets.Any(a => a.FromAddress.PublicAddress == address || a.ToAddress.PublicAddress == address));
Example #8
0
 public IEnumerable <ChartStatsViewModel> PeersChart(ChartFilterViewModel filter, int nodeId)
 {
     return(this.Filter <NodeAudit>(filter,
                                    x => new ValueExtractionModel {
         Size = x.Peers.Value, Timestamp = x.Timestamp
     },
                                    x => x.NodeId == nodeId && x.Peers.HasValue));
 }
Example #9
0
 public IEnumerable <ChartStatsViewModel> LatencyChart(ChartFilterViewModel filter, int nodeId)
 {
     return(this.Filter <NodeAudit>(filter,
                                    x => new ValueExtractionModel {
         Size = x.Latency, Timestamp = x.Timestamp
     },
                                    x => x.NodeId == nodeId));
 }
Example #10
0
        private ICollection <ChartStatsViewModel> GetBlockTimesStats(ChartFilterViewModel filter)
        {
            var latestBlockDate = this.GetLatestTimestamp();

            filter.StartDate  = latestBlockDate.ToUnixDate();
            filter.StartStamp = latestBlockDate;

            var result  = this.GetChartEntries(filter.UnitOfTime, ChartEntryType.BlockTimes);
            var periods = filter.GetPeriodStamps().Where(x => !result.Any(y => y.Timestamp == x));

            foreach (var endStamp in periods)
            {
                var blocksQuery = this.db.Blocks
                                  .Where(x => x.Timestamp <= latestBlockDate && x.Timestamp >= endStamp);
                var count = blocksQuery.Count();
                var sum   = count > 0 ? blocksQuery.Sum(x => x.TimeInSeconds) : 0;

                result.Add(new ChartStatsViewModel
                {
                    Label            = endStamp.ToUnixDate().ToString(),
                    AccumulatedValue = (decimal)sum,
                    Value            = (decimal)count,
                    StartDate        = DateOrderFilter.GetDateTime(endStamp, filter.UnitOfTime),
                    UnitOfTime       = filter.UnitOfTime
                });

                var exists = this.db.ChartEntries.Any(
                    x =>
                    x.Timestamp == endStamp &&
                    x.Type == ChartEntryType.BlockTimes &&
                    x.UnitOfTime == filter.UnitOfTime);

                latestBlockDate = endStamp;

                if (exists || !endStamp.IsPeriodOver(filter.UnitOfTime))
                {
                    continue;
                }

                this.db.ChartEntries.Add(new Data.Models.ChartEntry
                {
                    UnitOfTime       = filter.UnitOfTime,
                    Timestamp        = endStamp,
                    Type             = ChartEntryType.BlockTimes,
                    AccumulatedValue = (decimal)sum,
                    Value            = count
                });

                this.db.SaveChanges();
            }

            return(result);
        }
        protected void ConfirmStartDateValue<T>(ChartFilterViewModel filter)
            where T : StampedEntity
        {
            if (filter.StartDate == null)
            {
                var latestDbBlockTime = this.db.Set<T>()
                    .OrderByDescending(x => x.Timestamp)
                    .Select(x => x.Timestamp.ToUnixDate())
                    .FirstOrDefault();

                filter.StartDate = latestDbBlockTime;
            }
        }
Example #12
0
        private ICollection <ChartStatsViewModel> GetConsensusRewardsStats(ChartFilterViewModel filter)
        {
            var latestBlockDate = this.GetLatestTimestamp();

            filter.StartStamp = latestBlockDate;
            filter.StartDate  = latestBlockDate.ToUnixDate();

            var result  = this.GetChartEntries(filter.UnitOfTime, ChartEntryType.ConsensusRewards);
            var periods = filter.GetPeriodStamps().Where(x => !result.Any(y => y.Timestamp == x)).ToArray();

            for (int i = 1; i < periods.Length; i++)
            {
                var sum = this.db.Transactions
                          .Where(x => x.Type == TransactionType.MinerTransaction)
                          .Where(x => x.GlobalOutgoingAssets.Any())
                          .Where(x => x.Timestamp < periods[i - 1] && x.Timestamp >= periods[i])
                          .SelectMany(x => x.GlobalOutgoingAssets)
                          .Sum(x => x.Amount);

                result.Add(new ChartStatsViewModel
                {
                    Value      = (decimal)sum,
                    StartDate  = DateOrderFilter.GetDateTime(periods[i], filter.UnitOfTime),
                    UnitOfTime = filter.UnitOfTime
                });

                var exists = this.db.ChartEntries.Any(
                    x =>
                    x.Timestamp == periods[i] &&
                    x.Type == ChartEntryType.ConsensusRewards &&
                    x.UnitOfTime == filter.UnitOfTime);

                if (exists || !periods[i].IsPeriodOver(filter.UnitOfTime))
                {
                    continue;
                }

                this.db.ChartEntries.Add(new Data.Models.ChartEntry
                {
                    UnitOfTime = filter.UnitOfTime,
                    Timestamp  = periods[i],
                    Type       = ChartEntryType.ConsensusRewards,
                    Value      = sum
                });

                this.db.SaveChanges();
            }

            return(result);
        }
Example #13
0
        private ICollection <ChartStatsViewModel> GetActiveAddressesStats(ChartFilterViewModel filter)
        {
            var latestBlockDate = this.GetLatestTimestamp();

            filter.StartDate  = latestBlockDate.ToUnixDate();
            filter.StartStamp = latestBlockDate;

            var result  = this.GetChartEntries(filter.UnitOfTime, ChartEntryType.ActiveAddresses);
            var periods = filter.GetPeriodStamps().Where(x => !result.Any(y => y.Timestamp == x)).ToArray();

            for (int i = 1; i < periods.Length; i++)
            {
                var count = this.db.Addresses
                            .Count(x => x.AddressesInTransaction.Any(at => at.Timestamp < periods[i - 1] && at.Timestamp >= periods[i]));

                result.Add(new ChartStatsViewModel
                {
                    Value      = (decimal)count,
                    StartDate  = DateOrderFilter.GetDateTime(periods[i], filter.UnitOfTime),
                    UnitOfTime = filter.UnitOfTime
                });

                var exists = this.db.ChartEntries.Any(
                    x =>
                    x.Timestamp == periods[i] &&
                    x.Type == ChartEntryType.ActiveAddresses &&
                    x.UnitOfTime == filter.UnitOfTime);

                if (exists || !periods[i].IsPeriodOver(filter.UnitOfTime))
                {
                    continue;
                }

                this.db.ChartEntries.Add(new Data.Models.ChartEntry
                {
                    UnitOfTime = filter.UnitOfTime,
                    Timestamp  = periods[i],
                    Type       = ChartEntryType.ActiveAddresses,
                    Value      = count
                });

                this.db.SaveChanges();
            }

            return(result);
        }
        public IActionResult RegionStat(int?region = 1)
        {
            //Фильтрация
            IQueryable <IndicatorsModel> indicators = _context.Indicators.Include(i => i.Region).Include(i => i.Year);

            if (region != null && region != 0)
            {
                indicators = indicators.Where(p => p.RegionId == region);
            }
            indicators = indicators.OrderBy(s => s.Year.YearNumb);

            List <Region> regions = _context.Regions.ToList();
            List <Year>   years   = _context.Years.ToList();

            ChartFilterViewModel viewModel = new ChartFilterViewModel
            {
                Indicators = indicators.ToList(),
                Regions    = new SelectList(regions, "Id", "Name"),
                Years      = new SelectList(years, "Id", "YearName")
            };

            int IndMassSize = indicators.Count();

            string[] YearsMass = new string[IndMassSize];

            double[] VrpMass = new double[IndMassSize];
            double[] NumberOfEnterprisesMass   = new double[IndMassSize];
            double[] WasteGenerationMass       = new double[IndMassSize];
            double[] ExpendituresOnEnvProtMass = new double[IndMassSize];
            double[] TotalEmissionsMass        = new double[IndMassSize];
            double[] CarbonMonoxideMass        = new double[IndMassSize];
            double[] MethaneMass            = new double[IndMassSize];
            double[] NitrogenDioxideMass    = new double[IndMassSize];
            double[] NitricOxideMass        = new double[IndMassSize];
            double[] SootMass               = new double[IndMassSize];
            double[] SulfurDioxideMass      = new double[IndMassSize];
            double[] NonMetOrgCompoundsMass = new double[IndMassSize];
            double[] CarbonDioxideMass      = new double[IndMassSize];
            double[] FromMobileSourcesMass  = new double[IndMassSize];


            int i1 = 0;

            foreach (IndicatorsModel n in indicators)
            {
                YearsMass[i1] = n.Year.YearNumb.ToString();
                VrpMass[i1]   = n.Vrp;
                NumberOfEnterprisesMass[i1]   = n.NumberOfEnterprises;
                WasteGenerationMass[i1]       = n.WasteGeneration;
                ExpendituresOnEnvProtMass[i1] = n.ExpendituresOnEnvProt;
                TotalEmissionsMass[i1]        = n.TotalEmissions;
                CarbonMonoxideMass[i1]        = n.CarbonMonoxide;
                MethaneMass[i1]            = n.Methane;
                NitrogenDioxideMass[i1]    = n.NitrogenDioxide;
                NitricOxideMass[i1]        = n.NitricOxide;
                SootMass[i1]               = n.Soot;
                SulfurDioxideMass[i1]      = n.SulfurDioxide;
                NonMetOrgCompoundsMass[i1] = n.NonMetOrgCompounds;
                CarbonDioxideMass[i1]      = n.CarbonDioxide;
                FromMobileSourcesMass[i1]  = n.FromMobileSources;
                i1++;
            }
            ViewBag.YearsMass = YearsMass;

            ViewBag.VrpMass = VrpMass;
            ViewBag.NumberOfEnterprisesMass   = NumberOfEnterprisesMass;
            ViewBag.WasteGenerationMass       = WasteGenerationMass;
            ViewBag.ExpendituresOnEnvProtMass = ExpendituresOnEnvProtMass;

            ViewBag.TotalEmissionsMass = TotalEmissionsMass;

            ViewBag.CarbonMonoxideMass     = CarbonMonoxideMass;
            ViewBag.MethaneMass            = MethaneMass;
            ViewBag.NitrogenDioxideMass    = NitrogenDioxideMass;
            ViewBag.NitricOxideMass        = NitricOxideMass;
            ViewBag.SootMass               = SootMass;
            ViewBag.SulfurDioxideMass      = SulfurDioxideMass;
            ViewBag.NonMetOrgCompoundsMass = NonMetOrgCompoundsMass;

            ViewBag.CarbonDioxideMass     = CarbonDioxideMass;
            ViewBag.FromMobileSourcesMass = FromMobileSourcesMass;



            Region Reg = _context.Regions.FirstOrDefault(p => p.Id == region);

            ViewBag.Region = Reg.Name;



            return(View(viewModel));
        }
        public IActionResult ConsensusRewardsChart([FromBody] ChartFilterViewModel filter)
        {
            var result = this.state.GetConsensusRewardsChart(filter.UnitOfTime, filter.Period);

            return(this.Ok(result));
        }
        public IActionResult PeersChart([FromBody] ChartFilterViewModel filter, int nodeId)
        {
            var result = this.nodeService.PeersChart(filter, nodeId);

            return(Ok(result));
        }
        public IEnumerable <ChartStatsViewModel> GetCreatedAddressesChart(ChartFilterViewModel filter)
        {
            var query = this.db.Addresses.AsQueryable();

            return(this.GetChart(filter, query));
        }
Example #18
0
        public IActionResult AddressChart([FromBody] ChartFilterViewModel filter, string address)
        {
            var result = this.transactions.GetTransactionsForAddressChart(filter, address);

            return(this.Ok(result));
        }
Example #19
0
        public IActionResult ActiveChart([FromBody] ChartFilterViewModel filter)
        {
            var result = this.state.GetActiveAddressesChart(filter.UnitOfTime, filter.Period);

            return(this.Ok(result));
        }
Example #20
0
        public IActionResult AssetChart([FromBody] ChartFilterViewModel filter, string assetHash)
        {
            var result = this.addresses.GetAddressesForAssetChart(filter, assetHash);

            return(this.Ok(result));
        }
        public IEnumerable <ChartStatsViewModel> GetAddressesForAssetChart(ChartFilterViewModel filter, string assetHash)
        {
            var query = this.db.Addresses.Where(x => x.Balances.Any(b => b.AssetHash == assetHash && b.Balance > 0));

            return(this.GetChart(filter, query));
        }
        private ICollection <ChartStatsViewModel> GetAddressesStats(ChartFilterViewModel filter)
        {
            var latestBlockDate = this.GetLatestTimestamp();

            filter.StartDate = latestBlockDate.ToUnixDate();

            var result   = this.GetChartEntries(filter.UnitOfTime, ChartEntryType.CreatedAddresses);
            var addrList = this.db.Addresses
                           .AsNoTracking()
                           .Where(x =>
                                  x.FirstTransactionOn >= filter.GetEndDate() &&
                                  !result.Any(r => r.Timestamp == x.FirstTransactionOn.GetPeriodStart(filter.UnitOfTime).ToUnixTimestamp()))
                           .ToList();

            var newEntries = new List <ChartStatsViewModel>();

            if (filter.UnitOfTime == UnitOfTime.Hour)
            {
                newEntries = addrList
                             .GroupBy(x => new
                {
                    x.FirstTransactionOn.Year,
                    x.FirstTransactionOn.Month,
                    x.FirstTransactionOn.Day,
                    x.FirstTransactionOn.Hour
                })
                             .Select(x => new ChartStatsViewModel
                {
                    StartDate  = new DateTime(x.Key.Year, x.Key.Month, x.Key.Day, x.Key.Hour, 0, 0),
                    Timestamp  = new DateTime(x.Key.Year, x.Key.Month, x.Key.Day, x.Key.Hour, 0, 0).ToUnixTimestamp(),
                    UnitOfTime = UnitOfTime.Hour,
                    Value      = x.Count()
                })
                             .OrderBy(x => x.StartDate)
                             .ToList();

                result.AddRange(newEntries);
            }
            else if (filter.UnitOfTime == UnitOfTime.Day)
            {
                newEntries = addrList
                             .GroupBy(x => new
                {
                    x.FirstTransactionOn.Year,
                    x.FirstTransactionOn.Month,
                    x.FirstTransactionOn.Day
                })
                             .Select(x => new ChartStatsViewModel
                {
                    StartDate  = new DateTime(x.Key.Year, x.Key.Month, x.Key.Day),
                    Timestamp  = new DateTime(x.Key.Year, x.Key.Month, x.Key.Day).ToUnixTimestamp(),
                    UnitOfTime = UnitOfTime.Day,
                    Value      = x.Count()
                })
                             .OrderBy(x => x.StartDate)
                             .ToList();

                result.AddRange(newEntries);
            }
            else if (filter.UnitOfTime == UnitOfTime.Month)
            {
                newEntries = addrList
                             .GroupBy(x => new
                {
                    x.FirstTransactionOn.Year,
                    x.FirstTransactionOn.Month
                })
                             .Select(x => new ChartStatsViewModel
                {
                    StartDate  = new DateTime(x.Key.Year, x.Key.Month, 1),
                    Timestamp  = new DateTime(x.Key.Year, x.Key.Month, 1).ToUnixTimestamp(),
                    UnitOfTime = UnitOfTime.Month,
                    Value      = x.Count()
                })
                             .OrderBy(x => x.StartDate)
                             .ToList();

                result.AddRange(newEntries);
            }

            foreach (var entry in newEntries)
            {
                var exists = this.db.ChartEntries
                             .AsNoTracking()
                             .Any(x =>
                                  x.Timestamp == entry.Timestamp &&
                                  x.Type == ChartEntryType.CreatedAddresses &&
                                  x.UnitOfTime == entry.UnitOfTime);

                if (exists)
                {
                    continue;
                }

                this.db.ChartEntries.Add(new Data.Models.ChartEntry
                {
                    UnitOfTime = filter.UnitOfTime,
                    Timestamp  = entry.Timestamp,
                    Type       = ChartEntryType.CreatedAddresses,
                    Value      = entry.Value
                });

                this.db.SaveChanges();
            }

            return(result);
        }
        public IEnumerable <ChartStatsViewModel> GetTransactionTypesForAddress(ChartFilterViewModel filter, string address)
        {
            if (filter.StartDate == null)
            {
                filter.StartDate = this.db.Addresses
                                   .OrderByDescending(x => x.FirstTransactionOn)
                                   .Select(x => x.FirstTransactionOn)
                                   .FirstOrDefault();
            }
            var query  = this.db.Addresses.AsQueryable();
            var result = new List <ChartStatsViewModel>();

            query = query.Where(x => x.FirstTransactionOn >= filter.GetEndDate());

            if (filter.UnitOfTime == UnitOfTime.Hour)
            {
                result = query.ToList().GroupBy(x => new
                {
                    x.FirstTransactionOn.Year,
                    x.FirstTransactionOn.Month,
                    x.FirstTransactionOn.Day,
                    x.FirstTransactionOn.Hour
                })
                         .Select(x => new ChartStatsViewModel
                {
                    StartDate  = new DateTime(x.Key.Year, x.Key.Month, x.Key.Day, x.Key.Hour, 0, 0),
                    UnitOfTime = UnitOfTime.Hour,
                    Value      = x.Count()
                })
                         .OrderBy(x => x.StartDate)
                         .ToList();
            }
            else if (filter.UnitOfTime == UnitOfTime.Day)
            {
                result = query.ToList().GroupBy(x => new
                {
                    x.FirstTransactionOn.Year,
                    x.FirstTransactionOn.Month,
                    x.FirstTransactionOn.Day
                })
                         .Select(x => new ChartStatsViewModel
                {
                    StartDate  = new DateTime(x.Key.Year, x.Key.Month, x.Key.Day),
                    UnitOfTime = UnitOfTime.Day,
                    Value      = x.Count()
                })
                         .OrderBy(x => x.StartDate)
                         .ToList();
            }
            else if (filter.UnitOfTime == UnitOfTime.Month)
            {
                result = query.ToList().GroupBy(x => new
                {
                    x.FirstTransactionOn.Year,
                    x.FirstTransactionOn.Month
                })
                         .Select(x => new ChartStatsViewModel
                {
                    StartDate  = new DateTime(x.Key.Year, x.Key.Month, 1),
                    UnitOfTime = UnitOfTime.Month,
                    Value      = x.Count()
                })
                         .OrderBy(x => x.StartDate)
                         .ToList();
            }

            return(result);
        }