Esempio n. 1
0
        private static void UpdateMinerMiningStats(ApiData apiData, string minerUUID, string minerName, string groupKey, Dictionary <AlgorithmType, double> payingRates)
        {
            MinerMiningStats stat;

            if (_minersMiningStats.TryGetValue(groupKey, out stat) == false)
            {
                // create if it doesn't exist
                stat = new MinerMiningStats {
                    GroupKey = groupKey, MinerName = minerName
                };
                _minersMiningStats[groupKey] = stat;
            }

            var deviceUUIDs = apiData.AlgorithmSpeedsPerDevice
                              .Select(speedInfo => speedInfo.Key)
                              .ToArray();

            stat.Clear();
            // add device UUIDs
            foreach (var deviceUuid in deviceUUIDs)
            {
                stat.DeviceUUIDs.Add(deviceUuid);
            }

            // update stat
            stat.PowerUsageAPI = (double)apiData.PowerUsageTotal / 1000d;
            foreach (var speedInfo in apiData.AlgorithmSpeedsTotal())
            {
                stat.Speeds.Add(speedInfo);
                if (payingRates.TryGetValue(speedInfo.type, out var paying) == false)
                {
                    continue;
                }
                var payingRate = paying * speedInfo.speed * 0.000000001;
                stat.Rates.Add((speedInfo.type, payingRate));
            }
            var    relevantDevices                 = AvailableDevices.Devices.Where(dev => deviceUUIDs.Contains(dev.Uuid)).ToArray();
            double powerUsageFromDevice            = relevantDevices.Select(dev => dev.PowerUsage).Sum();
            double powerUsageFromAlgorithmSettings = relevantDevices
                                                     .Select(dev => (dev, speeds: apiData.AlgorithmSpeedsPerDevice[dev.Uuid]))
                                                     .Select(p => (p.dev, algoIds: p.speeds.Select(info => info.type).ToArray()))
                                                     .Select(p => p.dev.GetAlgorithm(minerUUID, p.algoIds))
                                                     .Where(algo => algo != null)
                                                     .Select(algo => algo.PowerUsage)
                                                     .Sum();

            stat.PowerUsageDeviceReading    = powerUsageFromDevice;
            stat.PowerUsageAlgorithmSetting = powerUsageFromAlgorithmSettings;
        }