Exemplo n.º 1
0
        private bool CheckIfShouldMine(double CurrentProfit, bool log = true)
        {
            // if profitable and connected to internet mine
            bool shouldMine = CheckIfProfitable(CurrentProfit, log) && IsConnectedToInternet;

            if (shouldMine)
            {
                _mainFormRatesComunication.HideNotProfitable();
            }
            else
            {
                if (!IsConnectedToInternet)
                {
                    // change msg
                    if (log)
                    {
                        Helpers.ConsolePrint(TAG, "NO INTERNET!!! Stopping mining.");
                    }
                    _mainFormRatesComunication.ShowNotProfitable(International.GetText("Form_Main_MINING_NO_INTERNET_CONNECTION"));
                }
                else
                {
                    _mainFormRatesComunication.ShowNotProfitable(International.GetText("Form_Main_MINING_NOT_PROFITABLE"));
                }
                // return don't group
                StopAllMinersNonProfitable();
            }
            return(shouldMine);
        }
        private bool CheckIfShouldMine(double currentProfit, bool log = true)
        {
            // if profitable and connected to internet mine
            var shouldMine = CheckIfProfitable(currentProfit, log) && _isConnectedToInternet;

            if (shouldMine)
            {
                _mainFormRatesComunication.HideNotProfitable();
            }
            else
            {
                if (!_isConnectedToInternet)
                {
                    // change msg
                    if (log)
                    {
                        Helpers.ConsolePrint(Tag, "NO INTERNET!!! Stopping mining.");
                    }
                    _mainFormRatesComunication.ShowNotProfitable(
                        Translations.Tr("CURRENTLY NOT MINING. NO INTERNET CONNECTION."));
                }
                else
                {
                    _mainFormRatesComunication.ShowNotProfitable(
                        Translations.Tr("CURRENTLY MINING NOT PROFITABLE."));
                }

                // return don't group
                StopAllMinersNonProfitable();
            }

            return(shouldMine);
        }
Exemplo n.º 3
0
        /// <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);
            }
        }