TriggerExam.cs 121 KB

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