TriggerExam.cs 96 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750
  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 TEAMModelOS.SDK.Helper.Common.JsonHelper.JsonPath;
  21. using Newtonsoft.Json.Linq;
  22. using TEAMModelOS.SDK.Models.Cosmos.Student;
  23. using HTEXLib.Helpers.ShapeHelpers;
  24. using TEAMModelOS.Models.Dto;
  25. using TEAMModelOS.SDK.Models.Cosmos.Common;
  26. using DocumentFormat.OpenXml.Office2010.Excel;
  27. using DocumentFormat.OpenXml.Drawing.Charts;
  28. using DocumentFormat.OpenXml.Vml;
  29. using System.Net.Http;
  30. using Newtonsoft.Json;
  31. using System.Net;
  32. using System.Security.Policy;
  33. using Microsoft.Extensions.Configuration;
  34. using DocumentFormat.OpenXml.EMMA;
  35. using Microsoft.Extensions.Options;
  36. using TEAMModelOS.Models;
  37. namespace TEAMModelOS.FunctionV4
  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)
  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 Azure.Cosmos.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").GetItemQueryStreamIterator(queryText: $"select value(c) from c where c.examId = '{info.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"ExamClassResult-{info.creatorId}") }))
  76. {
  77. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  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").GetItemQueryStreamIterator(queryText: $"select value(c) from c where c.examId = '{info.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"ExamClassResult-{data.school}") }))
  90. {
  91. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  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. sc = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(info.school, new Azure.Cosmos.PartitionKey("Base"));
  109. }
  110. foreach (ExamSubject subject in info.subjects)
  111. {
  112. sub.Add(subject.id);
  113. }
  114. //整合名单
  115. List<string> classes = ExamService.getClasses(info.classes, info.stuLists);
  116. //ChangeRecord record = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ChangeRecord>(input.Id, new Azure.Cosmos.PartitionKey($"{info.progress}"));
  117. switch (info.progress)
  118. {
  119. case "pending":
  120. var message = new ServiceBusMessage(new { id = data.id, progress = "going", code = data.code }.ToJsonString());
  121. message.ApplicationProperties.Add("name", "Exam");
  122. if (records.Count > 0)
  123. {
  124. try
  125. {
  126. await _serviceBus.GetServiceBusClient().CancelMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), records[0].sequenceNumber);
  127. }
  128. catch (Exception)
  129. {
  130. }
  131. long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), message, DateTimeOffset.FromUnixTimeMilliseconds(data.startTime));
  132. records[0].sequenceNumber = start;
  133. await table.SaveOrUpdate<ChangeRecord>(records[0]);
  134. //await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(record, record.id, new Azure.Cosmos.PartitionKey($"{record.code}"));
  135. }
  136. else
  137. {
  138. long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), message, DateTimeOffset.FromUnixTimeMilliseconds(data.startTime));
  139. //string pk = String.Format("{0}{1}{2}", info.code, "-", "pending");
  140. ChangeRecord changeRecord = new ChangeRecord
  141. {
  142. RowKey = data.id,
  143. PartitionKey = PartitionKey,
  144. sequenceNumber = start,
  145. msgId = message.MessageId
  146. };
  147. await table.Save<ChangeRecord>(changeRecord);
  148. //await client.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync(changeRecord, new Azure.Cosmos.PartitionKey($"{changeRecord.code}"));
  149. }
  150. break;
  151. case "going":
  152. try
  153. {
  154. //向学生或醍摩豆账号发起通知
  155. #region
  156. //Notice notice = new Notice()
  157. //{
  158. // msgId = info.id,
  159. // creation = info.startTime,
  160. // expire = info.endTime,
  161. // creatorId = info.creatorId,
  162. // stuids = studentss,
  163. // tmdids = tmdids,
  164. // type = "notice",//评测参加通知
  165. // priority = "normal",
  166. // school = info.school,
  167. // scope = info.scope,
  168. // //data = new { }.ToJsonString()
  169. // body = new Body { sid = info.id, scode = info.code, spk = info.pk, biztype = "exam-join" }
  170. //};
  171. //var messageBlob = new ServiceBusMessage(notice.ToJsonString());
  172. //messageBlob.ApplicationProperties.Add("name", "Notice");
  173. //await _serviceBus.GetServiceBusClient().SendMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageBlob);
  174. #endregion
  175. //List<string> classes = new List<string>();
  176. //处理活动中间件
  177. List<RGroupList> members = await Activity(_coreAPIHttpService, info, classes, client, _dingDing, sub, examClassResults);
  178. if (examClassResults.Count == 0)
  179. {
  180. foreach (string cla in classes)
  181. {
  182. int m = 0;
  183. RGroupList rGroup = new();
  184. rGroup = members.Where(m => m.id.Equals(cla)).FirstOrDefault();
  185. foreach (ExamSubject subject in info.subjects)
  186. {
  187. string classCode = string.Empty;
  188. string cname = string.Empty;
  189. if (string.IsNullOrEmpty(info.school) || !info.scope.Equals("school", StringComparison.OrdinalIgnoreCase))
  190. {
  191. classCode = "ExamClassResult-" + info.creatorId;
  192. }
  193. else
  194. {
  195. classCode = "ExamClassResult-" + info.school;
  196. }
  197. cname = members.Where(m => m.id.Equals(cla)).FirstOrDefault()?.name;
  198. // 预处理活动中间件信息
  199. ExamClassResult result = new()
  200. {
  201. code = classCode,
  202. examId = info.id,
  203. id = Guid.NewGuid().ToString(),
  204. subjectId = subject.id,
  205. year = info.year,
  206. scope = info.scope
  207. };
  208. result.info.id = cla;
  209. result.info.name = cname;
  210. List<string> ans = new();
  211. List<List<string>> anses = new();
  212. List<List<Details>> marks = new();
  213. List<double> ansPoint = new();
  214. List<(string sId, string scode)> ids = new();
  215. foreach (double p in info.papers[m].point)
  216. {
  217. //Details details = new Details();
  218. //ans.Add(new List<string>());
  219. anses.Add(new List<string>());
  220. marks.Add(new List<Details>());
  221. ansPoint.Add(-1);
  222. }
  223. var sresponse = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(cla, new Azure.Cosmos.PartitionKey($"Class-{info.school}"));
  224. if (sresponse.Status == 200)
  225. {
  226. using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
  227. Class classroom = json.ToObject<Class>();
  228. foreach (SDK.Models.Period period in sc.period)
  229. {
  230. if (period.id.Equals(classroom.periodId))
  231. {
  232. foreach (Semester semester in period.semesters)
  233. {
  234. if (semester.start == 1)
  235. {
  236. int year = DateTimeOffset.UtcNow.Year;
  237. int month = DateTimeOffset.UtcNow.Month;
  238. int day = DateTimeOffset.UtcNow.Day;
  239. int time = 0;
  240. if (month == semester.month)
  241. {
  242. time = day >= semester.day ? 0 : 1;
  243. }
  244. else
  245. {
  246. time = month > semester.month ? 0 : 1;
  247. }
  248. int eyear = year - time;
  249. result.gradeId = (eyear - classroom.year).ToString();
  250. }
  251. }
  252. }
  253. }
  254. //result.info.id = classroom.id;
  255. //result.info.name = classroom.name;
  256. //result.gradeId = classroom.year.ToString();
  257. //处理班级人数
  258. /* 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}") }))
  259. {
  260. using var json_stu = await JsonDocument.ParseAsync(item.ContentStream);
  261. if (json_stu.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  262. {
  263. var accounts = json_stu.RootElement.GetProperty("Documents").EnumerateArray();
  264. while (accounts.MoveNext())
  265. {
  266. JsonElement account = accounts.Current;
  267. ids.Add(account.GetProperty("id").GetString());
  268. }
  269. }
  270. }*/
  271. }
  272. /*if (info.scope.Equals("private", StringComparison.OrdinalIgnoreCase))
  273. {
  274. var stuResponse = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemStreamAsync(cla, new Azure.Cosmos.PartitionKey($"GroupList"));
  275. if (stuResponse.Status == 200)
  276. {
  277. using var json = await JsonDocument.ParseAsync(stuResponse.ContentStream);
  278. GroupList stuList = json.ToObject<GroupList>();
  279. //result.info.id = stuList.id;
  280. result.info.name = stuList.name;
  281. //处理发布对象为自选名单(个人)
  282. foreach (Member stus in stuList.members)
  283. {
  284. if (!ids.Contains(stus.id))
  285. {
  286. ids.Add(stus.id);
  287. }
  288. }
  289. }
  290. }
  291. else
  292. {
  293. var stuResponse = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(cla, new Azure.Cosmos.PartitionKey($"GroupList-{info.school}"));
  294. if (stuResponse.Status == 200)
  295. {
  296. using var json = await JsonDocument.ParseAsync(stuResponse.ContentStream);
  297. GroupList stuList = json.ToObject<GroupList>();
  298. //result.info.id = stuList.id;
  299. result.info.name = stuList.name;
  300. //处理发布对象为自选名单(校本)
  301. foreach (Member stus in stuList.members)
  302. {
  303. if (!ids.Contains(stus.id))
  304. {
  305. ids.Add(stus.id);
  306. }
  307. }
  308. }
  309. }*/
  310. foreach (RMember member in rGroup.members)
  311. {
  312. ids.Add((member.id, member.code));
  313. }
  314. //ids = members.Where(c => c.id.Equals(cla)).SelectMany(m => m.members).Select(g => g.id).ToList();
  315. foreach (var (sId, scode) in ids)
  316. {
  317. result.mark.Add(marks);
  318. result.studentIds.Add(sId);
  319. //result.scIds.Add(scode ?? "");
  320. result.studentAnswers.Add(ans);
  321. result.studentScores.Add(ansPoint);
  322. result.ans.Add(anses);
  323. result.sum.Add(0);
  324. result.status.Add(1);
  325. }
  326. //result.progress = info.progress;
  327. result.school = info.school;
  328. m++;
  329. await client.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync(result, new Azure.Cosmos.PartitionKey($"{result.code}"));
  330. }
  331. }
  332. }
  333. else
  334. {
  335. //处理单科结算时科目与试卷信息匹配的问题
  336. int gno = 0;
  337. foreach (ExamSubject subject in info.subjects)
  338. {
  339. if (subject.classCount == classes.Count)
  340. {
  341. await createClassResultAsync(info, examClassResults, subject, gno, _azureCosmos, _dingDing, _azureStorage, _httpClient, _configuration);
  342. }
  343. gno++;
  344. }
  345. var isScore = examClassResults.SelectMany(e => e.studentScores).ToList().Exists(c => c.Contains(-1));
  346. int newStatus = 0;
  347. if (!isScore)
  348. {
  349. newStatus = 1;
  350. }
  351. Settlement settlement = await getMore(client, info);
  352. long nowTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  353. //判断评分状态是否发生变化,便于实时的更新评测基本信息
  354. if (info.average != settlement.score || info.sStatus != newStatus)
  355. {
  356. info.sRate = settlement.rate;
  357. info.sStatus = newStatus;
  358. info.updateTime = nowTime;
  359. info.average = settlement.score;
  360. await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync<ExamInfo>(info, info.id, new PartitionKey(info.code));
  361. }
  362. }
  363. }
  364. catch (Exception e)
  365. {
  366. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测going状态异常{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  367. }
  368. finally
  369. {
  370. // 发送信息通知
  371. var messageEnd = new ServiceBusMessage(new { id = data.id, progress = "finish", code = data.code }.ToJsonString());
  372. messageEnd.ApplicationProperties.Add("name", "Exam");
  373. if (records.Count > 0)
  374. {
  375. long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageEnd, DateTimeOffset.FromUnixTimeMilliseconds(data.endTime));
  376. try
  377. {
  378. await _serviceBus.GetServiceBusClient().CancelMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), records[0].sequenceNumber);
  379. }
  380. catch (Exception)
  381. {
  382. }
  383. records[0].sequenceNumber = end;
  384. await table.SaveOrUpdate<ChangeRecord>(records[0]);
  385. //await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(record, record.id, new Azure.Cosmos.PartitionKey($"{record.code}"));
  386. }
  387. else
  388. {
  389. long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageEnd, DateTimeOffset.FromUnixTimeMilliseconds(data.endTime));
  390. //string pk = String.Format("{0}{1}{2}", info.code, "-", "going");
  391. ChangeRecord changeRecord = new ChangeRecord
  392. {
  393. RowKey = data.id,
  394. PartitionKey = PartitionKey,
  395. sequenceNumber = end,
  396. msgId = messageEnd.MessageId
  397. };
  398. await table.Save<ChangeRecord>(changeRecord);
  399. //await client.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync(changeRecord, new Azure.Cosmos.PartitionKey($"{changeRecord.code}"));
  400. }
  401. }
  402. break;
  403. case "finish":
  404. int fno = 0;
  405. try
  406. {
  407. //用来判定是否完成评分
  408. //bool isScore = true;
  409. await resultStatus(client, examClassResults);
  410. await Activity(_coreAPIHttpService, info, classes, client, _dingDing, sub, examClassResults);
  411. foreach (ExamSubject subject in info.subjects)
  412. {
  413. await createClassResultAsync(info, examClassResults, subject, fno, _azureCosmos, _dingDing, _azureStorage, _httpClient, _configuration);
  414. fno++;
  415. }
  416. Settlement settlement = await getMore(client, info);
  417. var isScore = examClassResults.SelectMany(e => e.studentScores).ToList().Exists(c => c.Contains(-1));
  418. int newStatus = 0;
  419. if (!isScore)
  420. {
  421. newStatus = 1;
  422. }
  423. //判断均分是否发生变化,便于实时的更新评测基本信息
  424. if (info.sRate != settlement.rate || info.average != settlement.score || info.sStatus != newStatus || info.qRate != settlement.qrate)
  425. {
  426. info.sRate = settlement.rate;
  427. info.average = settlement.score;
  428. info.sStatus = newStatus;
  429. info.lostStu = settlement.stus;
  430. info.stuCount = settlement.total;
  431. info.qRate = settlement.qrate;
  432. //新增数据推送 obj => Portrait
  433. Portrait portrait = new()
  434. {
  435. schoolCode = info.school,
  436. periodId = info.period.id,
  437. subjectId = "subject_intelligence"
  438. };
  439. //作答合格率
  440. var sta = examClassResults.SelectMany(x => x.status).ToList();
  441. /* var stus = examClassResults.SelectMany(x => x.studentIds).ToList();
  442. var stuScores = examClassResults.SelectMany(x => x.studentScores).ToList();*/
  443. var ansCount = sta.Where(x => x == 0).ToList();
  444. var persent = ansCount.Count * 1.0 / sta.Count * 100;
  445. var period = sc.period.Where(x => x.id.Equals(info.period.id)).FirstOrDefault();
  446. List<string> subjects = info.subjects.Select(x => x.id).ToList();
  447. //获取学期信息
  448. if (null != period && persent >= 60 && !subjects.Contains("subject_painting") && !subjects.Contains("subject_music")) {
  449. var (currSemester, studyYear, currSemesterDate, date, nextSemester) = SchoolService.GetSemester(period, info.startTime);
  450. //获取学生信息
  451. (List<RMember> rmembers, List<RGroupList> groups) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, info.classes, info.school);
  452. foreach (var member in rmembers)
  453. {
  454. if (info.lostStu.Contains(member.id))
  455. {
  456. continue;
  457. }
  458. PortraitStudent student = new()
  459. {
  460. studentId = member.id,
  461. name = member.name,
  462. classId = member.classId
  463. };
  464. var ec = examClassResults.Where(c => c.studentIds.Contains(member.id)).ToList();
  465. double scores = 0;
  466. List<(string subjectId, double score)> subScore = new();
  467. foreach (var eclass in ec) {
  468. int index_stu = eclass.studentIds.IndexOf(member.id);
  469. scores += eclass.sum[index_stu];
  470. subScore.Add((eclass.subjectId, eclass.sum[index_stu]));
  471. }
  472. SemesterData semesterData = new()
  473. {
  474. examName = info.name,
  475. examId = info.id,
  476. examDate = info.startTime,
  477. examType = info.examType?.name,
  478. year = info.year,
  479. semesterId = currSemester.id,
  480. totalScore = info.papers.SelectMany(x => x.point).Sum(),
  481. sumScore = scores,
  482. excellenceRate = 0,
  483. passRate = 0,
  484. };
  485. int index = 0;
  486. foreach (var sj in info.subjects)
  487. {
  488. ItemScore item = new()
  489. {
  490. id = sj.id,
  491. name = sj.name,
  492. score = subScore.Where(c => c.subjectId.Equals(sj.id)).FirstOrDefault().score,
  493. time = info.startTime,
  494. totalScore = info.papers[index].point.Sum(),
  495. type = sj.id
  496. };
  497. index++;
  498. semesterData.itemScore.Add(item);
  499. }
  500. student.semesterData.Add(semesterData);
  501. portrait.students.Add(student);
  502. }
  503. string location = $"{Environment.GetEnvironmentVariable("Option:Location")}";
  504. var (status, json) = await _httpTrigger.RequestHttpTrigger(portrait, location, "upsert-student-portrait");
  505. }
  506. //PortraitStudent student = new();
  507. //处理试卷活动结束统计账户信息
  508. List<FMember> idList = await GroupListService.GetFinishMemberInfo(_coreAPIHttpService, client, _dingDing, info.school, info.classes, info.stuLists, null);
  509. info.staffIds = idList;
  510. await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync<ExamInfo>(info, info.id, new Azure.Cosmos.PartitionKey(info.code));
  511. }
  512. }
  513. catch (Exception e)
  514. {
  515. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测finish状态异常{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  516. }
  517. break;
  518. }
  519. }
  520. }
  521. catch (CosmosException e)
  522. {
  523. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-CosmosDB异常{e.Message}\n{e.StackTrace}\n{e.Status}", GroupNames.醍摩豆服務運維群組);
  524. }
  525. catch (Exception e)
  526. {
  527. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-评测结算异常{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  528. }
  529. }
  530. public static async Task resultStatus(CosmosClient client, List<ExamClassResult> examClassResults)
  531. {
  532. List<Task<ItemResponse<ExamClassResult>>> tasks = new();
  533. //结算单科单班的标准差和平均分
  534. foreach (ExamClassResult classResult in examClassResults)
  535. {
  536. //标记单科单班总得分
  537. double subScore = 0;
  538. //标准差
  539. double sPowSum = 0;
  540. List<double> newSumScore = new List<double>();
  541. List<double> effectiveScore = new List<double>();
  542. int lostStu = classResult.status.Where(c => c == 1).ToList().Count;
  543. var scount = classResult.studentIds.Count - lostStu;
  544. int index = 0;
  545. if (classResult.status.Count > 0)
  546. {
  547. foreach (var sta in classResult.status)
  548. {
  549. if (sta == 1)
  550. {
  551. for (int i = 0; i < classResult.studentScores[index].Count; i++)
  552. {
  553. if (classResult.studentScores[index][i] == -1)
  554. {
  555. classResult.studentScores[index][i] = 0;
  556. }
  557. }
  558. }
  559. else if (sta == 0)
  560. {
  561. //var ans = classResult.studentAnswers[index];
  562. //该学生缺考,历史数据的判定
  563. //if (ans.Count == 0)
  564. //{
  565. for (int i = 0; i < classResult.studentScores[index].Count; i++)
  566. {
  567. if (classResult.studentScores[index][i] == -1)
  568. {
  569. classResult.studentScores[index][i] = 0;
  570. }
  571. }
  572. /*if (ans.Count == 0)
  573. {
  574. classResult.status[index] = 1;
  575. } */
  576. //}
  577. }
  578. index++;
  579. }
  580. }
  581. else
  582. {
  583. List<int> sta = new();
  584. foreach (var id in classResult.studentIds)
  585. {
  586. sta.Add(0);
  587. }
  588. classResult.status = sta;
  589. foreach (var ans in classResult.studentAnswers)
  590. {
  591. //该学生缺考,历史数据的判定
  592. if (ans.Count == 0)
  593. {
  594. for (int i = 0; i < classResult.studentScores[index].Count; i++)
  595. {
  596. if (classResult.studentScores[index][i] == -1)
  597. {
  598. classResult.studentScores[index][i] = 0;
  599. }
  600. }
  601. classResult.status[index] = 1;
  602. }
  603. index++;
  604. }
  605. }
  606. int sIndex = 0;
  607. foreach (List<double> sc in classResult.studentScores)
  608. {
  609. List<double> newSc = new List<double>();
  610. foreach (double ssc in sc)
  611. {
  612. if (ssc == -1)
  613. {
  614. newSc.Add(0);
  615. }
  616. else
  617. {
  618. newSc.Add(ssc);
  619. }
  620. }
  621. double nc = Math.Round(newSc.Sum(), 2);
  622. if (classResult.status[sIndex] == 0)
  623. {
  624. effectiveScore.Add(nc);
  625. };
  626. newSumScore.Add(nc);
  627. subScore += nc;
  628. classResult.sum[sIndex] = nc;
  629. sIndex++;
  630. }
  631. double rateScore = scount > 0 ? Math.Round(subScore * 1.0 / scount, 2) : 0;
  632. //有效分数
  633. foreach (double scs in effectiveScore)
  634. {
  635. sPowSum += Math.Pow(scs - rateScore, 2);
  636. }
  637. classResult.standard = Math.Round(scount > 0 ? Math.Pow(sPowSum / scount, 0.5) : 0, 2);
  638. classResult.average = scount > 0 ? Math.Round(subScore / scount, 2) : 0;
  639. classResult.progress = true;
  640. tasks.Add(client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new PartitionKey($"{classResult.code}")));
  641. }
  642. await Task.WhenAll(tasks);
  643. }
  644. public static async Task<Settlement> getMore(CosmosClient client, ExamInfo info)
  645. {
  646. //计算单次考试简易统计信息
  647. Settlement settlement = new();
  648. List<ExamResult> examResults = new();
  649. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<ExamResult>(
  650. queryText: $"select value(c) from c where c.examId = '{info.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"ExamResult-{info.id}") }))
  651. {
  652. examResults.Add(item);
  653. }
  654. if (examResults.Count > 0)
  655. {
  656. //记录某次考试所有学生得分总分
  657. double score = 0;
  658. double allScore = 0;
  659. int stuCount = 0;
  660. //标准差
  661. double powSum = 0;
  662. List<string> losStu = new List<string>();
  663. //当前完成考试得人数
  664. int total = examResults[0].studentIds.Distinct().Count();
  665. //先与第一个值取并集
  666. losStu = losStu.Union(examResults[0].lostStus).ToList();
  667. foreach (ExamResult examResult in examResults)
  668. {
  669. //取交集
  670. losStu = losStu.Intersect(examResult.lostStus).ToList();
  671. }
  672. //处理缺考的学生
  673. List<string> stus = examResults[0].studentIds.Except(losStu).ToList();
  674. foreach (ExamResult examResult in examResults)
  675. {
  676. foreach (var id in stus)
  677. {
  678. int index = examResult.studentIds.IndexOf(id);
  679. score += examResult.studentScores[index].Sum();
  680. }
  681. }
  682. stuCount = total - losStu.Count;
  683. double NewsRateScore = stuCount > 0 ? Math.Round(score * 1.0 / stuCount, 2) : 0;
  684. foreach (PaperSimple simple in info.papers)
  685. {
  686. allScore += simple.point.Sum();
  687. }
  688. //计算全科标准差
  689. foreach (string id in stus)
  690. {
  691. double sc = 0;
  692. foreach (ExamResult result in examResults)
  693. {
  694. if (result.studentScores.Count > 0)
  695. {
  696. sc += result.studentScores[result.studentIds.IndexOf(id)].Sum();
  697. }
  698. }
  699. powSum += Math.Pow(sc - NewsRateScore, 2);
  700. }
  701. info.standard = Math.Round(total - losStu.Count > 0 ? Math.Pow(powSum / (total - losStu.Count), 0.5) : 0, 2);
  702. double NewsRate = allScore > 0 ? Math.Round(NewsRateScore / allScore * 100, 2) : 0;
  703. double qrate = Math.Round(total > 0 ? losStu.Count * 1.0 / total * 100 : 0, 2);
  704. settlement.rate = NewsRate;
  705. settlement.score = NewsRateScore;
  706. settlement.stus = losStu;
  707. settlement.total = total;
  708. settlement.qrate = qrate;
  709. }
  710. return settlement;
  711. }
  712. //处理全部学生选题计数
  713. public static async Task examRecordCount(ExamInfo info, ExamSubject subject, DingDing _dingDing, int no, ExamResult er, List<ExamClassResult> classResults, AzureCosmosFactory _azureCosmos)
  714. {
  715. try
  716. {
  717. List<double> scores = new List<double>();
  718. foreach (List<double> sc in er.studentScores)
  719. {
  720. scores.Add(sc.Sum());
  721. }
  722. //确定高分组 最低分数
  723. //var srowallorder = scores.EnumerateIndexed().OrderByDescending(g => g.Item2); //各生總分排序
  724. //var srowallorder = scores.OrderByDescending(g => g);
  725. double[] point = StringHelper.ListTodouble(er.paper.point);
  726. double[,] result = StringHelper.ListToDouble(er.studentScores);
  727. var cdm = new ClouDASMatrix(result, point);
  728. scores.Sort((s1, s2) => { return s2.CompareTo(s1); });
  729. int rhwCount = cdm.SH.Count();
  730. double rhw = cdm.SH.LastOrDefault().Item2;
  731. int rhlCount = cdm.SL.Count();
  732. double rhl = cdm.SL.FirstOrDefault().Item2;
  733. List<string> phs = new();
  734. List<string> pls = new();
  735. //分别获取高分组低分组人员
  736. foreach (var ph in cdm.SH)
  737. {
  738. phs.Add(er.studentIds[ph.Item1]);
  739. }
  740. foreach (var pl in cdm.SL)
  741. {
  742. pls.Add(er.studentIds[pl.Item1]);
  743. }
  744. /* if (scores.Count > 3)
  745. {
  746. rhwCount = Convert.ToInt32(Math.Floor(scores.Count * 0.27));
  747. rhw = rhwCount > 0 ? scores[rhwCount - 1] : 0;
  748. rhlCount = Convert.ToInt32(Math.Ceiling(scores.Count * 0.73));
  749. rhl = rhlCount > 0 ? scores[rhlCount] : 0;
  750. }
  751. else
  752. {
  753. rhwCount = Convert.ToInt32(Math.Floor(scores.Count * 0.27));
  754. rhw = rhwCount > 0 ? scores[rhwCount] : 0;
  755. rhlCount = Convert.ToInt32(Math.Ceiling(scores.Count * 0.73));
  756. rhl = rhlCount > 0 ? scores[rhlCount - 1] : 0;
  757. }*/
  758. /*int rhwCount = Convert.ToInt32(Math.Floor(scores.Count * 0.27));
  759. double rhw = rhwCount > 0 ? scores[rhwCount-1] : 0;
  760. //var rhww = srowallorder.Take(Convert.ToInt32(Math.Floor(scores.Count * 0.27)));
  761. //确定低分组 最高分数
  762. //scores.Sort((s1, s2) => { return s1.CompareTo(s2); });
  763. int rhlCount = Convert.ToInt32(Math.Ceiling(scores.Count * 0.73));
  764. double rhl = rhlCount > 0 ? scores[rhlCount-1] : 0;*/
  765. //var rhll = srowallorder.Skip(Convert.ToInt32(Math.Ceiling(scores.Count * 0.73)));
  766. //存放高分组学生ID
  767. List<string> phId = new();
  768. List<string> plId = new();
  769. List<List<List<string>>> opth = new();
  770. List<List<List<string>>> optl = new();
  771. List<double> akp = await knowledgeCount(info, subject, _dingDing, no, classResults, rhwCount, rhw, rhlCount, rhl, _azureCosmos);
  772. List<double> afp = await fieldCount(info, subject, _dingDing, no, classResults, rhwCount, rhw, rhlCount, rhl, _azureCosmos);
  773. int PHCount = 0;
  774. int PLCount = 0;
  775. foreach (ExamClassResult classResult in classResults)
  776. {
  777. if (classResult.subjectId.Equals(subject.id))
  778. {
  779. foreach (string id in classResult.studentIds)
  780. {
  781. int index = classResult.studentIds.IndexOf(id);
  782. if (classResult.studentScores.Count > 0)
  783. {
  784. if (phs.Contains(id))
  785. {
  786. if (classResult.ans.Count > 0)
  787. {
  788. opth.Add(classResult.ans[index]);
  789. PHCount++;
  790. continue;
  791. }
  792. }
  793. if (pls.Contains(id))
  794. {
  795. if (classResult.ans.Count > 0)
  796. {
  797. optl.Add(classResult.ans[index]);
  798. PLCount++;
  799. continue;
  800. }
  801. }
  802. }
  803. }
  804. }
  805. }
  806. er.phc = getMore(info, no, opth);
  807. er.plc = getMore(info, no, optl);
  808. er.afp = afp;
  809. er.akp = akp;
  810. }
  811. catch (Exception ex)
  812. {
  813. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测作答记录结算异常{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  814. }
  815. }
  816. public static async Task<List<RGroupList>> Activity(CoreAPIHttpService _coreAPIHttpService, ExamInfo info, List<string> classes, CosmosClient client, DingDing _dingDing, List<string> sub, List<ExamClassResult> results)
  817. {
  818. List<(string pId, List<string> gid)> ps = new List<(string pId, List<string> gid)>();
  819. if (info.groupLists.Count > 0)
  820. {
  821. var group = info.groupLists;
  822. foreach (var gp in group)
  823. {
  824. foreach (KeyValuePair<string, List<string>> pp in gp)
  825. {
  826. ps.Add((pp.Key, pp.Value));
  827. }
  828. }
  829. }
  830. (List<RMember> tchList, List<RGroupList> classLists) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, classes, info.school, ps);
  831. var addStudentsCls = tchList.FindAll(x => x.type == 2);
  832. var addTmdidsCls = tchList.FindAll(x => x.type == 1);
  833. List<StuActivity> stuActivities = new List<StuActivity>();
  834. List<StuActivity> tmdActivities = new List<StuActivity>();
  835. var papers = info.papers.GroupBy(c => c.subjectId).Select(x => new {
  836. subject = x.Key,
  837. blob = x.ToList().Select(z => z.blob).ToList() });
  838. if (addTmdidsCls.IsNotEmpty())
  839. {
  840. addTmdidsCls.ForEach(x =>
  841. {
  842. HashSet<string> classIds = new HashSet<string>();
  843. classLists.ForEach(z =>
  844. {
  845. z.members.ForEach(y =>
  846. {
  847. if (y.id.Equals(x.id) && y.type == 1)
  848. {
  849. classIds.Add(z.id);
  850. }
  851. });
  852. });
  853. bool iss = false;
  854. //标记学生作答状态
  855. int ts = 0;
  856. if (results.Count > 0)
  857. {
  858. foreach (ExamClassResult exam in results)
  859. {
  860. int index = exam.studentIds.IndexOf(x.id);
  861. if (index != -1)
  862. {
  863. if (exam.studentAnswers[index].Count > 0)
  864. {
  865. bool flag = exam.studentScores[index].Exists(x => x == -1);
  866. if (!flag)
  867. {
  868. ts = 1;
  869. iss = true;
  870. break;
  871. }
  872. else
  873. {
  874. ts = 0;
  875. }
  876. }
  877. else
  878. {
  879. ts = -1;
  880. }
  881. }
  882. }
  883. }
  884. else
  885. {
  886. ts = -1;
  887. }
  888. tmdActivities.Add(new StuActivity
  889. {
  890. pk = "Activity",
  891. id = info.id,
  892. code = $"Activity-{x.id}",
  893. type = "Exam",
  894. name = info.name,
  895. source = info.source,
  896. startTime = info.startTime,
  897. endTime = info.endTime,
  898. scode = info.code,
  899. scope = info.scope,
  900. school = info.school,
  901. creatorId = info.creatorId,
  902. subjects = sub,
  903. blob = null,
  904. paper = info.pk.Equals("Art") ? papers.Select(c => new {
  905. c.subject,
  906. blob = c.blob[new Random().Next(c.blob.Count)]
  907. }) : "",
  908. owner = info.owner,
  909. createTime = info.createTime,
  910. taskStatus = ts,
  911. qamode = info.qamode,
  912. ext = new Dictionary<string, JsonElement>() { { "type", info.examType.ToJsonString().ToObject<JsonElement>() },
  913. { "subjects", info.subjects.ToJsonString().ToObject<JsonElement>() } },
  914. sStatus = iss ? 1 : 0,
  915. classIds = classIds.ToList()
  916. }); ;
  917. });
  918. }
  919. if (addStudentsCls.IsNotEmpty())
  920. {
  921. addStudentsCls.ForEach(x =>
  922. {
  923. HashSet<string> classIds = new HashSet<string>();
  924. classLists.ForEach(z =>
  925. {
  926. z.members.ForEach(y =>
  927. {
  928. if (y.id.Equals(x.id) && y.code.Equals(info.school) && y.type == 2)
  929. {
  930. classIds.Add(z.id);
  931. }
  932. });
  933. });
  934. bool iss = false;
  935. //标记学生作答状态
  936. int ts = 0;
  937. if (results.Count > 0)
  938. {
  939. foreach (ExamClassResult exam in results)
  940. {
  941. int index = exam.studentIds.IndexOf(x.id);
  942. if (index != -1)
  943. {
  944. if (exam.studentAnswers[index].Count > 0)
  945. {
  946. bool flag = exam.studentScores[index].Exists(x => x == -1);
  947. if (!flag)
  948. {
  949. ts = 1;
  950. iss = true;
  951. break;
  952. }
  953. else
  954. {
  955. ts = 0;
  956. }
  957. }
  958. else
  959. {
  960. ts = -1;
  961. }
  962. }
  963. }
  964. }
  965. else
  966. {
  967. ts = -1;
  968. }
  969. stuActivities.Add(new StuActivity
  970. {
  971. pk = "Activity",
  972. id = info.id,
  973. code = $"Activity-{x.code.Replace("Base-", "")}-{x.id}",
  974. type = "Exam",
  975. name = info.name,
  976. source = info.source,
  977. startTime = info.startTime,
  978. endTime = info.endTime,
  979. scode = info.code,
  980. scope = info.scope,
  981. school = info.school,
  982. creatorId = info.creatorId,
  983. subjects = sub,
  984. blob = null,
  985. paper = info.pk.Equals("Art") ? papers.Select(c => new {
  986. c.subject,
  987. blob = c.blob[new Random().Next(c.blob.Count)]
  988. }) : "",
  989. owner = info.owner,
  990. classIds = classIds.ToList(),
  991. createTime = info.createTime,
  992. qamode = info.qamode,
  993. ext = new Dictionary<string, JsonElement>() { { "type", info.examType.ToJsonString().ToObject<JsonElement>() },
  994. { "subjects", info.subjects.ToJsonString().ToObject<JsonElement>() } },
  995. taskStatus = ts,
  996. sStatus = iss ? 1 : 0,
  997. });
  998. });
  999. }
  1000. await IESActivityService.SaveStuActivity(client, _dingDing, stuActivities, tmdActivities, null);
  1001. return classLists;
  1002. }
  1003. public static async Task<List<double>> knowledgeCount(ExamInfo info, ExamSubject subject, DingDing _dingDing, int no, List<ExamClassResult> classResults,
  1004. double rhwCount, double rhw, double rhlCount, double rhl, AzureCosmosFactory _azureCosmos)
  1005. {
  1006. List<double> akp = new();
  1007. try
  1008. {
  1009. int phcount = 0;
  1010. int plcount = 0;
  1011. //存放并去重知识点
  1012. HashSet<string> kname = new HashSet<string>();
  1013. if (info.papers[no].knowledge.Count > 0)
  1014. {
  1015. info.papers[no].knowledge.ForEach(kno =>
  1016. {
  1017. kno.ForEach(k =>
  1018. {
  1019. kname.Add(k);
  1020. });
  1021. });
  1022. List<string> knowledgeName = new List<string>();
  1023. foreach (string cla in kname)
  1024. {
  1025. knowledgeName.Add(cla);
  1026. }
  1027. for (int k = 0; k < knowledgeName.Count; k++)
  1028. {
  1029. if (null == knowledgeName[k])
  1030. {
  1031. knowledgeName.Remove(knowledgeName[k]);
  1032. }
  1033. }
  1034. foreach (ExamClassResult classResult in classResults)
  1035. {
  1036. if (classResult.subjectId.Equals(subject.id))
  1037. {
  1038. //List<int> phc = new List<int>();
  1039. List<int> ph = new List<int>();
  1040. List<int> pl = new List<int>();
  1041. List<int> pc = new List<int>();
  1042. List<double> persent = new List<double>();
  1043. int lostStu = classResult.status.Where(c => c == 1).ToList().Count;
  1044. for (int i = 0; i < knowledgeName.Count; i++)
  1045. {
  1046. //初始化单个知识点得分
  1047. double score = 0;
  1048. int n = 0;
  1049. int phCount = 0;
  1050. int plCount = 0;
  1051. int pCount = 0;
  1052. double classScore = 0;
  1053. foreach (List<string> str in info.papers[no].knowledge)
  1054. {
  1055. if (str.Contains(knowledgeName[i]))
  1056. {
  1057. var itemPersent = str.Count > 0 ? 1 / Convert.ToDouble(str.Count) : 0;
  1058. classScore += info.papers[no].point.Count > 0 ? (info.papers[no].point[n] * itemPersent) : 0;
  1059. foreach (string id in classResult.studentIds)
  1060. {
  1061. int index = classResult.studentIds.IndexOf(id);
  1062. if (classResult.studentScores.Count > 0)
  1063. {
  1064. if (classResult.studentScores[index].Count > 0)
  1065. {
  1066. double realScore = classResult.studentScores[index][n] == -1 ? 0 : classResult.studentScores[index][n] * itemPersent;
  1067. score += realScore;
  1068. //score += classResult.studentScores[index][n] == -1 ? 0 : classResult.studentScores[index][n] * itemPersent;
  1069. if (classResult.studentScores[index].Sum() >= rhw && phcount < rhwCount)
  1070. {
  1071. if (classResult.studentScores[index][n] <= 0)
  1072. {
  1073. phCount++;
  1074. }
  1075. phcount++;
  1076. continue;
  1077. }
  1078. if (classResult.studentScores[index].Sum() <= rhl && plcount < (info.stuCount - rhlCount))
  1079. {
  1080. if (classResult.studentScores[index][n] <= 0)
  1081. {
  1082. plCount++;
  1083. }
  1084. plcount++;
  1085. continue;
  1086. }
  1087. if (classResult.studentScores[index][n] <= 0)
  1088. {
  1089. pCount++;
  1090. }
  1091. }
  1092. }
  1093. }
  1094. }
  1095. n++;
  1096. }
  1097. pc.Add(pCount);
  1098. ph.Add(phCount);
  1099. pl.Add(plCount);
  1100. double per = classResult.studentIds.Count - lostStu > 0 ? Math.Round(score / (classResult.studentIds.Count - lostStu), 2) : 0;
  1101. persent.Add(classScore > 0 ? Math.Round(per * 1.0 / classScore, 2) : 0);
  1102. }
  1103. classResult.phc = ph;
  1104. classResult.plc = pl;
  1105. classResult.pc = pc;
  1106. classResult.krate = persent;
  1107. }
  1108. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new Azure.Cosmos.PartitionKey($"{classResult.code}"));
  1109. }
  1110. foreach (string k in knowledgeName)
  1111. {
  1112. double score = 0;
  1113. double allScore = 0;
  1114. int count = 0;
  1115. int m = 0;
  1116. foreach (List<string> str in info.papers[no].knowledge)
  1117. {
  1118. if (str.Contains(k))
  1119. {
  1120. var itemPersent = str.Count > 0 ? 1 / Convert.ToDouble(str.Count) : 0;
  1121. allScore += info.papers[no].point.Count > 0 ? info.papers[no].point[m] * itemPersent : 0;
  1122. }
  1123. m++;
  1124. }
  1125. foreach (ExamClassResult result in classResults)
  1126. {
  1127. if (result.subjectId.Equals(subject.id))
  1128. {
  1129. int n = 0;
  1130. foreach (List<string> str in info.papers[no].knowledge)
  1131. {
  1132. if (str.Contains(k))
  1133. {
  1134. var itemPersent = str.Count > 0 ? 1 / Convert.ToDouble(str.Count) : 0;
  1135. if (result.studentScores.Count > 0)
  1136. {
  1137. foreach (List<double> sc in result.studentScores)
  1138. {
  1139. double tsc = sc[n] == -1 ? 0 : sc[n];
  1140. score += (tsc * itemPersent);
  1141. }
  1142. }
  1143. }
  1144. n++;
  1145. }
  1146. count += result.studentIds.Count;
  1147. }
  1148. }
  1149. double per = count - info.lostStu.Count > 0 ? Math.Round(score / (count - info.lostStu.Count), 2) : 0;
  1150. akp.Add(allScore > 0 ? Math.Round(per / allScore, 2) : 0);
  1151. }
  1152. }
  1153. return akp;
  1154. }
  1155. catch (Exception ex)
  1156. {
  1157. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测知识点结算异常{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  1158. return null;
  1159. }
  1160. }
  1161. public static async Task<List<double>> fieldCount(ExamInfo info, ExamSubject subject, DingDing _dingDing, int no, List<ExamClassResult> classResults,
  1162. double rhwCount, double rhw, double rhlCount, double rhl, AzureCosmosFactory _azureCosmos)
  1163. {
  1164. List<double> afp = new();
  1165. try
  1166. {
  1167. int phcount = 0;
  1168. int plcount = 0;
  1169. //存放并去重知识点
  1170. List<int> knowledgeName = new List<int>() { 1, 2, 3, 4, 5, 6 };
  1171. /* knowledgeName.Add(1);
  1172. knowledgeName.Add(2);
  1173. knowledgeName.Add(3);
  1174. knowledgeName.Add(4);
  1175. knowledgeName.Add(5);
  1176. knowledgeName.Add(6);*/
  1177. foreach (ExamClassResult classResult in classResults)
  1178. {
  1179. if (classResult.subjectId.Equals(subject.id))
  1180. {
  1181. //List<int> phc = new List<int>();
  1182. List<int> ph = new List<int>();
  1183. List<int> pl = new List<int>();
  1184. List<int> pc = new List<int>();
  1185. List<double> persent = new List<double>();
  1186. int lostStu = classResult.status.Where(c => c == 1).ToList().Count;
  1187. for (int i = 0; i < knowledgeName.Count; i++)
  1188. {
  1189. //初始化单个知识点得分
  1190. double score = 0;
  1191. int n = 0;
  1192. int phCount = 0;
  1193. int plCount = 0;
  1194. int pCount = 0;
  1195. double classScore = 0;
  1196. if (info.papers[no].field.Count > 0)
  1197. {
  1198. foreach (int str in info.papers[no].field)
  1199. {
  1200. if (str == knowledgeName[i])
  1201. {
  1202. var itemPersent = 1;
  1203. classScore += info.papers[no].point.Count > 0 ? info.papers[no].point[n] * itemPersent : 0;
  1204. foreach (string id in classResult.studentIds)
  1205. {
  1206. int index = classResult.studentIds.IndexOf(id);
  1207. if (classResult.studentScores.Count > 0)
  1208. {
  1209. if (classResult.studentScores[index].Count > 0)
  1210. {
  1211. score += classResult.studentScores[index][n] == -1 ? 0 : classResult.studentScores[index][n];
  1212. if (classResult.studentScores[index].Sum() >= rhw && phcount < rhwCount)
  1213. {
  1214. if (classResult.studentScores[index][n] <= 0)
  1215. {
  1216. phCount++;
  1217. }
  1218. phcount++;
  1219. continue;
  1220. }
  1221. if (classResult.studentScores[index].Sum() <= rhl && plcount < (info.stuCount - rhlCount))
  1222. {
  1223. if (classResult.studentScores[index][n] <= 0)
  1224. {
  1225. plCount++;
  1226. }
  1227. plcount++;
  1228. continue;
  1229. }
  1230. if (classResult.studentScores[index][n] <= 0)
  1231. {
  1232. pCount++;
  1233. }
  1234. }
  1235. }
  1236. }
  1237. }
  1238. n++;
  1239. }
  1240. pc.Add(pCount);
  1241. ph.Add(phCount);
  1242. pl.Add(plCount);
  1243. double per = classResult.studentIds.Count - lostStu > 0 ? Math.Round(score / (classResult.studentIds.Count - lostStu), 2) : 0;
  1244. persent.Add(classScore > 0 ? Math.Round(per / classScore, 2) : 0);
  1245. }
  1246. }
  1247. classResult.fphc = ph;
  1248. classResult.fplc = pl;
  1249. classResult.fpc = pc;
  1250. classResult.frate = persent;
  1251. }
  1252. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new Azure.Cosmos.PartitionKey($"{classResult.code}"));
  1253. }
  1254. for (int i = 0; i < knowledgeName.Count; i++)
  1255. {
  1256. double score = 0;
  1257. double allScore = 0;
  1258. int count = 0;
  1259. int m = 0;
  1260. foreach (int str in info.papers[no].field)
  1261. {
  1262. if (str == knowledgeName[i])
  1263. {
  1264. var itemPersent = 1;
  1265. allScore += info.papers[no].point.Count > 0 ? info.papers[no].point[m] * itemPersent : 0;
  1266. }
  1267. m++;
  1268. }
  1269. foreach (ExamClassResult result in classResults)
  1270. {
  1271. if (result.subjectId.Equals(subject.id))
  1272. {
  1273. int n = 0;
  1274. foreach (int str in info.papers[no].field)
  1275. {
  1276. var itemPersent = 1;
  1277. if (str == knowledgeName[i])
  1278. {
  1279. if (result.studentScores.Count > 0)
  1280. {
  1281. foreach (List<double> sc in result.studentScores)
  1282. {
  1283. double tsc = sc[n] == -1 ? 0 : sc[n];
  1284. score += tsc * itemPersent;
  1285. }
  1286. }
  1287. }
  1288. n++;
  1289. }
  1290. count += result.studentIds.Count;
  1291. }
  1292. }
  1293. double per = count - info.lostStu.Count > 0 ? Math.Round(score / (count - info.lostStu.Count), 2) : 0;
  1294. afp.Add(allScore > 0 ? Math.Round(per / allScore, 2) : 0);
  1295. }
  1296. return afp;
  1297. }
  1298. catch (Exception ex)
  1299. {
  1300. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测认知层次结算异常{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  1301. return null;
  1302. }
  1303. }
  1304. //处理选题计数
  1305. public static List<Dictionary<string, int>> getMore(ExamInfo info, int no, List<List<List<string>>> list)
  1306. {
  1307. List<Dictionary<string, int>> recorde = new List<Dictionary<string, int>>();
  1308. try
  1309. {
  1310. for (int i = 0; i < info.papers[no].answers.Count; i++)
  1311. {
  1312. if (info.papers[no].answers[i].Count <= 0)
  1313. {
  1314. recorde.Add(new Dictionary<string, int>());
  1315. continue;
  1316. }
  1317. Dictionary<string, int> optCount = new Dictionary<string, int>();
  1318. foreach (List<List<string>> stu in list)
  1319. {
  1320. if (stu.Count == info.papers[no].answers.Count)
  1321. {
  1322. var item = stu[i];
  1323. foreach (string opt in item)
  1324. {
  1325. if (optCount.ContainsKey(opt))
  1326. {
  1327. optCount[opt] = optCount[opt] + 1;
  1328. }
  1329. else
  1330. {
  1331. optCount[opt] = 1;
  1332. }
  1333. }
  1334. }
  1335. }
  1336. recorde.Add(optCount);
  1337. }
  1338. return recorde;
  1339. }
  1340. catch (Exception)
  1341. {
  1342. return recorde;
  1343. }
  1344. }
  1345. public static async Task createClassResultAsync(ExamInfo info, List<ExamClassResult> examClassResults, ExamSubject subject, int no, AzureCosmosFactory _azureCosmos, DingDing _dingDing, AzureStorageFactory _azureStorage, IHttpClientFactory _httpClient, IConfiguration _configuration)
  1346. {
  1347. //保证试卷信息与科目信息同步
  1348. ExamResult result = new ExamResult();
  1349. //人数总和
  1350. int Count = 0;
  1351. int m = 0;
  1352. double score = 0;
  1353. //标准差
  1354. //double powSum = 0;
  1355. double allScore = info.papers[no].point.Sum();
  1356. List<ClassRange> classRanges = new List<ClassRange>();
  1357. List<string> lostStu = new List<string>();
  1358. List<double> csRate = new List<double>();
  1359. List<List<List<string>>> opt = new List<List<List<string>>>();
  1360. //List<Task<ItemResponse<ExamClassResult>>> tasks = new();
  1361. foreach (ExamClassResult classResult in examClassResults)
  1362. {
  1363. double classSrate = 0;
  1364. if (classResult.subjectId.Equals(subject.id))
  1365. {
  1366. foreach (List<List<string>> op in classResult.ans)
  1367. {
  1368. opt.Add(op);
  1369. }
  1370. //记录缺考学生索引位置
  1371. int index_stu = 0;
  1372. foreach (var ans in classResult.studentAnswers)
  1373. {
  1374. if (ans.Count == 0)
  1375. {
  1376. if (!lostStu.Contains(classResult.studentIds[index_stu]))
  1377. {
  1378. lostStu.Add(classResult.studentIds[index_stu]);
  1379. }
  1380. }
  1381. else
  1382. {
  1383. if (classResult.status[index_stu] == 1)
  1384. {
  1385. if (!lostStu.Contains(classResult.studentIds[index_stu]))
  1386. {
  1387. lostStu.Add(classResult.studentIds[index_stu]);
  1388. }
  1389. }
  1390. }
  1391. index_stu++;
  1392. }
  1393. int index = 0;
  1394. foreach (List<double> scores in classResult.studentScores)
  1395. {
  1396. List<double> newScores = new List<double>();
  1397. //int count = 0;
  1398. if (scores.Count > 0)
  1399. {
  1400. foreach (double sc in scores)
  1401. {
  1402. newScores.Add(sc > -1 ? sc : 0);
  1403. }
  1404. }
  1405. else {
  1406. newScores.Add(0);
  1407. }
  1408. classSrate += newScores.Sum();
  1409. score += newScores.Sum();
  1410. result.studentScores.Add(newScores);
  1411. index++;
  1412. }
  1413. //处理班级信息
  1414. ClassRange range = new ClassRange();
  1415. range.id = classResult.info.id;
  1416. range.name = classResult.info.name;
  1417. range.gradeId = classResult.gradeId;
  1418. List<int> ran = new List<int>();
  1419. int stuCount = classResult.studentIds.Count;
  1420. //todo 与实际的缺考人数比较
  1421. int lostStus = classResult.status.Where(c => c == 1).ToList().Count;
  1422. Count += stuCount;
  1423. if (m == 0)
  1424. {
  1425. ran.Add(0);
  1426. ran.Add(stuCount - 1);
  1427. }
  1428. else
  1429. {
  1430. ran.Add(Count - stuCount);
  1431. ran.Add(Count - 1);
  1432. }
  1433. m++;
  1434. range.range = ran;
  1435. classRanges.Add(range);
  1436. //处理学生ID
  1437. foreach (string id in classResult.studentIds)
  1438. {
  1439. result.studentIds.Add(id);
  1440. }
  1441. if (allScore > 0)
  1442. {
  1443. csRate.Add(classResult.studentIds.Count - lostStus > 0 ? Math.Round(classSrate * 1.0 / (classResult.studentIds.Count - lostStus), 2) : 0 / allScore);
  1444. }
  1445. else
  1446. {
  1447. csRate.Add(0);
  1448. }
  1449. //powSum += Math.Pow(classSrate - result.average, 2);
  1450. //处理选项计数内容
  1451. }
  1452. //tasks.Add(_azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new PartitionKey($"{classResult.code}")));
  1453. }
  1454. //await tasks.TaskPage(10);
  1455. /*foreach (string id in result.lostStus) {
  1456. if (!examClassResults[0].studentIds.Contains(id)) {
  1457. int index = result.lostStus.IndexOf(id);
  1458. result.lostStus.RemoveAt(index);
  1459. }
  1460. }*/
  1461. //处理人员变更时被移除的人员
  1462. result.lostStus = lostStu;
  1463. List<string> stuIds = examClassResults.SelectMany(x => x.studentIds).ToList();
  1464. if (result.lostStus.Count > 0)
  1465. {
  1466. for (int i = 0; i < result.lostStus.Count; i++)
  1467. {
  1468. if (!stuIds.Contains(result.lostStus[i]))
  1469. {
  1470. result.lostStus.RemoveAt(i);
  1471. }
  1472. }
  1473. }
  1474. result.record = getMore(info, no, opt);
  1475. result.average = result.studentIds.Count - result.lostStus.Count > 0 ? Math.Round(score * 1.0 / (result.studentIds.Count - result.lostStus.Count), 2) : 0;
  1476. double powSum = 0;
  1477. //int sco = 0;
  1478. result.studentIds.ForEach(x =>
  1479. {
  1480. double sc = result.studentScores[result.studentIds.IndexOf(x)].Sum();
  1481. if (!result.lostStus.Contains(x))
  1482. {
  1483. powSum += Math.Pow(sc - result.average, 2);
  1484. }
  1485. });
  1486. result.standard = Math.Round((result.studentIds.Count - result.lostStus.Count) > 0 ? Math.Pow(powSum / (result.studentIds.Count - result.lostStus.Count), 0.5) : 0, 2);
  1487. result.csRate = csRate;
  1488. result.sRate = allScore > 0 ? Math.Round(result.average / allScore * 100, 2) : 0;
  1489. result.classes = classRanges;
  1490. result.code = "ExamResult-" + info.id;
  1491. result.school = info.school;
  1492. result.id = subject.id;
  1493. result.examId = info.id;
  1494. result.subjectId = subject.id;
  1495. result.year = info.year;
  1496. result.paper = info.papers[no];
  1497. //result.point = info.papers[j].point;
  1498. result.scope = info.scope;
  1499. result.name = info.name;
  1500. result.time = info.startTime;
  1501. await examRecordCount(info, subject, _dingDing, no, result, examClassResults, _azureCosmos);
  1502. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").UpsertItemAsync(result, new Azure.Cosmos.PartitionKey($"ExamResult-{info.id}"));
  1503. List<ErrorItems> errorItems = new();
  1504. 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}'"))})";
  1505. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Student").GetItemQueryIterator<ErrorItems>(queryText: sqlqueryText, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("ErrorItems") }))
  1506. {
  1507. errorItems.Add(item);
  1508. }
  1509. try {
  1510. /* bool isError = examClassResults.SelectMany(c => c.status).ToList().Exists(z => z == 1);
  1511. if () {
  1512. }*/
  1513. if (errorItems.Count == 0)
  1514. {
  1515. // 新增逻辑 收集错题内容
  1516. BlobDownloadResult index_json;
  1517. if (info.scope.Equals("school"))
  1518. {
  1519. index_json = await _azureStorage.GetBlobContainerClient($"{info.school}").GetBlobClient($"{info.papers[no].blob}/index.json").DownloadContentAsync();
  1520. }
  1521. else
  1522. {
  1523. index_json = await _azureStorage.GetBlobContainerClient($"{info.creatorId}").GetBlobClient($"{info.papers[no].blob}/index.json").DownloadContentAsync();
  1524. }
  1525. //BlobDownloadResult index_json = await _azureStorage.GetBlobContainerClient($"{info.school}").GetBlobClient($"{info.papers[no].blob}/index.json").DownloadContentAsync();
  1526. JObject jo = JObject.Parse(index_json.Content.ToString());
  1527. JArray array = jo.Value<JArray>("slides");
  1528. List<string> urls = new();
  1529. foreach (var ne in array)
  1530. {
  1531. if (!ne["type"].ToString().Equals("compose"))
  1532. {
  1533. urls.Add(ne["url"].ToString());
  1534. }
  1535. }
  1536. string code = string.Empty;
  1537. string pk = string.Empty;
  1538. string table = "School";
  1539. if (info.scope.Equals("school"))
  1540. {
  1541. code = $"ErrorItems-{info.school}";
  1542. pk = $"Item-{info.school}";
  1543. }
  1544. else
  1545. {
  1546. code = "ErrorItems";
  1547. pk = $"Item-{info.creatorId}";
  1548. table = "Teacher";
  1549. }
  1550. // 获取整体的题目ID集合
  1551. List<string> ids = new();
  1552. List<(string id, string pid, int level, string type, List<string> knows)> itemInfos = new();
  1553. foreach (string url in urls)
  1554. {
  1555. string id = url.Replace(".json", "");
  1556. BlobDownloadResult index_item_json;
  1557. if (info.scope.Equals("school"))
  1558. {
  1559. index_item_json = await _azureStorage.GetBlobContainerClient($"{info.school}").GetBlobClient($"{info.papers[no].blob}/{url}").DownloadContentAsync();
  1560. }
  1561. else
  1562. {
  1563. index_item_json = await _azureStorage.GetBlobContainerClient($"{info.creatorId}").GetBlobClient($"{info.papers[no].blob}/{url}").DownloadContentAsync();
  1564. }
  1565. JObject keys = JObject.Parse(index_item_json.Content.ToString());
  1566. string type = keys["exercise"].Value<string>("type");
  1567. int level = keys["exercise"].Value<int>("level");
  1568. var knowledge = keys["exercise"].Value<JArray>("knowledge")?.ToObject<List<string>>();
  1569. string pid = keys.Value<string>("pid");
  1570. itemInfos.Add((id, pid, level, type, knowledge));
  1571. }
  1572. /*await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, table).GetItemQueryStreamIterator(
  1573. queryText: $"select c.id,c.pid,c.level,c.type from c where c.id in ({string.Join(",", ids.Select(o => $"'{o}'"))})", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{pk}") }))
  1574. {
  1575. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  1576. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  1577. {
  1578. var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
  1579. while (accounts.MoveNext())
  1580. {
  1581. JsonElement account = accounts.Current;
  1582. string pid = "";
  1583. if (account.TryGetProperty("pid",out JsonElement element)) {
  1584. pid = element.GetString();
  1585. }
  1586. itemInfos.Add((account.GetProperty("id").GetString(), pid, account.GetProperty("level").GetInt32(), account.GetProperty("type").GetString()));
  1587. }
  1588. }
  1589. }*/
  1590. /* double[] point = StringHelper.ListTodouble(result.paper.point);
  1591. double[,] res = StringHelper.ListToDouble(result.studentScores);
  1592. var cdm = new ClouDASMatrix(res, point);*/
  1593. //需要努力的题目
  1594. //var ss = cdm.StriveTopic;
  1595. int n = 0;
  1596. List<Task<ItemResponse<ErrorItems>>> task_error = new();
  1597. List<ErrorItems> errors = new();
  1598. foreach (var sIds in result.studentIds)
  1599. {
  1600. ErrorItems error = new()
  1601. {
  1602. ttl = -1,
  1603. code = code,
  1604. id = Guid.NewGuid().ToString(),
  1605. stuId = sIds,
  1606. school = info.school,
  1607. activityId = info.id,
  1608. subjectId = result.subjectId,
  1609. time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
  1610. };
  1611. int index_stu = result.studentIds.IndexOf(sIds);
  1612. //顺序学生错题的索引
  1613. var itemScore = result.studentScores[index_stu];
  1614. List<int> index = new();
  1615. int index_item = 0;
  1616. foreach (var sc in itemScore) {
  1617. if (sc == 0) {
  1618. index.Add(index_item+1);
  1619. }
  1620. index_item++;
  1621. }
  1622. if (index.Count == 0) {
  1623. continue;
  1624. }
  1625. //int[] item_index = ss[n];
  1626. foreach (var item in index)
  1627. {
  1628. Items items = new()
  1629. {
  1630. id = urls[item - 1].Replace(".json", ""),
  1631. blob = info.papers[no].blob
  1632. };
  1633. items.level = itemInfos.Where(c => c.id.Equals(items.id)).FirstOrDefault().level;
  1634. items.type = itemInfos.Where(c => c.id.Equals(items.id)).FirstOrDefault().type;
  1635. items.pId = itemInfos.Where(c => c.id.Equals(items.id)).FirstOrDefault().pid;
  1636. items.knowledge = itemInfos.Where(c => c.id.Equals(items.id)).FirstOrDefault().knows;
  1637. error.its.Add(items);
  1638. }
  1639. errors.Add(error);
  1640. n++;
  1641. task_error.Add(_azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student").CreateItemAsync(error, new PartitionKey($"{error.code}")));
  1642. }
  1643. //string connect = _configuration.GetValue<string>("HaBookAuth:Crtmabank") + "https://malearnfunction.chinacloudsites.cn/api/crtmabank";
  1644. string location = $"{Environment.GetEnvironmentVariable("Option:Location")}";
  1645. string urlAction = string.Empty;
  1646. string accessKey = string.Empty;
  1647. if (location.Contains("China"))
  1648. {
  1649. if(location.Equals("China")) //大陸正式站
  1650. {
  1651. urlAction = "https://malearn.teammodel.cn";
  1652. accessKey = "QUzQqbqbnLsTDTeaJy4Br6wUuqPoAlKpzRK2S6PGImRHAzFuySGAeA==";
  1653. }
  1654. else if(location.Equals("China-Dep") || location.Equals("China-Test")) //大陸測試站
  1655. {
  1656. urlAction = "https://malearn-rc.teammodel.cn";
  1657. accessKey = "hESc0g7Q60FTEss4ZnVXPB61S1a8WlAXIq5ULl3T3oTxAzFunpLDwA==";
  1658. }
  1659. }
  1660. else if (location.Contains("Global"))
  1661. {
  1662. if(location.Equals("Global")) //國際正式站
  1663. {
  1664. urlAction = "https://malearn.teammodel.net";
  1665. accessKey = "I-2lTcdggJkZWSBwOXQIm4oHx-huwX3d0wLe-9pgojThAzFuq_KNFg==";
  1666. }
  1667. else if(location.Equals("Global-Test")) //國際測試站
  1668. {
  1669. urlAction = "https://malearn-rc.teammodel.net";
  1670. accessKey = "_l4Cb_tHIRBw_iv3ZuwVqjkMwjg4_HtDaxhAmZ8OwJraAzFu_DAY8A==";
  1671. }
  1672. }
  1673. string connect = $"{urlAction}/api/crtmabank";
  1674. var htc = _httpClient.CreateClient();
  1675. if (htc.DefaultRequestHeaders.Contains("x-functions-key"))
  1676. {
  1677. htc.DefaultRequestHeaders.Remove("x-functions-key");
  1678. }
  1679. htc.DefaultRequestHeaders.Add("x-functions-key", accessKey);
  1680. string paramJson = JsonConvert.SerializeObject(errors);
  1681. var content = new StringContent(paramJson, Encoding.UTF8, "application/json");
  1682. await htc.PostAsync(connect, content);
  1683. await task_error.TaskPage(10);
  1684. }
  1685. } catch (Exception e) {
  1686. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测错题异常{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  1687. }
  1688. }
  1689. public class Settlement
  1690. {
  1691. public double rate { get; set; }
  1692. public double score { get; set; }
  1693. public List<string> stus { get; set; } = new List<string>();
  1694. public int total { get; set; }
  1695. public double qrate { get; set; }
  1696. }
  1697. }
  1698. }