TriggerExam.cs 68 KB

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