AnalysisController.cs 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629
  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;
  22. using static TEAMModelOS.SDK.Models.Cosmos.ClassAnalysis;
  23. using static TEAMModelOS.SDK.Models.Cosmos.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 = examResults.Select(e => new
  568. {
  569. id = e.id,
  570. name = info.subjects.FirstOrDefault(c => c.id == e.id).name,
  571. record = e.record,
  572. phc = e.phc,
  573. plc = e.plc,
  574. sRate = e.sRate,
  575. average = e.average,
  576. standard = e.standard
  577. });
  578. /*var sub = info.subjects.Select(x => new
  579. {
  580. id = x.id,
  581. name = x.name,
  582. record = examResults.FirstOrDefault(c => c.id == x.id).record,
  583. phc = examResults.FirstOrDefault(c => c.id == x.id).phc,
  584. plc = examResults.FirstOrDefault(c => c.id == x.id).plc,
  585. sRate = examResults.FirstOrDefault(c => c.id == x.id).sRate,
  586. average = examResults.FirstOrDefault(c => c.id == x.id).average,
  587. standard = examResults.FirstOrDefault(c => c.id == x.id).standard
  588. });*/
  589. var subAll = new { sRate = info.sRate, average = info.average, standard = info.standard, total = info.stuCount };
  590. return Ok(new
  591. {
  592. students,
  593. classes,
  594. grades,
  595. paper = subjectPaperDatas,
  596. subjects = sub,
  597. scatterKey = scatterKey,
  598. paperKey = paperKey,
  599. pointLevelKey = valuePairs,
  600. ipoint = ipoint,
  601. touchScore = touch,
  602. knowKey = knowkey,
  603. wrongKey = keynowWrong,
  604. wrong = wrongDatas,
  605. knowName = knowNameDatas,
  606. knowPer = knowPerDatas,
  607. knowAllper = knowAllPerDatas,
  608. fieldwrong = fieldwrongDatas,
  609. fieldName = fieldNameDatas,
  610. fieldPer = fieldPerDatas,
  611. fieldAllPer = fieldAllPerDatas,
  612. kScores = knowScoreDatas,
  613. fScores = fieldScoreDatas,
  614. all = subAll
  615. });
  616. }
  617. private static (KeyValuePair<string, List<List<string>>>, KeyValuePair<string, List<KeyValuePair<string, List<double>>>>, Dictionary<string, List<double>>) DoExerciseScatteres(ExamResult e, List<string> paperKey)
  618. {
  619. List<int> examAnswer = new List<int>();
  620. List<string> examPersent = new List<string>();
  621. for (int n = 0; n < e.paper.point.Count; n++)
  622. {
  623. examAnswer.Add(0);
  624. }
  625. //参考人数
  626. double Qnum = 0;
  627. e.studentIds.ForEach(i =>
  628. {
  629. if (!i.Equals("0"))
  630. {
  631. Qnum++;
  632. }
  633. });
  634. List<List<string>> datas = new List<List<string>>();
  635. List<string[]> itemAnalysis = new List<string[]>();
  636. Dictionary<string, List<int>> gradeItemScore = new Dictionary<string, List<int>>();
  637. Dictionary<string, int> gradeItemStuCount = new Dictionary<string, int>();
  638. List<KeyValuePair<string, List<double>>> classdatas = new List<KeyValuePair<string, List<double>>>();
  639. try
  640. {
  641. e.classes.ForEach(c =>
  642. {
  643. //初始化每题得分情况
  644. List<int> answerCount = new List<int>();
  645. List<double> persent = new List<double>();
  646. int peopleCount = 0;
  647. for (int n = 0; n < e.paper.point.Count; n++)
  648. {
  649. answerCount.Add(0);
  650. }
  651. int qCount = 0;
  652. //每个班级得分占比
  653. for (int i = c.range[0]; i <= c.range[1]; i++)
  654. {
  655. if (e.studentScores[i].Sum() > 0)
  656. {
  657. for (int j = 0; j < e.studentScores[i].Count; j++)
  658. {
  659. if (e.studentScores[i][j] > 0)
  660. {
  661. //记录班级每题得分数
  662. answerCount[j] = answerCount[j] + 1;
  663. //记录年级每题得分数
  664. examAnswer[j] = examAnswer[j] + 1;
  665. }
  666. }
  667. }
  668. else
  669. {
  670. qCount++;
  671. }
  672. peopleCount = c.range[1] - c.range[0] + 1 - qCount;
  673. }
  674. foreach (int p in answerCount)
  675. {
  676. var t = peopleCount > 0 ? Math.Round(p * 1.0 / peopleCount * 100, 2) : 0;
  677. //var t = Math.Round(p * 1.0 / peopleCount * 100,2);
  678. persent.Add(t);
  679. }
  680. classdatas.Add(new KeyValuePair<string, List<double>>(c.id, persent));
  681. if (gradeItemScore.ContainsKey(c.gradeId))
  682. {
  683. var we = gradeItemScore[c.gradeId];
  684. List<int> count = we;
  685. for (int index = 0; index < count.Count; index++)
  686. {
  687. count[index] = count[index] + answerCount[index];
  688. }
  689. gradeItemScore[c.gradeId] = count;
  690. // gradeItemScore[c.gradeId].ForEach(x => { x = x + answerCount[index]; index += 1; });
  691. gradeItemStuCount[c.gradeId] = gradeItemStuCount[c.gradeId] + peopleCount;
  692. }
  693. else
  694. {
  695. gradeItemScore.Add(c.gradeId, answerCount);
  696. gradeItemStuCount.Add(c.gradeId, peopleCount);
  697. }
  698. });
  699. double[] point = StringHelper.ListTodouble(e.paper.point);
  700. double[,] result = StringHelper.ListToDouble(e.studentScores);
  701. var cdm = new ClouDASMatrix(result, point);
  702. //试题Y
  703. List<double> answer = cdm.AnswerRate;
  704. //试题X
  705. List<double> quality = cdm.QualityRate;
  706. //试题区域
  707. List<string> topic = cdm.TopicFallArea;
  708. //试题相关分析结果
  709. List<(double Diff, double D, double R1, double R2, double R3, double R4, double R5, double R6, double PH, double PL)> rs = cdm.RS;
  710. for (int i = 0; i < rs.Count; i++)
  711. {
  712. string[] ex = new string[] { };
  713. string ss = rs[i].ToString()[1..^1];
  714. ex = ss.Split(",");
  715. itemAnalysis.Add(ex);
  716. }
  717. foreach (int p in examAnswer)
  718. {
  719. var t = Qnum > 0 ? Math.Round(p * 1.0 / Qnum * 100, 2) : 0;
  720. //var t = Math.Round(p * 1.0 / Qnum * 100,2);
  721. examPersent.Add(t.ToString());
  722. }
  723. for (int k = 0; k < e.paper.point.Count; k++)
  724. {
  725. List<string> values = new List<string>();
  726. paperKey.ForEach(x =>
  727. {
  728. values.Add("-");
  729. });
  730. values[0] = (k + 1).ToString();
  731. if (e.paper.type.Count > 0)
  732. {
  733. values[1] = e.paper.type[k].ToString();
  734. }
  735. else
  736. {
  737. values[1] = "";
  738. }
  739. values[2] = topic[k].ToString();
  740. values[3] = e.paper.point[k].ToString();
  741. /* List<string> sk = new List<string>();
  742. foreach (string kl in e.paper.knowledge[k]) {
  743. sk.Add(kl);
  744. }*/
  745. values[22] = string.Join(",", e.paper.knowledge[k]);
  746. if (itemAnalysis.Count > 0)
  747. {
  748. values[4] = itemAnalysis[k][0];
  749. values[5] = itemAnalysis[k][1].Trim();
  750. values[12] = itemAnalysis[k][2];
  751. values[13] = itemAnalysis[k][3];
  752. values[14] = itemAnalysis[k][4];
  753. values[15] = itemAnalysis[k][5];
  754. values[16] = itemAnalysis[k][6];
  755. values[17] = itemAnalysis[k][7];
  756. values[18] = itemAnalysis[k][8];
  757. values[19] = itemAnalysis[k][9];
  758. }
  759. else
  760. {
  761. values[4] = "-";
  762. values[5] = "-";
  763. values[12] = "-";
  764. values[13] = "-";
  765. values[14] = "-";
  766. values[15] = "-";
  767. values[16] = "-";
  768. values[17] = "-";
  769. values[18] = "-";
  770. values[19] = "-";
  771. }
  772. Dictionary<string, double> its = new Dictionary<string, double>();
  773. classdatas.ForEach(cls => { its.Add(cls.Key, cls.Value[k]); });
  774. StringBuilder classBuilder = new StringBuilder();
  775. foreach (var key in its.Keys)
  776. {
  777. classBuilder.Append(key + ":" + its[key] + ",");
  778. }
  779. var cstr = classBuilder.ToString();
  780. values[7] = cstr.Substring(0, cstr.Length - 1);
  781. StringBuilder gradeBuilder = new StringBuilder();
  782. //处理年级的这个题的得分
  783. foreach (var key in gradeItemScore.Keys)
  784. {
  785. var data = gradeItemStuCount[key] > 0 ? Math.Round(gradeItemScore[key][k] * 1.0 / gradeItemStuCount[key] * 100, 2) : 0;
  786. //var data = Math.Round(gradeItemScore[key][k] * 1.0 / gradeItemStuCount[key] * 100, 2);
  787. gradeBuilder.Append(key + ":" + data + ",");
  788. }
  789. var gstr = gradeBuilder.ToString();
  790. values[8] = gstr.Substring(0, gstr.Length - 1);
  791. values[20] = quality[k].ToString();
  792. values[21] = answer[k].ToString();
  793. // string pointName = "";
  794. values[23] = examPersent[k];
  795. datas.Add(values);
  796. }
  797. Dictionary<string, List<double>> dict = new Dictionary<string, List<double>>();
  798. //处理年级的这个题的得分
  799. foreach (var key in gradeItemScore.Keys)
  800. {
  801. List<double> gscores = new List<double>();
  802. gradeItemScore[key].ForEach(x =>
  803. {
  804. var data = gradeItemStuCount[key] > 0 ? Math.Round(x * 1.0 / gradeItemStuCount[key] * 100, 2) : 0;
  805. //var data = Math.Round(x * 1.0 / gradeItemStuCount[key] * 100, 2);
  806. gscores.Add(data);
  807. });
  808. dict.TryAdd(key, gscores);
  809. }
  810. KeyValuePair<string, List<List<string>>> keyValue = new KeyValuePair<string, List<List<string>>>(e.subjectId, datas);
  811. KeyValuePair<string, List<KeyValuePair<string, List<double>>>> classdata = new KeyValuePair<string, List<KeyValuePair<string, List<double>>>>(e.subjectId, classdatas);
  812. return (keyValue, classdata, dict);
  813. }
  814. catch (Exception ex)
  815. {
  816. // throw new BizException(ex.Message);
  817. }
  818. return (default, default, default);
  819. }
  820. //落点分析
  821. private KeyValuePair<string, List<KeyValuePair<string, List<string>>>> DoSubjectScatter(ExamResult e)
  822. {
  823. List<KeyValuePair<string, List<string>>> datas = new List<KeyValuePair<string, List<string>>>();
  824. double[] point = StringHelper.ListTodouble(e.paper.point);
  825. double[,] result = StringHelper.ListToDouble(e.studentScores);
  826. try
  827. {
  828. var cdm = new ClouDASMatrix(result, point);
  829. //学生通过率
  830. List<double> pass = cdm.ScoringRate;
  831. //学生稳定度
  832. List<double> sta = cdm.StabilityRate;
  833. //落点区域
  834. List<string> stu = cdm.StuFallArea;
  835. //需努力的题型
  836. List<int[]> strive = cdm.StriveTopic;
  837. //需小心的题型
  838. List<int[]> careful = cdm.CarefulTopic;
  839. int i = 0;
  840. for (int k = e.studentIds.Count - 1; k >= 0; k--)
  841. {
  842. if (e.studentIds[k].Equals("0"))
  843. {
  844. e.studentIds.Remove(e.studentIds[k]);
  845. }
  846. }
  847. e.studentIds.ForEach(s =>
  848. {
  849. /* if (e.studentScores[i].Sum() != 0)
  850. {*/
  851. List<string> info = new List<string>
  852. {
  853. s,
  854. "-",
  855. sta[i].ToString(),
  856. pass[i].ToString(),
  857. i + 1 + "",
  858. e.studentScores[i].Sum().ToString()
  859. };
  860. int right = 0;
  861. int wrong = 0;
  862. foreach (int p in e.studentScores[i])
  863. {
  864. if (p > 0)
  865. {
  866. right++;
  867. }
  868. else
  869. {
  870. wrong++;
  871. }
  872. }
  873. info.Add(right + "");
  874. info.Add(wrong + "");
  875. int[] str = strive[i];
  876. string striveAll = "";
  877. foreach (int n in str)
  878. {
  879. striveAll += n.ToString() + ",";
  880. }
  881. int[] care = careful[i];
  882. string careAll = "";
  883. foreach (int n in care)
  884. {
  885. careAll += n.ToString() + ",";
  886. }
  887. if (string.IsNullOrEmpty(striveAll))
  888. {
  889. info.Add("-");
  890. }
  891. else
  892. {
  893. info.Add(striveAll.Substring(0, striveAll.Length - 1));
  894. }
  895. if (string.IsNullOrEmpty(careAll))
  896. {
  897. info.Add("-");
  898. }
  899. else
  900. {
  901. info.Add(careAll.Substring(0, careAll.Length - 1)); ;
  902. }
  903. info.Add(stu[i].ToString());
  904. KeyValuePair<string, List<string>> keyValue = new KeyValuePair<string, List<string>>(s, info);
  905. datas.Add(keyValue);
  906. //}
  907. i++;
  908. });
  909. return new KeyValuePair<string, List<KeyValuePair<string, List<string>>>>(e.subjectId, datas);
  910. }
  911. catch (Exception ex)
  912. {
  913. BadRequest(ex.Message + ex.StackTrace);
  914. Console.WriteLine("---------------------" + ex.Message + "--------------------------");
  915. }
  916. return default;
  917. }
  918. 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)
  919. {
  920. HashSet<string> knowledge = new HashSet<string>();
  921. //HashSet<string> area = new HashSet<string>();
  922. List<double> point = new List<double>();
  923. List<List<double>> result = new List<List<double>>();
  924. List<ClassRange> classes = new List<ClassRange>();
  925. //List<string> ids = new List<string>();
  926. List<KeyValuePair<string, List<double>>> datas = new List<KeyValuePair<string, List<double>>>();
  927. //求单个知识点所占分数
  928. List<string> per = new List<string>();
  929. //List<string> gper = new List<string>();
  930. //List<string> knowPer = new List<string>();
  931. //Dictionary<string, object> wrongMap = new Dictionary<string, object>();
  932. List<List<string>> wrongPersent = new List<List<string>>();
  933. //定位试卷信息
  934. int index = 0;
  935. foreach (ExamSubject subject in info.subjects)
  936. {
  937. if (subject.id.Equals(exam.subjectId))
  938. {
  939. break;
  940. }
  941. else
  942. {
  943. index++;
  944. }
  945. }
  946. if (info.papers[index].knowledge != null && info.papers[index].knowledge.Count > 0)
  947. {
  948. info.papers[index].knowledge.ForEach(k =>
  949. {
  950. k.ForEach(e =>
  951. {
  952. knowledge.Add(e);
  953. });
  954. });
  955. }
  956. else
  957. {
  958. return (default, default, default, default, default, default);
  959. }
  960. point = info.papers[index].point;
  961. result = exam.studentScores;
  962. classes = exam.classes;
  963. //ids = exam.studentIds;
  964. //确定高分组 低分组人数
  965. List<List<double>> re = exam.studentScores;
  966. List<double> resultSum = new List<double>();
  967. foreach (List<double> data in re)
  968. {
  969. resultSum.Add(data.Sum());
  970. }
  971. //确定高分组 最低分数
  972. resultSum.Sort((s1, s2) => { return s2.CompareTo(s1); });
  973. double rhwCount = Math.Floor(resultSum.Count * 0.27);
  974. double rhw = rhwCount > 0 ? resultSum[int.Parse(rhwCount.ToString("0"))] : 0;
  975. double rhlCount = Math.Ceiling(resultSum.Count * 0.73);
  976. double rhl = rhlCount > 0 ? resultSum[int.Parse(rhlCount.ToString("0"))] : 0;
  977. //double rhl = resultSum[int.Parse(rhwCount.ToString("0"))];
  978. List<string> knowledgeName = new List<string>();
  979. foreach (string cla in knowledge)
  980. {
  981. knowledgeName.Add(cla);
  982. }
  983. for (int k = 0; k < knowledgeName.Count; k++)
  984. {
  985. if (null == knowledgeName[k])
  986. {
  987. knowledgeName.Remove(knowledgeName[k]);
  988. }
  989. }
  990. //初始化年级总分
  991. double total = 0;
  992. //处理年级单个知识点得分率
  993. foreach (List<double> grade in result)
  994. {
  995. total += grade.Sum();
  996. }
  997. //试卷总分
  998. double TotalPoint = point.Sum();
  999. List<double> knowScore = new List<double>();
  1000. //得分率
  1001. List<double> Score = new List<double>();
  1002. //分值
  1003. List<double> kScore = new List<double>();
  1004. for (int k = 0; k < knowledgeName.Count; k++)
  1005. {
  1006. double OnePoint = 0;
  1007. List<string> valuew = new List<string>();
  1008. List<string> itemNo = new List<string>();
  1009. keynowWrong.ForEach(x =>
  1010. {
  1011. valuew.Add("-");
  1012. });
  1013. valuew[0] = knowledgeName[k];
  1014. int n = 0;
  1015. int wrong = 0;
  1016. int rhwC = 0;
  1017. int rhlC = 0;
  1018. int scoreCount = 0;
  1019. double scores = 0;
  1020. //知识点分值
  1021. double gPoint = 0;
  1022. info.papers[index].knowledge.ForEach(kno =>
  1023. {
  1024. if (kno.Contains(knowledgeName[k]))
  1025. {
  1026. var itemPersent = kno.Count > 0 ? 1 / Convert.ToDouble(kno.Count) : 0;
  1027. OnePoint += point[n];
  1028. itemNo.Add((n + 1).ToString());
  1029. //处理单个知识点错题人数
  1030. int phCount = 0;
  1031. int plCount = 0;
  1032. foreach (string id in exam.studentIds)
  1033. {
  1034. int index = exam.studentIds.IndexOf(id);
  1035. if (exam.studentScores[index][n] == 0)
  1036. {
  1037. wrong++;
  1038. if (exam.studentScores[index].Sum() >= rhw && phCount < rhwCount)
  1039. {
  1040. rhwC++;
  1041. phCount++;
  1042. continue;
  1043. }
  1044. if (exam.studentScores[index].Sum() <= rhl && plCount < (exam.studentIds.Count - rhlCount))
  1045. {
  1046. rhlC++;
  1047. plCount++;
  1048. continue;
  1049. }
  1050. continue;
  1051. }
  1052. else
  1053. {
  1054. //单个知识点得分情况
  1055. scores += exam.studentScores[index][n] * itemPersent;
  1056. //scoreCount++;
  1057. }
  1058. /*if (exam.studentScores[index].Sum() >= rhw && phCount < rhwCount)
  1059. {
  1060. rhwC++;
  1061. phCount++;
  1062. continue;
  1063. }
  1064. if (exam.studentScores[index].Sum() <= rhl && plCount < (exam.studentIds.Count - rhlCount))
  1065. {
  1066. rhlC++;
  1067. plCount++;
  1068. continue;
  1069. }*/
  1070. }
  1071. gPoint += point[n];
  1072. }
  1073. valuew[1] = OnePoint.ToString();
  1074. string itemNos = "";
  1075. if (itemNo.Count > 0)
  1076. {
  1077. foreach (string np in itemNo)
  1078. {
  1079. itemNos += np + ",";
  1080. }
  1081. valuew[2] = itemNos[0..^1];
  1082. }
  1083. else
  1084. {
  1085. valuew[2] = itemNos;
  1086. }
  1087. n++;
  1088. });
  1089. kScore.Add(gPoint);
  1090. Score.Add(scores);
  1091. knowScore.Add(OnePoint);
  1092. //该知识点平均得分
  1093. double sc = exam.studentIds.Count > 0 ? Math.Round(scores * 1.0 / exam.studentIds.Count, 2) : 0;
  1094. //错题关系表
  1095. valuew[3] = (sc / OnePoint).ToString();
  1096. valuew[4] = wrong.ToString();
  1097. valuew[5] = rhwC.ToString();
  1098. valuew[6] = rhlC.ToString();
  1099. wrongPersent.Add(valuew);
  1100. //知识点占比
  1101. double persent = TotalPoint > 0 ? OnePoint / TotalPoint : 0;
  1102. //double persent = OnePoint / TotalPoint;
  1103. per.Add(persent.ToString("0.00"));
  1104. }
  1105. //本次考试知识点占比
  1106. List<double> allPer = new List<double>();
  1107. foreach (double sc in Score)
  1108. {
  1109. allPer.Add(exam.studentIds.Count > 0 ? Math.Round(sc * 1.0 / exam.studentIds.Count, 2) : 0);
  1110. }
  1111. int stuNo = 0;
  1112. exam.studentIds.ForEach(e =>
  1113. {
  1114. List<double> valueKnow = new List<double>();
  1115. foreach (string know in knowledge)
  1116. {
  1117. double anwPoint = 0;
  1118. double itemPersent = 0;
  1119. int sno = 0;
  1120. info.papers[index].knowledge.ForEach(kno =>
  1121. {
  1122. if (kno.Contains(know))
  1123. {
  1124. //当前知识点在该题占比多少
  1125. itemPersent = kno.Count > 0 ? 1 / Convert.ToDouble(kno.Count) : 0;
  1126. //itemPersent = 1 / Convert.ToDouble(kno.Count);
  1127. anwPoint += result[stuNo][sno] * itemPersent;
  1128. }
  1129. sno++;
  1130. });
  1131. valueKnow.Add(anwPoint);
  1132. }
  1133. KeyValuePair<string, List<double>> keyValue = new KeyValuePair<string, List<double>>(e, valueKnow);
  1134. datas.Add(keyValue);
  1135. stuNo++;
  1136. });
  1137. KeyValuePair<string, List<string>> key1 = new KeyValuePair<string, List<string>>(exam.subjectId, knowledgeName);
  1138. KeyValuePair<string, List<string>> key2 = new KeyValuePair<string, List<string>>(exam.subjectId, per);
  1139. KeyValuePair<string, List<double>> key3 = new KeyValuePair<string, List<double>>(exam.subjectId, allPer);
  1140. KeyValuePair<string, List<double>> key4 = new KeyValuePair<string, List<double>>(exam.subjectId, kScore);
  1141. KeyValuePair<string, List<List<string>>> keyValue = new KeyValuePair<string, List<List<string>>>(exam.subjectId, wrongPersent);
  1142. KeyValuePair<string, List<KeyValuePair<string, List<double>>>> valuePair = new KeyValuePair<string, List<KeyValuePair<string, List<double>>>>(exam.subjectId, datas);
  1143. return (key1, key2, key3, key4, keyValue, valuePair);
  1144. }
  1145. 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)
  1146. {
  1147. List<double> point = new List<double>();
  1148. List<List<double>> result = new List<List<double>>();
  1149. List<ClassRange> classes = new List<ClassRange>();
  1150. List<KeyValuePair<string, List<double>>> datas = new List<KeyValuePair<string, List<double>>>();
  1151. //求单个认知层次所占分数
  1152. List<string> per = new List<string>();
  1153. List<List<string>> wrongPersent = new List<List<string>>();
  1154. List<int> knowledgeName = new List<int>();
  1155. //定位试卷信息
  1156. int index = 0;
  1157. foreach (ExamSubject subject in info.subjects)
  1158. {
  1159. if (subject.id.Equals(exam.subjectId))
  1160. {
  1161. break;
  1162. }
  1163. else
  1164. {
  1165. index++;
  1166. }
  1167. }
  1168. knowledgeName.Add(1);
  1169. knowledgeName.Add(2);
  1170. knowledgeName.Add(3);
  1171. knowledgeName.Add(4);
  1172. knowledgeName.Add(5);
  1173. knowledgeName.Add(6);
  1174. //double Qnum = 0;
  1175. point = info.papers[index].point;
  1176. result = exam.studentScores;
  1177. classes = exam.classes;
  1178. //ids = exam.studentIds;
  1179. //确定高分组 低分组人数
  1180. List<List<double>> re = exam.studentScores;
  1181. List<double> resultSum = new List<double>();
  1182. foreach (List<double> data in re)
  1183. {
  1184. resultSum.Add(data.Sum());
  1185. }
  1186. //确定高分组 最低分数
  1187. resultSum.Sort((s1, s2) => { return s2.CompareTo(s1); });
  1188. double rhwCount = Math.Floor(resultSum.Count * 0.27);
  1189. double rhw = rhwCount > 0 ? resultSum[int.Parse(rhwCount.ToString("0"))] : 0;
  1190. double rhlCount = Math.Ceiling(resultSum.Count * 0.73);
  1191. double rhl = rhlCount > 0 ? resultSum[int.Parse(rhlCount.ToString("0"))] : 0;
  1192. //初始化年级总分
  1193. double total = 0;
  1194. //处理年级单个知识点得分率
  1195. foreach (List<double> grade in result)
  1196. {
  1197. total += grade.Sum();
  1198. }
  1199. //试卷总分
  1200. double TotalPoint = point.Sum();
  1201. List<double> knowScore = new List<double>();
  1202. //得分率
  1203. List<double> Score = new List<double>();
  1204. //分值
  1205. List<double> kScore = new List<double>();
  1206. //List<double> allPer = new List<double>();
  1207. for (int k = 0; k < knowledgeName.Count; k++)
  1208. {
  1209. double OnePoint = 0;
  1210. List<string> valuew = new List<string>();
  1211. List<string> itemNo = new List<string>();
  1212. keynowWrong.ForEach(x =>
  1213. {
  1214. valuew.Add("-");
  1215. });
  1216. valuew[0] = knowledgeName[k].ToString();
  1217. int n = 0;
  1218. int wrong = 0;
  1219. int rhwC = 0;
  1220. int rhlC = 0;
  1221. //int scoreCount = 0;
  1222. double scores = 0;
  1223. //所有认知层次得分
  1224. double anwGPoint = 0;
  1225. double gPoint = 0;
  1226. info.papers[index].field.ForEach(kno =>
  1227. {
  1228. if (kno == knowledgeName[k])
  1229. {
  1230. OnePoint += point[n];
  1231. itemNo.Add((n + 1).ToString());
  1232. //处理认知层次错题人数
  1233. int phCount = 0;
  1234. int plCount = 0;
  1235. foreach (string id in exam.studentIds)
  1236. {
  1237. int index = exam.studentIds.IndexOf(id);
  1238. if (exam.studentScores[index][n] == 0)
  1239. {
  1240. wrong++;
  1241. if (exam.studentScores[index].Sum() >= rhw && phCount < rhwCount)
  1242. {
  1243. rhwC++;
  1244. phCount++;
  1245. continue;
  1246. }
  1247. if (exam.studentScores[index].Sum() <= rhl && plCount < (exam.studentIds.Count - rhlCount))
  1248. {
  1249. rhlC++;
  1250. plCount++;
  1251. continue;
  1252. }
  1253. continue;
  1254. }
  1255. else
  1256. {
  1257. //单个认知层次得分情况
  1258. scores += exam.studentScores[index][n];
  1259. }
  1260. /* if (exam.studentScores[index].Sum() >= rhw && phCount < rhwCount && exam.studentScores[index][n] == 0)
  1261. {
  1262. rhwC++;
  1263. phCount++;
  1264. continue;
  1265. }
  1266. if (exam.studentScores[index].Sum() <= rhl && plCount < (exam.studentIds.Count - rhlCount) && exam.studentScores[index][n] == 0)
  1267. {
  1268. rhlC++;
  1269. plCount++;
  1270. continue;
  1271. }*/
  1272. //anwGPoint += exam.studentScores[index][n];
  1273. }
  1274. gPoint += point[n];
  1275. }
  1276. valuew[1] = OnePoint.ToString();
  1277. string itemNos = "";
  1278. if (itemNo.Count > 0)
  1279. {
  1280. foreach (string np in itemNo)
  1281. {
  1282. itemNos += np + ",";
  1283. }
  1284. valuew[2] = itemNos[0..^1];
  1285. }
  1286. else
  1287. {
  1288. valuew[2] = itemNos;
  1289. }
  1290. n++;
  1291. });
  1292. Score.Add(scores);
  1293. kScore.Add(gPoint);
  1294. knowScore.Add(OnePoint);
  1295. double sc = exam.studentIds.Count > 0 ? Math.Round(scores * 1.0 / exam.studentIds.Count, 2) : 0;
  1296. //错题关系表
  1297. valuew[3] = (OnePoint > 0 ? Math.Round(sc / OnePoint, 2) : 0).ToString();
  1298. valuew[4] = wrong.ToString();
  1299. valuew[5] = rhwC.ToString();
  1300. valuew[6] = rhlC.ToString();
  1301. wrongPersent.Add(valuew);
  1302. //认知层次占比
  1303. double persent = TotalPoint > 0 ? OnePoint / TotalPoint : 0;
  1304. //allPer.Add(OnePoint > 0 ? Math.Round(sc / OnePoint, 2) : 0);
  1305. per.Add(persent.ToString("0.00"));
  1306. }
  1307. //本次考试认知层次占比
  1308. List<double> allPer = new List<double>();
  1309. foreach (double sc in Score)
  1310. {
  1311. allPer.Add(exam.studentIds.Count > 0 ? Math.Round(sc * 1.0 / exam.studentIds.Count, 2) : 0);
  1312. }
  1313. int stuNo = 0;
  1314. exam.studentIds.ForEach(e =>
  1315. {
  1316. List<double> valueKnow = new List<double>();
  1317. foreach (int know in knowledgeName)
  1318. {
  1319. double anwPoint = 0;
  1320. double itemPersent = 0;
  1321. int sno = 0;
  1322. info.papers[index].field.ForEach(kno =>
  1323. {
  1324. if (kno == know)
  1325. {
  1326. //当前认知层次在该题占比多少
  1327. itemPersent = 1;
  1328. anwPoint += result[stuNo][sno] * itemPersent;
  1329. }
  1330. sno++;
  1331. });
  1332. valueKnow.Add(anwPoint);
  1333. }
  1334. KeyValuePair<string, List<double>> keyValue = new KeyValuePair<string, List<double>>(e, valueKnow);
  1335. datas.Add(keyValue);
  1336. stuNo++;
  1337. });
  1338. KeyValuePair<string, List<int>> key1 = new KeyValuePair<string, List<int>>(exam.subjectId, knowledgeName);
  1339. KeyValuePair<string, List<string>> key2 = new KeyValuePair<string, List<string>>(exam.subjectId, per);
  1340. KeyValuePair<string, List<double>> key3 = new KeyValuePair<string, List<double>>(exam.subjectId, allPer);
  1341. KeyValuePair<string, List<double>> key4 = new KeyValuePair<string, List<double>>(exam.subjectId, kScore);
  1342. KeyValuePair<string, List<List<string>>> keyValue = new KeyValuePair<string, List<List<string>>>(exam.subjectId, wrongPersent);
  1343. KeyValuePair<string, List<KeyValuePair<string, List<double>>>> valuePair = new KeyValuePair<string, List<KeyValuePair<string, List<double>>>>(exam.subjectId, datas);
  1344. return (key1, key2, key3, key4, keyValue, valuePair);
  1345. }
  1346. [HttpPost("simple")]
  1347. public async Task<IActionResult> simple(JsonElement request)
  1348. {
  1349. //获取评测的ID
  1350. if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
  1351. if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
  1352. try
  1353. {
  1354. List<Dictionary<string, object>> averageMap = new List<Dictionary<string, object>>();
  1355. List<Dictionary<string, object>> averageTotal = new List<Dictionary<string, object>>();
  1356. var client = _azureCosmos.GetCosmosClient();
  1357. ExamInfo info = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"Exam-{code}"));
  1358. List<ExamResult> examResults = new List<ExamResult>();
  1359. var query = $"select c.id,c.name,c.subjectId,c.studentScores,c.studentIds,c.paper,c.classes from c where c.examId = '{id}' ";
  1360. await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<ExamResult>(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamResult-{id}") }))
  1361. {
  1362. examResults.Add(item);
  1363. }
  1364. foreach (ExamResult result in examResults)
  1365. {
  1366. List<double> ClassAverage = new List<double>();
  1367. List<ClassSimple> ClassName = new List<ClassSimple>();
  1368. Dictionary<string, object> mapSubject = new Dictionary<string, object>();
  1369. Dictionary<string, object> mapClass = new Dictionary<string, object>();
  1370. mapClass.Add("subjectId", result.subjectId);
  1371. foreach (ClassRange range in result.classes)
  1372. {
  1373. ClassSimple classSimple = new ClassSimple();
  1374. classSimple.id = range.id;
  1375. classSimple.name = range.name;
  1376. ClassName.Add(classSimple);
  1377. double totalClass = 0;
  1378. for (int i = range.range[0]; i <= range.range[1]; i++)
  1379. {
  1380. totalClass += result.studentScores[i].Sum();
  1381. }
  1382. ClassAverage.Add(range.range[1] - range.range[0] + 1 > 0 ? totalClass * 1.0 / (range.range[1] - range.range[0] + 1) : 0);
  1383. }
  1384. mapClass.Add("className", ClassName);
  1385. mapClass.Add("ClassAverage", ClassAverage);
  1386. averageMap.Add(mapClass);
  1387. List<double> SubjectTotal = new List<double>();
  1388. foreach (List<double> score in result.studentScores)
  1389. {
  1390. SubjectTotal.Add(score.Sum());
  1391. }
  1392. mapSubject.Add("subjectId", result.subjectId);
  1393. mapSubject.Add("total", SubjectTotal);
  1394. averageTotal.Add(mapSubject);
  1395. }
  1396. return Ok(new { averageMap, averageTotal });
  1397. }
  1398. catch (Exception e)
  1399. {
  1400. await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/simple()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
  1401. return BadRequest();
  1402. }
  1403. }
  1404. public class ClassSimple
  1405. {
  1406. public string id { get; set; }
  1407. public string name { get; set; }
  1408. }
  1409. [HttpPost("studentAnalysis")]
  1410. public async Task<IActionResult> studentAnalysis(JsonElement request)
  1411. {
  1412. //获取个人或者校本
  1413. if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
  1414. //评测Id
  1415. if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
  1416. if (!request.TryGetProperty("sId", out JsonElement sId)) return BadRequest();
  1417. if (!request.TryGetProperty("cId", out JsonElement cId)) return BadRequest();
  1418. if (!request.TryGetProperty("gId", out JsonElement gId)) return BadRequest();
  1419. try
  1420. {
  1421. List<Dictionary<string, object>> averageMap = new();
  1422. List<Dictionary<string, object>> averageTotal = new();
  1423. List<List<double>> classAllAverage = new();
  1424. School school = new();
  1425. var client = _azureCosmos.GetCosmosClient();
  1426. ExamInfo info = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"Exam-{code}"));
  1427. var response = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(code.ToString(), new PartitionKey($"Base"));
  1428. if (response.Status == 200)
  1429. {
  1430. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  1431. school = json.ToObject<School>();
  1432. }
  1433. //School school = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<School>(code.ToString(), new PartitionKey($"Base"));
  1434. List<ExamResult> examResults = new List<ExamResult>();
  1435. var query = $"select c.id,c.name,c.subjectId,c.studentScores,c.studentIds,c.paper,c.classes from c where c.examId = '{id}' ";
  1436. await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<ExamResult>(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamResult-{id}") }))
  1437. {
  1438. examResults.Add(item);
  1439. }
  1440. if (examResults.Count == 0)
  1441. {
  1442. return Ok(new { code = ResponseCode.DATA_EMPTY_NULL, v = "正在结算中" });
  1443. }
  1444. int indexClass = 0;
  1445. HashSet<string> cla = new HashSet<string>();
  1446. HashSet<string> stu = new HashSet<string>();
  1447. double totalScore = 0;
  1448. List<List<double>> allList = new List<List<double>>();
  1449. double income = 0;
  1450. foreach (Period period in school.period)
  1451. {
  1452. if (info.period.id.Equals(period.id))
  1453. {
  1454. income = period.analysis.income;
  1455. }
  1456. }
  1457. //获取进线人数
  1458. int count = (int)System.Math.Round(info.stuCount * (income / 100.0), MidpointRounding.AwayFromZero);
  1459. foreach (ExamResult result in examResults)
  1460. {
  1461. List<double> ClassAverage = new List<double>();
  1462. List<int> personCount = new List<int>();
  1463. List<string> ClassId = new List<string>();
  1464. Dictionary<string, object> mapClass = new Dictionary<string, object>();
  1465. int index = result.studentIds.IndexOf(sId.ToString());
  1466. //个人总分
  1467. totalScore += result.studentScores[index].Sum();
  1468. mapClass.Add("subjectId", result.subjectId);
  1469. double totalGrade = 0;
  1470. List<double> gradeScores = new List<double>();
  1471. List<List<double>> classScores = new List<List<double>>();
  1472. //此处声明集合存储原本的成绩序列
  1473. List<List<double>> cScores = new List<List<double>>();
  1474. /*var sc = result.classes.GroupBy(m => new { m.gradeId }).Select(c => new { gId = c.Key.gradeId, ranges = c.ToList() }).ToList();
  1475. foreach (var aa in sc)
  1476. {
  1477. foreach (ClassRange range in aa.ranges)
  1478. {
  1479. List<double> scores = new();
  1480. List<double> finalScores = new();
  1481. ClassId.Add(range.id);
  1482. cla.Add(range.id);
  1483. double totalClass = 0;
  1484. for (int i = range.range[0]; i <= range.range[1]; i++)
  1485. {
  1486. totalClass += result.studentScores[i].Sum();
  1487. scores.Add(result.studentScores[i].Sum());
  1488. finalScores.Add(result.studentScores[i].Sum());
  1489. gradeScores.Add(result.studentScores[i].Sum());
  1490. totalGrade += result.studentScores[i].Sum();
  1491. stu.Add(result.studentIds[i]);
  1492. }
  1493. classScores.Add(scores);
  1494. cScores.Add(finalScores);
  1495. ClassAverage.Add(range.range[1] - range.range[0] + 1 > 0 ? Math.Round(totalClass * 1.0 / (range.range[1] - range.range[0] + 1), 2) : 0);
  1496. personCount.Add(range.range[1] - range.range[0] + 1);
  1497. }
  1498. classAllAverage.Add(ClassAverage);
  1499. gradeScores.Sort((s1, s2) => { return s2.CompareTo(s1); });
  1500. indexClass = ClassId.IndexOf(cId.ToString());
  1501. //单科成绩
  1502. allList.Add(cScores[indexClass]);
  1503. classScores[indexClass].Sort((s1, s2) => { return s2.CompareTo(s1); });
  1504. mapClass.Add("scoreSum", result.paper.point.Sum());
  1505. mapClass.Add("score", result.studentScores[index].Sum());
  1506. mapClass.Add("classAverage", ClassAverage[indexClass]);
  1507. mapClass.Add("classCount", personCount[indexClass]);
  1508. mapClass.Add("classRank", classScores[indexClass].IndexOf(result.studentScores[index].Sum()));
  1509. mapClass.Add("gradeAverage", result.studentIds.Count > 0 ? Math.Round(totalGrade * 1.0 / result.studentIds.Count, 2) : 0);
  1510. mapClass.Add("gradeCount", result.studentIds.Count);
  1511. mapClass.Add("gradeRank", gradeScores.IndexOf(result.studentScores[index].Sum()));
  1512. averageMap.Add(mapClass);
  1513. }
  1514. */
  1515. foreach (ClassRange range in result.classes)
  1516. {
  1517. List<double> scores = new List<double>();
  1518. List<double> finalScores = new List<double>();
  1519. ClassId.Add(range.id);
  1520. cla.Add(range.id);
  1521. double totalClass = 0;
  1522. for (int i = range.range[0]; i <= range.range[1]; i++)
  1523. {
  1524. totalClass += result.studentScores[i].Sum();
  1525. scores.Add(result.studentScores[i].Sum());
  1526. finalScores.Add(result.studentScores[i].Sum());
  1527. gradeScores.Add(result.studentScores[i].Sum());
  1528. totalGrade += result.studentScores[i].Sum();
  1529. stu.Add(result.studentIds[i]);
  1530. }
  1531. classScores.Add(scores);
  1532. cScores.Add(finalScores);
  1533. ClassAverage.Add(range.range[1] - range.range[0] + 1 > 0 ? Math.Round(totalClass * 1.0 / (range.range[1] - range.range[0] + 1), 2) : 0);
  1534. personCount.Add(range.range[1] - range.range[0] + 1);
  1535. }
  1536. }
  1537. //处理班级/年级全科均分
  1538. List<double> AllAverage = new List<double>();
  1539. double a = 0;
  1540. for (int k = 0; k < cla.Count; k++)
  1541. {
  1542. for (int i = 0; i < classAllAverage.Count; i++)
  1543. {
  1544. a += classAllAverage[i][k];
  1545. }
  1546. AllAverage.Add(a);
  1547. }
  1548. List<double> classScore = new List<double>();
  1549. for (int i = 0; i < allList[0].Count; i++)
  1550. {
  1551. double b = 0;
  1552. for (int m = 0; m < allList.Count; m++)
  1553. {
  1554. b += allList[m][i];
  1555. }
  1556. classScore.Add(b);
  1557. }
  1558. classScore.Sort((s1, s2) => { return s2.CompareTo(s1); });
  1559. //处理年级总分以及排名
  1560. List<double> GradeScore = new List<double>();
  1561. foreach (string ss in stu)
  1562. {
  1563. double score = 0;
  1564. foreach (ExamResult result in examResults)
  1565. {
  1566. int index = result.studentIds.IndexOf(ss);
  1567. score += result.studentScores[index].Sum();
  1568. }
  1569. GradeScore.Add(score);
  1570. }
  1571. GradeScore.Sort((s1, s2) => { return s2.CompareTo(s1); });
  1572. double ipoint = GradeScore[count];
  1573. 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 }); ;
  1574. }
  1575. catch (Exception e)
  1576. {
  1577. await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/studentAnalysis()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
  1578. return BadRequest();
  1579. }
  1580. }
  1581. }
  1582. }