// TODO implement if all devices alive function check

        public static ApiData ParseApiDataFromApiDevsRoot(ApiDevsRoot apiDevsResult, AlgorithmType algorithmType, IEnumerable <BaseDevice> miningDevices, string logGroup)
        {
            var ad = new ApiData();

            if (apiDevsResult == null)
            {
                return(ad);
            }

            try
            {
                var deviveStats        = apiDevsResult.DEVS;
                var perDeviceSpeedInfo = new Dictionary <string, IReadOnlyList <AlgorithmTypeSpeedPair> >();
                var perDevicePowerInfo = new Dictionary <string, int>();
                var totalSpeed         = 0d;
                var totalPowerUsage    = 0;

                foreach (var gpu in miningDevices)
                {
                    var deviceStats = deviveStats
                                      .Where(devStat => gpu.ID == devStat.GPU)
                                      .FirstOrDefault();
                    if (deviceStats == null)
                    {
                        Logger.Info(logGroup, $"Device stats from api data are empty. Device: {gpu.UUID}");
                        continue;
                    }


                    var speedHS = deviceStats.KHS_5s * 1000;
                    totalSpeed += speedHS;
                    var algoSpeedPair = new AlgorithmTypeSpeedPair(algorithmType, speedHS);
                    perDeviceSpeedInfo.Add(gpu.UUID, new List <AlgorithmTypeSpeedPair>()
                    {
                        algoSpeedPair
                    });
                    // TODO check PowerUsage API
                }
                var totalAlgoSpeedPair = new AlgorithmTypeSpeedPair(algorithmType, totalSpeed);
                ad.AlgorithmSpeedsTotal = new List <AlgorithmTypeSpeedPair>()
                {
                    totalAlgoSpeedPair
                };
                ad.AlgorithmSpeedsPerDevice = perDeviceSpeedInfo;

                ad.PowerUsagePerDevice = perDevicePowerInfo;
                ad.PowerUsageTotal     = totalPowerUsage;
            }
            catch (Exception e)
            {
                Logger.Error(logGroup, $"Error occured while parsing API stats: {e.Message}");
            }

            return(ad);
        }
Exemplo n.º 2
0
        // TODO implement if all devices alive function check

        public static ApiData ParseApiDataFromApiDevsRoot(ApiDevsRoot apiDevsResult, AlgorithmType algorithmType, IEnumerable <BaseDevice> miningDevices)
        {
            var ad = new ApiData();

            if (apiDevsResult == null)
            {
                return(ad);
            }

            try
            {
                var deviveStats        = apiDevsResult.DEVS;
                var perDeviceSpeedInfo = new List <(string uuid, IReadOnlyList <(AlgorithmType, double)>)>();
                var perDevicePowerInfo = new List <(string, int)>();
                var totalSpeed         = 0d;
                var totalPowerUsage    = 0;

                foreach (var gpu in miningDevices)
                {
                    Console.WriteLine($"GPU_ID={gpu.ID}");
                    var deviceStats = deviveStats
                                      .Where(devStat => gpu.ID == devStat.GPU)
                                      .FirstOrDefault();
                    if (deviceStats == null)
                    {
                        Console.WriteLine($"SgminerAPIHelpers.ParseApiDataFromApiDevsRoot deviceStats == null");
                        continue;
                    }


                    var speedHS = deviceStats.KHS_5s * 1000;
                    totalSpeed += speedHS;
                    perDeviceSpeedInfo.Add((gpu.UUID, new List <(AlgorithmType, double)>()
                    {
                        (algorithmType, speedHS)
                    }));
                    // TODO check PowerUsage API
                }
                ad.AlgorithmSpeedsTotal = new List <(AlgorithmType, double)> {
                    (algorithmType, totalSpeed)
                };
                ad.PowerUsageTotal = totalPowerUsage;
            }
            catch (Exception ex)
            {
                Console.WriteLine($"SgminerAPIHelpers.ParseApiDataFromApiDevsRoot exception: {ex.Message}");
                //return null;
            }

            return(ad);
        }