TriggerExam.cs 122 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225
  1. using Microsoft.Azure.Cosmos;
  2. using Azure.Messaging.ServiceBus;
  3. using TEAMModelOS.SDK.DI;
  4. using TEAMModelOS.SDK.Extension;
  5. using TEAMModelOS.SDK;
  6. using TEAMModelOS.SDK.Models;
  7. using TEAMModelOS.SDK.Models.Service;
  8. using HTEXLib.COMM.Helpers;
  9. using ClouDASLibx;
  10. using System.Text.Json;
  11. using System.Collections.Generic;
  12. using System.Threading.Tasks;
  13. using System;
  14. using System.Linq;
  15. using TEAMModelOS.SDK.Models.Service.BI;
  16. using Azure.Storage.Blobs.Models;
  17. using System.IO;
  18. using System.Text;
  19. using System.Text.Json.Nodes;
  20. using Newtonsoft.Json.Linq;
  21. using TEAMModelOS.SDK.Models.Cosmos.Student;
  22. using HTEXLib.Helpers.ShapeHelpers;
  23. using TEAMModelOS.Models.Dto;
  24. using TEAMModelOS.SDK.Models.Cosmos.Common;
  25. using DocumentFormat.OpenXml.Office2010.Excel;
  26. using DocumentFormat.OpenXml.Drawing.Charts;
  27. using DocumentFormat.OpenXml.Vml;
  28. using System.Net.Http;
  29. using Newtonsoft.Json;
  30. using System.Net;
  31. using System.Security.Policy;
  32. using Microsoft.Extensions.Configuration;
  33. using DocumentFormat.OpenXml.EMMA;
  34. using Microsoft.Extensions.Options;
  35. using TEAMModelOS.Models;
  36. using Microsoft.AspNetCore.Razor.TagHelpers;
  37. using HtmlAgilityPack;
  38. using Azure.Storage.Blobs;
  39. using System.ComponentModel;
  40. using TEAMModelOS.Function;
  41. namespace TEAMModelOS.CosmosDBTriggers
  42. {
  43. public class TriggerExam
  44. {
  45. public static async Task Trigger(CoreAPIHttpService _coreAPIHttpService, AzureCosmosFactory _azureCosmos, AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, DingDing _dingDing,
  46. CosmosClient client, JsonElement input, TriggerData data, IHttpClientFactory _httpClient, IConfiguration _configuration, HttpTrigger _httpTrigger,AzureRedisFactory _azureRedis)
  47. {
  48. List<ExamClassResult> examClassResults = new();
  49. List<ExamSubject> examSubjects = new();
  50. try
  51. {
  52. if ((data.status != null && data.status.Value == 404))
  53. {
  54. await client.GetContainer(Constant.TEAMModelOS, "Common").DeleteItemStreamAsync(data.id, new PartitionKey(data.code));
  55. ActivityList activity = input.ToObject<ActivityList>();
  56. //await IESActivityService.DeleteActivity(_coreAPIHttpService, client, _dingDing, activity);
  57. var table_cancel = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord");
  58. List<ChangeRecord> records = await table_cancel.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", data.id } });
  59. foreach (var record in records)
  60. {
  61. try
  62. {
  63. await table_cancel.DeleteSingle<ChangeRecord>(record.PartitionKey, record.RowKey);
  64. await _serviceBus.GetServiceBusClient().CancelMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), record.sequenceNumber);
  65. }
  66. catch (Exception)
  67. {
  68. continue;
  69. }
  70. }
  71. await BIStats.SetTypeAddStats(client, _dingDing, data.school, "Exam", -1, careDate: data.startTime);//BI统计增/减量
  72. return;
  73. }
  74. ExamInfo info = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(data.id, new PartitionKey($"{data.code}"));
  75. if (info != null)
  76. {
  77. if (info.scope.Equals("teacher", StringComparison.OrdinalIgnoreCase) || info.scope.Equals("private", StringComparison.OrdinalIgnoreCase))
  78. {
  79. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryStreamIteratorSql(queryText: $"select value(c) from c where c.examId = '{info.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{info.creatorId}") }))
  80. {
  81. using var json = await JsonDocument.ParseAsync(item.Content);
  82. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  83. {
  84. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  85. {
  86. examClassResults.Add(obj.ToObject<ExamClassResult>());
  87. }
  88. }
  89. }
  90. }
  91. else
  92. {
  93. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryStreamIteratorSql(queryText: $"select value(c) from c where c.examId = '{info.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{data.school}") }))
  94. {
  95. using var json = await JsonDocument.ParseAsync(item.Content);
  96. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  97. {
  98. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  99. {
  100. examClassResults.Add(obj.ToObject<ExamClassResult>());
  101. }
  102. }
  103. }
  104. }
  105. var table = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord");
  106. string PartitionKey = string.Format("{0}{1}{2}", info.code, "-", info.progress);
  107. List<ChangeRecord> records = await table.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", data.id }, { "PartitionKey", PartitionKey } });
  108. //处理科目信息
  109. List<string> sub = new List<string>();
  110. School sc = new();
  111. if (!string.IsNullOrEmpty(info.school) && !info.school.Equals("SYSTEM_NO_SCHOOL"))
  112. {
  113. sc = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(info.school, new PartitionKey("Base"));
  114. }
  115. foreach (ExamSubject subject in info.subjects)
  116. {
  117. sub.Add(subject.id);
  118. }
  119. //整合名单
  120. List<string> classes = ExamService.getClasses(info.classes, info.stuLists);
  121. //ChangeRecord record = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ChangeRecord>(input.Id, new PartitionKey($"{info.progress}"));
  122. switch (info.progress)
  123. {
  124. case "pending":
  125. var message = new ServiceBusMessage(new { id = data.id, progress = "going", code = data.code }.ToJsonString());
  126. message.ApplicationProperties.Add("name", "Exam");
  127. if (records.Count > 0)
  128. {
  129. try
  130. {
  131. await _serviceBus.GetServiceBusClient().CancelMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), records[0].sequenceNumber);
  132. }
  133. catch (Exception)
  134. {
  135. }
  136. long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), message, DateTimeOffset.FromUnixTimeMilliseconds(data.startTime));
  137. records[0].sequenceNumber = start;
  138. await table.SaveOrUpdate<ChangeRecord>(records[0]);
  139. //await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(record, record.id, new PartitionKey($"{record.code}"));
  140. }
  141. else
  142. {
  143. long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), message, DateTimeOffset.FromUnixTimeMilliseconds(data.startTime));
  144. //string pk = String.Format("{0}{1}{2}", info.code, "-", "pending");
  145. ChangeRecord changeRecord = new ChangeRecord
  146. {
  147. RowKey = data.id,
  148. PartitionKey = PartitionKey,
  149. sequenceNumber = start,
  150. msgId = message.MessageId
  151. };
  152. await table.Save<ChangeRecord>(changeRecord);
  153. //await client.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync(changeRecord, new PartitionKey($"{changeRecord.code}"));
  154. }
  155. break;
  156. case "going":
  157. try
  158. {
  159. //向学生或醍摩豆账号发起通知
  160. #region
  161. //Notice notice = new Notice()
  162. //{
  163. // msgId = info.id,
  164. // creation = info.startTime,
  165. // expire = info.endTime,
  166. // creatorId = info.creatorId,
  167. // stuids = studentss,
  168. // tmdids = tmdids,
  169. // type = "notice",//评测参加通知
  170. // priority = "normal",
  171. // school = info.school,
  172. // scope = info.scope,
  173. // //data = new { }.ToJsonString()
  174. // body = new Body { sid = info.id, scode = info.code, spk = info.pk, biztype = "exam-join" }
  175. //};
  176. //var messageBlob = new ServiceBusMessage(notice.ToJsonString());
  177. //messageBlob.ApplicationProperties.Add("name", "Notice");
  178. //await _serviceBus.GetServiceBusClient().SendMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageBlob);
  179. #endregion
  180. //List<string> classes = new List<string>();
  181. if (info!=null && info.scope.Equals("private"))
  182. {
  183. await SystemService.RecordAccumulateData(_azureRedis, _dingDing, new SDK.Models.Dtos.Accumulate { client="web", count=1, id=info.id, key="exam-going", name=info.name, scope="teacher", target=info.creatorId });
  184. }
  185. //处理活动中间件
  186. List<RGroupList> members = await Activity(_coreAPIHttpService, info, classes, client, _dingDing, sub, examClassResults);
  187. if (examClassResults.Count == 0)
  188. {
  189. List<Task<ItemResponse<ExamClassResult>>> tasks = new List<Task<ItemResponse<ExamClassResult>>>();
  190. foreach (string cla in classes)
  191. {
  192. int m = 0;
  193. RGroupList rGroup = new();
  194. rGroup = members.Where(m => m.id.Equals(cla)).FirstOrDefault();
  195. foreach (ExamSubject subject in info.subjects)
  196. {
  197. string classCode = string.Empty;
  198. string cname = string.Empty;
  199. if (string.IsNullOrEmpty(info.school) || !info.scope.Equals("school", StringComparison.OrdinalIgnoreCase))
  200. {
  201. classCode = "ExamClassResult-" + info.creatorId;
  202. }
  203. else
  204. {
  205. classCode = "ExamClassResult-" + info.school;
  206. }
  207. cname = members.Where(m => m.id.Equals(cla)).FirstOrDefault()?.name;
  208. // 预处理活动中间件信息
  209. ExamClassResult result = new()
  210. {
  211. code = classCode,
  212. examId = info.id,
  213. id = Guid.NewGuid().ToString(),
  214. subjectId = subject.id,
  215. year = info.year,
  216. scope = info.scope
  217. };
  218. result.info.id = cla;
  219. result.info.name = cname;
  220. List<string> ans = new();
  221. List<List<string>> anses = new();
  222. List<List<Details>> marks = new();
  223. List<double> ansPoint = new();
  224. List<(string sId, string scode)> ids = new();
  225. foreach (double p in info.papers[m].point)
  226. {
  227. //Details details = new Details();
  228. //ans.Add(new List<string>());
  229. anses.Add(new List<string>());
  230. marks.Add(new List<Details>());
  231. ansPoint.Add(-1);
  232. }
  233. var sresponse = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(cla, new PartitionKey($"Class-{info.school}"));
  234. if (sresponse.Status == 200)
  235. {
  236. using var json = await JsonDocument.ParseAsync(sresponse.Content);
  237. Class classroom = json.ToObject<Class>();
  238. foreach (SDK.Models.Period period in sc.period)
  239. {
  240. if (period.id.Equals(classroom.periodId))
  241. {
  242. foreach (Semester semester in period.semesters)
  243. {
  244. if (semester.start == 1)
  245. {
  246. int year = DateTimeOffset.UtcNow.Year;
  247. int month = DateTimeOffset.UtcNow.Month;
  248. int day = DateTimeOffset.UtcNow.Day;
  249. int time = 0;
  250. if (month == semester.month)
  251. {
  252. time = day >= semester.day ? 0 : 1;
  253. }
  254. else
  255. {
  256. time = month > semester.month ? 0 : 1;
  257. }
  258. int eyear = year - time;
  259. result.gradeId = (eyear - classroom.year).ToString();
  260. }
  261. }
  262. }
  263. }
  264. //result.info.id = classroom.id;
  265. //result.info.name = classroom.name;
  266. //result.gradeId = classroom.year.ToString();
  267. //处理班级人数
  268. /* await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIteratorSql(queryText: $"select c.id from c where c.classId = '{classroom.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{info.school}") }))
  269. {
  270. using var json_stu = await JsonDocument.ParseAsync(item.Content);
  271. if (json_stu.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  272. {
  273. var accounts = json_stu.RootElement.GetProperty("Documents").EnumerateArray();
  274. while (accounts.MoveNext())
  275. {
  276. JsonElement account = accounts.Current;
  277. ids.Add(account.GetProperty("id").GetString());
  278. }
  279. }
  280. }*/
  281. }
  282. /*if (info.scope.Equals("private", StringComparison.OrdinalIgnoreCase))
  283. {
  284. var stuResponse = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemStreamAsync(cla, new PartitionKey($"GroupList"));
  285. if (stuResponse.Status == 200)
  286. {
  287. using var json = await JsonDocument.ParseAsync(stuResponse.Content);
  288. GroupList stuList = json.ToObject<GroupList>();
  289. //result.info.id = stuList.id;
  290. result.info.name = stuList.name;
  291. //处理发布对象为自选名单(个人)
  292. foreach (Member stus in stuList.members)
  293. {
  294. if (!ids.Contains(stus.id))
  295. {
  296. ids.Add(stus.id);
  297. }
  298. }
  299. }
  300. }
  301. else
  302. {
  303. var stuResponse = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(cla, new PartitionKey($"GroupList-{info.school}"));
  304. if (stuResponse.Status == 200)
  305. {
  306. using var json = await JsonDocument.ParseAsync(stuResponse.Content);
  307. GroupList stuList = json.ToObject<GroupList>();
  308. //result.info.id = stuList.id;
  309. result.info.name = stuList.name;
  310. //处理发布对象为自选名单(校本)
  311. foreach (Member stus in stuList.members)
  312. {
  313. if (!ids.Contains(stus.id))
  314. {
  315. ids.Add(stus.id);
  316. }
  317. }
  318. }
  319. }*/
  320. foreach (RMember member in rGroup.members)
  321. {
  322. ids.Add((member.id, member.code));
  323. }
  324. //ids = members.Where(c => c.id.Equals(cla)).SelectMany(m => m.members).Select(g => g.id).ToList();
  325. List<string> blobs = new();
  326. if (info.qamode == 2) {
  327. blobs = info.papers.Where(c => c.subjectId.Equals(subject.id)).Select(c => c.blob).ToList();
  328. }
  329. foreach (var (sId, scode) in ids)
  330. {
  331. result.mark.Add(marks);
  332. result.studentIds.Add(sId);
  333. //result.scIds.Add(scode ?? "");
  334. result.studentAnswers.Add(ans);
  335. result.studentScores.Add(ansPoint);
  336. result.ans.Add(anses);
  337. result.sum.Add(0);
  338. result.status.Add(1);
  339. if (info.qamode == 2) {
  340. result.paper.Add(blobs[new Random().Next(blobs.Count)]);
  341. }
  342. }
  343. //result.progress = info.progress;
  344. result.school = info.school;
  345. m++;
  346. tasks.Add(client.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync(result, new PartitionKey($"{result.code}")));
  347. }
  348. }
  349. await tasks.TaskPage(10);
  350. }
  351. else
  352. {
  353. //处理单科结算时科目与试卷信息匹配的问题
  354. int gno = 0;
  355. foreach (ExamSubject subject in info.subjects)
  356. {
  357. if (subject.classCount == classes.Count)
  358. {
  359. await createClassResultAsync(info, examClassResults, subject, gno, _azureCosmos, _dingDing, _azureStorage, _httpClient, _configuration);
  360. }
  361. gno++;
  362. }
  363. var isScore = examClassResults.SelectMany(e => e.studentScores).ToList().Exists(c => c.Contains(-1));
  364. int newStatus = 0;
  365. if (!isScore)
  366. {
  367. newStatus = 1;
  368. }
  369. Settlement settlement = await getMore(client, info);
  370. long nowTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  371. //判断评分状态是否发生变化,便于实时的更新评测基本信息
  372. if (info.average != settlement.score || info.sStatus != newStatus)
  373. {
  374. info.sRate = settlement.rate;
  375. info.sStatus = newStatus;
  376. info.updateTime = nowTime;
  377. info.average = settlement.score;
  378. await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync<ExamInfo>(info, info.id, new PartitionKey(info.code));
  379. }
  380. }
  381. }
  382. catch (Exception e)
  383. {
  384. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测going状态异常{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  385. }
  386. finally
  387. {
  388. try {
  389. //新增serviceBus 消息释放后处理table
  390. string pkey = string.Format("{0}{1}{2}", info.code, "-", "pending");
  391. await table.DeleteSingle<ChangeRecord>(pkey, data.id);
  392. // 发送信息通知
  393. var messageEnd = new ServiceBusMessage(new { id = data.id, progress = "finish", code = data.code }.ToJsonString());
  394. messageEnd.ApplicationProperties.Add("name", "Exam");
  395. if (records.Count > 0)
  396. {
  397. long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageEnd, DateTimeOffset.FromUnixTimeMilliseconds(data.endTime));
  398. await _serviceBus.GetServiceBusClient().CancelMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), records[0].sequenceNumber);
  399. records[0].sequenceNumber = end;
  400. await table.SaveOrUpdate<ChangeRecord>(records[0]);
  401. //await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(record, record.id, new PartitionKey($"{record.code}"));
  402. }
  403. else
  404. {
  405. long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageEnd, DateTimeOffset.FromUnixTimeMilliseconds(data.endTime));
  406. //string pk = String.Format("{0}{1}{2}", info.code, "-", "going");
  407. ChangeRecord changeRecord = new ChangeRecord
  408. {
  409. RowKey = data.id,
  410. PartitionKey = PartitionKey,
  411. sequenceNumber = end,
  412. msgId = messageEnd.MessageId
  413. };
  414. await table.Save<ChangeRecord>(changeRecord);
  415. //await client.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync(changeRecord, new PartitionKey($"{changeRecord.code}"));
  416. }
  417. } catch (Exception e) {
  418. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-ChangeRecord{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  419. }
  420. }
  421. break;
  422. case "finish":
  423. int fno = 0;
  424. try
  425. {
  426. //await SetLearnRecordContent(info, data, _azureStorage, _azureCosmos);
  427. //用来判定是否完成评分
  428. //bool isScore = true;
  429. await resultStatus(client, examClassResults);
  430. await Activity(_coreAPIHttpService, info, classes, client, _dingDing, sub, examClassResults);
  431. foreach (ExamSubject subject in info.subjects)
  432. {
  433. await createClassResultAsync(info, examClassResults, subject, fno, _azureCosmos, _dingDing, _azureStorage, _httpClient, _configuration);
  434. fno++;
  435. }
  436. Settlement settlement = await getMore(client, info);
  437. var isScore = examClassResults.SelectMany(e => e.studentScores).ToList().Exists(c => c.Contains(-1));
  438. int newStatus = 0;
  439. if (!isScore)
  440. {
  441. newStatus = 1;
  442. }
  443. //判断均分是否发生变化,便于实时的更新评测基本信息
  444. if (info.sRate != settlement.rate || info.average != settlement.score || info.sStatus != newStatus || info.qRate != settlement.qrate)
  445. {
  446. info.sRate = settlement.rate;
  447. info.average = settlement.score;
  448. info.sStatus = newStatus;
  449. info.lostStu = settlement.stus;
  450. info.stuCount = settlement.total;
  451. info.qRate = settlement.qrate;
  452. //新增数据推送 obj => Portrait
  453. Portrait portrait = new()
  454. {
  455. schoolCode = info.school,
  456. periodId = info.period.id,
  457. subjectId = "subject_intelligence"
  458. };
  459. //作答合格率
  460. var sta = examClassResults.SelectMany(x => x.status).ToList();
  461. /* var stus = examClassResults.SelectMany(x => x.studentIds).ToList();
  462. var stuScores = examClassResults.SelectMany(x => x.studentScores).ToList();*/
  463. var ansCount = sta.Where(x => x == 0).ToList();
  464. var persent = ansCount.Count * 1.0 / sta.Count * 100;
  465. var period = sc.period.Where(x => x.id.Equals(info.period.id)).FirstOrDefault();
  466. List<string> subjects = info.subjects.Select(x => x.id).ToList();
  467. //获取学期信息
  468. if (null != period && persent >= 60 && !subjects.Contains("subject_painting") && !subjects.Contains("subject_music"))
  469. {
  470. var (currSemester, studyYear, currSemesterDate, date, nextSemester) = SchoolService.GetSemester(period, info.startTime);
  471. //获取学生信息
  472. (List<RMember> rmembers, List<RGroupList> groups) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, info.classes, info.school);
  473. foreach (var member in rmembers)
  474. {
  475. if (info.lostStu.Contains(member.id))
  476. {
  477. continue;
  478. }
  479. PortraitStudent student = new()
  480. {
  481. studentId = member.id,
  482. name = member.name,
  483. classId = member.classId
  484. };
  485. var ec = examClassResults.Where(c => c.studentIds.Contains(member.id)).ToList();
  486. double scores = 0;
  487. List<(string subjectId, double score)> subScore = new();
  488. foreach (var eclass in ec)
  489. {
  490. int index_stu = eclass.studentIds.IndexOf(member.id);
  491. scores += eclass.sum[index_stu];
  492. subScore.Add((eclass.subjectId, eclass.sum[index_stu]));
  493. }
  494. SemesterData semesterData = new()
  495. {
  496. examName = info.name,
  497. examId = info.id,
  498. examDate = info.startTime,
  499. examType = info.examType?.name,
  500. year = info.year,
  501. semesterId = currSemester.id,
  502. totalScore = info.papers.SelectMany(x => x.point).Sum(),
  503. sumScore = scores,
  504. excellenceRate = 0,
  505. passRate = 0,
  506. };
  507. int index = 0;
  508. foreach (var sj in info.subjects)
  509. {
  510. ItemScore item = new()
  511. {
  512. id = sj.id,
  513. name = sj.name,
  514. score = subScore.Where(c => c.subjectId.Equals(sj.id)).FirstOrDefault().score,
  515. time = info.startTime,
  516. totalScore = info.papers[index].point.Sum(),
  517. type = sj.id
  518. };
  519. index++;
  520. semesterData.itemScore.Add(item);
  521. }
  522. student.semesterData.Add(semesterData);
  523. portrait.students.Add(student);
  524. }
  525. string location = $"{Environment.GetEnvironmentVariable("Option:Location")}";
  526. var (status, json) = await _httpTrigger.RequestHttpTrigger(portrait, location, "upsert-student-portrait");
  527. }
  528. //PortraitStudent student = new();
  529. //处理试卷活动结束统计账户信息
  530. List<FMember> idList = await GroupListService.GetFinishMemberInfo(_coreAPIHttpService, client, _dingDing, info.school, info.classes, info.stuLists, null);
  531. info.staffIds = idList;
  532. await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync<ExamInfo>(info, info.id, new PartitionKey(info.code));
  533. }
  534. await SetLearnRecordContent(info, data, _azureStorage, _azureCosmos);
  535. }
  536. catch (Exception e)
  537. {
  538. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测finish状态异常{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  539. }
  540. finally {
  541. //新增serviceBus 消息释放后处理table
  542. string pk = string.Format("{0}{1}{2}", info.code, "-", "going");
  543. await table.DeleteSingle<ChangeRecord>(pk, data.id);
  544. }
  545. break;
  546. }
  547. }
  548. }
  549. catch (CosmosException e)
  550. {
  551. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-CosmosDB异常{e.Message}\n{e.StackTrace}\n{e.Status}", GroupNames.醍摩豆服務運維群組);
  552. }
  553. catch (Exception e)
  554. {
  555. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-评测结算异常{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  556. }
  557. }
  558. private static async Task SetLearnRecordContent(ExamInfo info, TriggerData data, AzureStorageFactory _azureStorage, AzureCosmosFactory _azureCosmos)
  559. {
  560. try
  561. {
  562. if (info.papers.Count > 0)
  563. {
  564. for (int i = 0; i < info.papers.Count; i++)
  565. {// 每一個科目的試卷
  566. string rootName = "";
  567. //if (info.school == "SYSTEM_NO_SCHOOL")
  568. if (info.scope == "private")
  569. {// 未入校老師的評量
  570. rootName = info.creatorId;
  571. }
  572. else
  573. {// 如果有學校代碼
  574. rootName = info.school;
  575. }
  576. if (_azureStorage.GetBlobContainerClient(rootName).GetBlobClient($"{info.papers[i].blob}/index.json").Exists())
  577. {// 如果試卷的blob存在,再開始
  578. BlobDownloadResult paperblobDownload = await _azureStorage.GetBlobContainerClient(rootName).GetBlobClient($"{info.papers[i].blob}/index.json").DownloadContentAsync();
  579. PaperIndex paperIndex = paperblobDownload.Content.ToObjectFromJson<PaperIndex>();
  580. List<LearnRecordItem> learnRecordItems = new();
  581. StringBuilder sbsql = new StringBuilder($" SELECT * FROM c WHERE c.examId = '{info.id}' and c.pk = 'ExamClassResult' and c.subjectId = '{info.subjects[i].id}' ");
  582. #region === 開始拼裝資料 ===
  583. if (info.classes.Count > 0 || info.stuLists.Count > 0)
  584. {
  585. // 組合SQL
  586. if (info.classes.Count > 0)
  587. {// 按照classes取ans.json
  588. sbsql.Append($" and ARRAY_CONTAINS({System.Text.Json.JsonSerializer.Serialize(info.classes)}, c.info.id)");
  589. }
  590. else if (info.stuLists.Count > 0)
  591. {
  592. sbsql.Append($" and ARRAY_CONTAINS({System.Text.Json.JsonSerializer.Serialize(info.stuLists)}, c.info.id)");
  593. }
  594. // 取學生答案及學生名單
  595. var client = _azureCosmos.GetCosmosClient();
  596. Dictionary<string, List<string>> stuDic = new Dictionary<string, List<string>>();
  597. if (!string.IsNullOrWhiteSpace(info.school) && !stuDic.ContainsKey(info.school))
  598. {
  599. stuDic.Add(info.school, new List<string>());
  600. }
  601. List<StudentAnswers> studentAnswersList = new List<StudentAnswers>();
  602. List<string> stuListForSql = new List<string>();
  603. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Common).GetItemQueryIteratorSql<StudentAnswers>(queryText: sbsql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{rootName}") }))
  604. {
  605. studentAnswersList.Add(item);
  606. stuListForSql = stuListForSql.Union(item.studentIds).ToList();
  607. }
  608. //取得學校的學生名單
  609. List<string> stuOpenIdList = new List<string>();
  610. if(!string.IsNullOrWhiteSpace(info.school))
  611. {
  612. StringBuilder stusql = new StringBuilder($"SELECT VALUE c.id FROM c WHERE c.pk = 'Base' AND ARRAY_CONTAINS({System.Text.Json.JsonSerializer.Serialize(stuListForSql)}, c.id)");
  613. await foreach (string item in client.GetContainer(Constant.TEAMModelOS, Constant.Student).GetItemQueryIteratorSql<string>(queryText: stusql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{info.school}") }))
  614. {
  615. stuDic[info.school].Add(item);
  616. }
  617. }
  618. // 按照取出的學生答案blob 對答案 組合資料
  619. foreach (var studentAnswers in studentAnswersList)
  620. {// 每一個班級
  621. foreach (var studentAnswersBlob in studentAnswers.studentAnswers)
  622. {// 每一個學生
  623. if (studentAnswersBlob.Count > 0)
  624. {// 有學生的答案才開始
  625. if (_azureStorage.GetBlobContainerClient(rootName).GetBlobClient($"/exam/{studentAnswersBlob[0]}").Exists())
  626. {// 如果blob存在才開始
  627. BlobDownloadResult ansblobDownload = await _azureStorage.GetBlobContainerClient(rootName).GetBlobClient($"/exam/{studentAnswersBlob[0]}").DownloadContentAsync();
  628. List<List<string>> ansList = JsonConvert.DeserializeObject<List<List<string>>>(ansblobDownload.Content.ToString());
  629. // 從blob路徑取出學生id
  630. string[] arr = studentAnswersBlob[0].Split('/');
  631. string stuid = arr[arr.Length - 2];
  632. #region ===StartExam 開始課堂===
  633. LearnRecordItem LRItem_StartExam = new();
  634. LRItem_StartExam.verb = "StartExam";
  635. LRItem_StartExam.actor = getStuId(info.school, stuid, stuDic);
  636. LRItem_StartExam.time = info.createTime;
  637. LRItem_StartExam.ID = info.id;
  638. LRItem_StartExam.Desc = info.name;
  639. LRItem_StartExam.Correct = null;
  640. LRItem_StartExam.Choices = null;
  641. LRItem_StartExam.ExamQuesQty = info.papers[i].point.Count;
  642. LRItem_StartExam.TotalScore = 0;
  643. foreach (var pointItem in info.papers[i].point)
  644. {
  645. LRItem_StartExam.TotalScore = LRItem_StartExam.TotalScore + pointItem;
  646. }
  647. LRItem_StartExam.Success = null;
  648. learnRecordItems.Add(LRItem_StartExam);
  649. #endregion
  650. #region ===評量題目===
  651. for (int j = 0; j < ansList.Count; j++)
  652. {
  653. #region === 判斷題型 ===
  654. // 這五種題型才記錄
  655. if (paperIndex.slides[j].type == "single" ||
  656. paperIndex.slides[j].type == "multiple" ||
  657. paperIndex.slides[j].type == "judge" ||
  658. paperIndex.slides[j].type == "complete" ||
  659. paperIndex.slides[j].type == "subjective")
  660. {
  661. LearnRecordItem learnRecordItem = new();
  662. // 單選
  663. if (paperIndex.slides[j].type == "single") { learnRecordItem.verb = "AnsSingle"; }
  664. // 複選
  665. if (paperIndex.slides[j].type == "multiple") { learnRecordItem.verb = "AnsMultiple"; }
  666. // 是非
  667. if (paperIndex.slides[j].type == "judge") { learnRecordItem.verb = "AnsJudge"; }
  668. // 填充
  669. if (paperIndex.slides[j].type == "complete") { learnRecordItem.verb = "AnsComplete"; }
  670. // 問答
  671. if (paperIndex.slides[j].type == "subjective") { learnRecordItem.verb = "AnsSubjective"; }
  672. learnRecordItem.actor = getStuId(info.school, stuid, stuDic);
  673. learnRecordItem.time = data.endTime;
  674. string[] arrurlsingle = paperIndex.slides[j].url.Split('.');
  675. learnRecordItem.ID = arrurlsingle[0];
  676. #region === 設定Correct Choices Desc===
  677. if (_azureStorage.GetBlobContainerClient(rootName).GetBlobClient($"{info.papers[i].blob}/{paperIndex.slides[j].url}").Exists())
  678. {
  679. BlobDownloadResult itemblobDownload = await _azureStorage.GetBlobContainerClient(rootName).GetBlobClient($"{info.papers[i].blob}/{paperIndex.slides[j].url}").DownloadContentAsync();
  680. QuestionData questionData = itemblobDownload.Content.ToObjectFromJson<QuestionData>();
  681. setCorrectChoices(questionData, learnRecordItem);
  682. // 使用HtmlAgilityPack解析HTML
  683. HtmlDocument doc = new HtmlDocument();
  684. doc.LoadHtml(questionData.item[0].question);
  685. // 先刪除所有<img>標籤
  686. foreach (var imgNode in doc.DocumentNode.Descendants("img").ToArray())
  687. {
  688. imgNode.Remove();
  689. }
  690. // 再取純文字
  691. learnRecordItem.Desc = doc.DocumentNode.InnerText;
  692. }
  693. #endregion
  694. learnRecordItem.ExamQuesQty = null;
  695. learnRecordItem.TotalScore = null;
  696. learnRecordItem.Points = paperIndex.slides[j].scoring == null ? new List<string>() : paperIndex.slides[j].scoring.knowledge;
  697. //比對答案
  698. learnRecordItem.Success = paperIndex.slides[j].scoring == null ? null : (paperIndex.slides[j].scoring.ans.SequenceEqual(ansList[j]) ? true : false);
  699. learnRecordItems.Add(learnRecordItem);
  700. }
  701. #endregion
  702. }
  703. #endregion
  704. #region ===EndExam 結束課堂===
  705. LearnRecordItem LRItem_EndExam = new();
  706. LRItem_EndExam.verb = "EndExam";
  707. LRItem_EndExam.actor = getStuId(info.school, stuid, stuDic);
  708. LRItem_EndExam.time = info.endTime;
  709. LRItem_EndExam.ID = info.id;
  710. LRItem_EndExam.Desc = info.name;
  711. LRItem_EndExam.Correct = null;
  712. LRItem_EndExam.Choices = null;
  713. LRItem_EndExam.ExamQuesQty = info.papers[i].point.Count;
  714. LRItem_EndExam.TotalScore = 0;
  715. foreach (var pointItem in info.papers[i].point)
  716. {
  717. LRItem_EndExam.TotalScore = LRItem_EndExam.TotalScore + pointItem;
  718. }
  719. LRItem_EndExam.Success = null;
  720. learnRecordItems.Add(LRItem_EndExam);
  721. #endregion
  722. }
  723. }
  724. }
  725. }
  726. }
  727. #endregion
  728. if (learnRecordItems.Count > 0)
  729. {
  730. #region 寫入blob
  731. // 容器名称
  732. string containerName = "twmoeld";
  733. // 新文件的名称
  734. string blobName = $"/{DateTime.Now.ToString("yyyyMMdd")}/{info.id}.json";
  735. // 要上传的文件内容
  736. string fileContent = Newtonsoft.Json.JsonConvert.SerializeObject(learnRecordItems);
  737. // 获取容器引用
  738. BlobContainerClient containerClient = _azureStorage.GetBlobContainerClient(containerName);
  739. // 获取 Blob 客户端
  740. BlobClient blobClient = containerClient.GetBlobClient(blobName);
  741. // 将文件内容上传到 Blob
  742. using (MemoryStream stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(fileContent)))
  743. {
  744. await blobClient.UploadAsync(stream, true);
  745. }
  746. #endregion
  747. }
  748. }
  749. }
  750. }
  751. }
  752. catch (Exception ex)
  753. {
  754. }
  755. }
  756. /// <summary>
  757. /// 取得學習紀錄的actor
  758. /// </summary>
  759. /// <param name="learnRecordItem"></param>
  760. /// <param name="school"></param>
  761. /// <param name="stuid"></param>
  762. /// <returns></returns>
  763. private static string getStuId(string school, string stuid, Dictionary<string, List<string>> stuDic)
  764. {
  765. if (!string.IsNullOrWhiteSpace(school) && stuDic.ContainsKey(school) && stuDic[school].Contains(stuid))
  766. {// 校內帳號用組合的 "Base-hbgl,473891247381"
  767. return $"Base-{school.Trim()},{stuid}";
  768. }
  769. else
  770. {// 未入校老師的評量
  771. return stuid;
  772. }
  773. }
  774. private static void setCorrectChoices(QuestionData questionData, LearnRecordItem learnRecordItem)
  775. {
  776. #region === Correct Choices ===
  777. #region === 是非題邏輯 ===
  778. if (questionData.exercise.type == "judge" && questionData.exercise.answer.Count > 0)
  779. {// 如果是是非題 正確答案要用true false的方式設定
  780. if (questionData.exercise.answer[0] == "A")
  781. {
  782. learnRecordItem.Correct = new string[] { "true" };
  783. }
  784. else
  785. {
  786. learnRecordItem.Correct = new string[] { "false" };
  787. }
  788. }
  789. else
  790. {// 防呆 去html標籤
  791. if (questionData.exercise.answer.Count > 0)
  792. {
  793. List<string> anslist = new();
  794. foreach (var answer in questionData.exercise.answer)
  795. {
  796. // 使用HtmlAgilityPack解析HTML
  797. HtmlDocument doc = new HtmlDocument();
  798. doc.LoadHtml(answer);
  799. // 再取純文字
  800. anslist.Add(doc.DocumentNode.InnerText);
  801. }
  802. learnRecordItem.Correct = anslist;
  803. }
  804. else
  805. {
  806. learnRecordItem.Correct = questionData.exercise.answer;
  807. }
  808. }
  809. #endregion
  810. if (questionData.item[0].option.Count > 0)
  811. {// 如果有選項資料 記錄起來
  812. foreach (var option in questionData.item[0].option)
  813. {
  814. ChoicesItem item = new();
  815. item.id = option.code;
  816. if (questionData.exercise.type == "judge")
  817. {// 如果是是非題 固定選項
  818. if (option.code == "A")
  819. {
  820. item.description.zhTW = "是";
  821. }
  822. else
  823. {
  824. item.description.zhTW = "否";
  825. }
  826. }
  827. else
  828. {
  829. if (string.IsNullOrWhiteSpace(option.value))
  830. {
  831. item.description.zhTW = $"選項{option.code}";
  832. }
  833. else
  834. {
  835. // 使用HtmlAgilityPack解析HTML
  836. HtmlDocument doc = new HtmlDocument();
  837. doc.LoadHtml(option.value);
  838. // 再取純文字
  839. item.description.zhTW = doc.DocumentNode.InnerText;
  840. }
  841. }
  842. learnRecordItem.Choices.Add(item);
  843. }
  844. }
  845. #endregion
  846. }
  847. public static async Task resultStatus(CosmosClient client, List<ExamClassResult> examClassResults)
  848. {
  849. List<Task<ItemResponse<ExamClassResult>>> tasks = new();
  850. //结算单科单班的标准差和平均分
  851. foreach (ExamClassResult classResult in examClassResults)
  852. {
  853. //标记单科单班总得分
  854. double subScore = 0;
  855. //标准差
  856. double sPowSum = 0;
  857. List<double> newSumScore = new List<double>();
  858. List<double> effectiveScore = new List<double>();
  859. int lostStu = classResult.status.Where(c => c == 1).ToList().Count;
  860. var scount = classResult.studentIds.Count - lostStu;
  861. int index = 0;
  862. if (classResult.status.Count > 0)
  863. {
  864. foreach (var sta in classResult.status)
  865. {
  866. if (sta == 1)
  867. {
  868. for (int i = 0; i < classResult.studentScores[index].Count; i++)
  869. {
  870. if (classResult.studentScores[index][i] == -1)
  871. {
  872. classResult.studentScores[index][i] = 0;
  873. }
  874. }
  875. }
  876. else if (sta == 0)
  877. {
  878. //var ans = classResult.studentAnswers[index];
  879. //该学生缺考,历史数据的判定
  880. //if (ans.Count == 0)
  881. //{
  882. for (int i = 0; i < classResult.studentScores[index].Count; i++)
  883. {
  884. if (classResult.studentScores[index][i] == -1)
  885. {
  886. classResult.studentScores[index][i] = 0;
  887. }
  888. }
  889. /*if (ans.Count == 0)
  890. {
  891. classResult.status[index] = 1;
  892. } */
  893. //}
  894. }
  895. index++;
  896. }
  897. }
  898. else
  899. {
  900. List<int> sta = new();
  901. foreach (var id in classResult.studentIds)
  902. {
  903. sta.Add(0);
  904. }
  905. classResult.status = sta;
  906. foreach (var ans in classResult.studentAnswers)
  907. {
  908. //该学生缺考,历史数据的判定
  909. if (ans.Count == 0)
  910. {
  911. for (int i = 0; i < classResult.studentScores[index].Count; i++)
  912. {
  913. if (classResult.studentScores[index][i] == -1)
  914. {
  915. classResult.studentScores[index][i] = 0;
  916. }
  917. }
  918. classResult.status[index] = 1;
  919. }
  920. index++;
  921. }
  922. }
  923. int sIndex = 0;
  924. foreach (List<double> sc in classResult.studentScores)
  925. {
  926. List<double> newSc = new List<double>();
  927. foreach (double ssc in sc)
  928. {
  929. if (ssc == -1)
  930. {
  931. newSc.Add(0);
  932. }
  933. else
  934. {
  935. newSc.Add(ssc);
  936. }
  937. }
  938. double nc = Math.Round(newSc.Sum(), 2);
  939. if (classResult.status[sIndex] == 0)
  940. {
  941. effectiveScore.Add(nc);
  942. };
  943. newSumScore.Add(nc);
  944. subScore += nc;
  945. classResult.sum[sIndex] = nc;
  946. sIndex++;
  947. }
  948. double rateScore = scount > 0 ? Math.Round(subScore * 1.0 / scount, 2) : 0;
  949. //有效分数
  950. foreach (double scs in effectiveScore)
  951. {
  952. sPowSum += Math.Pow(scs - rateScore, 2);
  953. }
  954. classResult.standard = Math.Round(scount > 0 ? Math.Pow(sPowSum / scount, 0.5) : 0, 2);
  955. classResult.average = scount > 0 ? Math.Round(subScore / scount, 2) : 0;
  956. classResult.progress = true;
  957. tasks.Add(client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new PartitionKey($"{classResult.code}")));
  958. }
  959. await Task.WhenAll(tasks);
  960. }
  961. public static async Task<Settlement> getMore(CosmosClient client, ExamInfo info)
  962. {
  963. //计算单次考试简易统计信息
  964. Settlement settlement = new();
  965. List<ExamResult> examResults = new();
  966. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIteratorSql<ExamResult>(
  967. queryText: $"select value(c) from c where c.examId = '{info.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamResult-{info.id}") }))
  968. {
  969. examResults.Add(item);
  970. }
  971. if (examResults.Count > 0)
  972. {
  973. //记录某次考试所有学生得分总分
  974. double score = 0;
  975. double allScore = 0;
  976. int stuCount = 0;
  977. //标准差
  978. double powSum = 0;
  979. List<string> losStu = new List<string>();
  980. //当前完成考试得人数
  981. int total = examResults[0].studentIds.Distinct().Count();
  982. //先与第一个值取并集
  983. losStu = losStu.Union(examResults[0].lostStus).ToList();
  984. foreach (ExamResult examResult in examResults)
  985. {
  986. //取交集
  987. losStu = losStu.Intersect(examResult.lostStus).ToList();
  988. }
  989. //处理缺考的学生
  990. List<string> stus = examResults[0].studentIds.Except(losStu).ToList();
  991. foreach (ExamResult examResult in examResults)
  992. {
  993. foreach (var id in stus)
  994. {
  995. int index = examResult.studentIds.IndexOf(id);
  996. score += examResult.studentScores[index].Sum();
  997. }
  998. }
  999. stuCount = total - losStu.Count;
  1000. double NewsRateScore = stuCount > 0 ? Math.Round(score * 1.0 / stuCount, 2) : 0;
  1001. foreach (PaperSimple simple in info.papers)
  1002. {
  1003. allScore += simple.point.Sum();
  1004. }
  1005. //计算全科标准差
  1006. foreach (string id in stus)
  1007. {
  1008. double sc = 0;
  1009. foreach (ExamResult result in examResults)
  1010. {
  1011. if (result.studentScores.Count > 0)
  1012. {
  1013. sc += result.studentScores[result.studentIds.IndexOf(id)].Sum();
  1014. }
  1015. }
  1016. powSum += Math.Pow(sc - NewsRateScore, 2);
  1017. }
  1018. info.standard = Math.Round(total - losStu.Count > 0 ? Math.Pow(powSum / (total - losStu.Count), 0.5) : 0, 2);
  1019. double NewsRate = allScore > 0 ? Math.Round(NewsRateScore / allScore * 100, 2) : 0;
  1020. double qrate = Math.Round(total > 0 ? losStu.Count * 1.0 / total * 100 : 0, 2);
  1021. settlement.rate = NewsRate;
  1022. settlement.score = NewsRateScore;
  1023. settlement.stus = losStu;
  1024. settlement.total = total;
  1025. settlement.qrate = qrate;
  1026. }
  1027. return settlement;
  1028. }
  1029. //处理全部学生选题计数
  1030. public static async Task examRecordCount(ExamInfo info, ExamSubject subject, DingDing _dingDing, int no, ExamResult er, List<ExamClassResult> classResults, AzureCosmosFactory _azureCosmos)
  1031. {
  1032. try
  1033. {
  1034. List<double> scores = new List<double>();
  1035. foreach (List<double> sc in er.studentScores)
  1036. {
  1037. scores.Add(sc.Sum());
  1038. }
  1039. //确定高分组 最低分数
  1040. //var srowallorder = scores.EnumerateIndexed().OrderByDescending(g => g.Item2); //各生總分排序
  1041. //var srowallorder = scores.OrderByDescending(g => g);
  1042. double[] point = StringHelper.ListTodouble(er.paper.point);
  1043. double[,] result = StringHelper.ListToDouble(er.studentScores);
  1044. var cdm = new ClouDASMatrix(result, point);
  1045. scores.Sort((s1, s2) => { return s2.CompareTo(s1); });
  1046. int rhwCount = cdm.SH.Count();
  1047. double rhw = cdm.SH.LastOrDefault().Item2;
  1048. int rhlCount = cdm.SL.Count();
  1049. double rhl = cdm.SL.FirstOrDefault().Item2;
  1050. List<string> phs = new();
  1051. List<string> pls = new();
  1052. //分别获取高分组低分组人员
  1053. foreach (var ph in cdm.SH)
  1054. {
  1055. phs.Add(er.studentIds[ph.Item1]);
  1056. }
  1057. foreach (var pl in cdm.SL)
  1058. {
  1059. pls.Add(er.studentIds[pl.Item1]);
  1060. }
  1061. /* if (scores.Count > 3)
  1062. {
  1063. rhwCount = Convert.ToInt32(Math.Floor(scores.Count * 0.27));
  1064. rhw = rhwCount > 0 ? scores[rhwCount - 1] : 0;
  1065. rhlCount = Convert.ToInt32(Math.Ceiling(scores.Count * 0.73));
  1066. rhl = rhlCount > 0 ? scores[rhlCount] : 0;
  1067. }
  1068. else
  1069. {
  1070. rhwCount = Convert.ToInt32(Math.Floor(scores.Count * 0.27));
  1071. rhw = rhwCount > 0 ? scores[rhwCount] : 0;
  1072. rhlCount = Convert.ToInt32(Math.Ceiling(scores.Count * 0.73));
  1073. rhl = rhlCount > 0 ? scores[rhlCount - 1] : 0;
  1074. }*/
  1075. /*int rhwCount = Convert.ToInt32(Math.Floor(scores.Count * 0.27));
  1076. double rhw = rhwCount > 0 ? scores[rhwCount-1] : 0;
  1077. //var rhww = srowallorder.Take(Convert.ToInt32(Math.Floor(scores.Count * 0.27)));
  1078. //确定低分组 最高分数
  1079. //scores.Sort((s1, s2) => { return s1.CompareTo(s2); });
  1080. int rhlCount = Convert.ToInt32(Math.Ceiling(scores.Count * 0.73));
  1081. double rhl = rhlCount > 0 ? scores[rhlCount-1] : 0;*/
  1082. //var rhll = srowallorder.Skip(Convert.ToInt32(Math.Ceiling(scores.Count * 0.73)));
  1083. //存放高分组学生ID
  1084. List<string> phId = new();
  1085. List<string> plId = new();
  1086. List<List<List<string>>> opth = new();
  1087. List<List<List<string>>> optl = new();
  1088. List<double> akp = await knowledgeCount(info, subject, _dingDing, no, classResults, rhwCount, rhw, rhlCount, rhl, _azureCosmos);
  1089. List<double> afp = await fieldCount(info, subject, _dingDing, no, classResults, rhwCount, rhw, rhlCount, rhl, _azureCosmos);
  1090. int PHCount = 0;
  1091. int PLCount = 0;
  1092. foreach (ExamClassResult classResult in classResults)
  1093. {
  1094. if (classResult.subjectId.Equals(subject.id))
  1095. {
  1096. foreach (string id in classResult.studentIds)
  1097. {
  1098. int index = classResult.studentIds.IndexOf(id);
  1099. if (classResult.studentScores.Count > 0)
  1100. {
  1101. if (phs.Contains(id))
  1102. {
  1103. if (classResult.ans.Count > 0)
  1104. {
  1105. opth.Add(classResult.ans[index]);
  1106. PHCount++;
  1107. continue;
  1108. }
  1109. }
  1110. if (pls.Contains(id))
  1111. {
  1112. if (classResult.ans.Count > 0)
  1113. {
  1114. optl.Add(classResult.ans[index]);
  1115. PLCount++;
  1116. continue;
  1117. }
  1118. }
  1119. }
  1120. }
  1121. }
  1122. }
  1123. er.phc = getMore(info, no, opth);
  1124. er.plc = getMore(info, no, optl);
  1125. er.afp = afp;
  1126. er.akp = akp;
  1127. }
  1128. catch (Exception ex)
  1129. {
  1130. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测作答记录结算异常{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  1131. }
  1132. }
  1133. public static async Task<List<RGroupList>> Activity(CoreAPIHttpService _coreAPIHttpService, ExamInfo info, List<string> classes, CosmosClient client, DingDing _dingDing, List<string> sub, List<ExamClassResult> results)
  1134. {
  1135. List<(string pId, List<string> gid)> ps = new List<(string pId, List<string> gid)>();
  1136. if (info.groupLists.Count > 0)
  1137. {
  1138. var group = info.groupLists;
  1139. foreach (var gp in group)
  1140. {
  1141. foreach (KeyValuePair<string, List<string>> pp in gp)
  1142. {
  1143. ps.Add((pp.Key, pp.Value));
  1144. }
  1145. }
  1146. }
  1147. (List<RMember> tchList, List<RGroupList> classLists) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, classes, info.school, ps);
  1148. /*
  1149. var addStudentsCls = tchList.FindAll(x => x.type == 2);
  1150. var addTmdidsCls = tchList.FindAll(x => x.type == 1);
  1151. List<StuActivity> stuActivities = new List<StuActivity>();
  1152. List<StuActivity> tmdActivities = new List<StuActivity>();
  1153. var papers = info.papers.GroupBy(c => c.subjectId).Select(x => new
  1154. {
  1155. subject = x.Key,
  1156. blob = x.ToList().Select(z => z.blob).ToList()
  1157. });
  1158. bool flag = info.papers.Exists(c => c.subjectId != null);
  1159. if (addTmdidsCls.IsNotEmpty())
  1160. {
  1161. addTmdidsCls.ForEach(x =>
  1162. {
  1163. HashSet<string> classIds = new HashSet<string>();
  1164. classLists.ForEach(z =>
  1165. {
  1166. z.members.ForEach(y =>
  1167. {
  1168. if (y.id.Equals(x.id) && y.type == 1)
  1169. {
  1170. classIds.Add(z.id);
  1171. }
  1172. });
  1173. });
  1174. bool iss = false;
  1175. //标记学生作答状态
  1176. int ts = 0;
  1177. if (results.Count > 0)
  1178. {
  1179. foreach (ExamClassResult exam in results)
  1180. {
  1181. int index = exam.studentIds.IndexOf(x.id);
  1182. if (index != -1)
  1183. {
  1184. if (exam.studentAnswers[index].Count > 0)
  1185. {
  1186. bool flag = exam.studentScores[index].Exists(x => x == -1);
  1187. if (!flag)
  1188. {
  1189. ts = 1;
  1190. iss = true;
  1191. break;
  1192. }
  1193. else
  1194. {
  1195. ts = 0;
  1196. }
  1197. }
  1198. else
  1199. {
  1200. ts = -1;
  1201. }
  1202. }
  1203. }
  1204. }
  1205. else
  1206. {
  1207. ts = -1;
  1208. }
  1209. tmdActivities.Add(new StuActivity
  1210. {
  1211. pk = "Activity",
  1212. id = info.id,
  1213. code = $"Activity-{x.id}",
  1214. type = "Exam",
  1215. name = info.name,
  1216. source = info.source,
  1217. startTime = info.startTime,
  1218. endTime = info.endTime,
  1219. scode = info.code,
  1220. scope = info.scope,
  1221. school = info.school,
  1222. creatorId = info.creatorId,
  1223. subjects = sub,
  1224. blob = null,
  1225. paper = flag ? papers.Select(c => new
  1226. {
  1227. c.subject,
  1228. blob = c.blob[new Random().Next(c.blob.Count)]
  1229. }) : "",
  1230. owner = info.owner,
  1231. createTime = info.createTime,
  1232. taskStatus = ts,
  1233. qamode = info.qamode,
  1234. ext = new Dictionary<string, JsonElement>() { { "type", info.examType.ToJsonString().ToObject<JsonElement>() },
  1235. { "subjects", info.subjects.ToJsonString().ToObject<JsonElement>() } },
  1236. sStatus = iss ? 1 : 0,
  1237. classIds = classIds.ToList()
  1238. }); ;
  1239. });
  1240. }
  1241. if (addStudentsCls.IsNotEmpty())
  1242. {
  1243. addStudentsCls.ForEach(x =>
  1244. {
  1245. HashSet<string> classIds = new HashSet<string>();
  1246. classLists.ForEach(z =>
  1247. {
  1248. z.members.ForEach(y =>
  1249. {
  1250. if (y.id.Equals(x.id) && y.code.Equals(info.school) && y.type == 2)
  1251. {
  1252. classIds.Add(z.id);
  1253. }
  1254. });
  1255. });
  1256. bool iss = false;
  1257. //标记学生作答状态
  1258. int ts = 0;
  1259. if (results.Count > 0)
  1260. {
  1261. foreach (ExamClassResult exam in results)
  1262. {
  1263. int index = exam.studentIds.IndexOf(x.id);
  1264. if (index != -1)
  1265. {
  1266. if (exam.studentAnswers[index].Count > 0)
  1267. {
  1268. bool flag = exam.studentScores[index].Exists(x => x == -1);
  1269. if (!flag)
  1270. {
  1271. ts = 1;
  1272. iss = true;
  1273. break;
  1274. }
  1275. else
  1276. {
  1277. ts = 0;
  1278. }
  1279. }
  1280. else
  1281. {
  1282. ts = -1;
  1283. }
  1284. }
  1285. }
  1286. }
  1287. else
  1288. {
  1289. ts = -1;
  1290. }
  1291. stuActivities.Add(new StuActivity
  1292. {
  1293. pk = "Activity",
  1294. id = info.id,
  1295. code = $"Activity-{x.code.Replace("Base-", "")}-{x.id}",
  1296. type = "Exam",
  1297. name = info.name,
  1298. source = info.source,
  1299. startTime = info.startTime,
  1300. endTime = info.endTime,
  1301. scode = info.code,
  1302. scope = info.scope,
  1303. school = info.school,
  1304. creatorId = info.creatorId,
  1305. subjects = sub,
  1306. blob = null,
  1307. paper = flag ? papers.Select(c => new
  1308. {
  1309. c.subject,
  1310. blob = c.blob[new Random().Next(c.blob.Count)]
  1311. }) : "",
  1312. owner = info.owner,
  1313. classIds = classIds.ToList(),
  1314. createTime = info.createTime,
  1315. qamode = info.qamode,
  1316. ext = new Dictionary<string, JsonElement>() { { "type", info.examType.ToJsonString().ToObject<JsonElement>() },
  1317. { "subjects", info.subjects.ToJsonString().ToObject<JsonElement>() } },
  1318. taskStatus = ts,
  1319. sStatus = iss ? 1 : 0,
  1320. });
  1321. });
  1322. }
  1323. await IESActivityService.SaveStuActivity(client, _dingDing, stuActivities, tmdActivities, null);
  1324. */
  1325. return classLists;
  1326. }
  1327. public static async Task<List<double>> knowledgeCount(ExamInfo info, ExamSubject subject, DingDing _dingDing, int no, List<ExamClassResult> classResults,
  1328. double rhwCount, double rhw, double rhlCount, double rhl, AzureCosmosFactory _azureCosmos)
  1329. {
  1330. List<double> akp = new();
  1331. try
  1332. {
  1333. int phcount = 0;
  1334. int plcount = 0;
  1335. //存放并去重知识点
  1336. HashSet<string> kname = new HashSet<string>();
  1337. if (info.papers[no].knowledge.Count > 0)
  1338. {
  1339. info.papers[no].knowledge.ForEach(kno =>
  1340. {
  1341. kno.ForEach(k =>
  1342. {
  1343. kname.Add(k);
  1344. });
  1345. });
  1346. List<string> knowledgeName = new List<string>();
  1347. foreach (string cla in kname)
  1348. {
  1349. knowledgeName.Add(cla);
  1350. }
  1351. for (int k = 0; k < knowledgeName.Count; k++)
  1352. {
  1353. if (null == knowledgeName[k])
  1354. {
  1355. knowledgeName.Remove(knowledgeName[k]);
  1356. }
  1357. }
  1358. foreach (ExamClassResult classResult in classResults)
  1359. {
  1360. if (classResult.subjectId.Equals(subject.id))
  1361. {
  1362. //List<int> phc = new List<int>();
  1363. List<int> ph = new List<int>();
  1364. List<int> pl = new List<int>();
  1365. List<int> pc = new List<int>();
  1366. List<double> persent = new List<double>();
  1367. int lostStu = classResult.status.Where(c => c == 1).ToList().Count;
  1368. for (int i = 0; i < knowledgeName.Count; i++)
  1369. {
  1370. //初始化单个知识点得分
  1371. double score = 0;
  1372. int n = 0;
  1373. int phCount = 0;
  1374. int plCount = 0;
  1375. int pCount = 0;
  1376. double classScore = 0;
  1377. foreach (List<string> str in info.papers[no].knowledge)
  1378. {
  1379. if (str.Contains(knowledgeName[i]))
  1380. {
  1381. var itemPersent = str.Count > 0 ? 1 / Convert.ToDouble(str.Count) : 0;
  1382. classScore += info.papers[no].point.Count > 0 ? (info.papers[no].point[n] * itemPersent) : 0;
  1383. foreach (string id in classResult.studentIds)
  1384. {
  1385. int index = classResult.studentIds.IndexOf(id);
  1386. if (classResult.studentScores.Count > 0)
  1387. {
  1388. if (classResult.studentScores[index].Count > 0)
  1389. {
  1390. double realScore = classResult.studentScores[index][n] == -1 ? 0 : classResult.studentScores[index][n] * itemPersent;
  1391. score += realScore;
  1392. //score += classResult.studentScores[index][n] == -1 ? 0 : classResult.studentScores[index][n] * itemPersent;
  1393. if (classResult.studentScores[index].Sum() >= rhw && phcount < rhwCount)
  1394. {
  1395. if (classResult.studentScores[index][n] <= 0)
  1396. {
  1397. phCount++;
  1398. }
  1399. phcount++;
  1400. continue;
  1401. }
  1402. if (classResult.studentScores[index].Sum() <= rhl && plcount < (info.stuCount - rhlCount))
  1403. {
  1404. if (classResult.studentScores[index][n] <= 0)
  1405. {
  1406. plCount++;
  1407. }
  1408. plcount++;
  1409. continue;
  1410. }
  1411. if (classResult.studentScores[index][n] <= 0)
  1412. {
  1413. pCount++;
  1414. }
  1415. }
  1416. }
  1417. }
  1418. }
  1419. n++;
  1420. }
  1421. pc.Add(pCount);
  1422. ph.Add(phCount);
  1423. pl.Add(plCount);
  1424. double per = classResult.studentIds.Count - lostStu > 0 ? Math.Round(score / (classResult.studentIds.Count - lostStu), 2) : 0;
  1425. persent.Add(classScore > 0 ? Math.Round(per * 1.0 / classScore, 2) : 0);
  1426. }
  1427. classResult.phc = ph;
  1428. classResult.plc = pl;
  1429. classResult.pc = pc;
  1430. classResult.krate = persent;
  1431. }
  1432. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new PartitionKey($"{classResult.code}"));
  1433. }
  1434. foreach (string k in knowledgeName)
  1435. {
  1436. double score = 0;
  1437. double allScore = 0;
  1438. int count = 0;
  1439. int m = 0;
  1440. foreach (List<string> str in info.papers[no].knowledge)
  1441. {
  1442. if (str.Contains(k))
  1443. {
  1444. var itemPersent = str.Count > 0 ? 1 / Convert.ToDouble(str.Count) : 0;
  1445. allScore += info.papers[no].point.Count > 0 ? info.papers[no].point[m] * itemPersent : 0;
  1446. }
  1447. m++;
  1448. }
  1449. foreach (ExamClassResult result in classResults)
  1450. {
  1451. if (result.subjectId.Equals(subject.id))
  1452. {
  1453. int n = 0;
  1454. foreach (List<string> str in info.papers[no].knowledge)
  1455. {
  1456. if (str.Contains(k))
  1457. {
  1458. var itemPersent = str.Count > 0 ? 1 / Convert.ToDouble(str.Count) : 0;
  1459. if (result.studentScores.Count > 0)
  1460. {
  1461. foreach (List<double> sc in result.studentScores)
  1462. {
  1463. double tsc = sc[n] == -1 ? 0 : sc[n];
  1464. score += (tsc * itemPersent);
  1465. }
  1466. }
  1467. }
  1468. n++;
  1469. }
  1470. count += result.studentIds.Count;
  1471. }
  1472. }
  1473. double per = count - info.lostStu.Count > 0 ? Math.Round(score / (count - info.lostStu.Count), 2) : 0;
  1474. akp.Add(allScore > 0 ? Math.Round(per / allScore, 2) : 0);
  1475. }
  1476. }
  1477. return akp;
  1478. }
  1479. catch (Exception ex)
  1480. {
  1481. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测知识点结算异常{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  1482. return null;
  1483. }
  1484. }
  1485. public static async Task<List<double>> fieldCount(ExamInfo info, ExamSubject subject, DingDing _dingDing, int no, List<ExamClassResult> classResults,
  1486. double rhwCount, double rhw, double rhlCount, double rhl, AzureCosmosFactory _azureCosmos)
  1487. {
  1488. List<double> afp = new();
  1489. try
  1490. {
  1491. int phcount = 0;
  1492. int plcount = 0;
  1493. //存放并去重知识点
  1494. List<int> knowledgeName = new List<int>() { 1, 2, 3, 4, 5, 6 };
  1495. /* knowledgeName.Add(1);
  1496. knowledgeName.Add(2);
  1497. knowledgeName.Add(3);
  1498. knowledgeName.Add(4);
  1499. knowledgeName.Add(5);
  1500. knowledgeName.Add(6);*/
  1501. foreach (ExamClassResult classResult in classResults)
  1502. {
  1503. if (classResult.subjectId.Equals(subject.id))
  1504. {
  1505. //List<int> phc = new List<int>();
  1506. List<int> ph = new List<int>();
  1507. List<int> pl = new List<int>();
  1508. List<int> pc = new List<int>();
  1509. List<double> persent = new List<double>();
  1510. int lostStu = classResult.status.Where(c => c == 1).ToList().Count;
  1511. for (int i = 0; i < knowledgeName.Count; i++)
  1512. {
  1513. //初始化单个知识点得分
  1514. double score = 0;
  1515. int n = 0;
  1516. int phCount = 0;
  1517. int plCount = 0;
  1518. int pCount = 0;
  1519. double classScore = 0;
  1520. if (info.papers[no].field.Count > 0)
  1521. {
  1522. foreach (int str in info.papers[no].field)
  1523. {
  1524. if (str == knowledgeName[i])
  1525. {
  1526. var itemPersent = 1;
  1527. classScore += info.papers[no].point.Count > 0 ? info.papers[no].point[n] * itemPersent : 0;
  1528. foreach (string id in classResult.studentIds)
  1529. {
  1530. int index = classResult.studentIds.IndexOf(id);
  1531. if (classResult.studentScores.Count > 0)
  1532. {
  1533. if (classResult.studentScores[index].Count > 0)
  1534. {
  1535. score += classResult.studentScores[index][n] == -1 ? 0 : classResult.studentScores[index][n];
  1536. if (classResult.studentScores[index].Sum() >= rhw && phcount < rhwCount)
  1537. {
  1538. if (classResult.studentScores[index][n] <= 0)
  1539. {
  1540. phCount++;
  1541. }
  1542. phcount++;
  1543. continue;
  1544. }
  1545. if (classResult.studentScores[index].Sum() <= rhl && plcount < (info.stuCount - rhlCount))
  1546. {
  1547. if (classResult.studentScores[index][n] <= 0)
  1548. {
  1549. plCount++;
  1550. }
  1551. plcount++;
  1552. continue;
  1553. }
  1554. if (classResult.studentScores[index][n] <= 0)
  1555. {
  1556. pCount++;
  1557. }
  1558. }
  1559. }
  1560. }
  1561. }
  1562. n++;
  1563. }
  1564. pc.Add(pCount);
  1565. ph.Add(phCount);
  1566. pl.Add(plCount);
  1567. double per = classResult.studentIds.Count - lostStu > 0 ? Math.Round(score / (classResult.studentIds.Count - lostStu), 2) : 0;
  1568. persent.Add(classScore > 0 ? Math.Round(per / classScore, 2) : 0);
  1569. }
  1570. }
  1571. classResult.fphc = ph;
  1572. classResult.fplc = pl;
  1573. classResult.fpc = pc;
  1574. classResult.frate = persent;
  1575. }
  1576. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new PartitionKey($"{classResult.code}"));
  1577. }
  1578. for (int i = 0; i < knowledgeName.Count; i++)
  1579. {
  1580. double score = 0;
  1581. double allScore = 0;
  1582. int count = 0;
  1583. int m = 0;
  1584. foreach (int str in info.papers[no].field)
  1585. {
  1586. if (str == knowledgeName[i])
  1587. {
  1588. var itemPersent = 1;
  1589. allScore += info.papers[no].point.Count > 0 ? info.papers[no].point[m] * itemPersent : 0;
  1590. }
  1591. m++;
  1592. }
  1593. foreach (ExamClassResult result in classResults)
  1594. {
  1595. if (result.subjectId.Equals(subject.id))
  1596. {
  1597. int n = 0;
  1598. foreach (int str in info.papers[no].field)
  1599. {
  1600. var itemPersent = 1;
  1601. if (str == knowledgeName[i])
  1602. {
  1603. if (result.studentScores.Count > 0)
  1604. {
  1605. foreach (List<double> sc in result.studentScores)
  1606. {
  1607. double tsc = sc[n] == -1 ? 0 : sc[n];
  1608. score += tsc * itemPersent;
  1609. }
  1610. }
  1611. }
  1612. n++;
  1613. }
  1614. count += result.studentIds.Count;
  1615. }
  1616. }
  1617. double per = count - info.lostStu.Count > 0 ? Math.Round(score / (count - info.lostStu.Count), 2) : 0;
  1618. afp.Add(allScore > 0 ? Math.Round(per / allScore, 2) : 0);
  1619. }
  1620. return afp;
  1621. }
  1622. catch (Exception ex)
  1623. {
  1624. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测认知层次结算异常{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  1625. return null;
  1626. }
  1627. }
  1628. //处理选题计数
  1629. public static List<Dictionary<string, int>> getMore(ExamInfo info, int no, List<List<List<string>>> list)
  1630. {
  1631. List<Dictionary<string, int>> recorde = new List<Dictionary<string, int>>();
  1632. try
  1633. {
  1634. for (int i = 0; i < info.papers[no].answers.Count; i++)
  1635. {
  1636. if (info.papers[no].answers[i].Count <= 0)
  1637. {
  1638. recorde.Add(new Dictionary<string, int>());
  1639. continue;
  1640. }
  1641. Dictionary<string, int> optCount = new Dictionary<string, int>();
  1642. foreach (List<List<string>> stu in list)
  1643. {
  1644. if (stu.Count == info.papers[no].answers.Count)
  1645. {
  1646. var item = stu[i];
  1647. foreach (string opt in item)
  1648. {
  1649. if (optCount.ContainsKey(opt))
  1650. {
  1651. optCount[opt] = optCount[opt] + 1;
  1652. }
  1653. else
  1654. {
  1655. optCount[opt] = 1;
  1656. }
  1657. }
  1658. }
  1659. }
  1660. recorde.Add(optCount);
  1661. }
  1662. return recorde;
  1663. }
  1664. catch (Exception)
  1665. {
  1666. return recorde;
  1667. }
  1668. }
  1669. public static async Task createClassResultAsync(ExamInfo info, List<ExamClassResult> examClassResults, ExamSubject subject, int no, AzureCosmosFactory _azureCosmos, DingDing _dingDing, AzureStorageFactory _azureStorage, IHttpClientFactory _httpClient, IConfiguration _configuration)
  1670. {
  1671. //保证试卷信息与科目信息同步
  1672. ExamResult result = new ExamResult();
  1673. //人数总和
  1674. int Count = 0;
  1675. int m = 0;
  1676. double score = 0;
  1677. //标准差
  1678. //double powSum = 0;
  1679. double allScore = info.papers[no].point.Sum();
  1680. List<ClassRange> classRanges = new List<ClassRange>();
  1681. List<string> lostStu = new List<string>();
  1682. List<double> csRate = new List<double>();
  1683. List<List<List<string>>> opt = new List<List<List<string>>>();
  1684. //List<Task<ItemResponse<ExamClassResult>>> tasks = new();
  1685. foreach (ExamClassResult classResult in examClassResults)
  1686. {
  1687. double classSrate = 0;
  1688. if (classResult.subjectId.Equals(subject.id))
  1689. {
  1690. foreach (List<List<string>> op in classResult.ans)
  1691. {
  1692. opt.Add(op);
  1693. }
  1694. //记录缺考学生索引位置
  1695. int index_stu = 0;
  1696. foreach (var ans in classResult.studentAnswers)
  1697. {
  1698. if (ans.Count == 0)
  1699. {
  1700. if (!lostStu.Contains(classResult.studentIds[index_stu]))
  1701. {
  1702. lostStu.Add(classResult.studentIds[index_stu]);
  1703. }
  1704. }
  1705. else
  1706. {
  1707. if (classResult.status[index_stu] == 1)
  1708. {
  1709. if (!lostStu.Contains(classResult.studentIds[index_stu]))
  1710. {
  1711. lostStu.Add(classResult.studentIds[index_stu]);
  1712. }
  1713. }
  1714. }
  1715. index_stu++;
  1716. }
  1717. int index = 0;
  1718. foreach (List<double> scores in classResult.studentScores)
  1719. {
  1720. List<double> newScores = new List<double>();
  1721. //int count = 0;
  1722. if (scores.Count > 0)
  1723. {
  1724. foreach (double sc in scores)
  1725. {
  1726. newScores.Add(sc > -1 ? sc : 0);
  1727. }
  1728. }
  1729. else
  1730. {
  1731. newScores.Add(0);
  1732. }
  1733. classSrate += newScores.Sum();
  1734. score += newScores.Sum();
  1735. result.studentScores.Add(newScores);
  1736. index++;
  1737. }
  1738. //处理班级信息
  1739. ClassRange range = new ClassRange();
  1740. range.id = classResult.info.id;
  1741. range.name = classResult.info.name;
  1742. range.gradeId = classResult.gradeId;
  1743. List<int> ran = new List<int>();
  1744. int stuCount = classResult.studentIds.Count;
  1745. //todo 与实际的缺考人数比较
  1746. int lostStus = classResult.status.Where(c => c == 1).ToList().Count;
  1747. Count += stuCount;
  1748. if (m == 0)
  1749. {
  1750. ran.Add(0);
  1751. ran.Add(stuCount - 1);
  1752. }
  1753. else
  1754. {
  1755. ran.Add(Count - stuCount);
  1756. ran.Add(Count - 1);
  1757. }
  1758. m++;
  1759. range.range = ran;
  1760. classRanges.Add(range);
  1761. //处理学生ID
  1762. foreach (string id in classResult.studentIds)
  1763. {
  1764. result.studentIds.Add(id);
  1765. }
  1766. if (allScore > 0)
  1767. {
  1768. csRate.Add(classResult.studentIds.Count - lostStus > 0 ? Math.Round(classSrate * 1.0 / (classResult.studentIds.Count - lostStus), 2) : 0 / allScore);
  1769. }
  1770. else
  1771. {
  1772. csRate.Add(0);
  1773. }
  1774. //powSum += Math.Pow(classSrate - result.average, 2);
  1775. //处理选项计数内容
  1776. }
  1777. //tasks.Add(_azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new PartitionKey($"{classResult.code}")));
  1778. }
  1779. //await tasks.TaskPage(10);
  1780. /*foreach (string id in result.lostStus) {
  1781. if (!examClassResults[0].studentIds.Contains(id)) {
  1782. int index = result.lostStus.IndexOf(id);
  1783. result.lostStus.RemoveAt(index);
  1784. }
  1785. }*/
  1786. //处理人员变更时被移除的人员
  1787. result.lostStus = lostStu;
  1788. List<string> stuIds = examClassResults.SelectMany(x => x.studentIds).ToList();
  1789. if (result.lostStus.Count > 0)
  1790. {
  1791. for (int i = 0; i < result.lostStus.Count; i++)
  1792. {
  1793. if (!stuIds.Contains(result.lostStus[i]))
  1794. {
  1795. result.lostStus.RemoveAt(i);
  1796. }
  1797. }
  1798. }
  1799. result.record = getMore(info, no, opt);
  1800. result.average = result.studentIds.Count - result.lostStus.Count > 0 ? Math.Round(score * 1.0 / (result.studentIds.Count - result.lostStus.Count), 2) : 0;
  1801. double powSum = 0;
  1802. //int sco = 0;
  1803. result.studentIds.ForEach(x =>
  1804. {
  1805. double sc = result.studentScores[result.studentIds.IndexOf(x)].Sum();
  1806. if (!result.lostStus.Contains(x))
  1807. {
  1808. powSum += Math.Pow(sc - result.average, 2);
  1809. }
  1810. });
  1811. result.standard = Math.Round((result.studentIds.Count - result.lostStus.Count) > 0 ? Math.Pow(powSum / (result.studentIds.Count - result.lostStus.Count), 0.5) : 0, 2);
  1812. result.csRate = csRate;
  1813. result.sRate = allScore > 0 ? Math.Round(result.average / allScore * 100, 2) : 0;
  1814. result.classes = classRanges;
  1815. result.code = "ExamResult-" + info.id;
  1816. result.school = info.school;
  1817. result.id = subject.id;
  1818. result.examId = info.id;
  1819. result.subjectId = subject.id;
  1820. result.year = info.year;
  1821. result.paper = info.papers[no];
  1822. //result.point = info.papers[j].point;
  1823. result.scope = info.scope;
  1824. result.name = info.name;
  1825. result.time = info.startTime;
  1826. if (info.qamode != 2) {
  1827. await examRecordCount(info, subject, _dingDing, no, result, examClassResults, _azureCosmos);
  1828. }
  1829. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").UpsertItemAsync(result, new PartitionKey($"ExamResult-{info.id}"));
  1830. List<ErrorItems> errorItems = new();
  1831. string code = string.Empty;
  1832. string pk = string.Empty;
  1833. string table = "School";
  1834. if (info.scope.Equals("school"))
  1835. {
  1836. code = $"ErrorItems-{info.school}";
  1837. pk = $"Item-{info.school}";
  1838. }
  1839. else
  1840. {
  1841. code = "ErrorItems";
  1842. pk = $"Item-{info.creatorId}";
  1843. table = "Teacher";
  1844. }
  1845. if (result.studentIds.Any()) {
  1846. string sqlqueryText = $"select value(c) from c where c.activityId = '{info.id}'and c.subjectId = '{info.subjects[no].id}' and c.stuId in ({string.Join(",", result.studentIds.Select(x => $"'{x}'"))})";
  1847. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Student").GetItemQueryIteratorSql<ErrorItems>(queryText: sqlqueryText, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
  1848. {
  1849. errorItems.Add(item);
  1850. }
  1851. try
  1852. {
  1853. /* bool isError = examClassResults.SelectMany(c => c.status).ToList().Exists(z => z == 1);
  1854. if () {
  1855. }*/
  1856. if (errorItems.Count == 0 && info.qamode != 2)
  1857. {
  1858. // 新增逻辑 收集错题内容
  1859. BlobDownloadResult index_json;
  1860. if (info.scope.Equals("school"))
  1861. {
  1862. index_json = await _azureStorage.GetBlobContainerClient($"{info.school}").GetBlobClient($"{info.papers[no].blob}/index.json").DownloadContentAsync();
  1863. }
  1864. else
  1865. {
  1866. index_json = await _azureStorage.GetBlobContainerClient($"{info.creatorId}").GetBlobClient($"{info.papers[no].blob}/index.json").DownloadContentAsync();
  1867. }
  1868. //BlobDownloadResult index_json = await _azureStorage.GetBlobContainerClient($"{info.school}").GetBlobClient($"{info.papers[no].blob}/index.json").DownloadContentAsync();
  1869. JsonElement RecordingJson = JsonDocument.Parse(new MemoryStream(Encoding.UTF8.GetBytes(index_json.Content.ToString()))).RootElement;
  1870. RecordingJson.TryGetProperty("slides", out JsonElement slides);
  1871. int qamode = info.qamode;
  1872. if (RecordingJson.TryGetProperty("qamode", out JsonElement element))
  1873. {
  1874. qamode = element.GetInt32();
  1875. }
  1876. var sdes = slides.ToObject<List<Slides>>();
  1877. List<string> attachments = new List<string>();
  1878. if (qamode == 1)
  1879. {
  1880. attachments = RecordingJson.GetProperty("attachments").ToObject<List<string>>();
  1881. if (attachments.Count == 0)
  1882. {
  1883. return;
  1884. }
  1885. }
  1886. List<string> urls = new();
  1887. foreach (var ne in sdes)
  1888. {
  1889. if (!ne.type.Equals("compose"))
  1890. {
  1891. urls.Add(ne.url);
  1892. }
  1893. }
  1894. // 获取整体的题目ID集合
  1895. List<string> ids = new();
  1896. List<(string id, string pid, int level, string type, List<string> knows)> itemInfos = new();
  1897. foreach (string url in urls)
  1898. {
  1899. string id = url.Replace(".json", "");
  1900. BlobDownloadResult index_item_json;
  1901. if (info.scope.Equals("school"))
  1902. {
  1903. index_item_json = await _azureStorage.GetBlobContainerClient($"{info.school}").GetBlobClient($"{info.papers[no].blob}/{url}").DownloadContentAsync();
  1904. }
  1905. else
  1906. {
  1907. index_item_json = await _azureStorage.GetBlobContainerClient($"{info.creatorId}").GetBlobClient($"{info.papers[no].blob}/{url}").DownloadContentAsync();
  1908. }
  1909. JsonElement itemJson = JsonDocument.Parse(new MemoryStream(Encoding.UTF8.GetBytes(index_item_json.Content.ToString()))).RootElement;
  1910. itemJson.TryGetProperty("exercise", out JsonElement exercise);
  1911. //itemJson.TryGetProperty("pid", out JsonElement pid);
  1912. var item_json = exercise.ToObject<Exercise>();
  1913. //JObject keys = JObject.Parse(index_item_json.Content.ToString());
  1914. string type = item_json.type;
  1915. int level = item_json.level;
  1916. var knowledge = item_json.knowledges;
  1917. //string pid = keys.Value<string>("pid");
  1918. if (itemJson.TryGetProperty("pid", out JsonElement pid))
  1919. {
  1920. itemInfos.Add((id, pid.ToString(), level, type, knowledge));
  1921. }
  1922. else
  1923. {
  1924. itemInfos.Add((id, "", level, type, knowledge));
  1925. }
  1926. }
  1927. /* double[] point = StringHelper.ListTodouble(result.paper.point);
  1928. double[,] res = StringHelper.ListToDouble(result.studentScores);
  1929. var cdm = new ClouDASMatrix(res, point);*/
  1930. //需要努力的题目
  1931. //var ss = cdm.StriveTopic;
  1932. int n = 0;
  1933. List<Task<ItemResponse<ErrorItems>>> task_error = new();
  1934. List<ErrorItems> errors = new();
  1935. foreach (var sIds in result.studentIds)
  1936. {
  1937. ErrorItems error = new()
  1938. {
  1939. ttl = -1,
  1940. code = code,
  1941. id = Guid.NewGuid().ToString(),
  1942. stuId = sIds,
  1943. school = info.school,
  1944. activityId = info.id,
  1945. subjectId = result.subjectId,
  1946. time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
  1947. };
  1948. int index_stu = result.studentIds.IndexOf(sIds);
  1949. //顺序学生错题的索引
  1950. var itemScore = result.studentScores[index_stu];
  1951. List<int> index = new();
  1952. int index_item = 0;
  1953. foreach (var sc in itemScore)
  1954. {
  1955. if (sc == 0)
  1956. {
  1957. index.Add(index_item + 1);
  1958. }
  1959. index_item++;
  1960. }
  1961. if (index.Count == 0)
  1962. {
  1963. continue;
  1964. }
  1965. //int[] item_index = ss[n];
  1966. foreach (var item in index)
  1967. {
  1968. Items items = new()
  1969. {
  1970. id = urls[item - 1].Replace(".json", ""),
  1971. blob = info.papers[no].blob
  1972. };
  1973. items.level = itemInfos.Where(c => c.id.Equals(items.id)).FirstOrDefault().level;
  1974. items.type = itemInfos.Where(c => c.id.Equals(items.id)).FirstOrDefault().type;
  1975. items.pId = itemInfos.Where(c => c.id.Equals(items.id)).FirstOrDefault().pid;
  1976. items.knowledge = itemInfos.Where(c => c.id.Equals(items.id)).FirstOrDefault().knows;
  1977. items.qamode = qamode;
  1978. error.its.Add(items);
  1979. }
  1980. errors.Add(error);
  1981. n++;
  1982. task_error.Add(_azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student").CreateItemAsync(error, new PartitionKey($"{error.code}")));
  1983. }
  1984. //string connect = _configuration.GetValue<string>("HaBookAuth:Crtmabank") + "https://malearnfunction.chinacloudsites.cn/api/crtmabank";
  1985. string location = $"{Environment.GetEnvironmentVariable("Option:Location")}";
  1986. string urlAction = string.Empty;
  1987. string accessKey = string.Empty;
  1988. if (location.Contains("China"))
  1989. {
  1990. if (location.Equals("China")) //大陸正式站
  1991. {
  1992. urlAction = "https://malearn.teammodel.cn";
  1993. accessKey = "2BcXFR_hvzG1pZjqIkaM7Dx74Hcu6m0PwwOacFpDpq44AzFuHJBRXA==";
  1994. }
  1995. else if (location.Equals("China-Dep") || location.Equals("China-Test")) //大陸測試站
  1996. {
  1997. urlAction = "https://malearn-rc.teammodel.cn";
  1998. accessKey = "lghWhJduNiAlo-e8isqEoROjdR7DAC-50XNtanIwHKYlAzFu1aog_A==";
  1999. }
  2000. }
  2001. else if (location.Contains("Global"))
  2002. {
  2003. if (location.Equals("Global")) //國際正式站
  2004. {
  2005. urlAction = "https://malearn.teammodel.net";
  2006. accessKey = "I-2lTcdggJkZWSBwOXQIm4oHx-huwX3d0wLe-9pgojThAzFuq_KNFg==";
  2007. }
  2008. else if (location.Equals("Global-Test")) //國際測試站
  2009. {
  2010. urlAction = "https://malearn-rc.teammodel.net";
  2011. accessKey = "_l4Cb_tHIRBw_iv3ZuwVqjkMwjg4_HtDaxhAmZ8OwJraAzFu_DAY8A==";
  2012. }
  2013. }
  2014. string connect = $"{urlAction}/api/crtmabank";
  2015. var htc = _httpClient.CreateClient();
  2016. if (htc.DefaultRequestHeaders.Contains("x-functions-key"))
  2017. {
  2018. htc.DefaultRequestHeaders.Remove("x-functions-key");
  2019. }
  2020. htc.DefaultRequestHeaders.Add("x-functions-key", accessKey);
  2021. ///智慧題庫school欄位修正
  2022. foreach (ErrorItems error in errors)
  2023. {
  2024. error.school = (info.scope.Equals("school")) ? info.school : string.Empty;
  2025. }
  2026. string paramJson = JsonConvert.SerializeObject(errors);
  2027. var content = new StringContent(paramJson, Encoding.UTF8, "application/json");
  2028. var response = await htc.PostAsync(connect, content);
  2029. if ((int)response.StatusCode == 200)
  2030. {
  2031. await task_error.TaskPage(10);
  2032. }
  2033. }
  2034. }
  2035. catch (Exception e)
  2036. {
  2037. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测错题异常{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  2038. }
  2039. }
  2040. }
  2041. public class Settlement
  2042. {
  2043. public double rate { get; set; }
  2044. public double score { get; set; }
  2045. public List<string> stus { get; set; } = new List<string>();
  2046. public int total { get; set; }
  2047. public double qrate { get; set; }
  2048. }
  2049. #region ===學習記錄用類別===
  2050. private class PaperIndex
  2051. {
  2052. public PaperIndex()
  2053. {
  2054. slides = new List<Slide>();
  2055. }
  2056. public List<Slide> slides { get; set; }
  2057. }
  2058. private class Slide
  2059. {
  2060. /// <summary>
  2061. /// blob 路徑
  2062. /// </summary>
  2063. public string url { get; set; }
  2064. /// <summary>
  2065. /// 題型
  2066. /// </summary>
  2067. public string type { get; set; }
  2068. /// <summary>
  2069. /// scoring
  2070. /// </summary>
  2071. public Scoring scoring { get; set; }
  2072. }
  2073. private class Exercise
  2074. {
  2075. /// <summary>
  2076. /// 题目类型
  2077. /// </summary>
  2078. public string type { get; set; }
  2079. /// <summary>
  2080. /// 难度
  2081. /// </summary>
  2082. public int level { get; set; }
  2083. /// <summary>
  2084. /// 知识点
  2085. /// </summary>
  2086. public List<string> knowledges { get; set; }
  2087. }
  2088. private class Scoring
  2089. {
  2090. /// <summary>
  2091. /// knowledge
  2092. /// </summary>
  2093. public List<string> knowledge { get; set; }
  2094. /// <summary>
  2095. /// 答案
  2096. /// </summary>
  2097. public List<string> ans { get; set; }
  2098. }
  2099. private class StudentAnswers
  2100. {
  2101. /// <summary>
  2102. /// 學生作答 blob 路徑
  2103. /// </summary>
  2104. public List<List<string>> studentAnswers { get; set; }
  2105. /// <summary>
  2106. /// 學生ID
  2107. /// </summary>
  2108. public List<string> studentIds { get; set; } = new();
  2109. }
  2110. private class QuestionData
  2111. {
  2112. public QuestionData()
  2113. {
  2114. item = new List<QuestionItem>();
  2115. }
  2116. public QuestionExercise exercise { get; set; }
  2117. public List<QuestionItem> item { get; set; }
  2118. }
  2119. private class QuestionItem
  2120. {
  2121. public QuestionItem()
  2122. {
  2123. option = new List<OptionItem>();
  2124. }
  2125. public string question { get; set; }
  2126. public List<OptionItem> option { get; set; }
  2127. }
  2128. private class OptionItem
  2129. {
  2130. public string code { get; set; }
  2131. public string value { get; set; }
  2132. }
  2133. private class QuestionExercise
  2134. {
  2135. public string type { get; set; }
  2136. public List<string> knowledge { get; set; }
  2137. public List<string> answer { get; set; }
  2138. }
  2139. #endregion
  2140. }
  2141. }