TriggerExam.cs 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229
  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. for (int i =0; i < classResult.studentScores[index].Count; i++) {
  460. classResult.studentScores[index][i] = 0;
  461. }
  462. }
  463. index++;
  464. }
  465. foreach (List<double> sc in classResult.studentScores)
  466. {
  467. List<double> newSc = new List<double>();
  468. foreach (double ssc in sc)
  469. {
  470. if (ssc == -1)
  471. {
  472. newSc.Add(0);
  473. }
  474. else
  475. {
  476. newSc.Add(ssc);
  477. }
  478. }
  479. double nc = newSc.Sum();
  480. newSumScore.Add(nc);
  481. subScore += nc;
  482. }
  483. double rateScore = scount > 0 ? Math.Round(subScore * 1.0 / scount, 2) : 0;
  484. foreach (double scs in newSumScore)
  485. {
  486. sPowSum += Math.Pow(scs - rateScore, 2);
  487. }
  488. classResult.standard = Math.Round(scount > 0 ? Math.Pow(sPowSum / scount, 0.5) : 0, 2);
  489. classResult.average = scount > 0 ? Math.Round(subScore / scount, 2) : 0;
  490. classResult.progress = true;
  491. tasks.Add(client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new PartitionKey($"{classResult.code}")));
  492. }
  493. await Task.WhenAll(tasks);
  494. //记录某次考试所有学生得分总分
  495. double score = 0;
  496. double allScore = 0;
  497. int stuCount = 0;
  498. //标准差
  499. double powSum = 0;
  500. List<string> losStu = new List<string>();
  501. //当前完成考试得人数
  502. int total = examResults[0].studentIds.Count;
  503. //先与第一个值取并集
  504. losStu = losStu.Union(examResults[0].lostStus).ToList();
  505. foreach (ExamResult examResult in examResults)
  506. {
  507. if (info.id == examResult.examId)
  508. {
  509. foreach (List<double> sc in examResult.studentScores)
  510. {
  511. score += sc.Sum();
  512. }
  513. stuCount = examResult.studentIds.Count;
  514. }
  515. //powSum += Math.Pow(score - examResult.studentIds.Count > 0 ? Math.Round(score * 1.0 / examResult.studentIds.Count, 2) : 0, 2);
  516. //取交集
  517. losStu = losStu.Intersect(examResult.lostStus).ToList();
  518. }
  519. double NewsRateScore = stuCount > 0 ? Math.Round(score * 1.0 / stuCount, 2) : 0;
  520. foreach (PaperSimple simple in info.papers)
  521. {
  522. allScore += simple.point.Sum();
  523. }
  524. //计算全科标准差
  525. foreach (string id in examResults[0].studentIds)
  526. {
  527. double sc = 0;
  528. foreach (ExamResult result in examResults)
  529. {
  530. sc += result.studentScores[result.studentIds.IndexOf(id)].Sum();
  531. }
  532. powSum += Math.Pow(sc - NewsRateScore, 2);
  533. }
  534. info.standard = Math.Round(total > 0 ? Math.Pow(powSum / total, 0.5) : 0, 2);
  535. double NewsRate = allScore > 0 ? Math.Round(NewsRateScore / allScore * 100, 2) : 0;
  536. settlement.rate = NewsRate;
  537. settlement.score = NewsRateScore;
  538. settlement.stus = losStu;
  539. settlement.total = total;
  540. }
  541. return settlement;
  542. }
  543. //处理全部学生选题计数
  544. public static async Task examRecordCount(ExamInfo info, ExamSubject subject, DingDing _dingDing, int no, ExamResult result, List<ExamClassResult> classResults, AzureCosmosFactory _azureCosmos)
  545. {
  546. try
  547. {
  548. List<double> scores = new List<double>();
  549. foreach (List<double> sc in result.studentScores)
  550. {
  551. scores.Add(sc.Sum());
  552. }
  553. //确定高分组 最低分数
  554. scores.Sort((s1, s2) => { return s2.CompareTo(s1); });
  555. double rhwCount = Math.Floor(scores.Count * 0.27);
  556. double rhw = rhwCount > 0 ? scores[int.Parse(rhwCount.ToString("0"))] : 0;
  557. //确定低分组 最高分数
  558. //scores.Sort((s1, s2) => { return s1.CompareTo(s2); });
  559. double rhlCount = Math.Ceiling(scores.Count * 0.73);
  560. double rhl = rhlCount > 0 ? scores[int.Parse(rhlCount.ToString("0")) - 1] : 0;
  561. //存放高分组学生ID
  562. List<string> phId = new List<string>();
  563. List<string> plId = new List<string>();
  564. List<List<List<string>>> opth = new List<List<List<string>>>();
  565. List<List<List<string>>> optl = new List<List<List<string>>>();
  566. await knowledgeCount(info, subject, _dingDing, no, classResults, rhwCount, rhw, rhlCount, rhl, _azureCosmos);
  567. await fieldCount(info, subject, _dingDing, no, classResults, rhwCount, rhw, rhlCount, rhl, _azureCosmos);
  568. int PHCount = 0;
  569. int PLCount = 0;
  570. foreach (ExamClassResult classResult in classResults)
  571. {
  572. if (classResult.subjectId.Equals(subject.id))
  573. {
  574. foreach (string id in classResult.studentIds)
  575. {
  576. int index = classResult.studentIds.IndexOf(id);
  577. if (classResult.studentScores.Count > 0)
  578. {
  579. if (classResult.studentScores[index].Sum() >= rhw && PHCount < rhwCount)
  580. {
  581. if (classResult.ans.Count > 0)
  582. {
  583. opth.Add(classResult.ans[index]);
  584. PHCount++;
  585. continue;
  586. }
  587. }
  588. if (classResult.studentScores[index].Sum() <= rhl && PLCount < (scores.Count - rhlCount))
  589. {
  590. if (classResult.ans.Count > 0)
  591. {
  592. optl.Add(classResult.ans[index]);
  593. PLCount++;
  594. continue;
  595. }
  596. }
  597. }
  598. }
  599. }
  600. }
  601. result.phc = getMore(info, no, opth);
  602. result.plc = getMore(info, no, optl);
  603. }
  604. catch (Exception ex)
  605. {
  606. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测作答记录结算异常{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  607. }
  608. }
  609. public static async Task<List<RGroupList>> Activity(CoreAPIHttpService _coreAPIHttpService, ExamInfo info, List<string> classes, CosmosClient client, DingDing _dingDing, List<string> sub, List<ExamClassResult> results)
  610. {
  611. List<(string pId, List<string> gid)> ps = new List<(string pId, List<string> gid)>();
  612. if (info.groupLists.Count > 0)
  613. {
  614. var group = info.groupLists;
  615. foreach (var gp in group)
  616. {
  617. foreach (KeyValuePair<string, List<string>> pp in gp)
  618. {
  619. ps.Add((pp.Key, pp.Value));
  620. }
  621. }
  622. }
  623. (List<RMember> tchList, List<RGroupList> classLists) = await GroupListService.GetStutmdidListids(_coreAPIHttpService, client, _dingDing, classes, info.school, ps);
  624. var addStudentsCls = tchList.FindAll(x => x.type == 2);
  625. var addTmdidsCls = tchList.FindAll(x => x.type == 1);
  626. List<StuActivity> stuActivities = new List<StuActivity>();
  627. List<StuActivity> tmdActivities = new List<StuActivity>();
  628. if (addTmdidsCls.IsNotEmpty())
  629. {
  630. addTmdidsCls.ForEach(x =>
  631. {
  632. HashSet<string> classIds = new HashSet<string>();
  633. classLists.ForEach(z =>
  634. {
  635. z.members.ForEach(y =>
  636. {
  637. if (y.id.Equals(x.id) && y.type == 1)
  638. {
  639. classIds.Add(z.id);
  640. }
  641. });
  642. });
  643. bool iss = false;
  644. //标记学生作答状态
  645. int ts = 0;
  646. if (results.Count > 0)
  647. {
  648. foreach (ExamClassResult exam in results)
  649. {
  650. int index = exam.studentIds.IndexOf(x.id);
  651. if (index != -1)
  652. {
  653. if (exam.studentAnswers[index].Count > 0)
  654. {
  655. bool flag = exam.studentScores[index].Exists(x => x == -1);
  656. if (!flag)
  657. {
  658. ts = 1;
  659. iss = true;
  660. break;
  661. }
  662. else
  663. {
  664. ts = 0;
  665. }
  666. }
  667. else
  668. {
  669. ts = -1;
  670. }
  671. }
  672. }
  673. }
  674. else
  675. {
  676. ts = -1;
  677. }
  678. tmdActivities.Add(new StuActivity
  679. {
  680. pk = "Activity",
  681. id = info.id,
  682. code = $"Activity-{x.id}",
  683. type = "Exam",
  684. name = info.name,
  685. source = info.source,
  686. startTime = info.startTime,
  687. endTime = info.endTime,
  688. scode = info.code,
  689. scope = info.scope,
  690. school = info.school,
  691. creatorId = info.creatorId,
  692. subjects = sub,
  693. blob = null,
  694. owner = info.owner,
  695. createTime = info.createTime,
  696. taskStatus = ts,
  697. ext = new Dictionary<string, JsonElement>() { { "type", info.type.ToJsonString().ToObject<JsonElement>() }, { "subjects", info.subjects.ToJsonString().ToObject<JsonElement>() } },
  698. sStatus = iss ? 1 : 0,
  699. classIds = classIds.ToList()
  700. }); ;
  701. });
  702. }
  703. if (addStudentsCls.IsNotEmpty())
  704. {
  705. addStudentsCls.ForEach(x =>
  706. {
  707. HashSet<string> classIds = new HashSet<string>();
  708. classLists.ForEach(z =>
  709. {
  710. z.members.ForEach(y =>
  711. {
  712. if (y.id.Equals(x.id) && y.code.Equals(info.school) && y.type == 2)
  713. {
  714. classIds.Add(z.id);
  715. }
  716. });
  717. });
  718. bool iss = false;
  719. //标记学生作答状态
  720. int ts = 0;
  721. if (results.Count > 0)
  722. {
  723. foreach (ExamClassResult exam in results)
  724. {
  725. int index = exam.studentIds.IndexOf(x.id);
  726. if (index != -1)
  727. {
  728. if (exam.studentAnswers[index].Count > 0)
  729. {
  730. bool flag = exam.studentScores[index].Exists(x => x == -1);
  731. if (!flag)
  732. {
  733. ts = 1;
  734. iss = true;
  735. break;
  736. }
  737. else
  738. {
  739. ts = 0;
  740. }
  741. }
  742. else
  743. {
  744. ts = -1;
  745. }
  746. }
  747. }
  748. }
  749. else
  750. {
  751. ts = -1;
  752. }
  753. stuActivities.Add(new StuActivity
  754. {
  755. pk = "Activity",
  756. id = info.id,
  757. code = $"Activity-{x.code.Replace("Base-", "")}-{x.id}",
  758. type = "Exam",
  759. name = info.name,
  760. source = info.source,
  761. startTime = info.startTime,
  762. endTime = info.endTime,
  763. scode = info.code,
  764. scope = info.scope,
  765. school = info.school,
  766. creatorId = info.creatorId,
  767. subjects = sub,
  768. blob = null,
  769. owner = info.owner,
  770. classIds = classIds.ToList(),
  771. createTime = info.createTime,
  772. ext = new Dictionary<string, JsonElement>() { { "type", info.type.ToJsonString().ToObject<JsonElement>() },
  773. { "subjects", info.subjects.ToJsonString().ToObject<JsonElement>() } },
  774. taskStatus = ts,
  775. sStatus = iss ? 1 : 0,
  776. });
  777. });
  778. }
  779. await ActivityService.SaveStuActivity(client, _dingDing, stuActivities, tmdActivities, null);
  780. return classLists;
  781. }
  782. public static async Task knowledgeCount(ExamInfo info, ExamSubject subject, DingDing _dingDing, int no, List<ExamClassResult> classResults,
  783. double rhwCount, double rhw, double rhlCount, double rhl, AzureCosmosFactory _azureCosmos)
  784. {
  785. try
  786. {
  787. int phcount = 0;
  788. int plcount = 0;
  789. //存放并去重知识点
  790. HashSet<string> kname = new HashSet<string>();
  791. if (info.papers[no].knowledge.Count > 0)
  792. {
  793. info.papers[no].knowledge.ForEach(kno =>
  794. {
  795. kno.ForEach(k =>
  796. {
  797. kname.Add(k);
  798. });
  799. });
  800. List<string> knowledgeName = new List<string>();
  801. foreach (string cla in kname)
  802. {
  803. knowledgeName.Add(cla);
  804. }
  805. for (int k = 0; k < knowledgeName.Count; k++)
  806. {
  807. if (null == knowledgeName[k])
  808. {
  809. knowledgeName.Remove(knowledgeName[k]);
  810. }
  811. }
  812. foreach (ExamClassResult classResult in classResults)
  813. {
  814. if (classResult.subjectId.Equals(subject.id))
  815. {
  816. //List<int> phc = new List<int>();
  817. List<int> ph = new List<int>();
  818. List<int> pl = new List<int>();
  819. List<int> pc = new List<int>();
  820. List<double> persent = new List<double>();
  821. for (int i = 0; i < knowledgeName.Count; i++)
  822. {
  823. //初始化单个知识点得分
  824. double score = 0;
  825. double allScore = 0;
  826. int n = 0;
  827. int phCount = 0;
  828. int plCount = 0;
  829. int pCount = 0;
  830. foreach (List<string> str in info.papers[no].knowledge)
  831. {
  832. if (str.Contains(knowledgeName[i]))
  833. {
  834. var itemPersent = str.Count > 0 ? 1 / Convert.ToDouble(str.Count) : 0;
  835. allScore += info.papers[no].point.Count > 0 ? info.papers[no].point[n] * itemPersent : 0;
  836. foreach (string id in classResult.studentIds)
  837. {
  838. int index = classResult.studentIds.IndexOf(id);
  839. if (classResult.studentScores.Count > 0)
  840. {
  841. if (classResult.studentScores[index].Count > 0)
  842. {
  843. score += classResult.studentScores[index][n] == -1 ? 0 : classResult.studentScores[index][n];
  844. if (classResult.studentScores[index].Sum() >= rhw && phcount < rhwCount)
  845. {
  846. if (classResult.studentScores[index][n] <= 0)
  847. {
  848. phCount++;
  849. }
  850. phcount++;
  851. continue;
  852. }
  853. if (classResult.studentScores[index].Sum() <= rhl && plcount < (info.stuCount - rhlCount))
  854. {
  855. if (classResult.studentScores[index][n] <= 0)
  856. {
  857. plCount++;
  858. }
  859. plcount++;
  860. continue;
  861. }
  862. if (classResult.studentScores[index][n] <= 0)
  863. {
  864. pCount++;
  865. }
  866. }
  867. }
  868. }
  869. }
  870. n++;
  871. }
  872. pc.Add(pCount);
  873. ph.Add(phCount);
  874. pl.Add(plCount);
  875. double per = classResult.studentIds.Count > 0 ? Math.Round(score / classResult.studentIds.Count, 2) : 0;
  876. persent.Add(allScore > 0 ? per / allScore : 0);
  877. }
  878. classResult.phc = ph;
  879. classResult.plc = pl;
  880. classResult.pc = pc;
  881. classResult.krate = persent;
  882. }
  883. //await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new Azure.Cosmos.PartitionKey($"{classResult.code}"));
  884. }
  885. }
  886. }
  887. catch (Exception ex)
  888. {
  889. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测知识点结算异常{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  890. }
  891. }
  892. public static async Task fieldCount(ExamInfo info, ExamSubject subject, DingDing _dingDing, int no, List<ExamClassResult> classResults,
  893. double rhwCount, double rhw, double rhlCount, double rhl, AzureCosmosFactory _azureCosmos)
  894. {
  895. try
  896. {
  897. int phcount = 0;
  898. int plcount = 0;
  899. //存放并去重知识点
  900. List<int> knowledgeName = new List<int>() { 1, 2, 3, 4, 5, 6 };
  901. /* knowledgeName.Add(1);
  902. knowledgeName.Add(2);
  903. knowledgeName.Add(3);
  904. knowledgeName.Add(4);
  905. knowledgeName.Add(5);
  906. knowledgeName.Add(6);*/
  907. foreach (ExamClassResult classResult in classResults)
  908. {
  909. if (classResult.subjectId.Equals(subject.id))
  910. {
  911. //List<int> phc = new List<int>();
  912. List<int> ph = new List<int>();
  913. List<int> pl = new List<int>();
  914. List<int> pc = new List<int>();
  915. List<double> persent = new List<double>();
  916. for (int i = 0; i < knowledgeName.Count; i++)
  917. {
  918. //初始化单个知识点得分
  919. double score = 0;
  920. double allScore = 0;
  921. int n = 0;
  922. int phCount = 0;
  923. int plCount = 0;
  924. int pCount = 0;
  925. if (info.papers[no].field.Count > 0)
  926. {
  927. foreach (int str in info.papers[no].field)
  928. {
  929. if (str == knowledgeName[i])
  930. {
  931. var itemPersent = 1;
  932. allScore += info.papers[no].point.Count > 0 ? info.papers[no].point[n] * itemPersent : 0;
  933. foreach (string id in classResult.studentIds)
  934. {
  935. int index = classResult.studentIds.IndexOf(id);
  936. if (classResult.studentScores.Count > 0)
  937. {
  938. if (classResult.studentScores[index].Count > 0)
  939. {
  940. score += classResult.studentScores[index][n] == -1 ? 0 : classResult.studentScores[index][n];
  941. if (classResult.studentScores[index].Sum() >= rhw && phcount < rhwCount)
  942. {
  943. if (classResult.studentScores[index][n] <= 0)
  944. {
  945. phCount++;
  946. }
  947. phcount++;
  948. continue;
  949. }
  950. if (classResult.studentScores[index].Sum() <= rhl && plcount < (info.stuCount - rhlCount))
  951. {
  952. if (classResult.studentScores[index][n] <= 0)
  953. {
  954. plCount++;
  955. }
  956. plcount++;
  957. continue;
  958. }
  959. if (classResult.studentScores[index][n] <= 0)
  960. {
  961. pCount++;
  962. }
  963. }
  964. }
  965. }
  966. }
  967. n++;
  968. }
  969. pc.Add(pCount);
  970. ph.Add(phCount);
  971. pl.Add(plCount);
  972. double per = classResult.studentIds.Count > 0 ? Math.Round(score / classResult.studentIds.Count, 2) : 0;
  973. persent.Add(allScore > 0 ? per / allScore : 0);
  974. }
  975. }
  976. classResult.fphc = ph;
  977. classResult.fplc = pl;
  978. classResult.fpc = pc;
  979. classResult.frate = persent;
  980. }
  981. //await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new Azure.Cosmos.PartitionKey($"{classResult.code}"));
  982. }
  983. }
  984. catch (Exception ex)
  985. {
  986. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测认知层次结算异常{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  987. }
  988. }
  989. //处理选题计数
  990. public static List<Dictionary<string, int>> getMore(ExamInfo info, int no, List<List<List<string>>> list)
  991. {
  992. List<Dictionary<string, int>> recorde = new List<Dictionary<string, int>>();
  993. try
  994. {
  995. for (int i = 0; i < info.papers[no].answers.Count; i++)
  996. {
  997. if (info.papers[no].answers[i].Count <= 0)
  998. {
  999. recorde.Add(new Dictionary<string, int>());
  1000. continue;
  1001. }
  1002. Dictionary<string, int> optCount = new Dictionary<string, int>();
  1003. foreach (List<List<string>> stu in list)
  1004. {
  1005. if (stu.Count == info.papers[no].answers.Count)
  1006. {
  1007. var item = stu[i];
  1008. foreach (string opt in item)
  1009. {
  1010. if (optCount.ContainsKey(opt))
  1011. {
  1012. optCount[opt] = optCount[opt] + 1;
  1013. }
  1014. else
  1015. {
  1016. optCount[opt] = 1;
  1017. }
  1018. }
  1019. }
  1020. }
  1021. recorde.Add(optCount);
  1022. }
  1023. return recorde;
  1024. }
  1025. catch (Exception)
  1026. {
  1027. return recorde;
  1028. }
  1029. }
  1030. public static async Task createClassResultAsync(ExamInfo info, List<ExamClassResult> examClassResults, ExamSubject subject, int no, AzureCosmosFactory _azureCosmos, DingDing _dingDing, AzureStorageFactory _azureStorage)
  1031. {
  1032. //保证试卷信息与科目信息同步
  1033. ExamResult result = new ExamResult();
  1034. //人数总和
  1035. int Count = 0;
  1036. int m = 0;
  1037. double score = 0;
  1038. //标准差
  1039. double powSum = 0;
  1040. double allScore = info.papers[no].point.Sum();
  1041. List<ClassRange> classRanges = new List<ClassRange>();
  1042. List<string> lostStu = new List<string>();
  1043. List<double> csRate = new List<double>();
  1044. List<List<List<string>>> opt = new List<List<List<string>>>();
  1045. foreach (ExamClassResult classResult in examClassResults)
  1046. {
  1047. double classSrate = 0;
  1048. if (classResult.subjectId.Equals(subject.id))
  1049. {
  1050. foreach (List<List<string>> op in classResult.ans)
  1051. {
  1052. opt.Add(op);
  1053. }
  1054. //记录缺考学生索引位置
  1055. int index_stu = 0;
  1056. foreach (var ans in classResult.studentAnswers)
  1057. {
  1058. if (ans.Count == 0)
  1059. {
  1060. if (!lostStu.Contains(classResult.studentIds[index_stu]))
  1061. {
  1062. lostStu.Add(classResult.studentIds[index_stu]);
  1063. }
  1064. }
  1065. index_stu++;
  1066. }
  1067. int index = 0;
  1068. foreach (List<double> scores in classResult.studentScores)
  1069. {
  1070. List<double> newScores = new List<double>();
  1071. //int count = 0;
  1072. foreach (double sc in scores)
  1073. {
  1074. newScores.Add(sc > -1 ? sc : 0);
  1075. /*if (sc == -1)
  1076. {
  1077. count++;
  1078. }*/
  1079. }
  1080. /*if (count == scores.Count)
  1081. {
  1082. if (!lostStu.Contains(classResult.studentIds[index]))
  1083. {
  1084. lostStu.Add(classResult.studentIds[index]);
  1085. }
  1086. //mcount++;
  1087. }*/
  1088. classSrate += newScores.Sum();
  1089. score += newScores.Sum();
  1090. result.studentScores.Add(newScores);
  1091. index++;
  1092. }
  1093. //处理班级信息
  1094. ClassRange range = new ClassRange();
  1095. range.id = classResult.info.id;
  1096. range.name = classResult.info.name;
  1097. range.gradeId = classResult.gradeId;
  1098. List<int> ran = new List<int>();
  1099. int stuCount = classResult.studentIds.Count;
  1100. Count += stuCount;
  1101. if (m == 0)
  1102. {
  1103. ran.Add(0);
  1104. ran.Add(stuCount - 1);
  1105. }
  1106. else
  1107. {
  1108. ran.Add(Count - stuCount);
  1109. ran.Add(Count - 1);
  1110. }
  1111. m++;
  1112. range.range = ran;
  1113. classRanges.Add(range);
  1114. //处理学生ID
  1115. foreach (string id in classResult.studentIds)
  1116. {
  1117. result.studentIds.Add(id);
  1118. }
  1119. if (allScore > 0)
  1120. {
  1121. csRate.Add(classResult.studentIds.Count > 0 ? Math.Round(classSrate * 1.0 / classResult.studentIds.Count, 2) : 0 / allScore);
  1122. }
  1123. else
  1124. {
  1125. csRate.Add(0);
  1126. }
  1127. //powSum += Math.Pow(classSrate - result.average, 2);
  1128. //处理选项计数内容
  1129. }
  1130. }
  1131. /*foreach (string id in result.lostStus) {
  1132. if (!examClassResults[0].studentIds.Contains(id)) {
  1133. int index = result.lostStus.IndexOf(id);
  1134. result.lostStus.RemoveAt(index);
  1135. }
  1136. }*/
  1137. //处理人员变更时被移除的人员
  1138. if (result.lostStus.Count > 0)
  1139. {
  1140. for (int i = 0; i < result.lostStus.Count; i++)
  1141. {
  1142. if (!examClassResults[0].studentIds.Contains(result.lostStus[i]))
  1143. {
  1144. result.lostStus.RemoveAt(i);
  1145. }
  1146. }
  1147. }
  1148. await examRecordCount(info, subject, _dingDing, no, result, examClassResults, _azureCosmos);
  1149. result.record = getMore(info, no, opt);
  1150. result.average = result.studentIds.Count > 0 ? Math.Round(score * 1.0 / result.studentIds.Count, 2) : 0;
  1151. double stand = 0;
  1152. int sco = 0;
  1153. foreach (ExamClassResult classResult in examClassResults)
  1154. {
  1155. //double classSrate = 0;
  1156. if (classResult.subjectId.Equals(subject.id))
  1157. {
  1158. stand += classResult.standard;
  1159. sco++;
  1160. }
  1161. }
  1162. result.standard = sco > 0 ? Math.Round(stand / sco, 2) : 0;
  1163. result.csRate = csRate;
  1164. result.lostStus = lostStu;
  1165. result.sRate = allScore > 0 ? Math.Round(result.average / allScore * 100, 2) : 0;
  1166. result.classes = classRanges;
  1167. result.code = "ExamResult-" + info.id;
  1168. result.school = info.school;
  1169. result.id = subject.id;
  1170. result.examId = info.id;
  1171. result.subjectId = subject.id;
  1172. result.year = info.year;
  1173. result.paper = info.papers[no];
  1174. //result.point = info.papers[j].point;
  1175. result.scope = info.scope;
  1176. result.name = info.name;
  1177. result.time = info.startTime;
  1178. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").UpsertItemAsync(result, new Azure.Cosmos.PartitionKey($"ExamResult-{info.id}"));
  1179. }
  1180. public class Settlement
  1181. {
  1182. public double rate { get; set; }
  1183. public double score { get; set; }
  1184. public List<string> stus { get; set; } = new List<string>();
  1185. public int total { get; set; }
  1186. }
  1187. }
  1188. }