示例#1
0
        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);
                }
            }
        }