TriggerExam.cs 121 KB

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