ArtService.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. using Azure.Cosmos;
  2. using Azure.Messaging.ServiceBus;
  3. using HTEXLib.COMM.Helpers;
  4. using Microsoft.AspNetCore.Hosting;
  5. using Microsoft.Extensions.Configuration;
  6. using Microsoft.Extensions.Hosting;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Text.Json;
  13. using System.Threading.Tasks;
  14. using TEAMModelOS.SDK.DI;
  15. using TEAMModelOS.SDK.Extension;
  16. using TEAMModelOS.SDK.Models.Cosmos.Common;
  17. namespace TEAMModelOS.SDK.Models.Service
  18. {
  19. public static class ArtService
  20. {
  21. public static List<ArtQuota> GetParentByChildId(List<ArtQuota> quotas, string childId) {
  22. List<ArtQuota> list_quotas = new List<ArtQuota>();
  23. list_quotas = TreeToList(quotas, list_quotas, null);
  24. List<ArtQuota> parents = new List<ArtQuota>();
  25. parents = GetParents(list_quotas, parents, $"{childId}");
  26. if (parents.IsNotEmpty()) {
  27. int len = parents.Count;
  28. parents.ForEach(x => {
  29. x.level= len-x.level+1;
  30. });
  31. }
  32. return parents;
  33. }
  34. private static List<ArtQuota> GetParents(List<ArtQuota> list, List<ArtQuota> parents, string cid, int level = 1)
  35. {
  36. var child = list.Find(x => x.id.Equals(cid));
  37. if (child != null)
  38. {
  39. child.level = level;
  40. parents.Add(child);
  41. if (!child.pid.Equals(child.id))
  42. {
  43. level++;
  44. return GetParents(list, parents, child.pid, level);
  45. }
  46. else
  47. {
  48. return parents;
  49. }
  50. }
  51. else { return parents; }
  52. }
  53. private static List<ArtQuota> TreeToList(List<ArtQuota> trees, List<ArtQuota> nodes, string pid)
  54. {
  55. List<ArtQuota> list = new List<ArtQuota>();
  56. trees.ForEach(x => {
  57. var node = new ArtQuota
  58. {
  59. pid = string.IsNullOrWhiteSpace(pid) ? x.id : pid,
  60. id = x.id,
  61. name = x.name,
  62. percent = x.percent,
  63. type = x.type,
  64. };
  65. list.Add(node);
  66. });
  67. nodes.AddRange(list);
  68. foreach (ArtQuota tree in trees)
  69. {
  70. if (tree.children.IsNotEmpty())
  71. {
  72. TreeToList(tree.children, nodes, tree.id);
  73. }
  74. }
  75. return nodes;
  76. }
  77. public async static Task<List<ArtStudentPdf>> GenArtPDF(List<StudentArtResult> artResults,string _artId,string _schoolId,string head_lang ,AzureCosmosFactory _azureCosmos,
  78. IWebHostEnvironment _environment, CoreAPIHttpService _coreAPIHttpService, DingDing _dingDing, AzureServiceBusFactory _serviceBus, IConfiguration _configuration) {
  79. var client = _azureCosmos.GetCosmosClient();
  80. School school = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<School>($"{_schoolId}", new PartitionKey("Base"));
  81. string path = Path.Combine(_environment.ContentRootPath, $"Lang/{head_lang}.json");
  82. string comment1 = "";
  83. string comment2 = "";
  84. string comment3 = "";
  85. string comment4 = "";
  86. string comment5 = "";
  87. string comment_subject_music = "";
  88. string comment_subject_painting = "";
  89. var jsonDoc = readFileJson(path);
  90. if (jsonDoc != null)
  91. {
  92. if (jsonDoc.RootElement.TryGetProperty("art-template-comment1", out JsonElement _c1))
  93. {
  94. comment1 = $"{_c1}";
  95. }
  96. if (jsonDoc.RootElement.TryGetProperty("art-template-comment2", out JsonElement _c2))
  97. {
  98. comment2 = $"{_c2}";
  99. }
  100. if (jsonDoc.RootElement.TryGetProperty("art-template-comment3", out JsonElement _c3))
  101. {
  102. comment3 = $"{_c3}";
  103. }
  104. if (jsonDoc.RootElement.TryGetProperty("art-template-comment4", out JsonElement _c4))
  105. {
  106. comment4 = $"{_c4}";
  107. }
  108. if (jsonDoc.RootElement.TryGetProperty("art-template-comment5", out JsonElement _c5))
  109. {
  110. comment5 = $"{_c5}";
  111. }
  112. if (jsonDoc.RootElement.TryGetProperty("art-template-subject_music", out JsonElement _subject_music))
  113. {
  114. comment_subject_music = $"{_subject_music}";
  115. }
  116. if (jsonDoc.RootElement.TryGetProperty("art-template-subject_painting", out JsonElement _subject_painting))
  117. {
  118. comment_subject_painting = $"{_subject_painting}";
  119. }
  120. }
  121. ArtEvaluation art = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ArtEvaluation>($"{_artId}", new PartitionKey($"Art-{_schoolId}"));
  122. ArtSetting artSetting = await client.GetContainer(Constant.TEAMModelOS, Constant.Normal).ReadItemAsync<ArtSetting>($"{school.areaId}", new PartitionKey($"ArtSetting"));
  123. var allExamIds = art.settings.SelectMany(x => x.task).Where(z => z.type == 1);
  124. var subjects = art.subjects;
  125. //获取学校的所有艺术科目的uuid,并映射找到相应的知识点,知识块。
  126. var schoolSubjects = school.period.SelectMany(x => x.subjects).Where(s => !string.IsNullOrWhiteSpace(s.bindId) && subjects.Select(z => z.id).Contains(s.bindId));
  127. StringBuilder sql = new StringBuilder($"select value(c) from c");
  128. List<KeyValuePair<string, List<Block>>> subjectBindBlocks = new List<KeyValuePair<string, List<Block>>>();
  129. foreach (var schSub in schoolSubjects)
  130. {
  131. List<Block> blocks = new List<Block>();
  132. string code = $"Knowledge-{_schoolId}-{schSub.id}";
  133. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School")
  134. .GetItemQueryIterator<Knowledge>(queryText: sql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
  135. {
  136. item.blocks.ForEach(x =>
  137. {
  138. var block = blocks.Find(z => z.name.Equals(x.name));
  139. if (block != null)
  140. {
  141. block.points.AddRange(x.points);
  142. }
  143. else
  144. {
  145. blocks.Add(x);
  146. }
  147. });
  148. }
  149. subjectBindBlocks.Add(new KeyValuePair<string, List<Block>>(schSub.bindId, blocks));
  150. }
  151. List<ExamInfo> exams = new List<ExamInfo>();
  152. List<ExamResult> examResults = new();
  153. if (allExamIds.Any())
  154. {
  155. var queryExam = $"select value c from c where c.id in ({string.Join(",", allExamIds.Select(x => $"'{x.acId}'"))}) ";
  156. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<ExamInfo>(queryText: queryExam, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Exam-{_schoolId}") }))
  157. {
  158. exams.Add(item);
  159. }
  160. foreach (var allexamId in allExamIds)
  161. {
  162. var queryResult = $"select c.id,c.name,c.subjectId,c.studentScores,c.studentIds,c.paper,c.classes,c.sRate,c.average,c.standard,c.lostStus,c.record,c.phc,c.plc,c.examId from c where c.examId = '{allexamId.acId}' and c.subjectId = '{allexamId.subject}' ";
  163. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<ExamResult>(queryText: queryResult, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamResult-{allexamId.acId}") }))
  164. {
  165. examResults.Add(item);
  166. }
  167. }
  168. }
  169. (List<RMember> rmembers, List<RGroupList> groups) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, art.classes, art.school);
  170. List<ArtStudentPdf> studentPdfs = new List<ArtStudentPdf>();
  171. artResults.ForEach(x =>
  172. {
  173. var allSubject = x.results.GroupBy(g => g.quotaId).Select(s => new { key = s.Key, list = s.ToList() }).ToList();
  174. var groupSubject = x.results.GroupBy(g => $"{g.quotaId}-{g.subjectId}").Select(s => new { key = s.Key, list = s.ToList() }).ToList();
  175. //综合-所有科目的艺术评测指标维度。
  176. List<ArtQuotaPdf> allSubjectArtQuotaPdfs = new List<ArtQuotaPdf>();
  177. allSubject.ForEach(a =>
  178. {
  179. ArtQuotaPdf artPdf = new ArtQuotaPdf();
  180. List<ArtQuota> parents = ArtService.GetParentByChildId(artSetting.quotas, $"{a.key}");
  181. parents.ForEach(x =>
  182. {
  183. switch (true)
  184. {
  185. case bool when x.level == 1:
  186. artPdf.quota1 = x.id;
  187. artPdf.quotaN1 = x.name;
  188. artPdf.quotaP1 = x.percent;
  189. if (a.key.Equals(x.id))
  190. {
  191. artPdf.quotaName = x.name;
  192. }
  193. break;
  194. case bool when x.level == 2:
  195. artPdf.quota2 = x.id;
  196. artPdf.quotaN2 = x.name;
  197. artPdf.quotaP2 = x.percent;
  198. if (a.key.Equals(x.id))
  199. {
  200. artPdf.quotaName = x.name;
  201. }
  202. break;
  203. case bool when x.level == 3:
  204. artPdf.quota3 = x.id;
  205. artPdf.quotaN3 = x.name;
  206. artPdf.quotaP3 = x.percent;
  207. if (a.key.Equals(x.id))
  208. {
  209. artPdf.quotaName = x.name;
  210. }
  211. break;
  212. }
  213. });
  214. var noneScore = a.list.FindAll(x => x.score == -1);
  215. if (!noneScore.IsNotEmpty())
  216. {
  217. //全部未打分。
  218. if (noneScore.Count >= art.subjects.Count)
  219. {
  220. artPdf.quotaId = a.key;
  221. artPdf.score = 0;
  222. artPdf.scoreData = "-";
  223. artPdf.percent = "0";
  224. }
  225. else
  226. {
  227. //有一部分打分的,只算有分的平均分。
  228. var hasScore = a.list.FindAll(x => x.score >= 0);
  229. if (hasScore.IsNotEmpty())
  230. {
  231. var avgScore = hasScore.Sum(x => x.score) * 1.0 / a.list.Count;
  232. var avg = decimal.Round(decimal.Parse($"{avgScore}"), 2);
  233. artPdf.quotaId = a.key;
  234. artPdf.score = double.Parse($"{avg}");
  235. artPdf.scoreData = $"{avg}";
  236. artPdf.percent = $"{avg}";
  237. }
  238. else
  239. {
  240. artPdf.quotaId = a.key;
  241. artPdf.score = 0;
  242. artPdf.scoreData = "-";
  243. artPdf.percent = "0";
  244. }
  245. }
  246. }
  247. else
  248. {
  249. artPdf.quotaId = a.key;
  250. artPdf.score = 0;
  251. artPdf.scoreData = "-";
  252. artPdf.percent = "0";
  253. }
  254. allSubjectArtQuotaPdfs.Add(artPdf);
  255. });
  256. string level = "";
  257. double allScore = 0;
  258. if (allSubjectArtQuotaPdfs.Any())
  259. {
  260. allScore = allSubjectArtQuotaPdfs.Sum(a => a.score) / allSubjectArtQuotaPdfs.Count;
  261. }
  262. if (allScore >= 100)
  263. {
  264. allScore = 100;
  265. level = "优秀(A+)";
  266. }
  267. if (allScore <= 0)
  268. {
  269. allScore = 0;
  270. level = "待及格(D)";
  271. }
  272. if (allScore < 100)
  273. {
  274. artSetting.reviewLevel.ForEach(r =>
  275. {
  276. if (r.value[0] <= allScore && r.value[1] > allScore)
  277. {
  278. level = r.code;
  279. }
  280. });
  281. }
  282. var rmbs = rmembers.FindAll(r => r.id.Equals(x.studentId) && r.type == 2 && x.code.Equals(x.school));
  283. if (rmbs.IsNotEmpty())
  284. {
  285. x.studentName = rmbs[0].name;
  286. }
  287. List<string> classNames = new List<string>();
  288. HashSet<string> periodIds = new HashSet<string>();
  289. x.classIds.ForEach(c =>
  290. {
  291. var gps = groups.FindAll(g => g.id.Equals(c));
  292. if (gps.IsNotEmpty())
  293. {
  294. classNames.Add(gps[0].name);
  295. if (!string.IsNullOrWhiteSpace(gps[0].periodId))
  296. {
  297. periodIds.Add(gps[0].periodId);
  298. }
  299. }
  300. });
  301. allSubjectArtQuotaPdfs.ForEach(x => x.level = level);
  302. var allSubjectQuotas = allSubjectArtQuotaPdfs.OrderBy(o => o.quota1).ThenBy(o => o.quota2).ThenBy(o => o.quota3);
  303. StringBuilder comment = new StringBuilder();
  304. switch (true)
  305. {
  306. case bool when level.Contains("(A+)"):
  307. comment.Append(comment1.Replace("{studentName}", x.studentName).Replace("{level}", "表现优异"));
  308. break;
  309. case bool when level.Contains("(A)"):
  310. comment.Append(comment1.Replace("{studentName}", x.studentName).Replace("{level}", "表现优秀"));
  311. break;
  312. case bool when level.Contains("(B+)"):
  313. comment.Append(comment1.Replace("{studentName}", x.studentName).Replace("{level}", "表现优良"));
  314. break;
  315. case bool when level.Contains("(B)"):
  316. comment.Append(comment1.Replace("{studentName}", x.studentName).Replace("{level}", "表现良好"));
  317. break;
  318. case bool when level.Contains("(C+)"):
  319. comment.Append(comment1.Replace("{studentName}", x.studentName).Replace("{level}", "还需加强"));
  320. break;
  321. case bool when level.Contains("(C)"):
  322. comment.Append(comment1.Replace("{studentName}", x.studentName).Replace("{level}", "有待提高"));
  323. break;
  324. case bool when level.Contains("(D)"):
  325. comment.Append(comment1.Replace("{studentName}", x.studentName).Replace("{level}", "还需努力"));
  326. break;
  327. }
  328. var score80 = allSubjectArtQuotaPdfs.Where(x => x.score >= 80);
  329. if (score80.Any())
  330. {
  331. List<string> quota = new List<string>();
  332. var quota3s = score80.Where(c => !string.IsNullOrWhiteSpace(c.quota3)).Select(z => z.quotaN3);
  333. if (quota3s.Any())
  334. {
  335. quota.AddRange(quota3s);
  336. }
  337. var quota2s = score80.Where(c => string.IsNullOrWhiteSpace(c.quota3) && !string.IsNullOrWhiteSpace(c.quota2)).Select(z => z.quotaN2);
  338. if (quota2s.Any())
  339. {
  340. quota.AddRange(quota2s);
  341. }
  342. comment.Append(comment2.Replace("{quotasHigh}", string.Join("、", quota)));
  343. }
  344. var score60 = allSubjectArtQuotaPdfs.Where(x => x.score < 60);
  345. if (score60.Any())
  346. {
  347. List<string> quota = new List<string>();
  348. var quota3s = score60.Where(c => !string.IsNullOrWhiteSpace(c.quota3)).Select(z => z.quotaN3);
  349. if (quota3s.Any())
  350. {
  351. quota.AddRange(quota3s);
  352. }
  353. var quota2s = score60.Where(c => string.IsNullOrWhiteSpace(c.quota3) && !string.IsNullOrWhiteSpace(c.quota2)).Select(z => z.quotaN2);
  354. if (quota2s.Any())
  355. {
  356. quota.AddRange(quota2s);
  357. }
  358. comment.Append(comment3.Replace("{quotasLow}", string.Join("、", quota)));
  359. }
  360. string periodId = "";
  361. string periodName = "";
  362. if (periodIds.Any())
  363. {
  364. var ps = school.period.FindAll(x => periodIds.Contains(x.id));
  365. if (ps.Any())
  366. {
  367. periodName = String.Join(",", ps.Select(x => x.name));
  368. periodId = String.Join(",", ps.Select(x => x.id));
  369. }
  370. }
  371. List<ArtSubjectPdf> subjectPdfs = new List<ArtSubjectPdf>();
  372. exams.ForEach(exam => {
  373. var result = examResults.FindAll(e => e.examId.Equals(exam.id));
  374. if (result.Any())
  375. {
  376. var datas = DoKnowledgePoint(result.First(), exam, x.studentId);
  377. if (exam.subjects.Any())
  378. {
  379. ArtSubjectPdf artSubjectPdf = new ArtSubjectPdf()
  380. {
  381. subjectId = exam.subjects.First().id,
  382. subjectName = exam.subjects.First().name
  383. };
  384. datas.pointScores.Value.ForEach(k => {
  385. var artPointPdfs = GetBlockAndDimension(k.score, k.tscore, artSubjectPdf.subjectId, k.name, subjectBindBlocks, artSetting);
  386. artSubjectPdf.pointPdfs.AddRange(artPointPdfs);
  387. });
  388. var pointHigh = artSubjectPdf.pointPdfs.Where(z => z.percent >= 0.8).Select(z => z.point).ToHashSet();
  389. var pointLow = artSubjectPdf.pointPdfs.Where(z => z.percent < 0.6).Select(z => z.point).ToHashSet();
  390. StringBuilder comment = new StringBuilder();
  391. if (pointHigh.Any())
  392. {
  393. comment.Append(comment4.Replace("{pointHigh}", string.Join("、", pointHigh)));
  394. }
  395. if (pointLow.Any())
  396. {
  397. comment.Append(comment5.Replace("{pointLow}", string.Join("、", pointLow)));
  398. }
  399. if (artSubjectPdf.subjectId.Equals("subject_music"))
  400. {
  401. comment.Append(comment_subject_music);
  402. }
  403. if (artSubjectPdf.subjectId.Equals("subject_painting"))
  404. {
  405. comment.Append(comment_subject_painting);
  406. }
  407. artSubjectPdf.comment = comment.ToString();
  408. subjectPdfs.Add(artSubjectPdf);
  409. }
  410. }
  411. });
  412. ArtStudentPdf studentPdf = new ArtStudentPdf
  413. {
  414. artId = art.id,
  415. schoolCode = school.id,
  416. schoolName = school.name,
  417. periodId = periodId,
  418. periodName = periodName,
  419. studentId = x.studentId,
  420. studentName = x.studentName,
  421. picture = x.picture,
  422. classNames = classNames,
  423. artName = art.name,
  424. level = level,
  425. score = allScore,
  426. allSubjectQuotas = allSubjectQuotas.ToList(),
  427. comment = comment.ToString(),
  428. subjectPdfs = subjectPdfs,
  429. };
  430. studentPdfs.Add(studentPdf);
  431. });
  432. // _ = _httpTrigger.RequestHttpTrigger(new { studentPdfs = studentPdfs, artResults, schoolCode = $"{_schoolId}" }, _option.Location, "gen-art-pdf");
  433. var messageBlobPDF = new ServiceBusMessage(new { studentPdfs = studentPdfs, artResults, schoolCode = $"{_schoolId}", bizType = "ArtStudentPdf" }.ToJsonString());
  434. var GenPdfQueue = _configuration.GetValue<string>("Azure:ServiceBus:GenPdfQueue");
  435. await _serviceBus.GetServiceBusClient().SendMessageAsync(GenPdfQueue, messageBlobPDF);
  436. return studentPdfs;
  437. }
  438. private static JsonDocument readFileJson(string path)
  439. {
  440. var sampleJson = System.IO.File.ReadAllBytes(path).AsSpan();
  441. Utf8JsonReader reader = new Utf8JsonReader(sampleJson);
  442. if (JsonDocument.TryParseValue(ref reader, out JsonDocument jsonDoc))
  443. {
  444. return jsonDoc;
  445. }
  446. else
  447. {
  448. return null;
  449. }
  450. }
  451. //获取本次评测所有科目结算结果
  452. /* List<ExamResult> examResults = new();
  453. ExamInfo info = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(examId.ToString(), new PartitionKey($"Exam-{code}"));
  454. var query = $"select c.id,c.name,c.subjectId,c.studentScores,c.studentIds,c.paper,c.classes,c.sRate,c.average,c.standard,c.lostStus,c.record,c.phc,c.plc from c where c.examId = '{examId}' and c.subjectId = '{subjectId}' ";
  455. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<ExamResult>(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamResult-{examId}") }))
  456. {
  457. examResults.Add(item);
  458. }*/
  459. private static (KeyValuePair<string, List<string>> knowledgeName,
  460. KeyValuePair<string, List<(string name, double score)>> pointScore,
  461. KeyValuePair<string, List<(string name, double score)>> pointTScore,
  462. KeyValuePair<string, List<(string name, double score, double tscore)>> pointScores) DoKnowledgePoint(ExamResult exam, ExamInfo info, string studentId)
  463. {
  464. HashSet<string> knowledge = new();
  465. List<double> point = new();
  466. List<List<double>> result = new();
  467. List<ClassRange> classes = new();
  468. //定位试卷信息
  469. int index = 0;
  470. foreach (ExamSubject subject in info.subjects)
  471. {
  472. if (subject.id.Equals(exam.subjectId))
  473. {
  474. break;
  475. }
  476. else
  477. {
  478. index++;
  479. }
  480. }
  481. if (info.papers[index].knowledge != null && info.papers[index].knowledge.Count > 0)
  482. {
  483. info.papers[index].knowledge.ForEach(k =>
  484. {
  485. k.ForEach(e =>
  486. {
  487. knowledge.Add(e);
  488. });
  489. });
  490. }
  491. else
  492. {
  493. return (default, default, default, default);
  494. }
  495. point = info.papers[index].point;
  496. result = exam.studentScores;
  497. classes = exam.classes;
  498. List<string> knowledgeName = new List<string>();
  499. foreach (string cla in knowledge)
  500. {
  501. knowledgeName.Add(cla);
  502. }
  503. for (int k = 0; k < knowledgeName.Count; k++)
  504. {
  505. if (null == knowledgeName[k])
  506. {
  507. knowledgeName.Remove(knowledgeName[k]);
  508. }
  509. }
  510. List<double> knowScore = new();
  511. //学生得分情况
  512. List<(string name, double score)> pointScore = new();
  513. List<(string name, double score)> pointTScore = new();
  514. List<(string name, double score, double tscore)> pointScores = new();
  515. for (int k = 0; k < knowledgeName.Count; k++)
  516. {
  517. double OnePoint = 0;
  518. List<string> itemNo = new();
  519. int n = 0;
  520. double scores = 0;
  521. info.papers[index].knowledge.ForEach(kno =>
  522. {
  523. if (kno.Contains(knowledgeName[k]))
  524. {
  525. var itemPersent = kno.Count > 0 ? 1 / Convert.ToDouble(kno.Count) : 0;
  526. OnePoint += point[n] * itemPersent;
  527. int stuIndex = exam.studentIds.IndexOf(studentId);
  528. if (exam.studentScores[stuIndex][n] > 0)
  529. {
  530. scores += exam.studentScores[stuIndex][n] * itemPersent;
  531. }
  532. }
  533. n++;
  534. });
  535. //单个知识点的配分
  536. pointScore.Add((knowledgeName[k], OnePoint));
  537. pointTScore.Add((knowledgeName[k], scores));
  538. pointScores.Add((knowledgeName[k], OnePoint, scores));
  539. }
  540. KeyValuePair<string, List<string>> key1 = new(exam.subjectId, knowledgeName);
  541. KeyValuePair<string, List<(string name, double score)>> key2 = new(exam.subjectId, pointScore);
  542. KeyValuePair<string, List<(string name, double score)>> key3 = new(exam.subjectId, pointTScore);
  543. KeyValuePair<string, List<(string name, double score, double tscore)>> key4 = new(exam.subjectId, pointScores);
  544. return (key1, key2, key3, key4);
  545. }
  546. private static List<ArtPointPdf> GetBlockAndDimension(double score, double tscore, string subjectId, string point, List<KeyValuePair<string, List<Block>>> subjectBindBlocks, ArtSetting artSetting)
  547. {
  548. var block = subjectBindBlocks.Find(z => z.Key.Equals(subjectId));
  549. List<ArtPointPdf> artPointPdfs = new List<ArtPointPdf>();
  550. if (!string.IsNullOrWhiteSpace(block.Key))
  551. {
  552. block.Value.ForEach(z => {
  553. if (z.points.Contains(point))
  554. {
  555. var dims = artSetting.dimensions.FindAll(m => m.blocks.Contains(z.name));
  556. if (dims.Any())
  557. {
  558. foreach (var dim in dims)
  559. {
  560. artPointPdfs.Add(
  561. new ArtPointPdf
  562. {
  563. dimension = dim.dimension,
  564. block = z.name,
  565. point = point,
  566. totalScore = score,
  567. score = tscore,
  568. percent = score > 0 ? tscore * 1.0 / score : 0,
  569. }
  570. );
  571. }
  572. }
  573. }
  574. });
  575. }
  576. return artPointPdfs;
  577. }
  578. }
  579. }