AnalysisController.cs 90 KB

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