|
@@ -1694,5 +1694,58 @@ namespace TEAMModelOS.Controllers.Analysis
|
|
|
public string name { get; set; }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ [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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|