public bool StartInitialize(IMainFormRatesComunication mainFormRatesComunication, string miningLocation, string worker, string btcAdress) { _mainFormRatesComunication = mainFormRatesComunication; _miningLocation = miningLocation; _worker = worker; _btcAdress = btcAdress; if (_worker.Length > 0) { _workerBtcStringWorker = _btcAdress + "." + _worker; } else { _workerBtcStringWorker = _btcAdress; } _perDeviceSpeedDictionary = GetEnabledDeviceTypeSpeeds(); //_groupedDevicesMiners = new Dictionary<GroupedDevices, GroupMiners>(); _groupedDevicesMiners = new Dictionary <string, GroupMiners>(); _enabledDevices = new List <ComputeDevice>(); _currentAllGroupedDevices = new AllGroupedDevices(); // assume profitable IsProfitable = true; // this checks if there are enabled devices and enabled algorithms bool isMiningEnabled = false; foreach (var cdev in ComputeDevice.AllAvaliableDevices) { if (cdev.Enabled) { _enabledDevices.Add(cdev); // check if in CPU group and add the saved CPU miners if (cdev.DeviceGroupType == DeviceGroupType.CPU) { GroupedDevices gdevs = new GroupedDevices(); gdevs.Add(cdev.UUID); cpuminer miner = _cpuMiners[cdev.Group]; CpuGroupMiner cpuGroupMiner = new CpuGroupMiner(gdevs, miner); _groupedDevicesMiners.Add(CalcGroupedDevicesKey(gdevs), cpuGroupMiner); } // check if any algorithm enabled if (!isMiningEnabled) { foreach (var algorithm in cdev.DeviceBenchmarkConfig.AlgorithmSettings) { if (!algorithm.Value.Skip) { isMiningEnabled = true; break; } } } } } if (isMiningEnabled) { _preventSleepTimer.Start(); } IsCurrentlyIdle = !isMiningEnabled; return(isMiningEnabled); }
/// <summary> /// SwichMostProfitable should check the best combination for most profit. /// Calculate profit for each supported algorithm per device group. /// Build from ground up compatible devices and algorithms. /// See #region Groupping logic /// Device groups are CPU, AMD_OpenCL and NVIDIA CUDA SM.x.x. /// NVIDIA SMx.x should be paired separately except for daggerhashimoto. /// </summary> /// <param name="NiceHashData"></param> public void SwichMostProfitableGroupUpMethod(Dictionary <AlgorithmType, NiceHashSMA> NiceHashData) { var devProfits = GetEnabledDeviceProifitDictionary(_perDeviceSpeedDictionary, NiceHashData); #if (SWITCH_TESTING) SwitchTesting.Instance.SetNext(ref devProfits, _enabledDevices); #endif double CurrentProfit = 0.0d; // calculate most profitable algorithm per enabled device foreach (var cdev in _enabledDevices) { var curDevProfits = devProfits[cdev.UUID]; double maxProfit = double.MinValue; AlgorithmType maxAlgorithmTypeKey = AlgorithmType.NONE; var algorithmSettings = cdev.DeviceBenchmarkConfig.AlgorithmSettings; foreach (var kvpTypeProfit in curDevProfits) { if (algorithmSettings.ContainsKey(kvpTypeProfit.Key) && !algorithmSettings[kvpTypeProfit.Key].Skip && kvpTypeProfit.Value > 0.0d && maxProfit < kvpTypeProfit.Value) { // extra check if current device can't handle dagger if (AlgorithmType.DaggerHashimoto == kvpTypeProfit.Key && !cdev.IsEtherumCapale) { continue; } maxProfit = kvpTypeProfit.Value; maxAlgorithmTypeKey = kvpTypeProfit.Key; } } if (maxAlgorithmTypeKey == AlgorithmType.NONE) { cdev.MostProfitableAlgorithm = null; } else { cdev.MostProfitableAlgorithm = algorithmSettings[maxAlgorithmTypeKey]; // add most profitable to cumulative profit CurrentProfit += maxProfit; } } // now if profitable check // TODO FOR NOW USD ONLY var currentProfitUSD = (CurrentProfit * Globals.BitcoinRate); Helpers.ConsolePrint(TAG, "Current Global profit: " + currentProfitUSD.ToString("F8") + " USD/Day"); if (ConfigManager.Instance.GeneralConfig.MinimumProfit > 0 && currentProfitUSD < ConfigManager.Instance.GeneralConfig.MinimumProfit) { IsProfitable = false; IsCurrentlyIdle = true; _mainFormRatesComunication.ShowNotProfitable(); // return don't group StopAllMinersNonProfitable(); Helpers.ConsolePrint(TAG, "Current Global profit: NOT PROFITABLE MinProfit " + ConfigManager.Instance.GeneralConfig.MinimumProfit.ToString("F8") + " USD/Day"); return; } else { IsProfitable = true; IsCurrentlyIdle = false; _mainFormRatesComunication.HideNotProfitable(); string profitabilityInfo = ConfigManager.Instance.GeneralConfig.MinimumProfit == 0 ? "mine always regardless of profit" : ConfigManager.Instance.GeneralConfig.MinimumProfit.ToString("F8") + " USD/Day"; Helpers.ConsolePrint(TAG, "Current Global profit: IS PROFITABLE MinProfit " + profitabilityInfo); } // group devices with same supported algorithms _previousAllGroupedDevices = _currentAllGroupedDevices; _currentAllGroupedDevices = new AllGroupedDevices(); Dictionary <GroupedDevices, Algorithm> newGroupAndAlgorithm = new Dictionary <GroupedDevices, Algorithm>(); for (int first = 0; first < _enabledDevices.Count; ++first) { var firstDev = _enabledDevices[first]; // skip if no algorithm is profitable if (firstDev.MostProfitableAlgorithm == null) { Helpers.ConsolePrint("SwichMostProfitableGroupUpMethod", String.Format("Device {0}, MostProfitableAlgorithm == null", firstDev.Name)); continue; } // check if is in group bool isInGroup = false; foreach (var groupedDevices in _currentAllGroupedDevices) { if (groupedDevices.Contains(firstDev.UUID)) { isInGroup = true; break; } } if (isInGroup) { continue; } var newGroup = new GroupedDevices(); newGroup.Add(firstDev.UUID); for (int second = first + 1; second < _enabledDevices.Count; ++second) { var secondDev = _enabledDevices[second]; // first check if second device has profitable algorithm if (secondDev.MostProfitableAlgorithm != null) { // check if we should group if (IsDaggerAndSameComputePlatform(firstDev, secondDev) || IsGroupBinaryAndAlgorithmSame(firstDev, secondDev)) { newGroup.Add(secondDev.UUID); } } } _currentAllGroupedDevices.Add(newGroup); newGroupAndAlgorithm.Add(newGroup, firstDev.MostProfitableAlgorithm); } // stop groupes that aren't in current group devices foreach (var curPrevGroup in _previousAllGroupedDevices) { var curPrevGroupKey = CalcGroupedDevicesKey(curPrevGroup); bool contains = false; foreach (var curCheckGroup in _currentAllGroupedDevices) { var curCheckGroupKey = CalcGroupedDevicesKey(curCheckGroup); if (curPrevGroupKey == curCheckGroupKey) { contains = true; break; } } if (!contains) { _groupedDevicesMiners[curPrevGroupKey].Stop(); } } // switch to newGroupAndAlgorithm most profitable algorithm foreach (var kvpGroupAlgorithm in newGroupAndAlgorithm) { var group = kvpGroupAlgorithm.Key; var algorithm = kvpGroupAlgorithm.Value; GroupMiners currentGroupMiners; // try find if it doesn't exist create new string groupStringKey = CalcGroupedDevicesKey(group); if (!_groupedDevicesMiners.TryGetValue(groupStringKey, out currentGroupMiners)) { currentGroupMiners = new GroupMiners(group); _groupedDevicesMiners.Add(groupStringKey, currentGroupMiners); } currentGroupMiners.StartAlgorihtm(algorithm, _miningLocation, _workerBtcStringWorker); } // stats quick fix code if (_currentAllGroupedDevices.Count != _previousAllGroupedDevices.Count) { MinerStatsCheck(NiceHashData); } }
public bool StartInitialize(IMainFormRatesComunication mainFormRatesComunication, string miningLocation, string worker, string btcAdress) { _mainFormRatesComunication = mainFormRatesComunication; _miningLocation = miningLocation; _worker = worker; _btcAdress = btcAdress; if (_worker.Length > 0) { _workerBtcStringWorker = _btcAdress + "." + _worker; } else { _workerBtcStringWorker = _btcAdress; } _perDeviceSpeedDictionary = GetEnabledDeviceTypeSpeeds(); //_groupedDevicesMiners = new Dictionary<GroupedDevices, GroupMiners>(); _groupedDevicesMiners = new Dictionary <string, GroupMiners>(); _enabledDevices = new List <ComputeDevice>(); _currentAllGroupedDevices = new AllGroupedDevices(); // assume profitable IsProfitable = true; // assume we have internet IsConnectedToInternet = true; // this checks if there are enabled devices and enabled algorithms bool isMiningEnabled = false; foreach (var cdev in ComputeDevice.AllAvaliableDevices) { if (cdev.Enabled) { _enabledDevices.Add(cdev); // check if any algorithm enabled if (!isMiningEnabled) { foreach (var algorithm in cdev.DeviceBenchmarkConfig.AlgorithmSettings) { if (!algorithm.Value.Skip) { isMiningEnabled = true; break; } } } } } if (isMiningEnabled) { _preventSleepTimer.Start(); _internetCheckTimer.Start(); } IsCurrentlyIdle = !isMiningEnabled; return(isMiningEnabled); }