Exemplo n.º 1
0
        private static void PickTotalShare(INTMinerRoot root, string input, IKernelOutput kernelOutput, ICoin coin, bool isDual)
        {
            string totalSharePattern = kernelOutput.TotalSharePattern;

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

            if (match.Success)
            {
                string totalShareText = match.Groups[NTKeyword.TotalShareGroupName].Value;
                if (int.TryParse(totalShareText, out int totalShare))
                {
                    ICoinShare share = root.CoinShareSet.GetOrCreate(coin.GetId());
                    root.CoinShareSet.UpdateShare(coin.GetId(), acceptShareCount: totalShare - share.RejectShareCount, rejectShareCount: null, now: DateTime.Now);
                }
            }
        }
Exemplo n.º 2
0
        private static void PicGotOneIncorrectShare(INTMinerContext context, IMineContext mineContext, string line, string preline, IKernelOutput kernelOutput)
        {
            string pattern = kernelOutput.GpuGotOneIncorrectShare;

            if (string.IsNullOrEmpty(pattern))
            {
                return;
            }
            if (pattern.Contains("\n"))
            {
                line = preline + "\n" + line;
            }
            Regex regex = VirtualRoot.GetRegex(pattern);
            var   match = regex.Match(line);

            if (match.Success)
            {
                string gpuText = match.Groups[NTKeyword.GpuIndexGroupName].Value;
                if (!string.IsNullOrEmpty(gpuText))
                {
                    if (int.TryParse(gpuText, out int gpuIndex))
                    {
                        if (IsMapGpuIndex(context, mineContext, kernelOutput) && gpuIndex < mineContext.UseDevices.Length)
                        {
                            gpuIndex = mineContext.UseDevices[gpuIndex];
                        }
                        context.GpusSpeed.IncreaseIncorrectShare(gpuIndex);
                    }
                }
            }
        }
Exemplo n.º 3
0
        private static void PicGotOneIncorrectShare(INTMinerContext root, IMineContext mineContext, string input, string preline, IKernelOutput kernelOutput)
        {
            string pattern = kernelOutput.GpuGotOneIncorrectShare;

            if (string.IsNullOrEmpty(pattern))
            {
                return;
            }
            if (pattern.Contains("\n"))
            {
                input = preline + "\n" + input;
            }
            Regex regex = VirtualRoot.GetRegex(pattern);
            var   match = regex.Match(input);

            if (match.Success)
            {
                string gpuText = match.Groups[NTKeyword.GpuIndexGroupName].Value;
                if (!string.IsNullOrEmpty(gpuText))
                {
                    if (int.TryParse(gpuText, out int gpuIndex))
                    {
                        if (kernelOutput.IsMapGpuIndex && !string.IsNullOrWhiteSpace(mineContext.KernelInput.DevicesArg))
                        {
                            if (mineContext.UseDevices.Length != 0 && mineContext.UseDevices.Length != root.GpuSet.Count && gpuIndex < mineContext.UseDevices.Length)
                            {
                                gpuIndex = mineContext.UseDevices[gpuIndex];
                            }
                        }
                        root.GpusSpeed.IncreaseIncorrectShare(gpuIndex);
                    }
                }
            }
        }
Exemplo n.º 4
0
        private static void PickRejectPattern(INTMinerContext root, string input, IKernelOutput kernelOutput, ICoin coin, bool isDual)
        {
            string rejectSharePattern = kernelOutput.RejectSharePattern;

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

            if (match.Success)
            {
                string rejectShareText = match.Groups[NTKeyword.RejectShareGroupName].Value;

                if (int.TryParse(rejectShareText, out int rejectShare))
                {
                    root.CoinShareSet.UpdateShare(coin.GetId(), acceptShareCount: null, rejectShareCount: rejectShare, now: DateTime.Now);
                }
            }
        }
Exemplo n.º 5
0
 private static bool TryGetClaymoreCommandLine(out string minerName, out string userWallet)
 {
     minerName  = string.Empty;
     userWallet = string.Empty;
     try {
         var lines = Windows.WMI.GetCommandLines("EthDcrMiner64.exe");
         if (lines.Count == 0)
         {
             return(false);
         }
         string       text             = string.Join(" ", lines) + " ";
         const string walletPattern    = @"-ewal\s+(\w+)\s";
         const string minerNamePattern = @"-eworker\s+(\w+)\s";
         Regex        regex            = VirtualRoot.GetRegex(walletPattern);
         var          matches          = regex.Matches(text);
         if (matches.Count != 0)
         {
             userWallet = matches[matches.Count - 1].Groups[1].Value;
         }
         regex   = VirtualRoot.GetRegex(minerNamePattern);
         matches = regex.Matches(text);
         if (matches.Count != 0)
         {
             minerName = matches[matches.Count - 1].Groups[1].Value;
         }
         return(!string.IsNullOrEmpty(minerName) && !string.IsNullOrEmpty(userWallet));
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(false);
     }
 }
Exemplo n.º 6
0
 public void Translate(Guid kernelOutputId, ref string input, bool isPre = false)
 {
     try {
         InitOnece();
         if (string.IsNullOrEmpty(input) || !_dicByKernelOutputId.TryGetValue(kernelOutputId, out List <KernelOutputTranslaterData> translaters))
         {
             return;
         }
         foreach (var consoleTranslater in translaters)
         {
             if (isPre && !consoleTranslater.IsPre)
             {
                 continue;
             }
             Regex regex = VirtualRoot.GetRegex(consoleTranslater.RegexPattern);
             if (regex == null)
             {
                 continue;
             }
             Match match = regex.Match(input);
             if (match.Success)
             {
                 string replacement = consoleTranslater.Replacement ?? string.Empty;
                 input = regex.Replace(input, replacement);
             }
         }
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
     }
 }
Exemplo n.º 7
0
 public void Filter(Guid kernelOutputId, ref string input)
 {
     try {
         InitOnece();
         if (string.IsNullOrEmpty(input) || !_dicByKernelOutputId.TryGetValue(kernelOutputId, out List <KernelOutputFilterData> filters))
         {
             return;
         }
         foreach (var kernelOutputFilter in filters)
         {
             Regex regex = VirtualRoot.GetRegex(kernelOutputFilter.RegexPattern);
             if (regex == null)
             {
                 continue;
             }
             Match match = regex.Match(input);
             if (match.Success)
             {
                 input = string.Empty;
                 break;
             }
         }
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
     }
 }
Exemplo n.º 8
0
        private static void PickTotalSpeed(INTMinerRoot 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;
                    }
                }
                double totalSpeed;
                if (double.TryParse(totalSpeedText, out totalSpeed))
                {
                    double     totalSpeedL = totalSpeed.FromUnitSpeed(totalSpeedUnit);
                    var        now         = DateTime.Now;
                    IGpusSpeed gpuSpeeds   = NTMinerRoot.Instance.GpusSpeed;
                    gpuSpeeds.SetCurrentSpeed(NTMinerRoot.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)
                        {
                            if (item.Gpu.Index != NTMinerRoot.GpuAllId)
                            {
                                gpuSpeeds.SetCurrentSpeed(item.Gpu.Index, gpuSpeedL, isDual, now);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 9
0
        private static void PickTotalSpeed(INTMinerContext context, string line, 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(line);

            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))
                {
                    totalSpeed = totalSpeed.FromUnitSpeed(totalSpeedUnit);
                    var        now       = DateTime.Now;
                    IGpusSpeed gpuSpeeds = NTMinerContext.Instance.GpusSpeed;
                    gpuSpeeds.SetCurrentSpeed(NTMinerContext.GpuAllId, totalSpeed, isDual, now);
                    string gpuSpeedPattern = kernelOutput.GpuSpeedPattern;
                    if (isDual)
                    {
                        gpuSpeedPattern = kernelOutput.DualGpuSpeedPattern;
                    }
                    // 如果没有单卡算力正则则平分总算力作为单卡算力正则
                    if ((string.IsNullOrEmpty(gpuSpeedPattern) || context.GpuSet.Count == 1) && context.GpuSet.Count != 0)
                    {
                        double gpuSpeed = totalSpeed / context.GpuSet.Count;
                        foreach (var item in gpuSpeeds.AsEnumerable())
                        {
                            if (item.Gpu.Index != NTMinerContext.GpuAllId)
                            {
                                gpuSpeeds.SetCurrentSpeed(item.Gpu.Index, gpuSpeed, isDual, now);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 10
0
        public void RegexReplaceTest()
        {
            Regex  regex = VirtualRoot.GetRegex(@"t=");
            string text  = @"11:55:42:201	384	ETH: GPU0 t=88 fan=77, GPU1 t=66 fan=99";

            text  = regex.Replace(text, "温度=");
            regex = VirtualRoot.GetRegex(@"fan=");
            text  = regex.Replace(text, "风扇=");
            Console.WriteLine(text);
        }
Exemplo n.º 11
0
        public void RegexTest3()
        {
            string line  = @"04:33:17:677	1b04	buf: {""result"":true,""id"":17}";
            Regex  regex = VirtualRoot.GetRegex(@"{""result"":true,""id"":1(?<gpu>\d+)}");
            var    match = regex.Match(line);

            Assert.IsTrue(match.Success);
            string gpuText = match.Groups[NTKeyword.GpuIndexGroupName].Value;

            Assert.AreEqual("7", gpuText);
            Assert.IsTrue(string.IsNullOrEmpty(match.Groups["aaa"].Value));
        }
Exemplo n.º 12
0
        public void RegexTest()
        {
            Regex           regex   = VirtualRoot.GetRegex(@"GPU(?<gpu>\d+) (?<gpuSpeed>[\d\.]+) (?<gpuSpeedUnit>.+?/s)");
            string          text    = @"11:55:42:201	384	ETH: GPU0 14.015 Mh/s, GPU1 21.048 Mh/s";
            MatchCollection matches = regex.Matches(text);

            foreach (Match match in matches)
            {
                Console.WriteLine(match.Groups["gpu"]);
                Console.WriteLine(match.Groups["gpuSpeed"]);
                Console.WriteLine(match.Groups["gpuSpeedUnit"]);
                Console.WriteLine("notexit=" + match.Groups["notexit"]);
            }
        }
Exemplo n.º 13
0
        public void RegexTest1()
        {
            string          line    = "11.1 h/s | 12.2 h/s | 13.3 h/s";
            Regex           regex   = VirtualRoot.GetRegex(@"(?<gpuSpeed>\d+\.?\d*) (?<gpuSpeedUnit>.+?/s)(?: \|)?");
            MatchCollection matches = regex.Matches(line);

            for (int gpuId = 0; gpuId < matches.Count; gpuId++)
            {
                Match  match        = matches[gpuId];
                string gpuSpeedUnit = match.Groups["gpuSpeedUnit"].Value;
                double.TryParse(match.Groups["gpuSpeed"].Value, out double gpuSpeed);
                Console.WriteLine($"GPU{gpuId.ToString()} {gpuSpeed.ToString()} {gpuSpeedUnit}");
            }
        }
Exemplo n.º 14
0
        public void RegexTest4()
        {
            string line    = @"17:18:33:747	a88	buf: {""result"":true,""id"":12}";
            string pattern = @"buf:.+(""result"":true,""id"":1(?<gpu>\d+))|(""id"":1(?<gpu>\d+),""result"":true)";
            var    regex   = VirtualRoot.GetRegex(pattern);
            var    match   = regex.Match(line);

            Assert.IsTrue(match.Success);
            Assert.AreEqual("2", match.Groups["gpu"].Value);
            line  = @"10:52:52:601	1158	buf: {""jsonrpc"":""2.0"",""id"":15,""result"":true}";
            regex = VirtualRoot.GetRegex(pattern);
            match = regex.Match(line);
            Assert.IsTrue(match.Success);
            Assert.AreEqual("5", match.Groups["gpu"].Value);
        }
Exemplo n.º 15
0
        private static void PickAcceptOneShare(INTMinerContext root, IMineContext mineContext, string input, string preline, IKernelOutput kernelOutput, ICoin coin, bool isDual)
        {
            string acceptOneShare = kernelOutput.AcceptOneShare;

            if (isDual)
            {
                acceptOneShare = kernelOutput.DualAcceptOneShare;
            }
            if (string.IsNullOrEmpty(acceptOneShare))
            {
                return;
            }
            if (acceptOneShare.Contains("\n"))
            {
                input = preline + "\n" + input;
            }
            Regex regex = VirtualRoot.GetRegex(acceptOneShare);
            var   match = regex.Match(input);

            if (match.Success)
            {
                if (!isDual)
                {
                    // 决定不支持双挖的单卡份额统计
                    string gpuText = match.Groups[NTKeyword.GpuIndexGroupName].Value;
                    if (!string.IsNullOrEmpty(gpuText))
                    {
                        if (int.TryParse(gpuText, out int gpuIndex))
                        {
                            if (kernelOutput.IsMapGpuIndex && !string.IsNullOrWhiteSpace(mineContext.KernelInput.DevicesArg))
                            {
                                if (mineContext.UseDevices.Length != 0 && mineContext.UseDevices.Length != root.GpuSet.Count && gpuIndex < mineContext.UseDevices.Length)
                                {
                                    gpuIndex = mineContext.UseDevices[gpuIndex];
                                }
                            }
                            if (string.IsNullOrEmpty(kernelOutput.FoundOneShare))
                            {
                                root.GpusSpeed.IncreaseFoundShare(gpuIndex);
                            }
                            root.GpusSpeed.IncreaseAcceptShare(gpuIndex);
                        }
                    }
                }
                ICoinShare share = root.CoinShareSet.GetOrCreate(coin.GetId());
                root.CoinShareSet.UpdateShare(coin.GetId(), acceptShareCount: share.AcceptShareCount + 1, rejectShareCount: null, now: DateTime.Now);
            }
        }
Exemplo n.º 16
0
        public void RegexTest2()
        {
            string line  = "Share accepted";
            Regex  regex = VirtualRoot.GetRegex(@"(Share accepted)|(GPU\s?(?<gpu>\d+).+\nShare accepted)");
            var    match = regex.Match(line);

            Assert.IsTrue(match.Success);
            string gpuText = match.Groups[NTKeyword.GpuIndexGroupName].Value;

            Assert.AreEqual("", gpuText);

            line  = "GPU 1: this is a test\nShare accepted";
            regex = VirtualRoot.GetRegex(@"(Share accepted)|(GPU\s?(?<gpu>\d+).+\nShare accepted)");
            match = regex.Match(line);
            Assert.IsTrue(match.Success);
            gpuText = match.Groups[NTKeyword.GpuIndexGroupName].Value;
            Assert.AreEqual("1", gpuText);
        }
Exemplo n.º 17
0
        public void RegexPerfomanceTest()
        {
            string text = @"11:55:42:201	384	ETH: GPU0 14.015 Mh/s, GPU1 21.048 Mh/s";

            NTStopwatch.Start();
            Regex regex = new Regex(@"GPU(?<gpu>\d+) (?<gpuSpeed>[\d\.]+) (?<gpuSpeedUnit>.+?/s)");

            for (int i = 0; i < 100; i++)
            {
                MatchCollection matches = regex.Matches(text);
                foreach (Match match in matches)
                {
                    var a = match.Groups["gpu"];
                    var b = match.Groups["gpuSpeed"];
                    var c = match.Groups["gpuSpeedUnit"];
                    var d = match.Groups["notexit"];
                }
            }
            var elapsedMilliseconds = NTStopwatch.Stop();

            Console.WriteLine($"非编译:耗时{elapsedMilliseconds}");

            string pattern = @"GPU(?<gpu>\d+) (?<gpuSpeed>[\d\.]+) (?<gpuSpeedUnit>.+?/s)";

            for (int i = 0; i < 1000; i++)
            {
                VirtualRoot.GetRegex(Guid.NewGuid().ToString());
            }
            NTStopwatch.Start();
            for (int i = 0; i < 100; i++)
            {
                MatchCollection matches = VirtualRoot.GetRegex(pattern).Matches(text);
                foreach (Match match in matches)
                {
                    var a = match.Groups["gpu"];
                    var b = match.Groups["gpuSpeed"];
                    var c = match.Groups["gpuSpeedUnit"];
                    var d = match.Groups["notexit"];
                }
            }
            elapsedMilliseconds = NTStopwatch.Stop();
            Console.WriteLine($"编译 :耗时{elapsedMilliseconds}");
        }
Exemplo n.º 18
0
        private static void PickPoolDelay(string input, IKernelOutput kernelOutput, bool isDual, Guid poolId)
        {
            string poolDelayPattern = kernelOutput.PoolDelayPattern;

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

            if (match.Success)
            {
                string poolDelayText = match.Groups[NTKeyword.PoolDelayGroupName].Value;
                VirtualRoot.RaiseEvent(new PoolDelayPickedEvent(poolId, isDual, poolDelayText));
            }
        }
Exemplo n.º 19
0
        private static void PickRejectPercent(INTMinerContext root, string input, IKernelOutput kernelOutput, ICoin coin, bool isDual)
        {
            string rejectPercentPattern = kernelOutput.RejectPercentPattern;

            if (isDual)
            {
                rejectPercentPattern = kernelOutput.DualRejectPercentPattern;
            }
            if (string.IsNullOrEmpty(rejectPercentPattern))
            {
                return;
            }
            Regex  regex             = VirtualRoot.GetRegex(rejectPercentPattern);
            var    match             = regex.Match(input);
            string rejectPercentText = match.Groups[NTKeyword.RejectPercentGroupName].Value;

            if (double.TryParse(rejectPercentText, out double rejectPercent))
            {
                ICoinShare share = root.CoinShareSet.GetOrCreate(coin.GetId());
                root.CoinShareSet.UpdateShare(coin.GetId(), acceptShareCount: null, rejectShareCount: (int)(share.TotalShareCount * rejectPercent), now: DateTime.Now);
            }
        }
Exemplo n.º 20
0
        private static void PicGpuRejectShare(INTMinerContext context, IMineContext mineContext, string line, IKernelOutput kernelOutput, bool isDual)
        {
            string gpuRejectSharePattern = kernelOutput.GpuRejectShare;

            if (isDual)
            {
                return;
            }
            if (string.IsNullOrEmpty(gpuRejectSharePattern))
            {
                return;
            }
            Regex regex = VirtualRoot.GetRegex(gpuRejectSharePattern);
            Match match = regex.Match(line);

            if (match.Success)
            {
                string gpuText         = match.Groups[NTKeyword.GpuIndexGroupName].Value;
                string rejectShareText = match.Groups[NTKeyword.RejectShareGroupName].Value;
                if (!string.IsNullOrEmpty(gpuText))
                {
                    if (int.TryParse(gpuText, out int gpuIndex))
                    {
                        if (IsMapGpuIndex(context, mineContext, kernelOutput) && gpuIndex < mineContext.UseDevices.Length)
                        {
                            gpuIndex = mineContext.UseDevices[gpuIndex];
                        }
                        if (!string.IsNullOrEmpty(rejectShareText))
                        {
                            if (int.TryParse(rejectShareText, out int rejectShare))
                            {
                                context.GpusSpeed.SetRejectShare(gpuIndex, rejectShare);
                                // TODO:如果gpuTotal的拒绝份额为0,求和拒绝份额
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 21
0
        private static void PickRejectOneShare(INTMinerContext root, IMineContext mineContext, string input, string preline, IKernelOutput kernelOutput, ICoin coin, bool isDual)
        {
            string rejectOneShare = kernelOutput.RejectOneShare;

            if (isDual)
            {
                rejectOneShare = kernelOutput.DualRejectOneShare;
            }
            if (string.IsNullOrEmpty(rejectOneShare))
            {
                return;
            }
            if (rejectOneShare.Contains("\n"))
            {
                input = preline + "\n" + input;
            }
            Regex regex = VirtualRoot.GetRegex(rejectOneShare);
            var   match = regex.Match(input);

            if (match.Success)
            {
                if (!isDual)
                {
                    // 决定不支持双挖的单卡份额统计
                    string gpuText = match.Groups[NTKeyword.GpuIndexGroupName].Value;
                    if (!string.IsNullOrEmpty(gpuText))
                    {
                        if (int.TryParse(gpuText, out int gpuIndex))
                        {
                            if (kernelOutput.IsMapGpuIndex && !string.IsNullOrWhiteSpace(mineContext.KernelInput.DevicesArg))
                            {
                                if (mineContext.UseDevices.Length != 0 && mineContext.UseDevices.Length != root.GpuSet.Count && gpuIndex < mineContext.UseDevices.Length)
                                {
                                    gpuIndex = mineContext.UseDevices[gpuIndex];
                                }
                            }
                            if (string.IsNullOrEmpty(kernelOutput.FoundOneShare))
                            {
                                root.GpusSpeed.IncreaseFoundShare(gpuIndex);
                            }
                            root.GpusSpeed.IncreaseRejectShare(gpuIndex);
                        }
                    }
                    else if (!string.IsNullOrEmpty(kernelOutput.FoundOneShare))
                    {
                        // 哪个GPU最近找到了一个share就是那个GPU拒绝了一个share
                        var       gpuSpeeds = root.GpusSpeed.AsEnumerable();
                        IGpuSpeed gpuSpeed  = null;
                        foreach (var item in gpuSpeeds)
                        {
                            if (gpuSpeed == null)
                            {
                                gpuSpeed = item;
                            }
                            else if (item.FoundShareOn > gpuSpeed.FoundShareOn)
                            {
                                gpuSpeed = item;
                            }
                        }
                        if (gpuSpeed != null)
                        {
                            var gpuIndex = gpuSpeed.Gpu.Index;
                            root.GpusSpeed.IncreaseRejectShare(gpuIndex);
                        }
                    }
                }
                ICoinShare share = root.CoinShareSet.GetOrCreate(coin.GetId());
                root.CoinShareSet.UpdateShare(coin.GetId(), null, share.RejectShareCount + 1, DateTime.Now);
            }
        }
Exemplo n.º 22
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);
                }
            }
        }