public void Update() { for (int index = 0; index < RigLogs.Count; index++) { Rig rig = RigLogs[index]; // Makes sure the rigname the user sees is always correct StringBuilder sb = new StringBuilder(); sb.Append("Rig #").Append(index + 1).Append(", ").Append(rig.Name) .Append(": ").Append(rig.IpAddress).Append(":").Append(rig.Port); rig.UserFriendlyName = sb.ToString(); //Gets all API information here first and passes it on Dictionary <string, string>[][] allApiResults = new Dictionary <string, string> [4][]; allApiResults[0] = PruvotApi.GetSummary(rig.IpAddress, rig.Port); allApiResults[1] = PruvotApi.GetPoolInfo(rig.IpAddress, rig.Port); allApiResults[2] = PruvotApi.GetHwInfo(rig.IpAddress, rig.Port); if (allApiResults[0] != null && allApiResults[1] != null && allApiResults[2] != null) { // Ping times measuring needs only to be done once too int[] pingTimes = GetPingTimes(allApiResults[1], rig); // If it's a new rig or hardware has been added/removed, it should add/remove it in the logs too CheckLiveGpus(allApiResults, rig); // Prepping for total rig statistics decimal totalHashCount = 0, totalHashRate = 0, totalAverageHashRate = 0, totalStandardDeviation = 0, totalAverageStandardDeviation = 0, lowestHashRate = decimal.MaxValue, highestHashRate = 0, totalAverageTemperature = 0; foreach (GpuLogger gpu in rig.GpuLogs) { allApiResults[3] = gpu.Info.MinerMap != -1 ? PruvotApi.GetHistory(rig.IpAddress, rig.Port, gpu.Info.MinerMap) : new Dictionary <string, string> [0]; gpu.ChangeAvailability(allApiResults[3] != null); string liveAlgo = PruvotApi.GetDictValue <string>(allApiResults[0][0], "ALGO"); gpu.FindCurrentBenchmark(liveAlgo); gpu.Update(allApiResults, pingTimes); // While we're at it, calculate the total stats for the rig totalHashCount += gpu.CurrentBenchmark.CurrentStatistic.TotalHashCount; totalHashRate += gpu.CurrentBenchmark.CurrentStatistic.HarmonicAverageHashRate; totalAverageHashRate += gpu.CurrentBenchmark.CurrentStatistic.HarmonicAverageHashRate * gpu.CurrentBenchmark.CurrentStatistic.TotalHashCount; lowestHashRate = lowestHashRate < gpu.CurrentBenchmark.CurrentStatistic.LowestHashRate ? lowestHashRate : gpu.CurrentBenchmark.CurrentStatistic.LowestHashRate; highestHashRate = highestHashRate > gpu.CurrentBenchmark.CurrentStatistic.HighestHashRate ? highestHashRate : gpu.CurrentBenchmark.CurrentStatistic.HighestHashRate; totalStandardDeviation += gpu.CurrentBenchmark.CurrentStatistic.StandardDeviation; totalAverageStandardDeviation += gpu.CurrentBenchmark.CurrentStatistic.StandardDeviation * gpu.CurrentBenchmark.CurrentStatistic.TotalHashCount; totalAverageTemperature += gpu.CurrentBenchmark.CurrentStatistic.AverageTemperature; if (totalHashRate > 0) { rig.Available = true; } } if (rig.GpuLogs.Count > 0 && totalHashCount > 0) { rig.CurrentStatistic = new Rig.RigStat { Algorithm = rig.GpuLogs[rig.GpuLogs.Count - 1].CurrentBenchmark.Algorithm, TotalHashCount = totalHashCount, TotalHashRate = totalHashRate, AverageHashRate = totalAverageHashRate / totalHashCount, TotalStandardDeviation = totalStandardDeviation, AverageStandardDeviation = totalAverageStandardDeviation / totalHashCount, LowestHashRate = lowestHashRate, HighestHashRate = highestHashRate, Accepts = PruvotApi.GetDictValue <int>(allApiResults[0][0], "ACC"), Rejects = PruvotApi.GetDictValue <int>(allApiResults[0][0], "REJ"), AverageTemperature = totalAverageTemperature / rig.GpuLogs.Count, ShareAnswerPing = pingTimes[0], }; } } else { DisableRig(rig); } } }
private static void CheckLiveGpus(Dictionary <string, string>[][] allApiResults, Rig rig) { int apiGpuCount = PruvotApi.GetDictValue <int>(allApiResults[0][0], "GPUS"); if (rig.GpuLogs.Count < apiGpuCount) { foreach (Dictionary <string, string> hwInfo in allApiResults[2]) { GpuLogger.Benchmark benchmark = new GpuLogger.Benchmark { AvailableTimeStamps = new List <GpuLogger.Benchmark.Availability>(), Statistics = new List <GpuLogger.Benchmark.GpuStat>(), HashLogs = new HashSet <GpuLogger.Benchmark.HashEntry>(), SensorLog = new List <GpuLogger.Benchmark.SensorValue>() }; GpuLogger newGpu = new GpuLogger { Info = new GpuLogger.GpuInfo { Name = PruvotApi.GetDictValue(hwInfo, "CARD"), Bus = PruvotApi.GetDictValue <int>(hwInfo, "BUS"), MinerMap = PruvotApi.GetDictValue <int>(hwInfo, "GPU"), NvapiId = PruvotApi.GetDictValue <int>(hwInfo, "NVAPI"), NvmlId = PruvotApi.GetDictValue <int>(hwInfo, "NVML"), ComputeCapability = PruvotApi.GetDictValue <uint>(hwInfo, "SM"), }, BenchLogs = new List <GpuLogger.Benchmark> { }, CurrentBenchmark = benchmark }; newGpu.ChangeAvailability(true); if (newGpu.Info.Bus >= 0) { bool found = false; foreach (GpuLogger gpu in rig.GpuLogs) { if (gpu.Info.Equals(newGpu.Info) && gpu.CurrentBenchmark.AvailableTimeStamps.Last().Available) { found = true; } } if (!found) { foreach (GpuLogger gpu in rig.GpuLogs) { // Let's loop again, but now only check for "old" GPUs on that specific bus // Don't delete them, just make them unavailable if (gpu.Info.Bus == newGpu.Info.Bus) { gpu.ChangeAvailability(false); } } rig.GpuLogs.Add(newGpu); } } } } if (rig.GpuLogs.Count > apiGpuCount) { foreach (GpuLogger gpu in rig.GpuLogs) { bool found = false; foreach (Dictionary <string, string> hwInfo in allApiResults[2]) { int apiBus = PruvotApi.GetDictValue <int>(hwInfo, "BUS"); if (gpu.Info.Bus == apiBus) { found = true; } } gpu.ChangeAvailability(found); } } }
private void txtApiConsole_KeyDown(object sender, KeyEventArgs e) { // Always go to the end of the textbox, never type in the middle txtApiConsole.SelectionStart = txtApiConsole.TextLength; txtApiConsole.ScrollToCaret(); // Never remove the last > if (e.KeyCode == Keys.Back) { if (txtApiConsole.Text[txtApiConsole.TextLength - 1] == '>') { e.SuppressKeyPress = true; } } if (e.KeyCode == Keys.Enter) { string[] splitStrings = txtApiConsole.Text.Split('>'); string trimmed = splitStrings[splitStrings.Length - 1].Trim(); // Only the last line starting with a > is needed // Avoid sending empty requests if (trimmed != string.Empty) { _apiCommands.Insert(0, trimmed); Dictionary <string, string>[] request = PruvotApi.Request(Rig.IpAddress, Rig.Port, trimmed); if (request != null) { txtApiConsole.AppendText(Environment.NewLine + JsonConvert.SerializeObject(request, Formatting.Indented) + Environment.NewLine + " > "); _apiCommandsIndex = 0; } } else { txtApiConsole.AppendText(Environment.NewLine + " > "); } e.SuppressKeyPress = true; } if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down) { if (string.IsNullOrEmpty(_stringBeforeUpOrDown)) { _stringBeforeUpOrDown = txtApiConsole.Lines[txtApiConsole.Lines.Length - 1]; // Keep the current string in memory when browsing through history of commands } StringBuilder sb = new StringBuilder(txtApiConsole.TextLength); for (int index = 0; index < txtApiConsole.Lines.Length - 1; index++) { sb.AppendLine(txtApiConsole.Lines[index]); } if (_apiCommands.Count > 0) { if (e.KeyCode == Keys.Up) { if (_apiCommandsIndex >= _apiCommands.Count) { _apiCommandsIndex = _apiCommands.Count - 1; } sb.AppendLine(" > " + _apiCommands[_apiCommandsIndex]); } else { _apiCommandsIndex -= 2; // -2 seems to give the most normal behavior if (_apiCommandsIndex < 0) { _apiCommandsIndex = -1; sb.AppendLine(_stringBeforeUpOrDown); } else { sb.AppendLine(" > " + _apiCommands[_apiCommandsIndex]); } } _apiCommandsIndex++; } else { sb.AppendLine(_stringBeforeUpOrDown); } txtApiConsole.Text = sb.ToString(0, sb.Length - 2); txtApiConsole.SelectionStart = txtApiConsole.TextLength; txtApiConsole.ScrollToCaret(); e.SuppressKeyPress = true; } else { _stringBeforeUpOrDown = string.Empty; } }