예제 #1
0
        public async Task TestGetByAlgorithmAndYear(MiningAlgorithm algo, int year)
        {
            var result = await _jsonHardwareProvider.GetHardwareByAlgorithmAndYear(algo, year);

            Assert.NotEmpty(result);
            Assert.All(result, item => Assert.True(item.Algorithm == algo && item.ProductionYear == year));
        }
예제 #2
0
            public void CalculateProfits(Dictionary <AlgorithmType, NiceHashSMA> NiceHashData)
            {
                // assume none is profitable
                MostProfitableKey = AlgorithmType.NONE;
                // calculate new profits
                foreach (var miningAlgo in Algorithms)
                {
                    AlgorithmType   key  = miningAlgo.Key;
                    MiningAlgorithm algo = miningAlgo.Value;
                    if (NiceHashData.ContainsKey(key))
                    {
                        algo.CurNhmSMADataVal = NiceHashData[key].paying;
                        algo.CurrentProfit    = algo.CurNhmSMADataVal * algo.AvaragedSpeed * 0.000000001;
                    }
                    else
                    {
                        algo.CurrentProfit = 0;
                    }
                }
                // find max paying value and save key
                double maxProfit = 0;

                foreach (var miningAlgo in Algorithms)
                {
                    AlgorithmType   key  = miningAlgo.Key;
                    MiningAlgorithm algo = miningAlgo.Value;
                    if (maxProfit < algo.CurrentProfit)
                    {
                        maxProfit         = algo.CurrentProfit;
                        MostProfitableKey = key;
                    }
                }
            }
예제 #3
0
        public async Task TestGetByAlgorithm(MiningAlgorithm algo)
        {
            var result = await _jsonHardwareProvider.GetHardwareByMiningAlgorithm(algo);

            Assert.NotEmpty(result);
            Assert.All(result, item => Assert.True(item.Algorithm == algo));
        }
예제 #4
0
 public MiningDevice(ComputeDevice device)
 {
     Device = device;
     foreach (var kvp in Device.DeviceBenchmarkConfig.AlgorithmSettings)
     {
         AlgorithmType key  = kvp.Key;
         Algorithm     algo = kvp.Value;
         if (IsAlgoMiningCapable(algo))
         {
             Algorithms[key] = new MiningAlgorithm(algo);
         }
     }
 }
예제 #5
0
        public MiningSession(List <ComputeDevice> devices,
                             IMainFormRatesComunication mainFormRatesComunication,
                             string miningLocation, string worker, string btcAdress)
        {
            // init fixed
            _mainFormRatesComunication = mainFormRatesComunication;
            _miningLocation            = miningLocation;

            if (worker.Length > 0)
            {
                _workerBtcStringWorker = btcAdress + "." + worker;
            }
            else
            {
                _workerBtcStringWorker = btcAdress;
            }

            // initial settup
            {
                // used for logging
                List <Tuple <ComputeDevice, DeviceMiningStatus> > disabledDevicesStatuses = new List <Tuple <ComputeDevice, DeviceMiningStatus> >();
                // logging and settup
                List <ComputeDevice> enabledDevices = new List <ComputeDevice>();
                // get enabled devices
                {
                    // check passed devices statuses
                    List <Tuple <ComputeDevice, DeviceMiningStatus> > devicesStatuses = new List <Tuple <ComputeDevice, DeviceMiningStatus> >();
                    foreach (var device in devices)
                    {
                        devicesStatuses.Add(getDeviceMiningStatus(device));
                    }
                    // sort device statuses
                    foreach (var deviceStatus in devicesStatuses)
                    {
                        if (deviceStatus.Item2 == DeviceMiningStatus.CanMine)
                        {
                            enabledDevices.Add(deviceStatus.Item1);
                        }
                        else
                        {
                            disabledDevicesStatuses.Add(deviceStatus);
                        }
                    }
                }
                // print statuses
                if (disabledDevicesStatuses.Count > 0)
                {
                    Helpers.ConsolePrint(TAG, "Disabled Devices:");
                    foreach (var deviceStatus in disabledDevicesStatuses)
                    {
                        ComputeDevice      device = deviceStatus.Item1;
                        DeviceMiningStatus status = deviceStatus.Item2;
                        if (status == DeviceMiningStatus.DeviceNull)
                        {
                            Helpers.ConsolePrint(TAG, "Critical Device is NULL");
                        }
                        else if (status == DeviceMiningStatus.Disabled)
                        {
                            Helpers.ConsolePrint(TAG, String.Format("DISABLED ({0})", device.GetFullName()));
                        }
                        else if (status == DeviceMiningStatus.NoEnabledAlgorithms)
                        {
                            Helpers.ConsolePrint(TAG, String.Format("No Enabled Algorithms ({0})", device.GetFullName()));
                        }
                    }
                }
                if (enabledDevices.Count > 0)
                {
                    // print enabled
                    Helpers.ConsolePrint(TAG, "Enabled Devices for Mining session:");
                    foreach (var device in enabledDevices)
                    {
                        Helpers.ConsolePrint(TAG, String.Format("ENABLED ({0})", device.GetFullName()));
                        foreach (var algo in device.DeviceBenchmarkConfig.AlgorithmSettings.Values)
                        {
                            var isEnabled = IsAlgoMiningCapable(algo);
                            Helpers.ConsolePrint(TAG, String.Format("\t\tALGORITHM {0} ({1})",
                                                                    isEnabled ? "ENABLED " : "DISABLED", // ENABLED/DISABLED
                                                                    AlgorithmNiceHashNames.GetName(algo.NiceHashID)));
                        }
                    }
                    // settup mining devices
                    foreach (var device in enabledDevices)
                    {
                        _miningDevices.Add(new MiningDevice(device));
                    }
                }
            }
            if (_miningDevices.Count > 0)
            {
                // calculate avarage speeds, to ensure mining stability
                // device name, algo key, algos refs list
                Dictionary <string,
                            Dictionary <AlgorithmType,
                                        List <MiningAlgorithm> > > avarager = new Dictionary <string, Dictionary <AlgorithmType, List <MiningAlgorithm> > >();
                // init empty avarager
                foreach (var device in _miningDevices)
                {
                    string devName = device.Device.Name;
                    avarager[devName] = new Dictionary <AlgorithmType, List <MiningAlgorithm> >();
                    foreach (var key in AlgorithmNiceHashNames.GetAllAvaliableTypes())
                    {
                        avarager[devName][key] = new List <MiningAlgorithm>();
                    }
                }
                // fill avarager
                foreach (var device in _miningDevices)
                {
                    string devName = device.Device.Name;
                    foreach (var kvp in device.Algorithms)
                    {
                        var             key  = kvp.Key;
                        MiningAlgorithm algo = kvp.Value;
                        avarager[devName][key].Add(algo);
                    }
                }
                // calculate avarages
                foreach (var devDict in avarager.Values)
                {
                    foreach (List <MiningAlgorithm> miningAlgosList in devDict.Values)
                    {
                        // if list not empty calculate avarage
                        if (miningAlgosList.Count > 0)
                        {
                            // calculate avarage
                            double sum = 0;
                            foreach (var algo in miningAlgosList)
                            {
                                sum += algo.AvaragedSpeed;
                            }
                            double avarageSpeed = sum / miningAlgosList.Count;
                            // set avarage
                            foreach (var algo in miningAlgosList)
                            {
                                algo.AvaragedSpeed = avarageSpeed;
                            }
                        }
                    }
                }
            }

            // init timer stuff
            _preventSleepTimer          = new Timer();
            _preventSleepTimer.Elapsed += PreventSleepTimer_Tick;
            // sleep time is minimal 1 minute
            _preventSleepTimer.Interval = 20 * 1000; // leave this interval, it works

            // set internet checking
            _internetCheckTimer          = new Timer();
            _internetCheckTimer.Elapsed += InternetCheckTimer_Tick;
            _internetCheckTimer.Interval = 1000 * 30 * 1; // every minute or 5?? // 1000 * 60 * 1

            _miningStatusCheckTimer          = new Timer();
            _miningStatusCheckTimer.Elapsed += MiningStatusCheckTimer_Tick;
            _miningStatusCheckTimer.Interval = 1000 * 30;

            // assume profitable
            IsProfitable = true;
            // assume we have internet
            IsConnectedToInternet = true;

            if (IsMiningEnabled)
            {
                _preventSleepTimer.Start();
                _internetCheckTimer.Start();
                _miningStatusCheckTimer.Start();
            }

            IsMiningRegardlesOfProfit = ConfigManager.Instance.GeneralConfig.MinimumProfit == 0;
        }
예제 #6
0
        public async Task TestGetByAlgorithmReturnsEMpty(MiningAlgorithm algo)
        {
            var result = await _jsonHardwareProvider.GetHardwareByMiningAlgorithm(algo);

            Assert.Empty(result);
        }
예제 #7
0
        public async Task TestGetByAlgorithmAndYearReturnsEmpty(MiningAlgorithm algo, int year)
        {
            var result = await _jsonHardwareProvider.GetHardwareByAlgorithmAndYear(algo, year);

            Assert.Empty(result);
        }
예제 #8
0
        public async Task <List <MiningDevice> > GetHardwareByAlgorithmAndYear(MiningAlgorithm algorithm, int year)
        {
            var devices = await GetAll();

            return(devices.Where(i => i.Algorithm == algorithm && i.ProductionYear == year).ToList());
        }
예제 #9
0
        public async Task <List <MiningDevice> > GetHardwareByMiningAlgorithm(MiningAlgorithm algorithm = MiningAlgorithm.SHA256)
        {
            var devices = await GetAll();

            return(devices.Where(i => i.Algorithm == algorithm).ToList());
        }
예제 #10
0
 public async Task <List <MiningDevice> > GetHardwareByMiningAlgorithm(MiningAlgorithm algorithm)
 {
     return(await jsonHardwareProvider.GetHardwareByMiningAlgorithm(algorithm));
 }
예제 #11
0
 public async Task <List <MiningDevice> > GetHardwareByAlgorithmAndYear(MiningAlgorithm algorithm, int year)
 {
     return(await jsonHardwareProvider.GetHardwareByAlgorithmAndYear(algorithm, year));
 }