TriggerExam.cs 95 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732
  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 ActivityService.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. if (addTmdidsCls.IsNotEmpty())
  836. {
  837. addTmdidsCls.ForEach(x =>
  838. {
  839. HashSet<string> classIds = new HashSet<string>();
  840. classLists.ForEach(z =>
  841. {
  842. z.members.ForEach(y =>
  843. {
  844. if (y.id.Equals(x.id) && y.type == 1)
  845. {
  846. classIds.Add(z.id);
  847. }
  848. });
  849. });
  850. bool iss = false;
  851. //标记学生作答状态
  852. int ts = 0;
  853. if (results.Count > 0)
  854. {
  855. foreach (ExamClassResult exam in results)
  856. {
  857. int index = exam.studentIds.IndexOf(x.id);
  858. if (index != -1)
  859. {
  860. if (exam.studentAnswers[index].Count > 0)
  861. {
  862. bool flag = exam.studentScores[index].Exists(x => x == -1);
  863. if (!flag)
  864. {
  865. ts = 1;
  866. iss = true;
  867. break;
  868. }
  869. else
  870. {
  871. ts = 0;
  872. }
  873. }
  874. else
  875. {
  876. ts = -1;
  877. }
  878. }
  879. }
  880. }
  881. else
  882. {
  883. ts = -1;
  884. }
  885. tmdActivities.Add(new StuActivity
  886. {
  887. pk = "Activity",
  888. id = info.id,
  889. code = $"Activity-{x.id}",
  890. type = "Exam",
  891. name = info.name,
  892. source = info.source,
  893. startTime = info.startTime,
  894. endTime = info.endTime,
  895. scode = info.code,
  896. scope = info.scope,
  897. school = info.school,
  898. creatorId = info.creatorId,
  899. subjects = sub,
  900. blob = null,
  901. owner = info.owner,
  902. createTime = info.createTime,
  903. taskStatus = ts,
  904. qamode = info.qamode,
  905. ext = new Dictionary<string, JsonElement>() { { "type", info.examType.ToJsonString().ToObject<JsonElement>() },
  906. { "subjects", info.subjects.ToJsonString().ToObject<JsonElement>() } },
  907. sStatus = iss ? 1 : 0,
  908. classIds = classIds.ToList()
  909. });
  910. });
  911. }
  912. if (addStudentsCls.IsNotEmpty())
  913. {
  914. addStudentsCls.ForEach(x =>
  915. {
  916. HashSet<string> classIds = new HashSet<string>();
  917. classLists.ForEach(z =>
  918. {
  919. z.members.ForEach(y =>
  920. {
  921. if (y.id.Equals(x.id) && y.code.Equals(info.school) && y.type == 2)
  922. {
  923. classIds.Add(z.id);
  924. }
  925. });
  926. });
  927. bool iss = false;
  928. //标记学生作答状态
  929. int ts = 0;
  930. if (results.Count > 0)
  931. {
  932. foreach (ExamClassResult exam in results)
  933. {
  934. int index = exam.studentIds.IndexOf(x.id);
  935. if (index != -1)
  936. {
  937. if (exam.studentAnswers[index].Count > 0)
  938. {
  939. bool flag = exam.studentScores[index].Exists(x => x == -1);
  940. if (!flag)
  941. {
  942. ts = 1;
  943. iss = true;
  944. break;
  945. }
  946. else
  947. {
  948. ts = 0;
  949. }
  950. }
  951. else
  952. {
  953. ts = -1;
  954. }
  955. }
  956. }
  957. }
  958. else
  959. {
  960. ts = -1;
  961. }
  962. stuActivities.Add(new StuActivity
  963. {
  964. pk = "Activity",
  965. id = info.id,
  966. code = $"Activity-{x.code.Replace("Base-", "")}-{x.id}",
  967. type = "Exam",
  968. name = info.name,
  969. source = info.source,
  970. startTime = info.startTime,
  971. endTime = info.endTime,
  972. scode = info.code,
  973. scope = info.scope,
  974. school = info.school,
  975. creatorId = info.creatorId,
  976. subjects = sub,
  977. blob = null,
  978. owner = info.owner,
  979. classIds = classIds.ToList(),
  980. createTime = info.createTime,
  981. qamode = info.qamode,
  982. ext = new Dictionary<string, JsonElement>() { { "type", info.examType.ToJsonString().ToObject<JsonElement>() },
  983. { "subjects", info.subjects.ToJsonString().ToObject<JsonElement>() } },
  984. taskStatus = ts,
  985. sStatus = iss ? 1 : 0,
  986. });
  987. });
  988. }
  989. await ActivityService.SaveStuActivity(client, _dingDing, stuActivities, tmdActivities, null);
  990. return classLists;
  991. }
  992. public static async Task<List<double>> knowledgeCount(ExamInfo info, ExamSubject subject, DingDing _dingDing, int no, List<ExamClassResult> classResults,
  993. double rhwCount, double rhw, double rhlCount, double rhl, AzureCosmosFactory _azureCosmos)
  994. {
  995. List<double> akp = new();
  996. try
  997. {
  998. int phcount = 0;
  999. int plcount = 0;
  1000. //存放并去重知识点
  1001. HashSet<string> kname = new HashSet<string>();
  1002. if (info.papers[no].knowledge.Count > 0)
  1003. {
  1004. info.papers[no].knowledge.ForEach(kno =>
  1005. {
  1006. kno.ForEach(k =>
  1007. {
  1008. kname.Add(k);
  1009. });
  1010. });
  1011. List<string> knowledgeName = new List<string>();
  1012. foreach (string cla in kname)
  1013. {
  1014. knowledgeName.Add(cla);
  1015. }
  1016. for (int k = 0; k < knowledgeName.Count; k++)
  1017. {
  1018. if (null == knowledgeName[k])
  1019. {
  1020. knowledgeName.Remove(knowledgeName[k]);
  1021. }
  1022. }
  1023. foreach (ExamClassResult classResult in classResults)
  1024. {
  1025. if (classResult.subjectId.Equals(subject.id))
  1026. {
  1027. //List<int> phc = new List<int>();
  1028. List<int> ph = new List<int>();
  1029. List<int> pl = new List<int>();
  1030. List<int> pc = new List<int>();
  1031. List<double> persent = new List<double>();
  1032. int lostStu = classResult.status.Where(c => c == 1).ToList().Count;
  1033. for (int i = 0; i < knowledgeName.Count; i++)
  1034. {
  1035. //初始化单个知识点得分
  1036. double score = 0;
  1037. int n = 0;
  1038. int phCount = 0;
  1039. int plCount = 0;
  1040. int pCount = 0;
  1041. double classScore = 0;
  1042. foreach (List<string> str in info.papers[no].knowledge)
  1043. {
  1044. if (str.Contains(knowledgeName[i]))
  1045. {
  1046. var itemPersent = str.Count > 0 ? 1 / Convert.ToDouble(str.Count) : 0;
  1047. classScore += info.papers[no].point.Count > 0 ? (info.papers[no].point[n] * itemPersent) : 0;
  1048. foreach (string id in classResult.studentIds)
  1049. {
  1050. int index = classResult.studentIds.IndexOf(id);
  1051. if (classResult.studentScores.Count > 0)
  1052. {
  1053. if (classResult.studentScores[index].Count > 0)
  1054. {
  1055. double realScore = classResult.studentScores[index][n] == -1 ? 0 : classResult.studentScores[index][n] * itemPersent;
  1056. score += realScore;
  1057. //score += classResult.studentScores[index][n] == -1 ? 0 : classResult.studentScores[index][n] * itemPersent;
  1058. if (classResult.studentScores[index].Sum() >= rhw && phcount < rhwCount)
  1059. {
  1060. if (classResult.studentScores[index][n] <= 0)
  1061. {
  1062. phCount++;
  1063. }
  1064. phcount++;
  1065. continue;
  1066. }
  1067. if (classResult.studentScores[index].Sum() <= rhl && plcount < (info.stuCount - rhlCount))
  1068. {
  1069. if (classResult.studentScores[index][n] <= 0)
  1070. {
  1071. plCount++;
  1072. }
  1073. plcount++;
  1074. continue;
  1075. }
  1076. if (classResult.studentScores[index][n] <= 0)
  1077. {
  1078. pCount++;
  1079. }
  1080. }
  1081. }
  1082. }
  1083. }
  1084. n++;
  1085. }
  1086. pc.Add(pCount);
  1087. ph.Add(phCount);
  1088. pl.Add(plCount);
  1089. double per = classResult.studentIds.Count - lostStu > 0 ? Math.Round(score / (classResult.studentIds.Count - lostStu), 2) : 0;
  1090. persent.Add(classScore > 0 ? Math.Round(per * 1.0 / classScore, 2) : 0);
  1091. }
  1092. classResult.phc = ph;
  1093. classResult.plc = pl;
  1094. classResult.pc = pc;
  1095. classResult.krate = persent;
  1096. }
  1097. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new Azure.Cosmos.PartitionKey($"{classResult.code}"));
  1098. }
  1099. foreach (string k in knowledgeName)
  1100. {
  1101. double score = 0;
  1102. double allScore = 0;
  1103. int count = 0;
  1104. int m = 0;
  1105. foreach (List<string> str in info.papers[no].knowledge)
  1106. {
  1107. if (str.Contains(k))
  1108. {
  1109. var itemPersent = str.Count > 0 ? 1 / Convert.ToDouble(str.Count) : 0;
  1110. allScore += info.papers[no].point.Count > 0 ? info.papers[no].point[m] * itemPersent : 0;
  1111. }
  1112. m++;
  1113. }
  1114. foreach (ExamClassResult result in classResults)
  1115. {
  1116. if (result.subjectId.Equals(subject.id))
  1117. {
  1118. int n = 0;
  1119. foreach (List<string> str in info.papers[no].knowledge)
  1120. {
  1121. if (str.Contains(k))
  1122. {
  1123. var itemPersent = str.Count > 0 ? 1 / Convert.ToDouble(str.Count) : 0;
  1124. if (result.studentScores.Count > 0)
  1125. {
  1126. foreach (List<double> sc in result.studentScores)
  1127. {
  1128. double tsc = sc[n] == -1 ? 0 : sc[n];
  1129. score += (tsc * itemPersent);
  1130. }
  1131. }
  1132. }
  1133. n++;
  1134. }
  1135. count += result.studentIds.Count;
  1136. }
  1137. }
  1138. double per = count - info.lostStu.Count > 0 ? Math.Round(score / (count - info.lostStu.Count), 2) : 0;
  1139. akp.Add(allScore > 0 ? Math.Round(per / allScore, 2) : 0);
  1140. }
  1141. }
  1142. return akp;
  1143. }
  1144. catch (Exception ex)
  1145. {
  1146. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测知识点结算异常{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  1147. return null;
  1148. }
  1149. }
  1150. public static async Task<List<double>> fieldCount(ExamInfo info, ExamSubject subject, DingDing _dingDing, int no, List<ExamClassResult> classResults,
  1151. double rhwCount, double rhw, double rhlCount, double rhl, AzureCosmosFactory _azureCosmos)
  1152. {
  1153. List<double> afp = new();
  1154. try
  1155. {
  1156. int phcount = 0;
  1157. int plcount = 0;
  1158. //存放并去重知识点
  1159. List<int> knowledgeName = new List<int>() { 1, 2, 3, 4, 5, 6 };
  1160. /* knowledgeName.Add(1);
  1161. knowledgeName.Add(2);
  1162. knowledgeName.Add(3);
  1163. knowledgeName.Add(4);
  1164. knowledgeName.Add(5);
  1165. knowledgeName.Add(6);*/
  1166. foreach (ExamClassResult classResult in classResults)
  1167. {
  1168. if (classResult.subjectId.Equals(subject.id))
  1169. {
  1170. //List<int> phc = new List<int>();
  1171. List<int> ph = new List<int>();
  1172. List<int> pl = new List<int>();
  1173. List<int> pc = new List<int>();
  1174. List<double> persent = new List<double>();
  1175. int lostStu = classResult.status.Where(c => c == 1).ToList().Count;
  1176. for (int i = 0; i < knowledgeName.Count; i++)
  1177. {
  1178. //初始化单个知识点得分
  1179. double score = 0;
  1180. int n = 0;
  1181. int phCount = 0;
  1182. int plCount = 0;
  1183. int pCount = 0;
  1184. double classScore = 0;
  1185. if (info.papers[no].field.Count > 0)
  1186. {
  1187. foreach (int str in info.papers[no].field)
  1188. {
  1189. if (str == knowledgeName[i])
  1190. {
  1191. var itemPersent = 1;
  1192. classScore += info.papers[no].point.Count > 0 ? info.papers[no].point[n] * itemPersent : 0;
  1193. foreach (string id in classResult.studentIds)
  1194. {
  1195. int index = classResult.studentIds.IndexOf(id);
  1196. if (classResult.studentScores.Count > 0)
  1197. {
  1198. if (classResult.studentScores[index].Count > 0)
  1199. {
  1200. score += classResult.studentScores[index][n] == -1 ? 0 : classResult.studentScores[index][n];
  1201. if (classResult.studentScores[index].Sum() >= rhw && phcount < rhwCount)
  1202. {
  1203. if (classResult.studentScores[index][n] <= 0)
  1204. {
  1205. phCount++;
  1206. }
  1207. phcount++;
  1208. continue;
  1209. }
  1210. if (classResult.studentScores[index].Sum() <= rhl && plcount < (info.stuCount - rhlCount))
  1211. {
  1212. if (classResult.studentScores[index][n] <= 0)
  1213. {
  1214. plCount++;
  1215. }
  1216. plcount++;
  1217. continue;
  1218. }
  1219. if (classResult.studentScores[index][n] <= 0)
  1220. {
  1221. pCount++;
  1222. }
  1223. }
  1224. }
  1225. }
  1226. }
  1227. n++;
  1228. }
  1229. pc.Add(pCount);
  1230. ph.Add(phCount);
  1231. pl.Add(plCount);
  1232. double per = classResult.studentIds.Count - lostStu > 0 ? Math.Round(score / (classResult.studentIds.Count - lostStu), 2) : 0;
  1233. persent.Add(classScore > 0 ? Math.Round(per / classScore, 2) : 0);
  1234. }
  1235. }
  1236. classResult.fphc = ph;
  1237. classResult.fplc = pl;
  1238. classResult.fpc = pc;
  1239. classResult.frate = persent;
  1240. }
  1241. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new Azure.Cosmos.PartitionKey($"{classResult.code}"));
  1242. }
  1243. for (int i = 0; i < knowledgeName.Count; i++)
  1244. {
  1245. double score = 0;
  1246. double allScore = 0;
  1247. int count = 0;
  1248. int m = 0;
  1249. foreach (int str in info.papers[no].field)
  1250. {
  1251. if (str == knowledgeName[i])
  1252. {
  1253. var itemPersent = 1;
  1254. allScore += info.papers[no].point.Count > 0 ? info.papers[no].point[m] * itemPersent : 0;
  1255. }
  1256. m++;
  1257. }
  1258. foreach (ExamClassResult result in classResults)
  1259. {
  1260. if (result.subjectId.Equals(subject.id))
  1261. {
  1262. int n = 0;
  1263. foreach (int str in info.papers[no].field)
  1264. {
  1265. var itemPersent = 1;
  1266. if (str == knowledgeName[i])
  1267. {
  1268. if (result.studentScores.Count > 0)
  1269. {
  1270. foreach (List<double> sc in result.studentScores)
  1271. {
  1272. double tsc = sc[n] == -1 ? 0 : sc[n];
  1273. score += tsc * itemPersent;
  1274. }
  1275. }
  1276. }
  1277. n++;
  1278. }
  1279. count += result.studentIds.Count;
  1280. }
  1281. }
  1282. double per = count - info.lostStu.Count > 0 ? Math.Round(score / (count - info.lostStu.Count), 2) : 0;
  1283. afp.Add(allScore > 0 ? Math.Round(per / allScore, 2) : 0);
  1284. }
  1285. return afp;
  1286. }
  1287. catch (Exception ex)
  1288. {
  1289. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测认知层次结算异常{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  1290. return null;
  1291. }
  1292. }
  1293. //处理选题计数
  1294. public static List<Dictionary<string, int>> getMore(ExamInfo info, int no, List<List<List<string>>> list)
  1295. {
  1296. List<Dictionary<string, int>> recorde = new List<Dictionary<string, int>>();
  1297. try
  1298. {
  1299. for (int i = 0; i < info.papers[no].answers.Count; i++)
  1300. {
  1301. if (info.papers[no].answers[i].Count <= 0)
  1302. {
  1303. recorde.Add(new Dictionary<string, int>());
  1304. continue;
  1305. }
  1306. Dictionary<string, int> optCount = new Dictionary<string, int>();
  1307. foreach (List<List<string>> stu in list)
  1308. {
  1309. if (stu.Count == info.papers[no].answers.Count)
  1310. {
  1311. var item = stu[i];
  1312. foreach (string opt in item)
  1313. {
  1314. if (optCount.ContainsKey(opt))
  1315. {
  1316. optCount[opt] = optCount[opt] + 1;
  1317. }
  1318. else
  1319. {
  1320. optCount[opt] = 1;
  1321. }
  1322. }
  1323. }
  1324. }
  1325. recorde.Add(optCount);
  1326. }
  1327. return recorde;
  1328. }
  1329. catch (Exception)
  1330. {
  1331. return recorde;
  1332. }
  1333. }
  1334. public static async Task createClassResultAsync(ExamInfo info, List<ExamClassResult> examClassResults, ExamSubject subject, int no, AzureCosmosFactory _azureCosmos, DingDing _dingDing, AzureStorageFactory _azureStorage, IHttpClientFactory _httpClient, IConfiguration _configuration)
  1335. {
  1336. //保证试卷信息与科目信息同步
  1337. ExamResult result = new ExamResult();
  1338. //人数总和
  1339. int Count = 0;
  1340. int m = 0;
  1341. double score = 0;
  1342. //标准差
  1343. //double powSum = 0;
  1344. double allScore = info.papers[no].point.Sum();
  1345. List<ClassRange> classRanges = new List<ClassRange>();
  1346. List<string> lostStu = new List<string>();
  1347. List<double> csRate = new List<double>();
  1348. List<List<List<string>>> opt = new List<List<List<string>>>();
  1349. //List<Task<ItemResponse<ExamClassResult>>> tasks = new();
  1350. foreach (ExamClassResult classResult in examClassResults)
  1351. {
  1352. double classSrate = 0;
  1353. if (classResult.subjectId.Equals(subject.id))
  1354. {
  1355. foreach (List<List<string>> op in classResult.ans)
  1356. {
  1357. opt.Add(op);
  1358. }
  1359. //记录缺考学生索引位置
  1360. int index_stu = 0;
  1361. foreach (var ans in classResult.studentAnswers)
  1362. {
  1363. if (ans.Count == 0)
  1364. {
  1365. if (!lostStu.Contains(classResult.studentIds[index_stu]))
  1366. {
  1367. lostStu.Add(classResult.studentIds[index_stu]);
  1368. }
  1369. }
  1370. else
  1371. {
  1372. if (classResult.status[index_stu] == 1)
  1373. {
  1374. if (!lostStu.Contains(classResult.studentIds[index_stu]))
  1375. {
  1376. lostStu.Add(classResult.studentIds[index_stu]);
  1377. }
  1378. }
  1379. }
  1380. index_stu++;
  1381. }
  1382. int index = 0;
  1383. foreach (List<double> scores in classResult.studentScores)
  1384. {
  1385. List<double> newScores = new List<double>();
  1386. //int count = 0;
  1387. if (scores.Count > 0)
  1388. {
  1389. foreach (double sc in scores)
  1390. {
  1391. newScores.Add(sc > -1 ? sc : 0);
  1392. }
  1393. }
  1394. else {
  1395. newScores.Add(0);
  1396. }
  1397. classSrate += newScores.Sum();
  1398. score += newScores.Sum();
  1399. result.studentScores.Add(newScores);
  1400. index++;
  1401. }
  1402. //处理班级信息
  1403. ClassRange range = new ClassRange();
  1404. range.id = classResult.info.id;
  1405. range.name = classResult.info.name;
  1406. range.gradeId = classResult.gradeId;
  1407. List<int> ran = new List<int>();
  1408. int stuCount = classResult.studentIds.Count;
  1409. //todo 与实际的缺考人数比较
  1410. int lostStus = classResult.status.Where(c => c == 1).ToList().Count;
  1411. Count += stuCount;
  1412. if (m == 0)
  1413. {
  1414. ran.Add(0);
  1415. ran.Add(stuCount - 1);
  1416. }
  1417. else
  1418. {
  1419. ran.Add(Count - stuCount);
  1420. ran.Add(Count - 1);
  1421. }
  1422. m++;
  1423. range.range = ran;
  1424. classRanges.Add(range);
  1425. //处理学生ID
  1426. foreach (string id in classResult.studentIds)
  1427. {
  1428. result.studentIds.Add(id);
  1429. }
  1430. if (allScore > 0)
  1431. {
  1432. csRate.Add(classResult.studentIds.Count - lostStus > 0 ? Math.Round(classSrate * 1.0 / (classResult.studentIds.Count - lostStus), 2) : 0 / allScore);
  1433. }
  1434. else
  1435. {
  1436. csRate.Add(0);
  1437. }
  1438. //powSum += Math.Pow(classSrate - result.average, 2);
  1439. //处理选项计数内容
  1440. }
  1441. //tasks.Add(_azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new PartitionKey($"{classResult.code}")));
  1442. }
  1443. //await tasks.TaskPage(10);
  1444. /*foreach (string id in result.lostStus) {
  1445. if (!examClassResults[0].studentIds.Contains(id)) {
  1446. int index = result.lostStus.IndexOf(id);
  1447. result.lostStus.RemoveAt(index);
  1448. }
  1449. }*/
  1450. //处理人员变更时被移除的人员
  1451. result.lostStus = lostStu;
  1452. List<string> stuIds = examClassResults.SelectMany(x => x.studentIds).ToList();
  1453. if (result.lostStus.Count > 0)
  1454. {
  1455. for (int i = 0; i < result.lostStus.Count; i++)
  1456. {
  1457. if (!stuIds.Contains(result.lostStus[i]))
  1458. {
  1459. result.lostStus.RemoveAt(i);
  1460. }
  1461. }
  1462. }
  1463. result.record = getMore(info, no, opt);
  1464. result.average = result.studentIds.Count - result.lostStus.Count > 0 ? Math.Round(score * 1.0 / (result.studentIds.Count - result.lostStus.Count), 2) : 0;
  1465. double powSum = 0;
  1466. //int sco = 0;
  1467. result.studentIds.ForEach(x =>
  1468. {
  1469. double sc = result.studentScores[result.studentIds.IndexOf(x)].Sum();
  1470. if (!result.lostStus.Contains(x))
  1471. {
  1472. powSum += Math.Pow(sc - result.average, 2);
  1473. }
  1474. });
  1475. result.standard = Math.Round((result.studentIds.Count - result.lostStus.Count) > 0 ? Math.Pow(powSum / (result.studentIds.Count - result.lostStus.Count), 0.5) : 0, 2);
  1476. result.csRate = csRate;
  1477. result.sRate = allScore > 0 ? Math.Round(result.average / allScore * 100, 2) : 0;
  1478. result.classes = classRanges;
  1479. result.code = "ExamResult-" + info.id;
  1480. result.school = info.school;
  1481. result.id = subject.id;
  1482. result.examId = info.id;
  1483. result.subjectId = subject.id;
  1484. result.year = info.year;
  1485. result.paper = info.papers[no];
  1486. //result.point = info.papers[j].point;
  1487. result.scope = info.scope;
  1488. result.name = info.name;
  1489. result.time = info.startTime;
  1490. await examRecordCount(info, subject, _dingDing, no, result, examClassResults, _azureCosmos);
  1491. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").UpsertItemAsync(result, new Azure.Cosmos.PartitionKey($"ExamResult-{info.id}"));
  1492. List<ErrorItems> errorItems = new();
  1493. 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}'"))})";
  1494. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Student").GetItemQueryIterator<ErrorItems>(queryText: sqlqueryText, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("ErrorItems") }))
  1495. {
  1496. errorItems.Add(item);
  1497. }
  1498. try {
  1499. if (errorItems.Count == 0)
  1500. {
  1501. // 新增逻辑 收集错题内容
  1502. BlobDownloadResult index_json;
  1503. if (info.scope.Equals("school"))
  1504. {
  1505. index_json = await _azureStorage.GetBlobContainerClient($"{info.school}").GetBlobClient($"{info.papers[no].blob}/index.json").DownloadContentAsync();
  1506. }
  1507. else
  1508. {
  1509. index_json = await _azureStorage.GetBlobContainerClient($"{info.creatorId}").GetBlobClient($"{info.papers[no].blob}/index.json").DownloadContentAsync();
  1510. }
  1511. //BlobDownloadResult index_json = await _azureStorage.GetBlobContainerClient($"{info.school}").GetBlobClient($"{info.papers[no].blob}/index.json").DownloadContentAsync();
  1512. JObject jo = JObject.Parse(index_json.Content.ToString());
  1513. JArray array = jo.Value<JArray>("slides");
  1514. List<string> urls = new();
  1515. foreach (var ne in array)
  1516. {
  1517. if (!ne["type"].ToString().Equals("compose"))
  1518. {
  1519. urls.Add(ne["url"].ToString());
  1520. }
  1521. }
  1522. string code = string.Empty;
  1523. string pk = string.Empty;
  1524. string table = "School";
  1525. if (info.scope.Equals("school"))
  1526. {
  1527. code = $"ErrorItems-{info.school}";
  1528. pk = $"Item-{info.school}";
  1529. }
  1530. else
  1531. {
  1532. code = "ErrorItems";
  1533. pk = $"Item-{info.creatorId}";
  1534. table = "Teacher";
  1535. }
  1536. // 获取整体的题目ID集合
  1537. List<string> ids = new();
  1538. List<(string id, string pid, int level, string type, List<string> knows)> itemInfos = new();
  1539. foreach (string url in urls)
  1540. {
  1541. string id = url.Replace(".json", "");
  1542. BlobDownloadResult index_item_json;
  1543. if (info.scope.Equals("school"))
  1544. {
  1545. index_item_json = await _azureStorage.GetBlobContainerClient($"{info.school}").GetBlobClient($"{info.papers[no].blob}/{url}").DownloadContentAsync();
  1546. }
  1547. else
  1548. {
  1549. index_item_json = await _azureStorage.GetBlobContainerClient($"{info.creatorId}").GetBlobClient($"{info.papers[no].blob}/{url}").DownloadContentAsync();
  1550. }
  1551. JObject keys = JObject.Parse(index_item_json.Content.ToString());
  1552. string type = keys["exercise"].Value<string>("type");
  1553. int level = keys["exercise"].Value<int>("level");
  1554. var knowledge = keys["exercise"].Value<JArray>("knowledge")?.ToObject<List<string>>();
  1555. string pid = keys.Value<string>("pid");
  1556. itemInfos.Add((id, pid, level, type, knowledge));
  1557. }
  1558. /*await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, table).GetItemQueryStreamIterator(
  1559. 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}") }))
  1560. {
  1561. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  1562. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  1563. {
  1564. var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
  1565. while (accounts.MoveNext())
  1566. {
  1567. JsonElement account = accounts.Current;
  1568. string pid = "";
  1569. if (account.TryGetProperty("pid",out JsonElement element)) {
  1570. pid = element.GetString();
  1571. }
  1572. itemInfos.Add((account.GetProperty("id").GetString(), pid, account.GetProperty("level").GetInt32(), account.GetProperty("type").GetString()));
  1573. }
  1574. }
  1575. }*/
  1576. /* double[] point = StringHelper.ListTodouble(result.paper.point);
  1577. double[,] res = StringHelper.ListToDouble(result.studentScores);
  1578. var cdm = new ClouDASMatrix(res, point);*/
  1579. //需要努力的题目
  1580. //var ss = cdm.StriveTopic;
  1581. int n = 0;
  1582. List<Task<ItemResponse<ErrorItems>>> task_error = new();
  1583. List<ErrorItems> errors = new();
  1584. foreach (var sIds in result.studentIds)
  1585. {
  1586. ErrorItems error = new()
  1587. {
  1588. ttl = -1,
  1589. code = code,
  1590. id = Guid.NewGuid().ToString(),
  1591. stuId = sIds,
  1592. school = info.school,
  1593. activityId = info.id,
  1594. subjectId = result.subjectId,
  1595. time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
  1596. };
  1597. int index_stu = result.studentIds.IndexOf(sIds);
  1598. //顺序学生错题的索引
  1599. var itemScore = result.studentScores[index_stu];
  1600. List<int> index = new();
  1601. int index_item = 0;
  1602. foreach (var sc in itemScore) {
  1603. if (sc == 0) {
  1604. index.Add(index_item+1);
  1605. }
  1606. index_item++;
  1607. }
  1608. //int[] item_index = ss[n];
  1609. foreach (var item in index)
  1610. {
  1611. Items items = new()
  1612. {
  1613. id = urls[item - 1].Replace(".json", ""),
  1614. blob = info.papers[no].blob
  1615. };
  1616. items.level = itemInfos.Where(c => c.id.Equals(items.id)).FirstOrDefault().level;
  1617. items.type = itemInfos.Where(c => c.id.Equals(items.id)).FirstOrDefault().type;
  1618. items.pId = itemInfos.Where(c => c.id.Equals(items.id)).FirstOrDefault().pid;
  1619. items.knowledge = itemInfos.Where(c => c.id.Equals(items.id)).FirstOrDefault().knows;
  1620. error.its.Add(items);
  1621. }
  1622. errors.Add(error);
  1623. n++;
  1624. task_error.Add(_azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student").CreateItemAsync(error, new PartitionKey($"{error.code}")));
  1625. }
  1626. //string connect = _configuration.GetValue<string>("HaBookAuth:Crtmabank") + "https://malearnfunction.chinacloudsites.cn/api/crtmabank";
  1627. string location = $"{Environment.GetEnvironmentVariable("Option:Location")}";
  1628. string urlAction = string.Empty;
  1629. string accessKey = string.Empty;
  1630. if (location.Contains("China"))
  1631. {
  1632. if(location.Equals("China")) //大陸正式站
  1633. {
  1634. urlAction = "https://malearn.teammodel.cn";
  1635. accessKey = "QUzQqbqbnLsTDTeaJy4Br6wUuqPoAlKpzRK2S6PGImRHAzFuySGAeA==";
  1636. }
  1637. else if(location.Equals("China-Dep") || location.Equals("China-Test")) //大陸測試站
  1638. {
  1639. urlAction = "https://malearn-rc.teammodel.cn";
  1640. accessKey = "hESc0g7Q60FTEss4ZnVXPB61S1a8WlAXIq5ULl3T3oTxAzFunpLDwA==";
  1641. }
  1642. }
  1643. else if (location.Contains("Global"))
  1644. {
  1645. if(location.Equals("Global")) //國際正式站
  1646. {
  1647. urlAction = "https://malearn.teammodel.net";
  1648. accessKey = "I-2lTcdggJkZWSBwOXQIm4oHx-huwX3d0wLe-9pgojThAzFuq_KNFg==";
  1649. }
  1650. else if(location.Equals("Global-Test")) //國際測試站
  1651. {
  1652. urlAction = "https://malearn-rc.teammodel.net";
  1653. accessKey = "_l4Cb_tHIRBw_iv3ZuwVqjkMwjg4_HtDaxhAmZ8OwJraAzFu_DAY8A==";
  1654. }
  1655. }
  1656. string connect = $"{urlAction}/api/crtmabank";
  1657. var htc = _httpClient.CreateClient();
  1658. if (htc.DefaultRequestHeaders.Contains("x-functions-key"))
  1659. {
  1660. htc.DefaultRequestHeaders.Remove("x-functions-key");
  1661. }
  1662. htc.DefaultRequestHeaders.Add("x-functions-key", accessKey);
  1663. string paramJson = JsonConvert.SerializeObject(errors);
  1664. var content = new StringContent(paramJson, Encoding.UTF8, "application/json");
  1665. await htc.PostAsync(connect, content);
  1666. await task_error.TaskPage(10);
  1667. }
  1668. } catch (Exception e) {
  1669. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测错题异常{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  1670. }
  1671. }
  1672. public class Settlement
  1673. {
  1674. public double rate { get; set; }
  1675. public double score { get; set; }
  1676. public List<string> stus { get; set; } = new List<string>();
  1677. public int total { get; set; }
  1678. public double qrate { get; set; }
  1679. }
  1680. }
  1681. }