فهرست منبع

评测数据结构

CrazyIter 5 سال پیش
والد
کامیت
6040d47b0d

+ 18 - 18
TEAMModelOS.SDK/Module/AzureCosmosDBV3/AzureCosmosDBV3Repository.cs

@@ -16,7 +16,7 @@ using TEAMModelOS.SDK.Module.AzureCosmosDB.Configuration;
 
 namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
 {
-    public class AzureCosmosDBV3Repository : IAzureCosmosDBV3Repository, IDisposable
+    public class AzureCosmosDBV3Repository : IAzureCosmosDBV3Repository
     {
         private CosmosClient CosmosClient { get; set; }
         /// <summary>
@@ -50,7 +50,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
             }
             catch (CosmosException e)
             {
-                Dispose(true);
+               // Dispose(true);
                 throw new BizException(e.Message, 500, e.StackTrace);
             }
         }
@@ -74,7 +74,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
             }
             catch (CosmosException e)
             {
-                Dispose(true);
+             //   Dispose(true);
                 throw new BizException(e.Message, 500, e.StackTrace);
             }
         }
@@ -234,7 +234,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
         public async Task DeleteAll<T>(List<KeyValuePair<string, string>> ids) where T : ID
         {
             string partitionKey = GetPartitionKey<T>();
-            await Task.Run(() => Parallel.ForEach(ids, (item) =>
+            await Task.Run(() => Parallel.ForEach(ids, new ParallelOptions { MaxDegreeOfParallelism = 2 }, (item) =>
             {
                 Task.WaitAll(DeleteAsync<T>(item.Value, item.Key));
             }));
@@ -244,7 +244,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
         {
             string partitionKey = GetPartitionKey<T>();
             Type type = typeof(T);
-            await Task.Run(() => Parallel.ForEach(entities, (item) =>
+            await Task.Run(() => Parallel.ForEach(entities, new ParallelOptions { MaxDegreeOfParallelism = 2 }, (item) =>
             {
                 object o = type.GetProperty(partitionKey).GetValue(item, null);
                 Task.WaitAll(DeleteAsync<T>(item.id, o.ToString()));
@@ -556,7 +556,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
         public async Task<List<T>> SaveAll<T>(List<T> enyites) where T : ID
         {
 
-            await Task.Run(() => Parallel.ForEach(enyites, (item) =>
+            await Task.Run(() => Parallel.ForEach(enyites, new ParallelOptions { MaxDegreeOfParallelism = 2 }, (item) =>
             {
                 Task.WaitAll(Save(item));
             }));
@@ -572,24 +572,24 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
 
         public async Task<List<T>> UpdateAll<T>(List<T> entities) where T : ID
         {
-            await Task.Run(() => Parallel.ForEach(entities, (item) =>
+            await Task.Run(() => Parallel.ForEach(entities, new ParallelOptions { MaxDegreeOfParallelism = 2 }, (item) =>
             {
                 Task.WaitAll(Update(item));
             }));
             return entities;
         }
 
-        public void Dispose()
-        {
-            Dispose(true);
-        }
-        protected virtual void Dispose(bool disposing)
-        {
-            if (disposing)
-            {
-                CosmosClient?.Dispose();
-            }
-        }
+        //public void Dispose()
+        //{
+        //    Dispose(true);
+        //}
+        //protected virtual void Dispose(bool disposing)
+        //{
+        //    if (disposing)
+        //    {
+        //        CosmosClient?.Dispose();
+        //    }
+        //}
 
         public async Task<T> FindById<T>(string id) where T : ID
         {

+ 7 - 0
TEAMModelOS.Service/Models/Evaluation/Models/ExamAnswer.cs

@@ -7,6 +7,9 @@ using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
 
 namespace TEAMModelOS.Service.Models.Evaluation.Models
 {
+    /// <summary>
+    /// 考生作答信息
+    /// </summary>
     [CosmosDB(RU = 400, Name = "ExamAnswer")]
     public class ExamAnswer :ID
     {
@@ -18,6 +21,10 @@ namespace TEAMModelOS.Service.Models.Evaluation.Models
         public string id { get; set; }
         [PartitionKey]
         public string Code { get; set; }
+        /// <summary>
+        /// 考试活动code
+        /// </summary>
+        public string examCode { get; set; }
         public List<List<string>> Answer { get; set; }
     }
 }

+ 29 - 4
TEAMModelOS.Service/Models/Evaluation/Models/ExamInfo.cs

@@ -7,20 +7,34 @@ using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
 
 namespace TEAMModelOS.Service.Models.Evaluation.Models
 {
+    /// <summary>
+    /// 考试基础信息
+    /// </summary>
     [CosmosDB(RU = 400, Name = "ExamInfo")]
     public class ExamInfo :ID
     {
         public ExamInfo() {
-
-            Conditions = new Condition();
         }
         [JsonProperty(PropertyName = "id")]
         public string id { get; set; }
         [PartitionKey]
         public string Code { get; set; }
-        public string Name { get; set; }
+        public string schoolCode { get; set; }
+        public string name { get; set; }
         public int StuCount { get; set; }
-        public string Time { get; set; }
+        public int createTime { get; set; }
+       
+       
+       
+        
+        /// <summary>
+        /// 施测起始时间
+        /// </summary>
+        public int startTime { get; set; }
+        /// <summary>
+        /// 施测结束时间
+        /// </summary>
+        public int endTime { get; set; }
         public Condition Conditions { get; set; }
     }
     public class Condition
@@ -28,9 +42,20 @@ namespace TEAMModelOS.Service.Models.Evaluation.Models
         public string Period { get; set; }
         public string Grade { get; set; }
         public string Semester { get; set; }
+        /// <summary>
+        /// 周考,期初考,期中考,期末考,诊断测验,模拟测验
+        /// </summary>
         public string Type { get; set; }
         public string Range { get; set; }
+        /// <summary>
+        /// 评测来源
+        /// </summary>
         public string FeedBackType { get; set; }
+        /// <summary>
+        /// 科目
+        /// </summary>
         public List<string> Subject { get; set; }
+        public List<string> classCodes { get; set; }
     }
+
 }

+ 10 - 1
TEAMModelOS.Service/Models/Evaluation/Models/ExamPaper.cs

@@ -7,9 +7,13 @@ using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
 
 namespace TEAMModelOS.Service.Models.Evaluation.Models
 {
+    /// <summary>
+    /// 试卷信息
+    /// </summary>
     [CosmosDB(RU = 400, Name = "ExamPaper")]
     public class ExamPaper :ID
     {
+
         public ExamPaper() {
             item = new List<ItemInfo>();
         }
@@ -17,7 +21,12 @@ namespace TEAMModelOS.Service.Models.Evaluation.Models
         public string id { get; set; }
         [PartitionKey]
         public string code { get; set; }
+        /// <summary>
+        /// 考试活动code
+        /// </summary>
+        public string examCode { get; set; }
         public List<ItemInfo> item { get; set; }       
-        public string Subject { get; set; }
+        public string subject { get; set; }
+        public string period { get; set; }
     }
 }

+ 49 - 2
TEAMModelOS.Service/Models/Evaluation/Models/ItemInfo.cs

@@ -1,11 +1,17 @@
 using System;
 using System.Collections.Generic;
 using System.Text;
+using TEAMModelOS.SDK.Context.Attributes.Azure;
+using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
 using TEAMModelOS.Service.Models.Core;
 
 namespace TEAMModelOS.Service.Models.Evaluation.Models
 {
-    public class ItemInfo
+    /// <summary>
+    /// 题目信息
+    /// </summary>
+    [CosmosDB(RU = 400, Name = "ItemInfo")]
+    public class ItemInfo :ID
     {
         public ItemInfo()
         {
@@ -15,18 +21,59 @@ namespace TEAMModelOS.Service.Models.Evaluation.Models
             points = new List<string>();
         }
         public string shaCode { get; set; }
+        //题干
         public string question { get; set; }
+        // 选项 单选 多选 判断
         public List<CodeValue> option { get; set; }
         public List<string> answer { get; set; }
+        //解析
         public string explain { get; set; }
+        /// <summary>
+        /// 题型  Single单选,Multiple多选,Judge判断,Complete填空,Subjective问答,Compose综合
+        /// </summary>
         public string type { get; set; }
+        /// <summary>
+        /// 上级shaCode
+        /// </summary>
         public string pShaCode { get; set; }
         //管理知识点
         public List<string> points { get; set; }
-        //认知层次
+        //认知层次 应用 综合 理解 评鉴 知识
         public string field { get; set; }
         public List<ItemInfo> children { get; set; }
         // 配分  
         public double score { get; set; }
+        /// <summary>
+        /// 题号
+        /// </summary>
+        public int order { get; set; }
+        //补救
+        public string repair { get; set; }
+        /// <summary>
+        /// 来源编码  个人 学校
+        /// </summary>
+        [PartitionKey]
+        public string scopeCode { get; set; }
+        /// <summary>
+        /// 学段
+        /// </summary>
+        public string period { get; set; }
+        /// <summary>
+        /// 年级
+        /// </summary>
+        public string grade { get; set; }
+        /// <summary>
+        /// 难度
+        /// </summary>
+        public int level { get; set; }
+        public string id { get ; set ; }
+        /// <summary>
+        /// 科目
+        /// </summary>
+        public string subject { get; set; }
+        /// <summary>
+        /// 是否综合题的小题
+        /// </summary>
+        public bool lite { get; set; } = false;
     }
 }

+ 4 - 4
TEAMModelOS.Service/Models/Evaluation/Models/SimpleExam.cs

@@ -7,6 +7,9 @@ using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
 
 namespace TEAMModelOS.Service.Model.Evaluation.Models
 {
+    /// <summary>
+    /// 考试成绩信息
+    /// </summary>
     [CosmosDB(RU = 400, Name = "SimpleExam")]
     public class SimpleExam :ID
     {
@@ -30,9 +33,6 @@ namespace TEAMModelOS.Service.Model.Evaluation.Models
         public List<string> Ids { get; set; }
         public List<int> Point { get; set; }
 
-        public void ForEach(Func<object, object> p)
-        {
-            throw new NotImplementedException();
-        }
+       
     }
 }

+ 1 - 1
TEAMModelOS.Service/Services/Evaluation/Implements/HtmlAnalyzeService.cs

@@ -261,7 +261,7 @@ namespace TEAMModelOS.Service.Services.Evaluation.Implements
                 {
                     dtos.ForEach(x => { testQs = testQs + x.shaCode; });
                     exercise.shaCode = ShaHashHelper.GetSHA1(testQs);
-                    dtos.ForEach(x => { x.pShaCode = exercise.shaCode; });
+                    dtos.ForEach(x => { x.pShaCode = exercise.shaCode; x.lite = true; });
                     exercise.children.AddRange(dtos);
                 }
                 exerciseDtos.Add(exercise);

+ 14 - 9
TEAMModelOS/Controllers/Core/StudentController.cs

@@ -131,15 +131,20 @@ namespace TEAMModelOS.Controllers.Syllabus
             Student data = await azureCosmosDBRepository.Update<Student>(request.@params);
             return builder.Data(data).build();
         }
-        [HttpPost("UpdateAllStudent")]
-        public async Task<BaseJosnRPCResponse> UpdateAllStudent(JosnRPCRequest<List<Student>> request)
-        {
-            JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
-            //bool find = request.@params.TryGetValue("find", out Dictionary<string, object> findObj);
-            //bool update = request.@params.TryGetValue("update", out Dictionary<string, object> updateObj);
-            List<Student> data = await azureCosmosDBRepository.UpdateAll<Student>(request.@params);
-            return builder.Data(data).build();
-        }
+        //[HttpPost("UpdateAllStudent")]
+        //public async Task<BaseJosnRPCResponse> UpdateAllStudent(JosnRPCRequest<Dictionary<string, Dictionary<string, object>>> request)
+        //{
+        //    JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
+        //    bool find = request.@params.TryGetValue("find", out Dictionary<string, object> findObj);
+        //    bool update = request.@params.TryGetValue("update", out Dictionary<string, object> updateObj);
+        //    List<Student> data = null ;
+        //    if (find && update)
+        //    {
+        //        data = await azureCosmosDBRepository.FindByDict<Student>(findObj);
+        //        data = await azureCosmosDBRepository.UpdateAll<Student>(findObj, updateObj);
+        //    }
+        //    return builder.Data(data).build();
+        //}
         /// <summary>
         /// 根据ID删除
         /// </summary>

+ 169 - 0
TEAMModelOS/Controllers/Evaluation/ExamController.cs

@@ -0,0 +1,169 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Mvc;
+using TEAMModelOS.SDK.Extension.DataResult.JsonRpcRequest;
+using TEAMModelOS.SDK.Extension.DataResult.JsonRpcResponse;
+using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
+using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
+using TEAMModelOS.Service.Models.Evaluation.Models;
+
+namespace TEAMModelOS.Controllers.Evaluation
+{
+    [Route("api/[controller]")]
+    [ApiController]
+    public class ExamController : BaseController
+    {
+        private readonly IAzureCosmosDBV3Repository cosmosDBV3Repository;
+        public ExamController(IAzureCosmosDBV3Repository _cosmosDBV3Repository) {
+            cosmosDBV3Repository = _cosmosDBV3Repository;
+        }
+        /// <summary>
+        /// 手动挑题
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpPost("Manual")]
+        public async Task<BaseJosnRPCResponse> Manual(JosnRPCRequest<Compose> request) {
+            JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
+            return builder.Data(null).build();
+        }
+        /// <summary>
+        /// 自动组题
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpPost("Automatic")]
+        public async Task<BaseJosnRPCResponse> Automatic(JosnRPCRequest<Compose> request) {
+            JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
+            Dictionary<string, object> dict = new Dictionary<string, object>();
+            if (request.@params.scopeCode.IsNotEmpty()) {
+                dict.Add("scopeCode", request.@params.scopeCode.ToArray());
+            }
+            if (request.@params.period.IsNotEmpty())
+            {
+                dict.Add("period", request.@params.period.ToArray());
+            }
+            ///处理知识点均分问题
+            int avg = 0;
+            Dictionary<string, int> point = new Dictionary<string, int>();
+            if (request.@params.points.IsNotEmpty())
+            {
+                avg=(int) Math.Ceiling( request.@params.count * 1.0 / request.@params.points.Count);
+                dict.Add("points", request.@params.points.ToArray());
+                foreach (string p in request.@params.points) {
+                    point.TryAdd(p, avg);
+                }
+            }
+            dict.Add("lite",false);
+            List<ItemInfo> itemInfos = new List<ItemInfo>();
+            if (request.@params.quInfos.IsNotEmpty())
+            {
+                List<string> types = new List<string>();
+                List<int> levels = new List<int>();
+                foreach (QuInfo quInfo in request.@params.quInfos) {
+                  //  types.Add(quInfo.type);
+                    if (quInfo.custom.IsNotEmpty() && quInfo.policy.Equals("custom"))
+                    {
+                        foreach (Custom custom in quInfo.custom) {
+                           
+                            dict.Add("type", quInfo.type);
+                            dict.Add("level", custom.level);
+                            List<ItemInfo> items = await cosmosDBV3Repository.FindByDict<ItemInfo>(dict);
+                            //id去重
+                            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);
+                            
+                            
+                        }
+                    }
+                    else {
+                        dict.Add("type", quInfo.type);
+                        List<ItemInfo> items = await cosmosDBV3Repository.FindByDict<ItemInfo>(dict);
+                        //id去重
+                        items = items.Where((x, i) => items.FindIndex(z => z.id == x.id) == i).ToList();
+                        //均分
+                        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();
+                            
+                            foreach (int i in lvls)
+                            {
+                                ////均分知识点题目
+                                itemInfos.AddRange(items.Where(x => x.level == i).OrderBy(x => Guid.NewGuid()).Take(quInfo.count / lvls.Count));
+                            }
+                        }
+                        //随机
+                        if (quInfo.policy.Equals("random"))
+                        {
+                            items = items.OrderBy(x => Guid.NewGuid()).Take(quInfo.count).ToList();
+
+                            itemInfos.AddRange(items);
+                        }
+                    }
+                }
+            }
+            
+            return builder.Data(null).build();
+        }
+    }
+
+    public class Compose {
+        /// <summary>
+        /// 科目
+        /// </summary>
+        public string subject { get; set; }
+        /// <summary>
+        /// 来源,个人题库,校本题库
+        /// </summary>
+        public List<string> scopeCode { get; set; }
+        /// <summary>
+        /// 适用学段,小学,初中,高中
+        /// </summary>
+        public List<string> period { get; set; }
+        /// <summary>
+        /// 关联知识点
+        /// </summary>
+        public List<string> points { get; set; }
+        /// <summary>
+        /// 题目组合
+        /// </summary>
+        public List<QuInfo> quInfos { get; set; }
+        /// <summary>
+        /// 题目总数
+        /// </summary>
+        public int count { get; set; }
+    }
+    public  class QuInfo{
+        /// <summary>
+        /// 题目类型,单选,多选,判断,填空,问答,综合
+        /// </summary>
+        public string type { get; set; }
+        /// <summary>
+        /// 随机 random  平均的 average ,自定义 custom
+        /// </summary>
+        public string policy { get; set; }
+        /// <summary>
+        /// 自定义题目类型
+        /// </summary>
+        public List<Custom> custom { get; set; }
+        /// <summary>
+        /// 总题
+        /// </summary>
+        public int count { get; set; }
+    }
+    public class Custom {
+        /// <summary>
+        /// 难易程度
+        /// </summary>
+        public int level { get; set; }
+        /// <summary>
+        /// 数量
+        /// </summary>
+        public int count { get; set; }
+    }
+}