Ver Fonte

处理结算分数为-1的情况

zhouj1203@hotmail.com há 4 anos atrás
pai
commit
4decbf30d9

+ 5 - 1
TEAMModelFunction/ExamTrigger.cs

@@ -207,7 +207,11 @@ namespace TEAMModelFunction
                 {
                 {
                     foreach (List<double> scores in classResult.studentScores)
                     foreach (List<double> scores in classResult.studentScores)
                     {
                     {
-                        result.studentScores.Add(scores);
+                        List<double> newScores = new List<double>();
+                        foreach (double sc in scores) {
+                            newScores.Add(sc > -1 ? sc : 0);
+                        }
+                        result.studentScores.Add(newScores);
                     }
                     }
                     //处理班级信息
                     //处理班级信息
                     ClassRange range = new ClassRange();
                     ClassRange range = new ClassRange();

+ 53 - 0
TEAMModelOS/Controllers/Analysis/AnalysisController.cs

@@ -1687,5 +1687,58 @@ namespace TEAMModelOS.Controllers.Analysis
             }
             }
         }
         }
 
 
+
+        [HttpPost("studentAnalysis")]
+        public async Task<IActionResult> studentAnalysis(JsonElement request)
+        {
+            //获取个人或者校本
+            if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
+            //评测Id
+            if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
+            if (!request.TryGetProperty("sId", out JsonElement sId)) return BadRequest();
+            if (!request.TryGetProperty("cId", out JsonElement cId)) return BadRequest();
+            if (!request.TryGetProperty("gId", out JsonElement gId)) return BadRequest();
+            try
+            {
+                List<Dictionary<string, object>> averageMap = new List<Dictionary<string, object>>();
+                List<Dictionary<string, object>> averageTotal = new List<Dictionary<string, object>>();
+                var client = _azureCosmos.GetCosmosClient();
+                ExamInfo info = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"Exam-{code}"));
+                List<ExamResult> examResults = new List<ExamResult>();
+                var query = $"select c.id,c.name,c.subjectId,c.studentScores,c.studentIds,c.paper,c.classes from c where c.examId =  '{id}' ";
+                await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<ExamResult>(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamResult-{id}") }))
+                {
+                    examResults.Add(item);
+                }
+                foreach (ExamResult result in examResults)
+                {
+                    List<double> ClassAverage = new List<double>();
+                    List<string> ClassName = new List<string>();
+                    Dictionary<string, object> mapClass = new Dictionary<string, object>();
+                    int index = result.studentIds.IndexOf(sId.ToString());
+
+                    mapClass.Add("subjectId", result.subjectId);
+                    foreach (ClassRange range in result.classes)
+                    {
+                            double totalClass = 0;
+                            for (int i = range.range[0]; i <= range.range[1]; i++)
+                            {
+                                totalClass += result.studentScores[i].Sum();
+                            }
+                            ClassAverage.Add(range.range[1] - range.range[0] + 1 > 0 ? totalClass * 1.0 / (range.range[1] - range.range[0] + 1) : 0);                   
+                    }
+                    mapClass.Add("Score",result.studentScores[index].Sum());
+                    mapClass.Add("ClassAverage", ClassAverage);                
+                    averageMap.Add(mapClass);
+                }
+                return Ok(new { averageMap});
+            }
+            catch (Exception e)
+            {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/studentAnalysis()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
+                return BadRequest();
+            }
+        }
+
     }
     }
 }
 }

+ 10 - 0
TEAMModelOS/Controllers/Common/ExamController.cs

@@ -359,6 +359,16 @@ namespace TEAMModelOS.Controllers
                         result.studentAnswers.Add(new List<string>());
                         result.studentAnswers.Add(new List<string>());
                         result.sum.Add(0);
                         result.sum.Add(0);
                     }
                     }
+                    int flagCount = 0;
+                    foreach (List<string> str in ans) {
+
+                            if (str.Count == 0) {
+                                flagCount++;
+                        }
+                    }
+                    if (flagCount == standard.Count) {
+                        continue;
+                    }
                     int newIndex = result.studentIds.IndexOf(studentId.ToString());
                     int newIndex = result.studentIds.IndexOf(studentId.ToString());
                     string FileName = result.examId + "/" + result.subjectId+"/" +studentId ;
                     string FileName = result.examId + "/" + result.subjectId+"/" +studentId ;
                     string blob = await _azureStorage.UploadFileByContainer(school.ToString(), ans.ToJsonString(), "exam", FileName +"/"+ "ans.json");
                     string blob = await _azureStorage.UploadFileByContainer(school.ToString(), ans.ToJsonString(), "exam", FileName +"/"+ "ans.json");