Пример #1
0
        public async Task <PoolValueStat[]> GetPoolNetworkPercentage(IDbConnection con, string poolId, DateTime start, DateTime end)
        {
            logger.LogInvoke(new[] { poolId });
            StatsGranularity granularity = getPoolStatsGranularity(con, poolId, start, end);

            var(selectStatement, groupStatement) = RepositoryUtils.GetSelectAndGroupStatements(granularity);
            var query = selectStatement +
                        "AVG(poolhashrate), " +
                        "AVG(networkhashrate) " +
                        "FROM poolstats " +
                        "WHERE poolid = @poolId AND created >= @start AND created <= @end " +
                        groupStatement;
            var values = (await con.QueryAsync <(DateTime, double, double)>(query, new { poolId, start, end })).ToArray();
            List <PoolValueStat> stats = new List <PoolValueStat>();

            for (int i = 0; i < values.Length; i++)
            {
                var(ts, ph, nh) = values[i];
                if (nh > 0 && ph / nh < 2) //ignore outlier values
                {
                    stats.Add(new PoolValueStat
                    {
                        Timestamp = ts,
                        Value     = Math.Truncate(ph / nh * 100) / 100
                    });
                }
            }

            return(stats.ToArray());
        }
Пример #2
0
        public async Task <PoolValueStat[]> GetPoolPaid(IDbConnection con, string poolId, DateTime start, DateTime end)
        {
            logger.LogInvoke(new[] { poolId });
            StatsGranularity granularity = getPaymentsGranularity(con, poolId, start, end);

            var(selectStatement, groupStatement) = RepositoryUtils.GetSelectAndGroupStatements(granularity);
            var query = selectStatement +
                        "SUM(amount) as value " +
                        "FROM payments " +
                        "WHERE poolid = @poolid AND created >= @start AND created <= @end " +
                        groupStatement;

            return((await con.QueryAsync <PoolValueStat>(query, new { poolId, start, end }))
                   .Select(mapper.Map <PoolValueStat>)
                   .ToArray());
        }
Пример #3
0
        private async Task <PoolValueStat[]> getPoolValueStats(IDbConnection con, string poolId, DateTime start, DateTime end, string valueQuery)
        {
            logger.LogInvoke(new[] { poolId });
            StatsGranularity granularity = getPoolStatsGranularity(con, poolId, start, end);

            var(selectStatement, groupStatement) = RepositoryUtils.GetSelectAndGroupStatements(granularity);
            var query = selectStatement +
                        valueQuery +
                        "FROM poolstats " +
                        "WHERE poolid = @poolId AND created >= @start AND created <= @end AND networkhashrate > 0 " +

                        groupStatement;

            return((await con.QueryAsync <PoolValueStat>(query, new { poolId, start, end }))
                   .Select(mapper.Map <PoolValueStat>)
                   .ToArray());
        }