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. foreach (ExamSubject subject in info.subjects)
  139. {
  140. string classCode = String.Empty;
  141. string cname = string.Empty;
  142. if (string.IsNullOrEmpty(info.school) || !info.scope.Equals("school", StringComparison.OrdinalIgnoreCase))
  143. {
  144. classCode = "ExamClassResult-" + info.creatorId;
  145. }
  146. else
  147. {
  148. classCode = "ExamClassResult-" + info.school;
  149. }
  150. cname = members.Where(m => m.id.Equals(cla)).FirstOrDefault()?.name;
  151. ExamClassResult result = new()
  152. {
  153. code = classCode,
  154. examId = info.id,
  155. id = Guid.NewGuid().ToString(),
  156. subjectId = subject.id,
  157. year = info.year,
  158. scope = info.scope
  159. };
  160. result.info.id = cla;
  161. result.info.name = cname;
  162. List<string> ans = new List<string>();
  163. List<List<string>> anses = new List<List<string>>();
  164. List<List<Details>> marks = new List<List<Details>>();
  165. List<double> ansPoint = new List<double>();
  166. List<(string sId, string scode)> ids = new List<(string sId, string scode)>();
  167. foreach (double p in info.papers[m].point)
  168. {
  169. //Details details = new Details();
  170. //ans.Add(new List<string>());
  171. anses.Add(new List<string>());
  172. marks.Add(new List<Details>());
  173. ansPoint.Add(-1);
  174. }
  175. var sresponse = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(cla, new Azure.Cosmos.PartitionKey($"Class-{info.school}"));
  176. if (sresponse.Status == 200)
  177. {
  178. using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
  179. Class classroom = json.ToObject<Class>();
  180. School sc = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(info.school, new Azure.Cosmos.PartitionKey("Base"));
  181. foreach (Period period in sc.period)
  182. {
  183. if (period.id.Equals(classroom.periodId))
  184. {
  185. foreach (Semester semester in period.semesters)
  186. {
  187. if (semester.start == 1)
  188. {
  189. int year = DateTimeOffset.UtcNow.Year;
  190. int month = DateTimeOffset.UtcNow.Month;
  191. int day = DateTimeOffset.UtcNow.Day;
  192. int time = 0;
  193. if (month == semester.month)
  194. {
  195. time = day >= semester.day ? 0 : 1;
  196. }
  197. else
  198. {
  199. time = month > semester.month ? 0 : 1;
  200. }
  201. int eyear = year - time;
  202. result.gradeId = (eyear - classroom.year).ToString();
  203. }
  204. }
  205. }
  206. }
  207. //result.info.id = classroom.id;
  208. //result.info.name = classroom.name;
  209. //result.gradeId = classroom.year.ToString();
  210. //处理班级人数
  211. /* 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}") }))
  212. {
  213. using var json_stu = await JsonDocument.ParseAsync(item.ContentStream);
  214. if (json_stu.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  215. {
  216. var accounts = json_stu.RootElement.GetProperty("Documents").EnumerateArray();
  217. while (accounts.MoveNext())
  218. {
  219. JsonElement account = accounts.Current;
  220. ids.Add(account.GetProperty("id").GetString());
  221. }
  222. }
  223. }*/
  224. }
  225. /*if (info.scope.Equals("private", StringComparison.OrdinalIgnoreCase))
  226. {
  227. var stuResponse = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemStreamAsync(cla, new Azure.Cosmos.PartitionKey($"GroupList"));
  228. if (stuResponse.Status == 200)
  229. {
  230. using var json = await JsonDocument.ParseAsync(stuResponse.ContentStream);
  231. GroupList stuList = json.ToObject<GroupList>();
  232. //result.info.id = stuList.id;
  233. result.info.name = stuList.name;
  234. //处理发布对象为自选名单(个人)
  235. foreach (Member stus in stuList.members)
  236. {
  237. if (!ids.Contains(stus.id))
  238. {
  239. ids.Add(stus.id);
  240. }
  241. }
  242. }
  243. }
  244. else
  245. {
  246. var stuResponse = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(cla, new Azure.Cosmos.PartitionKey($"GroupList-{info.school}"));
  247. if (stuResponse.Status == 200)
  248. {
  249. using var json = await JsonDocument.ParseAsync(stuResponse.ContentStream);
  250. GroupList stuList = json.ToObject<GroupList>();
  251. //result.info.id = stuList.id;
  252. result.info.name = stuList.name;
  253. //处理发布对象为自选名单(校本)
  254. foreach (Member stus in stuList.members)
  255. {
  256. if (!ids.Contains(stus.id))
  257. {
  258. ids.Add(stus.id);
  259. }
  260. }
  261. }
  262. }*/
  263. foreach (RGroupList list in members)
  264. {
  265. foreach (RMember member in list.members)
  266. {
  267. ids.Add((member.id, member.code));
  268. }
  269. }
  270. //ids = members.Where(c => c.id.Equals(cla)).SelectMany(m => m.members).Select(g => g.id).ToList();
  271. foreach (var (sId, scode) in ids)
  272. {
  273. result.mark.Add(marks);
  274. result.studentIds.Add(sId);
  275. //result.scIds.Add(scode ?? "");
  276. result.studentAnswers.Add(ans);
  277. result.studentScores.Add(ansPoint);
  278. result.ans.Add(anses);
  279. result.sum.Add(0);
  280. result.status.Add(0);
  281. }
  282. //result.progress = info.progress;
  283. result.school = info.school;
  284. m++;
  285. await client.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync(result, new Azure.Cosmos.PartitionKey($"{result.code}"));
  286. }
  287. }
  288. }
  289. else
  290. {
  291. //处理单科结算时科目与试卷信息匹配的问题
  292. int gno = 0;
  293. foreach (ExamSubject subject in info.subjects)
  294. {
  295. if (subject.classCount == classes.Count)
  296. {
  297. await createClassResultAsync(info, examClassResults, subject, gno, _azureCosmos, _dingDing, _azureStorage);
  298. }
  299. gno++;
  300. }
  301. var isScore = examClassResults.SelectMany(e => e.studentScores).ToList().Exists(c => c.Contains(-1));
  302. int newStatus = 0;
  303. if (!isScore)
  304. {
  305. newStatus = 1;
  306. }
  307. Settlement settlement = await getMore(client, info, examClassResults);
  308. long nowTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  309. //判断评分状态是否发生变化,便于实时的更新评测基本信息
  310. if ((info.updateTime != nowTime && info.average != settlement.score) || info.sStatus != newStatus)
  311. {
  312. info.sRate = settlement.rate;
  313. info.sStatus = newStatus;
  314. info.updateTime = nowTime;
  315. info.average = settlement.score;
  316. await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync<ExamInfo>(info, info.id, new PartitionKey(info.code));
  317. }
  318. }
  319. }
  320. catch (Exception e)
  321. {
  322. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测going状态异常{e.Message}\n{e.StackTrace}", GroupNames.成都开发測試群組);
  323. }
  324. finally
  325. {
  326. // 发送信息通知
  327. var messageEnd = new ServiceBusMessage(new { id = data.id, progress = "finish", code = data.code }.ToJsonString());
  328. messageEnd.ApplicationProperties.Add("name", "Exam");
  329. if (records.Count > 0)
  330. {
  331. long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageEnd, DateTimeOffset.FromUnixTimeMilliseconds(data.endTime));
  332. await _serviceBus.GetServiceBusClient().cancelMessage(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), records[0].sequenceNumber);
  333. records[0].sequenceNumber = end;
  334. await table.SaveOrUpdate<ChangeRecord>(records[0]);
  335. //await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(record, record.id, new Azure.Cosmos.PartitionKey($"{record.code}"));
  336. }
  337. else
  338. {
  339. long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageEnd, DateTimeOffset.FromUnixTimeMilliseconds(data.endTime));
  340. //string pk = String.Format("{0}{1}{2}", info.code, "-", "going");
  341. ChangeRecord changeRecord = new ChangeRecord
  342. {
  343. RowKey = data.id,
  344. PartitionKey = PartitionKey,
  345. sequenceNumber = end,
  346. msgId = messageEnd.MessageId
  347. };
  348. await table.Save<ChangeRecord>(changeRecord);
  349. //await client.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync(changeRecord, new Azure.Cosmos.PartitionKey($"{changeRecord.code}"));
  350. }
  351. }
  352. break;
  353. case "finish":
  354. int fno = 0;
  355. try
  356. {
  357. //用来判定是否完成评分
  358. //bool isScore = true;
  359. var isScore = examClassResults.SelectMany(e => e.studentScores).ToList().Exists(c => c.Contains(-1));
  360. int newStatus = 0;
  361. if (!isScore)
  362. {
  363. newStatus = 1;
  364. }
  365. //处理活动中间件
  366. List<StuActivity> stus = new();
  367. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<StuActivity>(
  368. queryText: $"select c.id from c where c.id = '{info.id}'"))
  369. {
  370. stus.Add(item);
  371. }
  372. if (info.source.Equals("1") && stus.Count == 0)
  373. {
  374. await Activity(_coreAPIHttpService, info, classes, client, _dingDing, sub, examClassResults);
  375. }
  376. foreach (ExamSubject subject in info.subjects)
  377. {
  378. await createClassResultAsync(info, examClassResults, subject, fno, _azureCosmos, _dingDing, _azureStorage);
  379. fno++;
  380. }
  381. Settlement settlement = await getMore(client, info, examClassResults);
  382. //info.lostStu = losStu;
  383. /*//补充历史数据的容器名称
  384. if (string.IsNullOrEmpty(info.cn)) {
  385. if (info.scope.Equals("school"))
  386. {
  387. info.cn = info.school;
  388. }
  389. else {
  390. info.cn = info.creatorId;
  391. }
  392. }*/
  393. //判断均分是否发生变化,便于实时的更新评测基本信息
  394. if (info.sRate != settlement.rate || info.average != settlement.score || info.sStatus != newStatus)
  395. {
  396. info.sRate = settlement.rate;
  397. info.average = settlement.score;
  398. info.sStatus = newStatus;
  399. info.lostStu = settlement.stus;
  400. info.stuCount = settlement.total;
  401. await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync<ExamInfo>(info, info.id, new Azure.Cosmos.PartitionKey(info.code));
  402. }
  403. }
  404. catch (Exception e)
  405. {
  406. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测finish状态异常{e.Message}\n{e.StackTrace}", GroupNames.成都开发測試群組);
  407. }
  408. break;
  409. }
  410. }
  411. }
  412. catch (CosmosException e)
  413. {
  414. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-CosmosDB异常{e.StackTrace}{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
  415. }
  416. catch (Exception e)
  417. {
  418. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-评测结算异常{e.Message}\n{e.StackTrace}", GroupNames.成都开发測試群組);
  419. }
  420. }
  421. public static async Task<Settlement> getMore(CosmosClient client, ExamInfo info, List<ExamClassResult> examClassResults)
  422. {
  423. //计算单次考试简易统计信息
  424. Settlement settlement = new();
  425. List<ExamResult> examResults = new();
  426. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<ExamResult>(
  427. queryText: $"select value(c) from c where c.examId = '{info.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"ExamResult-{info.id}") }))
  428. {
  429. examResults.Add(item);
  430. }
  431. if (examResults.Count > 0)
  432. {
  433. List<Task<ItemResponse<ExamClassResult>>> tasks = new List<Task<ItemResponse<ExamClassResult>>>();
  434. //结算单科单班的标准差和平均分
  435. foreach (ExamClassResult classResult in examClassResults)
  436. {
  437. //标记单科单班总得分
  438. double subScore = 0;
  439. //标准差
  440. double sPowSum = 0;
  441. List<double> newSumScore = new List<double>();
  442. var scount = classResult.studentIds.Count;
  443. foreach (List<double> sc in classResult.studentScores)
  444. {
  445. List<double> newSc = new List<double>();
  446. foreach (double ssc in sc)
  447. {
  448. if (ssc == -1)
  449. {
  450. newSc.Add(0);
  451. }
  452. else
  453. {
  454. newSc.Add(ssc);
  455. }
  456. }
  457. double nc = newSc.Sum();
  458. newSumScore.Add(nc);
  459. subScore += nc;
  460. }
  461. double rateScore = scount > 0 ? Math.Round(subScore * 1.0 / scount, 2) : 0;
  462. foreach (double scs in newSumScore)
  463. {
  464. sPowSum += Math.Pow(scs - rateScore, 2);
  465. }
  466. classResult.standard = Math.Round(scount > 0 ? Math.Pow(sPowSum / scount, 0.5) : 0, 2);
  467. classResult.average = scount > 0 ? Math.Round(subScore / scount, 2) : 0;
  468. classResult.progress = true;
  469. tasks.Add(client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new Azure.Cosmos.PartitionKey($"{classResult.code}")));
  470. }
  471. await Task.WhenAll(tasks);
  472. //记录某次考试所有学生得分总分
  473. double score = 0;
  474. double allScore = 0;
  475. int stuCount = 0;
  476. //标准差
  477. double powSum = 0;
  478. List<string> losStu = new List<string>();
  479. //当前完成考试得人数
  480. int total = examResults[0].studentIds.Count;
  481. //先与第一个值取并集
  482. losStu = losStu.Union(examResults[0].lostStus).ToList();
  483. foreach (ExamResult examResult in examResults)
  484. {
  485. if (info.id == examResult.examId)
  486. {
  487. foreach (List<double> sc in examResult.studentScores)
  488. {
  489. score += sc.Sum();
  490. }
  491. stuCount = examResult.studentIds.Count;
  492. }
  493. //powSum += Math.Pow(score - examResult.studentIds.Count > 0 ? Math.Round(score * 1.0 / examResult.studentIds.Count, 2) : 0, 2);
  494. //取交集
  495. losStu = losStu.Intersect(examResult.lostStus).ToList();
  496. }
  497. double NewsRateScore = stuCount > 0 ? Math.Round(score * 1.0 / stuCount, 2) : 0;
  498. foreach (PaperSimple simple in info.papers)
  499. {
  500. allScore += simple.point.Sum();
  501. }
  502. //计算全科标准差
  503. foreach (string id in examResults[0].studentIds)
  504. {
  505. double sc = 0;
  506. foreach (ExamResult result in examResults)
  507. {
  508. sc += result.studentScores[result.studentIds.IndexOf(id)].Sum();
  509. }
  510. powSum += Math.Pow(sc - NewsRateScore, 2);
  511. }
  512. info.standard = Math.Round(total > 0 ? Math.Pow(powSum / total, 0.5) : 0, 2);
  513. double NewsRate = allScore > 0 ? Math.Round(NewsRateScore / allScore * 100, 2) : 0;
  514. settlement.rate = NewsRate;
  515. settlement.score = NewsRateScore;
  516. settlement.stus = losStu;
  517. settlement.total = total;
  518. }
  519. return settlement;
  520. }
  521. //处理全部学生选题计数
  522. public static async Task examRecordCount(ExamInfo info, ExamSubject subject, DingDing _dingDing, int no, ExamResult result, List<ExamClassResult> classResults, AzureCosmosFactory _azureCosmos)
  523. {
  524. try
  525. {
  526. List<double> scores = new List<double>();
  527. foreach (List<double> sc in result.studentScores)
  528. {
  529. scores.Add(sc.Sum());
  530. }
  531. //确定高分组 最低分数
  532. scores.Sort((s1, s2) => { return s2.CompareTo(s1); });
  533. double rhwCount = Math.Floor(scores.Count * 0.27);
  534. double rhw = rhwCount > 0 ? scores[int.Parse(rhwCount.ToString("0"))] : 0;
  535. //确定低分组 最高分数
  536. //scores.Sort((s1, s2) => { return s1.CompareTo(s2); });
  537. double rhlCount = Math.Ceiling(scores.Count * 0.73);
  538. double rhl = rhlCount > 0 ? scores[int.Parse(rhlCount.ToString("0")) - 1] : 0;
  539. //存放高分组学生ID
  540. List<string> phId = new List<string>();
  541. List<string> plId = new List<string>();
  542. List<List<List<string>>> opth = new List<List<List<string>>>();
  543. List<List<List<string>>> optl = new List<List<List<string>>>();
  544. await knowledgeCount(info, subject, _dingDing, no, classResults, rhwCount, rhw, rhlCount, rhl, _azureCosmos);
  545. await fieldCount(info, subject, _dingDing, no, classResults, rhwCount, rhw, rhlCount, rhl, _azureCosmos);
  546. int PHCount = 0;
  547. int PLCount = 0;
  548. foreach (ExamClassResult classResult in classResults)
  549. {
  550. if (classResult.subjectId.Equals(subject.id))
  551. {
  552. foreach (string id in classResult.studentIds)
  553. {
  554. int index = classResult.studentIds.IndexOf(id);
  555. if (classResult.studentScores.Count > 0)
  556. {
  557. if (classResult.studentScores[index].Sum() >= rhw && PHCount < rhwCount)
  558. {
  559. if (classResult.ans.Count > 0)
  560. {
  561. opth.Add(classResult.ans[index]);
  562. PHCount++;
  563. continue;
  564. }
  565. }
  566. if (classResult.studentScores[index].Sum() <= rhl && PLCount < (scores.Count - rhlCount))
  567. {
  568. if (classResult.ans.Count > 0)
  569. {
  570. optl.Add(classResult.ans[index]);
  571. PLCount++;
  572. continue;
  573. }
  574. }
  575. }
  576. }
  577. }
  578. }
  579. result.phc = getMore(info, no, opth);
  580. result.plc = getMore(info, no, optl);
  581. }
  582. catch (Exception ex)
  583. {
  584. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测作答记录结算异常{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  585. }
  586. }
  587. public static async Task<List<RGroupList>> Activity(CoreAPIHttpService _coreAPIHttpService, ExamInfo info, List<string> classes, CosmosClient client, DingDing _dingDing, List<string> sub, List<ExamClassResult> results)
  588. {
  589. List<(string pId, List<string> gid)> ps = new List<(string pId, List<string> gid)>();
  590. if (info.groupLists.Count > 0)
  591. {
  592. var group = info.groupLists;
  593. foreach (var gp in group)
  594. {
  595. foreach (KeyValuePair<string, List<string>> pp in gp)
  596. {
  597. ps.Add((pp.Key, pp.Value));
  598. }
  599. }
  600. }
  601. (List<RMember> tchList, List<RGroupList> classLists) = await GroupListService.GetStutmdidListids(_coreAPIHttpService, client, _dingDing, classes, info.school, ps);
  602. var addStudentsCls = tchList.FindAll(x => x.type == 2);
  603. var addTmdidsCls = tchList.FindAll(x => x.type == 1);
  604. List<StuActivity> stuActivities = new List<StuActivity>();
  605. List<StuActivity> tmdActivities = new List<StuActivity>();
  606. if (addTmdidsCls.IsNotEmpty())
  607. {
  608. addTmdidsCls.ForEach(x =>
  609. {
  610. HashSet<string> classIds = new HashSet<string>();
  611. classLists.ForEach(z =>
  612. {
  613. z.members.ForEach(y =>
  614. {
  615. if (y.id.Equals(x.id) && y.type == 1)
  616. {
  617. classIds.Add(z.id);
  618. }
  619. });
  620. });
  621. bool iss = false;
  622. //标记学生作答状态
  623. int ts = 0;
  624. if (results.Count > 0)
  625. {
  626. foreach (ExamClassResult exam in results)
  627. {
  628. int index = exam.studentIds.IndexOf(x.id);
  629. if (index != -1)
  630. {
  631. if (exam.studentAnswers[index].Count > 0)
  632. {
  633. bool flag = exam.studentScores[index].Exists(x => x == -1);
  634. if (!flag)
  635. {
  636. ts = 1;
  637. iss = true;
  638. break;
  639. }
  640. else
  641. {
  642. ts = 0;
  643. }
  644. }
  645. else {
  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. }