public async override Task <ApiData> GetMinerStatsDataAsync() { var api = new ApiData(); try { var result = await _http.GetStringAsync($"http://127.0.0.1:{_apiPort}/stats"); var apiResponse = JsonConvert.DeserializeObject <JsonApiResponse>(result); var parsedApiResponse = JsonApiHelpers.ParseJsonApiResponse(apiResponse, _mappedIDs); var perDeviceSpeedInfo = new Dictionary <string, IReadOnlyList <AlgorithmTypeSpeedPair> >(); var perDevicePowerInfo = new Dictionary <string, int>(); var totalSpeed = 0d; var totalPowerUsage = 0; foreach (var miningPair in _miningPairs) { var deviceUUID = miningPair.Device.UUID; if (parsedApiResponse.ContainsKey(deviceUUID)) { var stat = parsedApiResponse[deviceUUID]; var currentPower = (int)stat.Power; totalPowerUsage += currentPower; var hashrate = stat.Hashrate * (1 - DevFee * 0.01); totalSpeed += hashrate; perDeviceSpeedInfo.Add(deviceUUID, new List <AlgorithmTypeSpeedPair>() { new AlgorithmTypeSpeedPair(_algorithmType, hashrate) }); perDevicePowerInfo.Add(deviceUUID, currentPower); } else { perDeviceSpeedInfo.Add(deviceUUID, new List <AlgorithmTypeSpeedPair>() { new AlgorithmTypeSpeedPair(_algorithmType, 0) }); perDevicePowerInfo.Add(deviceUUID, 0); } } api.AlgorithmSpeedsPerDevice = perDeviceSpeedInfo; api.AlgorithmSpeedsTotal = new List <AlgorithmTypeSpeedPair> { new AlgorithmTypeSpeedPair(_algorithmType, totalSpeed) }; api.PowerUsagePerDevice = perDevicePowerInfo; api.PowerUsageTotal = totalPowerUsage; } catch (Exception e) { Logger.Error(_logGroup, $"Error occured while getting API stats: {e.Message}"); } return(api); }
public async override Task <ApiData> GetMinerStatsDataAsync() { var api = new ApiData(); try { var result = await _http.GetStringAsync($"http://127.0.0.1:{_apiPort}/stats"); var summary = JsonConvert.DeserializeObject <JsonApiResponse>(result); var gpuDevices = _miningPairs.Select(pair => pair.Device); var perDeviceSpeedInfo = new Dictionary <string, IReadOnlyList <AlgorithmTypeSpeedPair> >(); var perDevicePowerInfo = new Dictionary <string, int>(); var totalSpeed = 0d; var totalPowerUsage = 0; var apiDevs = summary.Devices; var apiAlgos = summary.Algorithms; foreach (var miningPair in _miningPairs) { var deviceUUID = miningPair.Device.UUID; var minerID = _mappedIDs[deviceUUID]; var deviceData = apiDevs.FirstOrDefault().ToDictionary(x => x.Key, y => y.Value); deviceData.TryGetValue($"GPU {minerID}", out var gpuData); var currentPower = Convert.ToInt32(gpuData.Power); totalPowerUsage += currentPower; perDevicePowerInfo.Add(deviceUUID, currentPower); var algosData = apiAlgos.FirstOrDefault().ToDictionary(x => x.Key, y => y.Value).Values; algosData.FirstOrDefault().TryGetValue($"GPU {minerID}", out var algoData); var speed = algoData.ToString(); perDeviceSpeedInfo.Add(deviceUUID, new List <AlgorithmTypeSpeedPair>() { new AlgorithmTypeSpeedPair(_algorithmType, JsonApiHelpers.HashrateFromApiData(speed, _logGroup) * (1 - DevFee * 0.01)) }); algosData.FirstOrDefault().TryGetValue("Total", out var totalData); totalSpeed = JsonApiHelpers.HashrateFromApiData(totalData.ToString(), _logGroup); } api.AlgorithmSpeedsPerDevice = perDeviceSpeedInfo; api.AlgorithmSpeedsTotal = new List <AlgorithmTypeSpeedPair> { new AlgorithmTypeSpeedPair(_algorithmType, totalSpeed * (1 - DevFee * 0.01)) }; api.PowerUsagePerDevice = perDevicePowerInfo; api.PowerUsageTotal = totalPowerUsage; } catch (Exception e) { Logger.Error(_logGroup, $"Error occured while getting API stats: {e.Message}"); } return(api); }