protected override void BenchmarkThreadRoutineStartSettup() { AlgorithmType nhDataIndex = BenchmarkAlgorithm.NiceHashID; if (!NHSmaData.HasData) { Helpers.ConsolePrint("BENCHMARK", "Skipping mkxminer benchmark because there is no internet " + "connection. mkxminer needs internet connection to do benchmarking."); throw new Exception("No internet connection"); } NHSmaData.TryGetPaying(nhDataIndex, out var paying); if (paying == 0) { Helpers.ConsolePrint("BENCHMARK", "Skipping mkxminer benchmark because there is no work on Nicehash.com " + "[algo: " + BenchmarkAlgorithm.AlgorithmName + "(" + nhDataIndex + ")]"); throw new Exception("No work can be used for benchmarking"); } _benchmarkTimer.Reset(); _benchmarkTimer.Start(); // call base, read only outpus //BenchmarkHandle.BeginOutputReadLine(); }
public async Task MinerStatsCheck() { var currentProfit = 0.0d; _mainFormRatesComunication.ClearRates(_runningGroupMiners.Count); var checks = new List <GroupMiner>(_runningGroupMiners.Values); try { foreach (var groupMiners in checks) { var m = groupMiners.Miner; // skip if not running or if await already in progress if (!m.IsRunning || m.IsUpdatingApi) { continue; } m.IsUpdatingApi = true; var ad = await m.GetSummaryAsync(); m.IsUpdatingApi = false; if (ad == null) { Helpers.ConsolePrint(m.MinerTag(), "GetSummary returned null.."); } // set rates if (ad != null && NHSmaData.TryGetPaying(ad.AlgorithmID, out var paying)) { groupMiners.CurrentRate = paying * ad.Speed * 0.000000001; if (NHSmaData.TryGetPaying(ad.SecondaryAlgorithmID, out var secPaying)) { groupMiners.CurrentRate += secPaying * ad.SecondarySpeed * 0.000000001; } // Deduct power costs var powerUsage = ad.PowerUsage > 0 ? ad.PowerUsage : groupMiners.TotalPower; groupMiners.CurrentRate -= ExchangeRateApi.GetKwhPriceInBtc() * powerUsage * 24 / 1000; groupMiners.PowerRate = ExchangeRateApi.GetKwhPriceInBtc() * powerUsage * 24 / 1000; } else { groupMiners.CurrentRate = 0; // set empty ad = new ApiData(groupMiners.AlgorithmType); } currentProfit += groupMiners.CurrentRate; // Update GUI _mainFormRatesComunication.AddRateInfo(m.MinerTag(), groupMiners.DevicesInfoString, ad, groupMiners.CurrentRate, groupMiners.PowerRate, m.IsApiReadException); } } catch (Exception e) { Helpers.ConsolePrint(Tag, e.Message); } }
public void Paying_ShouldReturnCorrectAndFlagsAreSet() { var testPaying = new Dictionary <AlgorithmType, double> { { AlgorithmType.CryptoNight, 0.11 }, { AlgorithmType.DaggerHashimoto, 0.9 }, { AlgorithmType.Blake2s, 0 } }; var testZero = new List <AlgorithmType> { AlgorithmType.Keccak, AlgorithmType.Equihash, AlgorithmType.Pascal }; // Check initialized flag and initialize NHSmaData.Initialize(); Assert.IsTrue(NHSmaData.Initialized); // Check hasdata flag and update with test data NHSmaData.UpdateSmaPaying(testPaying); Assert.IsTrue(NHSmaData.HasData); foreach (var algo in testPaying.Keys) { // Every key from test dict should return true and paying Assert.IsTrue(NHSmaData.TryGetPaying(algo, out var paying)); Assert.AreEqual(testPaying[algo], paying); } foreach (var algo in testZero) { // These algos were not set so their value should be 0 (but still return true) Assert.IsTrue(NHSmaData.TryGetPaying(algo, out var paying)); Assert.AreEqual(0, paying); } // Should be false since DaggerDecred does not have a valid SMA Assert.IsFalse(NHSmaData.TryGetPaying(AlgorithmType.DaggerDecred, out _)); }
public void SwitchingManager_ShouldAlwaysReportLowerProfit() { var manager = new AlgorithmSwitchingManager(); manager.SmaCheckTimerOnElapsed(null, null); var currentPaying = new Dictionary <AlgorithmType, double>(); for (var i = 0; i < AlgorithmSwitchingManager.MaxHistory + 10; i++) { foreach (var algo in StartPaying.Keys) { currentPaying[algo] = manager.LastPayingForAlgo(algo); // Randomly add or subtract NHSmaData.UpdatePayingForAlgo(algo, StartPaying[algo] + (R.NextDouble() - 0.5)); } manager.SmaCheckTimerOnElapsed(null, null); // Iterate again to check foreach (var algo in StartPaying.Keys) { Assert.IsTrue(NHSmaData.TryGetPaying(algo, out var paying)); if (paying <= currentPaying[algo]) { // New value was less/same, so normalized value should be that Assert.AreEqual(paying, manager.LastPayingForAlgo(algo)); } else { // New value was more, so normalized should be equal or greater (depending on ticks) Assert.IsTrue(manager.LastPayingForAlgo(algo) >= currentPaying[algo]); } } } }