TriggerExam.cs 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704
  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_exam"
  438. };
  439. //作答合格率
  440. var sta = examClassResults.SelectMany(x => x.status).ToList();
  441. var ansCount = sta.Where(x => x == 0).ToList();
  442. var persent = ansCount.Count * 1.0 / sta.Count * 100;
  443. var period = sc.period.Where(x => x.id.Equals(info.period.id)).FirstOrDefault();
  444. //获取学期信息
  445. if (null != period && persent >= 60) {
  446. var (currSemester, studyYear, date, nextSemester) = SchoolService.GetSemester(period, info.startTime);
  447. //获取学生信息
  448. (List<RMember> rmembers, List<RGroupList> groups) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, info.classes, info.school);
  449. foreach (var member in rmembers)
  450. {
  451. if (info.lostStu.Contains(member.id))
  452. {
  453. continue;
  454. }
  455. PortraitStudent student = new()
  456. {
  457. studentId = member.id,
  458. name = member.name,
  459. classId = member.classId
  460. };
  461. SemesterData semesterData = new()
  462. {
  463. examName = info.name,
  464. examId = info.id,
  465. examDate = info.startTime,
  466. examType = info.examType?.name,
  467. year = info.year,
  468. semesterId = currSemester.id,
  469. totalScore = info.papers.SelectMany(x => x.point).Sum(),
  470. sumScore = examClassResults.SelectMany(x => x.sum).Sum(),
  471. excellenceRate = 0,
  472. passRate = 0,
  473. };
  474. int index = 0;
  475. foreach (var sj in info.subjects)
  476. {
  477. ItemScore item = new()
  478. {
  479. name = sj.name,
  480. score = examClassResults.Where(x => x.subjectId.Equals(sj.id)).FirstOrDefault().sum.Sum(),
  481. time = info.startTime,
  482. totalScore = info.papers[index].point.Sum(),
  483. type = sj.id
  484. };
  485. index++;
  486. semesterData.itemScore.Add(item);
  487. }
  488. student.semesterData.Add(semesterData);
  489. portrait.students.Add(student);
  490. }
  491. string location = $"{Environment.GetEnvironmentVariable("Option:Location")}";
  492. var (status, json) = await _httpTrigger.RequestHttpTrigger(portrait.ToJson(), location, "upsert-student-portrait");
  493. }
  494. //PortraitStudent student = new();
  495. //处理试卷活动结束统计账户信息
  496. List<FMember> idList = await GroupListService.GetFinishMemberInfo(_coreAPIHttpService, client, _dingDing, info.school, info.classes, info.stuLists, null);
  497. info.staffIds = idList;
  498. await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync<ExamInfo>(info, info.id, new Azure.Cosmos.PartitionKey(info.code));
  499. }
  500. }
  501. catch (Exception e)
  502. {
  503. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测finish状态异常{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  504. }
  505. break;
  506. }
  507. }
  508. }
  509. catch (CosmosException e)
  510. {
  511. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-CosmosDB异常{e.Message}\n{e.StackTrace}\n{e.Status}", GroupNames.醍摩豆服務運維群組);
  512. }
  513. catch (Exception e)
  514. {
  515. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-评测结算异常{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  516. }
  517. }
  518. public static async Task resultStatus(CosmosClient client, List<ExamClassResult> examClassResults)
  519. {
  520. List<Task<ItemResponse<ExamClassResult>>> tasks = new();
  521. //结算单科单班的标准差和平均分
  522. foreach (ExamClassResult classResult in examClassResults)
  523. {
  524. //标记单科单班总得分
  525. double subScore = 0;
  526. //标准差
  527. double sPowSum = 0;
  528. List<double> newSumScore = new List<double>();
  529. List<double> effectiveScore = new List<double>();
  530. int lostStu = classResult.status.Where(c => c == 1).ToList().Count;
  531. var scount = classResult.studentIds.Count - lostStu;
  532. int index = 0;
  533. if (classResult.status.Count > 0)
  534. {
  535. foreach (var sta in classResult.status)
  536. {
  537. if (sta == 1)
  538. {
  539. for (int i = 0; i < classResult.studentScores[index].Count; i++)
  540. {
  541. if (classResult.studentScores[index][i] == -1)
  542. {
  543. classResult.studentScores[index][i] = 0;
  544. }
  545. }
  546. }
  547. else if (sta == 0)
  548. {
  549. //var ans = classResult.studentAnswers[index];
  550. //该学生缺考,历史数据的判定
  551. //if (ans.Count == 0)
  552. //{
  553. for (int i = 0; i < classResult.studentScores[index].Count; i++)
  554. {
  555. if (classResult.studentScores[index][i] == -1)
  556. {
  557. classResult.studentScores[index][i] = 0;
  558. }
  559. }
  560. /*if (ans.Count == 0)
  561. {
  562. classResult.status[index] = 1;
  563. } */
  564. //}
  565. }
  566. index++;
  567. }
  568. }
  569. else
  570. {
  571. List<int> sta = new();
  572. foreach (var id in classResult.studentIds)
  573. {
  574. sta.Add(0);
  575. }
  576. classResult.status = sta;
  577. foreach (var ans in classResult.studentAnswers)
  578. {
  579. //该学生缺考,历史数据的判定
  580. if (ans.Count == 0)
  581. {
  582. for (int i = 0; i < classResult.studentScores[index].Count; i++)
  583. {
  584. if (classResult.studentScores[index][i] == -1)
  585. {
  586. classResult.studentScores[index][i] = 0;
  587. }
  588. }
  589. classResult.status[index] = 1;
  590. }
  591. index++;
  592. }
  593. }
  594. int sIndex = 0;
  595. foreach (List<double> sc in classResult.studentScores)
  596. {
  597. List<double> newSc = new List<double>();
  598. foreach (double ssc in sc)
  599. {
  600. if (ssc == -1)
  601. {
  602. newSc.Add(0);
  603. }
  604. else
  605. {
  606. newSc.Add(ssc);
  607. }
  608. }
  609. double nc = Math.Round(newSc.Sum(), 2);
  610. if (classResult.status[sIndex] == 0)
  611. {
  612. effectiveScore.Add(nc);
  613. };
  614. newSumScore.Add(nc);
  615. subScore += nc;
  616. classResult.sum[sIndex] = nc;
  617. sIndex++;
  618. }
  619. double rateScore = scount > 0 ? Math.Round(subScore * 1.0 / scount, 2) : 0;
  620. //有效分数
  621. foreach (double scs in effectiveScore)
  622. {
  623. sPowSum += Math.Pow(scs - rateScore, 2);
  624. }
  625. classResult.standard = Math.Round(scount > 0 ? Math.Pow(sPowSum / scount, 0.5) : 0, 2);
  626. classResult.average = scount > 0 ? Math.Round(subScore / scount, 2) : 0;
  627. classResult.progress = true;
  628. tasks.Add(client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new PartitionKey($"{classResult.code}")));
  629. }
  630. await Task.WhenAll(tasks);
  631. }
  632. public static async Task<Settlement> getMore(CosmosClient client, ExamInfo info)
  633. {
  634. //计算单次考试简易统计信息
  635. Settlement settlement = new();
  636. List<ExamResult> examResults = new();
  637. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<ExamResult>(
  638. queryText: $"select value(c) from c where c.examId = '{info.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"ExamResult-{info.id}") }))
  639. {
  640. examResults.Add(item);
  641. }
  642. if (examResults.Count > 0)
  643. {
  644. //记录某次考试所有学生得分总分
  645. double score = 0;
  646. double allScore = 0;
  647. int stuCount = 0;
  648. //标准差
  649. double powSum = 0;
  650. List<string> losStu = new List<string>();
  651. //当前完成考试得人数
  652. int total = examResults[0].studentIds.Distinct().Count();
  653. //先与第一个值取并集
  654. losStu = losStu.Union(examResults[0].lostStus).ToList();
  655. foreach (ExamResult examResult in examResults)
  656. {
  657. //取交集
  658. losStu = losStu.Intersect(examResult.lostStus).ToList();
  659. }
  660. //处理缺考的学生
  661. List<string> stus = examResults[0].studentIds.Except(losStu).ToList();
  662. foreach (ExamResult examResult in examResults)
  663. {
  664. foreach (var id in stus)
  665. {
  666. int index = examResult.studentIds.IndexOf(id);
  667. score += examResult.studentScores[index].Sum();
  668. }
  669. }
  670. stuCount = total - losStu.Count;
  671. double NewsRateScore = stuCount > 0 ? Math.Round(score * 1.0 / stuCount, 2) : 0;
  672. foreach (PaperSimple simple in info.papers)
  673. {
  674. allScore += simple.point.Sum();
  675. }
  676. //计算全科标准差
  677. foreach (string id in stus)
  678. {
  679. double sc = 0;
  680. foreach (ExamResult result in examResults)
  681. {
  682. if (result.studentScores.Count > 0)
  683. {
  684. sc += result.studentScores[result.studentIds.IndexOf(id)].Sum();
  685. }
  686. }
  687. powSum += Math.Pow(sc - NewsRateScore, 2);
  688. }
  689. info.standard = Math.Round(total - losStu.Count > 0 ? Math.Pow(powSum / (total - losStu.Count), 0.5) : 0, 2);
  690. double NewsRate = allScore > 0 ? Math.Round(NewsRateScore / allScore * 100, 2) : 0;
  691. double qrate = Math.Round(total > 0 ? losStu.Count * 1.0 / total * 100 : 0, 2);
  692. settlement.rate = NewsRate;
  693. settlement.score = NewsRateScore;
  694. settlement.stus = losStu;
  695. settlement.total = total;
  696. settlement.qrate = qrate;
  697. }
  698. return settlement;
  699. }
  700. //处理全部学生选题计数
  701. public static async Task examRecordCount(ExamInfo info, ExamSubject subject, DingDing _dingDing, int no, ExamResult er, List<ExamClassResult> classResults, AzureCosmosFactory _azureCosmos)
  702. {
  703. try
  704. {
  705. List<double> scores = new List<double>();
  706. foreach (List<double> sc in er.studentScores)
  707. {
  708. scores.Add(sc.Sum());
  709. }
  710. //确定高分组 最低分数
  711. //var srowallorder = scores.EnumerateIndexed().OrderByDescending(g => g.Item2); //各生總分排序
  712. //var srowallorder = scores.OrderByDescending(g => g);
  713. double[] point = StringHelper.ListTodouble(er.paper.point);
  714. double[,] result = StringHelper.ListToDouble(er.studentScores);
  715. var cdm = new ClouDASMatrix(result, point);
  716. scores.Sort((s1, s2) => { return s2.CompareTo(s1); });
  717. int rhwCount = cdm.SH.Count();
  718. double rhw = cdm.SH.LastOrDefault().Item2;
  719. int rhlCount = cdm.SL.Count();
  720. double rhl = cdm.SL.FirstOrDefault().Item2;
  721. List<string> phs = new();
  722. List<string> pls = new();
  723. //分别获取高分组低分组人员
  724. foreach (var ph in cdm.SH)
  725. {
  726. phs.Add(er.studentIds[ph.Item1]);
  727. }
  728. foreach (var pl in cdm.SL)
  729. {
  730. pls.Add(er.studentIds[pl.Item1]);
  731. }
  732. /* if (scores.Count > 3)
  733. {
  734. rhwCount = Convert.ToInt32(Math.Floor(scores.Count * 0.27));
  735. rhw = rhwCount > 0 ? scores[rhwCount - 1] : 0;
  736. rhlCount = Convert.ToInt32(Math.Ceiling(scores.Count * 0.73));
  737. rhl = rhlCount > 0 ? scores[rhlCount] : 0;
  738. }
  739. else
  740. {
  741. rhwCount = Convert.ToInt32(Math.Floor(scores.Count * 0.27));
  742. rhw = rhwCount > 0 ? scores[rhwCount] : 0;
  743. rhlCount = Convert.ToInt32(Math.Ceiling(scores.Count * 0.73));
  744. rhl = rhlCount > 0 ? scores[rhlCount - 1] : 0;
  745. }*/
  746. /*int rhwCount = Convert.ToInt32(Math.Floor(scores.Count * 0.27));
  747. double rhw = rhwCount > 0 ? scores[rhwCount-1] : 0;
  748. //var rhww = srowallorder.Take(Convert.ToInt32(Math.Floor(scores.Count * 0.27)));
  749. //确定低分组 最高分数
  750. //scores.Sort((s1, s2) => { return s1.CompareTo(s2); });
  751. int rhlCount = Convert.ToInt32(Math.Ceiling(scores.Count * 0.73));
  752. double rhl = rhlCount > 0 ? scores[rhlCount-1] : 0;*/
  753. //var rhll = srowallorder.Skip(Convert.ToInt32(Math.Ceiling(scores.Count * 0.73)));
  754. //存放高分组学生ID
  755. List<string> phId = new();
  756. List<string> plId = new();
  757. List<List<List<string>>> opth = new();
  758. List<List<List<string>>> optl = new();
  759. List<double> akp = await knowledgeCount(info, subject, _dingDing, no, classResults, rhwCount, rhw, rhlCount, rhl, _azureCosmos);
  760. List<double> afp = await fieldCount(info, subject, _dingDing, no, classResults, rhwCount, rhw, rhlCount, rhl, _azureCosmos);
  761. int PHCount = 0;
  762. int PLCount = 0;
  763. foreach (ExamClassResult classResult in classResults)
  764. {
  765. if (classResult.subjectId.Equals(subject.id))
  766. {
  767. foreach (string id in classResult.studentIds)
  768. {
  769. int index = classResult.studentIds.IndexOf(id);
  770. if (classResult.studentScores.Count > 0)
  771. {
  772. if (phs.Contains(id))
  773. {
  774. if (classResult.ans.Count > 0)
  775. {
  776. opth.Add(classResult.ans[index]);
  777. PHCount++;
  778. continue;
  779. }
  780. }
  781. if (pls.Contains(id))
  782. {
  783. if (classResult.ans.Count > 0)
  784. {
  785. optl.Add(classResult.ans[index]);
  786. PLCount++;
  787. continue;
  788. }
  789. }
  790. }
  791. }
  792. }
  793. }
  794. er.phc = getMore(info, no, opth);
  795. er.plc = getMore(info, no, optl);
  796. er.afp = afp;
  797. er.akp = akp;
  798. }
  799. catch (Exception ex)
  800. {
  801. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测作答记录结算异常{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  802. }
  803. }
  804. public static async Task<List<RGroupList>> Activity(CoreAPIHttpService _coreAPIHttpService, ExamInfo info, List<string> classes, CosmosClient client, DingDing _dingDing, List<string> sub, List<ExamClassResult> results)
  805. {
  806. List<(string pId, List<string> gid)> ps = new List<(string pId, List<string> gid)>();
  807. if (info.groupLists.Count > 0)
  808. {
  809. var group = info.groupLists;
  810. foreach (var gp in group)
  811. {
  812. foreach (KeyValuePair<string, List<string>> pp in gp)
  813. {
  814. ps.Add((pp.Key, pp.Value));
  815. }
  816. }
  817. }
  818. (List<RMember> tchList, List<RGroupList> classLists) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, classes, info.school, ps);
  819. var addStudentsCls = tchList.FindAll(x => x.type == 2);
  820. var addTmdidsCls = tchList.FindAll(x => x.type == 1);
  821. List<StuActivity> stuActivities = new List<StuActivity>();
  822. List<StuActivity> tmdActivities = new List<StuActivity>();
  823. if (addTmdidsCls.IsNotEmpty())
  824. {
  825. addTmdidsCls.ForEach(x =>
  826. {
  827. HashSet<string> classIds = new HashSet<string>();
  828. classLists.ForEach(z =>
  829. {
  830. z.members.ForEach(y =>
  831. {
  832. if (y.id.Equals(x.id) && y.type == 1)
  833. {
  834. classIds.Add(z.id);
  835. }
  836. });
  837. });
  838. bool iss = false;
  839. //标记学生作答状态
  840. int ts = 0;
  841. if (results.Count > 0)
  842. {
  843. foreach (ExamClassResult exam in results)
  844. {
  845. int index = exam.studentIds.IndexOf(x.id);
  846. if (index != -1)
  847. {
  848. if (exam.studentAnswers[index].Count > 0)
  849. {
  850. bool flag = exam.studentScores[index].Exists(x => x == -1);
  851. if (!flag)
  852. {
  853. ts = 1;
  854. iss = true;
  855. break;
  856. }
  857. else
  858. {
  859. ts = 0;
  860. }
  861. }
  862. else
  863. {
  864. ts = -1;
  865. }
  866. }
  867. }
  868. }
  869. else
  870. {
  871. ts = -1;
  872. }
  873. tmdActivities.Add(new StuActivity
  874. {
  875. pk = "Activity",
  876. id = info.id,
  877. code = $"Activity-{x.id}",
  878. type = "Exam",
  879. name = info.name,
  880. source = info.source,
  881. startTime = info.startTime,
  882. endTime = info.endTime,
  883. scode = info.code,
  884. scope = info.scope,
  885. school = info.school,
  886. creatorId = info.creatorId,
  887. subjects = sub,
  888. blob = null,
  889. owner = info.owner,
  890. createTime = info.createTime,
  891. taskStatus = ts,
  892. qamode = info.qamode,
  893. ext = new Dictionary<string, JsonElement>() { { "type", info.examType.ToJsonString().ToObject<JsonElement>() },
  894. { "subjects", info.subjects.ToJsonString().ToObject<JsonElement>() } },
  895. sStatus = iss ? 1 : 0,
  896. classIds = classIds.ToList()
  897. });
  898. });
  899. }
  900. if (addStudentsCls.IsNotEmpty())
  901. {
  902. addStudentsCls.ForEach(x =>
  903. {
  904. HashSet<string> classIds = new HashSet<string>();
  905. classLists.ForEach(z =>
  906. {
  907. z.members.ForEach(y =>
  908. {
  909. if (y.id.Equals(x.id) && y.code.Equals(info.school) && y.type == 2)
  910. {
  911. classIds.Add(z.id);
  912. }
  913. });
  914. });
  915. bool iss = false;
  916. //标记学生作答状态
  917. int ts = 0;
  918. if (results.Count > 0)
  919. {
  920. foreach (ExamClassResult exam in results)
  921. {
  922. int index = exam.studentIds.IndexOf(x.id);
  923. if (index != -1)
  924. {
  925. if (exam.studentAnswers[index].Count > 0)
  926. {
  927. bool flag = exam.studentScores[index].Exists(x => x == -1);
  928. if (!flag)
  929. {
  930. ts = 1;
  931. iss = true;
  932. break;
  933. }
  934. else
  935. {
  936. ts = 0;
  937. }
  938. }
  939. else
  940. {
  941. ts = -1;
  942. }
  943. }
  944. }
  945. }
  946. else
  947. {
  948. ts = -1;
  949. }
  950. stuActivities.Add(new StuActivity
  951. {
  952. pk = "Activity",
  953. id = info.id,
  954. code = $"Activity-{x.code.Replace("Base-", "")}-{x.id}",
  955. type = "Exam",
  956. name = info.name,
  957. source = info.source,
  958. startTime = info.startTime,
  959. endTime = info.endTime,
  960. scode = info.code,
  961. scope = info.scope,
  962. school = info.school,
  963. creatorId = info.creatorId,
  964. subjects = sub,
  965. blob = null,
  966. owner = info.owner,
  967. classIds = classIds.ToList(),
  968. createTime = info.createTime,
  969. qamode = info.qamode,
  970. ext = new Dictionary<string, JsonElement>() { { "type", info.examType.ToJsonString().ToObject<JsonElement>() },
  971. { "subjects", info.subjects.ToJsonString().ToObject<JsonElement>() } },
  972. taskStatus = ts,
  973. sStatus = iss ? 1 : 0,
  974. });
  975. });
  976. }
  977. await ActivityService.SaveStuActivity(client, _dingDing, stuActivities, tmdActivities, null);
  978. return classLists;
  979. }
  980. public static async Task<List<double>> knowledgeCount(ExamInfo info, ExamSubject subject, DingDing _dingDing, int no, List<ExamClassResult> classResults,
  981. double rhwCount, double rhw, double rhlCount, double rhl, AzureCosmosFactory _azureCosmos)
  982. {
  983. List<double> akp = new();
  984. try
  985. {
  986. int phcount = 0;
  987. int plcount = 0;
  988. //存放并去重知识点
  989. HashSet<string> kname = new HashSet<string>();
  990. if (info.papers[no].knowledge.Count > 0)
  991. {
  992. info.papers[no].knowledge.ForEach(kno =>
  993. {
  994. kno.ForEach(k =>
  995. {
  996. kname.Add(k);
  997. });
  998. });
  999. List<string> knowledgeName = new List<string>();
  1000. foreach (string cla in kname)
  1001. {
  1002. knowledgeName.Add(cla);
  1003. }
  1004. for (int k = 0; k < knowledgeName.Count; k++)
  1005. {
  1006. if (null == knowledgeName[k])
  1007. {
  1008. knowledgeName.Remove(knowledgeName[k]);
  1009. }
  1010. }
  1011. foreach (ExamClassResult classResult in classResults)
  1012. {
  1013. if (classResult.subjectId.Equals(subject.id))
  1014. {
  1015. //List<int> phc = new List<int>();
  1016. List<int> ph = new List<int>();
  1017. List<int> pl = new List<int>();
  1018. List<int> pc = new List<int>();
  1019. List<double> persent = new List<double>();
  1020. int lostStu = classResult.status.Where(c => c == 1).ToList().Count;
  1021. for (int i = 0; i < knowledgeName.Count; i++)
  1022. {
  1023. //初始化单个知识点得分
  1024. double score = 0;
  1025. int n = 0;
  1026. int phCount = 0;
  1027. int plCount = 0;
  1028. int pCount = 0;
  1029. double classScore = 0;
  1030. foreach (List<string> str in info.papers[no].knowledge)
  1031. {
  1032. if (str.Contains(knowledgeName[i]))
  1033. {
  1034. var itemPersent = str.Count > 0 ? 1 / Convert.ToDouble(str.Count) : 0;
  1035. classScore += info.papers[no].point.Count > 0 ? (info.papers[no].point[n] * itemPersent) : 0;
  1036. foreach (string id in classResult.studentIds)
  1037. {
  1038. int index = classResult.studentIds.IndexOf(id);
  1039. if (classResult.studentScores.Count > 0)
  1040. {
  1041. if (classResult.studentScores[index].Count > 0)
  1042. {
  1043. double realScore = classResult.studentScores[index][n] == -1 ? 0 : classResult.studentScores[index][n] * itemPersent;
  1044. score += realScore;
  1045. //score += classResult.studentScores[index][n] == -1 ? 0 : classResult.studentScores[index][n] * itemPersent;
  1046. if (classResult.studentScores[index].Sum() >= rhw && phcount < rhwCount)
  1047. {
  1048. if (classResult.studentScores[index][n] <= 0)
  1049. {
  1050. phCount++;
  1051. }
  1052. phcount++;
  1053. continue;
  1054. }
  1055. if (classResult.studentScores[index].Sum() <= rhl && plcount < (info.stuCount - rhlCount))
  1056. {
  1057. if (classResult.studentScores[index][n] <= 0)
  1058. {
  1059. plCount++;
  1060. }
  1061. plcount++;
  1062. continue;
  1063. }
  1064. if (classResult.studentScores[index][n] <= 0)
  1065. {
  1066. pCount++;
  1067. }
  1068. }
  1069. }
  1070. }
  1071. }
  1072. n++;
  1073. }
  1074. pc.Add(pCount);
  1075. ph.Add(phCount);
  1076. pl.Add(plCount);
  1077. double per = classResult.studentIds.Count - lostStu > 0 ? Math.Round(score / (classResult.studentIds.Count - lostStu), 2) : 0;
  1078. persent.Add(classScore > 0 ? Math.Round(per * 1.0 / classScore, 2) : 0);
  1079. }
  1080. classResult.phc = ph;
  1081. classResult.plc = pl;
  1082. classResult.pc = pc;
  1083. classResult.krate = persent;
  1084. }
  1085. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new Azure.Cosmos.PartitionKey($"{classResult.code}"));
  1086. }
  1087. foreach (string k in knowledgeName)
  1088. {
  1089. double score = 0;
  1090. double allScore = 0;
  1091. int count = 0;
  1092. int m = 0;
  1093. foreach (List<string> str in info.papers[no].knowledge)
  1094. {
  1095. if (str.Contains(k))
  1096. {
  1097. var itemPersent = str.Count > 0 ? 1 / Convert.ToDouble(str.Count) : 0;
  1098. allScore += info.papers[no].point.Count > 0 ? info.papers[no].point[m] * itemPersent : 0;
  1099. }
  1100. m++;
  1101. }
  1102. foreach (ExamClassResult result in classResults)
  1103. {
  1104. if (result.subjectId.Equals(subject.id))
  1105. {
  1106. int n = 0;
  1107. foreach (List<string> str in info.papers[no].knowledge)
  1108. {
  1109. if (str.Contains(k))
  1110. {
  1111. var itemPersent = str.Count > 0 ? 1 / Convert.ToDouble(str.Count) : 0;
  1112. if (result.studentScores.Count > 0)
  1113. {
  1114. foreach (List<double> sc in result.studentScores)
  1115. {
  1116. double tsc = sc[n] == -1 ? 0 : sc[n];
  1117. score += (tsc * itemPersent);
  1118. }
  1119. }
  1120. }
  1121. n++;
  1122. }
  1123. count += result.studentIds.Count;
  1124. }
  1125. }
  1126. double per = count - info.lostStu.Count > 0 ? Math.Round(score / (count - info.lostStu.Count), 2) : 0;
  1127. akp.Add(allScore > 0 ? Math.Round(per / allScore, 2) : 0);
  1128. }
  1129. }
  1130. return akp;
  1131. }
  1132. catch (Exception ex)
  1133. {
  1134. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测知识点结算异常{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  1135. return null;
  1136. }
  1137. }
  1138. public static async Task<List<double>> fieldCount(ExamInfo info, ExamSubject subject, DingDing _dingDing, int no, List<ExamClassResult> classResults,
  1139. double rhwCount, double rhw, double rhlCount, double rhl, AzureCosmosFactory _azureCosmos)
  1140. {
  1141. List<double> afp = new();
  1142. try
  1143. {
  1144. int phcount = 0;
  1145. int plcount = 0;
  1146. //存放并去重知识点
  1147. List<int> knowledgeName = new List<int>() { 1, 2, 3, 4, 5, 6 };
  1148. /* knowledgeName.Add(1);
  1149. knowledgeName.Add(2);
  1150. knowledgeName.Add(3);
  1151. knowledgeName.Add(4);
  1152. knowledgeName.Add(5);
  1153. knowledgeName.Add(6);*/
  1154. foreach (ExamClassResult classResult in classResults)
  1155. {
  1156. if (classResult.subjectId.Equals(subject.id))
  1157. {
  1158. //List<int> phc = new List<int>();
  1159. List<int> ph = new List<int>();
  1160. List<int> pl = new List<int>();
  1161. List<int> pc = new List<int>();
  1162. List<double> persent = new List<double>();
  1163. int lostStu = classResult.status.Where(c => c == 1).ToList().Count;
  1164. for (int i = 0; i < knowledgeName.Count; i++)
  1165. {
  1166. //初始化单个知识点得分
  1167. double score = 0;
  1168. int n = 0;
  1169. int phCount = 0;
  1170. int plCount = 0;
  1171. int pCount = 0;
  1172. double classScore = 0;
  1173. if (info.papers[no].field.Count > 0)
  1174. {
  1175. foreach (int str in info.papers[no].field)
  1176. {
  1177. if (str == knowledgeName[i])
  1178. {
  1179. var itemPersent = 1;
  1180. classScore += info.papers[no].point.Count > 0 ? info.papers[no].point[n] * itemPersent : 0;
  1181. foreach (string id in classResult.studentIds)
  1182. {
  1183. int index = classResult.studentIds.IndexOf(id);
  1184. if (classResult.studentScores.Count > 0)
  1185. {
  1186. if (classResult.studentScores[index].Count > 0)
  1187. {
  1188. score += classResult.studentScores[index][n] == -1 ? 0 : classResult.studentScores[index][n];
  1189. if (classResult.studentScores[index].Sum() >= rhw && phcount < rhwCount)
  1190. {
  1191. if (classResult.studentScores[index][n] <= 0)
  1192. {
  1193. phCount++;
  1194. }
  1195. phcount++;
  1196. continue;
  1197. }
  1198. if (classResult.studentScores[index].Sum() <= rhl && plcount < (info.stuCount - rhlCount))
  1199. {
  1200. if (classResult.studentScores[index][n] <= 0)
  1201. {
  1202. plCount++;
  1203. }
  1204. plcount++;
  1205. continue;
  1206. }
  1207. if (classResult.studentScores[index][n] <= 0)
  1208. {
  1209. pCount++;
  1210. }
  1211. }
  1212. }
  1213. }
  1214. }
  1215. n++;
  1216. }
  1217. pc.Add(pCount);
  1218. ph.Add(phCount);
  1219. pl.Add(plCount);
  1220. double per = classResult.studentIds.Count - lostStu > 0 ? Math.Round(score / (classResult.studentIds.Count - lostStu), 2) : 0;
  1221. persent.Add(classScore > 0 ? Math.Round(per / classScore, 2) : 0);
  1222. }
  1223. }
  1224. classResult.fphc = ph;
  1225. classResult.fplc = pl;
  1226. classResult.fpc = pc;
  1227. classResult.frate = persent;
  1228. }
  1229. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new Azure.Cosmos.PartitionKey($"{classResult.code}"));
  1230. }
  1231. for (int i = 0; i < knowledgeName.Count; i++)
  1232. {
  1233. double score = 0;
  1234. double allScore = 0;
  1235. int count = 0;
  1236. int m = 0;
  1237. foreach (int str in info.papers[no].field)
  1238. {
  1239. if (str == knowledgeName[i])
  1240. {
  1241. var itemPersent = 1;
  1242. allScore += info.papers[no].point.Count > 0 ? info.papers[no].point[m] * itemPersent : 0;
  1243. }
  1244. m++;
  1245. }
  1246. foreach (ExamClassResult result in classResults)
  1247. {
  1248. if (result.subjectId.Equals(subject.id))
  1249. {
  1250. int n = 0;
  1251. foreach (int str in info.papers[no].field)
  1252. {
  1253. var itemPersent = 1;
  1254. if (str == knowledgeName[i])
  1255. {
  1256. if (result.studentScores.Count > 0)
  1257. {
  1258. foreach (List<double> sc in result.studentScores)
  1259. {
  1260. double tsc = sc[n] == -1 ? 0 : sc[n];
  1261. score += tsc * itemPersent;
  1262. }
  1263. }
  1264. }
  1265. n++;
  1266. }
  1267. count += result.studentIds.Count;
  1268. }
  1269. }
  1270. double per = count - info.lostStu.Count > 0 ? Math.Round(score / (count - info.lostStu.Count), 2) : 0;
  1271. afp.Add(allScore > 0 ? Math.Round(per / allScore, 2) : 0);
  1272. }
  1273. return afp;
  1274. }
  1275. catch (Exception ex)
  1276. {
  1277. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测认知层次结算异常{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  1278. return null;
  1279. }
  1280. }
  1281. //处理选题计数
  1282. public static List<Dictionary<string, int>> getMore(ExamInfo info, int no, List<List<List<string>>> list)
  1283. {
  1284. List<Dictionary<string, int>> recorde = new List<Dictionary<string, int>>();
  1285. try
  1286. {
  1287. for (int i = 0; i < info.papers[no].answers.Count; i++)
  1288. {
  1289. if (info.papers[no].answers[i].Count <= 0)
  1290. {
  1291. recorde.Add(new Dictionary<string, int>());
  1292. continue;
  1293. }
  1294. Dictionary<string, int> optCount = new Dictionary<string, int>();
  1295. foreach (List<List<string>> stu in list)
  1296. {
  1297. if (stu.Count == info.papers[no].answers.Count)
  1298. {
  1299. var item = stu[i];
  1300. foreach (string opt in item)
  1301. {
  1302. if (optCount.ContainsKey(opt))
  1303. {
  1304. optCount[opt] = optCount[opt] + 1;
  1305. }
  1306. else
  1307. {
  1308. optCount[opt] = 1;
  1309. }
  1310. }
  1311. }
  1312. }
  1313. recorde.Add(optCount);
  1314. }
  1315. return recorde;
  1316. }
  1317. catch (Exception)
  1318. {
  1319. return recorde;
  1320. }
  1321. }
  1322. public static async Task createClassResultAsync(ExamInfo info, List<ExamClassResult> examClassResults, ExamSubject subject, int no, AzureCosmosFactory _azureCosmos, DingDing _dingDing, AzureStorageFactory _azureStorage, IHttpClientFactory _httpClient, IConfiguration _configuration)
  1323. {
  1324. //保证试卷信息与科目信息同步
  1325. ExamResult result = new ExamResult();
  1326. //人数总和
  1327. int Count = 0;
  1328. int m = 0;
  1329. double score = 0;
  1330. //标准差
  1331. //double powSum = 0;
  1332. double allScore = info.papers[no].point.Sum();
  1333. List<ClassRange> classRanges = new List<ClassRange>();
  1334. List<string> lostStu = new List<string>();
  1335. List<double> csRate = new List<double>();
  1336. List<List<List<string>>> opt = new List<List<List<string>>>();
  1337. //List<Task<ItemResponse<ExamClassResult>>> tasks = new();
  1338. foreach (ExamClassResult classResult in examClassResults)
  1339. {
  1340. double classSrate = 0;
  1341. if (classResult.subjectId.Equals(subject.id))
  1342. {
  1343. foreach (List<List<string>> op in classResult.ans)
  1344. {
  1345. opt.Add(op);
  1346. }
  1347. //记录缺考学生索引位置
  1348. int index_stu = 0;
  1349. foreach (var ans in classResult.studentAnswers)
  1350. {
  1351. if (ans.Count == 0)
  1352. {
  1353. if (!lostStu.Contains(classResult.studentIds[index_stu]))
  1354. {
  1355. lostStu.Add(classResult.studentIds[index_stu]);
  1356. }
  1357. }
  1358. else
  1359. {
  1360. if (classResult.status[index_stu] == 1)
  1361. {
  1362. if (!lostStu.Contains(classResult.studentIds[index_stu]))
  1363. {
  1364. lostStu.Add(classResult.studentIds[index_stu]);
  1365. }
  1366. }
  1367. }
  1368. index_stu++;
  1369. }
  1370. int index = 0;
  1371. foreach (List<double> scores in classResult.studentScores)
  1372. {
  1373. List<double> newScores = new List<double>();
  1374. //int count = 0;
  1375. foreach (double sc in scores)
  1376. {
  1377. newScores.Add(sc > -1 ? sc : 0);
  1378. }
  1379. classSrate += newScores.Sum();
  1380. score += newScores.Sum();
  1381. result.studentScores.Add(newScores);
  1382. index++;
  1383. }
  1384. //处理班级信息
  1385. ClassRange range = new ClassRange();
  1386. range.id = classResult.info.id;
  1387. range.name = classResult.info.name;
  1388. range.gradeId = classResult.gradeId;
  1389. List<int> ran = new List<int>();
  1390. int stuCount = classResult.studentIds.Count;
  1391. //todo 与实际的缺考人数比较
  1392. int lostStus = classResult.status.Where(c => c == 1).ToList().Count;
  1393. Count += stuCount;
  1394. if (m == 0)
  1395. {
  1396. ran.Add(0);
  1397. ran.Add(stuCount - 1);
  1398. }
  1399. else
  1400. {
  1401. ran.Add(Count - stuCount);
  1402. ran.Add(Count - 1);
  1403. }
  1404. m++;
  1405. range.range = ran;
  1406. classRanges.Add(range);
  1407. //处理学生ID
  1408. foreach (string id in classResult.studentIds)
  1409. {
  1410. result.studentIds.Add(id);
  1411. }
  1412. if (allScore > 0)
  1413. {
  1414. csRate.Add(classResult.studentIds.Count - lostStus > 0 ? Math.Round(classSrate * 1.0 / (classResult.studentIds.Count - lostStus), 2) : 0 / allScore);
  1415. }
  1416. else
  1417. {
  1418. csRate.Add(0);
  1419. }
  1420. //powSum += Math.Pow(classSrate - result.average, 2);
  1421. //处理选项计数内容
  1422. }
  1423. //tasks.Add(_azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new PartitionKey($"{classResult.code}")));
  1424. }
  1425. //await tasks.TaskPage(10);
  1426. /*foreach (string id in result.lostStus) {
  1427. if (!examClassResults[0].studentIds.Contains(id)) {
  1428. int index = result.lostStus.IndexOf(id);
  1429. result.lostStus.RemoveAt(index);
  1430. }
  1431. }*/
  1432. //处理人员变更时被移除的人员
  1433. result.lostStus = lostStu;
  1434. List<string> stuIds = examClassResults.SelectMany(x => x.studentIds).ToList();
  1435. if (result.lostStus.Count > 0)
  1436. {
  1437. for (int i = 0; i < result.lostStus.Count; i++)
  1438. {
  1439. if (!stuIds.Contains(result.lostStus[i]))
  1440. {
  1441. result.lostStus.RemoveAt(i);
  1442. }
  1443. }
  1444. }
  1445. result.record = getMore(info, no, opt);
  1446. result.average = result.studentIds.Count - result.lostStus.Count > 0 ? Math.Round(score * 1.0 / (result.studentIds.Count - result.lostStus.Count), 2) : 0;
  1447. double powSum = 0;
  1448. //int sco = 0;
  1449. result.studentIds.ForEach(x =>
  1450. {
  1451. double sc = result.studentScores[result.studentIds.IndexOf(x)].Sum();
  1452. if (!result.lostStus.Contains(x))
  1453. {
  1454. powSum += Math.Pow(sc - result.average, 2);
  1455. }
  1456. });
  1457. result.standard = Math.Round((result.studentIds.Count - result.lostStus.Count) > 0 ? Math.Pow(powSum / (result.studentIds.Count - result.lostStus.Count), 0.5) : 0, 2);
  1458. result.csRate = csRate;
  1459. result.sRate = allScore > 0 ? Math.Round(result.average / allScore * 100, 2) : 0;
  1460. result.classes = classRanges;
  1461. result.code = "ExamResult-" + info.id;
  1462. result.school = info.school;
  1463. result.id = subject.id;
  1464. result.examId = info.id;
  1465. result.subjectId = subject.id;
  1466. result.year = info.year;
  1467. result.paper = info.papers[no];
  1468. //result.point = info.papers[j].point;
  1469. result.scope = info.scope;
  1470. result.name = info.name;
  1471. result.time = info.startTime;
  1472. await examRecordCount(info, subject, _dingDing, no, result, examClassResults, _azureCosmos);
  1473. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").UpsertItemAsync(result, new Azure.Cosmos.PartitionKey($"ExamResult-{info.id}"));
  1474. List<ErrorItems> errorItems = new();
  1475. 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}'"))})";
  1476. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Student").GetItemQueryIterator<ErrorItems>(queryText: sqlqueryText, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("ErrorItems") }))
  1477. {
  1478. errorItems.Add(item);
  1479. }
  1480. try {
  1481. if (errorItems.Count == 0)
  1482. {
  1483. // 新增逻辑 收集错题内容
  1484. BlobDownloadResult index_json;
  1485. if (info.scope.Equals("school"))
  1486. {
  1487. index_json = await _azureStorage.GetBlobContainerClient($"{info.school}").GetBlobClient($"{info.papers[no].blob}/index.json").DownloadContentAsync();
  1488. }
  1489. else
  1490. {
  1491. index_json = await _azureStorage.GetBlobContainerClient($"{info.creatorId}").GetBlobClient($"{info.papers[no].blob}/index.json").DownloadContentAsync();
  1492. }
  1493. //BlobDownloadResult index_json = await _azureStorage.GetBlobContainerClient($"{info.school}").GetBlobClient($"{info.papers[no].blob}/index.json").DownloadContentAsync();
  1494. JObject jo = JObject.Parse(index_json.Content.ToString());
  1495. JArray array = jo.Value<JArray>("slides");
  1496. List<string> urls = new();
  1497. foreach (var ne in array)
  1498. {
  1499. if (!ne["type"].ToString().Equals("compose"))
  1500. {
  1501. urls.Add(ne["url"].ToString());
  1502. }
  1503. }
  1504. string code = string.Empty;
  1505. string pk = string.Empty;
  1506. string table = "School";
  1507. if (info.scope.Equals("school"))
  1508. {
  1509. code = $"ErrorItems-{info.school}";
  1510. pk = $"Item-{info.school}";
  1511. }
  1512. else
  1513. {
  1514. code = "ErrorItems";
  1515. pk = $"Item-{info.creatorId}";
  1516. table = "Teacher";
  1517. }
  1518. // 获取整体的题目ID集合
  1519. List<string> ids = new();
  1520. List<(string id, string pid, int level, string type, List<string> knows)> itemInfos = new();
  1521. foreach (string url in urls)
  1522. {
  1523. string id = url.Replace(".json", "");
  1524. BlobDownloadResult index_item_json;
  1525. if (info.scope.Equals("school"))
  1526. {
  1527. index_item_json = await _azureStorage.GetBlobContainerClient($"{info.school}").GetBlobClient($"{info.papers[no].blob}/{url}").DownloadContentAsync();
  1528. }
  1529. else
  1530. {
  1531. index_item_json = await _azureStorage.GetBlobContainerClient($"{info.creatorId}").GetBlobClient($"{info.papers[no].blob}/{url}").DownloadContentAsync();
  1532. }
  1533. JObject keys = JObject.Parse(index_item_json.Content.ToString());
  1534. string type = keys["exercise"].Value<string>("type");
  1535. int level = keys["exercise"].Value<int>("level");
  1536. var knowledge = keys["exercise"].Value<JArray>("knowledge")?.ToObject<List<string>>();
  1537. string pid = keys.Value<string>("pid");
  1538. itemInfos.Add((id, pid, level, type, knowledge));
  1539. }
  1540. /*await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, table).GetItemQueryStreamIterator(
  1541. 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}") }))
  1542. {
  1543. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  1544. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  1545. {
  1546. var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
  1547. while (accounts.MoveNext())
  1548. {
  1549. JsonElement account = accounts.Current;
  1550. string pid = "";
  1551. if (account.TryGetProperty("pid",out JsonElement element)) {
  1552. pid = element.GetString();
  1553. }
  1554. itemInfos.Add((account.GetProperty("id").GetString(), pid, account.GetProperty("level").GetInt32(), account.GetProperty("type").GetString()));
  1555. }
  1556. }
  1557. }*/
  1558. double[] point = StringHelper.ListTodouble(result.paper.point);
  1559. double[,] res = StringHelper.ListToDouble(result.studentScores);
  1560. var cdm = new ClouDASMatrix(res, point);
  1561. //需要努力的题目
  1562. var ss = cdm.StriveTopic;
  1563. int n = 0;
  1564. List<Task<ItemResponse<ErrorItems>>> task_error = new();
  1565. List<ErrorItems> errors = new();
  1566. foreach (var sIds in result.studentIds)
  1567. {
  1568. ErrorItems error = new()
  1569. {
  1570. ttl = -1,
  1571. code = code,
  1572. id = Guid.NewGuid().ToString(),
  1573. stuId = sIds,
  1574. school = info.school,
  1575. activityId = info.id,
  1576. subjectId = result.subjectId,
  1577. time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
  1578. };
  1579. //顺序学生错题的索引
  1580. int[] item_index = ss[n];
  1581. foreach (var item in item_index)
  1582. {
  1583. Items items = new()
  1584. {
  1585. id = urls[item - 1].Replace(".json", ""),
  1586. blob = info.papers[no].blob
  1587. };
  1588. items.level = itemInfos.Where(c => c.id.Equals(items.id)).FirstOrDefault().level;
  1589. items.type = itemInfos.Where(c => c.id.Equals(items.id)).FirstOrDefault().type;
  1590. items.pId = itemInfos.Where(c => c.id.Equals(items.id)).FirstOrDefault().pid;
  1591. items.knowledge = itemInfos.Where(c => c.id.Equals(items.id)).FirstOrDefault().knows;
  1592. error.its.Add(items);
  1593. }
  1594. errors.Add(error);
  1595. n++;
  1596. task_error.Add(_azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student").CreateItemAsync(error, new PartitionKey($"{error.code}")));
  1597. }
  1598. //string connect = _configuration.GetValue<string>("HaBookAuth:Crtmabank") + "https://malearnfunction.chinacloudsites.cn/api/crtmabank";
  1599. string location = $"{Environment.GetEnvironmentVariable("Option:Location")}";
  1600. string urlAction = string.Empty;
  1601. string accessKey = string.Empty;
  1602. if (location.Contains("China"))
  1603. {
  1604. if(location.Equals("China")) //大陸正式站
  1605. {
  1606. urlAction = "https://malearn.teammodel.cn";
  1607. accessKey = "QUzQqbqbnLsTDTeaJy4Br6wUuqPoAlKpzRK2S6PGImRHAzFuySGAeA==";
  1608. }
  1609. else if(location.Equals("China-Dep") || location.Equals("China-Test")) //大陸測試站
  1610. {
  1611. urlAction = "https://malearn-rc.teammodel.cn";
  1612. accessKey = "hESc0g7Q60FTEss4ZnVXPB61S1a8WlAXIq5ULl3T3oTxAzFunpLDwA==";
  1613. }
  1614. }
  1615. else if (location.Contains("Global"))
  1616. {
  1617. if(location.Equals("Global")) //國際正式站
  1618. {
  1619. urlAction = "https://malearn.teammodel.net";
  1620. accessKey = "I-2lTcdggJkZWSBwOXQIm4oHx-huwX3d0wLe-9pgojThAzFuq_KNFg==";
  1621. }
  1622. else if(location.Equals("Global-Test")) //國際測試站
  1623. {
  1624. urlAction = "https://malearn-rc.teammodel.net";
  1625. accessKey = "_l4Cb_tHIRBw_iv3ZuwVqjkMwjg4_HtDaxhAmZ8OwJraAzFu_DAY8A==";
  1626. }
  1627. }
  1628. string connect = $"{urlAction}/api/crtmabank";
  1629. var htc = _httpClient.CreateClient();
  1630. if (htc.DefaultRequestHeaders.Contains("x-functions-key"))
  1631. {
  1632. htc.DefaultRequestHeaders.Remove("x-functions-key");
  1633. }
  1634. htc.DefaultRequestHeaders.Add("x-functions-key", accessKey);
  1635. string paramJson = JsonConvert.SerializeObject(errors);
  1636. var content = new StringContent(paramJson, Encoding.UTF8, "application/json");
  1637. await htc.PostAsync(connect, content);
  1638. await task_error.TaskPage(10);
  1639. }
  1640. } catch (Exception e) {
  1641. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测错题异常{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  1642. }
  1643. }
  1644. public class Settlement
  1645. {
  1646. public double rate { get; set; }
  1647. public double score { get; set; }
  1648. public List<string> stus { get; set; } = new List<string>();
  1649. public int total { get; set; }
  1650. public double qrate { get; set; }
  1651. }
  1652. }
  1653. }