private static void PickTotalSpeed(INTMinerRoot root, string input, IKernelOutput kernelOutput, bool isDual) { string totalSpeedPattern = kernelOutput.TotalSpeedPattern; if (isDual) { totalSpeedPattern = kernelOutput.DualTotalSpeedPattern; } if (string.IsNullOrEmpty(totalSpeedPattern)) { return; } Regex regex = VirtualRoot.GetRegex(totalSpeedPattern); Match match = regex.Match(input); if (match.Success) { string totalSpeedText = match.Groups[NTKeyword.TotalSpeedGroupName].Value; string totalSpeedUnit = match.Groups[NTKeyword.TotalSpeedUnitGroupName].Value; if (string.IsNullOrEmpty(totalSpeedUnit)) { if (isDual) { totalSpeedUnit = kernelOutput.DualSpeedUnit; } else { totalSpeedUnit = kernelOutput.SpeedUnit; } } double totalSpeed; if (double.TryParse(totalSpeedText, out totalSpeed)) { double totalSpeedL = totalSpeed.FromUnitSpeed(totalSpeedUnit); var now = DateTime.Now; IGpusSpeed gpuSpeeds = NTMinerRoot.Instance.GpusSpeed; gpuSpeeds.SetCurrentSpeed(NTMinerRoot.GpuAllId, totalSpeedL, isDual, now); string gpuSpeedPattern = kernelOutput.GpuSpeedPattern; if (isDual) { gpuSpeedPattern = kernelOutput.DualGpuSpeedPattern; } if (string.IsNullOrEmpty(gpuSpeedPattern) && root.GpuSet.Count != 0) { // 平分总算力 double gpuSpeedL = totalSpeedL / root.GpuSet.Count; foreach (var item in gpuSpeeds) { if (item.Gpu.Index != NTMinerRoot.GpuAllId) { gpuSpeeds.SetCurrentSpeed(item.Gpu.Index, gpuSpeedL, isDual, now); } } } } } }
private static void PickGpuSpeed(string input, IKernelOutput kernelOutput, ICoin coin, bool isDual) { string gpuSpeedPattern = kernelOutput.GpuSpeedPattern; if (isDual) { gpuSpeedPattern = kernelOutput.DualGpuSpeedPattern; } if (string.IsNullOrEmpty(gpuSpeedPattern)) { return; } var now = DateTime.Now; bool hasGpuId = gpuSpeedPattern.Contains("?<gpu>"); Regex regex = new Regex(gpuSpeedPattern); MatchCollection matches = regex.Matches(input); if (matches.Count > 0) { IGpusSpeed gpuSpeeds = NTMinerRoot.Instance.GpusSpeed; for (int i = 0; i < matches.Count; i++) { Match match = matches[i]; string gpuSpeedText = match.Groups["gpuSpeed"].Value; string gpuSpeedUnit = match.Groups["gpuSpeedUnit"].Value; int gpu = i; if (hasGpuId) { string gpuText = match.Groups["gpu"].Value; if (!int.TryParse(gpuText, out gpu)) { gpu = i; } } double gpuSpeed; if (double.TryParse(gpuSpeedText, out gpuSpeed)) { double gpuSpeedL = gpuSpeed.FromUnitSpeed(gpuSpeedUnit); gpuSpeeds.SetCurrentSpeed(gpu, gpuSpeedL, isDual, now); } } string totalSpeedPattern = kernelOutput.DualTotalSpeedPattern; if (isDual) { totalSpeedPattern = kernelOutput.DualTotalSpeedPattern; } if (string.IsNullOrEmpty(totalSpeedPattern)) { // 求和分算力 double speed = isDual? gpuSpeeds.Where(a => a.Gpu.Index != NTMinerRoot.GpuAllId).Sum(a => a.DualCoinSpeed.Value) : gpuSpeeds.Where(a => a.Gpu.Index != NTMinerRoot.GpuAllId).Sum(a => a.MainCoinSpeed.Value); gpuSpeeds.SetCurrentSpeed(NTMinerRoot.GpuAllId, speed, isDual, now); } } }
private static void PickTotalSpeed(INTMinerContext context, string line, IKernelOutput kernelOutput, bool isDual) { string totalSpeedPattern = kernelOutput.TotalSpeedPattern; if (isDual) { totalSpeedPattern = kernelOutput.DualTotalSpeedPattern; } if (string.IsNullOrEmpty(totalSpeedPattern)) { return; } Regex regex = VirtualRoot.GetRegex(totalSpeedPattern); Match match = regex.Match(line); if (match.Success) { string totalSpeedText = match.Groups[NTKeyword.TotalSpeedGroupName].Value; string totalSpeedUnit = match.Groups[NTKeyword.TotalSpeedUnitGroupName].Value; if (string.IsNullOrEmpty(totalSpeedUnit)) { if (isDual) { totalSpeedUnit = kernelOutput.DualSpeedUnit; } else { totalSpeedUnit = kernelOutput.SpeedUnit; } } if (double.TryParse(totalSpeedText, out double totalSpeed)) { totalSpeed = totalSpeed.FromUnitSpeed(totalSpeedUnit); var now = DateTime.Now; IGpusSpeed gpuSpeeds = NTMinerContext.Instance.GpusSpeed; gpuSpeeds.SetCurrentSpeed(NTMinerContext.GpuAllId, totalSpeed, isDual, now); string gpuSpeedPattern = kernelOutput.GpuSpeedPattern; if (isDual) { gpuSpeedPattern = kernelOutput.DualGpuSpeedPattern; } // 如果没有单卡算力正则则平分总算力作为单卡算力正则 if ((string.IsNullOrEmpty(gpuSpeedPattern) || context.GpuSet.Count == 1) && context.GpuSet.Count != 0) { double gpuSpeed = totalSpeed / context.GpuSet.Count; foreach (var item in gpuSpeeds.AsEnumerable()) { if (item.Gpu.Index != NTMinerContext.GpuAllId) { gpuSpeeds.SetCurrentSpeed(item.Gpu.Index, gpuSpeed, isDual, now); } } } } } }
private static void PickTotalSpeed(INTMinerRoot root, string input, IKernelOutput kernelOutput, ICoin coin, bool isDual) { string totalSpeedPattern = kernelOutput.TotalSpeedPattern; if (isDual) { totalSpeedPattern = kernelOutput.DualTotalSpeedPattern; } if (string.IsNullOrEmpty(totalSpeedPattern)) { return; } Match match = Regex.Match(input, totalSpeedPattern, RegexOptions.Compiled); if (match.Success) { string totalSpeedText = match.Groups["totalSpeed"].Value; string totalSpeedUnit = match.Groups["totalSpeedUnit"].Value; double totalSpeed; if (double.TryParse(totalSpeedText, out totalSpeed)) { double totalSpeedL = totalSpeed.FromUnitSpeed(totalSpeedUnit); var now = DateTime.Now; IGpusSpeed gpuSpeeds = NTMinerRoot.Instance.GpusSpeed; gpuSpeeds.SetCurrentSpeed(NTMinerRoot.GpuAllId, totalSpeedL, isDual, now); string gpuSpeedPattern = kernelOutput.GpuSpeedPattern; if (isDual) { gpuSpeedPattern = kernelOutput.DualGpuSpeedPattern; } if (string.IsNullOrEmpty(gpuSpeedPattern)) { // 平分总算力 double gpuSpeedL = totalSpeedL / root.GpuSet.Count; foreach (var item in gpuSpeeds) { if (item.Gpu.Index != NTMinerRoot.GpuAllId) { gpuSpeeds.SetCurrentSpeed(item.Gpu.Index, gpuSpeedL, isDual, now); } } } } } }
private static void PickGpuSpeed(INTMinerContext root, IMineContext mineContext, string input, IKernelOutput kernelOutput, bool isDual) { string gpuSpeedPattern = kernelOutput.GpuSpeedPattern; if (isDual) { gpuSpeedPattern = kernelOutput.DualGpuSpeedPattern; } if (string.IsNullOrEmpty(gpuSpeedPattern)) { return; } var now = DateTime.Now; bool hasGpuId = gpuSpeedPattern.Contains($"?<{NTKeyword.GpuIndexGroupName}>"); Regex regex = VirtualRoot.GetRegex(gpuSpeedPattern); MatchCollection matches = regex.Matches(input); if (matches.Count > 0) { IGpusSpeed gpuSpeeds = NTMinerContext.Instance.GpusSpeed; for (int i = 0; i < matches.Count; i++) { Match match = matches[i]; string gpuSpeedText = match.Groups[NTKeyword.GpuSpeedGroupName].Value; string gpuSpeedUnit = match.Groups[NTKeyword.GpuSpeedUnitGroupName].Value; if (string.IsNullOrEmpty(gpuSpeedUnit)) { if (isDual) { gpuSpeedUnit = kernelOutput.DualSpeedUnit; } else { gpuSpeedUnit = kernelOutput.SpeedUnit; } } int gpu = i; if (hasGpuId) { string gpuText = match.Groups[NTKeyword.GpuIndexGroupName].Value; if (!int.TryParse(gpuText, out gpu)) { gpu = i; } else { gpu -= kernelOutput.GpuBaseIndex; if (gpu < 0) { continue; } } } if (kernelOutput.IsMapGpuIndex && !string.IsNullOrWhiteSpace(mineContext.KernelInput.DevicesArg)) { if (mineContext.UseDevices.Length != 0 && mineContext.UseDevices.Length != root.GpuSet.Count && gpu < mineContext.UseDevices.Length) { gpu = mineContext.UseDevices[gpu]; } } if (double.TryParse(gpuSpeedText, out double gpuSpeed)) { double gpuSpeedL = gpuSpeed.FromUnitSpeed(gpuSpeedUnit); gpuSpeeds.SetCurrentSpeed(gpu, gpuSpeedL, isDual, now); } } string totalSpeedPattern = kernelOutput.TotalSpeedPattern; if (isDual) { totalSpeedPattern = kernelOutput.DualTotalSpeedPattern; } if (string.IsNullOrEmpty(totalSpeedPattern)) { // 求和分算力 double speed = isDual? gpuSpeeds.AsEnumerable().Where(a => a.Gpu.Index != NTMinerContext.GpuAllId).Sum(a => a.DualCoinSpeed.Value) : gpuSpeeds.AsEnumerable().Where(a => a.Gpu.Index != NTMinerContext.GpuAllId).Sum(a => a.MainCoinSpeed.Value); gpuSpeeds.SetCurrentSpeed(NTMinerContext.GpuAllId, speed, isDual, now); } } }
public SpeedDto CreateSpeedDto() { INTMinerContext ntminerContext = NTMinerContext.Instance; IWorkProfile workProfile = ntminerContext.MinerProfile; string localIps = VirtualRoot.FormatLocalIps(out string macAddress); Guid mineContextId = Guid.Empty; if (ntminerContext.CurrentMineContext != null) { mineContextId = ntminerContext.CurrentMineContext.Id; } SpeedDto speedDto = new SpeedDto { MineContextId = mineContextId, MainCoinSpeedOn = DateTime.MinValue, DualCoinSpeedOn = DateTime.MinValue, IsAutoDisableWindowsFirewall = workProfile.IsAutoDisableWindowsFirewall, IsDisableAntiSpyware = workProfile.IsDisableAntiSpyware, IsDisableUAC = workProfile.IsDisableUAC, IsDisableWAU = workProfile.IsDisableWAU, Is1080PillEnabled = workProfile.Is1080PillEnabled, IsPreventDisplaySleep = workProfile.IsPreventDisplaySleep, IsAutoReboot = workProfile.IsAutoReboot, LocalServerMessageTimestamp = VirtualRoot.LocalServerMessageSetTimestamp, KernelSelfRestartCount = 0, IsAutoBoot = workProfile.IsAutoBoot, IsAutoStart = workProfile.IsAutoStart, AutoStartDelaySeconds = workProfile.AutoStartDelaySeconds, Version = EntryAssemblyInfo.CurrentVersionStr, BootOn = ntminerContext.CreatedOn, MineStartedOn = null, IsMining = ntminerContext.IsMining, MineWorkId = Guid.Empty, MineWorkName = string.Empty, MinerName = workProfile.MinerName, GpuInfo = ntminerContext.GpuSetInfo, ClientId = NTMinerContext.Id, MACAddress = macAddress, LocalIp = localIps, MainCoinCode = string.Empty, MainCoinWallet = string.Empty, MainCoinTotalShare = 0, MainCoinRejectShare = 0, MainCoinSpeed = 0, DualCoinCode = string.Empty, DualCoinTotalShare = 0, DualCoinRejectShare = 0, DualCoinSpeed = 0, DualCoinPool = string.Empty, DualCoinWallet = string.Empty, IsDualCoinEnabled = false, Kernel = string.Empty, MainCoinPool = string.Empty, OSName = Windows.OS.Instance.WindowsEdition, GpuDriver = ntminerContext.GpuSet.DriverVersion, GpuType = ntminerContext.GpuSet.GpuType, OSVirtualMemoryMb = VirtualRoot.DriveSet.OSVirtualMemoryMb, TotalPhysicalMemoryMb = (int)(Windows.Ram.Instance.TotalPhysicalMemory / NTKeyword.IntM), KernelCommandLine = string.Empty, DiskSpace = VirtualRoot.DriveSet.ToDiskSpaceString(), IsAutoRestartKernel = workProfile.IsAutoRestartKernel, AutoRestartKernelTimes = workProfile.AutoRestartKernelTimes, IsNoShareRestartKernel = workProfile.IsNoShareRestartKernel, NoShareRestartKernelMinutes = workProfile.NoShareRestartKernelMinutes, IsNoShareRestartComputer = workProfile.IsNoShareRestartComputer, NoShareRestartComputerMinutes = workProfile.NoShareRestartComputerMinutes, IsPeriodicRestartComputer = workProfile.IsPeriodicRestartComputer, PeriodicRestartComputerHours = workProfile.PeriodicRestartComputerHours, IsPeriodicRestartKernel = workProfile.IsPeriodicRestartKernel, PeriodicRestartKernelHours = workProfile.PeriodicRestartKernelHours, PeriodicRestartComputerMinutes = workProfile.PeriodicRestartComputerMinutes, PeriodicRestartKernelMinutes = workProfile.PeriodicRestartKernelMinutes, IsAutoStartByCpu = workProfile.IsAutoStartByCpu, IsAutoStopByCpu = workProfile.IsAutoStopByCpu, CpuGETemperatureSeconds = workProfile.CpuGETemperatureSeconds, CpuLETemperatureSeconds = workProfile.CpuLETemperatureSeconds, CpuStartTemperature = workProfile.CpuStartTemperature, CpuStopTemperature = workProfile.CpuStopTemperature, MainCoinPoolDelay = string.Empty, DualCoinPoolDelay = string.Empty, MinerIp = string.Empty, IsFoundOneGpuShare = false, IsGotOneIncorrectGpuShare = false, IsRejectOneGpuShare = false, CpuPerformance = ntminerContext.CpuPackage.Performance, CpuTemperature = ntminerContext.CpuPackage.Temperature, IsRaiseHighCpuEvent = workProfile.IsRaiseHighCpuEvent, HighCpuPercent = workProfile.HighCpuBaseline, HighCpuSeconds = workProfile.HighCpuSeconds, IsOuterUserEnabled = workProfile.IsOuterUserEnabled, ReportOuterUserId = NTMinerRegistry.GetOuterUserId(), IsLowSpeedRestartComputer = false, LowSpeedRestartComputerMinutes = 0, LowSpeed = 0, IsLowSpeedReOverClock = false, LowSpeedReOverClockMinutes = 0, OverClockLowSpeed = 0, GpuTable = ntminerContext.GpusSpeed.AsEnumerable().Where(a => a.Gpu.Index != NTMinerContext.GpuAllId).Select(a => a.ToGpuSpeedData()).ToArray() }; if (workProfile.MineWork != null) { speedDto.MineWorkId = workProfile.MineWork.GetId(); speedDto.MineWorkName = workProfile.MineWork.Name; } #region 当前选中的币种是什么 if (ntminerContext.ServerContext.CoinSet.TryGetCoin(workProfile.CoinId, out ICoin mainCoin)) { speedDto.MainCoinCode = mainCoin.Code; ICoinProfile coinProfile = workProfile.GetCoinProfile(mainCoin.GetId()); speedDto.MainCoinWallet = coinProfile.Wallet; speedDto.IsLowSpeedRestartComputer = coinProfile.IsLowSpeedRestartComputer; speedDto.LowSpeed = coinProfile.LowSpeed; speedDto.LowSpeedRestartComputerMinutes = coinProfile.LowSpeedRestartComputerMinutes; speedDto.IsLowSpeedReOverClock = coinProfile.IsLowSpeedReOverClock; speedDto.LowSpeedReOverClockMinutes = coinProfile.LowSpeedReOverClockMinutes; speedDto.OverClockLowSpeed = coinProfile.OverClockLowSpeed; if (ntminerContext.ServerContext.PoolSet.TryGetPool(coinProfile.PoolId, out IPool mainCoinPool)) { speedDto.MainCoinPool = mainCoinPool.Server; if (ntminerContext.IsMining) { speedDto.MainCoinPoolDelay = ntminerContext.ServerContext.PoolSet.GetPoolDelayText(mainCoinPool.GetId(), isDual: false); } if (mainCoinPool.IsUserMode) { IPoolProfile mainCoinPoolProfile = workProfile.GetPoolProfile(coinProfile.PoolId); speedDto.MainCoinWallet = mainCoinPoolProfile.UserName; } } else { speedDto.MainCoinPool = string.Empty; } if (ntminerContext.ServerContext.CoinKernelSet.TryGetCoinKernel(coinProfile.CoinKernelId, out ICoinKernel coinKernel)) { if (ntminerContext.ServerContext.KernelSet.TryGetKernel(coinKernel.KernelId, out IKernel kernel)) { speedDto.Kernel = kernel.GetFullName(); if (ntminerContext.ServerContext.KernelOutputSet.TryGetKernelOutput(kernel.KernelOutputId, out IKernelOutput kernelOutput)) { speedDto.IsFoundOneGpuShare = !string.IsNullOrEmpty(kernelOutput.FoundOneShare); speedDto.IsGotOneIncorrectGpuShare = !string.IsNullOrEmpty(kernelOutput.GpuGotOneIncorrectShare); speedDto.IsRejectOneGpuShare = !string.IsNullOrEmpty(kernelOutput.RejectOneShare); } ICoinKernelProfile coinKernelProfile = workProfile.GetCoinKernelProfile(coinProfile.CoinKernelId); speedDto.IsDualCoinEnabled = coinKernelProfile.IsDualCoinEnabled; if (coinKernelProfile.IsDualCoinEnabled) { if (ntminerContext.ServerContext.CoinSet.TryGetCoin(coinKernelProfile.DualCoinId, out ICoin dualCoin)) { speedDto.DualCoinCode = dualCoin.Code; ICoinProfile dualCoinProfile = workProfile.GetCoinProfile(dualCoin.GetId()); speedDto.DualCoinWallet = dualCoinProfile.DualCoinWallet; if (ntminerContext.ServerContext.PoolSet.TryGetPool(dualCoinProfile.DualCoinPoolId, out IPool dualCoinPool)) { speedDto.DualCoinPool = dualCoinPool.Server; if (ntminerContext.IsMining) { speedDto.DualCoinPoolDelay = ntminerContext.ServerContext.PoolSet.GetPoolDelayText(dualCoinPool.GetId(), isDual: true); } if (dualCoinPool.IsUserMode) { IPoolProfile dualCoinPoolProfile = workProfile.GetPoolProfile(dualCoinProfile.DualCoinPoolId); speedDto.DualCoinWallet = dualCoinPoolProfile.UserName; } } else { speedDto.DualCoinPool = string.Empty; } } } } } } #endregion if (ntminerContext.IsMining) { var mineContext = ntminerContext.LockedMineContext; if (mineContext != null) { speedDto.KernelSelfRestartCount = mineContext.KernelSelfRestartCount; if (mineContext.MineStartedOn != DateTime.MinValue) { speedDto.MineStartedOn = mineContext.MineStartedOn; } speedDto.KernelCommandLine = mineContext.CommandLine; } // 判断上次报告的算力币种和本次报告的是否相同,否则说明刚刚切换了币种默认第一次报告0算力 if (_sLastSpeedMainCoin == null || _sLastSpeedMainCoin == ntminerContext.LockedMineContext.MainCoin) { _sLastSpeedMainCoin = ntminerContext.LockedMineContext.MainCoin; Guid coinId = ntminerContext.LockedMineContext.MainCoin.GetId(); IGpusSpeed gpuSpeeds = ntminerContext.GpusSpeed; IGpuSpeed totalSpeed = gpuSpeeds.CurrentSpeed(NTMinerContext.GpuAllId); speedDto.MainCoinSpeed = totalSpeed.MainCoinSpeed.Value; speedDto.MainCoinSpeedOn = totalSpeed.MainCoinSpeed.SpeedOn; ICoinShare share = ntminerContext.CoinShareSet.GetOrCreate(coinId); speedDto.MainCoinTotalShare = share.TotalShareCount; speedDto.MainCoinRejectShare = share.RejectShareCount; } else { _sLastSpeedMainCoin = ntminerContext.LockedMineContext.MainCoin; } if (ntminerContext.LockedMineContext is IDualMineContext dualMineContext) { // 判断上次报告的算力币种和本次报告的是否相同,否则说明刚刚切换了币种默认第一次报告0算力 if (_sLastSpeedDualCoin == null || _sLastSpeedDualCoin == dualMineContext.DualCoin) { _sLastSpeedDualCoin = dualMineContext.DualCoin; Guid coinId = dualMineContext.DualCoin.GetId(); IGpusSpeed gpuSpeeds = ntminerContext.GpusSpeed; IGpuSpeed totalSpeed = gpuSpeeds.CurrentSpeed(NTMinerContext.GpuAllId); speedDto.DualCoinSpeed = totalSpeed.DualCoinSpeed.Value; speedDto.DualCoinSpeedOn = totalSpeed.DualCoinSpeed.SpeedOn; ICoinShare share = ntminerContext.CoinShareSet.GetOrCreate(coinId); speedDto.DualCoinTotalShare = share.TotalShareCount; speedDto.DualCoinRejectShare = share.RejectShareCount; } else { _sLastSpeedDualCoin = dualMineContext.DualCoin; } } } return(speedDto); }
public static SpeedData CreateSpeedData() { INTMinerRoot root = NTMinerRoot.Instance; SpeedData data = new SpeedData { KernelSelfRestartCount = 0, IsAutoBoot = NTMinerRegistry.GetIsAutoBoot(), IsAutoStart = NTMinerRegistry.GetIsAutoStart(), Version = NTMinerRoot.CurrentVersion.ToString(4), BootOn = root.CreatedOn, MineStartedOn = null, IsMining = root.IsMining, MineWorkId = root.MinerProfile.MineWork != null?root.MinerProfile.MineWork.GetId() : Guid.Empty, MinerName = root.MinerProfile.MinerName, GpuInfo = root.GpuSetInfo, ClientId = VirtualRoot.Id, MainCoinCode = string.Empty, MainCoinWallet = string.Empty, MainCoinTotalShare = 0, MainCoinRejectShare = 0, MainCoinSpeed = 0, DualCoinCode = string.Empty, DualCoinTotalShare = 0, DualCoinRejectShare = 0, DualCoinSpeed = 0, DualCoinPool = string.Empty, DualCoinWallet = string.Empty, IsDualCoinEnabled = false, Kernel = string.Empty, MainCoinPool = string.Empty, OSName = Windows.OS.Instance.WindowsEdition, GpuDriver = root.GpuSet.DriverVersion, GpuType = root.GpuSet.GpuType, OSVirtualMemoryMb = NTMinerRoot.OSVirtualMemoryMb, KernelCommandLine = NTMinerRoot.UserKernelCommandLine, DiskSpace = NTMinerRoot.DiskSpace, IsAutoRestartKernel = root.MinerProfile.IsAutoRestartKernel, IsNoShareRestartKernel = root.MinerProfile.IsNoShareRestartKernel, IsPeriodicRestartComputer = root.MinerProfile.IsPeriodicRestartComputer, IsPeriodicRestartKernel = root.MinerProfile.IsPeriodicRestartKernel, NoShareRestartKernelMinutes = root.MinerProfile.NoShareRestartKernelMinutes, PeriodicRestartComputerHours = root.MinerProfile.PeriodicRestartComputerHours, PeriodicRestartKernelHours = root.MinerProfile.PeriodicRestartKernelHours, GpuTable = root.GpusSpeed.Where(a => a.Gpu.Index != NTMinerRoot.GpuAllId).Select(a => new GpuSpeedData { Index = a.Gpu.Index, Name = a.Gpu.Name, TotalMemory = a.Gpu.TotalMemory, MainCoinSpeed = a.MainCoinSpeed.Value, DualCoinSpeed = a.DualCoinSpeed.Value, FanSpeed = a.Gpu.FanSpeed, Temperature = a.Gpu.Temperature, PowerUsage = a.Gpu.PowerUsage, Cool = a.Gpu.Cool, PowerCapacity = a.Gpu.PowerCapacity, CoreClockDelta = a.Gpu.CoreClockDelta, MemoryClockDelta = a.Gpu.MemoryClockDelta, TempLimit = a.Gpu.TempLimit }).ToArray() }; #region 当前选中的币种是什么 if (root.CoinSet.TryGetCoin(root.MinerProfile.CoinId, out ICoin mainCoin)) { data.MainCoinCode = mainCoin.Code; ICoinProfile coinProfile = root.MinerProfile.GetCoinProfile(mainCoin.GetId()); data.MainCoinWallet = coinProfile.Wallet; if (root.PoolSet.TryGetPool(coinProfile.PoolId, out IPool mainCoinPool)) { data.MainCoinPool = mainCoinPool.Server; if (mainCoinPool.IsUserMode) { IPoolProfile mainCoinPoolProfile = root.MinerProfile.GetPoolProfile(coinProfile.PoolId); data.MainCoinWallet = mainCoinPoolProfile.UserName; } } else { data.MainCoinPool = string.Empty; } if (root.CoinKernelSet.TryGetCoinKernel(coinProfile.CoinKernelId, out ICoinKernel coinKernel)) { if (root.KernelSet.TryGetKernel(coinKernel.KernelId, out IKernel kernel)) { data.Kernel = kernel.GetFullName(); ICoinKernelProfile coinKernelProfile = root.MinerProfile.GetCoinKernelProfile(coinProfile.CoinKernelId); data.IsDualCoinEnabled = coinKernelProfile.IsDualCoinEnabled; if (coinKernelProfile.IsDualCoinEnabled) { if (root.CoinSet.TryGetCoin(coinKernelProfile.DualCoinId, out ICoin dualCoin)) { data.DualCoinCode = dualCoin.Code; ICoinProfile dualCoinProfile = root.MinerProfile.GetCoinProfile(dualCoin.GetId()); data.DualCoinWallet = dualCoinProfile.DualCoinWallet; if (root.PoolSet.TryGetPool(dualCoinProfile.DualCoinPoolId, out IPool dualCoinPool)) { data.DualCoinPool = dualCoinPool.Server; if (dualCoinPool.IsUserMode) { IPoolProfile dualCoinPoolProfile = root.MinerProfile.GetPoolProfile(dualCoinProfile.DualCoinPoolId); data.DualCoinWallet = dualCoinPoolProfile.UserName; } } else { data.DualCoinPool = string.Empty; } } } } } } #endregion if (root.IsMining) { var mineContext = root.CurrentMineContext; if (mineContext != null) { data.KernelSelfRestartCount = mineContext.KernelSelfRestartCount; data.MineStartedOn = mineContext.CreatedOn; data.KernelCommandLine = mineContext.CommandLine; } // 判断上次报告的算力币种和本次报告的是否相同,否则说明刚刚切换了币种默认第一次报告0算力 if (_sLastSpeedMainCoin == null || _sLastSpeedMainCoin == root.CurrentMineContext.MainCoin) { _sLastSpeedMainCoin = root.CurrentMineContext.MainCoin; Guid coinId = root.CurrentMineContext.MainCoin.GetId(); IGpusSpeed gpuSpeeds = NTMinerRoot.Instance.GpusSpeed; IGpuSpeed totalSpeed = gpuSpeeds.CurrentSpeed(NTMinerRoot.GpuAllId); data.MainCoinSpeed = totalSpeed.MainCoinSpeed.Value; ICoinShare share = root.CoinShareSet.GetOrCreate(coinId); data.MainCoinTotalShare = share.TotalShareCount; data.MainCoinRejectShare = share.RejectShareCount; } else { _sLastSpeedMainCoin = root.CurrentMineContext.MainCoin; } if (root.CurrentMineContext is IDualMineContext dualMineContext) { // 判断上次报告的算力币种和本次报告的是否相同,否则说明刚刚切换了币种默认第一次报告0算力 if (_sLastSpeedDualCoin == null || _sLastSpeedDualCoin == dualMineContext.DualCoin) { _sLastSpeedDualCoin = dualMineContext.DualCoin; Guid coinId = dualMineContext.DualCoin.GetId(); IGpusSpeed gpuSpeeds = NTMinerRoot.Instance.GpusSpeed; IGpuSpeed totalSpeed = gpuSpeeds.CurrentSpeed(NTMinerRoot.GpuAllId); data.DualCoinSpeed = totalSpeed.DualCoinSpeed.Value; ICoinShare share = root.CoinShareSet.GetOrCreate(coinId); data.DualCoinTotalShare = share.TotalShareCount; data.DualCoinRejectShare = share.RejectShareCount; } else { _sLastSpeedDualCoin = dualMineContext.DualCoin; } } } return(data); }
private GpuSpeedViewModels() { if (WpfUtil.IsInDesignMode) { return; } this.GpuAllVm = GpuVms.Items.FirstOrDefault(a => a.Index == NTMinerContext.GpuAllId); IGpusSpeed gpuSpeeds = NTMinerContext.Instance.GpusSpeed; foreach (var item in gpuSpeeds.AsEnumerable()) { this._list.Add(new GpuSpeedViewModel(item)); } _totalSpeedVm = this._list.FirstOrDefault(a => a.GpuVm.Index == NTMinerContext.GpuAllId); AddEventPath <GpuShareChangedEvent>("显卡份额变更后刷新VM内存", LogEnum.DevConsole, action: message => { ResetIfMainCoinSwitched(); int index = message.Source.Gpu.Index; GpuSpeedViewModel gpuSpeedVm = _list.FirstOrDefault(a => a.GpuVm.Index == index); if (gpuSpeedVm != null) { gpuSpeedVm.MainCoinSpeed.FoundShare = message.Source.MainCoinSpeed.FoundShare; gpuSpeedVm.MainCoinSpeed.AcceptShare = message.Source.MainCoinSpeed.AcceptShare; gpuSpeedVm.MainCoinSpeed.RejectShare = message.Source.MainCoinSpeed.RejectShare; } }, location: this.GetType()); AddEventPath <FoundShareIncreasedEvent>("找到一个份额后刷新VM内存", LogEnum.DevConsole, action: message => { ResetIfMainCoinSwitched(); int index = message.Source.Gpu.Index; GpuSpeedViewModel gpuSpeedVm = _list.FirstOrDefault(a => a.GpuVm.Index == index); if (gpuSpeedVm != null) { gpuSpeedVm.MainCoinSpeed.FoundShare = message.Source.MainCoinSpeed.FoundShare; } }, location: this.GetType()); AddEventPath <AcceptShareIncreasedEvent>("接受一个份额后刷新VM内存", LogEnum.DevConsole, action: message => { ResetIfMainCoinSwitched(); int index = message.Source.Gpu.Index; GpuSpeedViewModel gpuSpeedVm = _list.FirstOrDefault(a => a.GpuVm.Index == index); if (gpuSpeedVm != null) { gpuSpeedVm.MainCoinSpeed.AcceptShare = message.Source.MainCoinSpeed.AcceptShare; } }, location: this.GetType()); AddEventPath <RejectShareIncreasedEvent>("拒绝一个份额后刷新VM内存", LogEnum.DevConsole, action: message => { ResetIfMainCoinSwitched(); int index = message.Source.Gpu.Index; GpuSpeedViewModel gpuSpeedVm = _list.FirstOrDefault(a => a.GpuVm.Index == index); if (gpuSpeedVm != null) { gpuSpeedVm.MainCoinSpeed.RejectShare = message.Source.MainCoinSpeed.RejectShare; } }, location: this.GetType()); AddEventPath <IncorrectShareIncreasedEvent>("产生一个错误份额后刷新VM内存", LogEnum.DevConsole, action: message => { ResetIfMainCoinSwitched(); int index = message.Source.Gpu.Index; GpuSpeedViewModel gpuSpeedVm = _list.FirstOrDefault(a => a.GpuVm.Index == index); if (gpuSpeedVm != null) { gpuSpeedVm.MainCoinSpeed.IncorrectShare = message.Source.MainCoinSpeed.IncorrectShare; } }, location: this.GetType()); AddEventPath <GpuSpeedChangedEvent>("显卡算力变更后刷新VM内存", LogEnum.DevConsole, action: (message) => { ResetIfMainCoinSwitched(); int index = message.Source.Gpu.Index; GpuSpeedViewModel gpuSpeedVm = _list.FirstOrDefault(a => a.GpuVm.Index == index); if (gpuSpeedVm != null) { if (message.IsDual) { gpuSpeedVm.DualCoinSpeed.UpdateSpeed(message.Source.DualCoinSpeed.Value, message.Source.DualCoinSpeed.SpeedOn); gpuSpeedVm.OnPropertyChanged(nameof(gpuSpeedVm.AverageDualCoinSpeedText)); } else { gpuSpeedVm.MainCoinSpeed.UpdateSpeed(message.Source.MainCoinSpeed.Value, message.Source.MainCoinSpeed.SpeedOn); gpuSpeedVm.OnPropertyChanged(nameof(gpuSpeedVm.AverageMainCoinSpeedText)); } } if (index == _totalSpeedVm.GpuVm.Index) { var mineContext = NTMinerContext.Instance.LockedMineContext; if (mineContext == null) { IncomeMainCoinPerDay = 0; IncomeMainCoinUsdPerDay = 0; IncomeMainCoinCnyPerDay = 0; IncomeDualCoinPerDay = 0; IncomeDualCoinUsdPerDay = 0; IncomeDualCoinCnyPerDay = 0; } else { if (message.IsDual) { if (mineContext is IDualMineContext dualMineContext) { IncomePerDay incomePerDay = NTMinerContext.Instance.CalcConfigSet.GetIncomePerHashPerDay(dualMineContext.DualCoin.Code); IncomeDualCoinPerDay = _totalSpeedVm.DualCoinSpeed.Value * incomePerDay.IncomeCoin; IncomeDualCoinUsdPerDay = _totalSpeedVm.DualCoinSpeed.Value * incomePerDay.IncomeUsd; IncomeDualCoinCnyPerDay = _totalSpeedVm.DualCoinSpeed.Value * incomePerDay.IncomeCny; } } else { IncomePerDay incomePerDay = NTMinerContext.Instance.CalcConfigSet.GetIncomePerHashPerDay(mineContext.MainCoin.Code); IncomeMainCoinPerDay = _totalSpeedVm.MainCoinSpeed.Value * incomePerDay.IncomeCoin; IncomeMainCoinUsdPerDay = _totalSpeedVm.MainCoinSpeed.Value * incomePerDay.IncomeUsd; IncomeMainCoinCnyPerDay = _totalSpeedVm.MainCoinSpeed.Value * incomePerDay.IncomeCny; } } } }, location: this.GetType()); AddEventPath <Per1SecondEvent>("每秒钟更新算力活动时间", LogEnum.None, action: message => { TotalSpeedVm.MainCoinSpeed.OnPropertyChanged(nameof(SpeedViewModel.LastSpeedOnText)); TotalSpeedVm.DualCoinSpeed.OnPropertyChanged(nameof(SpeedViewModel.LastSpeedOnText)); }, location: this.GetType()); }
private static void ReportSpeed(INTMinerRoot root) { try { SpeedData data = new SpeedData { MessageId = Guid.NewGuid(), MinerName = root.MinerProfile.MinerName, ClientId = ClientId.Id, Timestamp = DateTime.Now, MainCoinCode = string.Empty, MainCoinShareDelta = 0, MainCoinSpeed = 0, DualCoinCode = string.Empty, DualCoinShareDelta = 0, DualCoinSpeed = 0, IsMining = root.IsMining, DualCoinPool = string.Empty, DualCoinWallet = string.Empty, IsDualCoinEnabled = false, Kernel = string.Empty, MainCoinPool = string.Empty, MainCoinWallet = string.Empty }; #region 当前选中的币种是什么 ICoin mainCoin; if (root.CoinSet.TryGetCoin(root.MinerProfile.CoinId, out mainCoin)) { data.MainCoinCode = mainCoin.Code; ICoinProfile coinProfile = root.CoinProfileSet.GetCoinProfile(mainCoin.GetId()); IPool mainCoinPool; if (root.PoolSet.TryGetPool(coinProfile.PoolId, out mainCoinPool)) { data.MainCoinPool = mainCoinPool.Server; } else { data.MainCoinPool = string.Empty; } data.MainCoinWallet = coinProfile.Wallet; ICoinKernel coinKernel; if (root.CoinKernelSet.TryGetKernel(coinProfile.CoinKernelId, out coinKernel)) { IKernel kernel; if (root.KernelSet.TryGetKernel(coinKernel.KernelId, out kernel)) { data.Kernel = kernel.FullName; ICoinKernelProfile coinKernelProfile = root.CoinKernelProfileSet.GetCoinKernelProfile(coinProfile.CoinKernelId); data.IsDualCoinEnabled = coinKernelProfile.IsDualCoinEnabled; if (coinKernelProfile.IsDualCoinEnabled) { ICoin dualCoin; if (root.CoinSet.TryGetCoin(coinKernelProfile.DualCoinId, out dualCoin)) { data.DualCoinCode = dualCoin.Code; ICoinProfile dualCoinProfile = root.CoinProfileSet.GetCoinProfile(dualCoin.GetId()); data.DualCoinWallet = dualCoinProfile.DualCoinWallet; IPool dualCoinPool; if (root.PoolSet.TryGetPool(dualCoinProfile.DualCoinPoolId, out dualCoinPool)) { data.DualCoinPool = dualCoinPool.Server; } else { data.DualCoinPool = string.Empty; } } } } } } #endregion if (root.IsMining) { // 判断上次报告的算力币种和本次报告的是否相同,否则说明刚刚切换了币种默认第一次报告0算力 if (_lastSpeedMainCoin == null || _lastSpeedMainCoin == root.CurrentMineContext.MainCoin) { _lastSpeedMainCoin = root.CurrentMineContext.MainCoin; CoinShareData preCoinShare; Guid coinId = root.CurrentMineContext.MainCoin.GetId(); IGpusSpeed gpuSpeeds = NTMinerRoot.Current.GpusSpeed; IGpuSpeed totalSpeed = gpuSpeeds.CurrentSpeed(NTMinerRoot.GpuAllId); data.MainCoinSpeed = (int)totalSpeed.MainCoinSpeed.Value; ICoinShare share = root.CoinShareSet.GetOrCreate(coinId); if (!_coinShareDic.TryGetValue(coinId, out preCoinShare)) { preCoinShare = new CoinShareData() { TotalShareCount = share.TotalShareCount }; _coinShareDic.Add(coinId, preCoinShare); data.MainCoinShareDelta = share.TotalShareCount; } else { data.MainCoinShareDelta = share.TotalShareCount - preCoinShare.TotalShareCount; } } if (root.CurrentMineContext is IDualMineContext dualMineContext) { // 判断上次报告的算力币种和本次报告的是否相同,否则说明刚刚切换了币种默认第一次报告0算力 if (_lastSpeedDualCoin == null || _lastSpeedDualCoin == dualMineContext.DualCoin) { _lastSpeedDualCoin = dualMineContext.DualCoin; CoinShareData preCoinShare; Guid coinId = dualMineContext.DualCoin.GetId(); IGpusSpeed gpuSpeeds = NTMinerRoot.Current.GpusSpeed; IGpuSpeed totalSpeed = gpuSpeeds.CurrentSpeed(NTMinerRoot.GpuAllId); data.DualCoinSpeed = (int)totalSpeed.DualCoinSpeed.Value; ICoinShare share = root.CoinShareSet.GetOrCreate(coinId); if (!_coinShareDic.TryGetValue(coinId, out preCoinShare)) { preCoinShare = new CoinShareData() { TotalShareCount = share.TotalShareCount }; _coinShareDic.Add(coinId, preCoinShare); data.DualCoinShareDelta = share.TotalShareCount; } else { data.DualCoinShareDelta = share.TotalShareCount - preCoinShare.TotalShareCount; } } } } Server.ReportService.ReportSpeed(data); } catch (Exception e) { Global.Logger.ErrorDebugLine(e.Message, e); } }
private GpuSpeedViewModels() { if (NTMinerRoot.IsInDesignMode) { return; } this.GpuAllVm = GpuViewModels.Current.FirstOrDefault(a => a.Index == NTMinerRoot.Current.GpuAllId); IGpusSpeed gpuSpeeds = NTMinerRoot.Current.GpusSpeed; foreach (var item in gpuSpeeds) { this._list.Add(new GpuSpeedViewModel(item)); } _totalSpeedVm = this._list.FirstOrDefault(a => a.GpuVm.Index == NTMinerRoot.Current.GpuAllId); Global.Access <GpuSpeedChangedEvent>( Guid.Parse("acb2e5fd-a3ed-4ed6-b8c7-583eafd5e579"), "显卡算力变更后刷新VM内存", LogEnum.None, action: (message) => { Guid mainCoinId = NTMinerRoot.Current.MinerProfile.CoinId; if (_mainCoinId != mainCoinId) { _mainCoinId = mainCoinId; DateTime now = DateTime.Now; foreach (var item in _list) { item.MainCoinSpeed.Value = 0; item.MainCoinSpeed.SpeedOn = now; item.DualCoinSpeed.Value = 0; item.DualCoinSpeed.SpeedOn = now; } IncomeMainCoinPerDay = 0; IncomeDualCoinPerDay = 0; } int index = message.Source.Gpu.Index; GpuSpeedViewModel gpuSpeedVm = _list.FirstOrDefault(a => a.GpuVm.Index == index); if (gpuSpeedVm != null) { if (message.IsDualSpeed) { gpuSpeedVm.DualCoinSpeed.Update(message.Source.DualCoinSpeed); } else { gpuSpeedVm.MainCoinSpeed.Update(message.Source.MainCoinSpeed); } } if (index == _totalSpeedVm.GpuVm.Index) { IMineContext mineContext = NTMinerRoot.Current.CurrentMineContext; if (mineContext == null) { IncomeMainCoinPerDay = 0; IncomeDualCoinPerDay = 0; } else { if (message.IsDualSpeed) { if (mineContext is IDualMineContext dualMineContext) { IncomeDualCoinPerDay = _totalSpeedVm.DualCoinSpeed.Value * NTMinerRoot.Current.CalcConfigSet.GetIncomePerHashPerDay(dualMineContext.DualCoin); } } else { IncomeMainCoinPerDay = _totalSpeedVm.MainCoinSpeed.Value * NTMinerRoot.Current.CalcConfigSet.GetIncomePerHashPerDay(mineContext.MainCoin); } } } }); }
private GpuSpeedViewModels() { #if DEBUG VirtualRoot.Stopwatch.Restart(); #endif if (Design.IsInDesignMode) { return; } this.GpuAllVm = AppContext.Instance.GpuVms.FirstOrDefault(a => a.Index == NTMinerRoot.GpuAllId); IGpusSpeed gpuSpeeds = NTMinerRoot.Instance.GpusSpeed; foreach (var item in gpuSpeeds) { this._list.Add(new GpuSpeedViewModel(item)); } _totalSpeedVm = this._list.FirstOrDefault(a => a.GpuVm.Index == NTMinerRoot.GpuAllId); On <GpuSpeedChangedEvent>("显卡算力变更后刷新VM内存", LogEnum.DevConsole, action: (message) => { Guid mainCoinId = NTMinerRoot.Instance.MinerProfile.CoinId; if (_mainCoinId != mainCoinId) { _mainCoinId = mainCoinId; DateTime now = DateTime.Now; foreach (var item in _list) { item.MainCoinSpeed.Value = 0; item.MainCoinSpeed.SpeedOn = now; item.DualCoinSpeed.Value = 0; item.DualCoinSpeed.SpeedOn = now; } IncomeMainCoinPerDay = 0; IncomeMainCoinUsdPerDay = 0; IncomeMainCoinCnyPerDay = 0; IncomeDualCoinPerDay = 0; IncomeDualCoinUsdPerDay = 0; IncomeDualCoinCnyPerDay = 0; } int index = message.Source.Gpu.Index; GpuSpeedViewModel gpuSpeedVm = _list.FirstOrDefault(a => a.GpuVm.Index == index); if (gpuSpeedVm != null) { if (message.IsDualSpeed) { gpuSpeedVm.DualCoinSpeed.Update(message.Source.DualCoinSpeed); gpuSpeedVm.OnPropertyChanged(nameof(gpuSpeedVm.AverageDualCoinSpeedText)); } else { gpuSpeedVm.MainCoinSpeed.Update(message.Source.MainCoinSpeed); gpuSpeedVm.OnPropertyChanged(nameof(gpuSpeedVm.AverageMainCoinSpeedText)); } } if (index == _totalSpeedVm.GpuVm.Index) { IMineContext mineContext = NTMinerRoot.Instance.CurrentMineContext; if (mineContext == null) { IncomeMainCoinPerDay = 0; IncomeMainCoinUsdPerDay = 0; IncomeMainCoinCnyPerDay = 0; IncomeDualCoinPerDay = 0; IncomeDualCoinUsdPerDay = 0; IncomeDualCoinCnyPerDay = 0; } else { if (message.IsDualSpeed) { if (mineContext is IDualMineContext dualMineContext) { IncomePerDay incomePerDay = NTMinerRoot.Instance.CalcConfigSet.GetIncomePerHashPerDay(dualMineContext.DualCoin.Code); IncomeDualCoinPerDay = _totalSpeedVm.DualCoinSpeed.Value * incomePerDay.IncomeCoin; IncomeDualCoinUsdPerDay = _totalSpeedVm.DualCoinSpeed.Value * incomePerDay.IncomeUsd; IncomeDualCoinCnyPerDay = _totalSpeedVm.DualCoinSpeed.Value * incomePerDay.IncomeCny; } } else { IncomePerDay incomePerDay = NTMinerRoot.Instance.CalcConfigSet.GetIncomePerHashPerDay(mineContext.MainCoin.Code); IncomeMainCoinPerDay = _totalSpeedVm.MainCoinSpeed.Value * incomePerDay.IncomeCoin; IncomeMainCoinUsdPerDay = _totalSpeedVm.MainCoinSpeed.Value * incomePerDay.IncomeUsd; IncomeMainCoinCnyPerDay = _totalSpeedVm.MainCoinSpeed.Value * incomePerDay.IncomeCny; } } } }); On <Per1SecondEvent>("每秒钟更新算力活动时间", LogEnum.None, action: message => { TotalSpeedVm.MainCoinSpeed.OnPropertyChanged(nameof(SpeedViewModel.LastSpeedOnText)); TotalSpeedVm.DualCoinSpeed.OnPropertyChanged(nameof(SpeedViewModel.LastSpeedOnText)); }); #if DEBUG Write.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
private GpuSpeedViewModels() { #if DEBUG Write.Stopwatch.Restart(); #endif if (WpfUtil.IsInDesignMode) { return; } this.GpuAllVm = AppContext.Instance.GpuVms.FirstOrDefault(a => a.Index == NTMinerRoot.GpuAllId); IGpusSpeed gpuSpeeds = NTMinerRoot.Instance.GpusSpeed; foreach (var item in gpuSpeeds) { this._list.Add(new GpuSpeedViewModel(item)); } _totalSpeedVm = this._list.FirstOrDefault(a => a.GpuVm.Index == NTMinerRoot.GpuAllId); AppContextEventPath <GpuShareChangedEvent>("显卡份额变更后刷新VM内存", LogEnum.DevConsole, action: message => { CheckReset(); int index = message.Source.Gpu.Index; GpuSpeedViewModel gpuSpeedVm = _list.FirstOrDefault(a => a.GpuVm.Index == index); if (gpuSpeedVm != null) { gpuSpeedVm.MainCoinSpeed.FoundShare = message.Source.MainCoinSpeed.FoundShare; gpuSpeedVm.MainCoinSpeed.AcceptShare = message.Source.MainCoinSpeed.AcceptShare; gpuSpeedVm.MainCoinSpeed.RejectShare = message.Source.MainCoinSpeed.RejectShare; } }); AppContextEventPath <FoundShareIncreasedEvent>("找到一个份额后刷新VM内存", LogEnum.DevConsole, action: message => { CheckReset(); int index = message.Source.Gpu.Index; GpuSpeedViewModel gpuSpeedVm = _list.FirstOrDefault(a => a.GpuVm.Index == index); if (gpuSpeedVm != null) { gpuSpeedVm.MainCoinSpeed.FoundShare = message.Source.MainCoinSpeed.FoundShare; } }); AppContextEventPath <AcceptShareIncreasedEvent>("接受一个份额后刷新VM内存", LogEnum.DevConsole, action: message => { CheckReset(); int index = message.Source.Gpu.Index; GpuSpeedViewModel gpuSpeedVm = _list.FirstOrDefault(a => a.GpuVm.Index == index); if (gpuSpeedVm != null) { gpuSpeedVm.MainCoinSpeed.AcceptShare = message.Source.MainCoinSpeed.AcceptShare; } }); AppContextEventPath <RejectShareIncreasedEvent>("拒绝一个份额后刷新VM内存", LogEnum.DevConsole, action: message => { CheckReset(); int index = message.Source.Gpu.Index; GpuSpeedViewModel gpuSpeedVm = _list.FirstOrDefault(a => a.GpuVm.Index == index); if (gpuSpeedVm != null) { gpuSpeedVm.MainCoinSpeed.RejectShare = message.Source.MainCoinSpeed.RejectShare; } }); AppContextEventPath <IncorrectShareIncreasedEvent>("产生一个错误份额后刷新VM内存", LogEnum.DevConsole, action: message => { CheckReset(); int index = message.Source.Gpu.Index; GpuSpeedViewModel gpuSpeedVm = _list.FirstOrDefault(a => a.GpuVm.Index == index); if (gpuSpeedVm != null) { gpuSpeedVm.MainCoinSpeed.IncorrectShare = message.Source.MainCoinSpeed.IncorrectShare; } }); AppContextEventPath <GpuSpeedChangedEvent>("显卡算力变更后刷新VM内存", LogEnum.DevConsole, action: (message) => { CheckReset(); int index = message.Source.Gpu.Index; GpuSpeedViewModel gpuSpeedVm = _list.FirstOrDefault(a => a.GpuVm.Index == index); if (gpuSpeedVm != null) { if (message.IsDual) { gpuSpeedVm.DualCoinSpeed.UpdateSpeed(message.Source.DualCoinSpeed.Value, message.Source.DualCoinSpeed.SpeedOn); gpuSpeedVm.OnPropertyChanged(nameof(gpuSpeedVm.AverageDualCoinSpeedText)); } else { gpuSpeedVm.MainCoinSpeed.UpdateSpeed(message.Source.MainCoinSpeed.Value, message.Source.MainCoinSpeed.SpeedOn); gpuSpeedVm.OnPropertyChanged(nameof(gpuSpeedVm.AverageMainCoinSpeedText)); } } if (index == _totalSpeedVm.GpuVm.Index) { IMineContext mineContext = NTMinerRoot.Instance.CurrentMineContext; if (mineContext == null) { IncomeMainCoinPerDay = 0; IncomeMainCoinUsdPerDay = 0; IncomeMainCoinCnyPerDay = 0; IncomeDualCoinPerDay = 0; IncomeDualCoinUsdPerDay = 0; IncomeDualCoinCnyPerDay = 0; } else { if (message.IsDual) { if (mineContext is IDualMineContext dualMineContext) { IncomePerDay incomePerDay = NTMinerRoot.Instance.CalcConfigSet.GetIncomePerHashPerDay(dualMineContext.DualCoin.Code); IncomeDualCoinPerDay = _totalSpeedVm.DualCoinSpeed.Value * incomePerDay.IncomeCoin; IncomeDualCoinUsdPerDay = _totalSpeedVm.DualCoinSpeed.Value * incomePerDay.IncomeUsd; IncomeDualCoinCnyPerDay = _totalSpeedVm.DualCoinSpeed.Value * incomePerDay.IncomeCny; } } else { IncomePerDay incomePerDay = NTMinerRoot.Instance.CalcConfigSet.GetIncomePerHashPerDay(mineContext.MainCoin.Code); IncomeMainCoinPerDay = _totalSpeedVm.MainCoinSpeed.Value * incomePerDay.IncomeCoin; IncomeMainCoinUsdPerDay = _totalSpeedVm.MainCoinSpeed.Value * incomePerDay.IncomeUsd; IncomeMainCoinCnyPerDay = _totalSpeedVm.MainCoinSpeed.Value * incomePerDay.IncomeCny; } } } }); AppContextEventPath <Per1SecondEvent>("每秒钟更新算力活动时间", LogEnum.None, action: message => { TotalSpeedVm.MainCoinSpeed.OnPropertyChanged(nameof(SpeedViewModel.LastSpeedOnText)); TotalSpeedVm.DualCoinSpeed.OnPropertyChanged(nameof(SpeedViewModel.LastSpeedOnText)); }); #if DEBUG Write.DevTimeSpan($"耗时{Write.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
private GpuSpeedViewModels() { if (Design.IsInDesignMode) { return; } this.GpuAllVm = GpuViewModels.Current.FirstOrDefault(a => a.Index == NTMinerRoot.GpuAllId); IGpusSpeed gpuSpeeds = NTMinerRoot.Current.GpusSpeed; foreach (var item in gpuSpeeds) { this._list.Add(new GpuSpeedViewModel(item)); } _totalSpeedVm = this._list.FirstOrDefault(a => a.GpuVm.Index == NTMinerRoot.GpuAllId); VirtualRoot.On <GpuSpeedChangedEvent>("显卡算力变更后刷新VM内存", LogEnum.DevConsole, action: (message) => { Guid mainCoinId = NTMinerRoot.Current.MinerProfile.CoinId; if (_mainCoinId != mainCoinId) { _mainCoinId = mainCoinId; DateTime now = DateTime.Now; foreach (var item in _list) { item.MainCoinSpeed.Value = 0; item.MainCoinSpeed.SpeedOn = now; item.DualCoinSpeed.Value = 0; item.DualCoinSpeed.SpeedOn = now; } IncomeMainCoinPerDay = 0; IncomeMainCoinUsdPerDay = 0; IncomeMainCoinCnyPerDay = 0; IncomeDualCoinPerDay = 0; IncomeDualCoinUsdPerDay = 0; IncomeDualCoinCnyPerDay = 0; } int index = message.Source.Gpu.Index; GpuSpeedViewModel gpuSpeedVm = _list.FirstOrDefault(a => a.GpuVm.Index == index); if (gpuSpeedVm != null) { if (message.IsDualSpeed) { gpuSpeedVm.DualCoinSpeed.Update(message.Source.DualCoinSpeed); } else { gpuSpeedVm.MainCoinSpeed.Update(message.Source.MainCoinSpeed); } } if (index == _totalSpeedVm.GpuVm.Index) { IMineContext mineContext = NTMinerRoot.Current.CurrentMineContext; if (mineContext == null) { IncomeMainCoinPerDay = 0; IncomeMainCoinUsdPerDay = 0; IncomeMainCoinCnyPerDay = 0; IncomeDualCoinPerDay = 0; IncomeDualCoinUsdPerDay = 0; IncomeDualCoinCnyPerDay = 0; } else { if (message.IsDualSpeed) { if (mineContext is IDualMineContext dualMineContext) { IncomePerDay incomePerDay = NTMinerRoot.Current.CalcConfigSet.GetIncomePerHashPerDay(dualMineContext.DualCoin.Code); IncomeDualCoinPerDay = _totalSpeedVm.DualCoinSpeed.Value * incomePerDay.IncomeCoin; IncomeDualCoinUsdPerDay = _totalSpeedVm.DualCoinSpeed.Value * incomePerDay.IncomeUsd; IncomeDualCoinCnyPerDay = _totalSpeedVm.DualCoinSpeed.Value * incomePerDay.IncomeCny; } } else { IncomePerDay incomePerDay = NTMinerRoot.Current.CalcConfigSet.GetIncomePerHashPerDay(mineContext.MainCoin.Code); IncomeMainCoinPerDay = _totalSpeedVm.MainCoinSpeed.Value * incomePerDay.IncomeCoin; IncomeMainCoinUsdPerDay = _totalSpeedVm.MainCoinSpeed.Value * incomePerDay.IncomeUsd; IncomeMainCoinCnyPerDay = _totalSpeedVm.MainCoinSpeed.Value * incomePerDay.IncomeCny; } } } }); }
public static SpeedData CreateSpeedData() { INTMinerRoot root = NTMinerRoot.Instance; IWorkProfile workProfile = root.MinerProfile; string macAddress = string.Empty; string localIp = string.Empty; foreach (var item in VirtualRoot.LocalIpSet.AsEnumerable()) { if (macAddress.Length != 0) { macAddress += "," + item.MACAddress; localIp += "," + item.IPAddress; } else { macAddress = item.MACAddress; localIp = item.IPAddress; } } SpeedData data = new SpeedData { LocalServerMessageTimestamp = VirtualRoot.LocalServerMessageSetTimestamp, KernelSelfRestartCount = 0, IsAutoBoot = workProfile.IsAutoBoot, IsAutoStart = workProfile.IsAutoStart, AutoStartDelaySeconds = workProfile.AutoStartDelaySeconds, Version = MainAssemblyInfo.CurrentVersion.ToString(4), BootOn = root.CreatedOn, MineStartedOn = null, IsMining = root.IsMining, MineWorkId = Guid.Empty, MineWorkName = string.Empty, MinerName = workProfile.MinerName, GpuInfo = root.GpuSetInfo, ClientId = VirtualRoot.Id, MACAddress = macAddress, LocalIp = localIp, MainCoinCode = string.Empty, MainCoinWallet = string.Empty, MainCoinTotalShare = 0, MainCoinRejectShare = 0, MainCoinSpeed = 0, DualCoinCode = string.Empty, DualCoinTotalShare = 0, DualCoinRejectShare = 0, DualCoinSpeed = 0, DualCoinPool = string.Empty, DualCoinWallet = string.Empty, IsDualCoinEnabled = false, Kernel = string.Empty, MainCoinPool = string.Empty, OSName = Windows.OS.Instance.WindowsEdition, GpuDriver = root.GpuSet.DriverVersion.ToString(), GpuType = root.GpuSet.GpuType, OSVirtualMemoryMb = NTMinerRoot.OSVirtualMemoryMb, KernelCommandLine = string.Empty, DiskSpace = NTMinerRoot.DiskSpace, IsAutoRestartKernel = workProfile.IsAutoRestartKernel, AutoRestartKernelTimes = workProfile.AutoRestartKernelTimes, IsNoShareRestartKernel = workProfile.IsNoShareRestartKernel, NoShareRestartKernelMinutes = workProfile.NoShareRestartKernelMinutes, IsNoShareRestartComputer = workProfile.IsNoShareRestartComputer, NoShareRestartComputerMinutes = workProfile.NoShareRestartComputerMinutes, IsPeriodicRestartComputer = workProfile.IsPeriodicRestartComputer, PeriodicRestartComputerHours = workProfile.PeriodicRestartComputerHours, IsPeriodicRestartKernel = workProfile.IsPeriodicRestartKernel, PeriodicRestartKernelHours = workProfile.PeriodicRestartKernelHours, PeriodicRestartComputerMinutes = workProfile.PeriodicRestartComputerMinutes, PeriodicRestartKernelMinutes = workProfile.PeriodicRestartKernelMinutes, IsAutoStartByCpu = workProfile.IsAutoStartByCpu, IsAutoStopByCpu = workProfile.IsAutoStopByCpu, CpuGETemperatureSeconds = workProfile.CpuGETemperatureSeconds, CpuLETemperatureSeconds = workProfile.CpuLETemperatureSeconds, CpuStartTemperature = workProfile.CpuStartTemperature, CpuStopTemperature = workProfile.CpuStopTemperature, MainCoinPoolDelay = string.Empty, DualCoinPoolDelay = string.Empty, MinerIp = string.Empty, IsFoundOneGpuShare = false, IsGotOneIncorrectGpuShare = false, IsRejectOneGpuShare = false, CpuPerformance = root.CpuPackage.Performance, CpuTemperature = root.CpuPackage.Temperature, IsRaiseHighCpuEvent = workProfile.IsRaiseHighCpuEvent, HighCpuPercent = workProfile.HighCpuBaseline, HighCpuSeconds = workProfile.HighCpuSeconds, GpuTable = root.GpusSpeed.AsEnumerable().Where(a => a.Gpu.Index != NTMinerRoot.GpuAllId).Select(a => a.ToGpuSpeedData()).ToArray() }; if (workProfile.MineWork != null) { data.MineWorkId = workProfile.MineWork.GetId(); data.MineWorkName = workProfile.MineWork.Name; } #region 当前选中的币种是什么 if (root.ServerContext.CoinSet.TryGetCoin(workProfile.CoinId, out ICoin mainCoin)) { data.MainCoinCode = mainCoin.Code; ICoinProfile coinProfile = workProfile.GetCoinProfile(mainCoin.GetId()); data.MainCoinWallet = coinProfile.Wallet; if (root.ServerContext.PoolSet.TryGetPool(coinProfile.PoolId, out IPool mainCoinPool)) { data.MainCoinPool = mainCoinPool.Server; if (root.IsMining) { data.MainCoinPoolDelay = root.ServerContext.PoolSet.GetPoolDelayText(mainCoinPool.GetId(), isDual: false); } if (mainCoinPool.IsUserMode) { IPoolProfile mainCoinPoolProfile = workProfile.GetPoolProfile(coinProfile.PoolId); data.MainCoinWallet = mainCoinPoolProfile.UserName; } } else { data.MainCoinPool = string.Empty; } if (root.ServerContext.CoinKernelSet.TryGetCoinKernel(coinProfile.CoinKernelId, out ICoinKernel coinKernel)) { if (root.ServerContext.KernelSet.TryGetKernel(coinKernel.KernelId, out IKernel kernel)) { data.Kernel = kernel.GetFullName(); if (root.ServerContext.KernelOutputSet.TryGetKernelOutput(kernel.KernelOutputId, out IKernelOutput kernelOutput)) { data.IsFoundOneGpuShare = !string.IsNullOrEmpty(kernelOutput.FoundOneShare); data.IsGotOneIncorrectGpuShare = !string.IsNullOrEmpty(kernelOutput.GpuGotOneIncorrectShare); data.IsRejectOneGpuShare = !string.IsNullOrEmpty(kernelOutput.RejectOneShare); } ICoinKernelProfile coinKernelProfile = workProfile.GetCoinKernelProfile(coinProfile.CoinKernelId); data.IsDualCoinEnabled = coinKernelProfile.IsDualCoinEnabled; if (coinKernelProfile.IsDualCoinEnabled) { if (root.ServerContext.CoinSet.TryGetCoin(coinKernelProfile.DualCoinId, out ICoin dualCoin)) { data.DualCoinCode = dualCoin.Code; ICoinProfile dualCoinProfile = workProfile.GetCoinProfile(dualCoin.GetId()); data.DualCoinWallet = dualCoinProfile.DualCoinWallet; if (root.ServerContext.PoolSet.TryGetPool(dualCoinProfile.DualCoinPoolId, out IPool dualCoinPool)) { data.DualCoinPool = dualCoinPool.Server; if (root.IsMining) { data.DualCoinPoolDelay = root.ServerContext.PoolSet.GetPoolDelayText(dualCoinPool.GetId(), isDual: true); } if (dualCoinPool.IsUserMode) { IPoolProfile dualCoinPoolProfile = workProfile.GetPoolProfile(dualCoinProfile.DualCoinPoolId); data.DualCoinWallet = dualCoinPoolProfile.UserName; } } else { data.DualCoinPool = string.Empty; } } } } } } #endregion if (root.IsMining) { var mineContext = root.LockedMineContext; if (mineContext != null) { data.KernelSelfRestartCount = mineContext.KernelSelfRestartCount; data.MineStartedOn = mineContext.CreatedOn; data.KernelCommandLine = mineContext.CommandLine; } // 判断上次报告的算力币种和本次报告的是否相同,否则说明刚刚切换了币种默认第一次报告0算力 if (_sLastSpeedMainCoin == null || _sLastSpeedMainCoin == root.LockedMineContext.MainCoin) { _sLastSpeedMainCoin = root.LockedMineContext.MainCoin; Guid coinId = root.LockedMineContext.MainCoin.GetId(); IGpusSpeed gpuSpeeds = NTMinerRoot.Instance.GpusSpeed; IGpuSpeed totalSpeed = gpuSpeeds.CurrentSpeed(NTMinerRoot.GpuAllId); data.MainCoinSpeed = totalSpeed.MainCoinSpeed.Value; ICoinShare share = root.CoinShareSet.GetOrCreate(coinId); data.MainCoinTotalShare = share.TotalShareCount; data.MainCoinRejectShare = share.RejectShareCount; } else { _sLastSpeedMainCoin = root.LockedMineContext.MainCoin; } if (root.LockedMineContext is IDualMineContext dualMineContext) { // 判断上次报告的算力币种和本次报告的是否相同,否则说明刚刚切换了币种默认第一次报告0算力 if (_sLastSpeedDualCoin == null || _sLastSpeedDualCoin == dualMineContext.DualCoin) { _sLastSpeedDualCoin = dualMineContext.DualCoin; Guid coinId = dualMineContext.DualCoin.GetId(); IGpusSpeed gpuSpeeds = NTMinerRoot.Instance.GpusSpeed; IGpuSpeed totalSpeed = gpuSpeeds.CurrentSpeed(NTMinerRoot.GpuAllId); data.DualCoinSpeed = totalSpeed.DualCoinSpeed.Value; ICoinShare share = root.CoinShareSet.GetOrCreate(coinId); data.DualCoinTotalShare = share.TotalShareCount; data.DualCoinRejectShare = share.RejectShareCount; } else { _sLastSpeedDualCoin = dualMineContext.DualCoin; } } } return(data); }
private static void ReportSpeed(INTMinerRoot root) { try { SpeedData data = new SpeedData { MessageId = Guid.NewGuid(), MinerName = root.MinerProfile.MinerName, ClientId = ClientId.Id, Timestamp = DateTime.Now, MainCoinCode = string.Empty, MainCoinShareDelta = 0, MainCoinSpeed = 0, DualCoinCode = string.Empty, DualCoinShareDelta = 0, DualCoinSpeed = 0, IsMining = root.IsMining, DualCoinPool = string.Empty, DualCoinWallet = string.Empty, IsDualCoinEnabled = false, Kernel = string.Empty, MainCoinPool = string.Empty, MainCoinWallet = string.Empty }; ICoin mainCoin; if (root.CoinSet.TryGetCoin(root.MinerProfile.CoinId, out mainCoin)) { data.MainCoinCode = mainCoin.Code; ICoinProfile coinProfile = root.CoinProfileSet.GetCoinProfile(mainCoin.GetId()); IPool mainCoinPool; if (root.PoolSet.TryGetPool(coinProfile.PoolId, out mainCoinPool)) { data.MainCoinPool = mainCoinPool.Server; } else { data.MainCoinPool = string.Empty; } data.MainCoinWallet = coinProfile.Wallet; ICoinKernel coinKernel; if (root.CoinKernelSet.TryGetKernel(coinProfile.CoinKernelId, out coinKernel)) { IKernel kernel; if (root.KernelSet.TryGetKernel(coinKernel.KernelId, out kernel)) { data.Kernel = kernel.FullName; ICoinKernelProfile coinKernelProfile = root.CoinKernelProfileSet.GetCoinKernelProfile(coinProfile.CoinKernelId); data.IsDualCoinEnabled = coinKernelProfile.IsDualCoinEnabled; if (coinKernelProfile.IsDualCoinEnabled) { ICoin dualCoin; if (root.CoinSet.TryGetCoin(coinKernelProfile.DualCoinId, out dualCoin)) { data.DualCoinCode = dualCoin.Code; ICoinProfile dualCoinProfile = root.CoinProfileSet.GetCoinProfile(dualCoin.GetId()); data.DualCoinWallet = dualCoinProfile.DualCoinWallet; IPool dualCoinPool; if (root.PoolSet.TryGetPool(dualCoinProfile.DualCoinPoolId, out dualCoinPool)) { data.DualCoinPool = dualCoinPool.Server; } else { data.DualCoinPool = string.Empty; } } } } } } // 如果正在挖矿则报告算力,否则默认报告0算力 if (root.IsMining) { CoinShareData preCoinShare; Guid coinId = root.CurrentMineContext.MainCoin.GetId(); IGpusSpeed gpuSpeeds = NTMinerRoot.Current.GpusSpeed; IGpuSpeed totalSpeed = gpuSpeeds.CurrentSpeed(root.GpuAllId); data.MainCoinSpeed = (int)totalSpeed.MainCoinSpeed.Value; ICoinShare share = root.CoinShareSet.GetOrCreate(coinId); if (!_coinShareDic.TryGetValue(coinId, out preCoinShare)) { preCoinShare = new CoinShareData() { TotalShareCount = share.TotalShareCount }; _coinShareDic.Add(coinId, preCoinShare); data.MainCoinShareDelta = share.TotalShareCount; } else { data.MainCoinShareDelta = share.TotalShareCount - preCoinShare.TotalShareCount; } if (root.CurrentMineContext is IDualMineContext dualMineContext) { if (root.IsMining) { coinId = dualMineContext.DualCoin.GetId(); gpuSpeeds = NTMinerRoot.Current.GpusSpeed; totalSpeed = gpuSpeeds.CurrentSpeed(root.GpuAllId); data.DualCoinSpeed = (int)totalSpeed.DualCoinSpeed.Value; share = root.CoinShareSet.GetOrCreate(coinId); if (!_coinShareDic.TryGetValue(coinId, out preCoinShare)) { preCoinShare = new CoinShareData() { TotalShareCount = share.TotalShareCount }; _coinShareDic.Add(coinId, preCoinShare); data.DualCoinShareDelta = share.TotalShareCount; } else { data.DualCoinShareDelta = share.TotalShareCount - preCoinShare.TotalShareCount; } } } } Server.ReportService.ReportSpeed(data); } catch (Exception e) { Global.DebugLine(e.Message, ConsoleColor.Red); Global.DebugLine(e.StackTrace, ConsoleColor.Red); } }