TriggerExam.cs 123 KB

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