TriggerExam.cs 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206
  1. using Azure.Cosmos;
  2. using Azure.Messaging.ServiceBus;
  3. using Microsoft.Azure.Documents;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Text.Json;
  9. using System.Threading.Tasks;
  10. using TEAMModelOS.SDK.DI;
  11. using TEAMModelOS.SDK.Extension;
  12. using TEAMModelOS.SDK;
  13. using TEAMModelOS.SDK.Models;
  14. using TEAMModelOS.SDK.Models.Service;
  15. using HTEXLib.COMM.Helpers;
  16. using System.Net.Http;
  17. namespace TEAMModelOS.FunctionV4
  18. {
  19. public class TriggerExam
  20. {
  21. public static async Task Trigger(CoreAPIHttpService _coreAPIHttpService, AzureCosmosFactory _azureCosmos, AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, DingDing _dingDing,
  22. CosmosClient client, JsonElement input, TriggerData data)
  23. {
  24. List<ExamClassResult> examClassResults = new();
  25. List<ExamSubject> examSubjects = new();
  26. try
  27. {
  28. if ((data.status != null && data.status.Value == 404))
  29. {
  30. await client.GetContainer(Constant.TEAMModelOS, "Common").DeleteItemStreamAsync(data.id, new PartitionKey(data.code));
  31. ActivityList activity = input.ToObject<ActivityList>();
  32. await ActivityService.DeleteActivity(_coreAPIHttpService, client, _dingDing, activity);
  33. return;
  34. }
  35. ExamInfo info = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(data.id, new Azure.Cosmos.PartitionKey($"{data.code}"));
  36. if (info != null)
  37. {
  38. if (info.scope.Equals("teacher", StringComparison.OrdinalIgnoreCase) || info.scope.Equals("private", StringComparison.OrdinalIgnoreCase))
  39. {
  40. 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}") }))
  41. {
  42. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  43. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  44. {
  45. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  46. {
  47. examClassResults.Add(obj.ToObject<ExamClassResult>());
  48. }
  49. }
  50. }
  51. }
  52. else
  53. {
  54. 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}") }))
  55. {
  56. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  57. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  58. {
  59. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  60. {
  61. examClassResults.Add(obj.ToObject<ExamClassResult>());
  62. }
  63. }
  64. }
  65. }
  66. var table = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord");
  67. string PartitionKey = string.Format("{0}{1}{2}", info.code, "-", info.progress);
  68. List<ChangeRecord> records = await table.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", data.id }, { "PartitionKey", PartitionKey } });
  69. //处理科目信息
  70. List<string> sub = new List<string>();
  71. foreach (ExamSubject subject in info.subjects)
  72. {
  73. sub.Add(subject.id);
  74. }
  75. //整合名单
  76. List<string> classes = ExamService.getClasses(info.classes, info.stuLists);
  77. //ChangeRecord record = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ChangeRecord>(input.Id, new Azure.Cosmos.PartitionKey($"{info.progress}"));
  78. switch (info.progress)
  79. {
  80. case "pending":
  81. var message = new ServiceBusMessage(new { id = data.id, progress = "going", code = data.code }.ToJsonString());
  82. message.ApplicationProperties.Add("name", "Exam");
  83. if (records.Count > 0)
  84. {
  85. await _serviceBus.GetServiceBusClient().cancelMessage(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), records[0].sequenceNumber);
  86. long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), message, DateTimeOffset.FromUnixTimeMilliseconds(data.startTime));
  87. records[0].sequenceNumber = start;
  88. await table.SaveOrUpdate<ChangeRecord>(records[0]);
  89. //await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(record, record.id, new Azure.Cosmos.PartitionKey($"{record.code}"));
  90. }
  91. else
  92. {
  93. long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), message, DateTimeOffset.FromUnixTimeMilliseconds(data.startTime));
  94. //string pk = String.Format("{0}{1}{2}", info.code, "-", "pending");
  95. ChangeRecord changeRecord = new ChangeRecord
  96. {
  97. RowKey = data.id,
  98. PartitionKey = PartitionKey,
  99. sequenceNumber = start,
  100. msgId = message.MessageId
  101. };
  102. await table.Save<ChangeRecord>(changeRecord);
  103. //await client.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync(changeRecord, new Azure.Cosmos.PartitionKey($"{changeRecord.code}"));
  104. }
  105. break;
  106. case "going":
  107. try
  108. {
  109. //向学生或醍摩豆账号发起通知
  110. #region
  111. //Notice notice = new Notice()
  112. //{
  113. // msgId = info.id,
  114. // creation = info.startTime,
  115. // expire = info.endTime,
  116. // creatorId = info.creatorId,
  117. // stuids = studentss,
  118. // tmdids = tmdids,
  119. // type = "notice",//评测参加通知
  120. // priority = "normal",
  121. // school = info.school,
  122. // scope = info.scope,
  123. // //data = new { }.ToJsonString()
  124. // body = new Body { sid = info.id, scode = info.code, spk = info.pk, biztype = "exam-join" }
  125. //};
  126. //var messageBlob = new ServiceBusMessage(notice.ToJsonString());
  127. //messageBlob.ApplicationProperties.Add("name", "Notice");
  128. //await _serviceBus.GetServiceBusClient().SendMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageBlob);
  129. #endregion
  130. //List<string> classes = new List<string>();
  131. //处理活动中间件
  132. List<RGroupList> members = await Activity(_coreAPIHttpService, info, classes, client, _dingDing, sub, examClassResults);
  133. if (examClassResults.Count == 0)
  134. {
  135. foreach (string cla in classes)
  136. {
  137. int m = 0;
  138. RGroupList rGroup = new();
  139. rGroup = members.Where(m => m.id.Equals(cla)).FirstOrDefault();
  140. foreach (ExamSubject subject in info.subjects)
  141. {
  142. string classCode = String.Empty;
  143. string cname = string.Empty;
  144. if (string.IsNullOrEmpty(info.school) || !info.scope.Equals("school", StringComparison.OrdinalIgnoreCase))
  145. {
  146. classCode = "ExamClassResult-" + info.creatorId;
  147. }
  148. else
  149. {
  150. classCode = "ExamClassResult-" + info.school;
  151. }
  152. cname = members.Where(m => m.id.Equals(cla)).FirstOrDefault()?.name;
  153. ExamClassResult result = new()
  154. {
  155. code = classCode,
  156. examId = info.id,
  157. id = Guid.NewGuid().ToString(),
  158. subjectId = subject.id,
  159. year = info.year,
  160. scope = info.scope
  161. };
  162. result.info.id = cla;
  163. result.info.name = cname;
  164. List<string> ans = new List<string>();
  165. List<List<string>> anses = new List<List<string>>();
  166. List<List<Details>> marks = new List<List<Details>>();
  167. List<double> ansPoint = new List<double>();
  168. List<(string sId, string scode)> ids = new List<(string sId, string scode)>();
  169. foreach (double p in info.papers[m].point)
  170. {
  171. //Details details = new Details();
  172. //ans.Add(new List<string>());
  173. anses.Add(new List<string>());
  174. marks.Add(new List<Details>());
  175. ansPoint.Add(-1);
  176. }
  177. var sresponse = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(cla, new Azure.Cosmos.PartitionKey($"Class-{info.school}"));
  178. if (sresponse.Status == 200)
  179. {
  180. using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
  181. Class classroom = json.ToObject<Class>();
  182. School sc = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(info.school, new Azure.Cosmos.PartitionKey("Base"));
  183. foreach (Period period in sc.period)
  184. {
  185. if (period.id.Equals(classroom.periodId))
  186. {
  187. foreach (Semester semester in period.semesters)
  188. {
  189. if (semester.start == 1)
  190. {
  191. int year = DateTimeOffset.UtcNow.Year;
  192. int month = DateTimeOffset.UtcNow.Month;
  193. int day = DateTimeOffset.UtcNow.Day;
  194. int time = 0;
  195. if (month == semester.month)
  196. {
  197. time = day >= semester.day ? 0 : 1;
  198. }
  199. else
  200. {
  201. time = month > semester.month ? 0 : 1;
  202. }
  203. int eyear = year - time;
  204. result.gradeId = (eyear - classroom.year).ToString();
  205. }
  206. }
  207. }
  208. }
  209. //result.info.id = classroom.id;
  210. //result.info.name = classroom.name;
  211. //result.gradeId = classroom.year.ToString();
  212. //处理班级人数
  213. /* 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}") }))
  214. {
  215. using var json_stu = await JsonDocument.ParseAsync(item.ContentStream);
  216. if (json_stu.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  217. {
  218. var accounts = json_stu.RootElement.GetProperty("Documents").EnumerateArray();
  219. while (accounts.MoveNext())
  220. {
  221. JsonElement account = accounts.Current;
  222. ids.Add(account.GetProperty("id").GetString());
  223. }
  224. }
  225. }*/
  226. }
  227. /*if (info.scope.Equals("private", StringComparison.OrdinalIgnoreCase))
  228. {
  229. var stuResponse = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemStreamAsync(cla, new Azure.Cosmos.PartitionKey($"GroupList"));
  230. if (stuResponse.Status == 200)
  231. {
  232. using var json = await JsonDocument.ParseAsync(stuResponse.ContentStream);
  233. GroupList stuList = json.ToObject<GroupList>();
  234. //result.info.id = stuList.id;
  235. result.info.name = stuList.name;
  236. //处理发布对象为自选名单(个人)
  237. foreach (Member stus in stuList.members)
  238. {
  239. if (!ids.Contains(stus.id))
  240. {
  241. ids.Add(stus.id);
  242. }
  243. }
  244. }
  245. }
  246. else
  247. {
  248. var stuResponse = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(cla, new Azure.Cosmos.PartitionKey($"GroupList-{info.school}"));
  249. if (stuResponse.Status == 200)
  250. {
  251. using var json = await JsonDocument.ParseAsync(stuResponse.ContentStream);
  252. GroupList stuList = json.ToObject<GroupList>();
  253. //result.info.id = stuList.id;
  254. result.info.name = stuList.name;
  255. //处理发布对象为自选名单(校本)
  256. foreach (Member stus in stuList.members)
  257. {
  258. if (!ids.Contains(stus.id))
  259. {
  260. ids.Add(stus.id);
  261. }
  262. }
  263. }
  264. }*/
  265. foreach (RMember member in rGroup.members)
  266. {
  267. ids.Add((member.id, member.code));
  268. }
  269. //ids = members.Where(c => c.id.Equals(cla)).SelectMany(m => m.members).Select(g => g.id).ToList();
  270. foreach (var (sId, scode) in ids)
  271. {
  272. result.mark.Add(marks);
  273. result.studentIds.Add(sId);
  274. //result.scIds.Add(scode ?? "");
  275. result.studentAnswers.Add(ans);
  276. result.studentScores.Add(ansPoint);
  277. result.ans.Add(anses);
  278. result.sum.Add(0);
  279. result.status.Add(0);
  280. }
  281. //result.progress = info.progress;
  282. result.school = info.school;
  283. m++;
  284. await client.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync(result, new Azure.Cosmos.PartitionKey($"{result.code}"));
  285. }
  286. }
  287. }
  288. else
  289. {
  290. //处理单科结算时科目与试卷信息匹配的问题
  291. int gno = 0;
  292. foreach (ExamSubject subject in info.subjects)
  293. {
  294. if (subject.classCount == classes.Count)
  295. {
  296. await createClassResultAsync(info, examClassResults, subject, gno, _azureCosmos, _dingDing, _azureStorage);
  297. }
  298. gno++;
  299. }
  300. var isScore = examClassResults.SelectMany(e => e.studentScores).ToList().Exists(c => c.Contains(-1));
  301. int newStatus = 0;
  302. if (!isScore)
  303. {
  304. newStatus = 1;
  305. }
  306. Settlement settlement = await getMore(client, info, examClassResults);
  307. long nowTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  308. //判断评分状态是否发生变化,便于实时的更新评测基本信息
  309. if ((info.updateTime != nowTime && info.average != settlement.score) || info.sStatus != newStatus)
  310. {
  311. info.sRate = settlement.rate;
  312. info.sStatus = newStatus;
  313. info.updateTime = nowTime;
  314. info.average = settlement.score;
  315. await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync<ExamInfo>(info, info.id, new PartitionKey(info.code));
  316. }
  317. }
  318. }
  319. catch (Exception e)
  320. {
  321. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测going状态异常{e.Message}\n{e.StackTrace}", GroupNames.成都开发測試群組);
  322. }
  323. finally
  324. {
  325. // 发送信息通知
  326. var messageEnd = new ServiceBusMessage(new { id = data.id, progress = "finish", code = data.code }.ToJsonString());
  327. messageEnd.ApplicationProperties.Add("name", "Exam");
  328. if (records.Count > 0)
  329. {
  330. long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageEnd, DateTimeOffset.FromUnixTimeMilliseconds(data.endTime));
  331. await _serviceBus.GetServiceBusClient().cancelMessage(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), records[0].sequenceNumber);
  332. records[0].sequenceNumber = end;
  333. await table.SaveOrUpdate<ChangeRecord>(records[0]);
  334. //await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(record, record.id, new Azure.Cosmos.PartitionKey($"{record.code}"));
  335. }
  336. else
  337. {
  338. long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageEnd, DateTimeOffset.FromUnixTimeMilliseconds(data.endTime));
  339. //string pk = String.Format("{0}{1}{2}", info.code, "-", "going");
  340. ChangeRecord changeRecord = new ChangeRecord
  341. {
  342. RowKey = data.id,
  343. PartitionKey = PartitionKey,
  344. sequenceNumber = end,
  345. msgId = messageEnd.MessageId
  346. };
  347. await table.Save<ChangeRecord>(changeRecord);
  348. //await client.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync(changeRecord, new Azure.Cosmos.PartitionKey($"{changeRecord.code}"));
  349. }
  350. }
  351. break;
  352. case "finish":
  353. int fno = 0;
  354. try
  355. {
  356. //用来判定是否完成评分
  357. //bool isScore = true;
  358. var isScore = examClassResults.SelectMany(e => e.studentScores).ToList().Exists(c => c.Contains(-1));
  359. int newStatus = 0;
  360. if (!isScore)
  361. {
  362. newStatus = 1;
  363. }
  364. //处理活动中间件
  365. List<StuActivity> stus = new();
  366. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<StuActivity>(
  367. queryText: $"select c.id from c where c.id = '{info.id}'"))
  368. {
  369. stus.Add(item);
  370. }
  371. if (info.source.Equals("1") && stus.Count == 0)
  372. {
  373. await Activity(_coreAPIHttpService, info, classes, client, _dingDing, sub, examClassResults);
  374. }
  375. foreach (ExamSubject subject in info.subjects)
  376. {
  377. await createClassResultAsync(info, examClassResults, subject, fno, _azureCosmos, _dingDing, _azureStorage);
  378. fno++;
  379. }
  380. Settlement settlement = await getMore(client, info, examClassResults);
  381. //info.lostStu = losStu;
  382. /*//补充历史数据的容器名称
  383. if (string.IsNullOrEmpty(info.cn)) {
  384. if (info.scope.Equals("school"))
  385. {
  386. info.cn = info.school;
  387. }
  388. else {
  389. info.cn = info.creatorId;
  390. }
  391. }*/
  392. //判断均分是否发生变化,便于实时的更新评测基本信息
  393. if (info.sRate != settlement.rate || info.average != settlement.score || info.sStatus != newStatus)
  394. {
  395. info.sRate = settlement.rate;
  396. info.average = settlement.score;
  397. info.sStatus = newStatus;
  398. info.lostStu = settlement.stus;
  399. info.stuCount = settlement.total;
  400. await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync<ExamInfo>(info, info.id, new Azure.Cosmos.PartitionKey(info.code));
  401. }
  402. }
  403. catch (Exception e)
  404. {
  405. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测finish状态异常{e.Message}\n{e.StackTrace}", GroupNames.成都开发測試群組);
  406. }
  407. break;
  408. }
  409. }
  410. }
  411. catch (CosmosException e)
  412. {
  413. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-CosmosDB异常{e.StackTrace}{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
  414. }
  415. catch (Exception e)
  416. {
  417. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-评测结算异常{e.Message}\n{e.StackTrace}", GroupNames.成都开发測試群組);
  418. }
  419. }
  420. public static async Task<Settlement> getMore(CosmosClient client, ExamInfo info, List<ExamClassResult> examClassResults)
  421. {
  422. //计算单次考试简易统计信息
  423. Settlement settlement = new();
  424. List<ExamResult> examResults = new();
  425. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<ExamResult>(
  426. queryText: $"select value(c) from c where c.examId = '{info.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"ExamResult-{info.id}") }))
  427. {
  428. examResults.Add(item);
  429. }
  430. if (examResults.Count > 0)
  431. {
  432. List<Task<ItemResponse<ExamClassResult>>> tasks = new List<Task<ItemResponse<ExamClassResult>>>();
  433. //结算单科单班的标准差和平均分
  434. foreach (ExamClassResult classResult in examClassResults)
  435. {
  436. //标记单科单班总得分
  437. double subScore = 0;
  438. //标准差
  439. double sPowSum = 0;
  440. List<double> newSumScore = new List<double>();
  441. var scount = classResult.studentIds.Count;
  442. foreach (List<double> sc in classResult.studentScores)
  443. {
  444. List<double> newSc = new List<double>();
  445. foreach (double ssc in sc)
  446. {
  447. if (ssc == -1)
  448. {
  449. newSc.Add(0);
  450. }
  451. else
  452. {
  453. newSc.Add(ssc);
  454. }
  455. }
  456. double nc = newSc.Sum();
  457. newSumScore.Add(nc);
  458. subScore += nc;
  459. }
  460. double rateScore = scount > 0 ? Math.Round(subScore * 1.0 / scount, 2) : 0;
  461. foreach (double scs in newSumScore)
  462. {
  463. sPowSum += Math.Pow(scs - rateScore, 2);
  464. }
  465. classResult.standard = Math.Round(scount > 0 ? Math.Pow(sPowSum / scount, 0.5) : 0, 2);
  466. classResult.average = scount > 0 ? Math.Round(subScore / scount, 2) : 0;
  467. classResult.progress = true;
  468. tasks.Add(client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new Azure.Cosmos.PartitionKey($"{classResult.code}")));
  469. }
  470. await Task.WhenAll(tasks);
  471. //记录某次考试所有学生得分总分
  472. double score = 0;
  473. double allScore = 0;
  474. int stuCount = 0;
  475. //标准差
  476. double powSum = 0;
  477. List<string> losStu = new List<string>();
  478. //当前完成考试得人数
  479. int total = examResults[0].studentIds.Count;
  480. //先与第一个值取并集
  481. losStu = losStu.Union(examResults[0].lostStus).ToList();
  482. foreach (ExamResult examResult in examResults)
  483. {
  484. if (info.id == examResult.examId)
  485. {
  486. foreach (List<double> sc in examResult.studentScores)
  487. {
  488. score += sc.Sum();
  489. }
  490. stuCount = examResult.studentIds.Count;
  491. }
  492. //powSum += Math.Pow(score - examResult.studentIds.Count > 0 ? Math.Round(score * 1.0 / examResult.studentIds.Count, 2) : 0, 2);
  493. //取交集
  494. losStu = losStu.Intersect(examResult.lostStus).ToList();
  495. }
  496. double NewsRateScore = stuCount > 0 ? Math.Round(score * 1.0 / stuCount, 2) : 0;
  497. foreach (PaperSimple simple in info.papers)
  498. {
  499. allScore += simple.point.Sum();
  500. }
  501. //计算全科标准差
  502. foreach (string id in examResults[0].studentIds)
  503. {
  504. double sc = 0;
  505. foreach (ExamResult result in examResults)
  506. {
  507. sc += result.studentScores[result.studentIds.IndexOf(id)].Sum();
  508. }
  509. powSum += Math.Pow(sc - NewsRateScore, 2);
  510. }
  511. info.standard = Math.Round(total > 0 ? Math.Pow(powSum / total, 0.5) : 0, 2);
  512. double NewsRate = allScore > 0 ? Math.Round(NewsRateScore / allScore * 100, 2) : 0;
  513. settlement.rate = NewsRate;
  514. settlement.score = NewsRateScore;
  515. settlement.stus = losStu;
  516. settlement.total = total;
  517. }
  518. return settlement;
  519. }
  520. //处理全部学生选题计数
  521. public static async Task examRecordCount(ExamInfo info, ExamSubject subject, DingDing _dingDing, int no, ExamResult result, List<ExamClassResult> classResults, AzureCosmosFactory _azureCosmos)
  522. {
  523. try
  524. {
  525. List<double> scores = new List<double>();
  526. foreach (List<double> sc in result.studentScores)
  527. {
  528. scores.Add(sc.Sum());
  529. }
  530. //确定高分组 最低分数
  531. scores.Sort((s1, s2) => { return s2.CompareTo(s1); });
  532. double rhwCount = Math.Floor(scores.Count * 0.27);
  533. double rhw = rhwCount > 0 ? scores[int.Parse(rhwCount.ToString("0"))] : 0;
  534. //确定低分组 最高分数
  535. //scores.Sort((s1, s2) => { return s1.CompareTo(s2); });
  536. double rhlCount = Math.Ceiling(scores.Count * 0.73);
  537. double rhl = rhlCount > 0 ? scores[int.Parse(rhlCount.ToString("0")) - 1] : 0;
  538. //存放高分组学生ID
  539. List<string> phId = new List<string>();
  540. List<string> plId = new List<string>();
  541. List<List<List<string>>> opth = new List<List<List<string>>>();
  542. List<List<List<string>>> optl = new List<List<List<string>>>();
  543. await knowledgeCount(info, subject, _dingDing, no, classResults, rhwCount, rhw, rhlCount, rhl, _azureCosmos);
  544. await fieldCount(info, subject, _dingDing, no, classResults, rhwCount, rhw, rhlCount, rhl, _azureCosmos);
  545. int PHCount = 0;
  546. int PLCount = 0;
  547. foreach (ExamClassResult classResult in classResults)
  548. {
  549. if (classResult.subjectId.Equals(subject.id))
  550. {
  551. foreach (string id in classResult.studentIds)
  552. {
  553. int index = classResult.studentIds.IndexOf(id);
  554. if (classResult.studentScores.Count > 0)
  555. {
  556. if (classResult.studentScores[index].Sum() >= rhw && PHCount < rhwCount)
  557. {
  558. if (classResult.ans.Count > 0)
  559. {
  560. opth.Add(classResult.ans[index]);
  561. PHCount++;
  562. continue;
  563. }
  564. }
  565. if (classResult.studentScores[index].Sum() <= rhl && PLCount < (scores.Count - rhlCount))
  566. {
  567. if (classResult.ans.Count > 0)
  568. {
  569. optl.Add(classResult.ans[index]);
  570. PLCount++;
  571. continue;
  572. }
  573. }
  574. }
  575. }
  576. }
  577. }
  578. result.phc = getMore(info, no, opth);
  579. result.plc = getMore(info, no, optl);
  580. }
  581. catch (Exception ex)
  582. {
  583. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测作答记录结算异常{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  584. }
  585. }
  586. public static async Task<List<RGroupList>> Activity(CoreAPIHttpService _coreAPIHttpService, ExamInfo info, List<string> classes, CosmosClient client, DingDing _dingDing, List<string> sub, List<ExamClassResult> results)
  587. {
  588. List<(string pId, List<string> gid)> ps = new List<(string pId, List<string> gid)>();
  589. if (info.groupLists.Count > 0)
  590. {
  591. var group = info.groupLists;
  592. foreach (var gp in group)
  593. {
  594. foreach (KeyValuePair<string, List<string>> pp in gp)
  595. {
  596. ps.Add((pp.Key, pp.Value));
  597. }
  598. }
  599. }
  600. (List<RMember> tchList, List<RGroupList> classLists) = await GroupListService.GetStutmdidListids(_coreAPIHttpService, client, _dingDing, classes, info.school, ps);
  601. var addStudentsCls = tchList.FindAll(x => x.type == 2);
  602. var addTmdidsCls = tchList.FindAll(x => x.type == 1);
  603. List<StuActivity> stuActivities = new List<StuActivity>();
  604. List<StuActivity> tmdActivities = new List<StuActivity>();
  605. if (addTmdidsCls.IsNotEmpty())
  606. {
  607. addTmdidsCls.ForEach(x =>
  608. {
  609. HashSet<string> classIds = new HashSet<string>();
  610. classLists.ForEach(z =>
  611. {
  612. z.members.ForEach(y =>
  613. {
  614. if (y.id.Equals(x.id) && y.type == 1)
  615. {
  616. classIds.Add(z.id);
  617. }
  618. });
  619. });
  620. bool iss = false;
  621. //标记学生作答状态
  622. int ts = 0;
  623. if (results.Count > 0)
  624. {
  625. foreach (ExamClassResult exam in results)
  626. {
  627. int index = exam.studentIds.IndexOf(x.id);
  628. if (index != -1)
  629. {
  630. if (exam.studentAnswers[index].Count > 0)
  631. {
  632. bool flag = exam.studentScores[index].Exists(x => x == -1);
  633. if (!flag)
  634. {
  635. ts = 1;
  636. iss = true;
  637. break;
  638. }
  639. else
  640. {
  641. ts = 0;
  642. }
  643. }
  644. else
  645. {
  646. ts = -1;
  647. }
  648. }
  649. }
  650. }
  651. else
  652. {
  653. ts = -1;
  654. }
  655. tmdActivities.Add(new StuActivity
  656. {
  657. pk = "Activity",
  658. id = info.id,
  659. code = $"Activity-{x.id}",
  660. type = "Exam",
  661. name = info.name,
  662. source = info.source,
  663. startTime = info.startTime,
  664. endTime = info.endTime,
  665. scode = info.code,
  666. scope = info.scope,
  667. school = info.school,
  668. creatorId = info.creatorId,
  669. subjects = sub,
  670. blob = null,
  671. owner = info.owner,
  672. createTime = info.createTime,
  673. taskStatus = ts,
  674. ext = new Dictionary<string, JsonElement>() { { "type", info.type.ToJsonString().ToObject<JsonElement>() }, { "subjects", info.subjects.ToJsonString().ToObject<JsonElement>() } },
  675. sStatus = iss ? 1 : 0,
  676. classIds = classIds.ToList()
  677. }); ;
  678. });
  679. }
  680. if (addStudentsCls.IsNotEmpty())
  681. {
  682. addStudentsCls.ForEach(x =>
  683. {
  684. HashSet<string> classIds = new HashSet<string>();
  685. classLists.ForEach(z =>
  686. {
  687. z.members.ForEach(y =>
  688. {
  689. if (y.id.Equals(x.id) && y.code.Equals(info.school) && y.type == 2)
  690. {
  691. classIds.Add(z.id);
  692. }
  693. });
  694. });
  695. bool iss = false;
  696. //标记学生作答状态
  697. int ts = 0;
  698. if (results.Count > 0)
  699. {
  700. foreach (ExamClassResult exam in results)
  701. {
  702. int index = exam.studentIds.IndexOf(x.id);
  703. if (index != -1)
  704. {
  705. if (exam.studentAnswers[index].Count > 0)
  706. {
  707. bool flag = exam.studentScores[index].Exists(x => x == -1);
  708. if (!flag)
  709. {
  710. ts = 1;
  711. iss = true;
  712. break;
  713. }
  714. else
  715. {
  716. ts = 0;
  717. }
  718. }
  719. else
  720. {
  721. ts = -1;
  722. }
  723. }
  724. }
  725. }
  726. else
  727. {
  728. ts = -1;
  729. }
  730. stuActivities.Add(new StuActivity
  731. {
  732. pk = "Activity",
  733. id = info.id,
  734. code = $"Activity-{x.code.Replace("Base-", "")}-{x.id}",
  735. type = "Exam",
  736. name = info.name,
  737. source = info.source,
  738. startTime = info.startTime,
  739. endTime = info.endTime,
  740. scode = info.code,
  741. scope = info.scope,
  742. school = info.school,
  743. creatorId = info.creatorId,
  744. subjects = sub,
  745. blob = null,
  746. owner = info.owner,
  747. classIds = classIds.ToList(),
  748. createTime = info.createTime,
  749. ext = new Dictionary<string, JsonElement>() { { "type", info.type.ToJsonString().ToObject<JsonElement>() },
  750. { "subjects", info.subjects.ToJsonString().ToObject<JsonElement>() } },
  751. taskStatus = ts,
  752. sStatus = iss ? 1 : 0,
  753. });
  754. });
  755. }
  756. await ActivityService.SaveStuActivity(client, _dingDing, stuActivities, tmdActivities, null);
  757. return classLists;
  758. }
  759. public static async Task knowledgeCount(ExamInfo info, ExamSubject subject, DingDing _dingDing, int no, List<ExamClassResult> classResults,
  760. double rhwCount, double rhw, double rhlCount, double rhl, AzureCosmosFactory _azureCosmos)
  761. {
  762. try
  763. {
  764. int phcount = 0;
  765. int plcount = 0;
  766. //存放并去重知识点
  767. HashSet<string> kname = new HashSet<string>();
  768. if (info.papers[no].knowledge.Count > 0)
  769. {
  770. info.papers[no].knowledge.ForEach(kno =>
  771. {
  772. kno.ForEach(k =>
  773. {
  774. kname.Add(k);
  775. });
  776. });
  777. List<string> knowledgeName = new List<string>();
  778. foreach (string cla in kname)
  779. {
  780. knowledgeName.Add(cla);
  781. }
  782. for (int k = 0; k < knowledgeName.Count; k++)
  783. {
  784. if (null == knowledgeName[k])
  785. {
  786. knowledgeName.Remove(knowledgeName[k]);
  787. }
  788. }
  789. foreach (ExamClassResult classResult in classResults)
  790. {
  791. if (classResult.subjectId.Equals(subject.id))
  792. {
  793. //List<int> phc = new List<int>();
  794. List<int> ph = new List<int>();
  795. List<int> pl = new List<int>();
  796. List<int> pc = new List<int>();
  797. List<double> persent = new List<double>();
  798. for (int i = 0; i < knowledgeName.Count; i++)
  799. {
  800. //初始化单个知识点得分
  801. double score = 0;
  802. double allScore = 0;
  803. int n = 0;
  804. int phCount = 0;
  805. int plCount = 0;
  806. int pCount = 0;
  807. foreach (List<string> str in info.papers[no].knowledge)
  808. {
  809. if (str.Contains(knowledgeName[i]))
  810. {
  811. var itemPersent = str.Count > 0 ? 1 / Convert.ToDouble(str.Count) : 0;
  812. allScore += info.papers[no].point.Count > 0 ? info.papers[no].point[n] * itemPersent : 0;
  813. foreach (string id in classResult.studentIds)
  814. {
  815. int index = classResult.studentIds.IndexOf(id);
  816. if (classResult.studentScores.Count > 0)
  817. {
  818. if (classResult.studentScores[index].Count > 0)
  819. {
  820. score += classResult.studentScores[index][n] == -1 ? 0 : classResult.studentScores[index][n];
  821. if (classResult.studentScores[index].Sum() >= rhw && phcount < rhwCount)
  822. {
  823. if (classResult.studentScores[index][n] <= 0)
  824. {
  825. phCount++;
  826. }
  827. phcount++;
  828. continue;
  829. }
  830. if (classResult.studentScores[index].Sum() <= rhl && plcount < (info.stuCount - rhlCount))
  831. {
  832. if (classResult.studentScores[index][n] <= 0)
  833. {
  834. plCount++;
  835. }
  836. plcount++;
  837. continue;
  838. }
  839. if (classResult.studentScores[index][n] <= 0)
  840. {
  841. pCount++;
  842. }
  843. }
  844. }
  845. }
  846. }
  847. n++;
  848. }
  849. pc.Add(pCount);
  850. ph.Add(phCount);
  851. pl.Add(plCount);
  852. double per = classResult.studentIds.Count > 0 ? Math.Round(score / classResult.studentIds.Count, 2) : 0;
  853. persent.Add(allScore > 0 ? per / allScore : 0);
  854. }
  855. classResult.phc = ph;
  856. classResult.plc = pl;
  857. classResult.pc = pc;
  858. classResult.krate = persent;
  859. }
  860. //await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new Azure.Cosmos.PartitionKey($"{classResult.code}"));
  861. }
  862. }
  863. }
  864. catch (Exception ex)
  865. {
  866. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测知识点结算异常{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  867. }
  868. }
  869. public static async Task fieldCount(ExamInfo info, ExamSubject subject, DingDing _dingDing, int no, List<ExamClassResult> classResults,
  870. double rhwCount, double rhw, double rhlCount, double rhl, AzureCosmosFactory _azureCosmos)
  871. {
  872. try
  873. {
  874. int phcount = 0;
  875. int plcount = 0;
  876. //存放并去重知识点
  877. List<int> knowledgeName = new List<int>() { 1, 2, 3, 4, 5, 6 };
  878. /* knowledgeName.Add(1);
  879. knowledgeName.Add(2);
  880. knowledgeName.Add(3);
  881. knowledgeName.Add(4);
  882. knowledgeName.Add(5);
  883. knowledgeName.Add(6);*/
  884. foreach (ExamClassResult classResult in classResults)
  885. {
  886. if (classResult.subjectId.Equals(subject.id))
  887. {
  888. //List<int> phc = new List<int>();
  889. List<int> ph = new List<int>();
  890. List<int> pl = new List<int>();
  891. List<int> pc = new List<int>();
  892. List<double> persent = new List<double>();
  893. for (int i = 0; i < knowledgeName.Count; i++)
  894. {
  895. //初始化单个知识点得分
  896. double score = 0;
  897. double allScore = 0;
  898. int n = 0;
  899. int phCount = 0;
  900. int plCount = 0;
  901. int pCount = 0;
  902. if (info.papers[no].field.Count > 0)
  903. {
  904. foreach (int str in info.papers[no].field)
  905. {
  906. if (str == knowledgeName[i])
  907. {
  908. var itemPersent = 1;
  909. allScore += info.papers[no].point.Count > 0 ? info.papers[no].point[n] * itemPersent : 0;
  910. foreach (string id in classResult.studentIds)
  911. {
  912. int index = classResult.studentIds.IndexOf(id);
  913. if (classResult.studentScores.Count > 0)
  914. {
  915. if (classResult.studentScores[index].Count > 0)
  916. {
  917. score += classResult.studentScores[index][n] == -1 ? 0 : classResult.studentScores[index][n];
  918. if (classResult.studentScores[index].Sum() >= rhw && phcount < rhwCount)
  919. {
  920. if (classResult.studentScores[index][n] <= 0)
  921. {
  922. phCount++;
  923. }
  924. phcount++;
  925. continue;
  926. }
  927. if (classResult.studentScores[index].Sum() <= rhl && plcount < (info.stuCount - rhlCount))
  928. {
  929. if (classResult.studentScores[index][n] <= 0)
  930. {
  931. plCount++;
  932. }
  933. plcount++;
  934. continue;
  935. }
  936. if (classResult.studentScores[index][n] <= 0)
  937. {
  938. pCount++;
  939. }
  940. }
  941. }
  942. }
  943. }
  944. n++;
  945. }
  946. pc.Add(pCount);
  947. ph.Add(phCount);
  948. pl.Add(plCount);
  949. double per = classResult.studentIds.Count > 0 ? Math.Round(score / classResult.studentIds.Count, 2) : 0;
  950. persent.Add(allScore > 0 ? per / allScore : 0);
  951. }
  952. }
  953. classResult.fphc = ph;
  954. classResult.fplc = pl;
  955. classResult.fpc = pc;
  956. classResult.frate = persent;
  957. }
  958. //await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new Azure.Cosmos.PartitionKey($"{classResult.code}"));
  959. }
  960. }
  961. catch (Exception ex)
  962. {
  963. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测认知层次结算异常{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  964. }
  965. }
  966. //处理选题计数
  967. public static List<Dictionary<string, int>> getMore(ExamInfo info, int no, List<List<List<string>>> list)
  968. {
  969. List<Dictionary<string, int>> recorde = new List<Dictionary<string, int>>();
  970. try
  971. {
  972. for (int i = 0; i < info.papers[no].answers.Count; i++)
  973. {
  974. if (info.papers[no].answers[i].Count <= 0)
  975. {
  976. recorde.Add(new Dictionary<string, int>());
  977. continue;
  978. }
  979. Dictionary<string, int> optCount = new Dictionary<string, int>();
  980. foreach (List<List<string>> stu in list)
  981. {
  982. if (stu.Count == info.papers[no].answers.Count)
  983. {
  984. var item = stu[i];
  985. foreach (string opt in item)
  986. {
  987. if (optCount.ContainsKey(opt))
  988. {
  989. optCount[opt] = optCount[opt] + 1;
  990. }
  991. else
  992. {
  993. optCount[opt] = 1;
  994. }
  995. }
  996. }
  997. }
  998. recorde.Add(optCount);
  999. }
  1000. return recorde;
  1001. }
  1002. catch (Exception)
  1003. {
  1004. return recorde;
  1005. }
  1006. }
  1007. public static async Task createClassResultAsync(ExamInfo info, List<ExamClassResult> examClassResults, ExamSubject subject, int no, AzureCosmosFactory _azureCosmos, DingDing _dingDing, AzureStorageFactory _azureStorage)
  1008. {
  1009. //保证试卷信息与科目信息同步
  1010. ExamResult result = new ExamResult();
  1011. //人数总和
  1012. int Count = 0;
  1013. int m = 0;
  1014. double score = 0;
  1015. //标准差
  1016. double powSum = 0;
  1017. double allScore = info.papers[no].point.Sum();
  1018. List<ClassRange> classRanges = new List<ClassRange>();
  1019. List<string> lostStu = new List<string>();
  1020. List<double> csRate = new List<double>();
  1021. List<List<List<string>>> opt = new List<List<List<string>>>();
  1022. foreach (ExamClassResult classResult in examClassResults)
  1023. {
  1024. double classSrate = 0;
  1025. if (classResult.subjectId.Equals(subject.id))
  1026. {
  1027. foreach (List<List<string>> op in classResult.ans)
  1028. {
  1029. opt.Add(op);
  1030. }
  1031. //记录缺考学生索引位置
  1032. int index_stu = 0;
  1033. foreach (var ans in classResult.studentAnswers)
  1034. {
  1035. if (ans.Count == 0)
  1036. {
  1037. if (!lostStu.Contains(classResult.studentIds[index_stu]))
  1038. {
  1039. lostStu.Add(classResult.studentIds[index_stu]);
  1040. }
  1041. }
  1042. index_stu++;
  1043. }
  1044. int index = 0;
  1045. foreach (List<double> scores in classResult.studentScores)
  1046. {
  1047. List<double> newScores = new List<double>();
  1048. //int count = 0;
  1049. foreach (double sc in scores)
  1050. {
  1051. newScores.Add(sc > -1 ? sc : 0);
  1052. /*if (sc == -1)
  1053. {
  1054. count++;
  1055. }*/
  1056. }
  1057. /*if (count == scores.Count)
  1058. {
  1059. if (!lostStu.Contains(classResult.studentIds[index]))
  1060. {
  1061. lostStu.Add(classResult.studentIds[index]);
  1062. }
  1063. //mcount++;
  1064. }*/
  1065. classSrate += newScores.Sum();
  1066. score += newScores.Sum();
  1067. result.studentScores.Add(newScores);
  1068. index++;
  1069. }
  1070. //处理班级信息
  1071. ClassRange range = new ClassRange();
  1072. range.id = classResult.info.id;
  1073. range.name = classResult.info.name;
  1074. range.gradeId = classResult.gradeId;
  1075. List<int> ran = new List<int>();
  1076. int stuCount = classResult.studentIds.Count;
  1077. Count += stuCount;
  1078. if (m == 0)
  1079. {
  1080. ran.Add(0);
  1081. ran.Add(stuCount - 1);
  1082. }
  1083. else
  1084. {
  1085. ran.Add(Count - stuCount);
  1086. ran.Add(Count - 1);
  1087. }
  1088. m++;
  1089. range.range = ran;
  1090. classRanges.Add(range);
  1091. //处理学生ID
  1092. foreach (string id in classResult.studentIds)
  1093. {
  1094. result.studentIds.Add(id);
  1095. }
  1096. if (allScore > 0)
  1097. {
  1098. csRate.Add(classResult.studentIds.Count > 0 ? Math.Round(classSrate * 1.0 / classResult.studentIds.Count, 2) : 0 / allScore);
  1099. }
  1100. else
  1101. {
  1102. csRate.Add(0);
  1103. }
  1104. //powSum += Math.Pow(classSrate - result.average, 2);
  1105. //处理选项计数内容
  1106. }
  1107. }
  1108. /*foreach (string id in result.lostStus) {
  1109. if (!examClassResults[0].studentIds.Contains(id)) {
  1110. int index = result.lostStus.IndexOf(id);
  1111. result.lostStus.RemoveAt(index);
  1112. }
  1113. }*/
  1114. //处理人员变更时被移除的人员
  1115. if (result.lostStus.Count > 0)
  1116. {
  1117. for (int i = 0; i < result.lostStus.Count; i++)
  1118. {
  1119. if (!examClassResults[0].studentIds.Contains(result.lostStus[i]))
  1120. {
  1121. result.lostStus.RemoveAt(i);
  1122. }
  1123. }
  1124. }
  1125. await examRecordCount(info, subject, _dingDing, no, result, examClassResults, _azureCosmos);
  1126. result.record = getMore(info, no, opt);
  1127. result.average = result.studentIds.Count > 0 ? Math.Round(score * 1.0 / result.studentIds.Count, 2) : 0;
  1128. double stand = 0;
  1129. int sco = 0;
  1130. foreach (ExamClassResult classResult in examClassResults)
  1131. {
  1132. //double classSrate = 0;
  1133. if (classResult.subjectId.Equals(subject.id))
  1134. {
  1135. stand += classResult.standard;
  1136. sco++;
  1137. }
  1138. }
  1139. result.standard = sco > 0 ? Math.Round(stand / sco, 2) : 0;
  1140. result.csRate = csRate;
  1141. result.lostStus = lostStu;
  1142. result.sRate = allScore > 0 ? Math.Round(result.average / allScore * 100, 2) : 0;
  1143. result.classes = classRanges;
  1144. result.code = "ExamResult-" + info.id;
  1145. result.school = info.school;
  1146. result.id = subject.id;
  1147. result.examId = info.id;
  1148. result.subjectId = subject.id;
  1149. result.year = info.year;
  1150. result.paper = info.papers[no];
  1151. //result.point = info.papers[j].point;
  1152. result.scope = info.scope;
  1153. result.name = info.name;
  1154. result.time = info.startTime;
  1155. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").UpsertItemAsync(result, new Azure.Cosmos.PartitionKey($"ExamResult-{info.id}"));
  1156. }
  1157. public class Settlement
  1158. {
  1159. public double rate { get; set; }
  1160. public double score { get; set; }
  1161. public List<string> stus { get; set; } = new List<string>();
  1162. public int total { get; set; }
  1163. }
  1164. }
  1165. }