AnalysisController.cs 89 KB

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