public async Task <GetPoolStatsResponse> GetPoolPerformanceAsync(string poolId, [FromQuery(Name = "r")] SampleRange range = SampleRange.Day, [FromQuery(Name = "i")] SampleInterval interval = SampleInterval.Hour) { var pool = GetPool(poolId); // set range var end = clock.Now; DateTime start; switch (range) { case SampleRange.Day: start = end.AddDays(-1); break; case SampleRange.Month: start = end.AddDays(-30); break; default: throw new ApiException("invalid interval"); } var stats = await cf.Run(con => statsRepo.GetPoolPerformanceBetweenAsync( con, pool.Id, interval, start, end)); var response = new GetPoolStatsResponse { Stats = stats.Select(mapper.Map <AggregatedPoolStats>).ToArray() }; return(response); }
// Module defining this command // Optional custom code for this activity /// <summary> /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run. /// </summary> /// <param name="context">The NativeActivityContext for the currently running activity.</param> /// <returns>A populated instance of System.Management.Automation.PowerShell</returns> /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks> protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context) { System.Management.Automation.PowerShell invoker = global::System.Management.Automation.PowerShell.Create(); System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName); // Initialize the arguments if (ListSet.Expression != null) { targetCommand.AddParameter("ListSet", ListSet.Get(context)); } if (Counter.Expression != null) { targetCommand.AddParameter("Counter", Counter.Get(context)); } if (SampleInterval.Expression != null) { targetCommand.AddParameter("SampleInterval", SampleInterval.Get(context)); } if (MaxSamples.Expression != null) { targetCommand.AddParameter("MaxSamples", MaxSamples.Get(context)); } if (Continuous.Expression != null) { targetCommand.AddParameter("Continuous", Continuous.Get(context)); } if (GetIsComputerNameSpecified(context) && (PSRemotingBehavior.Get(context) == RemotingBehavior.Custom)) { targetCommand.AddParameter("ComputerName", PSComputerName.Get(context)); } return(new ActivityImplementationContext() { PowerShellInstance = invoker }); }
public async Task <PoolStats[]> GetPoolPerformanceBetweenAsync(IDbConnection con, string poolId, SampleInterval interval, DateTime start, DateTime end, CancellationToken ct) { var trunc = interval switch { SampleInterval.Hour => "hour", SampleInterval.Day => "day", _ => null }; var query = @$ "SELECT date_trunc('{trunc}', created) AS created, AVG(poolhashrate) AS poolhashrate, AVG(networkhashrate) AS networkhashrate, AVG(networkdifficulty) AS networkdifficulty, CAST(AVG(connectedminers) AS BIGINT) AS connectedminers FROM poolstats WHERE poolid = @poolId AND created >= @start AND created <= @end GROUP BY date_trunc('{trunc}', created) ORDER BY created;"; return((await con.QueryAsync <Entities.PoolStats>(new CommandDefinition(query, new { poolId, start, end }, cancellationToken: ct))) .Select(mapper.Map <PoolStats>) .ToArray()); }
public async Task <PoolStats[]> GetPoolPerformanceBetweenAsync(IDbConnection con, string poolId, SampleInterval interval, DateTime start, DateTime end) { logger.LogInvoke(new[] { poolId }); string trunc = null; switch (interval) { case SampleInterval.Hour: trunc = "hour"; break; case SampleInterval.Day: trunc = "day"; break; } var query = $"SELECT date_trunc('{trunc}', created) AS created, " + "AVG(poolhashrate) AS poolhashrate, AVG(networkhashrate) AS networkhashrate, AVG(networkdifficulty) AS networkdifficulty, " + "CAST(AVG(connectedminers) AS BIGINT) AS connectedminers " + "FROM poolstats " + "WHERE poolid = @poolId AND created >= @start AND created <= @end " + $"GROUP BY date_trunc('{trunc}', created) " + "ORDER BY created;"; return((await con.QueryAsync <Entities.PoolStats>(query, new { poolId, start, end })) .Select(mapper.Map <PoolStats>) .ToArray()); }
private void cmdSampInfo_Click(object sender, EventArgs e) { int Hour, Minute, Second; int Month, Day, Year; int SampleInterval, SampleCount; int StartDate, StartTime; int Postfix; string PostfixStr, StartDateStr; string StartTimeStr; PostfixStr = ""; SampleInterval = 0; SampleCount = 0; StartDate = 0; StartTime = 0; // Get the sample information // Parameters: // Filename :name of file to get information from // SampleInterval :time between samples // SampleCount :number of samples in the file // StartDate :date of first sample // StartTime :time of first sample ULStat = logger.GetSampleInfo(ref SampleInterval, ref SampleCount, ref StartDate, ref StartTime); if (ULStat.Value != MccDaq.ErrorInfo.ErrorCode.NoErrors) { lblComment.Text = ULStat.Message + "."; } else { //Parse the date from the StartDate parameter Month = (StartDate >> 8) & 0xff; Day = StartDate & 0xff; Year = (StartDate >> 16) & 0xffff; StartDateStr = Month.ToString("00") + "/" + Day.ToString("00") + "/" + Year.ToString("0000"); //Parse the time from the StartTime parameter Hour = (StartTime >> 16) & 0xffff; Minute = (StartTime >> 8) & 0xff; Second = StartTime & 0xff; Postfix = (StartTime >> 24) & 0xff; if (Postfix == 0) { PostfixStr = " AM"; } if (Postfix == 1) { PostfixStr = " PM"; } StartTimeStr = Hour.ToString("00") + ":" + Minute.ToString("00") + ":" + Second.ToString("00") + PostfixStr; txtResults.Text = "The sample properties of '" + logger.FileName + "' are:" + "\r\n" + "\r\n" + "\t" + "SampleInterval: " + "\t" + SampleInterval.ToString("0") + "\r\n" + "\t" + "SampleCount: " + "\t" + SampleCount.ToString("0") + "\r\n" + "\t" + "Start Date: " + "\t" + StartDateStr + "\r\n" + "\t" + "Start Time: " + "\t" + StartTimeStr; } }