AnalysisController.cs 96 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914
  1. using ClouDASLibx;
  2. using Microsoft.AspNetCore.Mvc;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text.Json;
  7. using System.Threading.Tasks;
  8. using TEAMModelOS.SDK.Models;
  9. using TEAMModelOS.SDK;
  10. using TEAMModelOS.SDK.DI;
  11. using TEAMModelOS.SDK.Extension;
  12. using TEAMModelOS.SDK.Helper.Common.StringHelper;
  13. using TEAMModelOS.SDK.Helper.Security.ShaHash;
  14. using TEAMModelOS.Services.Analysis;
  15. using Microsoft.Extensions.Options;
  16. using TEAMModelOS.Models;
  17. using Azure.Cosmos;
  18. using System.Text;
  19. using Microsoft.AspNetCore.Authorization;
  20. using TEAMModelOS.Filter;
  21. using TEAMModelOS.SDK.Models.Service;
  22. using DocumentFormat.OpenXml.VariantTypes;
  23. namespace TEAMModelOS.Controllers.Analysis
  24. {
  25. [Route("analysis")]
  26. [ApiController]
  27. public class AnalysisController : ControllerBase
  28. {
  29. private readonly AzureCosmosFactory _azureCosmos;
  30. private readonly DingDing _dingDing;
  31. private readonly Option _option;
  32. private const string CacheCosmosPrefix = "Analysis:";
  33. private const int timeoutSeconds = 3600;
  34. private readonly CoreAPIHttpService _coreAPIHttpService;
  35. public AnalysisController(AzureCosmosFactory azureCosmos, DingDing dingDing, IOptionsSnapshot<Option> option,CoreAPIHttpService coreAPIHttpService)
  36. {
  37. _azureCosmos = azureCosmos;
  38. _dingDing = dingDing;
  39. _option = option?.Value;
  40. _coreAPIHttpService = coreAPIHttpService;
  41. }
  42. [ProducesDefaultResponseType]
  43. [HttpPost("process")]
  44. [Authorize(Roles = "IES")]
  45. [AuthToken(Roles = "teacher,admin")]
  46. public async Task<IActionResult> getAnalysis(JsonElement request)
  47. {
  48. //获取评测的ID
  49. if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
  50. if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
  51. List<StudentAys> students = new List<StudentAys>();
  52. List<ClassAys> classes = new List<ClassAys>();
  53. List<GradeAys> grades = new List<GradeAys>();
  54. List<Dictionary<string, dynamic>> PointAnalysis = new List<Dictionary<string, dynamic>>();
  55. List<string> scatterKey = new List<string>
  56. {
  57. "name",
  58. "className",
  59. "x",
  60. "y",
  61. "memberId",
  62. "score",
  63. "trueNum",
  64. "falseNum",
  65. "hardList",
  66. "carefulList",
  67. "scatter"
  68. };
  69. List<string> paperKey = new List<string>
  70. {
  71. "id",
  72. "type",
  73. "areaName",
  74. "score",
  75. "diff",
  76. "identify",
  77. "classScoreRate",
  78. "gradeScoreRate",
  79. "areaScoreRate",
  80. "highScoreRate",
  81. "lowScoreRate",
  82. "knowledgePoint",
  83. "R1",
  84. "R2",
  85. "R3",
  86. "R4",
  87. "R5",
  88. "R6",
  89. "PH",
  90. "PL",
  91. "X",
  92. "Y",
  93. "knowledge",
  94. "examScoreRate"
  95. };
  96. List<string> knowkey = new List<string>
  97. {
  98. "id",
  99. "className",
  100. "seatNO",
  101. "point",
  102. "anwPoint",
  103. "persent"
  104. };
  105. List<string> keynowWrong = new List<string>
  106. {
  107. "name",
  108. "point",
  109. "itemNO",
  110. "persent",
  111. "wrong",
  112. "rhw",
  113. "rlw"
  114. };
  115. ExamInfo info = null;
  116. double ipoint = 0;
  117. List<KeyValuePair<string, List<List<string>>>> subjectPaperDatas = new List<KeyValuePair<string, List<List<string>>>>();
  118. List<Dictionary<string, object>> valuePairs = new List<Dictionary<string, object>>();
  119. List<KeyValuePair<string, List<KeyValuePair<string, List<double>>>>> classSubjectPaperDatas = new List<KeyValuePair<string, List<KeyValuePair<string, List<double>>>>>();
  120. List<KeyValuePair<string, List<string>>> knowNameDatas = new List<KeyValuePair<string, List<string>>>();
  121. List<KeyValuePair<string, List<string>>> knowPerDatas = new List<KeyValuePair<string, List<string>>>();
  122. List<KeyValuePair<string, List<double>>> knowAllPerDatas = new List<KeyValuePair<string, List<double>>>();
  123. List<KeyValuePair<string, List<double>>> knowScoreDatas = new List<KeyValuePair<string, List<double>>>();
  124. List<KeyValuePair<string, List<List<string>>>> wrongDatas = new List<KeyValuePair<string, List<List<string>>>>();
  125. List<KeyValuePair<string, List<KeyValuePair<string, List<double>>>>> stuPerDatas = new List<KeyValuePair<string, List<KeyValuePair<string, List<double>>>>>();
  126. //声明认知层次变量
  127. List<KeyValuePair<string, List<int>>> fieldNameDatas = new List<KeyValuePair<string, List<int>>>();
  128. List<KeyValuePair<string, List<string>>> fieldPerDatas = new List<KeyValuePair<string, List<string>>>();
  129. List<KeyValuePair<string, List<double>>> fieldAllPerDatas = new List<KeyValuePair<string, List<double>>>();
  130. List<KeyValuePair<string, List<double>>> fieldScoreDatas = new List<KeyValuePair<string, List<double>>>();
  131. List<KeyValuePair<string, List<List<string>>>> fieldwrongDatas = new List<KeyValuePair<string, List<List<string>>>>();
  132. List<KeyValuePair<string, List<KeyValuePair<string, List<double>>>>> fieldStuPerDatas = new List<KeyValuePair<string, List<KeyValuePair<string, List<double>>>>>();
  133. //获取进线标准以及踩线分数
  134. int touch = 0;
  135. int income = 0;
  136. List<ExamResult> examResults = new List<ExamResult>();
  137. try
  138. {
  139. var client = _azureCosmos.GetCosmosClient();
  140. //获取本次评测所有科目结算结果
  141. info = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"Exam-{code}"));
  142. //School school = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(code.ToString(), new PartitionKey($"Base"));
  143. var query = $"select c.id,c.name,c.subjectId,c.studentScores,c.studentIds,c.paper,c.classes,c.sRate,c.average,c.standard,c.lostStus,c.record,c.phc,c.plc from c where c.examId = '{id}' ";
  144. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<ExamResult>(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamResult-{id}") }))
  145. {
  146. examResults.Add(item);
  147. }
  148. //获取本次评测所有班级作答结果
  149. List<ExamClassResult> examClassResults = new List<ExamClassResult>();
  150. if (info.owner.Equals("teacher") && info.scope.Equals("school"))
  151. {
  152. var queryClass = $"select c.id,c.name,c.subjectId,c.studentScores,c.studentIds,c.gradeId,c.info,c.standard,c.krate,c.phc,c.plc,c.pc,c.frate,c.fphc,c.fplc,c.fpc,c.status from c where c.examId = '{id}' and c.progress = true ";
  153. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<ExamClassResult>(queryText: queryClass, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{info.school}") }))
  154. {
  155. examClassResults.Add(item);
  156. }
  157. }
  158. else {
  159. var queryClass = $"select c.id,c.name,c.subjectId,c.studentScores,c.studentIds,c.gradeId,c.info,c.standard,c.krate,c.phc,c.plc,c.pc,c.frate,c.fphc,c.fplc,c.fpc,c.status from c where c.examId = '{id}' and c.progress = true ";
  160. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<ExamClassResult>(queryText: queryClass, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{code}") }))
  161. {
  162. examClassResults.Add(item);
  163. }
  164. }
  165. if (examClassResults.Count ==0) {
  166. return Ok(new { code = 404 ,msg = "数据还在结算中!"});
  167. }
  168. touch = info.touch;
  169. income = info.income;
  170. /*foreach (Period period in school.period)
  171. {
  172. if (info.period.id.Equals(period.id))
  173. {
  174. }
  175. }*/
  176. //计算每个年级参考人数并计算进线分数
  177. List<KeyValuePair<string, double>> keys = new List<KeyValuePair<string, double>>();
  178. List<double> gradeTotal = new List<double>();
  179. /*foreach (Grade grade in info.grades) {
  180. double ipoint = 0;
  181. int gradeCount = 0;
  182. //List<double> gradeTotal = new List<double>();
  183. HashSet<string> sno = new HashSet<string>();
  184. foreach (ExamClassResult examClassResult in examClassResults) {
  185. if (grade.id.Equals(examClassResult.gradeId)) {
  186. gradeCount += examClassResult.studentIds.Count;
  187. foreach (string s in examClassResult.studentIds) {
  188. sno.Add(s);
  189. }
  190. }
  191. }
  192. foreach (string sid in sno) {
  193. double total = 0;
  194. foreach (ExamClassResult examClassResult in examClassResults) {
  195. if (grade.id.Equals(examClassResult.gradeId))
  196. {
  197. int index = examClassResult.studentIds.IndexOf(sid);
  198. if (index == -1) continue;
  199. total += examClassResult.studentScores[index].Sum();
  200. }
  201. }
  202. gradeTotal.Add(total);
  203. }
  204. gradeTotal.Sort((s1, s2) => { return s2.CompareTo(s1); });
  205. //获取进线人数
  206. int personCount = (int)System.Math.Round(gradeCount / info.subjects.Count * (touch / 100.0), MidpointRounding.AwayFromZero);
  207. ipoint = gradeTotal[personCount];
  208. keys.Add(new KeyValuePair<string, double>(grade.id, ipoint));
  209. }*/
  210. //获取进线人数
  211. int personCount = (int)System.Math.Round(info.stuCount * (income / 100.0), MidpointRounding.AwayFromZero);
  212. /* //声明年级所有科目总分
  213. List<double> total = new List<double>();*/
  214. List<ClassRange> classReses = null;
  215. //按科目获取所有学生的分数
  216. Dictionary<string, List<double>> subjectTotal = new Dictionary<string, List<double>>();
  217. Dictionary<string, double> paperScore = new Dictionary<string, double>();
  218. List<KeyValuePair<string, List<KeyValuePair<string, List<string>>>>> subjectScatter = new List<KeyValuePair<string, List<KeyValuePair<string, List<string>>>>>();
  219. List<KeyValuePair<string, Dictionary<string, List<double>>>> gscores = new List<KeyValuePair<string, Dictionary<string, List<double>>>>();
  220. //声明全科总分
  221. double totalAll = 0;
  222. List<string> stuIds = new();
  223. foreach (ExamResult examResult in examResults)
  224. {
  225. (KeyValuePair<string, List<List<string>>> subjectData, KeyValuePair<string, List<KeyValuePair<string, List<double>>>> classSubjectData, Dictionary<string, List<double>> gscore) = DoExerciseScatteres(examResult, paperKey);
  226. (KeyValuePair<string, List<string>> knowName, KeyValuePair<string, List<string>> knowPer, KeyValuePair<string, List<double>> knowAllPer, KeyValuePair<string, List<double>> kScore, KeyValuePair<string, List<List<string>>> wrong, KeyValuePair<string, List<KeyValuePair<string, List<double>>>> stuPer) = DoKnowledgePoint(examResult, info, keynowWrong);
  227. (KeyValuePair<string, List<int>> fieldName, KeyValuePair<string, List<string>> fieldPer, KeyValuePair<string, List<double>> fieldAllPer, KeyValuePair<string, List<double>> fScore, KeyValuePair<string, List<List<string>>> fieldWrong, KeyValuePair<string, List<KeyValuePair<string, List<double>>>> fieldStuPer) = DoLevel(examResult, info, keynowWrong);
  228. gscores.Add(new KeyValuePair<string, Dictionary<string, List<double>>>(examResult.subjectId, gscore));
  229. /* Dictionary<string, dynamic> gpoint = new Dictionary<string, dynamic>();
  230. Dictionary<string, dynamic> glevel = new Dictionary<string, dynamic>();*/
  231. Dictionary<string, object> gpointList = new Dictionary<string, object>();
  232. subjectPaperDatas.Add(subjectData);
  233. classSubjectPaperDatas.Add(classSubjectData);
  234. subjectScatter.Add(DoSubjectScatter(examResult));
  235. knowNameDatas.Add(knowName);
  236. knowPerDatas.Add(knowPer);
  237. knowAllPerDatas.Add(knowAllPer);
  238. knowScoreDatas.Add(kScore);
  239. wrongDatas.Add(wrong);
  240. stuPerDatas.Add(stuPer);
  241. fieldNameDatas.Add(fieldName);
  242. fieldPerDatas.Add(fieldPer);
  243. fieldAllPerDatas.Add(fieldAllPer);
  244. fieldScoreDatas.Add(fScore);
  245. fieldwrongDatas.Add(fieldWrong);
  246. fieldStuPerDatas.Add(fieldStuPer);
  247. //gpointList.Add("subjectId", examResult.subjectId);
  248. //gpointList.Add("pointKey", DoKnowledgePoint(examResult, info));
  249. //gpointList.Add("levelKey", DoLevel(examResult, info));
  250. valuePairs.Add(gpointList);
  251. //获取一张试卷的满分
  252. totalAll += examResult.paper.point.Sum();
  253. paperScore.Add(examResult.subjectId, examResult.paper.point.Sum());
  254. List<double> StuSubjectTotals = new List<double>();
  255. classReses = examResult.classes;
  256. //处理个人
  257. foreach (var stuid in examResult.studentIds)
  258. {
  259. if (!stuIds.Contains(stuid))
  260. {
  261. stuIds.Add(stuid);
  262. }
  263. StudentAys student = null;
  264. int index = examResult.studentIds.IndexOf(stuid);
  265. if (students.Select(x => x.id).Contains(stuid))
  266. {
  267. student = students[index];
  268. }
  269. else
  270. {
  271. student = new StudentAys() { id = stuid };
  272. students.Add(student);
  273. }
  274. var score = Math.Round(examResult.studentScores[index].Sum(),2);
  275. student.total += score;
  276. student.total = Math.Round(student.total, 2);
  277. StuSubjectTotals.Add(score);
  278. if (student.subjects.Select(x => x.id).Contains(examResult.subjectId))
  279. {
  280. student.subjects.ForEach(y =>
  281. {
  282. if (y.id.Equals(examResult.subjectId))
  283. {
  284. y.score = score;
  285. y.sRate = Math.Round(examResult.paper.point.Sum() > 0 ? score / examResult.paper.point.Sum() : 0, 2);
  286. }
  287. });
  288. }
  289. else
  290. {
  291. StudentSubject subject = new StudentSubject
  292. {
  293. id = examResult.subjectId,
  294. scores = examResult.studentScores[examResult.studentIds.IndexOf(stuid)],
  295. name = info.subjects.Where(x => x.id == examResult.subjectId).FirstOrDefault().name,
  296. point = stuPerDatas.Where(x => x.Key == examResult.subjectId).SelectMany(va => va.Value).Where(stu => stu.Key == stuid).Select(pi => pi.Value).First(),
  297. fieldPoint = fieldStuPerDatas.Where(x => x.Key == examResult.subjectId).SelectMany(va => va.Value).Where(stu => stu.Key == stuid).Select(pi => pi.Value).First()
  298. };
  299. subject.score = score;
  300. subject.sRate = Math.Round(examResult.paper.point.Sum() > 0 ? score / examResult.paper.point.Sum() * 100 : 0, 2);
  301. student.subjects.Add(subject);
  302. }
  303. }
  304. subjectTotal.Add(examResult.subjectId, StuSubjectTotals);
  305. }
  306. //double powAll = 0;
  307. foreach (StudentAys student1 in students)
  308. {
  309. gradeTotal.Add(student1.total);
  310. student1.sRate = totalAll > 0 ? Math.Round(student1.total / totalAll * 100, 2) : 0;
  311. //powAll += Math.Pow(student1.total - examResult.studentIds.Count > 0 ? Math.Round(score * 1.0 / examResult.studentIds.Count, 2) : 0, 2);
  312. }
  313. //处理进线分数
  314. gradeTotal.Sort((s1, s2) => { return s2.CompareTo(s1); });
  315. if (personCount == 0)
  316. {
  317. ipoint = gradeTotal[personCount] + 1;
  318. }
  319. else
  320. {
  321. if (personCount == gradeTotal.Count)
  322. {
  323. ipoint = gradeTotal[personCount - 1];
  324. }
  325. else {
  326. ipoint = gradeTotal[personCount];
  327. }
  328. }
  329. //以班级为单位(此处处理的是行政班级,教学班如果被移除则会无法分析)
  330. List<string> clas = ExamService.getClasses(info.classes, info.stuLists);
  331. (List<RMember> members, List<RGroupList> classLists) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, clas, info.school, null,-1,info.startTime);
  332. foreach (RGroupList rGroup in classLists)
  333. {
  334. /* Class classroom = null;
  335. var sresponse = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(classId, new PartitionKey($"Class-{code}"));
  336. if (sresponse.Status == 200)
  337. {
  338. using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
  339. classroom = json.ToObject<Class>();
  340. }*/
  341. //处理班级
  342. var classRes = classReses.Where(x => x.id == rGroup.id).FirstOrDefault();
  343. var stuCount = classRes.range[1] - classRes.range[0] + 1;
  344. // 班级缺考人数
  345. var lostClassCount = examClassResults.Where(x => x.info.id.Equals(rGroup.id)).FirstOrDefault().status.Where(r => r == 1).ToList().Count;
  346. List<StudentAys> classStudents = new();
  347. /* foreach (string sid in stuIds)
  348. {
  349. foreach (var stu in students)
  350. {
  351. if (stu.id == sid && stu.classId == classRes.id)
  352. {
  353. classStudents.Add(stu);
  354. }
  355. }
  356. };*/
  357. for (int i = classRes.range[0]; i <= classRes.range[1]; i++) {
  358. foreach (var stu in students)
  359. {
  360. if (stu.id == examResults[0].studentIds[i])
  361. {
  362. classStudents.Add(stu);
  363. }
  364. }
  365. }
  366. //var classStudents = students.GetRange(classRes.range[0], classRes.range[1] - classRes.range[0] + 1);
  367. List<double> stuTotals = classStudents.Select(x => x.total).ToList();
  368. stuTotals.Sort((s1, s2) => { return s2.CompareTo(s1); });
  369. //初始化进线人数
  370. int lineCount = 0;
  371. //初始化班级总分
  372. double classTotal = stuTotals.Sum();
  373. //标准差
  374. double powSum = 0;
  375. //计算标准差
  376. //总平均分
  377. double totalAverage = 0;
  378. totalAverage = stuCount - lostClassCount > 0 ? classTotal * 1.0 / (stuCount - lostClassCount) : 0;
  379. //totalAverage = classTotal / stuCount;
  380. //获取整个班级 科目的分数情况
  381. List<KeyValuePair<string, double>> keyValues = new List<KeyValuePair<string, double>>();
  382. List<string> studentIds = new List<string>();
  383. List<KeyValuePair<string, List<double>>> pointClassTotal = new List<KeyValuePair<string, List<double>>>();
  384. List<KeyValuePair<string, List<double>>> fieldClassTotal = new List<KeyValuePair<string, List<double>>>();
  385. subjectTotal.Keys.ToList().ForEach(sub =>
  386. {
  387. var points = new List<double>();
  388. var fields = new List<double>();
  389. knowNameDatas.Where(su => su.Key == sub).First().Value.ForEach(x => { points.Add(0); });
  390. fieldNameDatas.Where(su => su.Key == sub).First().Value.ForEach(x => { fields.Add(0); });
  391. pointClassTotal.Add(new KeyValuePair<string, List<double>>(sub, points));
  392. fieldClassTotal.Add(new KeyValuePair<string, List<double>>(sub, fields));
  393. });
  394. /*List<Student> stus = new List<Student>();
  395. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<Student>(queryText: $"select c.id,c.name,c.no from c where c.classId = '{classId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{code}") }))
  396. {
  397. stus.Add(item);
  398. }*/
  399. classStudents.ForEach(x =>
  400. {
  401. studentIds.Add(x.id);
  402. x.classId = rGroup.id;
  403. x.className = examClassResults.FirstOrDefault(e => e.info.id.Equals(rGroup.id)).info.name;
  404. x.gradeId = examClassResults.FirstOrDefault(e => e.info.id.Equals(rGroup.id)).gradeId;
  405. var stu = members.Where(s => s.id == x.id).FirstOrDefault();
  406. if (stu != null)
  407. {
  408. x.nickname = stu.nickname;
  409. x.name = stu.name;
  410. x.no = stu.no;
  411. }
  412. else
  413. {
  414. x.nickname = x.nickname;
  415. x.name = x.id;
  416. x.no = "-";
  417. }
  418. /* //班级得分率
  419. x.csRate = totalAll > 0 ? Math.Round(totalAverage / totalAll,2) : 0;*/
  420. //标准差 介于缺考人员的判定逻辑 多科考试必须多科同时缺考才能算整个评测缺考
  421. int inx = examClassResults.FirstOrDefault(e => e.info.id.Equals(rGroup.id)).studentIds.IndexOf(x.id);
  422. var statu = examClassResults.Where(e => e.info.id.Equals(rGroup.id)).Select(x => x.status).ToList();
  423. bool flag = false;
  424. foreach (var ets in statu) {
  425. if (ets[inx] == 0) {
  426. flag = true;
  427. break;
  428. }
  429. }
  430. if (flag) {
  431. powSum += Math.Pow(x.total - totalAverage, 2);
  432. }
  433. //进线人数
  434. if (x.total >= ipoint)
  435. {
  436. lineCount++;
  437. }
  438. //班级全科的pr
  439. int index = stuTotals.IndexOf(x.total);
  440. //double CPR = stuCount - lostClassCount > 0 ? Math.Floor(100 - (100 * (index + 1) - 50) * 1.0 / (stuCount - lostClassCount)) : 0;
  441. double CPR = 100 - (100 * (index + 1) - 50) / stuCount;
  442. x.cpr = CPR;
  443. x.csort = index + 1;
  444. //班级单科的pr
  445. x.subjects.ForEach(y =>
  446. {
  447. //y.point
  448. var subjectT = classStudents.SelectMany(s => s.subjects).Where(sub => sub.id == y.id).Select(scr => scr.score).ToList();
  449. subjectT.Sort((s1, s2) => { return s2.CompareTo(s1); });
  450. int index = subjectT.IndexOf(y.score);
  451. //double CPR = stuCount - lostClassCount > 0 ? Math.Floor(100 - (100 * (index + 1) - 50) * 1.0 / (stuCount - lostClassCount)) : 0;
  452. double CPR = 100 - (100 * (index + 1) - 50) / stuCount;
  453. y.cpr = CPR;
  454. y.csort = index + 1;
  455. //按科目获取一个班的分数
  456. keyValues.Add(new KeyValuePair<string, double>(y.id, y.score));
  457. var pintTalt = pointClassTotal.Where(su => su.Key == y.id).Select(pint => pint.Value).First();
  458. for (int i = 0; i < y.point.Count; i++)
  459. {
  460. pintTalt[i] = pintTalt[i] + y.point[i];
  461. }
  462. var fieldTalt = fieldClassTotal.Where(su => su.Key == y.id).Select(pint => pint.Value).First();
  463. for (int i = 0; i < y.fieldPoint.Count; i++)
  464. {
  465. fieldTalt[i] = fieldTalt[i] + y.fieldPoint[i];
  466. }
  467. });
  468. });
  469. var pow = stuCount - lostClassCount > 0 ? Math.Pow(powSum / (stuCount - lostClassCount), 0.5) : 0;
  470. //var pow = Math.Pow(powSum / stuCount, 0.5);
  471. ClassAys classAys = new ClassAys
  472. {
  473. gradeId = examClassResults.FirstOrDefault(e => e.info.id.Equals(rGroup.id)).gradeId ?? "",
  474. year = rGroup.year,
  475. studentIds = studentIds,
  476. stuCount = stuCount,
  477. classId = rGroup.id,
  478. csRate = totalAll > 0 ? Math.Round(totalAverage / totalAll * 100, 2) : 0,
  479. className = rGroup.name,
  480. totalAverage = totalAverage,
  481. lineCount = lineCount,
  482. standardDeviation = Math.Round(pow,2)
  483. };
  484. foreach (var key in paperScore.Keys)
  485. {
  486. var subScore = keyValues.Where(x => x.Key.Equals(key)).Select(x => x.Value).ToList();
  487. //计算及格率
  488. int passCount = 0;
  489. double passScore = paperScore[key] * 0.6;
  490. subScore.ForEach(x =>
  491. {
  492. if (x > passScore)
  493. {
  494. passCount += 1;
  495. }
  496. });
  497. double passPercent = stuCount - lostClassCount > 0 ? Math.Round(passCount * 1.0 / (stuCount - lostClassCount), 2) : 0;
  498. //double passPercent = Math.Round(passCount * 1.0 / stuCount,2) ;
  499. double average = stuCount - lostClassCount > 0 ? Math.Round(subScore.Sum() * 1.0 / (stuCount - lostClassCount), 2) : 0;
  500. //double average = Math.Round(subScore.Sum() * 1.0 / stuCount,2) ;
  501. List<double> tt = new List<double>();
  502. List<double> fieldPoints = new List<double>();
  503. var pp = pointClassTotal.Where(su => su.Key == key).Select(pint => pint.Value).First();
  504. pp.ForEach(s =>
  505. {
  506. tt.Add(stuCount - lostClassCount > 0 ? Math.Round(s * 1.0 / (stuCount - lostClassCount), 2) : 0);
  507. });
  508. var ff = fieldClassTotal.Where(su => su.Key == key).Select(pint => pint.Value).First();
  509. ff.ForEach(s =>
  510. {
  511. fieldPoints.Add(stuCount - lostClassCount > 0 ? Math.Round(s * 1.0 / (stuCount - lostClassCount), 2) : 0);
  512. });
  513. double val = examClassResults.FirstOrDefault(c => c.subjectId == key && c.info.id == rGroup.id).standard;
  514. List<double> krate = examClassResults.FirstOrDefault(c => c.subjectId == key && c.info.id == rGroup.id).krate;
  515. List<int> phc = examClassResults.FirstOrDefault(c => c.subjectId == key && c.info.id == rGroup.id).phc;
  516. List<int> plc = examClassResults.FirstOrDefault(c => c.subjectId == key && c.info.id == rGroup.id).plc;
  517. List<int> pc = examClassResults.FirstOrDefault(c => c.subjectId == key && c.info.id == rGroup.id).pc;
  518. List<double> frate = examClassResults.FirstOrDefault(c => c.subjectId == key && c.info.id == rGroup.id).frate;
  519. List<int> fphc = examClassResults.FirstOrDefault(c => c.subjectId == key && c.info.id == rGroup.id).fphc;
  520. List<int> fplc = examClassResults.FirstOrDefault(c => c.subjectId == key && c.info.id == rGroup.id).fplc;
  521. List<int> fpc = examClassResults.FirstOrDefault(c => c.subjectId == key && c.info.id == rGroup.id).fpc;
  522. classAys.subjects.Add(new AysSubject
  523. {
  524. point = tt,
  525. field = fieldPoints,
  526. id = key,
  527. passPercent = passPercent,
  528. passCount = passCount,
  529. average = average,
  530. standard = val,
  531. krate = krate,
  532. phc = phc,
  533. plc = plc,
  534. pc = pc,
  535. frate = frate,
  536. fphc = fphc,
  537. fplc = fplc,
  538. fpc = fpc,
  539. sRate = paperScore[key] > 0 ? Math.Round(average / paperScore[key] * 100, 2) : 0,
  540. name = info.subjects.Where(x => x.id == key).FirstOrDefault().name,
  541. item = classSubjectPaperDatas.Where(subd => subd.Key == key).First().Value.Where(cls => cls.Key == rGroup.id).First().Value
  542. });
  543. }
  544. classes.Add(classAys);
  545. }
  546. //处理年级
  547. var tgrades = classes.GroupBy(x => x.year).Select(x => x.Key).OrderBy(c => c).ToList();
  548. int n = 0;
  549. if (tgrades.Count > 0)
  550. {
  551. if (info.grades.Count > 0) {
  552. foreach (var greade in tgrades)
  553. {
  554. string gid = info.grades.Count > 0 ? info.grades[n].id ?? "-" : "-";
  555. var clases = classes.Where(x => x.year.Equals(greade));
  556. var classCount = clases.Count();
  557. var stu = clases.SelectMany(x => x.studentIds).ToList();
  558. var lineCount = clases.Select(x => x.lineCount).Sum();
  559. var totalAverage = clases.Select(x => x.totalAverage).Sum() * 1.0 / classCount;
  560. GradeAys gradeAys = new GradeAys
  561. {
  562. gradeId = gid,
  563. studentIds = stu,
  564. gradeName = info.grades.Count > 0 ? info.grades[n].name ?? "-" : "-",
  565. stuCount = stu.Count,
  566. lineCount = lineCount,
  567. totalAverage = totalAverage,
  568. };
  569. foreach (var key in paperScore.Keys)
  570. {
  571. var AysSubject = clases.SelectMany(c => c.subjects).Where(x => x.id.Equals(key)).Select(x => x).ToList();
  572. var passCount = AysSubject.Select(x => x.passCount).Sum();
  573. var average = Math.Round(AysSubject.Select(x => x.average).Sum() * 1.0 / classCount);
  574. var passPercent = stu.Count > 0 ? Math.Round(passCount * 1.0 / stu.Count, 2) : 0;
  575. //var passPercent = Math.Round(passCount * 1.0 / stu.Count,2);
  576. AysSubject subject = new AysSubject
  577. {
  578. id = key,
  579. passCount = passCount,
  580. passPercent = passPercent,
  581. average = average,
  582. name = info.subjects.Where(x => x.id == key).FirstOrDefault().name,
  583. item = gscores.Where(x => x.Key == key).FirstOrDefault().Value.Where(cls => cls.Key == gid).FirstOrDefault().Value
  584. };
  585. gradeAys.subjects.Add(subject);
  586. }
  587. grades.Add(gradeAys);
  588. //处理学生年级相关的pr值
  589. var studentAys = students;
  590. int lostGrade = 0;
  591. if (!gid.Equals("-")) {
  592. studentAys = students.Where(x => x.gradeId != null && x.gradeId.Equals(gid)).ToList();
  593. lostGrade = examClassResults.Where(x => x.gradeId.Equals(gid)).SelectMany(y => y.status).Where (r => r == 1).ToList().Count;
  594. }
  595. var stuGradeTotal = studentAys.Select(x => x.total).ToList();
  596. stuGradeTotal.Sort((s1, s2) => { return s2.CompareTo(s1); });
  597. var stuCount = stuGradeTotal.Count;
  598. studentAys.ForEach(x =>
  599. {
  600. //年级全科的pr
  601. int index = stuGradeTotal.IndexOf(x.total);
  602. //double GPR = stuCount - lostGrade > 0 ? Math.Floor(100 - (100 * (index + 1) - 50) * 1.0 / (stuCount - lostGrade)) : 0;
  603. double GPR = 100 - (100 * (index + 1) - 50) / stuCount;
  604. x.gpr = GPR;
  605. x.gsort = index + 1;
  606. //年级单科的pr
  607. x.subjects.ForEach(y =>
  608. {
  609. var subjectT = studentAys.SelectMany(s => s.subjects).Where(sub => sub.id == y.id).Select(scr => scr.score).ToList();
  610. subjectT.Sort((s1, s2) => { return s2.CompareTo(s1); });
  611. int index = subjectT.IndexOf(y.score);
  612. //double GPR = stuCount- lostGrade > 0 ? Math.Floor(100 - (100 * (index + 1) - 50) * 1.0 / (stuCount - lostGrade)) : 0;
  613. double GPR = 100 - (100 * (index + 1) - 50) / stuCount;
  614. y.gpr = GPR;
  615. y.gsort = index + 1;
  616. });
  617. });
  618. n++;
  619. }
  620. }
  621. }
  622. subjectScatter.ForEach(x =>
  623. {
  624. string subjectId = x.Key;
  625. x.Value.ForEach(s =>
  626. {
  627. string stuId = s.Key;
  628. var data = s.Value;
  629. var stu = students.Where(stu => stu.id == stuId).First();
  630. students.Where(stu => stu.id == stuId).First().subjects.Where(sub => sub.id == subjectId).ToList().ForEach(sc =>
  631. {
  632. //处理阵列的索引1的班级名称
  633. data[1] = stu.className;
  634. sc.scatter = data;
  635. //data[3] = sc.sRate.ToString();
  636. //sc.sRate = double.Parse(data[3]);
  637. });
  638. });
  639. });
  640. }
  641. catch (Exception ex)
  642. {
  643. await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/process()\n{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  644. }
  645. var sub = examResults.Select(e => new
  646. {
  647. e.id,
  648. info.subjects.FirstOrDefault(c => c.id == e.id).name,
  649. e.record,
  650. e.phc,
  651. e.plc,
  652. e.sRate,
  653. e.average,
  654. e.standard
  655. });
  656. /*var sub = info.subjects.Select(x => new
  657. {
  658. id = x.id,
  659. name = x.name,
  660. record = examResults.FirstOrDefault(c => c.id == x.id).record,
  661. phc = examResults.FirstOrDefault(c => c.id == x.id).phc,
  662. plc = examResults.FirstOrDefault(c => c.id == x.id).plc,
  663. sRate = examResults.FirstOrDefault(c => c.id == x.id).sRate,
  664. average = examResults.FirstOrDefault(c => c.id == x.id).average,
  665. standard = examResults.FirstOrDefault(c => c.id == x.id).standard
  666. });*/
  667. var subAll = new { info.sRate, info.average, info.standard, total = info.stuCount,lost = info.lostStu.Count };
  668. return Ok(new
  669. {
  670. students,
  671. classes,
  672. grades,
  673. paper = subjectPaperDatas,
  674. subjects = sub,
  675. scatterKey,
  676. paperKey,
  677. pointLevelKey = valuePairs,
  678. ipoint,
  679. touchScore = touch,
  680. knowKey = knowkey,
  681. wrongKey = keynowWrong,
  682. wrong = wrongDatas,
  683. knowName = knowNameDatas,
  684. knowPer = knowPerDatas,
  685. knowAllper = knowAllPerDatas,
  686. fieldwrong = fieldwrongDatas,
  687. fieldName = fieldNameDatas,
  688. fieldPer = fieldPerDatas,
  689. fieldAllPer = fieldAllPerDatas,
  690. kScores = knowScoreDatas,
  691. fScores = fieldScoreDatas,
  692. all = subAll
  693. });
  694. }
  695. private static (KeyValuePair<string, List<List<string>>>, KeyValuePair<string, List<KeyValuePair<string, List<double>>>>, Dictionary<string, List<double>>) DoExerciseScatteres(ExamResult e, List<string> paperKey)
  696. {
  697. List<int> examAnswer = new List<int>();
  698. List<string> examPersent = new List<string>();
  699. for (int n = 0; n < e.paper.point.Count; n++)
  700. {
  701. examAnswer.Add(0);
  702. }
  703. //参考人数
  704. double Qnum = 0;
  705. e.studentIds.ForEach(i =>
  706. {
  707. if (!i.Equals("0"))
  708. {
  709. Qnum++;
  710. }
  711. });
  712. List<List<string>> datas = new List<List<string>>();
  713. List<string[]> itemAnalysis = new List<string[]>();
  714. Dictionary<string, List<int>> gradeItemScore = new Dictionary<string, List<int>>();
  715. Dictionary<string, int> gradeItemStuCount = new Dictionary<string, int>();
  716. List<KeyValuePair<string, List<double>>> classdatas = new List<KeyValuePair<string, List<double>>>();
  717. try
  718. {
  719. e.classes.ForEach(c =>
  720. {
  721. //初始化每题得分情况
  722. List<int> answerCount = new List<int>();
  723. List<double> persent = new List<double>();
  724. int peopleCount = 0;
  725. for (int n = 0; n < e.paper.point.Count; n++)
  726. {
  727. answerCount.Add(0);
  728. }
  729. int qCount = 0;
  730. //每个班级得分占比
  731. for (int i = c.range[0]; i <= c.range[1]; i++)
  732. {
  733. if (e.studentScores[i].Sum() > 0)
  734. {
  735. for (int j = 0; j < e.studentScores[i].Count; j++)
  736. {
  737. if (e.studentScores[i][j] > 0)
  738. {
  739. //记录班级每题得分数
  740. answerCount[j] = answerCount[j] + 1;
  741. //记录年级每题得分数
  742. examAnswer[j] = examAnswer[j] + 1;
  743. }
  744. }
  745. }
  746. else
  747. {
  748. qCount++;
  749. }
  750. peopleCount = c.range[1] - c.range[0] + 1 - qCount;
  751. }
  752. foreach (int p in answerCount)
  753. {
  754. var t = peopleCount > 0 ? Math.Round(p * 1.0 / peopleCount * 100, 2) : 0;
  755. //var t = Math.Round(p * 1.0 / peopleCount * 100,2);
  756. persent.Add(t);
  757. }
  758. classdatas.Add(new KeyValuePair<string, List<double>>(c.id, persent));
  759. if (!string.IsNullOrEmpty(c.gradeId))
  760. {
  761. if (gradeItemScore.ContainsKey(c.gradeId))
  762. {
  763. var we = gradeItemScore[c.gradeId];
  764. List<int> count = we;
  765. for (int index = 0; index < count.Count; index++)
  766. {
  767. count[index] = count[index] + answerCount[index];
  768. }
  769. gradeItemScore[c.gradeId] = count;
  770. // gradeItemScore[c.gradeId].ForEach(x => { x = x + answerCount[index]; index += 1; });
  771. gradeItemStuCount[c.gradeId] = gradeItemStuCount[c.gradeId] + peopleCount;
  772. }
  773. else
  774. {
  775. gradeItemScore.Add(c.gradeId, answerCount);
  776. gradeItemStuCount.Add(c.gradeId, peopleCount);
  777. }
  778. }
  779. });
  780. double[] point = StringHelper.ListTodouble(e.paper.point);
  781. double[,] result = StringHelper.ListToDouble(e.studentScores);
  782. var cdm = new ClouDASMatrix(result, point);
  783. //试题Y
  784. List<double> answer = cdm.AnswerRate;
  785. //试题X
  786. List<double> quality = cdm.QualityRate;
  787. //试题区域
  788. List<string> topic = cdm.TopicFallArea;
  789. //试题相关分析结果
  790. List<(double Diff, double D, double R0,double R1, double R2, double R3, double R4, double R5, double R6, double PH, double PL)> rs = cdm.RS;
  791. for (int i = 0; i < rs.Count; i++)
  792. {
  793. string[] ex = new string[] { };
  794. string ss = rs[i].ToString()[1..^1];
  795. ex = ss.Split(",");
  796. itemAnalysis.Add(ex);
  797. }
  798. foreach (int p in examAnswer)
  799. {
  800. var t = Qnum > 0 ? Math.Round(p * 1.0 / Qnum * 100, 2) : 0;
  801. //var t = Math.Round(p * 1.0 / Qnum * 100,2);
  802. examPersent.Add(t.ToString());
  803. }
  804. for (int k = 0; k < e.paper.point.Count; k++)
  805. {
  806. List<string> values = new List<string>();
  807. paperKey.ForEach(x =>
  808. {
  809. values.Add("-");
  810. });
  811. values[0] = (k + 1).ToString();
  812. if (e.paper.type.Count > 0)
  813. {
  814. values[1] = e.paper.type[k].ToString();
  815. }
  816. else
  817. {
  818. values[1] = "";
  819. }
  820. values[2] = topic[k].ToString();
  821. values[3] = e.paper.point[k].ToString();
  822. /* List<string> sk = new List<string>();
  823. foreach (string kl in e.paper.knowledge[k]) {
  824. sk.Add(kl);
  825. }*/
  826. values[22] = string.Join(",", e.paper.knowledge[k]);
  827. if (itemAnalysis.Count > 0)
  828. {
  829. values[4] = itemAnalysis[k][0].Trim();
  830. values[5] = itemAnalysis[k][1].Trim();
  831. values[6] = itemAnalysis[k][2].Trim();
  832. values[12] = itemAnalysis[k][3].Trim();
  833. values[13] = itemAnalysis[k][4].Trim();
  834. values[14] = itemAnalysis[k][5].Trim();
  835. values[15] = itemAnalysis[k][6].Trim();
  836. values[16] = itemAnalysis[k][7].Trim();
  837. values[17] = itemAnalysis[k][8].Trim();
  838. values[18] = itemAnalysis[k][9].Trim();
  839. values[19] = itemAnalysis[k][10].Trim();
  840. }
  841. else
  842. {
  843. values[4] = "0";
  844. values[5] = "0";
  845. values[6] = "0";
  846. values[12] = "0";
  847. values[13] = "0";
  848. values[14] = "0";
  849. values[15] = "0";
  850. values[16] = "0";
  851. values[17] = "0";
  852. values[18] = "0";
  853. values[19] = "0";
  854. }
  855. Dictionary<string, double> its = new Dictionary<string, double>();
  856. classdatas.ForEach(cls => { its.Add(cls.Key, cls.Value[k]); });
  857. StringBuilder classBuilder = new StringBuilder();
  858. foreach (var key in its.Keys)
  859. {
  860. classBuilder.Append(key + ":" + its[key] + ",");
  861. }
  862. var cstr = classBuilder.ToString();
  863. values[7] = cstr[..^1];
  864. StringBuilder gradeBuilder = new StringBuilder();
  865. //处理年级的这个题的得分
  866. foreach (var key in gradeItemScore.Keys)
  867. {
  868. var data = gradeItemStuCount[key] > 0 ? Math.Round(gradeItemScore[key][k] * 1.0 / gradeItemStuCount[key] * 100, 2) : 0;
  869. //var data = Math.Round(gradeItemScore[key][k] * 1.0 / gradeItemStuCount[key] * 100, 2);
  870. gradeBuilder.Append(key + ":" + data + ",");
  871. }
  872. var gstr = gradeBuilder.ToString();
  873. values[8] = string.IsNullOrEmpty(gstr) ? "-" : gstr.Substring(0, gstr.Length - 1);
  874. values[20] = quality[k].ToString();
  875. values[21] = answer[k].ToString();
  876. // string pointName = "";
  877. values[23] = examPersent[k];
  878. datas.Add(values);
  879. }
  880. Dictionary<string, List<double>> dict = new Dictionary<string, List<double>>();
  881. //处理年级的这个题的得分
  882. foreach (var key in gradeItemScore.Keys)
  883. {
  884. List<double> gscores = new List<double>();
  885. gradeItemScore[key].ForEach(x =>
  886. {
  887. var data = gradeItemStuCount[key] > 0 ? Math.Round(x * 1.0 / gradeItemStuCount[key] * 100, 2) : 0;
  888. //var data = Math.Round(x * 1.0 / gradeItemStuCount[key] * 100, 2);
  889. gscores.Add(data);
  890. });
  891. dict.TryAdd(key, gscores);
  892. }
  893. KeyValuePair<string, List<List<string>>> keyValue = new(e.subjectId, datas);
  894. KeyValuePair<string, List<KeyValuePair<string, List<double>>>> classdata = new(e.subjectId, classdatas);
  895. return (keyValue, classdata, dict);
  896. }
  897. catch (Exception ex)
  898. {
  899. // throw new BizException(ex.Message);
  900. }
  901. return (default, default, default);
  902. }
  903. //落点分析
  904. private KeyValuePair<string, List<KeyValuePair<string, List<string>>>> DoSubjectScatter(ExamResult e)
  905. {
  906. List<KeyValuePair<string, List<string>>> datas = new List<KeyValuePair<string, List<string>>>();
  907. double[] point = StringHelper.ListTodouble(e.paper.point);
  908. double[,] result = StringHelper.ListToDouble(e.studentScores);
  909. try
  910. {
  911. var cdm = new ClouDASMatrix(result, point);
  912. //学生通过率
  913. List<double> pass = cdm.ScoringRate;
  914. //学生稳定度
  915. List<double> sta = cdm.StabilityRate;
  916. //落点区域
  917. List<string> stu = cdm.StuFallArea;
  918. //需努力的题型
  919. List<int[]> strive = cdm.StriveTopic;
  920. //需小心的题型
  921. List<int[]> careful = cdm.CarefulTopic;
  922. int i = 0;
  923. for (int k = e.studentIds.Count - 1; k >= 0; k--)
  924. {
  925. if (e.studentIds[k].Equals("0"))
  926. {
  927. e.studentIds.Remove(e.studentIds[k]);
  928. }
  929. }
  930. e.studentIds.ForEach(s =>
  931. {
  932. /* if (e.studentScores[i].Sum() != 0)
  933. {*/
  934. List<string> info = new List<string>
  935. {
  936. s,
  937. "-",
  938. sta[i] > 1 ? "1" : sta[i].ToString(),
  939. pass[i].ToString(),
  940. i + 1 + "",
  941. Math.Round(e.studentScores[i].Sum(),2).ToString()
  942. };
  943. int right = 0;
  944. int wrong = 0;
  945. foreach (int p in e.studentScores[i])
  946. {
  947. if (p > 0)
  948. {
  949. right++;
  950. }
  951. else
  952. {
  953. wrong++;
  954. }
  955. }
  956. info.Add(right + "");
  957. info.Add(wrong + "");
  958. int[] str = strive[i];
  959. string striveAll = "";
  960. foreach (int n in str)
  961. {
  962. striveAll += n.ToString() + ",";
  963. }
  964. int[] care = careful[i];
  965. string careAll = "";
  966. foreach (int n in care)
  967. {
  968. careAll += n.ToString() + ",";
  969. }
  970. if (string.IsNullOrEmpty(striveAll))
  971. {
  972. info.Add("-");
  973. }
  974. else
  975. {
  976. info.Add(striveAll.Substring(0, striveAll.Length - 1));
  977. }
  978. if (string.IsNullOrEmpty(careAll))
  979. {
  980. info.Add("-");
  981. }
  982. else
  983. {
  984. info.Add(careAll.Substring(0, careAll.Length - 1)); ;
  985. }
  986. info.Add(stu[i].ToString());
  987. KeyValuePair<string, List<string>> keyValue = new KeyValuePair<string, List<string>>(s, info);
  988. datas.Add(keyValue);
  989. //}
  990. i++;
  991. });
  992. return new KeyValuePair<string, List<KeyValuePair<string, List<string>>>>(e.subjectId, datas);
  993. }
  994. catch (Exception ex)
  995. {
  996. BadRequest(ex.Message + ex.StackTrace);
  997. Console.WriteLine("---------------------" + ex.Message + "--------------------------");
  998. }
  999. return default;
  1000. }
  1001. private static (KeyValuePair<string, List<string>>, KeyValuePair<string, List<string>>, KeyValuePair<string, List<double>>, KeyValuePair<string, List<double>>, KeyValuePair<string, List<List<string>>>, KeyValuePair<string, List<KeyValuePair<string, List<double>>>>) DoKnowledgePoint(ExamResult exam, ExamInfo info, List<string> keynowWrong)
  1002. {
  1003. HashSet<string> knowledge = new HashSet<string>();
  1004. //HashSet<string> area = new HashSet<string>();
  1005. List<double> point = new List<double>();
  1006. List<List<double>> result = new List<List<double>>();
  1007. List<ClassRange> classes = new List<ClassRange>();
  1008. //List<string> ids = new List<string>();
  1009. List<KeyValuePair<string, List<double>>> datas = new List<KeyValuePair<string, List<double>>>();
  1010. //求单个知识点所占分数
  1011. List<string> per = new List<string>();
  1012. //List<string> gper = new List<string>();
  1013. //List<string> knowPer = new List<string>();
  1014. //Dictionary<string, object> wrongMap = new Dictionary<string, object>();
  1015. List<List<string>> wrongPersent = new List<List<string>>();
  1016. //定位试卷信息
  1017. int index = 0;
  1018. foreach (ExamSubject subject in info.subjects)
  1019. {
  1020. if (subject.id.Equals(exam.subjectId))
  1021. {
  1022. break;
  1023. }
  1024. else
  1025. {
  1026. index++;
  1027. }
  1028. }
  1029. if (info.papers[index].knowledge != null && info.papers[index].knowledge.Count > 0)
  1030. {
  1031. info.papers[index].knowledge.ForEach(k =>
  1032. {
  1033. k.ForEach(e =>
  1034. {
  1035. knowledge.Add(e);
  1036. });
  1037. });
  1038. }
  1039. else
  1040. {
  1041. return (default, default, default, default, default, default);
  1042. }
  1043. point = info.papers[index].point;
  1044. result = exam.studentScores;
  1045. classes = exam.classes;
  1046. //ids = exam.studentIds;
  1047. //确定高分组 低分组人数
  1048. //List<List<double>> re = exam.studentScores;
  1049. /* List<double> resultSum = new List<double>();
  1050. foreach (List<double> data in re)
  1051. {
  1052. resultSum.Add(data.Sum());
  1053. }*/
  1054. //确定高分组 最低分数
  1055. double[] points = StringHelper.ListTodouble(exam.paper.point);
  1056. double[,] scs = StringHelper.ListToDouble(exam.studentScores);
  1057. var cdm = new ClouDASMatrix(scs, points);
  1058. //scores.Sort((s1, s2) => { return s2.CompareTo(s1); });
  1059. int rhwCount = cdm.SH.Count();
  1060. double rhw = cdm.SH.LastOrDefault().Item2;
  1061. int rhlCount = cdm.SL.Count();
  1062. double rhl = cdm.SL.FirstOrDefault().Item2;
  1063. /* resultSum.Sort((s1, s2) => { return s2.CompareTo(s1); });
  1064. int rhwCount = 0;
  1065. double rhw = 0;
  1066. int rhlCount = 0;
  1067. double rhl = 0;
  1068. if (resultSum.Count > 3)
  1069. {
  1070. rhwCount = Convert.ToInt32(Math.Floor(resultSum.Count * 0.27));
  1071. rhw = rhwCount > 0 ? resultSum[rhwCount - 1] : 0;
  1072. rhlCount = Convert.ToInt32(Math.Ceiling(resultSum.Count * 0.73));
  1073. rhl = rhlCount > 0 ? resultSum[rhlCount] : 0;
  1074. }
  1075. else {
  1076. rhwCount = Convert.ToInt32(Math.Floor(resultSum.Count * 0.27));
  1077. rhw = rhwCount > 0 ? resultSum[rhwCount] : 0;
  1078. rhlCount = Convert.ToInt32(Math.Ceiling(resultSum.Count * 0.73));
  1079. rhl = rhlCount > 0 ? resultSum[rhlCount-1] : 0;
  1080. } */
  1081. List<string> knowledgeName = new List<string>();
  1082. foreach (string cla in knowledge)
  1083. {
  1084. knowledgeName.Add(cla);
  1085. }
  1086. for (int k = 0; k < knowledgeName.Count; k++)
  1087. {
  1088. if (null == knowledgeName[k])
  1089. {
  1090. knowledgeName.Remove(knowledgeName[k]);
  1091. }
  1092. }
  1093. //初始化年级总分
  1094. double total = 0;
  1095. //处理年级单个知识点得分率
  1096. foreach (List<double> grade in result)
  1097. {
  1098. total += grade.Sum();
  1099. }
  1100. //试卷总分
  1101. double TotalPoint = point.Sum();
  1102. List<double> knowScore = new List<double>();
  1103. //得分率
  1104. List<double> Score = new List<double>();
  1105. //分值
  1106. List<double> kScore = new List<double>();
  1107. for (int k = 0; k < knowledgeName.Count; k++)
  1108. {
  1109. double OnePoint = 0;
  1110. List<string> valuew = new List<string>();
  1111. List<string> itemNo = new List<string>();
  1112. keynowWrong.ForEach(x =>
  1113. {
  1114. valuew.Add("-");
  1115. });
  1116. valuew[0] = knowledgeName[k];
  1117. int n = 0;
  1118. int wrong = 0;
  1119. int rhwC = 0;
  1120. int rhlC = 0;
  1121. double scores = 0;
  1122. //知识点分值
  1123. double gPoint = 0;
  1124. info.papers[index].knowledge.ForEach(kno =>
  1125. {
  1126. if (kno.Contains(knowledgeName[k]))
  1127. {
  1128. var itemPersent = kno.Count > 0 ? 1 / Convert.ToDouble(kno.Count) : 0;
  1129. OnePoint += point[n] * itemPersent;
  1130. itemNo.Add((n + 1).ToString());
  1131. //处理单个知识点错题人数
  1132. int phCount = 0;
  1133. int plCount = 0;
  1134. foreach (string id in exam.studentIds)
  1135. {
  1136. int index = exam.studentIds.IndexOf(id);
  1137. if (exam.studentScores[index][n] == 0)
  1138. {
  1139. wrong++;
  1140. if (exam.studentScores[index].Sum() >= rhw && phCount < rhwCount)
  1141. {
  1142. rhwC++;
  1143. phCount++;
  1144. continue;
  1145. }
  1146. if (exam.studentScores[index].Sum() <= rhl && plCount < (exam.studentIds.Count - rhlCount))
  1147. {
  1148. rhlC++;
  1149. plCount++;
  1150. continue;
  1151. }
  1152. continue;
  1153. }
  1154. else
  1155. {
  1156. //单个知识点得分情况
  1157. scores += exam.studentScores[index][n] * itemPersent;
  1158. //scoreCount++;
  1159. }
  1160. /*if (exam.studentScores[index].Sum() >= rhw && phCount < rhwCount)
  1161. {
  1162. rhwC++;
  1163. phCount++;
  1164. continue;
  1165. }
  1166. if (exam.studentScores[index].Sum() <= rhl && plCount < (exam.studentIds.Count - rhlCount))
  1167. {
  1168. rhlC++;
  1169. plCount++;
  1170. continue;
  1171. }*/
  1172. }
  1173. gPoint += point[n];
  1174. }
  1175. valuew[1] = OnePoint.ToString();
  1176. string itemNos = "";
  1177. if (itemNo.Count > 0)
  1178. {
  1179. valuew[2] = string.Join(",", itemNo);
  1180. /*foreach (string np in itemNo)
  1181. {
  1182. itemNos += np + ",";
  1183. }
  1184. valuew[2] = itemNos[0..^1];*/
  1185. }
  1186. else
  1187. {
  1188. valuew[2] = itemNos;
  1189. }
  1190. n++;
  1191. });
  1192. kScore.Add(gPoint);
  1193. Score.Add(scores);
  1194. knowScore.Add(OnePoint);
  1195. //该知识点平均得分
  1196. double sc = (exam.studentIds.Count - exam.lostStus.Count) > 0 ? Math.Round(scores * 1.0 / (exam.studentIds.Count - exam.lostStus.Count), 2) : 0;
  1197. //错题关系表
  1198. valuew[3] = (OnePoint > 0 ? Math.Round(sc / OnePoint, 2) : 0).ToString(); ;
  1199. valuew[4] = wrong.ToString();
  1200. valuew[5] = rhwC.ToString();
  1201. valuew[6] = rhlC.ToString();
  1202. wrongPersent.Add(valuew);
  1203. //知识点占比
  1204. double persent = TotalPoint > 0 ? OnePoint / TotalPoint : 0;
  1205. //double persent = OnePoint / TotalPoint;
  1206. per.Add(persent.ToString("0.00"));
  1207. }
  1208. //本次考试知识点占比
  1209. List<double> allPer = new List<double>();
  1210. foreach (double sc in Score)
  1211. {
  1212. allPer.Add(exam.studentIds.Count > 0 ? Math.Round(sc * 1.0 / exam.studentIds.Count, 2) : 0);
  1213. }
  1214. int stuNo = 0;
  1215. exam.studentIds.ForEach(e =>
  1216. {
  1217. List<double> valueKnow = new List<double>();
  1218. foreach (string know in knowledge)
  1219. {
  1220. double anwPoint = 0;
  1221. double itemPersent = 0;
  1222. int sno = 0;
  1223. info.papers[index].knowledge.ForEach(kno =>
  1224. {
  1225. if (kno.Contains(know))
  1226. {
  1227. //当前知识点在该题占比多少
  1228. itemPersent = kno.Count > 0 ? 1 / Convert.ToDouble(kno.Count) : 0;
  1229. //itemPersent = 1 / Convert.ToDouble(kno.Count);
  1230. anwPoint += result[stuNo][sno] * itemPersent;
  1231. }
  1232. sno++;
  1233. });
  1234. valueKnow.Add(anwPoint);
  1235. }
  1236. KeyValuePair<string, List<double>> keyValue = new KeyValuePair<string, List<double>>(e, valueKnow);
  1237. datas.Add(keyValue);
  1238. stuNo++;
  1239. });
  1240. KeyValuePair<string, List<string>> key1 = new KeyValuePair<string, List<string>>(exam.subjectId, knowledgeName);
  1241. KeyValuePair<string, List<string>> key2 = new KeyValuePair<string, List<string>>(exam.subjectId, per);
  1242. KeyValuePair<string, List<double>> key3 = new KeyValuePair<string, List<double>>(exam.subjectId, allPer);
  1243. KeyValuePair<string, List<double>> key4 = new KeyValuePair<string, List<double>>(exam.subjectId, kScore);
  1244. KeyValuePair<string, List<List<string>>> keyValue = new KeyValuePair<string, List<List<string>>>(exam.subjectId, wrongPersent);
  1245. KeyValuePair<string, List<KeyValuePair<string, List<double>>>> valuePair = new KeyValuePair<string, List<KeyValuePair<string, List<double>>>>(exam.subjectId, datas);
  1246. return (key1, key2, key3, key4, keyValue, valuePair);
  1247. }
  1248. private static (KeyValuePair<string, List<int>>, KeyValuePair<string, List<string>>, KeyValuePair<string, List<double>>, KeyValuePair<string, List<double>>, KeyValuePair<string, List<List<string>>>, KeyValuePair<string, List<KeyValuePair<string, List<double>>>>) DoLevel(ExamResult exam, ExamInfo info, List<string> keynowWrong)
  1249. {
  1250. List<double> point = new List<double>();
  1251. List<List<double>> result = new List<List<double>>();
  1252. List<ClassRange> classes = new List<ClassRange>();
  1253. List<KeyValuePair<string, List<double>>> datas = new List<KeyValuePair<string, List<double>>>();
  1254. //求单个认知层次所占分数
  1255. List<string> per = new List<string>();
  1256. List<List<string>> wrongPersent = new List<List<string>>();
  1257. List<int> knowledgeName = new List<int>();
  1258. //定位试卷信息
  1259. int index = 0;
  1260. foreach (ExamSubject subject in info.subjects)
  1261. {
  1262. if (subject.id.Equals(exam.subjectId))
  1263. {
  1264. break;
  1265. }
  1266. else
  1267. {
  1268. index++;
  1269. }
  1270. }
  1271. knowledgeName.Add(1);
  1272. knowledgeName.Add(2);
  1273. knowledgeName.Add(3);
  1274. knowledgeName.Add(4);
  1275. knowledgeName.Add(5);
  1276. knowledgeName.Add(6);
  1277. //double Qnum = 0;
  1278. point = info.papers[index].point;
  1279. result = exam.studentScores;
  1280. classes = exam.classes;
  1281. //ids = exam.studentIds;
  1282. //确定高分组 低分组人数
  1283. /*List<List<double>> re = exam.studentScores;
  1284. List<double> resultSum = new List<double>();
  1285. foreach (List<double> data in re)
  1286. {
  1287. resultSum.Add(data.Sum());
  1288. }*/
  1289. double[] points = StringHelper.ListTodouble(exam.paper.point);
  1290. double[,] scs = StringHelper.ListToDouble(exam.studentScores);
  1291. var cdm = new ClouDASMatrix(scs, points);
  1292. //scores.Sort((s1, s2) => { return s2.CompareTo(s1); });
  1293. int rhwCount = cdm.SH.Count();
  1294. double rhw = cdm.SH.LastOrDefault().Item2;
  1295. int rhlCount = cdm.SL.Count();
  1296. double rhl = cdm.SL.FirstOrDefault().Item2;
  1297. //确定高分组 最低分数
  1298. /* resultSum.Sort((s1, s2) => { return s2.CompareTo(s1); });
  1299. int rhwCount = 0;
  1300. double rhw = 0;
  1301. int rhlCount = 0;
  1302. double rhl = 0;
  1303. if (resultSum.Count > 3)
  1304. {
  1305. rhwCount = Convert.ToInt32(Math.Floor(resultSum.Count * 0.27));
  1306. rhw = rhwCount > 0 ? resultSum[rhwCount - 1] : 0;
  1307. rhlCount = Convert.ToInt32(Math.Ceiling(resultSum.Count * 0.73));
  1308. rhl = rhlCount > 0 ? resultSum[rhlCount] : 0;
  1309. }
  1310. else
  1311. {
  1312. rhwCount = Convert.ToInt32(Math.Floor(resultSum.Count * 0.27));
  1313. rhw = rhwCount > 0 ? resultSum[rhwCount] : 0;
  1314. rhlCount = Convert.ToInt32(Math.Ceiling(resultSum.Count * 0.73));
  1315. rhl = rhlCount > 0 ? resultSum[rhlCount - 1] : 0;
  1316. }*/
  1317. //初始化年级总分
  1318. double total = 0;
  1319. //处理年级单个知识点得分率
  1320. foreach (List<double> grade in result)
  1321. {
  1322. total += grade.Sum();
  1323. }
  1324. //试卷总分
  1325. double TotalPoint = point.Sum();
  1326. List<double> knowScore = new List<double>();
  1327. //得分率
  1328. List<double> Score = new List<double>();
  1329. //分值
  1330. List<double> kScore = new List<double>();
  1331. //List<double> allPer = new List<double>();
  1332. for (int k = 0; k < knowledgeName.Count; k++)
  1333. {
  1334. double OnePoint = 0;
  1335. List<string> valuew = new List<string>();
  1336. List<string> itemNo = new List<string>();
  1337. keynowWrong.ForEach(x =>
  1338. {
  1339. valuew.Add("-");
  1340. });
  1341. valuew[0] = knowledgeName[k].ToString();
  1342. int n = 0;
  1343. int wrong = 0;
  1344. int rhwC = 0;
  1345. int rhlC = 0;
  1346. //int scoreCount = 0;
  1347. double scores = 0;
  1348. //所有认知层次得分
  1349. double anwGPoint = 0;
  1350. double gPoint = 0;
  1351. info.papers[index].field.ForEach(kno =>
  1352. {
  1353. if (kno == knowledgeName[k])
  1354. {
  1355. OnePoint += point[n];
  1356. itemNo.Add((n + 1).ToString());
  1357. //处理认知层次错题人数
  1358. int phCount = 0;
  1359. int plCount = 0;
  1360. foreach (string id in exam.studentIds)
  1361. {
  1362. int index = exam.studentIds.IndexOf(id);
  1363. if (exam.studentScores[index][n] == 0)
  1364. {
  1365. wrong++;
  1366. if (exam.studentScores[index].Sum() >= rhw && phCount < rhwCount)
  1367. {
  1368. rhwC++;
  1369. phCount++;
  1370. continue;
  1371. }
  1372. if (exam.studentScores[index].Sum() <= rhl && plCount < (exam.studentIds.Count - rhlCount))
  1373. {
  1374. rhlC++;
  1375. plCount++;
  1376. continue;
  1377. }
  1378. continue;
  1379. }
  1380. else
  1381. {
  1382. //单个认知层次得分情况
  1383. scores += exam.studentScores[index][n];
  1384. }
  1385. /* if (exam.studentScores[index].Sum() >= rhw && phCount < rhwCount && exam.studentScores[index][n] == 0)
  1386. {
  1387. rhwC++;
  1388. phCount++;
  1389. continue;
  1390. }
  1391. if (exam.studentScores[index].Sum() <= rhl && plCount < (exam.studentIds.Count - rhlCount) && exam.studentScores[index][n] == 0)
  1392. {
  1393. rhlC++;
  1394. plCount++;
  1395. continue;
  1396. }*/
  1397. //anwGPoint += exam.studentScores[index][n];
  1398. }
  1399. gPoint += point[n];
  1400. }
  1401. valuew[1] = OnePoint.ToString();
  1402. string itemNos = "";
  1403. if (itemNo.Count > 0)
  1404. {
  1405. foreach (string np in itemNo)
  1406. {
  1407. itemNos += np + ",";
  1408. }
  1409. valuew[2] = itemNos[0..^1];
  1410. }
  1411. else
  1412. {
  1413. valuew[2] = itemNos;
  1414. }
  1415. n++;
  1416. });
  1417. Score.Add(scores);
  1418. kScore.Add(gPoint);
  1419. knowScore.Add(OnePoint);
  1420. double sc = (exam.studentIds.Count - exam.lostStus.Count) > 0 ? Math.Round(scores * 1.0 / (exam.studentIds.Count - exam.lostStus.Count), 2) : 0;
  1421. //错题关系表
  1422. valuew[3] = (OnePoint > 0 ? Math.Round(sc / OnePoint, 2) : 0).ToString();
  1423. valuew[4] = wrong.ToString();
  1424. valuew[5] = rhwC.ToString();
  1425. valuew[6] = rhlC.ToString();
  1426. wrongPersent.Add(valuew);
  1427. //认知层次占比
  1428. double persent = TotalPoint > 0 ? OnePoint / TotalPoint : 0;
  1429. //allPer.Add(OnePoint > 0 ? Math.Round(sc / OnePoint, 2) : 0);
  1430. per.Add(persent.ToString("0.00"));
  1431. }
  1432. //本次考试认知层次占比
  1433. List<double> allPer = new List<double>();
  1434. foreach (double sc in Score)
  1435. {
  1436. allPer.Add(exam.studentIds.Count > 0 ? Math.Round(sc * 1.0 / exam.studentIds.Count, 2) : 0);
  1437. }
  1438. int stuNo = 0;
  1439. exam.studentIds.ForEach(e =>
  1440. {
  1441. List<double> valueKnow = new List<double>();
  1442. foreach (int know in knowledgeName)
  1443. {
  1444. double anwPoint = 0;
  1445. double itemPersent = 0;
  1446. int sno = 0;
  1447. info.papers[index].field.ForEach(kno =>
  1448. {
  1449. if (kno == know)
  1450. {
  1451. //当前认知层次在该题占比多少
  1452. itemPersent = 1;
  1453. anwPoint += result[stuNo][sno] * itemPersent;
  1454. }
  1455. sno++;
  1456. });
  1457. valueKnow.Add(anwPoint);
  1458. }
  1459. KeyValuePair<string, List<double>> keyValue = new KeyValuePair<string, List<double>>(e, valueKnow);
  1460. datas.Add(keyValue);
  1461. stuNo++;
  1462. });
  1463. KeyValuePair<string, List<int>> key1 = new KeyValuePair<string, List<int>>(exam.subjectId, knowledgeName);
  1464. KeyValuePair<string, List<string>> key2 = new KeyValuePair<string, List<string>>(exam.subjectId, per);
  1465. KeyValuePair<string, List<double>> key3 = new KeyValuePair<string, List<double>>(exam.subjectId, allPer);
  1466. KeyValuePair<string, List<double>> key4 = new KeyValuePair<string, List<double>>(exam.subjectId, kScore);
  1467. KeyValuePair<string, List<List<string>>> keyValue = new KeyValuePair<string, List<List<string>>>(exam.subjectId, wrongPersent);
  1468. KeyValuePair<string, List<KeyValuePair<string, List<double>>>> valuePair = new KeyValuePair<string, List<KeyValuePair<string, List<double>>>>(exam.subjectId, datas);
  1469. return (key1, key2, key3, key4, keyValue, valuePair);
  1470. }
  1471. [ProducesDefaultResponseType]
  1472. [HttpPost("simple")]
  1473. [Authorize(Roles = "IES")]
  1474. [AuthToken(Roles = "teacher,admin")]
  1475. public async Task<IActionResult> simple(JsonElement request)
  1476. {
  1477. //获取评测的ID
  1478. if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
  1479. if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
  1480. try
  1481. {
  1482. List<Dictionary<string, object>> averageMap = new List<Dictionary<string, object>>();
  1483. List<Dictionary<string, object>> averageTotal = new List<Dictionary<string, object>>();
  1484. var client = _azureCosmos.GetCosmosClient();
  1485. //todo 需要检查数据是否存在
  1486. ExamInfo info = new();
  1487. var response = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemStreamAsync(id.ToString(), new PartitionKey($"Exam-{code}"));
  1488. if (response.Status == 200)
  1489. {
  1490. using var cJson = await JsonDocument.ParseAsync(response.ContentStream);
  1491. info = cJson.ToObject<ExamInfo>();
  1492. }
  1493. else {
  1494. return Ok(new { averageMap, averageTotal });
  1495. }
  1496. List<ExamResult> examResults = new List<ExamResult>();
  1497. var query = $"select c.id,c.name,c.subjectId,c.studentScores,c.studentIds,c.paper,c.classes,c.afp,c.akp,c.lostStus from c where c.examId = '{id}' ";
  1498. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<ExamResult>(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamResult-{id}") }))
  1499. {
  1500. examResults.Add(item);
  1501. }
  1502. foreach (ExamResult result in examResults)
  1503. {
  1504. List<double> ClassAverage = new List<double>();
  1505. List<ClassSimple> ClassName = new List<ClassSimple>();
  1506. Dictionary<string, object> mapSubject = new Dictionary<string, object>();
  1507. Dictionary<string, object> mapClass = new Dictionary<string, object>();
  1508. int subIndex = 0;
  1509. foreach (var sub in info.subjects)
  1510. {
  1511. if (sub.id.Equals(result.subjectId))
  1512. {
  1513. break;
  1514. }
  1515. else
  1516. {
  1517. subIndex++;
  1518. }
  1519. }
  1520. List<double> points = info.papers[subIndex].point;
  1521. HashSet<string> kn = new HashSet<string>();
  1522. foreach (List<string> know in info.papers[subIndex].knowledge) {
  1523. foreach (string k in know) {
  1524. kn.Add(k);
  1525. }
  1526. }
  1527. List<int> fs = new() { 1,2,3,4,5,6 };
  1528. mapClass.Add("subjectId", result.subjectId);
  1529. foreach (ClassRange range in result.classes)
  1530. {
  1531. ClassSimple classSimple = new()
  1532. {
  1533. id = range.id,
  1534. name = range.name
  1535. };
  1536. ClassName.Add(classSimple);
  1537. double totalClass = 0;
  1538. List<string> counts = new();
  1539. for (int i = range.range[0]; i <= range.range[1]; i++)
  1540. {
  1541. if (result.lostStus.Contains(result.studentIds[i])) {
  1542. counts.Add(result.studentIds[i]);
  1543. continue;
  1544. }
  1545. totalClass += result.studentScores.Count > 0 ? result.studentScores[i].Sum() : 0;
  1546. }
  1547. ClassAverage.Add(range.range[1] - range.range[0] + 1 - counts.Count > 0 ? totalClass * 1.0 / (range.range[1] - range.range[0] + 1 - counts.Count) : 0);
  1548. }
  1549. mapClass.Add("className", ClassName);
  1550. mapClass.Add("ClassAverage", ClassAverage);
  1551. averageMap.Add(mapClass);
  1552. List<double> wn = await getWrongNum(result, points);
  1553. List<double> SubjectTotal = new List<double>();
  1554. foreach (List<double> score in result.studentScores)
  1555. {
  1556. SubjectTotal.Add(score.Sum());
  1557. }
  1558. mapSubject.Add("subjectId", result.subjectId);
  1559. mapSubject.Add("total", SubjectTotal);
  1560. mapSubject.Add("wrongNum", wn);
  1561. mapSubject.Add("akp", result.akp);
  1562. mapSubject.Add("afp", result.afp);
  1563. mapSubject.Add("kn",kn);
  1564. mapSubject.Add("fs", fs);
  1565. averageTotal.Add(mapSubject);
  1566. }
  1567. return Ok(new { averageMap, averageTotal });
  1568. }
  1569. catch (Exception e)
  1570. {
  1571. await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/simple()\n{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  1572. return BadRequest();
  1573. }
  1574. }
  1575. private Task<List<double>> getWrongNum(ExamResult result, List<double> points)
  1576. {
  1577. int num = 0;
  1578. List<double> wn = new List<double>();
  1579. foreach (var point in points)
  1580. {
  1581. int wnum = 0;
  1582. double p = point * 0.8;
  1583. foreach (ClassRange range in result.classes)
  1584. {
  1585. for (int i = range.range[0]; i <= range.range[1]; i++)
  1586. {
  1587. //判断推送的数据中,学生正常得分数据
  1588. if (result.studentScores[i].Count > 0)
  1589. {
  1590. if (result.studentScores[i][num] < point)
  1591. {
  1592. if (result.studentScores[i][num] < p)
  1593. {
  1594. wnum++;
  1595. }
  1596. else
  1597. {
  1598. continue;
  1599. }
  1600. }
  1601. else
  1602. {
  1603. continue;
  1604. }
  1605. }
  1606. else
  1607. {
  1608. wnum++;
  1609. }
  1610. }
  1611. }
  1612. wn.Add(wnum);
  1613. num++;
  1614. }
  1615. return Task.FromResult(wn);
  1616. }
  1617. public class ClassSimple
  1618. {
  1619. public string id { get; set; }
  1620. public string name { get; set; }
  1621. }
  1622. [ProducesDefaultResponseType]
  1623. [HttpPost("studentAnalysis")]
  1624. [Authorize(Roles = "IES")]
  1625. [AuthToken(Roles = "teacher,admin,student")]
  1626. public async Task<IActionResult> studentAnalysis(JsonElement request)
  1627. {
  1628. //获取个人或者校本
  1629. if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
  1630. //评测Id
  1631. if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
  1632. if (!request.TryGetProperty("sId", out JsonElement sId)) return BadRequest();
  1633. if (!request.TryGetProperty("cId", out JsonElement cId)) return BadRequest();
  1634. if (!request.TryGetProperty("gId", out JsonElement gId)) return BadRequest();
  1635. try
  1636. {
  1637. List<Dictionary<string, object>> averageMap = new();
  1638. List<Dictionary<string, object>> averageTotal = new();
  1639. List<List<double>> classAllAverage = new();
  1640. School school = new();
  1641. var client = _azureCosmos.GetCosmosClient();
  1642. ExamInfo info = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"Exam-{code}"));
  1643. var response = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(code.ToString(), new PartitionKey($"Base"));
  1644. if (response.Status == 200)
  1645. {
  1646. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  1647. school = json.ToObject<School>();
  1648. }
  1649. //School school = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(code.ToString(), new PartitionKey($"Base"));
  1650. List<ExamResult> examResults = new List<ExamResult>();
  1651. var query = $"select c.id,c.name,c.subjectId,c.studentScores,c.studentIds,c.paper,c.classes from c where c.examId = '{id}' ";
  1652. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<ExamResult>(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamResult-{id}") }))
  1653. {
  1654. examResults.Add(item);
  1655. }
  1656. if (examResults.Count == 0)
  1657. {
  1658. return Ok(new { code = ResponseCode.DATA_EMPTY_NULL, v = "正在结算中" });
  1659. }
  1660. int indexClass = 0;
  1661. HashSet<string> cla = new HashSet<string>();
  1662. HashSet<string> stu = new HashSet<string>();
  1663. double totalScore = 0;
  1664. List<List<double>> allList = new List<List<double>>();
  1665. double income = 0;
  1666. foreach (Period period in school.period)
  1667. {
  1668. if (info.period.id.Equals(period.id))
  1669. {
  1670. income = period.analysis.income;
  1671. }
  1672. }
  1673. //获取进线人数
  1674. int count = (int)System.Math.Round(info.stuCount * (income / 100.0), MidpointRounding.AwayFromZero);
  1675. foreach (ExamResult result in examResults)
  1676. {
  1677. List<double> ClassAverage = new List<double>();
  1678. List<int> personCount = new List<int>();
  1679. List<string> ClassId = new List<string>();
  1680. Dictionary<string, object> mapClass = new Dictionary<string, object>();
  1681. int index = result.studentIds.IndexOf(sId.ToString());
  1682. //个人总分
  1683. totalScore += result.studentScores[index].Sum();
  1684. mapClass.Add("subjectId", result.subjectId);
  1685. double totalGrade = 0;
  1686. List<double> gradeScores = new List<double>();
  1687. List<List<double>> classScores = new List<List<double>>();
  1688. //此处声明集合存储原本的成绩序列
  1689. List<List<double>> cScores = new List<List<double>>();
  1690. /*var sc = result.classes.GroupBy(m => new { m.gradeId }).Select(c => new { gId = c.Key.gradeId, ranges = c.ToList() }).ToList();
  1691. foreach (var aa in sc)
  1692. {
  1693. foreach (ClassRange range in aa.ranges)
  1694. {
  1695. List<double> scores = new();
  1696. List<double> finalScores = new();
  1697. ClassId.Add(range.id);
  1698. cla.Add(range.id);
  1699. double totalClass = 0;
  1700. for (int i = range.range[0]; i <= range.range[1]; i++)
  1701. {
  1702. totalClass += result.studentScores[i].Sum();
  1703. scores.Add(result.studentScores[i].Sum());
  1704. finalScores.Add(result.studentScores[i].Sum());
  1705. gradeScores.Add(result.studentScores[i].Sum());
  1706. totalGrade += result.studentScores[i].Sum();
  1707. stu.Add(result.studentIds[i]);
  1708. }
  1709. classScores.Add(scores);
  1710. cScores.Add(finalScores);
  1711. ClassAverage.Add(range.range[1] - range.range[0] + 1 > 0 ? Math.Round(totalClass * 1.0 / (range.range[1] - range.range[0] + 1), 2) : 0);
  1712. personCount.Add(range.range[1] - range.range[0] + 1);
  1713. }
  1714. classAllAverage.Add(ClassAverage);
  1715. gradeScores.Sort((s1, s2) => { return s2.CompareTo(s1); });
  1716. indexClass = ClassId.IndexOf(cId.ToString());
  1717. //单科成绩
  1718. allList.Add(cScores[indexClass]);
  1719. classScores[indexClass].Sort((s1, s2) => { return s2.CompareTo(s1); });
  1720. mapClass.Add("scoreSum", result.paper.point.Sum());
  1721. mapClass.Add("score", result.studentScores[index].Sum());
  1722. mapClass.Add("classAverage", ClassAverage[indexClass]);
  1723. mapClass.Add("classCount", personCount[indexClass]);
  1724. mapClass.Add("classRank", classScores[indexClass].IndexOf(result.studentScores[index].Sum()));
  1725. mapClass.Add("gradeAverage", result.studentIds.Count > 0 ? Math.Round(totalGrade * 1.0 / result.studentIds.Count, 2) : 0);
  1726. mapClass.Add("gradeCount", result.studentIds.Count);
  1727. mapClass.Add("gradeRank", gradeScores.IndexOf(result.studentScores[index].Sum()));
  1728. averageMap.Add(mapClass);
  1729. }
  1730. */
  1731. foreach (ClassRange range in result.classes)
  1732. {
  1733. List<double> scores = new List<double>();
  1734. List<double> finalScores = new List<double>();
  1735. ClassId.Add(range.id);
  1736. cla.Add(range.id);
  1737. double totalClass = 0;
  1738. for (int i = range.range[0]; i <= range.range[1]; i++)
  1739. {
  1740. totalClass += result.studentScores[i].Sum();
  1741. scores.Add(result.studentScores[i].Sum());
  1742. finalScores.Add(result.studentScores[i].Sum());
  1743. gradeScores.Add(result.studentScores[i].Sum());
  1744. totalGrade += result.studentScores[i].Sum();
  1745. stu.Add(result.studentIds[i]);
  1746. }
  1747. classScores.Add(scores);
  1748. cScores.Add(finalScores);
  1749. ClassAverage.Add(range.range[1] - range.range[0] + 1 > 0 ? Math.Round(totalClass * 1.0 / (range.range[1] - range.range[0] + 1), 2) : 0);
  1750. personCount.Add(range.range[1] - range.range[0] + 1);
  1751. }
  1752. }
  1753. //处理班级/年级全科均分
  1754. List<double> AllAverage = new List<double>();
  1755. double a = 0;
  1756. for (int k = 0; k < cla.Count; k++)
  1757. {
  1758. for (int i = 0; i < classAllAverage.Count; i++)
  1759. {
  1760. a += classAllAverage[i][k];
  1761. }
  1762. AllAverage.Add(a);
  1763. }
  1764. List<double> classScore = new List<double>();
  1765. for (int i = 0; i < allList[0].Count; i++)
  1766. {
  1767. double b = 0;
  1768. for (int m = 0; m < allList.Count; m++)
  1769. {
  1770. b += allList[m][i];
  1771. }
  1772. classScore.Add(b);
  1773. }
  1774. classScore.Sort((s1, s2) => { return s2.CompareTo(s1); });
  1775. //处理年级总分以及排名
  1776. List<double> GradeScore = new List<double>();
  1777. foreach (string ss in stu)
  1778. {
  1779. double score = 0;
  1780. foreach (ExamResult result in examResults)
  1781. {
  1782. int index = result.studentIds.IndexOf(ss);
  1783. score += result.studentScores[index].Sum();
  1784. }
  1785. GradeScore.Add(score);
  1786. }
  1787. GradeScore.Sort((s1, s2) => { return s2.CompareTo(s1); });
  1788. double ipoint = GradeScore[count];
  1789. return Ok(new { income = ipoint, rankc = classScore.IndexOf(totalScore), rankg = GradeScore.IndexOf(totalScore), classAverage = Math.Round(AllAverage[indexClass], 2), gradeAverage = cla.Count > 0 ? Math.Round(AllAverage.Sum() * 1.0 / cla.Count, 2) : 0, averageMap }); ;
  1790. }
  1791. catch (Exception e)
  1792. {
  1793. await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/studentAnalysis()\n{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  1794. return BadRequest();
  1795. }
  1796. }
  1797. [ProducesDefaultResponseType]
  1798. [HttpPost("education-analysis")]
  1799. [Authorize(Roles = "IES")]
  1800. [AuthToken(Roles = "teacher,admin,student")]
  1801. public async Task<IActionResult> education(JsonElement request) {
  1802. if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
  1803. if (!request.TryGetProperty("period", out JsonElement period)) return BadRequest();
  1804. if (!request.TryGetProperty("gId", out JsonElement gId)) return BadRequest();
  1805. try {
  1806. var client = _azureCosmos.GetCosmosClient();
  1807. List<ExamInfo> infos = new List<ExamInfo>();
  1808. var query = $"select c.id,c.name,c.source from c where c.period.id = '{period}'";
  1809. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<ExamInfo>(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Exam-{code}") }))
  1810. {
  1811. infos.Add(item);
  1812. }
  1813. return Ok();
  1814. } catch (Exception e) {
  1815. return Ok(new { code = 500});
  1816. }
  1817. }
  1818. public async Task<string> getGId(int cyear, string periodId, string code)
  1819. {
  1820. var client = _azureCosmos.GetCosmosClient();
  1821. School sc = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(code, new Azure.Cosmos.PartitionKey("Base"));
  1822. string gradeId = "";
  1823. foreach (Period period in sc.period)
  1824. {
  1825. if (period.id.Equals(periodId))
  1826. {
  1827. foreach (Semester semester in period.semesters)
  1828. {
  1829. if (semester.start == 1)
  1830. {
  1831. int year = DateTimeOffset.UtcNow.Year;
  1832. int month = DateTimeOffset.UtcNow.Month;
  1833. int day = DateTimeOffset.UtcNow.Day;
  1834. int time = 0;
  1835. if (month == semester.month)
  1836. {
  1837. time = day >= semester.day ? 0 : 1;
  1838. }
  1839. else
  1840. {
  1841. time = month > semester.month ? 0 : 1;
  1842. }
  1843. int eyear = year - time;
  1844. gradeId = (eyear - cyear).ToString();
  1845. }
  1846. }
  1847. }
  1848. }
  1849. return gradeId;
  1850. }
  1851. }
  1852. }