예제 #1
0
        private static void PickTotalSpeed(INTMinerContext root, string input, IKernelOutput kernelOutput, bool isDual)
        {
            string totalSpeedPattern = kernelOutput.TotalSpeedPattern;

            if (isDual)
            {
                totalSpeedPattern = kernelOutput.DualTotalSpeedPattern;
            }
            if (string.IsNullOrEmpty(totalSpeedPattern))
            {
                return;
            }
            Regex regex = VirtualRoot.GetRegex(totalSpeedPattern);
            Match match = regex.Match(input);

            if (match.Success)
            {
                string totalSpeedText = match.Groups[NTKeyword.TotalSpeedGroupName].Value;
                string totalSpeedUnit = match.Groups[NTKeyword.TotalSpeedUnitGroupName].Value;
                if (string.IsNullOrEmpty(totalSpeedUnit))
                {
                    if (isDual)
                    {
                        totalSpeedUnit = kernelOutput.DualSpeedUnit;
                    }
                    else
                    {
                        totalSpeedUnit = kernelOutput.SpeedUnit;
                    }
                }
                if (double.TryParse(totalSpeedText, out double totalSpeed))
                {
                    double     totalSpeedL = totalSpeed.FromUnitSpeed(totalSpeedUnit);
                    var        now         = DateTime.Now;
                    IGpusSpeed gpuSpeeds   = NTMinerContext.Instance.GpusSpeed;
                    gpuSpeeds.SetCurrentSpeed(NTMinerContext.GpuAllId, totalSpeedL, isDual, now);
                    string gpuSpeedPattern = kernelOutput.GpuSpeedPattern;
                    if (isDual)
                    {
                        gpuSpeedPattern = kernelOutput.DualGpuSpeedPattern;
                    }
                    if (string.IsNullOrEmpty(gpuSpeedPattern) && root.GpuSet.Count != 0)
                    {
                        // 平分总算力
                        double gpuSpeedL = totalSpeedL / root.GpuSet.Count;
                        foreach (var item in gpuSpeeds.AsEnumerable())
                        {
                            if (item.Gpu.Index != NTMinerContext.GpuAllId)
                            {
                                gpuSpeeds.SetCurrentSpeed(item.Gpu.Index, gpuSpeedL, isDual, now);
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
        private static void PickGpuSpeed(INTMinerContext root, IMineContext mineContext, string input, IKernelOutput kernelOutput, bool isDual)
        {
            string gpuSpeedPattern = kernelOutput.GpuSpeedPattern;

            if (isDual)
            {
                gpuSpeedPattern = kernelOutput.DualGpuSpeedPattern;
            }
            if (string.IsNullOrEmpty(gpuSpeedPattern))
            {
                return;
            }
            var             now      = DateTime.Now;
            bool            hasGpuId = gpuSpeedPattern.Contains($"?<{NTKeyword.GpuIndexGroupName}>");
            Regex           regex    = VirtualRoot.GetRegex(gpuSpeedPattern);
            MatchCollection matches  = regex.Matches(input);

            if (matches.Count > 0)
            {
                IGpusSpeed gpuSpeeds = NTMinerContext.Instance.GpusSpeed;
                for (int i = 0; i < matches.Count; i++)
                {
                    Match  match        = matches[i];
                    string gpuSpeedText = match.Groups[NTKeyword.GpuSpeedGroupName].Value;
                    string gpuSpeedUnit = match.Groups[NTKeyword.GpuSpeedUnitGroupName].Value;
                    if (string.IsNullOrEmpty(gpuSpeedUnit))
                    {
                        if (isDual)
                        {
                            gpuSpeedUnit = kernelOutput.DualSpeedUnit;
                        }
                        else
                        {
                            gpuSpeedUnit = kernelOutput.SpeedUnit;
                        }
                    }
                    int gpu = i;
                    if (hasGpuId)
                    {
                        string gpuText = match.Groups[NTKeyword.GpuIndexGroupName].Value;
                        if (!int.TryParse(gpuText, out gpu))
                        {
                            gpu = i;
                        }
                        else
                        {
                            gpu -= kernelOutput.GpuBaseIndex;
                            if (gpu < 0)
                            {
                                continue;
                            }
                        }
                    }
                    if (kernelOutput.IsMapGpuIndex && !string.IsNullOrWhiteSpace(mineContext.KernelInput.DevicesArg))
                    {
                        if (mineContext.UseDevices.Length != 0 && mineContext.UseDevices.Length != root.GpuSet.Count && gpu < mineContext.UseDevices.Length)
                        {
                            gpu = mineContext.UseDevices[gpu];
                        }
                    }
                    if (double.TryParse(gpuSpeedText, out double gpuSpeed))
                    {
                        double gpuSpeedL = gpuSpeed.FromUnitSpeed(gpuSpeedUnit);
                        gpuSpeeds.SetCurrentSpeed(gpu, gpuSpeedL, isDual, now);
                    }
                }
                string totalSpeedPattern = kernelOutput.TotalSpeedPattern;
                if (isDual)
                {
                    totalSpeedPattern = kernelOutput.DualTotalSpeedPattern;
                }
                if (string.IsNullOrEmpty(totalSpeedPattern))
                {
                    // 求和分算力
                    double speed = isDual? gpuSpeeds.AsEnumerable().Where(a => a.Gpu.Index != NTMinerContext.GpuAllId).Sum(a => a.DualCoinSpeed.Value)
                                         : gpuSpeeds.AsEnumerable().Where(a => a.Gpu.Index != NTMinerContext.GpuAllId).Sum(a => a.MainCoinSpeed.Value);
                    gpuSpeeds.SetCurrentSpeed(NTMinerContext.GpuAllId, speed, isDual, now);
                }
            }
        }
예제 #3
0
            private GpuSpeedViewModels()
            {
                if (WpfUtil.IsInDesignMode)
                {
                    return;
                }
                this.GpuAllVm = GpuVms.Items.FirstOrDefault(a => a.Index == NTMinerContext.GpuAllId);
                IGpusSpeed gpuSpeeds = NTMinerContext.Instance.GpusSpeed;

                foreach (var item in gpuSpeeds.AsEnumerable())
                {
                    this._list.Add(new GpuSpeedViewModel(item));
                }
                _totalSpeedVm = this._list.FirstOrDefault(a => a.GpuVm.Index == NTMinerContext.GpuAllId);
                AddEventPath <GpuShareChangedEvent>("显卡份额变更后刷新VM内存", LogEnum.DevConsole,
                                                    action: message => {
                    ResetIfMainCoinSwitched();
                    int index = message.Source.Gpu.Index;
                    GpuSpeedViewModel gpuSpeedVm = _list.FirstOrDefault(a => a.GpuVm.Index == index);
                    if (gpuSpeedVm != null)
                    {
                        gpuSpeedVm.MainCoinSpeed.FoundShare  = message.Source.MainCoinSpeed.FoundShare;
                        gpuSpeedVm.MainCoinSpeed.AcceptShare = message.Source.MainCoinSpeed.AcceptShare;
                        gpuSpeedVm.MainCoinSpeed.RejectShare = message.Source.MainCoinSpeed.RejectShare;
                    }
                }, location: this.GetType());
                AddEventPath <FoundShareIncreasedEvent>("找到一个份额后刷新VM内存", LogEnum.DevConsole,
                                                        action: message => {
                    ResetIfMainCoinSwitched();
                    int index = message.Source.Gpu.Index;
                    GpuSpeedViewModel gpuSpeedVm = _list.FirstOrDefault(a => a.GpuVm.Index == index);
                    if (gpuSpeedVm != null)
                    {
                        gpuSpeedVm.MainCoinSpeed.FoundShare = message.Source.MainCoinSpeed.FoundShare;
                    }
                }, location: this.GetType());
                AddEventPath <AcceptShareIncreasedEvent>("接受一个份额后刷新VM内存", LogEnum.DevConsole,
                                                         action: message => {
                    ResetIfMainCoinSwitched();
                    int index = message.Source.Gpu.Index;
                    GpuSpeedViewModel gpuSpeedVm = _list.FirstOrDefault(a => a.GpuVm.Index == index);
                    if (gpuSpeedVm != null)
                    {
                        gpuSpeedVm.MainCoinSpeed.AcceptShare = message.Source.MainCoinSpeed.AcceptShare;
                    }
                }, location: this.GetType());
                AddEventPath <RejectShareIncreasedEvent>("拒绝一个份额后刷新VM内存", LogEnum.DevConsole,
                                                         action: message => {
                    ResetIfMainCoinSwitched();
                    int index = message.Source.Gpu.Index;
                    GpuSpeedViewModel gpuSpeedVm = _list.FirstOrDefault(a => a.GpuVm.Index == index);
                    if (gpuSpeedVm != null)
                    {
                        gpuSpeedVm.MainCoinSpeed.RejectShare = message.Source.MainCoinSpeed.RejectShare;
                    }
                }, location: this.GetType());
                AddEventPath <IncorrectShareIncreasedEvent>("产生一个错误份额后刷新VM内存", LogEnum.DevConsole,
                                                            action: message => {
                    ResetIfMainCoinSwitched();
                    int index = message.Source.Gpu.Index;
                    GpuSpeedViewModel gpuSpeedVm = _list.FirstOrDefault(a => a.GpuVm.Index == index);
                    if (gpuSpeedVm != null)
                    {
                        gpuSpeedVm.MainCoinSpeed.IncorrectShare = message.Source.MainCoinSpeed.IncorrectShare;
                    }
                }, location: this.GetType());
                AddEventPath <GpuSpeedChangedEvent>("显卡算力变更后刷新VM内存", LogEnum.DevConsole,
                                                    action: (message) => {
                    ResetIfMainCoinSwitched();
                    int index = message.Source.Gpu.Index;
                    GpuSpeedViewModel gpuSpeedVm = _list.FirstOrDefault(a => a.GpuVm.Index == index);
                    if (gpuSpeedVm != null)
                    {
                        if (message.IsDual)
                        {
                            gpuSpeedVm.DualCoinSpeed.UpdateSpeed(message.Source.DualCoinSpeed.Value, message.Source.DualCoinSpeed.SpeedOn);
                            gpuSpeedVm.OnPropertyChanged(nameof(gpuSpeedVm.AverageDualCoinSpeedText));
                        }
                        else
                        {
                            gpuSpeedVm.MainCoinSpeed.UpdateSpeed(message.Source.MainCoinSpeed.Value, message.Source.MainCoinSpeed.SpeedOn);
                            gpuSpeedVm.OnPropertyChanged(nameof(gpuSpeedVm.AverageMainCoinSpeedText));
                        }
                    }
                    if (index == _totalSpeedVm.GpuVm.Index)
                    {
                        var mineContext = NTMinerContext.Instance.LockedMineContext;
                        if (mineContext == null)
                        {
                            IncomeMainCoinPerDay    = 0;
                            IncomeMainCoinUsdPerDay = 0;
                            IncomeMainCoinCnyPerDay = 0;
                            IncomeDualCoinPerDay    = 0;
                            IncomeDualCoinUsdPerDay = 0;
                            IncomeDualCoinCnyPerDay = 0;
                        }
                        else
                        {
                            if (message.IsDual)
                            {
                                if (mineContext is IDualMineContext dualMineContext)
                                {
                                    IncomePerDay incomePerDay = NTMinerContext.Instance.CalcConfigSet.GetIncomePerHashPerDay(dualMineContext.DualCoin.Code);
                                    IncomeDualCoinPerDay      = _totalSpeedVm.DualCoinSpeed.Value * incomePerDay.IncomeCoin;
                                    IncomeDualCoinUsdPerDay   = _totalSpeedVm.DualCoinSpeed.Value * incomePerDay.IncomeUsd;
                                    IncomeDualCoinCnyPerDay   = _totalSpeedVm.DualCoinSpeed.Value * incomePerDay.IncomeCny;
                                }
                            }
                            else
                            {
                                IncomePerDay incomePerDay = NTMinerContext.Instance.CalcConfigSet.GetIncomePerHashPerDay(mineContext.MainCoin.Code);
                                IncomeMainCoinPerDay      = _totalSpeedVm.MainCoinSpeed.Value * incomePerDay.IncomeCoin;
                                IncomeMainCoinUsdPerDay   = _totalSpeedVm.MainCoinSpeed.Value * incomePerDay.IncomeUsd;
                                IncomeMainCoinCnyPerDay   = _totalSpeedVm.MainCoinSpeed.Value * incomePerDay.IncomeCny;
                            }
                        }
                    }
                }, location: this.GetType());
                AddEventPath <Per1SecondEvent>("每秒钟更新算力活动时间", LogEnum.None,
                                               action: message => {
                    TotalSpeedVm.MainCoinSpeed.OnPropertyChanged(nameof(SpeedViewModel.LastSpeedOnText));
                    TotalSpeedVm.DualCoinSpeed.OnPropertyChanged(nameof(SpeedViewModel.LastSpeedOnText));
                }, location: this.GetType());
            }