TriggerExam.cs 122 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230
  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. /// <summary>
  774. ///
  775. /// </summary>
  776. /// <param name="questionData"></param>
  777. /// <param name="learnRecordItem"></param>
  778. private static void setCorrectChoices(QuestionData questionData, LearnRecordItem learnRecordItem)
  779. {
  780. #region === Correct Choices ===
  781. #region === 是非題邏輯 ===
  782. if (questionData.exercise.type == "judge" && questionData.exercise.answer.Count > 0)
  783. {// 如果是是非題 正確答案要用true false的方式設定
  784. if (questionData.exercise.answer[0] == "A")
  785. {
  786. learnRecordItem.Correct = new string[] { "true" };
  787. }
  788. else
  789. {
  790. learnRecordItem.Correct = new string[] { "false" };
  791. }
  792. }
  793. else
  794. {// 防呆 去html標籤
  795. if (questionData.exercise.answer.Count > 0)
  796. {
  797. List<string> anslist = new();
  798. foreach (var answer in questionData.exercise.answer)
  799. {
  800. // 使用HtmlAgilityPack解析HTML
  801. HtmlDocument doc = new HtmlDocument();
  802. doc.LoadHtml(answer);
  803. // 再取純文字
  804. anslist.Add(doc.DocumentNode.InnerText);
  805. }
  806. learnRecordItem.Correct = anslist;
  807. }
  808. else
  809. {
  810. learnRecordItem.Correct = questionData.exercise.answer;
  811. }
  812. }
  813. #endregion
  814. if (questionData.item[0].option.Count > 0)
  815. {// 如果有選項資料 記錄起來
  816. foreach (var option in questionData.item[0].option)
  817. {
  818. ChoicesItem item = new();
  819. item.id = option.code;
  820. if (questionData.exercise.type == "judge")
  821. {// 如果是是非題 固定選項
  822. if (option.code == "A")
  823. {
  824. item.description.zhTW = "是";
  825. }
  826. else
  827. {
  828. item.description.zhTW = "否";
  829. }
  830. }
  831. else
  832. {
  833. if (string.IsNullOrWhiteSpace(option.value))
  834. {
  835. item.description.zhTW = $"選項{option.code}";
  836. }
  837. else
  838. {
  839. // 使用HtmlAgilityPack解析HTML
  840. HtmlDocument doc = new HtmlDocument();
  841. doc.LoadHtml(option.value);
  842. // 再取純文字
  843. item.description.zhTW = doc.DocumentNode.InnerText;
  844. }
  845. }
  846. learnRecordItem.Choices.Add(item);
  847. }
  848. }
  849. #endregion
  850. }
  851. public static async Task resultStatus(CosmosClient client, List<ExamClassResult> examClassResults)
  852. {
  853. List<Task<ItemResponse<ExamClassResult>>> tasks = new();
  854. //结算单科单班的标准差和平均分
  855. foreach (ExamClassResult classResult in examClassResults)
  856. {
  857. //标记单科单班总得分
  858. double subScore = 0;
  859. //标准差
  860. double sPowSum = 0;
  861. List<double> newSumScore = new List<double>();
  862. List<double> effectiveScore = new List<double>();
  863. int lostStu = classResult.status.Where(c => c == 1).ToList().Count;
  864. var scount = classResult.studentIds.Count - lostStu;
  865. int index = 0;
  866. if (classResult.status.Count > 0)
  867. {
  868. foreach (var sta in classResult.status)
  869. {
  870. if (sta == 1)
  871. {
  872. for (int i = 0; i < classResult.studentScores[index].Count; i++)
  873. {
  874. if (classResult.studentScores[index][i] == -1)
  875. {
  876. classResult.studentScores[index][i] = 0;
  877. }
  878. }
  879. }
  880. else if (sta == 0)
  881. {
  882. //var ans = classResult.studentAnswers[index];
  883. //该学生缺考,历史数据的判定
  884. //if (ans.Count == 0)
  885. //{
  886. for (int i = 0; i < classResult.studentScores[index].Count; i++)
  887. {
  888. if (classResult.studentScores[index][i] == -1)
  889. {
  890. classResult.studentScores[index][i] = 0;
  891. }
  892. }
  893. /*if (ans.Count == 0)
  894. {
  895. classResult.status[index] = 1;
  896. } */
  897. //}
  898. }
  899. index++;
  900. }
  901. }
  902. else
  903. {
  904. List<int> sta = new();
  905. foreach (var id in classResult.studentIds)
  906. {
  907. sta.Add(0);
  908. }
  909. classResult.status = sta;
  910. foreach (var ans in classResult.studentAnswers)
  911. {
  912. //该学生缺考,历史数据的判定
  913. if (ans.Count == 0)
  914. {
  915. for (int i = 0; i < classResult.studentScores[index].Count; i++)
  916. {
  917. if (classResult.studentScores[index][i] == -1)
  918. {
  919. classResult.studentScores[index][i] = 0;
  920. }
  921. }
  922. classResult.status[index] = 1;
  923. }
  924. index++;
  925. }
  926. }
  927. int sIndex = 0;
  928. foreach (List<double> sc in classResult.studentScores)
  929. {
  930. List<double> newSc = new List<double>();
  931. foreach (double ssc in sc)
  932. {
  933. if (ssc == -1)
  934. {
  935. newSc.Add(0);
  936. }
  937. else
  938. {
  939. newSc.Add(ssc);
  940. }
  941. }
  942. double nc = Math.Round(newSc.Sum(), 2);
  943. if (classResult.status[sIndex] == 0)
  944. {
  945. effectiveScore.Add(nc);
  946. };
  947. newSumScore.Add(nc);
  948. subScore += nc;
  949. classResult.sum[sIndex] = nc;
  950. sIndex++;
  951. }
  952. double rateScore = scount > 0 ? Math.Round(subScore * 1.0 / scount, 2) : 0;
  953. //有效分数
  954. foreach (double scs in effectiveScore)
  955. {
  956. sPowSum += Math.Pow(scs - rateScore, 2);
  957. }
  958. classResult.standard = Math.Round(scount > 0 ? Math.Pow(sPowSum / scount, 0.5) : 0, 2);
  959. classResult.average = scount > 0 ? Math.Round(subScore / scount, 2) : 0;
  960. classResult.progress = true;
  961. tasks.Add(client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new PartitionKey($"{classResult.code}")));
  962. }
  963. await Task.WhenAll(tasks);
  964. }
  965. public static async Task<Settlement> getMore(CosmosClient client, ExamInfo info)
  966. {
  967. //计算单次考试简易统计信息
  968. Settlement settlement = new();
  969. List<ExamResult> examResults = new();
  970. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<ExamResult>(
  971. queryText: $"select value(c) from c where c.examId = '{info.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"ExamResult-{info.id}") }))
  972. {
  973. examResults.Add(item);
  974. }
  975. if (examResults.Count > 0)
  976. {
  977. //记录某次考试所有学生得分总分
  978. double score = 0;
  979. double allScore = 0;
  980. int stuCount = 0;
  981. //标准差
  982. double powSum = 0;
  983. List<string> losStu = new List<string>();
  984. //当前完成考试得人数
  985. int total = examResults[0].studentIds.Distinct().Count();
  986. //先与第一个值取并集
  987. losStu = losStu.Union(examResults[0].lostStus).ToList();
  988. foreach (ExamResult examResult in examResults)
  989. {
  990. //取交集
  991. losStu = losStu.Intersect(examResult.lostStus).ToList();
  992. }
  993. //处理缺考的学生
  994. List<string> stus = examResults[0].studentIds.Except(losStu).ToList();
  995. foreach (ExamResult examResult in examResults)
  996. {
  997. foreach (var id in stus)
  998. {
  999. int index = examResult.studentIds.IndexOf(id);
  1000. score += examResult.studentScores[index].Sum();
  1001. }
  1002. }
  1003. stuCount = total - losStu.Count;
  1004. double NewsRateScore = stuCount > 0 ? Math.Round(score * 1.0 / stuCount, 2) : 0;
  1005. foreach (PaperSimple simple in info.papers)
  1006. {
  1007. allScore += simple.point.Sum();
  1008. }
  1009. //计算全科标准差
  1010. foreach (string id in stus)
  1011. {
  1012. double sc = 0;
  1013. foreach (ExamResult result in examResults)
  1014. {
  1015. if (result.studentScores.Count > 0)
  1016. {
  1017. sc += result.studentScores[result.studentIds.IndexOf(id)].Sum();
  1018. }
  1019. }
  1020. powSum += Math.Pow(sc - NewsRateScore, 2);
  1021. }
  1022. info.standard = Math.Round(total - losStu.Count > 0 ? Math.Pow(powSum / (total - losStu.Count), 0.5) : 0, 2);
  1023. double NewsRate = allScore > 0 ? Math.Round(NewsRateScore / allScore * 100, 2) : 0;
  1024. double qrate = Math.Round(total > 0 ? losStu.Count * 1.0 / total * 100 : 0, 2);
  1025. settlement.rate = NewsRate;
  1026. settlement.score = NewsRateScore;
  1027. settlement.stus = losStu;
  1028. settlement.total = total;
  1029. settlement.qrate = qrate;
  1030. }
  1031. return settlement;
  1032. }
  1033. //处理全部学生选题计数
  1034. public static async Task examRecordCount(ExamInfo info, ExamSubject subject, DingDing _dingDing, int no, ExamResult er, List<ExamClassResult> classResults, AzureCosmosFactory _azureCosmos)
  1035. {
  1036. try
  1037. {
  1038. List<double> scores = new List<double>();
  1039. foreach (List<double> sc in er.studentScores)
  1040. {
  1041. scores.Add(sc.Sum());
  1042. }
  1043. //确定高分组 最低分数
  1044. //var srowallorder = scores.EnumerateIndexed().OrderByDescending(g => g.Item2); //各生總分排序
  1045. //var srowallorder = scores.OrderByDescending(g => g);
  1046. double[] point = StringHelper.ListTodouble(er.paper.point);
  1047. double[,] result = StringHelper.ListToDouble(er.studentScores);
  1048. var cdm = new ClouDASMatrix(result, point);
  1049. scores.Sort((s1, s2) => { return s2.CompareTo(s1); });
  1050. int rhwCount = cdm.SH.Count();
  1051. double rhw = cdm.SH.LastOrDefault().Item2;
  1052. int rhlCount = cdm.SL.Count();
  1053. double rhl = cdm.SL.FirstOrDefault().Item2;
  1054. List<string> phs = new();
  1055. List<string> pls = new();
  1056. //分别获取高分组低分组人员
  1057. foreach (var ph in cdm.SH)
  1058. {
  1059. phs.Add(er.studentIds[ph.Item1]);
  1060. }
  1061. foreach (var pl in cdm.SL)
  1062. {
  1063. pls.Add(er.studentIds[pl.Item1]);
  1064. }
  1065. /* if (scores.Count > 3)
  1066. {
  1067. rhwCount = Convert.ToInt32(Math.Floor(scores.Count * 0.27));
  1068. rhw = rhwCount > 0 ? scores[rhwCount - 1] : 0;
  1069. rhlCount = Convert.ToInt32(Math.Ceiling(scores.Count * 0.73));
  1070. rhl = rhlCount > 0 ? scores[rhlCount] : 0;
  1071. }
  1072. else
  1073. {
  1074. rhwCount = Convert.ToInt32(Math.Floor(scores.Count * 0.27));
  1075. rhw = rhwCount > 0 ? scores[rhwCount] : 0;
  1076. rhlCount = Convert.ToInt32(Math.Ceiling(scores.Count * 0.73));
  1077. rhl = rhlCount > 0 ? scores[rhlCount - 1] : 0;
  1078. }*/
  1079. /*int rhwCount = Convert.ToInt32(Math.Floor(scores.Count * 0.27));
  1080. double rhw = rhwCount > 0 ? scores[rhwCount-1] : 0;
  1081. //var rhww = srowallorder.Take(Convert.ToInt32(Math.Floor(scores.Count * 0.27)));
  1082. //确定低分组 最高分数
  1083. //scores.Sort((s1, s2) => { return s1.CompareTo(s2); });
  1084. int rhlCount = Convert.ToInt32(Math.Ceiling(scores.Count * 0.73));
  1085. double rhl = rhlCount > 0 ? scores[rhlCount-1] : 0;*/
  1086. //var rhll = srowallorder.Skip(Convert.ToInt32(Math.Ceiling(scores.Count * 0.73)));
  1087. //存放高分组学生ID
  1088. List<string> phId = new();
  1089. List<string> plId = new();
  1090. List<List<List<string>>> opth = new();
  1091. List<List<List<string>>> optl = new();
  1092. List<double> akp = await knowledgeCount(info, subject, _dingDing, no, classResults, rhwCount, rhw, rhlCount, rhl, _azureCosmos);
  1093. List<double> afp = await fieldCount(info, subject, _dingDing, no, classResults, rhwCount, rhw, rhlCount, rhl, _azureCosmos);
  1094. int PHCount = 0;
  1095. int PLCount = 0;
  1096. foreach (ExamClassResult classResult in classResults)
  1097. {
  1098. if (classResult.subjectId.Equals(subject.id))
  1099. {
  1100. foreach (string id in classResult.studentIds)
  1101. {
  1102. int index = classResult.studentIds.IndexOf(id);
  1103. if (classResult.studentScores.Count > 0)
  1104. {
  1105. if (phs.Contains(id))
  1106. {
  1107. if (classResult.ans.Count > 0)
  1108. {
  1109. opth.Add(classResult.ans[index]);
  1110. PHCount++;
  1111. continue;
  1112. }
  1113. }
  1114. if (pls.Contains(id))
  1115. {
  1116. if (classResult.ans.Count > 0)
  1117. {
  1118. optl.Add(classResult.ans[index]);
  1119. PLCount++;
  1120. continue;
  1121. }
  1122. }
  1123. }
  1124. }
  1125. }
  1126. }
  1127. er.phc = getMore(info, no, opth);
  1128. er.plc = getMore(info, no, optl);
  1129. er.afp = afp;
  1130. er.akp = akp;
  1131. }
  1132. catch (Exception ex)
  1133. {
  1134. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测作答记录结算异常{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  1135. }
  1136. }
  1137. public static async Task<List<RGroupList>> Activity(CoreAPIHttpService _coreAPIHttpService, ExamInfo info, List<string> classes, CosmosClient client, DingDing _dingDing, List<string> sub, List<ExamClassResult> results)
  1138. {
  1139. List<(string pId, List<string> gid)> ps = new List<(string pId, List<string> gid)>();
  1140. if (info.groupLists.Count > 0)
  1141. {
  1142. var group = info.groupLists;
  1143. foreach (var gp in group)
  1144. {
  1145. foreach (KeyValuePair<string, List<string>> pp in gp)
  1146. {
  1147. ps.Add((pp.Key, pp.Value));
  1148. }
  1149. }
  1150. }
  1151. (List<RMember> tchList, List<RGroupList> classLists) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, classes, info.school, ps);
  1152. /*
  1153. var addStudentsCls = tchList.FindAll(x => x.type == 2);
  1154. var addTmdidsCls = tchList.FindAll(x => x.type == 1);
  1155. List<StuActivity> stuActivities = new List<StuActivity>();
  1156. List<StuActivity> tmdActivities = new List<StuActivity>();
  1157. var papers = info.papers.GroupBy(c => c.subjectId).Select(x => new
  1158. {
  1159. subject = x.Key,
  1160. blob = x.ToList().Select(z => z.blob).ToList()
  1161. });
  1162. bool flag = info.papers.Exists(c => c.subjectId != null);
  1163. if (addTmdidsCls.IsNotEmpty())
  1164. {
  1165. addTmdidsCls.ForEach(x =>
  1166. {
  1167. HashSet<string> classIds = new HashSet<string>();
  1168. classLists.ForEach(z =>
  1169. {
  1170. z.members.ForEach(y =>
  1171. {
  1172. if (y.id.Equals(x.id) && y.type == 1)
  1173. {
  1174. classIds.Add(z.id);
  1175. }
  1176. });
  1177. });
  1178. bool iss = false;
  1179. //标记学生作答状态
  1180. int ts = 0;
  1181. if (results.Count > 0)
  1182. {
  1183. foreach (ExamClassResult exam in results)
  1184. {
  1185. int index = exam.studentIds.IndexOf(x.id);
  1186. if (index != -1)
  1187. {
  1188. if (exam.studentAnswers[index].Count > 0)
  1189. {
  1190. bool flag = exam.studentScores[index].Exists(x => x == -1);
  1191. if (!flag)
  1192. {
  1193. ts = 1;
  1194. iss = true;
  1195. break;
  1196. }
  1197. else
  1198. {
  1199. ts = 0;
  1200. }
  1201. }
  1202. else
  1203. {
  1204. ts = -1;
  1205. }
  1206. }
  1207. }
  1208. }
  1209. else
  1210. {
  1211. ts = -1;
  1212. }
  1213. tmdActivities.Add(new StuActivity
  1214. {
  1215. pk = "Activity",
  1216. id = info.id,
  1217. code = $"Activity-{x.id}",
  1218. type = "Exam",
  1219. name = info.name,
  1220. source = info.source,
  1221. startTime = info.startTime,
  1222. endTime = info.endTime,
  1223. scode = info.code,
  1224. scope = info.scope,
  1225. school = info.school,
  1226. creatorId = info.creatorId,
  1227. subjects = sub,
  1228. blob = null,
  1229. paper = flag ? papers.Select(c => new
  1230. {
  1231. c.subject,
  1232. blob = c.blob[new Random().Next(c.blob.Count)]
  1233. }) : "",
  1234. owner = info.owner,
  1235. createTime = info.createTime,
  1236. taskStatus = ts,
  1237. qamode = info.qamode,
  1238. ext = new Dictionary<string, JsonElement>() { { "type", info.examType.ToJsonString().ToObject<JsonElement>() },
  1239. { "subjects", info.subjects.ToJsonString().ToObject<JsonElement>() } },
  1240. sStatus = iss ? 1 : 0,
  1241. classIds = classIds.ToList()
  1242. }); ;
  1243. });
  1244. }
  1245. if (addStudentsCls.IsNotEmpty())
  1246. {
  1247. addStudentsCls.ForEach(x =>
  1248. {
  1249. HashSet<string> classIds = new HashSet<string>();
  1250. classLists.ForEach(z =>
  1251. {
  1252. z.members.ForEach(y =>
  1253. {
  1254. if (y.id.Equals(x.id) && y.code.Equals(info.school) && y.type == 2)
  1255. {
  1256. classIds.Add(z.id);
  1257. }
  1258. });
  1259. });
  1260. bool iss = false;
  1261. //标记学生作答状态
  1262. int ts = 0;
  1263. if (results.Count > 0)
  1264. {
  1265. foreach (ExamClassResult exam in results)
  1266. {
  1267. int index = exam.studentIds.IndexOf(x.id);
  1268. if (index != -1)
  1269. {
  1270. if (exam.studentAnswers[index].Count > 0)
  1271. {
  1272. bool flag = exam.studentScores[index].Exists(x => x == -1);
  1273. if (!flag)
  1274. {
  1275. ts = 1;
  1276. iss = true;
  1277. break;
  1278. }
  1279. else
  1280. {
  1281. ts = 0;
  1282. }
  1283. }
  1284. else
  1285. {
  1286. ts = -1;
  1287. }
  1288. }
  1289. }
  1290. }
  1291. else
  1292. {
  1293. ts = -1;
  1294. }
  1295. stuActivities.Add(new StuActivity
  1296. {
  1297. pk = "Activity",
  1298. id = info.id,
  1299. code = $"Activity-{x.code.Replace("Base-", "")}-{x.id}",
  1300. type = "Exam",
  1301. name = info.name,
  1302. source = info.source,
  1303. startTime = info.startTime,
  1304. endTime = info.endTime,
  1305. scode = info.code,
  1306. scope = info.scope,
  1307. school = info.school,
  1308. creatorId = info.creatorId,
  1309. subjects = sub,
  1310. blob = null,
  1311. paper = flag ? papers.Select(c => new
  1312. {
  1313. c.subject,
  1314. blob = c.blob[new Random().Next(c.blob.Count)]
  1315. }) : "",
  1316. owner = info.owner,
  1317. classIds = classIds.ToList(),
  1318. createTime = info.createTime,
  1319. qamode = info.qamode,
  1320. ext = new Dictionary<string, JsonElement>() { { "type", info.examType.ToJsonString().ToObject<JsonElement>() },
  1321. { "subjects", info.subjects.ToJsonString().ToObject<JsonElement>() } },
  1322. taskStatus = ts,
  1323. sStatus = iss ? 1 : 0,
  1324. });
  1325. });
  1326. }
  1327. await IESActivityService.SaveStuActivity(client, _dingDing, stuActivities, tmdActivities, null);
  1328. */
  1329. return classLists;
  1330. }
  1331. public static async Task<List<double>> knowledgeCount(ExamInfo info, ExamSubject subject, DingDing _dingDing, int no, List<ExamClassResult> classResults,
  1332. double rhwCount, double rhw, double rhlCount, double rhl, AzureCosmosFactory _azureCosmos)
  1333. {
  1334. List<double> akp = new();
  1335. try
  1336. {
  1337. int phcount = 0;
  1338. int plcount = 0;
  1339. //存放并去重知识点
  1340. HashSet<string> kname = new HashSet<string>();
  1341. if (info.papers[no].knowledge.Count > 0)
  1342. {
  1343. info.papers[no].knowledge.ForEach(kno =>
  1344. {
  1345. kno.ForEach(k =>
  1346. {
  1347. kname.Add(k);
  1348. });
  1349. });
  1350. List<string> knowledgeName = new List<string>();
  1351. foreach (string cla in kname)
  1352. {
  1353. knowledgeName.Add(cla);
  1354. }
  1355. for (int k = 0; k < knowledgeName.Count; k++)
  1356. {
  1357. if (null == knowledgeName[k])
  1358. {
  1359. knowledgeName.Remove(knowledgeName[k]);
  1360. }
  1361. }
  1362. foreach (ExamClassResult classResult in classResults)
  1363. {
  1364. if (classResult.subjectId.Equals(subject.id))
  1365. {
  1366. //List<int> phc = new List<int>();
  1367. List<int> ph = new List<int>();
  1368. List<int> pl = new List<int>();
  1369. List<int> pc = new List<int>();
  1370. List<double> persent = new List<double>();
  1371. int lostStu = classResult.status.Where(c => c == 1).ToList().Count;
  1372. for (int i = 0; i < knowledgeName.Count; i++)
  1373. {
  1374. //初始化单个知识点得分
  1375. double score = 0;
  1376. int n = 0;
  1377. int phCount = 0;
  1378. int plCount = 0;
  1379. int pCount = 0;
  1380. double classScore = 0;
  1381. foreach (List<string> str in info.papers[no].knowledge)
  1382. {
  1383. if (str.Contains(knowledgeName[i]))
  1384. {
  1385. var itemPersent = str.Count > 0 ? 1 / Convert.ToDouble(str.Count) : 0;
  1386. classScore += info.papers[no].point.Count > 0 ? (info.papers[no].point[n] * itemPersent) : 0;
  1387. foreach (string id in classResult.studentIds)
  1388. {
  1389. int index = classResult.studentIds.IndexOf(id);
  1390. if (classResult.studentScores.Count > 0)
  1391. {
  1392. if (classResult.studentScores[index].Count > 0)
  1393. {
  1394. double realScore = classResult.studentScores[index][n] == -1 ? 0 : classResult.studentScores[index][n] * itemPersent;
  1395. score += realScore;
  1396. //score += classResult.studentScores[index][n] == -1 ? 0 : classResult.studentScores[index][n] * itemPersent;
  1397. if (classResult.studentScores[index].Sum() >= rhw && phcount < rhwCount)
  1398. {
  1399. if (classResult.studentScores[index][n] <= 0)
  1400. {
  1401. phCount++;
  1402. }
  1403. phcount++;
  1404. continue;
  1405. }
  1406. if (classResult.studentScores[index].Sum() <= rhl && plcount < (info.stuCount - rhlCount))
  1407. {
  1408. if (classResult.studentScores[index][n] <= 0)
  1409. {
  1410. plCount++;
  1411. }
  1412. plcount++;
  1413. continue;
  1414. }
  1415. if (classResult.studentScores[index][n] <= 0)
  1416. {
  1417. pCount++;
  1418. }
  1419. }
  1420. }
  1421. }
  1422. }
  1423. n++;
  1424. }
  1425. pc.Add(pCount);
  1426. ph.Add(phCount);
  1427. pl.Add(plCount);
  1428. double per = classResult.studentIds.Count - lostStu > 0 ? Math.Round(score / (classResult.studentIds.Count - lostStu), 2) : 0;
  1429. persent.Add(classScore > 0 ? Math.Round(per * 1.0 / classScore, 2) : 0);
  1430. }
  1431. classResult.phc = ph;
  1432. classResult.plc = pl;
  1433. classResult.pc = pc;
  1434. classResult.krate = persent;
  1435. }
  1436. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new Azure.Cosmos.PartitionKey($"{classResult.code}"));
  1437. }
  1438. foreach (string k in knowledgeName)
  1439. {
  1440. double score = 0;
  1441. double allScore = 0;
  1442. int count = 0;
  1443. int m = 0;
  1444. foreach (List<string> str in info.papers[no].knowledge)
  1445. {
  1446. if (str.Contains(k))
  1447. {
  1448. var itemPersent = str.Count > 0 ? 1 / Convert.ToDouble(str.Count) : 0;
  1449. allScore += info.papers[no].point.Count > 0 ? info.papers[no].point[m] * itemPersent : 0;
  1450. }
  1451. m++;
  1452. }
  1453. foreach (ExamClassResult result in classResults)
  1454. {
  1455. if (result.subjectId.Equals(subject.id))
  1456. {
  1457. int n = 0;
  1458. foreach (List<string> str in info.papers[no].knowledge)
  1459. {
  1460. if (str.Contains(k))
  1461. {
  1462. var itemPersent = str.Count > 0 ? 1 / Convert.ToDouble(str.Count) : 0;
  1463. if (result.studentScores.Count > 0)
  1464. {
  1465. foreach (List<double> sc in result.studentScores)
  1466. {
  1467. double tsc = sc[n] == -1 ? 0 : sc[n];
  1468. score += (tsc * itemPersent);
  1469. }
  1470. }
  1471. }
  1472. n++;
  1473. }
  1474. count += result.studentIds.Count;
  1475. }
  1476. }
  1477. double per = count - info.lostStu.Count > 0 ? Math.Round(score / (count - info.lostStu.Count), 2) : 0;
  1478. akp.Add(allScore > 0 ? Math.Round(per / allScore, 2) : 0);
  1479. }
  1480. }
  1481. return akp;
  1482. }
  1483. catch (Exception ex)
  1484. {
  1485. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测知识点结算异常{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  1486. return null;
  1487. }
  1488. }
  1489. public static async Task<List<double>> fieldCount(ExamInfo info, ExamSubject subject, DingDing _dingDing, int no, List<ExamClassResult> classResults,
  1490. double rhwCount, double rhw, double rhlCount, double rhl, AzureCosmosFactory _azureCosmos)
  1491. {
  1492. List<double> afp = new();
  1493. try
  1494. {
  1495. int phcount = 0;
  1496. int plcount = 0;
  1497. //存放并去重知识点
  1498. List<int> knowledgeName = new List<int>() { 1, 2, 3, 4, 5, 6 };
  1499. /* knowledgeName.Add(1);
  1500. knowledgeName.Add(2);
  1501. knowledgeName.Add(3);
  1502. knowledgeName.Add(4);
  1503. knowledgeName.Add(5);
  1504. knowledgeName.Add(6);*/
  1505. foreach (ExamClassResult classResult in classResults)
  1506. {
  1507. if (classResult.subjectId.Equals(subject.id))
  1508. {
  1509. //List<int> phc = new List<int>();
  1510. List<int> ph = new List<int>();
  1511. List<int> pl = new List<int>();
  1512. List<int> pc = new List<int>();
  1513. List<double> persent = new List<double>();
  1514. int lostStu = classResult.status.Where(c => c == 1).ToList().Count;
  1515. for (int i = 0; i < knowledgeName.Count; i++)
  1516. {
  1517. //初始化单个知识点得分
  1518. double score = 0;
  1519. int n = 0;
  1520. int phCount = 0;
  1521. int plCount = 0;
  1522. int pCount = 0;
  1523. double classScore = 0;
  1524. if (info.papers[no].field.Count > 0)
  1525. {
  1526. foreach (int str in info.papers[no].field)
  1527. {
  1528. if (str == knowledgeName[i])
  1529. {
  1530. var itemPersent = 1;
  1531. classScore += info.papers[no].point.Count > 0 ? info.papers[no].point[n] * itemPersent : 0;
  1532. foreach (string id in classResult.studentIds)
  1533. {
  1534. int index = classResult.studentIds.IndexOf(id);
  1535. if (classResult.studentScores.Count > 0)
  1536. {
  1537. if (classResult.studentScores[index].Count > 0)
  1538. {
  1539. score += classResult.studentScores[index][n] == -1 ? 0 : classResult.studentScores[index][n];
  1540. if (classResult.studentScores[index].Sum() >= rhw && phcount < rhwCount)
  1541. {
  1542. if (classResult.studentScores[index][n] <= 0)
  1543. {
  1544. phCount++;
  1545. }
  1546. phcount++;
  1547. continue;
  1548. }
  1549. if (classResult.studentScores[index].Sum() <= rhl && plcount < (info.stuCount - rhlCount))
  1550. {
  1551. if (classResult.studentScores[index][n] <= 0)
  1552. {
  1553. plCount++;
  1554. }
  1555. plcount++;
  1556. continue;
  1557. }
  1558. if (classResult.studentScores[index][n] <= 0)
  1559. {
  1560. pCount++;
  1561. }
  1562. }
  1563. }
  1564. }
  1565. }
  1566. n++;
  1567. }
  1568. pc.Add(pCount);
  1569. ph.Add(phCount);
  1570. pl.Add(plCount);
  1571. double per = classResult.studentIds.Count - lostStu > 0 ? Math.Round(score / (classResult.studentIds.Count - lostStu), 2) : 0;
  1572. persent.Add(classScore > 0 ? Math.Round(per / classScore, 2) : 0);
  1573. }
  1574. }
  1575. classResult.fphc = ph;
  1576. classResult.fplc = pl;
  1577. classResult.fpc = pc;
  1578. classResult.frate = persent;
  1579. }
  1580. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new Azure.Cosmos.PartitionKey($"{classResult.code}"));
  1581. }
  1582. for (int i = 0; i < knowledgeName.Count; i++)
  1583. {
  1584. double score = 0;
  1585. double allScore = 0;
  1586. int count = 0;
  1587. int m = 0;
  1588. foreach (int str in info.papers[no].field)
  1589. {
  1590. if (str == knowledgeName[i])
  1591. {
  1592. var itemPersent = 1;
  1593. allScore += info.papers[no].point.Count > 0 ? info.papers[no].point[m] * itemPersent : 0;
  1594. }
  1595. m++;
  1596. }
  1597. foreach (ExamClassResult result in classResults)
  1598. {
  1599. if (result.subjectId.Equals(subject.id))
  1600. {
  1601. int n = 0;
  1602. foreach (int str in info.papers[no].field)
  1603. {
  1604. var itemPersent = 1;
  1605. if (str == knowledgeName[i])
  1606. {
  1607. if (result.studentScores.Count > 0)
  1608. {
  1609. foreach (List<double> sc in result.studentScores)
  1610. {
  1611. double tsc = sc[n] == -1 ? 0 : sc[n];
  1612. score += tsc * itemPersent;
  1613. }
  1614. }
  1615. }
  1616. n++;
  1617. }
  1618. count += result.studentIds.Count;
  1619. }
  1620. }
  1621. double per = count - info.lostStu.Count > 0 ? Math.Round(score / (count - info.lostStu.Count), 2) : 0;
  1622. afp.Add(allScore > 0 ? Math.Round(per / allScore, 2) : 0);
  1623. }
  1624. return afp;
  1625. }
  1626. catch (Exception ex)
  1627. {
  1628. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测认知层次结算异常{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  1629. return null;
  1630. }
  1631. }
  1632. //处理选题计数
  1633. public static List<Dictionary<string, int>> getMore(ExamInfo info, int no, List<List<List<string>>> list)
  1634. {
  1635. List<Dictionary<string, int>> recorde = new List<Dictionary<string, int>>();
  1636. try
  1637. {
  1638. for (int i = 0; i < info.papers[no].answers.Count; i++)
  1639. {
  1640. if (info.papers[no].answers[i].Count <= 0)
  1641. {
  1642. recorde.Add(new Dictionary<string, int>());
  1643. continue;
  1644. }
  1645. Dictionary<string, int> optCount = new Dictionary<string, int>();
  1646. foreach (List<List<string>> stu in list)
  1647. {
  1648. if (stu.Count == info.papers[no].answers.Count)
  1649. {
  1650. var item = stu[i];
  1651. foreach (string opt in item)
  1652. {
  1653. if (optCount.ContainsKey(opt))
  1654. {
  1655. optCount[opt] = optCount[opt] + 1;
  1656. }
  1657. else
  1658. {
  1659. optCount[opt] = 1;
  1660. }
  1661. }
  1662. }
  1663. }
  1664. recorde.Add(optCount);
  1665. }
  1666. return recorde;
  1667. }
  1668. catch (Exception)
  1669. {
  1670. return recorde;
  1671. }
  1672. }
  1673. public static async Task createClassResultAsync(ExamInfo info, List<ExamClassResult> examClassResults, ExamSubject subject, int no, AzureCosmosFactory _azureCosmos, DingDing _dingDing, AzureStorageFactory _azureStorage, IHttpClientFactory _httpClient, IConfiguration _configuration)
  1674. {
  1675. //保证试卷信息与科目信息同步
  1676. ExamResult result = new ExamResult();
  1677. //人数总和
  1678. int Count = 0;
  1679. int m = 0;
  1680. double score = 0;
  1681. //标准差
  1682. //double powSum = 0;
  1683. double allScore = info.papers[no].point.Sum();
  1684. List<ClassRange> classRanges = new List<ClassRange>();
  1685. List<string> lostStu = new List<string>();
  1686. List<double> csRate = new List<double>();
  1687. List<List<List<string>>> opt = new List<List<List<string>>>();
  1688. //List<Task<ItemResponse<ExamClassResult>>> tasks = new();
  1689. foreach (ExamClassResult classResult in examClassResults)
  1690. {
  1691. double classSrate = 0;
  1692. if (classResult.subjectId.Equals(subject.id))
  1693. {
  1694. foreach (List<List<string>> op in classResult.ans)
  1695. {
  1696. opt.Add(op);
  1697. }
  1698. //记录缺考学生索引位置
  1699. int index_stu = 0;
  1700. foreach (var ans in classResult.studentAnswers)
  1701. {
  1702. if (ans.Count == 0)
  1703. {
  1704. if (!lostStu.Contains(classResult.studentIds[index_stu]))
  1705. {
  1706. lostStu.Add(classResult.studentIds[index_stu]);
  1707. }
  1708. }
  1709. else
  1710. {
  1711. if (classResult.status[index_stu] == 1)
  1712. {
  1713. if (!lostStu.Contains(classResult.studentIds[index_stu]))
  1714. {
  1715. lostStu.Add(classResult.studentIds[index_stu]);
  1716. }
  1717. }
  1718. }
  1719. index_stu++;
  1720. }
  1721. int index = 0;
  1722. foreach (List<double> scores in classResult.studentScores)
  1723. {
  1724. List<double> newScores = new List<double>();
  1725. //int count = 0;
  1726. if (scores.Count > 0)
  1727. {
  1728. foreach (double sc in scores)
  1729. {
  1730. newScores.Add(sc > -1 ? sc : 0);
  1731. }
  1732. }
  1733. else
  1734. {
  1735. newScores.Add(0);
  1736. }
  1737. classSrate += newScores.Sum();
  1738. score += newScores.Sum();
  1739. result.studentScores.Add(newScores);
  1740. index++;
  1741. }
  1742. //处理班级信息
  1743. ClassRange range = new ClassRange();
  1744. range.id = classResult.info.id;
  1745. range.name = classResult.info.name;
  1746. range.gradeId = classResult.gradeId;
  1747. List<int> ran = new List<int>();
  1748. int stuCount = classResult.studentIds.Count;
  1749. //todo 与实际的缺考人数比较
  1750. int lostStus = classResult.status.Where(c => c == 1).ToList().Count;
  1751. Count += stuCount;
  1752. if (m == 0)
  1753. {
  1754. ran.Add(0);
  1755. ran.Add(stuCount - 1);
  1756. }
  1757. else
  1758. {
  1759. ran.Add(Count - stuCount);
  1760. ran.Add(Count - 1);
  1761. }
  1762. m++;
  1763. range.range = ran;
  1764. classRanges.Add(range);
  1765. //处理学生ID
  1766. foreach (string id in classResult.studentIds)
  1767. {
  1768. result.studentIds.Add(id);
  1769. }
  1770. if (allScore > 0)
  1771. {
  1772. csRate.Add(classResult.studentIds.Count - lostStus > 0 ? Math.Round(classSrate * 1.0 / (classResult.studentIds.Count - lostStus), 2) : 0 / allScore);
  1773. }
  1774. else
  1775. {
  1776. csRate.Add(0);
  1777. }
  1778. //powSum += Math.Pow(classSrate - result.average, 2);
  1779. //处理选项计数内容
  1780. }
  1781. //tasks.Add(_azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new PartitionKey($"{classResult.code}")));
  1782. }
  1783. //await tasks.TaskPage(10);
  1784. /*foreach (string id in result.lostStus) {
  1785. if (!examClassResults[0].studentIds.Contains(id)) {
  1786. int index = result.lostStus.IndexOf(id);
  1787. result.lostStus.RemoveAt(index);
  1788. }
  1789. }*/
  1790. //处理人员变更时被移除的人员
  1791. result.lostStus = lostStu;
  1792. List<string> stuIds = examClassResults.SelectMany(x => x.studentIds).ToList();
  1793. if (result.lostStus.Count > 0)
  1794. {
  1795. for (int i = 0; i < result.lostStus.Count; i++)
  1796. {
  1797. if (!stuIds.Contains(result.lostStus[i]))
  1798. {
  1799. result.lostStus.RemoveAt(i);
  1800. }
  1801. }
  1802. }
  1803. result.record = getMore(info, no, opt);
  1804. result.average = result.studentIds.Count - result.lostStus.Count > 0 ? Math.Round(score * 1.0 / (result.studentIds.Count - result.lostStus.Count), 2) : 0;
  1805. double powSum = 0;
  1806. //int sco = 0;
  1807. result.studentIds.ForEach(x =>
  1808. {
  1809. double sc = result.studentScores[result.studentIds.IndexOf(x)].Sum();
  1810. if (!result.lostStus.Contains(x))
  1811. {
  1812. powSum += Math.Pow(sc - result.average, 2);
  1813. }
  1814. });
  1815. result.standard = Math.Round((result.studentIds.Count - result.lostStus.Count) > 0 ? Math.Pow(powSum / (result.studentIds.Count - result.lostStus.Count), 0.5) : 0, 2);
  1816. result.csRate = csRate;
  1817. result.sRate = allScore > 0 ? Math.Round(result.average / allScore * 100, 2) : 0;
  1818. result.classes = classRanges;
  1819. result.code = "ExamResult-" + info.id;
  1820. result.school = info.school;
  1821. result.id = subject.id;
  1822. result.examId = info.id;
  1823. result.subjectId = subject.id;
  1824. result.year = info.year;
  1825. result.paper = info.papers[no];
  1826. //result.point = info.papers[j].point;
  1827. result.scope = info.scope;
  1828. result.name = info.name;
  1829. result.time = info.startTime;
  1830. if (info.qamode != 2) {
  1831. await examRecordCount(info, subject, _dingDing, no, result, examClassResults, _azureCosmos);
  1832. }
  1833. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").UpsertItemAsync(result, new Azure.Cosmos.PartitionKey($"ExamResult-{info.id}"));
  1834. List<ErrorItems> errorItems = new();
  1835. string code = string.Empty;
  1836. string pk = string.Empty;
  1837. string table = "School";
  1838. if (info.scope.Equals("school"))
  1839. {
  1840. code = $"ErrorItems-{info.school}";
  1841. pk = $"Item-{info.school}";
  1842. }
  1843. else
  1844. {
  1845. code = "ErrorItems";
  1846. pk = $"Item-{info.creatorId}";
  1847. table = "Teacher";
  1848. }
  1849. if (result.studentIds.Any()) {
  1850. 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}'"))})";
  1851. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Student").GetItemQueryIterator<ErrorItems>(queryText: sqlqueryText, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
  1852. {
  1853. errorItems.Add(item);
  1854. }
  1855. try
  1856. {
  1857. /* bool isError = examClassResults.SelectMany(c => c.status).ToList().Exists(z => z == 1);
  1858. if () {
  1859. }*/
  1860. if (errorItems.Count == 0 && info.qamode != 2)
  1861. {
  1862. // 新增逻辑 收集错题内容
  1863. BlobDownloadResult index_json;
  1864. if (info.scope.Equals("school"))
  1865. {
  1866. index_json = await _azureStorage.GetBlobContainerClient($"{info.school}").GetBlobClient($"{info.papers[no].blob}/index.json").DownloadContentAsync();
  1867. }
  1868. else
  1869. {
  1870. index_json = await _azureStorage.GetBlobContainerClient($"{info.creatorId}").GetBlobClient($"{info.papers[no].blob}/index.json").DownloadContentAsync();
  1871. }
  1872. //BlobDownloadResult index_json = await _azureStorage.GetBlobContainerClient($"{info.school}").GetBlobClient($"{info.papers[no].blob}/index.json").DownloadContentAsync();
  1873. JsonElement RecordingJson = JsonDocument.Parse(new MemoryStream(Encoding.UTF8.GetBytes(index_json.Content.ToString()))).RootElement;
  1874. RecordingJson.TryGetProperty("slides", out JsonElement slides);
  1875. int qamode = info.qamode;
  1876. if (RecordingJson.TryGetProperty("qamode", out JsonElement element))
  1877. {
  1878. qamode = element.GetInt32();
  1879. }
  1880. var sdes = slides.ToObject<List<Slides>>();
  1881. List<string> attachments = new List<string>();
  1882. if (qamode == 1)
  1883. {
  1884. attachments = RecordingJson.GetProperty("attachments").ToObject<List<string>>();
  1885. if (attachments.Count == 0)
  1886. {
  1887. return;
  1888. }
  1889. }
  1890. List<string> urls = new();
  1891. foreach (var ne in sdes)
  1892. {
  1893. if (!ne.type.Equals("compose"))
  1894. {
  1895. urls.Add(ne.url);
  1896. }
  1897. }
  1898. // 获取整体的题目ID集合
  1899. List<string> ids = new();
  1900. List<(string id, string pid, int level, string type, List<string> knows)> itemInfos = new();
  1901. foreach (string url in urls)
  1902. {
  1903. string id = url.Replace(".json", "");
  1904. BlobDownloadResult index_item_json;
  1905. if (info.scope.Equals("school"))
  1906. {
  1907. index_item_json = await _azureStorage.GetBlobContainerClient($"{info.school}").GetBlobClient($"{info.papers[no].blob}/{url}").DownloadContentAsync();
  1908. }
  1909. else
  1910. {
  1911. index_item_json = await _azureStorage.GetBlobContainerClient($"{info.creatorId}").GetBlobClient($"{info.papers[no].blob}/{url}").DownloadContentAsync();
  1912. }
  1913. JsonElement itemJson = JsonDocument.Parse(new MemoryStream(Encoding.UTF8.GetBytes(index_item_json.Content.ToString()))).RootElement;
  1914. itemJson.TryGetProperty("exercise", out JsonElement exercise);
  1915. //itemJson.TryGetProperty("pid", out JsonElement pid);
  1916. var item_json = exercise.ToObject<Exercise>();
  1917. //JObject keys = JObject.Parse(index_item_json.Content.ToString());
  1918. string type = item_json.type;
  1919. int level = item_json.level;
  1920. var knowledge = item_json.knowledges;
  1921. //string pid = keys.Value<string>("pid");
  1922. if (itemJson.TryGetProperty("pid", out JsonElement pid))
  1923. {
  1924. itemInfos.Add((id, pid.ToString(), level, type, knowledge));
  1925. }
  1926. else
  1927. {
  1928. itemInfos.Add((id, "", level, type, knowledge));
  1929. }
  1930. }
  1931. /* double[] point = StringHelper.ListTodouble(result.paper.point);
  1932. double[,] res = StringHelper.ListToDouble(result.studentScores);
  1933. var cdm = new ClouDASMatrix(res, point);*/
  1934. //需要努力的题目
  1935. //var ss = cdm.StriveTopic;
  1936. int n = 0;
  1937. List<Task<ItemResponse<ErrorItems>>> task_error = new();
  1938. List<ErrorItems> errors = new();
  1939. foreach (var sIds in result.studentIds)
  1940. {
  1941. ErrorItems error = new()
  1942. {
  1943. ttl = -1,
  1944. code = code,
  1945. id = Guid.NewGuid().ToString(),
  1946. stuId = sIds,
  1947. school = info.school,
  1948. activityId = info.id,
  1949. subjectId = result.subjectId,
  1950. time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
  1951. };
  1952. int index_stu = result.studentIds.IndexOf(sIds);
  1953. //顺序学生错题的索引
  1954. var itemScore = result.studentScores[index_stu];
  1955. List<int> index = new();
  1956. int index_item = 0;
  1957. foreach (var sc in itemScore)
  1958. {
  1959. if (sc == 0)
  1960. {
  1961. index.Add(index_item + 1);
  1962. }
  1963. index_item++;
  1964. }
  1965. if (index.Count == 0)
  1966. {
  1967. continue;
  1968. }
  1969. //int[] item_index = ss[n];
  1970. foreach (var item in index)
  1971. {
  1972. Items items = new()
  1973. {
  1974. id = urls[item - 1].Replace(".json", ""),
  1975. blob = info.papers[no].blob
  1976. };
  1977. items.level = itemInfos.Where(c => c.id.Equals(items.id)).FirstOrDefault().level;
  1978. items.type = itemInfos.Where(c => c.id.Equals(items.id)).FirstOrDefault().type;
  1979. items.pId = itemInfos.Where(c => c.id.Equals(items.id)).FirstOrDefault().pid;
  1980. items.knowledge = itemInfos.Where(c => c.id.Equals(items.id)).FirstOrDefault().knows;
  1981. items.qamode = qamode;
  1982. error.its.Add(items);
  1983. }
  1984. errors.Add(error);
  1985. n++;
  1986. task_error.Add(_azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student").CreateItemAsync(error, new PartitionKey($"{error.code}")));
  1987. }
  1988. //string connect = _configuration.GetValue<string>("HaBookAuth:Crtmabank") + "https://malearnfunction.chinacloudsites.cn/api/crtmabank";
  1989. string location = $"{Environment.GetEnvironmentVariable("Option:Location")}";
  1990. string urlAction = string.Empty;
  1991. string accessKey = string.Empty;
  1992. if (location.Contains("China"))
  1993. {
  1994. if (location.Equals("China")) //大陸正式站
  1995. {
  1996. urlAction = "https://malearn.teammodel.cn";
  1997. accessKey = "2BcXFR_hvzG1pZjqIkaM7Dx74Hcu6m0PwwOacFpDpq44AzFuHJBRXA==";
  1998. }
  1999. else if (location.Equals("China-Dep") || location.Equals("China-Test")) //大陸測試站
  2000. {
  2001. urlAction = "https://malearn-rc.teammodel.cn";
  2002. accessKey = "lghWhJduNiAlo-e8isqEoROjdR7DAC-50XNtanIwHKYlAzFu1aog_A==";
  2003. }
  2004. }
  2005. else if (location.Contains("Global"))
  2006. {
  2007. if (location.Equals("Global")) //國際正式站
  2008. {
  2009. urlAction = "https://malearn.teammodel.net";
  2010. accessKey = "I-2lTcdggJkZWSBwOXQIm4oHx-huwX3d0wLe-9pgojThAzFuq_KNFg==";
  2011. }
  2012. else if (location.Equals("Global-Test")) //國際測試站
  2013. {
  2014. urlAction = "https://malearn-rc.teammodel.net";
  2015. accessKey = "_l4Cb_tHIRBw_iv3ZuwVqjkMwjg4_HtDaxhAmZ8OwJraAzFu_DAY8A==";
  2016. }
  2017. }
  2018. string connect = $"{urlAction}/api/crtmabank";
  2019. var htc = _httpClient.CreateClient();
  2020. if (htc.DefaultRequestHeaders.Contains("x-functions-key"))
  2021. {
  2022. htc.DefaultRequestHeaders.Remove("x-functions-key");
  2023. }
  2024. htc.DefaultRequestHeaders.Add("x-functions-key", accessKey);
  2025. ///智慧題庫school欄位修正
  2026. foreach (ErrorItems error in errors)
  2027. {
  2028. error.school = (info.scope.Equals("school")) ? info.school : string.Empty;
  2029. }
  2030. string paramJson = JsonConvert.SerializeObject(errors);
  2031. var content = new StringContent(paramJson, Encoding.UTF8, "application/json");
  2032. var response = await htc.PostAsync(connect, content);
  2033. if ((int)response.StatusCode == 200)
  2034. {
  2035. await task_error.TaskPage(10);
  2036. }
  2037. }
  2038. }
  2039. catch (Exception e)
  2040. {
  2041. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测错题异常{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  2042. }
  2043. }
  2044. }
  2045. public class Settlement
  2046. {
  2047. public double rate { get; set; }
  2048. public double score { get; set; }
  2049. public List<string> stus { get; set; } = new List<string>();
  2050. public int total { get; set; }
  2051. public double qrate { get; set; }
  2052. }
  2053. #region ===學習記錄用類別===
  2054. private class PaperIndex
  2055. {
  2056. public PaperIndex()
  2057. {
  2058. slides = new List<Slide>();
  2059. }
  2060. public List<Slide> slides { get; set; }
  2061. }
  2062. private class Slide
  2063. {
  2064. /// <summary>
  2065. /// blob 路徑
  2066. /// </summary>
  2067. public string url { get; set; }
  2068. /// <summary>
  2069. /// 題型
  2070. /// </summary>
  2071. public string type { get; set; }
  2072. /// <summary>
  2073. /// scoring
  2074. /// </summary>
  2075. public Scoring scoring { get; set; }
  2076. }
  2077. private class Exercise
  2078. {
  2079. /// <summary>
  2080. /// 题目类型
  2081. /// </summary>
  2082. public string type { get; set; }
  2083. /// <summary>
  2084. /// 难度
  2085. /// </summary>
  2086. public int level { get; set; }
  2087. /// <summary>
  2088. /// 知识点
  2089. /// </summary>
  2090. public List<string> knowledges { get; set; }
  2091. }
  2092. private class Scoring
  2093. {
  2094. /// <summary>
  2095. /// knowledge
  2096. /// </summary>
  2097. public List<string> knowledge { get; set; }
  2098. /// <summary>
  2099. /// 答案
  2100. /// </summary>
  2101. public List<string> ans { get; set; }
  2102. }
  2103. private class StudentAnswers
  2104. {
  2105. /// <summary>
  2106. /// 學生作答 blob 路徑
  2107. /// </summary>
  2108. public List<List<string>> studentAnswers { get; set; }
  2109. /// <summary>
  2110. /// 學生ID
  2111. /// </summary>
  2112. public List<string> studentIds { get; set; } = new();
  2113. }
  2114. private class QuestionData
  2115. {
  2116. public QuestionData()
  2117. {
  2118. item = new List<QuestionItem>();
  2119. }
  2120. public QuestionExercise exercise { get; set; }
  2121. public List<QuestionItem> item { get; set; }
  2122. }
  2123. private class QuestionItem
  2124. {
  2125. public QuestionItem()
  2126. {
  2127. option = new List<OptionItem>();
  2128. }
  2129. public string question { get; set; }
  2130. public List<OptionItem> option { get; set; }
  2131. }
  2132. private class OptionItem
  2133. {
  2134. public string code { get; set; }
  2135. public string value { get; set; }
  2136. }
  2137. private class QuestionExercise
  2138. {
  2139. public string type { get; set; }
  2140. public List<string> knowledge { get; set; }
  2141. public List<string> answer { get; set; }
  2142. }
  2143. #endregion
  2144. }
  2145. }