ntminer 5 years ago
parent
commit
53c60e6670

+ 19 - 0
src/NTMinerDataSchemas/Core/Gpus/GpuName.cs

@@ -0,0 +1,19 @@
+namespace NTMiner.Core.Gpus {
+    public class GpuName : IGpuName {
+        public GpuName() { }
+
+        public string Name { get; set; }
+
+        public ulong TotalMemory { get; set; }
+
+        public override int GetHashCode() {
+            return this.ToString().GetHashCode();
+        }
+
+        public override string ToString() {
+            const ulong gb = 1024 * 1024 * 1024;
+            ulong totalMemoryGb = (this.TotalMemory + gb) / gb;
+            return $"{this.Name}///{totalMemoryGb.ToString()}";
+        }
+    }
+}

+ 1 - 0
src/NTMinerDataSchemas/NTMinerDataSchemas.csproj

@@ -42,6 +42,7 @@
   <ItemGroup>
     <Compile Include="Base64Util.cs" />
     <Compile Include="Core\CaptchaData.cs" />
+    <Compile Include="Core\Gpus\GpuName.cs" />
     <Compile Include="Core\Gpus\IGpuName.cs" />
     <Compile Include="Core\ICaptcha.cs" />
     <Compile Include="Core\IOperationResult.cs" />

+ 11 - 0
src/UnitTests/UnitTest1.cs

@@ -15,6 +15,17 @@ using System.Windows;
 namespace NTMiner {
     [TestClass]
     public class UnitTest1 {
+        [TestMethod]
+        public void CeilingTest() {
+            const ulong gb = 1024 * 1024 * 1024;
+            ulong totalMemory = (ulong)(3.9 * gb);
+            ulong totalMemoryGb = (totalMemory + gb) / gb;
+            Assert.IsTrue(4 == totalMemoryGb);
+            totalMemory = (ulong)(3.1 * gb);
+            totalMemoryGb = (totalMemory + gb) / gb;
+            Assert.IsTrue(4 == totalMemoryGb);
+        }
+
         [TestMethod]
         public void MaxValueText() {
             Console.WriteLine(ushort.MaxValue);

+ 9 - 0
src/WebApiServer/Core/IGpuNameSet.cs

@@ -0,0 +1,9 @@
+using NTMiner.Core.Gpus;
+using System.Collections.Generic;
+
+namespace NTMiner.Core {
+    public interface IGpuNameSet {
+        void Add(GpuName gpuName);
+        IEnumerable<IGpuName> AsEnumerable();
+    }
+}

+ 22 - 0
src/WebApiServer/Core/Impl/GpuNameSet.cs

@@ -0,0 +1,22 @@
+using NTMiner.Core.Gpus;
+using System.Collections.Generic;
+
+namespace NTMiner.Core.Impl {
+    public class GpuNameSet : IGpuNameSet {
+        private readonly HashSet<GpuName> _hashSet = new HashSet<GpuName>();
+
+        public GpuNameSet() {
+        }
+
+        public void Add(GpuName gpuName) {
+            if (gpuName == null) {
+                return;
+            }
+            _hashSet.Add(gpuName);
+        }
+
+        public IEnumerable<IGpuName> AsEnumerable() {
+            return _hashSet;
+        }
+    }
+}

+ 3 - 0
src/WebApiServer/WebApiRoot.cs

@@ -80,6 +80,7 @@ namespace NTMiner {
                         NTMinerWalletSet = new NTMinerWalletSet();
                         ClientDataSet clientDataSet = new ClientDataSet(minerRedis, speedDataRedis, minerClientMqSender);
                         ClientDataSet = clientDataSet;
+                        GpuNameSet = new GpuNameSet();
                         CoinSnapshotSet = new CoinSnapshotSet(clientDataSet);
                         MineWorkSet = new UserMineWorkSet();
                         MinerGroupSet = new UserMinerGroupSet();
@@ -167,6 +168,8 @@ namespace NTMiner {
 
         public static IClientDataSet ClientDataSet { get; private set; }
 
+        public static IGpuNameSet GpuNameSet { get; private set; }
+
         public static ICoinSnapshotSet CoinSnapshotSet { get; private set; }
 
         public static IUserMineWorkSet MineWorkSet { get; private set; }

+ 2 - 0
src/WebApiServer/WebApiServer.csproj

@@ -96,6 +96,8 @@
     </Compile>
     <Compile Include="Controllers\ClientDataBinaryController.cs" />
     <Compile Include="Controllers\ReportBinaryController.cs" />
+    <Compile Include="Core\IGpuNameSet.cs" />
+    <Compile Include="Core\Impl\GpuNameSet.cs" />
     <Compile Include="Role\AdminAttribute.cs" />
     <Compile Include="Role\UserAttribute.cs" />
     <Compile Include="Controllers\ApiControllerBase.cs" />