Example #1
0
        public async override Task <ApiData> GetMinerStatsDataAsync()
        {
            var summaryApiResult = await apiReader.GetApiDataAsync(_apiPort, ApiDataHelper.GetHttpRequestNhmAgentStrin("summary"));

            double totalSpeed = 0;
            int    totalPower = 0;

            if (!string.IsNullOrEmpty(summaryApiResult))
            {
                // TODO return empty
                try
                {
                    var summaryOptvals = summaryApiResult.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var optvalPairs in summaryOptvals)
                    {
                        var pair = optvalPairs.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
                        if (pair.Length != 2)
                        {
                            continue;
                        }
                        if (pair[0] == "KHS")
                        {
                            totalSpeed = double.Parse(pair[1], CultureInfo.InvariantCulture) * 1000; // HPS
                        }
                    }
                }
                catch
                { }
            }
            var ad    = new ApiData();
            var total = new List <(AlgorithmType, double)>();

            total.Add((_algorithmType, totalSpeed));
            ad.AlgorithmSpeedsTotal = total;
            ad.PowerUsageTotal      = totalPower;
            // cpuMiner is single device so no need for API

            return(ad);
        }
        public async override Task <ApiData> GetMinerStatsDataAsync()
        {
            var summaryApiResult = await apiReader.GetApiDataAsync(_apiPort, ApiDataHelper.GetHttpRequestNhmAgentStrin("summary"));

            double totalSpeed = 0;
            int    totalPower = 0;

            if (!string.IsNullOrEmpty(summaryApiResult))
            {
                // TODO return empty
                try
                {
                    var summaryOptvals = summaryApiResult.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var optvalPairs in summaryOptvals)
                    {
                        var pair = optvalPairs.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
                        if (pair.Length != 2)
                        {
                            continue;
                        }
                        if (pair[0] == "KHS")
                        {
                            totalSpeed = double.Parse(pair[1], CultureInfo.InvariantCulture) * 1000; // HPS
                        }
                    }
                }
                catch
                { }
            }
            // TODO if have multiple GPUs call the threads as well, but maybe not as often since it might crash the miner
            //var threadsApiResult = await _httpClient.GetStringAsync($"{localhost}/threads");
            var threadsApiResult = await apiReader.GetApiDataAsync(_apiPort, ApiDataHelper.GetHttpRequestNhmAgentStrin("threads"));

            var perDeviceSpeedInfo = new List <(string uuid, IReadOnlyList <(AlgorithmType, double)>)>();
            var perDevicePowerInfo = new List <(string, int)>();

            if (!string.IsNullOrEmpty(threadsApiResult))
            {
                // TODO return empty
                try
                {
                    var gpus = threadsApiResult.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var gpu in gpus)
                    {
                        var gpuOptvalPairs = gpu.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                        var gpuData        = (id : -1, power : -1, speed : -1d);
                        foreach (var optvalPairs in gpuOptvalPairs)
                        {
                            var optval = optvalPairs.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
                            if (optval.Length != 2)
                            {
                                continue;
                            }
                            if (optval[0] == "GPU")
                            {
                                gpuData.id = int.Parse(optval[1], CultureInfo.InvariantCulture);
                            }
                            if (optval[0] == "POWER")
                            {
                                gpuData.power = int.Parse(optval[1], CultureInfo.InvariantCulture);
                            }
                            if (optval[0] == "KHS")
                            {
                                gpuData.speed = double.Parse(optval[1], CultureInfo.InvariantCulture) * 1000; // HPS
                            }
                        }
                        // TODO do stuff with it gpuData
                        var device = _miningPairs.Where(kvp => kvp.device.ID == gpuData.id).Select(kvp => kvp.device).FirstOrDefault();
                        if (device != null)
                        {
                            perDeviceSpeedInfo.Add((device.UUID, new List <(AlgorithmType, double)>()
                            {
                                (_algorithmType, gpuData.speed)
                            }));
                            perDevicePowerInfo.Add((device.UUID, gpuData.power));
                            totalPower += gpuData.power;
                        }
                    }
                }
                catch
                { }
            }
            var ad    = new ApiData();
            var total = new List <(AlgorithmType, double)>();

            total.Add((_algorithmType, totalSpeed));
            ad.AlgorithmSpeedsTotal     = total;
            ad.PowerUsageTotal          = totalPower;
            ad.AlgorithmSpeedsPerDevice = perDeviceSpeedInfo;
            ad.PowerUsagePerDevice      = perDevicePowerInfo;

            return(ad);
        }
Example #3
0
        public async override Task <ApiData> GetMinerStatsDataAsync()
        {
            var api = new ApiData();

            try
            {
                var summaryApiResult = await apiReader.GetApiDataAsync(_apiPort, ApiDataHelper.GetHttpRequestNhmAgentStrin("summary"));

                double totalSpeed = 0;
                int    totalPower = 0;
                if (!string.IsNullOrEmpty(summaryApiResult))
                {
                    var summaryOptvals = summaryApiResult.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var optvalPairs in summaryOptvals)
                    {
                        var pair = optvalPairs.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
                        if (pair.Length != 2)
                        {
                            continue;
                        }
                        if (pair[0] == "KHS")
                        {
                            totalSpeed = double.Parse(pair[1], CultureInfo.InvariantCulture) * 1000; // HPS
                        }
                    }
                }

                var threadsApiResult = await apiReader.GetApiDataAsync(_apiPort, ApiDataHelper.GetHttpRequestNhmAgentStrin("threads"));

                var perDeviceSpeedInfo = new List <(string uuid, IReadOnlyList <(AlgorithmType, double)>)>();
                var perDevicePowerInfo = new List <(string, int)>();
                if (!string.IsNullOrEmpty(threadsApiResult))
                {
                    var gpus = threadsApiResult.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var gpu in gpus)
                    {
                        var gpuOptvalPairs = gpu.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                        var gpuData        = (id : -1, power : -1, speed : -1d);
                        foreach (var optvalPairs in gpuOptvalPairs)
                        {
                            var optval = optvalPairs.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
                            if (optval.Length != 2)
                            {
                                continue;
                            }
                            if (optval[0] == "GPU")
                            {
                                gpuData.id = int.Parse(optval[1], CultureInfo.InvariantCulture);
                            }
                            if (optval[0] == "POWER")
                            {
                                gpuData.power = int.Parse(optval[1], CultureInfo.InvariantCulture);
                            }
                            if (optval[0] == "KHS")
                            {
                                gpuData.speed = double.Parse(optval[1], CultureInfo.InvariantCulture) * 1000; // HPS
                            }
                        }

                        var device = _miningPairs.Where(kvp => kvp.device.ID == gpuData.id).Select(kvp => kvp.device).FirstOrDefault();
                        if (device != null)
                        {
                            perDeviceSpeedInfo.Add((device.UUID, new List <(AlgorithmType, double)>()
                            {
                                (_algorithmType, gpuData.speed)
                            }));
                            perDevicePowerInfo.Add((device.UUID, gpuData.power));
                            totalPower += gpuData.power;
                        }
                    }
                }
                var total = new List <(AlgorithmType, double)>();
                total.Add((_algorithmType, totalSpeed));
                api.AlgorithmSpeedsTotal     = total;
                api.PowerUsageTotal          = totalPower;
                api.AlgorithmSpeedsPerDevice = perDeviceSpeedInfo;
                api.PowerUsagePerDevice      = perDevicePowerInfo;
            }
            catch (Exception e)
            {
                Console.WriteLine($"exception: {e}");
            }
            return(api);
        }