TriggerExam.cs 68 KB

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