瀏覽代碼

实现自动组题算法,包含随机,均分,按难度自定义划分。并且将知识点随机到不同题型的不同难度的题目中

CrazyIter 5 年之前
父節點
當前提交
d6afe5b194

+ 1 - 1
TEAMModelOS.SDK/Context/Attributes/Azure/TableSpaceAttribute.cs

@@ -5,7 +5,7 @@ using System.Text;
 namespace TEAMModelOS.SDK.Context.Attributes.Azure
 namespace TEAMModelOS.SDK.Context.Attributes.Azure
 {
 {
     [AttributeUsage(AttributeTargets.Class)]
     [AttributeUsage(AttributeTargets.Class)]
-    public class TableSpaceAttribute :Attribute
+    public class TableNameAttribute : Attribute
     {
     {
         public string Name { get; set; }
         public string Name { get; set; }
     }
     }

+ 1 - 1
TEAMModelOS.SDK/Extension/JwtAuth/Models/JwtBlackRecord.cs

@@ -6,7 +6,7 @@ using TEAMModelOS.SDK.Context.Attributes.Azure;
 
 
 namespace TEAMModelOS.SDK.Extension.JwtAuth.Models
 namespace TEAMModelOS.SDK.Extension.JwtAuth.Models
 {
 {
-    [TableSpaceAttribute(Name = "Common")]
+    [TableNameAttribute(Name = "CommonJwtBlackRecord")]
     public class JwtBlackRecord :TableEntity
     public class JwtBlackRecord :TableEntity
     {
     {
         public string Jti { get; set; } 
         public string Jti { get; set; } 

+ 2 - 2
TEAMModelOS.SDK/Module/AzureTable/Implements/AzureTableDBRepository.cs

@@ -74,9 +74,9 @@ namespace TEAMModelOS.SDK.Module.AzureTable.Implements
             object[] attributes = type.GetCustomAttributes(true);
             object[] attributes = type.GetCustomAttributes(true);
             foreach (object attribute in attributes) //2.通过映射,找到成员属性上关联的特性类实例,
             foreach (object attribute in attributes) //2.通过映射,找到成员属性上关联的特性类实例,
             {
             {
-                if (attribute is TableSpaceAttribute tableSpace)
+                if (attribute is TableNameAttribute tableSpace)
                 {
                 {
-                    Name = tableSpace.Name + Name;
+                    Name = tableSpace.Name;
                 }
                 }
             }
             }
             return Name;
             return Name;

+ 4 - 4
TEAMModelOS.SDK/TEAMModelOS.SDK.csproj

@@ -2,10 +2,10 @@
 
 
   <PropertyGroup>
   <PropertyGroup>
     <TargetFramework>netcoreapp3.0</TargetFramework>
     <TargetFramework>netcoreapp3.0</TargetFramework>
-    <Version>2.0.4</Version>
-    <AssemblyVersion>2.0.0.3</AssemblyVersion>
-    <FileVersion>2.0.0.3</FileVersion>
-    <PackageReleaseNotes>jsonapi</PackageReleaseNotes>
+    <Version>2.0.6</Version>
+    <AssemblyVersion>2.0.0.6</AssemblyVersion>
+    <FileVersion>2.0.0.6</FileVersion>
+    <PackageReleaseNotes>更新TableNameAttribute</PackageReleaseNotes>
   </PropertyGroup>
   </PropertyGroup>
 
 
   <ItemGroup>
   <ItemGroup>

+ 1 - 1
TEAMModelOS.Service/Models/Core/ContentVerify.cs

@@ -6,7 +6,7 @@ using TEAMModelOS.SDK.Context.Attributes.Azure;
 
 
 namespace TEAMModelOS.Service.Models.Core
 namespace TEAMModelOS.Service.Models.Core
 {
 {
-    [TableSpace(Name = "Core")]
+    [TableName(Name = "CoreContentVerify")]
     public class ContentVerify : TableEntity
     public class ContentVerify : TableEntity
     {
     {
         public string Content { get; set; }
         public string Content { get; set; }

+ 1 - 1
TEAMModelOS.Service/Models/Core/LoginInfo.cs

@@ -8,7 +8,7 @@ namespace TEAMModelOS.Service.Models.Core
     /// <summary>
     /// <summary>
     /// 登录信息
     /// 登录信息
     /// </summary>
     /// </summary>
-    [TableSpace(Name = "Core")]
+    [TableName(Name = "CoreLoginInfo")]
     public class LoginInfo : TableEntity
     public class LoginInfo : TableEntity
     {
     {
         [JsonPropertyName("TEAMModelId")]
         [JsonPropertyName("TEAMModelId")]

+ 1 - 1
TEAMModelOS.Service/Models/Core/ResourceReference.cs

@@ -6,7 +6,7 @@ using TEAMModelOS.SDK.Context.Attributes.Azure;
 
 
 namespace TEAMModelOS.Service.Models.Core
 namespace TEAMModelOS.Service.Models.Core
 {
 {
-    [TableSpace(Name = "Core")]
+    [TableName(Name = "CoreResourceReference")]
     public class ResourceReference : TableEntity
     public class ResourceReference : TableEntity
     {
     {
         public string ResourceId { get; set; }
         public string ResourceId { get; set; }

+ 3 - 0
TEAMModelOS.Service/Models/Evaluation/Models/ItemInfo.cs

@@ -75,5 +75,8 @@ namespace TEAMModelOS.Service.Models.Evaluation.Models
         /// 是否综合题的小题
         /// 是否综合题的小题
         /// </summary>
         /// </summary>
         public bool lite { get; set; } = false;
         public bool lite { get; set; } = false;
+
+        //创建时间  
+        //使用次数
     }
     }
 }
 }

+ 1 - 1
TEAMModelOS.Service/Models/Syllabus/KnowledgeBlock.cs

@@ -4,7 +4,7 @@ using TEAMModelOS.SDK.Context.Attributes.Azure;
 
 
 namespace TEAMModelOS.Service.Models.Syllabus
 namespace TEAMModelOS.Service.Models.Syllabus
 {
 {
-    [TableSpace(Name = "Syllabus")]
+    [TableName(Name = "SyllabusKnowledgeBlock")]
     //
     //
     public class KnowledgeBlock : TableEntity
     public class KnowledgeBlock : TableEntity
     {
     {

+ 1 - 1
TEAMModelOS.Service/Models/Syllabus/KnowledgeBlockPoint.cs

@@ -4,7 +4,7 @@ using TEAMModelOS.SDK.Context.Attributes.Azure;
 
 
 namespace TEAMModelOS.Service.Models.Syllabus
 namespace TEAMModelOS.Service.Models.Syllabus
 {
 {
-    [TableSpace(Name = "Syllabus")]
+    [TableName(Name = "SyllabusKnowledgeBlockPoint")]
     //
     //
     public class KnowledgeBlockPoint : TableEntity
     public class KnowledgeBlockPoint : TableEntity
     {
     {

+ 1 - 1
TEAMModelOS.Service/Models/Syllabus/KnowledgePoint.cs

@@ -7,7 +7,7 @@ namespace TEAMModelOS.Service.Models.Syllabus
     /// <summary>
     /// <summary>
     /// 知识点
     /// 知识点
     /// </summary>
     /// </summary>
-    [TableSpace(Name = "Syllabus")]
+    [TableName(Name = "SyllabusKnowledgePoint")]
     //
     //
     public class KnowledgePoint : TableEntity
     public class KnowledgePoint : TableEntity
     {
     {

+ 42 - 14
TEAMModelOS/Controllers/Evaluation/ExamController.cs

@@ -57,27 +57,28 @@ namespace TEAMModelOS.Controllers.Evaluation
                 }
                 }
             }
             }
             dict.Add("lite",false);
             dict.Add("lite",false);
+            List<ItemInfo> retnInfos = new List<ItemInfo>();
             List<ItemInfo> itemInfos = new List<ItemInfo>();
             List<ItemInfo> itemInfos = new List<ItemInfo>();
+            List<TempItem> tempItems = new List<TempItem>();
             if (request.@params.quInfos.IsNotEmpty())
             if (request.@params.quInfos.IsNotEmpty())
             {
             {
                 List<string> types = new List<string>();
                 List<string> types = new List<string>();
                 List<int> levels = new List<int>();
                 List<int> levels = new List<int>();
                 foreach (QuInfo quInfo in request.@params.quInfos) {
                 foreach (QuInfo quInfo in request.@params.quInfos) {
-                  //  types.Add(quInfo.type);
+                    // 自定义
                     if (quInfo.custom.IsNotEmpty() && quInfo.policy.Equals("custom"))
                     if (quInfo.custom.IsNotEmpty() && quInfo.policy.Equals("custom"))
                     {
                     {
                         foreach (Custom custom in quInfo.custom) {
                         foreach (Custom custom in quInfo.custom) {
-                           
+                            for (int i = 0; i < custom.count; i++) {
+                                tempItems.Add(new TempItem { level = custom.level, type = quInfo.type });
+                            }
                             dict.Add("type", quInfo.type);
                             dict.Add("type", quInfo.type);
                             dict.Add("level", custom.level);
                             dict.Add("level", custom.level);
                             List<ItemInfo> items = await cosmosDBV3Repository.FindByDict<ItemInfo>(dict);
                             List<ItemInfo> items = await cosmosDBV3Repository.FindByDict<ItemInfo>(dict);
                             //id去重
                             //id去重
                             items = items.Where((x, i) => items.FindIndex(z => z.id == x.id) == i).ToList();
                             items = items.Where((x, i) => items.FindIndex(z => z.id == x.id) == i).ToList();
-                            items = items.OrderBy(x => Guid.NewGuid()).Take(custom.count).ToList();
                             ////均分知识点题目
                             ////均分知识点题目
                             itemInfos.AddRange(items);
                             itemInfos.AddRange(items);
-                            
-                            
                         }
                         }
                     }
                     }
                     else {
                     else {
@@ -85,33 +86,60 @@ namespace TEAMModelOS.Controllers.Evaluation
                         List<ItemInfo> items = await cosmosDBV3Repository.FindByDict<ItemInfo>(dict);
                         List<ItemInfo> items = await cosmosDBV3Repository.FindByDict<ItemInfo>(dict);
                         //id去重
                         //id去重
                         items = items.Where((x, i) => items.FindIndex(z => z.id == x.id) == i).ToList();
                         items = items.Where((x, i) => items.FindIndex(z => z.id == x.id) == i).ToList();
+                        itemInfos.AddRange(items);
                         //均分
                         //均分
                         if (quInfo.policy.Equals("average"))
                         if (quInfo.policy.Equals("average"))
                         {
                         {
                             //按等级去重 获取所有等级
                             //按等级去重 获取所有等级
                             List<int> lvls = items.Where((x, i) => items.FindIndex(z => z.level == x.level) == i).Select(x => x.level).ToList();
                             List<int> lvls = items.Where((x, i) => items.FindIndex(z => z.level == x.level) == i).Select(x => x.level).ToList();
-                            
                             foreach (int i in lvls)
                             foreach (int i in lvls)
                             {
                             {
-                                ////均分知识点题目
-                                itemInfos.AddRange(items.Where(x => x.level == i).OrderBy(x => Guid.NewGuid()).Take(quInfo.count / lvls.Count));
+                                int count = quInfo.count / lvls.Count;
+                                for (int j = 0; j < count; j++)
+                                {
+                                    tempItems.Add(new TempItem { level = i, type = quInfo.type });
+                                }
+                            }
+                            //  余数 取模 随机处理
+                            int mod = quInfo.count % lvls.Count;
+                            for (int m = 0; m < mod; m++) {
+                                int lv = lvls.OrderBy(x => Guid.NewGuid()).Take(1).FirstOrDefault();
+                                tempItems.Add(new TempItem { level = lv, type = quInfo.type });
+                                lvls.Remove(lv);
                             }
                             }
                         }
                         }
                         //随机
                         //随机
                         if (quInfo.policy.Equals("random"))
                         if (quInfo.policy.Equals("random"))
                         {
                         {
-                            items = items.OrderBy(x => Guid.NewGuid()).Take(quInfo.count).ToList();
-
-                            itemInfos.AddRange(items);
-                        }
+                            List<int> lvls = items.Where((x, i) => items.FindIndex(z => z.level == x.level) == i).Select(x => x.level).ToList();
+                            for (int n = 0; n < quInfo.count; n++) {
+                                int lv = lvls.OrderBy(x => Guid.NewGuid()).FirstOrDefault();
+                                tempItems.Add(new TempItem { level = lv, type = quInfo.type });
+                            }
+                        } 
                     }
                     }
                 }
                 }
             }
             }
-            
-            return builder.Data(null).build();
+            itemInfos = itemInfos.OrderBy(x=>Guid.NewGuid()).ToList();
+            tempItems =tempItems.OrderBy(x => Guid.NewGuid()).ToList();
+            foreach (TempItem temp in tempItems) {
+                ItemInfo itemInfo= itemInfos.Where(x => x.level == temp.level && x.type==temp.type).OrderBy(x => Guid.NewGuid()).FirstOrDefault();
+                if (itemInfo != null) {
+                    retnInfos.Add(itemInfo);
+                    itemInfos.Remove(itemInfo);
+                }
+            }
+            return builder.Data(retnInfos).build();
         }
         }
     }
     }
 
 
+    public class TempItem { 
+        public string type { get; set; }
+        public int level { get; set; }
+        public ItemInfo itemInfo { get; set; }
+    }
+
+
     public class Compose {
     public class Compose {
         /// <summary>
         /// <summary>
         /// 科目
         /// 科目