TriggerExam.cs 68 KB

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