AnalysisController.cs 80 KB

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