TriggerExam.cs 96 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739
  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. /* bool isError = examClassResults.SelectMany(c => c.status).ToList().Exists(z => z == 1);
  1500. if () {
  1501. }*/
  1502. if (errorItems.Count == 0)
  1503. {
  1504. // 新增逻辑 收集错题内容
  1505. BlobDownloadResult index_json;
  1506. if (info.scope.Equals("school"))
  1507. {
  1508. index_json = await _azureStorage.GetBlobContainerClient($"{info.school}").GetBlobClient($"{info.papers[no].blob}/index.json").DownloadContentAsync();
  1509. }
  1510. else
  1511. {
  1512. index_json = await _azureStorage.GetBlobContainerClient($"{info.creatorId}").GetBlobClient($"{info.papers[no].blob}/index.json").DownloadContentAsync();
  1513. }
  1514. //BlobDownloadResult index_json = await _azureStorage.GetBlobContainerClient($"{info.school}").GetBlobClient($"{info.papers[no].blob}/index.json").DownloadContentAsync();
  1515. JObject jo = JObject.Parse(index_json.Content.ToString());
  1516. JArray array = jo.Value<JArray>("slides");
  1517. List<string> urls = new();
  1518. foreach (var ne in array)
  1519. {
  1520. if (!ne["type"].ToString().Equals("compose"))
  1521. {
  1522. urls.Add(ne["url"].ToString());
  1523. }
  1524. }
  1525. string code = string.Empty;
  1526. string pk = string.Empty;
  1527. string table = "School";
  1528. if (info.scope.Equals("school"))
  1529. {
  1530. code = $"ErrorItems-{info.school}";
  1531. pk = $"Item-{info.school}";
  1532. }
  1533. else
  1534. {
  1535. code = "ErrorItems";
  1536. pk = $"Item-{info.creatorId}";
  1537. table = "Teacher";
  1538. }
  1539. // 获取整体的题目ID集合
  1540. List<string> ids = new();
  1541. List<(string id, string pid, int level, string type, List<string> knows)> itemInfos = new();
  1542. foreach (string url in urls)
  1543. {
  1544. string id = url.Replace(".json", "");
  1545. BlobDownloadResult index_item_json;
  1546. if (info.scope.Equals("school"))
  1547. {
  1548. index_item_json = await _azureStorage.GetBlobContainerClient($"{info.school}").GetBlobClient($"{info.papers[no].blob}/{url}").DownloadContentAsync();
  1549. }
  1550. else
  1551. {
  1552. index_item_json = await _azureStorage.GetBlobContainerClient($"{info.creatorId}").GetBlobClient($"{info.papers[no].blob}/{url}").DownloadContentAsync();
  1553. }
  1554. JObject keys = JObject.Parse(index_item_json.Content.ToString());
  1555. string type = keys["exercise"].Value<string>("type");
  1556. int level = keys["exercise"].Value<int>("level");
  1557. var knowledge = keys["exercise"].Value<JArray>("knowledge")?.ToObject<List<string>>();
  1558. string pid = keys.Value<string>("pid");
  1559. itemInfos.Add((id, pid, level, type, knowledge));
  1560. }
  1561. /*await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, table).GetItemQueryStreamIterator(
  1562. 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}") }))
  1563. {
  1564. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  1565. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  1566. {
  1567. var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
  1568. while (accounts.MoveNext())
  1569. {
  1570. JsonElement account = accounts.Current;
  1571. string pid = "";
  1572. if (account.TryGetProperty("pid",out JsonElement element)) {
  1573. pid = element.GetString();
  1574. }
  1575. itemInfos.Add((account.GetProperty("id").GetString(), pid, account.GetProperty("level").GetInt32(), account.GetProperty("type").GetString()));
  1576. }
  1577. }
  1578. }*/
  1579. /* double[] point = StringHelper.ListTodouble(result.paper.point);
  1580. double[,] res = StringHelper.ListToDouble(result.studentScores);
  1581. var cdm = new ClouDASMatrix(res, point);*/
  1582. //需要努力的题目
  1583. //var ss = cdm.StriveTopic;
  1584. int n = 0;
  1585. List<Task<ItemResponse<ErrorItems>>> task_error = new();
  1586. List<ErrorItems> errors = new();
  1587. foreach (var sIds in result.studentIds)
  1588. {
  1589. ErrorItems error = new()
  1590. {
  1591. ttl = -1,
  1592. code = code,
  1593. id = Guid.NewGuid().ToString(),
  1594. stuId = sIds,
  1595. school = info.school,
  1596. activityId = info.id,
  1597. subjectId = result.subjectId,
  1598. time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
  1599. };
  1600. int index_stu = result.studentIds.IndexOf(sIds);
  1601. //顺序学生错题的索引
  1602. var itemScore = result.studentScores[index_stu];
  1603. List<int> index = new();
  1604. int index_item = 0;
  1605. foreach (var sc in itemScore) {
  1606. if (sc == 0) {
  1607. index.Add(index_item+1);
  1608. }
  1609. index_item++;
  1610. }
  1611. if (index.Count == 0) {
  1612. continue;
  1613. }
  1614. //int[] item_index = ss[n];
  1615. foreach (var item in index)
  1616. {
  1617. Items items = new()
  1618. {
  1619. id = urls[item - 1].Replace(".json", ""),
  1620. blob = info.papers[no].blob
  1621. };
  1622. items.level = itemInfos.Where(c => c.id.Equals(items.id)).FirstOrDefault().level;
  1623. items.type = itemInfos.Where(c => c.id.Equals(items.id)).FirstOrDefault().type;
  1624. items.pId = itemInfos.Where(c => c.id.Equals(items.id)).FirstOrDefault().pid;
  1625. items.knowledge = itemInfos.Where(c => c.id.Equals(items.id)).FirstOrDefault().knows;
  1626. error.its.Add(items);
  1627. }
  1628. errors.Add(error);
  1629. n++;
  1630. task_error.Add(_azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student").CreateItemAsync(error, new PartitionKey($"{error.code}")));
  1631. }
  1632. //string connect = _configuration.GetValue<string>("HaBookAuth:Crtmabank") + "https://malearnfunction.chinacloudsites.cn/api/crtmabank";
  1633. string location = $"{Environment.GetEnvironmentVariable("Option:Location")}";
  1634. string urlAction = string.Empty;
  1635. string accessKey = string.Empty;
  1636. if (location.Contains("China"))
  1637. {
  1638. if(location.Equals("China")) //大陸正式站
  1639. {
  1640. urlAction = "https://malearn.teammodel.cn";
  1641. accessKey = "QUzQqbqbnLsTDTeaJy4Br6wUuqPoAlKpzRK2S6PGImRHAzFuySGAeA==";
  1642. }
  1643. else if(location.Equals("China-Dep") || location.Equals("China-Test")) //大陸測試站
  1644. {
  1645. urlAction = "https://malearn-rc.teammodel.cn";
  1646. accessKey = "hESc0g7Q60FTEss4ZnVXPB61S1a8WlAXIq5ULl3T3oTxAzFunpLDwA==";
  1647. }
  1648. }
  1649. else if (location.Contains("Global"))
  1650. {
  1651. if(location.Equals("Global")) //國際正式站
  1652. {
  1653. urlAction = "https://malearn.teammodel.net";
  1654. accessKey = "I-2lTcdggJkZWSBwOXQIm4oHx-huwX3d0wLe-9pgojThAzFuq_KNFg==";
  1655. }
  1656. else if(location.Equals("Global-Test")) //國際測試站
  1657. {
  1658. urlAction = "https://malearn-rc.teammodel.net";
  1659. accessKey = "_l4Cb_tHIRBw_iv3ZuwVqjkMwjg4_HtDaxhAmZ8OwJraAzFu_DAY8A==";
  1660. }
  1661. }
  1662. string connect = $"{urlAction}/api/crtmabank";
  1663. var htc = _httpClient.CreateClient();
  1664. if (htc.DefaultRequestHeaders.Contains("x-functions-key"))
  1665. {
  1666. htc.DefaultRequestHeaders.Remove("x-functions-key");
  1667. }
  1668. htc.DefaultRequestHeaders.Add("x-functions-key", accessKey);
  1669. string paramJson = JsonConvert.SerializeObject(errors);
  1670. var content = new StringContent(paramJson, Encoding.UTF8, "application/json");
  1671. await htc.PostAsync(connect, content);
  1672. await task_error.TaskPage(10);
  1673. }
  1674. } catch (Exception e) {
  1675. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测错题异常{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  1676. }
  1677. }
  1678. public class Settlement
  1679. {
  1680. public double rate { get; set; }
  1681. public double score { get; set; }
  1682. public List<string> stus { get; set; } = new List<string>();
  1683. public int total { get; set; }
  1684. public double qrate { get; set; }
  1685. }
  1686. }
  1687. }