|
@@ -0,0 +1,216 @@
|
|
|
+using Azure.Cosmos;
|
|
|
+using ClouDASLibx;
|
|
|
+using Google.Protobuf.WellKnownTypes;
|
|
|
+using Microsoft.AspNetCore.Authorization;
|
|
|
+using Microsoft.AspNetCore.Mvc;
|
|
|
+using Microsoft.Extensions.Options;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System.Text.Json;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using TEAMModelOS.Filter;
|
|
|
+using TEAMModelOS.SDK;
|
|
|
+using TEAMModelOS.SDK.DI;
|
|
|
+using TEAMModelOS.SDK.Extension;
|
|
|
+using TEAMModelOS.SDK.Helper.Common.StringHelper;
|
|
|
+using TEAMModelOS.SDK.Models;
|
|
|
+using TEAMModelOS.SDK.Models.Cosmos.Common;
|
|
|
+
|
|
|
+namespace TEAMModelOS.Controllers.Analysis
|
|
|
+{
|
|
|
+ [Route("analysis/art")]
|
|
|
+ [ApiController]
|
|
|
+ public class ArtAnalysisController : ControllerBase
|
|
|
+ {
|
|
|
+ private readonly AzureCosmosFactory _azureCosmos;
|
|
|
+ private readonly DingDing _dingDing;
|
|
|
+ private readonly Option _option;
|
|
|
+ private readonly CoreAPIHttpService _coreAPIHttpService;
|
|
|
+
|
|
|
+ public ArtAnalysisController(AzureCosmosFactory azureCosmos, DingDing dingDing, IOptionsSnapshot<Option> option, CoreAPIHttpService coreAPIHttpService)
|
|
|
+ {
|
|
|
+ _azureCosmos = azureCosmos;
|
|
|
+ _dingDing = dingDing;
|
|
|
+ _option = option?.Value;
|
|
|
+ _coreAPIHttpService = coreAPIHttpService;
|
|
|
+ }
|
|
|
+
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("statistics")]
|
|
|
+ [Authorize(Roles = "IES")]
|
|
|
+ [AuthToken(Roles = "teacher,admin")]
|
|
|
+ public async Task<IActionResult> getAnalysis(JsonElement request) {
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
|
|
|
+ if (!request.TryGetProperty("period", out JsonElement period)) return BadRequest();
|
|
|
+ try {
|
|
|
+ List<double> scores = new();
|
|
|
+ List<ArtEvaluation> arts = new();
|
|
|
+ string artId = string.Empty;
|
|
|
+ if (!request.TryGetProperty("id", out JsonElement id))
|
|
|
+ {
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryStreamIterator(queryText: $"SELECT top 1 FROM c where c.period ='{period}' order by c.createTime ",
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Art-{code}") }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ arts.Add(obj.ToObject<ArtEvaluation>());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ artId = arts[0].id;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ artId = id.GetString();
|
|
|
+ }
|
|
|
+ string queryScore = $" select c.totalScore from c ";
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Student).GetItemQueryStreamIterator
|
|
|
+ (queryText: queryScore, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"ArtResult-{artId}") }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
+ {
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ if (obj.TryGetProperty("totalScore", out JsonElement element))
|
|
|
+ {
|
|
|
+ double sc = element.GetDouble();
|
|
|
+ scores.Add(sc);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ scores.Add(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ //获取知识点得分率
|
|
|
+ private static (KeyValuePair<string, List<string>>, KeyValuePair<string, List<string>>) DoKnowledgePoint(ExamResult exam, ExamInfo info)
|
|
|
+ {
|
|
|
+ HashSet<string> knowledge = new HashSet<string>();
|
|
|
+ List<double> point = new List<double>();
|
|
|
+ List<List<double>> result = new List<List<double>>();
|
|
|
+ List<ClassRange> classes = new List<ClassRange>();
|
|
|
+ //求单个知识点所占分数
|
|
|
+ List<string> per = new List<string>();
|
|
|
+
|
|
|
+ //定位试卷信息
|
|
|
+ int index = 0;
|
|
|
+ foreach (ExamSubject subject in info.subjects)
|
|
|
+ {
|
|
|
+ if (subject.id.Equals(exam.subjectId))
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ index++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (info.papers[index].knowledge != null && info.papers[index].knowledge.Count > 0)
|
|
|
+ {
|
|
|
+ info.papers[index].knowledge.ForEach(k =>
|
|
|
+ {
|
|
|
+ k.ForEach(e =>
|
|
|
+ {
|
|
|
+ knowledge.Add(e);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return (default, default);
|
|
|
+ }
|
|
|
+ point = info.papers[index].point;
|
|
|
+ result = exam.studentScores;
|
|
|
+ classes = exam.classes;
|
|
|
+
|
|
|
+ /* //确定高分组 最低分数
|
|
|
+
|
|
|
+ double[] points = StringHelper.ListTodouble(exam.paper.point);
|
|
|
+ double[,] scs = StringHelper.ListToDouble(exam.studentScores);
|
|
|
+ var cdm = new ClouDASMatrix(scs, points);
|
|
|
+
|
|
|
+ int rhwCount = cdm.SH.Count();
|
|
|
+ double rhw = cdm.SH.LastOrDefault().Item2;
|
|
|
+ int rhlCount = cdm.SL.Count();
|
|
|
+ double rhl = cdm.SL.FirstOrDefault().Item2;*/
|
|
|
+
|
|
|
+ List<string> knowledgeName = new List<string>();
|
|
|
+ foreach (string cla in knowledge)
|
|
|
+ {
|
|
|
+ knowledgeName.Add(cla);
|
|
|
+ }
|
|
|
+ for (int k = 0; k < knowledgeName.Count; k++)
|
|
|
+ {
|
|
|
+ if (null == knowledgeName[k])
|
|
|
+ {
|
|
|
+ knowledgeName.Remove(knowledgeName[k]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //初始化年级总分
|
|
|
+ double total = 0;
|
|
|
+ //处理年级单个知识点得分率
|
|
|
+ foreach (List<double> grade in result)
|
|
|
+ {
|
|
|
+ total += grade.Sum();
|
|
|
+ }
|
|
|
+ //试卷总分
|
|
|
+ double TotalPoint = point.Sum();
|
|
|
+ List<double> knowScore = new List<double>();
|
|
|
+ //得分率
|
|
|
+ List<double> Score = new List<double>();
|
|
|
+ for (int k = 0; k < knowledgeName.Count; k++)
|
|
|
+ {
|
|
|
+ double OnePoint = 0;
|
|
|
+ List<string> itemNo = new List<string>();
|
|
|
+ int n = 0;
|
|
|
+ double scores = 0;
|
|
|
+
|
|
|
+ info.papers[index].knowledge.ForEach(kno =>
|
|
|
+ {
|
|
|
+ if (kno.Contains(knowledgeName[k]))
|
|
|
+ {
|
|
|
+ var itemPersent = kno.Count > 0 ? 1 / Convert.ToDouble(kno.Count) : 0;
|
|
|
+ OnePoint += point[n];
|
|
|
+ itemNo.Add((n + 1).ToString());
|
|
|
+ foreach (string id in exam.studentIds)
|
|
|
+ {
|
|
|
+ int index = exam.studentIds.IndexOf(id);
|
|
|
+ if (exam.studentScores[index][n] > 0)
|
|
|
+ {
|
|
|
+ scores += exam.studentScores[index][n] * itemPersent;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ n++;
|
|
|
+ });
|
|
|
+ Score.Add(scores);
|
|
|
+ //该知识点平均得分
|
|
|
+ double sc = exam.studentIds.Count > 0 ? Math.Round(scores * 1.0 / exam.studentIds.Count, 2) : 0;
|
|
|
+ //知识点占比
|
|
|
+ double persent = OnePoint > 0 ? sc / OnePoint : 0;
|
|
|
+ per.Add(persent.ToString("0.00"));
|
|
|
+
|
|
|
+ }
|
|
|
+ //本次考试知识点占比
|
|
|
+ /*List<double> allPer = new List<double>();
|
|
|
+ foreach (double sc in Score)
|
|
|
+ {
|
|
|
+ allPer.Add(exam.studentIds.Count > 0 ? Math.Round(sc * 1.0 / exam.studentIds.Count, 2) : 0);
|
|
|
+ } */
|
|
|
+ KeyValuePair<string, List<string>> key1 = new KeyValuePair<string, List<string>>(exam.subjectId, knowledgeName);
|
|
|
+ KeyValuePair<string, List<string>> key2 = new KeyValuePair<string, List<string>>(exam.subjectId, per);
|
|
|
+ //KeyValuePair<string, List<double>> key3 = new KeyValuePair<string, List<double>>(exam.subjectId, allPer);
|
|
|
+ return (key1, key2);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|