浏览代码

新增字段记录选项

zhouj1203@hotmail.com 4 年之前
父节点
当前提交
1b85c79a4f
共有 2 个文件被更改,包括 80 次插入41 次删除
  1. 79 41
      TEAMModelFunction/TriggerExam.cs
  2. 1 0
      TEAMModelOS.SDK/Models/Cosmos/School/ExamInfo.cs

+ 79 - 41
TEAMModelFunction/TriggerExam.cs

@@ -329,8 +329,10 @@ namespace TEAMModelFunction
                     foreach (ExamSubject subject in info.subjects)
                     {
                         await createClassResultAsync(info, examClassResults, subject, fno, _azureCosmos);
+                        await examRecordCount(info,subject, _dingDing, fno, _azureStorage);
                         fno++;
                     }
+                    
                     //计算单次考试简易统计信息
                     List<ExamResult> examResults = new List<ExamResult>();
                     await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<ExamResult>(
@@ -338,6 +340,27 @@ namespace TEAMModelFunction
                     {
                         examResults.Add(item);
                     }
+                    //结算单科单班的标准差和平均分
+                    foreach (ExamResult exam in examResults) {
+                        //标记单科单班总得分
+                        double subScore = 0;
+                        //标准差
+                        double sPowSum = 0;
+                        var scount = exam.studentIds.Count;
+                        foreach (List<double> sc in exam.studentScores)
+                        {
+                            subScore += sc.Sum();
+                        }
+                        foreach (string sid in exam.studentIds)
+                        {
+                            double ssc = exam.studentScores[exam.studentIds.IndexOf(sid)].Sum();
+                            sPowSum += Math.Pow(ssc - scount > 0 ? Math.Round(subScore * 1.0 / scount, 2) : 0, 2);
+
+                        }
+                        exam.standard = Math.Round(scount > 0 ? Math.Pow(sPowSum / scount, 0.5) : 0, 2);
+                        exam.average = scount > 0 ? Math.Round(subScore / scount, 2) : 0;
+                        await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(exam, exam.id, new Azure.Cosmos.PartitionKey($"{exam.code}"));
+                    }
                     //记录某次考试所有学生得分总分
                     double score = 0;
                     double allScore = 0;
@@ -386,49 +409,64 @@ namespace TEAMModelFunction
                         info.sRate = NewsRate;
                         info.average = NewsRateScore;
                         await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync<ExamInfo>(info, info.id, new Azure.Cosmos.PartitionKey(info.code));
+                    }         
+                    break;
+            }
+        }
+        public static async Task examRecordCount(ExamInfo info, ExamSubject subject, DingDing _dingDing, int no,AzureStorageFactory _azureStorage) {
+            try
+            {
+                string blobcntr = "";
+                if (info.scope.Equals("school"))
+                {
+                    blobcntr = info.school;
+                }
+                else {
+                    blobcntr = info.creatorId;
+                }
+                var ContainerClient = _azureStorage.GetBlobContainerClient(blobcntr);
+                List<string> items = await ContainerClient.List($"exam/{info.id}/{subject.id}");
+                List<List<List<string>>> ansList = new List<List<List<string>>>();
+                foreach (string item in items)
+                {
+                    var Download = await _azureStorage.GetBlobContainerClient(blobcntr).GetBlobClient(item).DownloadAsync();
+                    var json = await JsonDocument.ParseAsync(Download.Value.Content);
+                    var Record = json.RootElement.ToObject<List<List<string>>>();
+                    ansList.Add(Record);
+                }
+                /*foreach (List<string> str in info.papers[no].answers) { 
+                    
+                }*/
+                List<Dictionary<string, int>> recorde = new List<Dictionary<string, int>>();
+                for (int i = 0;i< info.papers[no].answers.Count;i++) {
+                    if (info.papers[no].answers[i].Count <= 0) {
+                        recorde.Add(new Dictionary<string, int>());
+                        continue;
                     }
-                   
-                  
-                    //ActivityData data;
-                    /*if (info.scope == "school")
-                    {
-                        data = new ActivityData
-                        {
-                            id = info.id,
-                            code = $"Activity-{info.school}",
-                            type = "exam",
-                            name = info.name,
-                            startTime = info.startTime,
-                            endTime = info.endTime,
-                            scode = info.code,
-                            scope = info.scope,
-                            progress = "finish",
-                            classes = info.classes.IsNotEmpty() ? info.classes : new List<string> { "" },
-                            tmdids = new List<string> { "" },
-                            subjects = sub
-                        };
-                        await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<ActivityData>(data, info.id, new Azure.Cosmos.PartitionKey(data.code));
+                    Dictionary<string, int> optCount = new Dictionary<string, int>();
+                    foreach (List<List<string>> stu in ansList) {
+                        if (stu.Count == info.papers[no].answers.Count) {
+
+                            var item = stu[i];
+                            foreach (string opt in item) {
+                                if (optCount.ContainsKey(opt))
+                                {
+                                    optCount[opt] = optCount[opt] + 1;
+                                }
+                                else { 
+                                    optCount[opt] = 1; 
+                                }
+                            }
+                          
+                        }
                     }
-                    else if (info.scope == "private")
-                    {
-                        data = new ActivityData
-                        {
-                            id = info.id,
-                            code = $"Activity-Common",
-                            type = "exam",
-                            name = info.name,
-                            startTime = info.startTime,
-                            endTime = info.endTime,
-                            scode = info.code,
-                            scope = info.scope,
-                            progress = "finish",
-                            classes = info.classes.IsNotEmpty() ? info.classes : new List<string> { "" },
-                            tmdids = new List<string> { "" },
-                            subjects = sub
-                        };
-                        await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<ActivityData>(data, info.id, new Azure.Cosmos.PartitionKey(data.code));
-                    }*/
-                    break;
+                    recorde.Add(optCount);
+                }
+                info.papers[no].recorde = recorde;
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"评测作答记录结算异常{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
             }
         }
         public static async Task createClassResultAsync(ExamInfo info, List<ExamClassResult> examClassResults, ExamSubject subject, int no, AzureCosmosFactory _azureCosmos)

+ 1 - 0
TEAMModelOS.SDK/Models/Cosmos/School/ExamInfo.cs

@@ -116,6 +116,7 @@ namespace TEAMModelOS.SDK.Models
         //题目类型
         public List<string> type { get; set; } = new List<string>();
         public List<int> field { get; set; } = new List<int>();
+        public List<Dictionary<string, int>> recorde = new List<Dictionary<string, int>>();
     }
     /*public class Condition
     {