ntminer 5 years ago
parent
commit
c2f9dc547d

+ 2 - 0
src/AppModels/AppModels.csproj

@@ -93,6 +93,7 @@
     <Compile Include="MinerStudio\MinerStudioRoot.cs" />
     <Compile Include="MinerStudio\Vms\ChangePasswordViewModel.cs" />
     <Compile Include="MinerStudio\Vms\CpuDataViewModel.cs" />
+    <Compile Include="MinerStudio\Vms\GpuNameCountViewModel.cs" />
     <Compile Include="MinerStudio\Vms\IWsStateViewModel.cs" />
     <Compile Include="Messages.cs" />
     <Compile Include="MinerStudio\ILocalMinerStudioService.cs" />
@@ -128,6 +129,7 @@
     <Compile Include="Vms\CoinProfileViewModel.cs" />
     <Compile Include="MinerStudio\Vms\CoinSnapshotViewModel.cs" />
     <Compile Include="MinerStudio\Vms\ColumnsShowSelectViewModel.cs" />
+    <Compile Include="Vms\GpuNameViewModel.cs" />
     <Compile Include="Vms\InnerPropertyViewModel.cs" />
     <Compile Include="Vms\KernelOutputKeywordViewModel.cs" />
     <Compile Include="Vms\KernelOutputKeywordsViewModel.cs" />

+ 82 - 0
src/AppModels/MinerStudio/Vms/GpuNameCountViewModel.cs

@@ -0,0 +1,82 @@
+using NTMiner.Core;
+using NTMiner.Core.Gpus;
+using NTMiner.Vms;
+
+namespace NTMiner.MinerStudio.Vms {
+    public class GpuNameCountViewModel : ViewModelBase, IGpuNameCount {
+        private GpuType _gpuType;
+        private string _name;
+        private ulong _totalMemory;
+        private int _count;
+
+        public GpuNameCountViewModel(IGpuNameCount data) {
+            _gpuType = data.GpuType;
+            _name = data.Name;
+            _totalMemory = data.TotalMemory;
+            _count = data.Count;
+        }
+
+        public int Count {
+            get => _count;
+            set {
+                if (_count != value) {
+                    _count = value;
+                    OnPropertyChanged(nameof(Count));
+                }
+            }
+        }
+
+        public GpuType GpuType {
+            get => _gpuType;
+            set {
+                if (_gpuType != value) {
+                    _gpuType = value;
+                    OnPropertyChanged(nameof(GpuType));
+                }
+            }
+        }
+
+        public string Name {
+            get => _name;
+            set {
+                if (_name != value) {
+                    _name = value;
+                    OnPropertyChanged(nameof(Name));
+                }
+            }
+        }
+
+        public ulong TotalMemory {
+            get => _totalMemory;
+            set {
+                if (_totalMemory != value) {
+                    _totalMemory = value;
+                    OnPropertyChanged(nameof(TotalMemory));
+                }
+            }
+        }
+
+        public bool IsValid() {
+            return GpuName.IsValid(this.GpuType, this.Name, this.TotalMemory);
+        }
+
+        public override bool Equals(object obj) {
+            if (obj == null) {
+                return false;
+            }
+            return this.ToString() == obj.ToString(); ;
+        }
+
+        public override int GetHashCode() {
+            return this.ToString().GetHashCode();
+        }
+
+        /// <summary>
+        /// 该ToString字符串会被作为redis key使用
+        /// </summary>
+        /// <returns></returns>
+        public override string ToString() {
+            return GpuName.Format(this.GpuType, this.Name, this.TotalMemory);
+        }
+    }
+}

+ 69 - 0
src/AppModels/Vms/GpuNameViewModel.cs

@@ -0,0 +1,69 @@
+using NTMiner.Core;
+using NTMiner.Core.Gpus;
+
+namespace NTMiner.Vms {
+    public class GpuNameViewModel : ViewModelBase, IGpuName {
+        private GpuType _gpuType;
+        private string _name;
+        private ulong _totalMemory;
+
+        public GpuNameViewModel(IGpuName data) {
+            _gpuType = data.GpuType;
+            _name = data.Name;
+            _totalMemory = data.TotalMemory;
+        }
+
+        public GpuType GpuType {
+            get => _gpuType;
+            set {
+                if (_gpuType != value) {
+                    _gpuType = value;
+                    OnPropertyChanged(nameof(GpuType));
+                }
+            }
+        }
+
+        public string Name {
+            get => _name;
+            set {
+                if (_name != value) {
+                    _name = value;
+                    OnPropertyChanged(nameof(Name));
+                }
+            }
+        }
+
+        public ulong TotalMemory {
+            get => _totalMemory;
+            set {
+                if (_totalMemory != value) {
+                    _totalMemory = value;
+                    OnPropertyChanged(nameof(TotalMemory));
+                }
+            }
+        }
+
+        public bool IsValid() {
+            return GpuName.IsValid(this.GpuType, this.Name, this.TotalMemory);
+        }
+
+        public override bool Equals(object obj) {
+            if (obj == null) {
+                return false;
+            }
+            return this.ToString() == obj.ToString(); ;
+        }
+
+        public override int GetHashCode() {
+            return this.ToString().GetHashCode();
+        }
+
+        /// <summary>
+        /// 该ToString字符串会被作为redis key使用
+        /// </summary>
+        /// <returns></returns>
+        public override string ToString() {
+            return GpuName.Format(this.GpuType, this.Name, this.TotalMemory);
+        }
+    }
+}

+ 4 - 0
src/AppModels/Vms/GpuViewModel.cs

@@ -756,5 +756,9 @@ namespace NTMiner.Vms {
                 NTMinerContext.RefreshArgsAssembly.Invoke("勾选或反勾选了显卡");
             }
         }
+
+        bool IGpuName.IsValid() {
+            return GpuName.IsValid(this.GpuType, this.Name, this.TotalMemory);
+        }
     }
 }

+ 4 - 0
src/NTMinerClient/Core/Gpus/Impl/Gpu.cs

@@ -51,5 +51,9 @@
         public int TempLimit { get; set; }
         public int CoreVoltage { get; set; }
         public int MemoryVoltage { get; set; }
+
+        bool IGpuName.IsValid() {
+            return GpuName.IsValid(this.GpuType, this.Name, this.TotalMemory);
+        }
     }
 }

+ 4 - 0
src/NTMinerDataSchemas/Core/Gpus/GpuData.cs

@@ -25,5 +25,9 @@
         public int TempLimitMin { get; set; }
         public int TempLimitDefault { get; set; }
         public int TempLimitMax { get; set; }
+
+        bool IGpuName.IsValid() {
+            return GpuName.IsValid(this.GpuType, this.Name, this.TotalMemory);
+        }
     }
 }

+ 5 - 1
src/NTMinerDataSchemas/Core/Gpus/GpuName.cs

@@ -14,6 +14,10 @@
             return $"{gpuType.GetName()}///{gpuName}///{totalMemoryGb.ToString()}";
         }
 
+        public static bool IsValid(GpuType gpuType, string name, ulong totalMemory) {
+            return gpuType != GpuType.Empty && !string.IsNullOrEmpty(name) && IsValidTotalMemory(totalMemory);
+        }
+
         public GpuName() { }
 
         public GpuType GpuType { get; set; }
@@ -26,7 +30,7 @@
         public ulong TotalMemory { get; set; }
 
         public bool IsValid() {
-            return GpuType != GpuType.Empty && !string.IsNullOrEmpty(Name) && IsValidTotalMemory(TotalMemory);
+            return IsValid(this.GpuType, this.Name, this.TotalMemory);
         }
 
         public override bool Equals(object obj) {

+ 33 - 10
src/NTMinerDataSchemas/Core/Gpus/GpuNameCount.cs

@@ -2,18 +2,41 @@
     /// <summary>
     /// GpuNameCount是挖矿端上报到服务端的显卡的原始名。而<see cref="GpuName"/>是管理员人脑基于GpuNameCount集提取的特征名。
     /// </summary>
-    public class GpuNameCount : GpuName {
-        public static GpuNameCount Create(GpuName gpuName) {
-            return new GpuNameCount {
-                GpuType = gpuName.GpuType,
-                Count = 0,
-                Name = gpuName.Name,
-                TotalMemory = gpuName.TotalMemory
-            };
-        }
-
+    public class GpuNameCount : IGpuNameCount {
         public GpuNameCount() { }
 
+        public GpuType GpuType { get; set; }
+
+        /// <summary>
+        /// 注意:匹配名称的时候注意按照名称长短的顺序由长到短运算,就是说先用5700关键字匹配再用570关键字匹配。
+        /// </summary>
+        public string Name { get; set; }
+
+        public ulong TotalMemory { get; set; }
+
         public int Count { get; set; }
+
+        public bool IsValid() {
+            return GpuName.IsValid(this.GpuType, this.Name, this.TotalMemory);
+        }
+
+        public override bool Equals(object obj) {
+            if (obj == null) {
+                return false;
+            }
+            return this.ToString() == obj.ToString(); ;
+        }
+
+        public override int GetHashCode() {
+            return this.ToString().GetHashCode();
+        }
+
+        /// <summary>
+        /// 该ToString字符串会被作为redis key使用
+        /// </summary>
+        /// <returns></returns>
+        public override string ToString() {
+            return GpuName.Format(this.GpuType, this.Name, this.TotalMemory);
+        }
     }
 }

+ 1 - 0
src/NTMinerDataSchemas/Core/Gpus/IGpuName.cs

@@ -6,5 +6,6 @@
         /// 单位Byte
         /// </summary>
         ulong TotalMemory { get; set; }
+        bool IsValid();
     }
 }

+ 5 - 0
src/NTMinerDataSchemas/Core/Gpus/IGpuNameCount.cs

@@ -0,0 +1,5 @@
+namespace NTMiner.Core.Gpus {
+    public interface IGpuNameCount : IGpuName {
+        int Count { get; }
+    }
+}

+ 1 - 0
src/NTMinerDataSchemas/NTMinerDataSchemas.csproj

@@ -46,6 +46,7 @@
     <Compile Include="Core\Gpus\GpuName.cs" />
     <Compile Include="Core\Gpus\GpuNameCount.cs" />
     <Compile Include="Core\Gpus\IGpuName.cs" />
+    <Compile Include="Core\Gpus\IGpuNameCount.cs" />
     <Compile Include="Core\ICaptcha.cs" />
     <Compile Include="Core\IOperationResult.cs" />
     <Compile Include="Core\LocalMessageDto.cs" />

+ 5 - 4
src/WebApiServer/Core/Impl/GpuNameSet.cs

@@ -40,11 +40,12 @@ namespace NTMiner.Core.Impl {
                 gpuNameCount.Count++;
             }
             else {
-                gpuNameCount = GpuNameCount.Create(new GpuName {
-                    GpuType = gpuType,
+                gpuNameCount = new GpuNameCount {
+                    TotalMemory = gpuTotalMemory,
                     Name = gpuName,
-                    TotalMemory = gpuTotalMemory
-                });
+                    GpuType = gpuType,
+                    Count = 1
+                };
                 _dic.Add(key, gpuNameCount);
             }
         }