Beispiel #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());
        }
Beispiel #2
0
        private (DateTime, DateTime, StatsGranularity) parseStatsRequestParams(HttpContext context)
        {
            //range
            var end   = context.GetQueryParameter <DateTime>("end", clock.Now);
            var start = context.GetQueryParameter <DateTime>("start", end.AddDays(-1));

            // stats granularity [minutely, hourly, daily]
            var granularity = (StatsGranularity)StatsGranularity.Parse(typeof(StatsGranularity), context.GetQueryParameter <string>("granularity", "minutely"), true);

            return(start, end, granularity);
        }
        public static (string, string) GetSelectAndGroupStatements(StatsGranularity granularity)
        {
            switch (granularity)
            {
            case StatsGranularity.Minutely:
                return("SELECT date_trunc('minute', created) AS timestamp, ", "GROUP BY date_trunc('minute', created) ORDER BY timestamp;");

            case StatsGranularity.Hourly:
                return("SELECT date_trunc('hour', created) AS timestamp, ", "GROUP BY date_trunc('hour', created) ORDER BY timestamp;");

            default:
                return("SELECT date_trunc('day', created) AS timestamp, ", "GROUP BY date_trunc('day', created) ORDER BY timestamp;");
            }
        }
Beispiel #4
0
        private string getMinerPerformanceDateTrunc(StatsGranularity granularity)
        {
            switch (granularity)
            {
            case StatsGranularity.Minutely:
                return("date_trunc('minute', created)");

            case StatsGranularity.Hourly:
                return("date_trunc('hour', created)");

            default:
                return("date_trunc('day', created)");
            }
        }
Beispiel #5
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());
        }
Beispiel #6
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());
        }
Beispiel #7
0
        private PoolValueStat[] getPoolValueStats(IDbConnection con, string poolId, DateTime start, DateTime end, StatsGranularity granularity, string valueQuery)
        {
            logger.LogInvoke(new[] { poolId });
            string selectStatement, groupStatement;

            (selectStatement, groupStatement) = getSelectAndGroupStatements(granularity);

            var query = selectStatement +
                        valueQuery +
                        "FROM poolstats " +
                        "WHERE poolid = @poolId AND created >= @start AND created <= @end " +
                        groupStatement;

            return(con.Query <Entities.PoolValueStat>(query, new { poolId, start, end })
                   .Select(mapper.Map <PoolValueStat>)
                   .ToArray());
        }
Beispiel #8
0
 public PoolValueStat[] GetPoolNetworkPercentage(IDbConnection con, string poolId, DateTime start, DateTime end, StatsGranularity granularity)
 {
     return(getPoolValueStats(con, poolId, start, end, granularity,
                              "AVG(poolhashrate) / AVG(networkhashrate) AS value "));
 }
Beispiel #9
0
 public PoolValueStat[] GetPoolConnectedMiners(IDbConnection con, string poolId, DateTime start, DateTime end, StatsGranularity granularity)
 {
     return(getPoolValueStats(con, poolId, start, end, granularity,
                              "CAST(AVG(connectedminers) AS BIGINT) AS value "));
 }