AchievementController.cs 95 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103
  1. using ClouDASLibx;
  2. using Microsoft.AspNetCore.Mvc;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Threading.Tasks;
  7. using TEAMModelOS.SDK;
  8. using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
  9. using TEAMModelOS.SDK.Helper.Common.StringHelper;
  10. using TEAMModelOS.SDK.DI;
  11. using System.Diagnostics;
  12. using TEAMModelOS.SDK.Helper.Common.JsonHelper;
  13. using TEAMModelOS.SDK.Helper.Security.ShaHash;
  14. using TEAMModelOS.SDK.Context.Exception;
  15. using TEAMModelOS.Service.Models;
  16. using TEAMModelOS.SDK.Helper.Network.HttpHelper;
  17. using TEAMModelOS.Service.Analysis.Implements;
  18. using OpenXmlPowerTools;
  19. using System.Text.Json;
  20. namespace TEAMModelOS.Controllers.Analysis
  21. {
  22. [Route("api/[controller]")]
  23. [ApiController]
  24. public class AchievementController : Controller
  25. {
  26. private readonly AzureCosmosFactory azureCosmosDBRepository;
  27. private const string CacheCosmosPrefix = "Analysis:";
  28. private const int timeoutSeconds = 3600;
  29. public AchievementController( AzureCosmosFactory _azureCosmosDBRepository)
  30. {
  31. azureCosmosDBRepository = _azureCosmosDBRepository;
  32. }
  33. [HttpPost("Achievement")]
  34. public async Task<BaseResponse> FindExam(JsonElement request)
  35. {
  36. ResponseBuilder builder = ResponseBuilder.custom();
  37. Dictionary<string, object> dict = new Dictionary<string, object>();
  38. var emobj = request.EnumerateObject();
  39. while (emobj.MoveNext())
  40. {
  41. dict[emobj.Current.Name] = emobj.Current.Value;
  42. }
  43. Dictionary<string, dynamic> info = new Dictionary<string, dynamic>();
  44. if (RedisHelper.Instance != null)
  45. {
  46. info = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "Achievement",
  47. ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), timeoutSeconds, () => { return FindExamRedis(dict, "Achievement"); });
  48. //数据从redis读取过后进行转换格式
  49. builder.Data(JsonApiHelper.FromApiJson<System.Text.Json.JsonElement>(info.ToJson()));
  50. }
  51. else
  52. {
  53. info = await FindExamRedis(dict, "Achievement");
  54. builder.Data(JsonApiHelper.FromApiJson<System.Text.Json.JsonElement>(info.ToJson()));
  55. }
  56. return builder.build();
  57. }
  58. public async Task<List<ExamResult>> FindExamResultRedis(Dictionary<string, object> dict, string method)
  59. {
  60. try
  61. {
  62. List<ExamResult> info = await azureCosmosDBRepository.FindByDict<ExamResult>(dict);
  63. if (RedisHelper.Instance != null)
  64. {
  65. if (!RedisHelper.Exists(CacheCosmosPrefix + method))
  66. {
  67. await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), info);
  68. }
  69. else
  70. {
  71. await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), info);
  72. await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
  73. }
  74. }
  75. return info;
  76. }
  77. catch (Exception e)
  78. {
  79. throw new BizException(e.Message);
  80. }
  81. }
  82. public async Task<Dictionary<string, dynamic>> FindExamRedis(Dictionary<string, object> dict, string method) {
  83. ResponseBuilder builder = ResponseBuilder.custom();
  84. //Console.WriteLine(DateTimeOffset.Now.Second);
  85. //
  86. dict.TryGetValue("subjectCode", out object subjectCode);
  87. dict.TryGetValue("code", out object code);
  88. List<ExamResult> exams = new List<ExamResult>();
  89. /*if (RedisHelper.Instance != null)
  90. {
  91. exams = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "FindExamResultRedis",
  92. ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), timeoutSeconds, () => { return FindExamResultRedis(dict, "FindExamResultRedis"); });
  93. }
  94. else
  95. {
  96. exams = await FindExamResultRedis(dict, "FindExamResultRedis");
  97. }*/
  98. List<string> subjectCouns = JsonApiHelper.FromApiJson<List<string>>(subjectCode.ToApiJson());
  99. for (int i =0;i < subjectCouns.Count;i++ ) {
  100. if (RedisHelper.Exists(CacheCosmosPrefix + "examResult" + subjectCouns[i]))
  101. {
  102. ExamResult result = RedisHelper.HGet<ExamResult>(CacheCosmosPrefix + "examResult" + subjectCouns[i], ShaHashHelper.GetSHA1(code.ToString()));
  103. //builder.Data(info);
  104. exams.Add(result);
  105. }
  106. }
  107. Dictionary<string, object> stuMap = new Dictionary<string, object>
  108. {
  109. { "schoolCode", "Habook" }
  110. };
  111. //声明进行标准用来设置进线标准,权重等参数
  112. dict.TryGetValue("Standard", out object Standard);
  113. List<Student> students = await azureCosmosDBRepository.FindByDict<Student>(stuMap);
  114. //Console.WriteLine(DateTimeOffset.Now.Second);
  115. List<Dictionary<string, object>> examList = new List<Dictionary<string, object>>();
  116. HashSet<string> classList = new HashSet<string>();
  117. HashSet<string> classId = new HashSet<string>();
  118. List<string> subjectAverage = new List<string>();
  119. List<List<string>> subjectPoints = new List<List<string>>();
  120. Dictionary<string, object> Average = new Dictionary<string, object>();
  121. Dictionary<string, object> entryTable = new Dictionary<string, object>();
  122. Dictionary<string, dynamic> achievementAnalysis = new Dictionary<string, dynamic>();
  123. List<string> arrSubject = new List<string>();
  124. List<string> keys = new List<string>();
  125. List<string> person = new List<string>();
  126. List<List<double>> subSum = new List<List<double>>();
  127. List<string> gAverage = new List<string>();
  128. List<string> cAverage = new List<string>();
  129. Dictionary<string, object> AclassAverage = new Dictionary<string, object>();
  130. Dictionary<string, object> passRateMap = new Dictionary<string, object>();
  131. List<List<string>> passALL = new List<List<string>>();
  132. List<string> gradeList = new List<string>();
  133. List<string> areaList = new List<string>();
  134. List<string> sbujectsList = new List<string>();
  135. if (exams.IsNotEmpty())
  136. {
  137. //存放进线情况统计key值
  138. keys.Add("name");
  139. keys.Add("className");
  140. keys.Add("gradeRank");
  141. keys.Add("score");
  142. //初始化进行人数
  143. double iPersons = 0;
  144. if (exams.IsNotEmpty())
  145. {
  146. int classLen = exams[0].classes.Count;
  147. for (int cls = 0; cls < classLen; cls++)
  148. {
  149. if (exams[0].classes[cls].TryGetValue(exams[0].classes[cls].Keys.ToArray<string>()[0], out int[] index))
  150. {
  151. List<double> stuScore = new List<double>();
  152. int stdLen = index[1] - index[0] + 1;
  153. for (int i = 0; i < stdLen; i++)
  154. {
  155. stuScore.Add(0);
  156. }
  157. subSum.Add(stuScore);
  158. }
  159. }
  160. }
  161. int xx = 0;
  162. //初始化总分
  163. double sumPoint = 0;
  164. int sumperson = exams[0].ids.Count;
  165. for (int i = 0; i < exams[0].ids.Count; i++)
  166. {
  167. if (exams[0].ids[i].Equals("0"))
  168. {
  169. sumperson--;
  170. }
  171. }
  172. exams.ForEach(e =>
  173. {
  174. //获取总分数
  175. e.result.ForEach(r =>
  176. {
  177. sumPoint += r.Sum();
  178. });
  179. });
  180. var gradeAverage = sumPoint / sumperson;
  181. //存放年级平均
  182. gAverage.Add(gradeAverage.ToString());
  183. //任意一次考试数据提取班级信息
  184. List<Dictionary<string, int[]>> classToName = exams[0].classes;
  185. //任意一次考试数据提取学生ID信息
  186. List<string> idToName = exams[0].ids;
  187. //var gradeAverage = Math.Floor(Math.Round(decimal.Parse((10 / 3).ToString("0.000")), 2));
  188. List<string> subjects = new List<string>();
  189. exams.ForEach(e =>
  190. {
  191. int peopleCount = 0;
  192. Dictionary<string, object> detail = new Dictionary<string, object>
  193. {
  194. { "name", e.subjectCode }
  195. };
  196. subjects.Add(e.subjectCode);
  197. List<string> ClassAverage = new List<string>();
  198. //计算试卷总分
  199. double sum = e.point.Sum();
  200. //及格分数
  201. double passRate = sum * 0.6;
  202. int gradeCount = 0;
  203. //初始化科目总分
  204. double subjectPoint = 0;
  205. //科目平均分
  206. double subAverage = 0;
  207. //计算班级平均分
  208. int classIndex = 0;
  209. List<string> passList = new List<string>();
  210. e.classes.ForEach(c =>
  211. {
  212. List<List<string>> classPRL = new List<List<string>>();
  213. //初始化班级总分
  214. double classPoint = 0;
  215. //初始化班级缺考人数
  216. int classCount = 0;
  217. //初始化班级平均分
  218. double points = 0;
  219. double passPoint = 0;
  220. //初始化及格人数
  221. int passCount = 0;
  222. //初始化各班参考人数
  223. int counts = 0;
  224. //c.Keys遍历key值
  225. foreach (string key in c.Keys)
  226. {
  227. classList.Add(key);
  228. }
  229. //每个班级平均分
  230. foreach (int[] value in c.Values)
  231. {
  232. for (int i = value[0]; i <= value[1]; i++)
  233. {
  234. //初始化学生单科个人得分
  235. double stuPoints = e.result[i].Sum();
  236. //Console.WriteLine("xx: "+xx+" classIndex:" + classIndex + ",i:" + i + " value[0]:" + value[0]+ " value[0]:" + value[1]);
  237. subSum[classIndex][i - value[0]] = stuPoints + subSum[classIndex][i - value[0]];
  238. if (stuPoints > passRate)
  239. {
  240. passCount++;
  241. gradeCount++;
  242. }
  243. classPoint += e.result[i].Sum();
  244. if (e.result[i].Sum() == 0)
  245. {
  246. classCount++;
  247. }
  248. }
  249. //每个班级实际参考人数
  250. counts = value[1] - value[0] - classCount + 1;
  251. points = Convert.ToDouble(classPoint) / counts;
  252. ClassAverage.Add(points.ToString("0.00"));
  253. person.Add(counts + "");
  254. }
  255. passPoint = Convert.ToDouble(passCount) / counts;
  256. passList.Add(passPoint.ToString("0.00"));
  257. //classPRM.Add(classPRL);
  258. classIndex += 1;
  259. });
  260. //科目平均分
  261. ClassAverage.ForEach(a =>
  262. {
  263. subjectPoint += Convert.ToDouble(a);
  264. });
  265. subAverage = subjectPoint / ClassAverage.Count();
  266. subjectAverage.Add(subAverage.ToString("0.00"));
  267. detail.Add("schoolAverage", subAverage.ToString("0.00"));
  268. detail.Add("areaAverage", subAverage.ToString("0.00"));
  269. detail.Add("score", ClassAverage);
  270. examList.Add(detail);
  271. //获取实际参考总人数
  272. e.ids.ForEach(i =>
  273. {
  274. if (!i.Equals("0"))
  275. {
  276. peopleCount++;
  277. }
  278. });
  279. //班级及格率
  280. passALL.Add(passList);
  281. //年级及格率
  282. double gradePass = Convert.ToDouble(gradeCount) / peopleCount;
  283. gradeList.Add(gradePass.ToString("0.00"));
  284. //passALL.Add(gradeList);
  285. //区级及格率
  286. //passALL.Add(areaList);
  287. //获取进线人数
  288. iPersons = peopleCount * 0.4;
  289. //计算每个学生单科成绩
  290. for (int i = 0; i < e.ids.Count(); i++)
  291. {
  292. List<string> info = new List<string>();
  293. //info = new List<string>();
  294. info.Add(e.ids[i]);
  295. info.Add(e.subjectCode);
  296. info.Add(e.result[i].Sum() + "");
  297. //classId.Add(e.Ids[i]);
  298. subjectPoints.Add(info);
  299. }
  300. keys.Add(e.subjectCode);
  301. xx += 1;
  302. //subjectPoints = GetMark(e.Result,e.Ids);
  303. });
  304. //subjectPoints.ForEach(f => f.GroupBy(f[0]));
  305. //进线情况统计
  306. Dictionary<string, List<List<string>>> dicts = new Dictionary<string, List<List<string>>>();
  307. foreach (IGrouping<string, List<string>> group in subjectPoints.GroupBy(c => c[0]))
  308. {
  309. dicts.Add(group.Key, group.ToList());
  310. };
  311. Average.Add("classList", classList);
  312. List<List<string>> sp = new List<List<string>>();
  313. //Dictionary<string, int> rankScore = new Dictionary<string, int>();
  314. List<int> rankScore = new List<int>();
  315. foreach (string key in dicts.Keys)
  316. {
  317. int score = 0;
  318. List<string> values = new List<string>();
  319. keys.ForEach(x =>
  320. {
  321. values.Add("-");
  322. });
  323. foreach (List<string> val in dicts[key])
  324. {
  325. int index = keys.IndexOf(val[1]);
  326. values[index] = val[2];
  327. values[keys.IndexOf("name")] = val[0];
  328. score += int.Parse(val[2]);
  329. values[keys.IndexOf("score")] = score + "";
  330. }
  331. rankScore.Add(score);
  332. sp.Add(values);
  333. }
  334. AchievementService.ReName(sp, idToName, classToName, students);
  335. //处理人数为整
  336. string ip = iPersons.ToString("0");
  337. //初始化进线分数
  338. int ipoint = 0;
  339. //计算成绩年级排名
  340. rankScore.Sort(delegate (int s1, int s2) { return s2.CompareTo(s1); });
  341. ipoint = rankScore[int.Parse(ip)];
  342. foreach (List<string> rank in sp)
  343. {
  344. int index = rankScore.IndexOf(int.Parse(rank[3]));
  345. rank[2] = (index + 1) + "";
  346. }
  347. //排除成绩为零的选手
  348. for (int i = sp.Count - 1; i >= 0; i--)
  349. {
  350. if (sp[i][0].Equals("0"))
  351. {
  352. sp.Remove(sp[i]);
  353. }
  354. }
  355. entryTable.Add("keys", keys);
  356. entryTable.Add("datas", sp);
  357. //封装进线人数统计
  358. List<string> keyLine = new List<string>
  359. {
  360. "gradeRank",
  361. "name",
  362. "entryNum",
  363. "totalNum",
  364. "overAverageRate"
  365. };
  366. Dictionary<string, object> entryLineBar = new Dictionary<string, object>();
  367. //存放班级信息
  368. List<string> className = new List<string>();
  369. foreach (string cla in classList)
  370. {
  371. className.Add(cla);
  372. }
  373. List<List<string>> datas = new List<List<string>>();
  374. //记录各个班级进线率占比
  375. List<string> persent = new List<string>();
  376. int m = 0;
  377. foreach (List<double> points in subSum)
  378. {
  379. List<string> detail = new List<string>();
  380. keyLine.ForEach(x =>
  381. {
  382. detail.Add("-");
  383. });
  384. double sum = points.Count;
  385. int j = 0;
  386. for (int i = 0; i < points.Count; i++)
  387. {
  388. if (points[i] > ipoint)
  389. {
  390. j++;
  391. }
  392. }
  393. double Lines = j;
  394. detail[1] = className[m].ToString();
  395. detail[2] = j.ToString();
  396. detail[3] = points.Count.ToString();
  397. var t3 = Math.Floor(Math.Round(decimal.Parse((Lines / sum).ToString("0.000")), 2) * 100);
  398. persent.Add(t3.ToString());
  399. detail[4] = t3.ToString();
  400. datas.Add(detail);
  401. m++;
  402. }
  403. persent.Sort(delegate (string s1, string s2) { return int.Parse(s2).CompareTo(int.Parse(s1)); });
  404. //存放班级的年级排名
  405. List<string> ranks = new List<string>();
  406. foreach (List<string> des in datas)
  407. {
  408. int index = persent.IndexOf(des[4]);
  409. des[0] = (index + 1).ToString();
  410. ranks.Add((index + 1).ToString());
  411. }
  412. //预警统计
  413. Dictionary<string, object> early = new Dictionary<string, object>();
  414. List<List<string>> earlyWarning = new List<List<string>>();
  415. List<string> keyWarning = new List<string>
  416. {
  417. "classId",
  418. "totalNum",
  419. "average",
  420. "standardDeviation",
  421. "overAverageRate",
  422. "gradeRank"
  423. };
  424. int n = 0;
  425. foreach (List<double> points in subSum)
  426. {
  427. double sum = 0;
  428. List<string> classInfo = new List<string>();
  429. classInfo.Add(className[n]);
  430. classInfo.Add(points.Count.ToString());
  431. foreach (int point in points)
  432. {
  433. sum += point;
  434. }
  435. double Aver = sum / points.Count;
  436. classInfo.Add(Aver.ToString());
  437. //存放班级平均
  438. cAverage.Add(Aver.ToString());
  439. //标准差
  440. double powSum = 0;
  441. foreach (int point in points)
  442. {
  443. powSum += Math.Pow(point - Aver, 2);
  444. }
  445. var pow = Math.Pow(powSum / points.Count, 0.5);
  446. classInfo.Add(pow.ToString("0.00"));
  447. //超均率
  448. var super = (sum - (sum - 100)) / (sum - 100);
  449. classInfo.Add(super.ToString("0.00"));
  450. //年级排名
  451. classInfo.Add(ranks[n]);
  452. earlyWarning.Add(classInfo);
  453. n++;
  454. }
  455. //sbujectsList.Add(subjects);
  456. passRateMap.Add("subjects", subjects);
  457. passRateMap.Add("class", passALL);
  458. passRateMap.Add("grade", gradeList);
  459. passRateMap.Add("area", areaList);
  460. //passRate.Add("passRate", passALL);
  461. early.Add("keys", keyWarning);
  462. early.Add("datas", earlyWarning);
  463. AclassAverage = AchievementService.GetAverage(exams, gAverage, cAverage, subSum, students);
  464. List<Dictionary<string, object>> rankPR = AchievementService.GetPR(exams, subSum, students);
  465. entryLineBar.Add("keys", keyLine);
  466. entryLineBar.Add("datas", datas);
  467. //sp.Sort(delegate (string s1, string s2) { return int.Parse(s1).CompareTo(int.Parse(s2)); });
  468. Average.Add("subjectAverage", subjectAverage);
  469. Average.Add("datas", examList);
  470. achievementAnalysis.Add("passRate", passRateMap);
  471. achievementAnalysis.Add("average", Average);
  472. achievementAnalysis.Add("entryLineBar", entryLineBar);
  473. achievementAnalysis.Add("entryTable", entryTable);
  474. achievementAnalysis.Add("earlyWarning", early);
  475. achievementAnalysis.Add("rankPR", rankPR);
  476. achievementAnalysis.Add("stuAverage", AclassAverage);
  477. //Redis处理结果集
  478. if (RedisHelper.Instance != null)
  479. {
  480. if (!RedisHelper.Exists(CacheCosmosPrefix + method))
  481. {
  482. await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), achievementAnalysis);
  483. }
  484. else
  485. {
  486. await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), achievementAnalysis);
  487. await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
  488. }
  489. }
  490. return achievementAnalysis;
  491. }
  492. else return achievementAnalysis;
  493. }
  494. /* public List<string> GetMark(List<List<int>> point,List<string> ids) {
  495. List<string> info = null;
  496. for (int i = 0;i <= ids.Count();i++) {
  497. info = new List<string>();
  498. info.Add(ids[i]);
  499. info.Add(point[i].Sum()+"");
  500. }
  501. return info;
  502. }*/
  503. [HttpPost("PointAnalysis")]
  504. public async Task<BaseResponse> PointAnalysis(JsonElement request)
  505. {
  506. ResponseBuilder builder = ResponseBuilder.custom();
  507. Dictionary<string, object> dict = new Dictionary<string, object>();
  508. var emobj = request.EnumerateObject();
  509. while (emobj.MoveNext())
  510. {
  511. dict[emobj.Current.Name] = emobj.Current.Value;
  512. }
  513. List<Dictionary<string, dynamic>> info = new List<Dictionary<string, dynamic>>();
  514. if (RedisHelper.Instance != null)
  515. {
  516. info = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "PointAnalysis",
  517. ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), timeoutSeconds, () => { return FindPointAnalysisRedis(dict, "PointAnalysis"); });
  518. //数据从redis读取过后进行转换格式
  519. builder.Data(JsonApiHelper.FromApiJson<System.Text.Json.JsonElement>(info.ToJson()));
  520. }
  521. else
  522. {
  523. info = await FindPointAnalysisRedis(dict, "PointAnalysis");
  524. builder.Data(JsonApiHelper.FromApiJson<System.Text.Json.JsonElement>(info.ToJson()));
  525. }
  526. return builder.build();
  527. }
  528. public async Task<List<Dictionary<string, dynamic>>> FindPointAnalysisRedis(Dictionary<string, object> dict, string method)
  529. {
  530. //ResponseBuilder builder = ResponseBuilder.custom();
  531. List<Dictionary<string, dynamic>> scatterAnalysis = new List<Dictionary<string, dynamic>>();
  532. //Dictionary<string, object> scatterAnalysis = new Dictionary<string, object>();
  533. List<ExamResult> exams = new List<ExamResult>();
  534. dict.TryGetValue("subjectCode", out object subjectCode);
  535. dict.TryGetValue("code", out object code);
  536. dict.TryGetValue("schoolCode", out object schoolCode);
  537. /* List<string> subjectCouns = JsonApiHelper.FromApiJson<List<string>>(subjectCode.ToApiJson());
  538. for (int i = 0; i < subjectCouns.Count; i++)
  539. {*/
  540. if (RedisHelper.Exists(CacheCosmosPrefix + "examResult" + subjectCode.ToString()))
  541. {
  542. ExamResult result = RedisHelper.HGet<ExamResult>(CacheCosmosPrefix + "examResult" + subjectCode.ToString(), ShaHashHelper.GetSHA1(code.ToString()));
  543. //builder.Data(info);
  544. exams.Add(result);
  545. }
  546. //}
  547. //List<Student> students = await azureCosmosDBRepository.FindByDict<Student>(stuMap);
  548. List<Student> students = null;
  549. if (RedisHelper.Exists(CacheCosmosPrefix + "students"))
  550. {
  551. students = RedisHelper.HGet<List<Student>>(CacheCosmosPrefix + "students", ShaHashHelper.GetSHA1(schoolCode.ToString()));
  552. //builder.Data(info);
  553. //students.Add(student);
  554. }
  555. List<string> key = new List<string>
  556. {
  557. "name",
  558. "className",
  559. "x",
  560. "y",
  561. "memberId",
  562. "score",
  563. "trueNum",
  564. "falseNum",
  565. "hardList",
  566. "carefulList",
  567. "scatter"
  568. };
  569. //key.Add("areaName");
  570. if (exams.IsNotEmpty())
  571. {
  572. //提取班级信息
  573. List<Dictionary<string, int[]>> classToName = exams[0].classes;
  574. //提取学生ID信息
  575. List<string> idToName = exams[0].ids;
  576. exams.ForEach(e =>
  577. {
  578. Dictionary<string, object> detail = new Dictionary<string, object>
  579. {
  580. { "keys", key }
  581. };
  582. List<List<string>> datas = new List<List<string>>();
  583. Dictionary<string, object> subject = new Dictionary<string, object>
  584. {
  585. { "name", e.subjectCode }
  586. };
  587. double[] point = StringHelper.ListTodouble(e.point);
  588. double[,] result = StringHelper.ListToDouble(e.result);
  589. try
  590. {
  591. var cdm = new ClouDASMatrix(result, point);
  592. //学生通过率
  593. List<double> pass = cdm.PassingRate;
  594. //学生稳定度
  595. List<double> sta = cdm.StabilityRate;
  596. //落点区域
  597. List<string> stu = cdm.StuFallArea;
  598. //需努力的题型
  599. List<int[]> strive = cdm.StriveTopic;
  600. //需小心的题型
  601. List<int[]> careful = cdm.CarefulTopic;
  602. int i = 0;
  603. for (int k = e.ids.Count - 1; k >= 0; k--)
  604. {
  605. if (e.ids[k].Equals("0"))
  606. {
  607. e.ids.Remove(e.ids[k]);
  608. }
  609. }
  610. e.ids.ForEach(s =>
  611. {
  612. if (e.result[i].Sum() != 0)
  613. {
  614. List<string> info = new List<string>
  615. {
  616. s,
  617. "-",
  618. sta[i].ToString(),
  619. pass[i].ToString(),
  620. i + 1 + "",
  621. e.result[i].Sum().ToString()
  622. };
  623. int right = 0;
  624. int wrong = 0;
  625. foreach (int p in e.result[i])
  626. {
  627. if (p > 0)
  628. {
  629. right++;
  630. }
  631. else
  632. {
  633. wrong++;
  634. }
  635. }
  636. info.Add(right + "");
  637. info.Add(wrong + "");
  638. int[] str = strive[i];
  639. string striveAll = "";
  640. foreach (int n in str)
  641. {
  642. striveAll += n.ToString() + ",";
  643. }
  644. int[] care = careful[i];
  645. string careAll = "";
  646. foreach (int n in care)
  647. {
  648. careAll += n.ToString() + ",";
  649. }
  650. if (string.IsNullOrEmpty(striveAll))
  651. {
  652. info.Add("无");
  653. }
  654. else {
  655. info.Add(striveAll.Substring(0, striveAll.Length - 1));
  656. }
  657. if (string.IsNullOrEmpty(careAll))
  658. {
  659. info.Add("无");
  660. }
  661. else
  662. {
  663. info.Add(careAll.Substring(0, careAll.Length - 1)); ;
  664. }
  665. info.Add(stu[i].ToString());
  666. datas.Add(info);
  667. }
  668. i++;
  669. });
  670. AchievementService.ReName(datas, idToName, classToName, students);
  671. detail.Add("datas", datas);
  672. subject.Add("scatter", detail);
  673. scatterAnalysis.Add(subject);
  674. }
  675. catch (Exception ex)
  676. {
  677. //builder.Data(exams);
  678. //ex.Message;
  679. Console.WriteLine("---------------------" + ex.Message + "--------------------------");
  680. }
  681. });
  682. //Redis处理结果集
  683. if (RedisHelper.Instance != null)
  684. {
  685. if (!RedisHelper.Exists(CacheCosmosPrefix + method))
  686. {
  687. await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), scatterAnalysis);
  688. }
  689. else
  690. {
  691. await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), scatterAnalysis);
  692. await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
  693. }
  694. }
  695. return scatterAnalysis;
  696. }else return scatterAnalysis;
  697. }
  698. [HttpPost("ExerciseScatter")]
  699. public async Task<BaseResponse> ExerciseScatter(JsonElement request)
  700. {
  701. ResponseBuilder builder = ResponseBuilder.custom();
  702. Dictionary<string, object> dict = new Dictionary<string, object>();
  703. var emobj = request.EnumerateObject();
  704. while (emobj.MoveNext())
  705. {
  706. dict[emobj.Current.Name] = emobj.Current.Value;
  707. }
  708. List<Dictionary<string, dynamic>> info = new List<Dictionary<string, dynamic>>();
  709. if (RedisHelper.Instance != null)
  710. {
  711. info = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "ExerciseScatter",
  712. ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), timeoutSeconds, () => { return FindExerciseScatterRedis(dict, "ExerciseScatter"); });
  713. //数据从redis读取过后进行转换格式
  714. builder.Data(JsonApiHelper.FromApiJson<System.Text.Json.JsonElement>(info.ToJson()));
  715. }
  716. else
  717. {
  718. info = await FindExerciseScatterRedis(dict, "ExerciseScatter");
  719. builder.Data(JsonApiHelper.FromApiJson<System.Text.Json.JsonElement>(info.ToJson()));
  720. }
  721. return builder.build();
  722. }
  723. public async Task<List<Dictionary<string, dynamic>>> FindExerciseScatterRedis(Dictionary<string, object> dict, string method)
  724. {
  725. ResponseBuilder builder = ResponseBuilder.custom();
  726. HashSet<string> classList = new HashSet<string>();
  727. List<Dictionary<string, object>> exerciseScatter = new List<Dictionary<string, object>>();
  728. Dictionary<string, object> scatterAnalysis = new Dictionary<string, object>();
  729. dict.TryGetValue("subjectCode", out object subjectCode);
  730. dict.TryGetValue("schoolCode", out object schoolCode);
  731. dict.TryGetValue("code", out object code);
  732. //dict.TryGetValue("scopeCode", out object scopeCode);
  733. /* Dictionary<string, object> sub = new Dictionary<string, object>
  734. {
  735. { "subjectCode", subjectCode.ToString()},
  736. { "code",code.ToString()}
  737. };
  738. Dictionary<string, object> examMap = new Dictionary<string, object>
  739. {
  740. { "subjectCode", subjectCode.ToString()},
  741. { "code", code.ToString()},
  742. { "schoolCode", schoolCode.ToString()}
  743. };*/
  744. //List<ExamResult> exams = await azureCosmosDBRepository.FindByDict<ExamResult>(examMap);
  745. List<ExamResult> exams = new List<ExamResult>();
  746. if (RedisHelper.Exists(CacheCosmosPrefix + "examResult" + subjectCode.ToString()))
  747. {
  748. ExamResult result = RedisHelper.HGet<ExamResult>(CacheCosmosPrefix + "examResult" + subjectCode.ToString(), ShaHashHelper.GetSHA1(code.ToString()));
  749. exams.Add(result);
  750. }
  751. List<Paper> paper = new List<Paper>();
  752. if (RedisHelper.Exists(CacheCosmosPrefix + "paperInfo" + subjectCode.ToString()))
  753. {
  754. Paper paper1 = RedisHelper.HGet<Paper>(CacheCosmosPrefix + "paperInfo" + subjectCode.ToString(), ShaHashHelper.GetSHA1(code.ToString()));
  755. paper.Add(paper1);
  756. }
  757. List<string> key = new List<string>
  758. {
  759. "id",
  760. "type",
  761. "areaName",
  762. "score",
  763. "diff",
  764. "identify",
  765. "classScoreRate",
  766. "gradeScoreRate",
  767. "areaScoreRate",
  768. "highScoreRate",
  769. "lowScoreRate",
  770. "knowledgePoint",
  771. "R1",
  772. "R2",
  773. "R3",
  774. "R4",
  775. "R5",
  776. "R6",
  777. "PH",
  778. "PL",
  779. "X",
  780. "Y",
  781. "knowledge"
  782. };
  783. //key.Add("areaName");
  784. if (exams.IsNotEmpty())
  785. {
  786. exams.ForEach(e =>
  787. {
  788. List<double> gradeAnswer = new List<double>();
  789. List<string> grasdepersent = new List<string>();
  790. for (int n = 0; n < e.point.Count; n++)
  791. {
  792. gradeAnswer.Add(0);
  793. }
  794. //参考人数
  795. double Qnum = 0;
  796. e.ids.ForEach(i =>
  797. {
  798. if (!i.Equals("0"))
  799. {
  800. Qnum++;
  801. }
  802. });
  803. Dictionary<string, object> detail = new Dictionary<string, object>
  804. {
  805. { "keys", key }
  806. };
  807. List<List<string>> datas = new List<List<string>>();
  808. List<string[]> itemAnalysis = new List<string[]>();
  809. Dictionary<string, object> subject = new Dictionary<string, object>
  810. {
  811. { "name", e.subjectCode }
  812. };
  813. Dictionary<string, object> classPersent = new Dictionary<string, object>();
  814. List<List<string>> classdatas = new List<List<string>>();
  815. try
  816. {
  817. e.classes.ForEach(c =>
  818. {
  819. //初始化每题得分情况
  820. List<int> answerCount = new List<int>();
  821. List<string> persent = new List<string>();
  822. double peopleCount = 0;
  823. for (int n = 0; n < e.point.Count; n++)
  824. {
  825. answerCount.Add(0);
  826. }
  827. int qCount = 0;
  828. //int right = 0;
  829. //c.Keys遍历key值
  830. foreach (string keys in c.Keys)
  831. {
  832. classList.Add(keys);
  833. }
  834. //每个班级得分占比
  835. foreach (int[] value in c.Values)
  836. {
  837. for (int i = value[0]; i <= value[1]; i++)
  838. {
  839. if (e.result[i].Sum() > 0)
  840. {
  841. for (int j = 0; j < e.result[i].Count; j++)
  842. {
  843. if (e.result[i][j] > 0)
  844. {
  845. //记录班级每题得分数
  846. answerCount[j] = answerCount[j] + 1;
  847. //记录年级每题得分数
  848. gradeAnswer[j] = gradeAnswer[j] + 1;
  849. //right++;
  850. }
  851. }
  852. }
  853. else
  854. {
  855. qCount++;
  856. }
  857. peopleCount = value[1] - value[0] + 1 - qCount;
  858. }
  859. }
  860. foreach (int p in answerCount)
  861. {
  862. var t = Math.Floor(Math.Round(decimal.Parse((p / peopleCount).ToString("0.000")), 2) * 100);
  863. persent.Add(t.ToString());
  864. }
  865. classdatas.Add(persent);
  866. });
  867. classPersent.Add("classList", classList);
  868. classPersent.Add("datas", classdatas);
  869. exerciseScatter.Add(classPersent);
  870. double[] point = StringHelper.ListTodouble(e.point);
  871. double[,] result = StringHelper.ListToDouble(e.result);
  872. var cdm = new ClouDASMatrix(result, point);
  873. //试题Y
  874. List<double> answer = cdm.AnswerRate;
  875. //试题X
  876. List<double> quality = cdm.QualityRate;
  877. //试题区域
  878. List<string> topic = cdm.TopicFallArea;
  879. //试题相关分析结果
  880. List<(double Diff, double Identify, double R1, double R2, double R3, double R4, double R5, double R6, double RH, double RL)> rs = cdm.RS;
  881. for (int i = 0; i < rs.Count; i++)
  882. {
  883. string[] ex = new string[] { };
  884. string ss = rs[i].ToString()[1..^1];
  885. ex = ss.Split(",");
  886. itemAnalysis.Add(ex);
  887. }
  888. foreach (int p in gradeAnswer)
  889. {
  890. var t = Math.Floor(Math.Round(decimal.Parse((p / Qnum).ToString("0.000")), 2) * 100);
  891. grasdepersent.Add(t.ToString());
  892. }
  893. for (int k = 0; k < e.point.Count; k++)
  894. {
  895. List<string> values = new List<string>();
  896. key.ForEach(x =>
  897. {
  898. values.Add("-");
  899. });
  900. values[0] = (k + 1).ToString();
  901. values[1] = paper[0].item[k].type;
  902. values[2] = topic[k].ToString();
  903. values[3] = e.point[k].ToString();
  904. values[4] = itemAnalysis[k][0];
  905. values[5] = itemAnalysis[k][1];
  906. values[7] = grasdepersent[k];
  907. values[8] = grasdepersent[k];
  908. values[12] = itemAnalysis[k][2];
  909. values[13] = itemAnalysis[k][3];
  910. values[14] = itemAnalysis[k][4];
  911. values[15] = itemAnalysis[k][5];
  912. values[16] = itemAnalysis[k][6];
  913. values[17] = itemAnalysis[k][7];
  914. values[18] = itemAnalysis[k][8];
  915. values[19] = itemAnalysis[k][9];
  916. values[20] = quality[k].ToString();
  917. values[21] = answer[k].ToString();
  918. string pointName = "";
  919. if (paper[0].item[k].points.Count == 1 ) {
  920. foreach (string index in paper[0].item[k].points)
  921. {
  922. pointName = index ;
  923. }
  924. } else if (paper[0].item[k].points.Count > 1) {
  925. foreach (string index in paper[0].item[k].points)
  926. {
  927. pointName += index + ",";
  928. }
  929. }
  930. values[22] = pointName;
  931. datas.Add(values);
  932. }
  933. subject.Add("keys", key);
  934. subject.Add("datas", datas);
  935. exerciseScatter.Add(subject);
  936. }
  937. catch (Exception ex)
  938. {
  939. throw new BizException(ex.Message);
  940. }
  941. });
  942. //Redis处理结果集
  943. if (RedisHelper.Instance != null)
  944. {
  945. if (!RedisHelper.Exists(CacheCosmosPrefix + method))
  946. {
  947. await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), exerciseScatter);
  948. }
  949. else
  950. {
  951. await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), exerciseScatter);
  952. await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
  953. }
  954. }
  955. return exerciseScatter;
  956. }
  957. else return exerciseScatter;
  958. }
  959. public async Task<Dictionary<string, dynamic>> FindKnowledgePointRedis(Dictionary<string, object> dict, string method)
  960. {
  961. //ResponseBuilder builder = ResponseBuilder.custom();
  962. dict.TryGetValue("subjectCode", out object subjectCode);
  963. dict.TryGetValue("schoolCode", out object schoolCode);
  964. dict.TryGetValue("code", out object code);
  965. //dict.TryGetValue("scopeCode", out object scopeCode);
  966. /* Dictionary<string, object> sub = new Dictionary<string, object>
  967. {
  968. { "subjectCode", subjectCode.ToString()},
  969. { "code",code.ToString()}
  970. };
  971. Dictionary<string, object> examMap = new Dictionary<string, object>
  972. {
  973. { "schoolCode", schoolCode.ToString()},
  974. { "code", code.ToString()},
  975. { "subjectCode", subjectCode.ToString()}
  976. };*/
  977. List<ExamResult> exams = new List<ExamResult>();
  978. if (RedisHelper.Exists(CacheCosmosPrefix + "examResult" + subjectCode.ToString()))
  979. {
  980. ExamResult res = RedisHelper.HGet<ExamResult>(CacheCosmosPrefix + "examResult" + subjectCode.ToString(), ShaHashHelper.GetSHA1(code.ToString()));
  981. exams.Add(res);
  982. }
  983. List<Paper> paper = new List<Paper>();
  984. if (RedisHelper.Exists(CacheCosmosPrefix + "paperInfo" + subjectCode.ToString()))
  985. {
  986. Paper papers = RedisHelper.HGet<Paper>(CacheCosmosPrefix + "paperInfo" + subjectCode.ToString(), ShaHashHelper.GetSHA1(code.ToString()));
  987. paper.Add(papers);
  988. }
  989. Dictionary<string, object> stuMap = new Dictionary<string, object>
  990. {
  991. { "schoolCode", "Habook" }
  992. };
  993. //List<Student> students = await azureCosmosDBRepository.FindByDict<Student>(stuMap);
  994. List<Student> students = null;
  995. if (RedisHelper.Exists(CacheCosmosPrefix + "students"))
  996. {
  997. students = RedisHelper.HGet<List<Student>>(CacheCosmosPrefix + "students", ShaHashHelper.GetSHA1(schoolCode.ToString()));
  998. //builder.Data(info);
  999. //students.Add(student);
  1000. }
  1001. HashSet<string> knowledge = new HashSet<string>();
  1002. HashSet<string> area = new HashSet<string>();
  1003. List<double> point = new List<double>();
  1004. List<List<double>> result = new List<List<double>>();
  1005. List<Dictionary<string, int[]>> classes = new List<Dictionary<string, int[]>>();
  1006. List<string> ids = new List<string>();
  1007. //string Type = "";
  1008. if (dict.TryGetValue("type", out object Type))
  1009. {
  1010. paper.ForEach(p =>
  1011. {
  1012. p.item.ForEach(i =>
  1013. {
  1014. knowledge.Add(i.field);
  1015. area.Add(i.field);
  1016. });
  1017. });
  1018. }
  1019. else {
  1020. paper.ForEach(p =>
  1021. {
  1022. p.item.ForEach(i =>
  1023. {
  1024. i.points.ForEach(o =>
  1025. {
  1026. knowledge.Add(o);
  1027. });
  1028. area.Add(i.field);
  1029. });
  1030. });
  1031. }
  1032. double Qnum = 0;
  1033. //确定高分组 低分组人数
  1034. List<List<double>> re = exams[0].result;
  1035. List<double> resultSum = new List<double>();
  1036. foreach (List<double> data in re)
  1037. {
  1038. resultSum.Add(data.Sum());
  1039. }
  1040. //确定高分组 最低分数
  1041. resultSum.Sort(delegate (double s1, double s2) { return s2.CompareTo(s1); });
  1042. for (int i = resultSum.Count - 1; i >= 0; i--)
  1043. {
  1044. if (resultSum[i] == 0)
  1045. {
  1046. resultSum.Remove(resultSum[i]);
  1047. }
  1048. }
  1049. double rhwCount = resultSum.Count * 0.27;
  1050. double rhw = resultSum[int.Parse(rhwCount.ToString("0"))];
  1051. //确定低分组 最高分数
  1052. resultSum.Sort(delegate (double s1, double s2) { return s1.CompareTo(s2); });
  1053. double rhlCount = resultSum.Count * 0.27;
  1054. double rhl = resultSum[int.Parse(rhwCount.ToString("0"))];
  1055. foreach (ExamResult ex in exams) {
  1056. point = ex.point;
  1057. result = ex.result;
  1058. classes = ex.classes;
  1059. ids = ex.ids;
  1060. }
  1061. /* exams.ForEach(e =>
  1062. {
  1063. point = e.Point;
  1064. result = e.Result;
  1065. classes = e.Classes;
  1066. ids = e.Ids;
  1067. });*/
  1068. List<string> knowledgeName = new List<string>();
  1069. foreach (string cla in knowledge)
  1070. {
  1071. knowledgeName.Add(cla);
  1072. }
  1073. for (int k = 0;k < knowledgeName.Count;k++ ) {
  1074. if (null == knowledgeName[k]) {
  1075. knowledgeName.Remove(knowledgeName[k]);
  1076. }
  1077. }
  1078. List<string> areaName = new List<string>();
  1079. foreach (string cla in area)
  1080. {
  1081. areaName.Add(cla);
  1082. }
  1083. for (int k = 0; k < areaName.Count; k++)
  1084. {
  1085. if (null == areaName[k])
  1086. {
  1087. areaName.Remove(areaName[k]);
  1088. }
  1089. }
  1090. //初始化年级总分
  1091. double total = 0;
  1092. //处理年级单个知识点得分率
  1093. foreach (List<double> grade in result)
  1094. {
  1095. total += grade.Sum();
  1096. }
  1097. foreach (string id in ids)
  1098. {
  1099. if (!id.Equals("0"))
  1100. {
  1101. Qnum++;
  1102. }
  1103. }
  1104. //试卷总分
  1105. double TotalPoint = point.Sum();
  1106. //计算认知层次占比
  1107. List<string> fper = new List<string>();
  1108. for (int a = 0; a < areaName.Count; a++)
  1109. {
  1110. double fieldPoint = 0;
  1111. paper.ForEach(p =>
  1112. {
  1113. int n = 0;
  1114. p.item.ForEach(i =>
  1115. {
  1116. if (i.field != null && i.field.Contains(areaName[a]))
  1117. {
  1118. fieldPoint += point[n];
  1119. }
  1120. n++;
  1121. });
  1122. });
  1123. double fieldPersent = fieldPoint / TotalPoint;
  1124. fper.Add(fieldPersent.ToString("0.00"));
  1125. }
  1126. //求单个知识点所占分数
  1127. List<string> per = new List<string>();
  1128. List<string> gper = new List<string>();
  1129. List<string> knowPer = new List<string>();
  1130. List<Dictionary<string, double>> eper = new List<Dictionary<string, double>>();
  1131. Dictionary<string, object> knowledgeALL = new Dictionary<string, object>();
  1132. Dictionary<string, object> knowledgeMap = new Dictionary<string, object>();
  1133. Dictionary<string, object> classMap = new Dictionary<string, object>();
  1134. Dictionary<string, object> wrongMap = new Dictionary<string, object>();
  1135. HashSet<string> className = new HashSet<string>();
  1136. List<List<string>> wrongPersent = new List<List<string>>();
  1137. List<string> key = new List<string>
  1138. {
  1139. "id",
  1140. "className",
  1141. "seatNO",
  1142. "point",
  1143. "anwPoint",
  1144. "persent"
  1145. };
  1146. List<string> keyWrong = new List<string>
  1147. {
  1148. "name",
  1149. "point",
  1150. "itemNO",
  1151. "persent",
  1152. "wrong",
  1153. "rhw",
  1154. "rlw"
  1155. };
  1156. for (int k = 0; k < knowledgeName.Count; k++)
  1157. {
  1158. List<string> knowledgeClass = new List<string>();
  1159. List<List<string>> stuPersent = new List<List<string>>();
  1160. double OnePoint = 0;
  1161. //获取每个知识点占有多少分值
  1162. double ePoint = 0;
  1163. double anwGPoint = 0;
  1164. double poG = 0;
  1165. int m = 0;
  1166. List<string> valuew = new List<string>();
  1167. List<string> itemNo = new List<string>();
  1168. keyWrong.ForEach(x =>
  1169. {
  1170. valuew.Add("-");
  1171. });
  1172. int wrongCount = 0;
  1173. valuew[0] = knowledgeName[k];
  1174. paper.ForEach(p =>
  1175. {
  1176. int n = 0;
  1177. if (dict.TryGetValue("type", out object Type)) {
  1178. p.item.ForEach(i =>
  1179. {
  1180. if (i.field != null && i.field.Contains(knowledgeName[k]))
  1181. {
  1182. OnePoint += point[n];
  1183. itemNo.Add((n + 1).ToString());
  1184. }
  1185. n++;
  1186. });
  1187. } else {
  1188. p.item.ForEach(i =>
  1189. {
  1190. if (i.points != null && i.points.Contains(knowledgeName[k]))
  1191. {
  1192. OnePoint += 1 / Convert.ToDouble(i.points.Count) * point[n];
  1193. itemNo.Add((n + 1).ToString());
  1194. }
  1195. n++;
  1196. });
  1197. }
  1198. valuew[1] = OnePoint.ToString();
  1199. string itemNos = "";
  1200. foreach (string index in itemNo)
  1201. {
  1202. itemNos += index + ",";
  1203. }
  1204. valuew[2] = itemNos[0..^1];
  1205. });
  1206. int rhwC = 0;
  1207. int rhlC = 0;
  1208. foreach (string id in ids)
  1209. {
  1210. if (id.Equals("0") || result[m].Sum() == 0)
  1211. {
  1212. m++;
  1213. continue;
  1214. }
  1215. List<string> values = new List<string>();
  1216. key.ForEach(x =>
  1217. {
  1218. values.Add("-");
  1219. });
  1220. foreach (Student info in students)
  1221. {
  1222. if (info.studentId.Equals(id))
  1223. {
  1224. values[2] = info.seatNo.ToString();
  1225. break;
  1226. }
  1227. }
  1228. //List<string> stu = new List<string>();
  1229. values[0] = id;
  1230. values[1] = "-";
  1231. //List<List<string>> stuItem = new List<List<string>>();
  1232. int statuCount = 0;
  1233. paper.ForEach(p =>
  1234. {
  1235. int n = 0;
  1236. double anwPoint = 0;
  1237. double po = 0;
  1238. p.item.ForEach(i =>
  1239. {
  1240. if (dict.TryGetValue("type", out object Type))
  1241. {
  1242. if (i.field!= null && i.field.Contains(knowledgeName[k]))
  1243. {
  1244. //Dictionary<string, double> mapkeyItem = new Dictionary<string, double>();
  1245. //OnePoint += 1 / Convert.ToDouble(i.points.Count) * point[n];
  1246. //当前认知层次在该题占比多少
  1247. ePoint = 1;
  1248. anwPoint += result[m][n] * ePoint;
  1249. //所有学生单个认知层次得分情况
  1250. anwGPoint += result[m][n] * ePoint;
  1251. po += point[n] * ePoint;
  1252. //认知层次所占分数
  1253. poG += point[n] * ePoint;
  1254. if (result[m][n] == 0 && statuCount == 0)
  1255. {
  1256. statuCount++;
  1257. wrongCount++;
  1258. if (result[m].Sum() >= rhw)
  1259. {
  1260. rhwC++;
  1261. }
  1262. if (result[m].Sum() <= rhl)
  1263. {
  1264. rhlC++;
  1265. }
  1266. }
  1267. }
  1268. n++;
  1269. }
  1270. else {
  1271. if (i.points != null && i.points.Contains(knowledgeName[k]))
  1272. {
  1273. //Dictionary<string, double> mapkeyItem = new Dictionary<string, double>();
  1274. //OnePoint += 1 / Convert.ToDouble(i.points.Count) * point[n];
  1275. //当前知识点在该题占比多少
  1276. ePoint = 1 / Convert.ToDouble(i.points.Count);
  1277. anwPoint += result[m][n] * ePoint;
  1278. //所有学生单个知识点得分情况
  1279. anwGPoint += result[m][n] * ePoint;
  1280. po += point[n] * ePoint;
  1281. //知识点所占分数
  1282. poG += point[n] * ePoint;
  1283. if (result[m][n] == 0 && statuCount == 0)
  1284. {
  1285. statuCount++;
  1286. wrongCount++;
  1287. if (result[m].Sum() >= rhw)
  1288. {
  1289. rhwC++;
  1290. }
  1291. if (result[m].Sum() <= rhl)
  1292. {
  1293. rhlC++;
  1294. }
  1295. }
  1296. }
  1297. n++;
  1298. }
  1299. });
  1300. double stuPser = anwPoint / po;
  1301. values[3] = po.ToString();
  1302. values[4] = anwPoint.ToString();
  1303. values[5] = stuPser.ToString("0.00");
  1304. //stuItem.Add(values);
  1305. });
  1306. stuPersent.Add(values);
  1307. m++;
  1308. }
  1309. AchievementService.ReName(stuPersent, ids, classes, students);
  1310. double knowPser = anwGPoint / poG;
  1311. knowPer.Add(knowPser.ToString("0.00"));
  1312. //错题关系表
  1313. valuew[3] = knowPser.ToString("0.00");
  1314. valuew[4] = wrongCount.ToString();
  1315. valuew[5] = rhwC.ToString();
  1316. valuew[6] = rhlC.ToString();
  1317. wrongPersent.Add(valuew);
  1318. knowledgeMap.Add(knowledgeName[k], stuPersent);
  1319. //知识点占比
  1320. double persent = OnePoint / TotalPoint;
  1321. foreach (Dictionary<string, int[]> map in classes)
  1322. {
  1323. List<string> classPoints = new List<string>();
  1324. //初始化班级得分
  1325. double anwCPoint = 0;
  1326. double cpo = 0;
  1327. foreach (KeyValuePair<string, int[]> kvp in map)
  1328. {
  1329. className.Add(kvp.Key);
  1330. for (int n = kvp.Value[0]; n < kvp.Value[1]; n++)
  1331. {
  1332. if (result[n].Sum() == 0) continue;
  1333. paper.ForEach(p =>
  1334. {
  1335. int x = 0;
  1336. p.item.ForEach(i =>
  1337. {
  1338. if (dict.TryGetValue("type", out object Type))
  1339. {
  1340. if (i.field != null && i.field.Contains(knowledgeName[k]))
  1341. {
  1342. //当前认知层次在该题占比多少
  1343. ePoint = 1;
  1344. anwCPoint += result[n][x] * ePoint;
  1345. cpo += point[x] * ePoint;
  1346. }
  1347. x++;
  1348. }
  1349. else {
  1350. if (i.points != null && i.points.Contains(knowledgeName[k]))
  1351. {
  1352. //当前知识点在该题占比多少
  1353. ePoint = 1 / Convert.ToDouble(i.points.Count);
  1354. anwCPoint += result[n][x] * ePoint;
  1355. cpo += point[x] * ePoint;
  1356. }
  1357. x++;
  1358. }
  1359. });
  1360. });
  1361. }
  1362. }
  1363. double classPser = anwCPoint / cpo;
  1364. knowledgeClass.Add(classPser.ToString("0.00"));
  1365. }
  1366. classMap.Add(knowledgeName[k], knowledgeClass);
  1367. per.Add(persent.ToString("0.00"));
  1368. }
  1369. knowledgeMap.Add("grade", knowPer);
  1370. knowledgeMap.Add("keys", key);
  1371. classMap.Add("className", className);
  1372. wrongMap.Add("keys", keyWrong);
  1373. wrongMap.Add("datas", wrongPersent);
  1374. knowledgeALL.Add("pointList", knowledgeName);
  1375. knowledgeALL.Add("per", per);
  1376. knowledgeALL.Add("level", areaName);
  1377. knowledgeALL.Add("fper", fper);
  1378. knowledgeALL.Add("stupercent", knowledgeMap);
  1379. knowledgeALL.Add("classpercent", classMap);
  1380. knowledgeALL.Add("wrong", wrongMap);
  1381. //builder.Data(knowledgeALL);
  1382. //Redis处理结果集
  1383. if (RedisHelper.Instance != null)
  1384. {
  1385. if (!RedisHelper.Exists(CacheCosmosPrefix + method))
  1386. {
  1387. await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), knowledgeALL);
  1388. }
  1389. else
  1390. {
  1391. await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), knowledgeALL);
  1392. await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
  1393. }
  1394. }
  1395. return knowledgeALL;
  1396. }
  1397. [HttpPost("knowledgePoint")]
  1398. public async Task<BaseResponse> KnowledgePoint(JsonElement request)
  1399. {
  1400. ResponseBuilder builder = ResponseBuilder.custom();
  1401. Dictionary<string, object> dict = new Dictionary<string, object>();
  1402. var emobj = request.EnumerateObject();
  1403. while (emobj.MoveNext())
  1404. {
  1405. dict[emobj.Current.Name] = emobj.Current.Value;
  1406. }
  1407. Dictionary<string, dynamic> info = new Dictionary<string, dynamic>();
  1408. if (RedisHelper.Instance != null)
  1409. {
  1410. info = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "knowledgePoint",
  1411. ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), timeoutSeconds, () => { return FindKnowledgePointRedis(dict, "knowledgePoint"); });
  1412. //数据从redis读取过后进行转换格式
  1413. builder.Data(JsonApiHelper.FromApiJson<System.Text.Json.JsonElement>(info.ToJson()));
  1414. }
  1415. else
  1416. {
  1417. info = await FindKnowledgePointRedis(dict, "knowledgePoint");
  1418. builder.Data(JsonApiHelper.FromApiJson<System.Text.Json.JsonElement>(info.ToJson()));
  1419. }
  1420. return builder.build();
  1421. }
  1422. [HttpPost("FindExamInfo")]
  1423. public async Task<BaseResponse> FindExamInfo(JsonElement request)
  1424. {
  1425. ResponseBuilder builder = ResponseBuilder.custom();
  1426. Dictionary<string, object> dict = new Dictionary<string, object>();
  1427. var emobj = request.EnumerateObject();
  1428. while (emobj.MoveNext())
  1429. {
  1430. dict[emobj.Current.Name] = emobj.Current.Value;
  1431. }
  1432. if (RedisHelper.Instance != null)
  1433. {
  1434. try {
  1435. ///RedisHelper.Instance.CurrentSerialize = obj => System.Text.Json.JsonSerializer.Serialize(obj);
  1436. /// RedisHelper.Instance.CurrentDeserialize = (json, type) => System.Text.Json.JsonSerializer.Deserialize(json, type);
  1437. List<ExamInfo> info = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "FindExamInfo",
  1438. ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), timeoutSeconds, () => { return FindExamInfoRedis(dict, "FindExamInfo"); });
  1439. builder.Data(info);
  1440. } catch (Exception e) {
  1441. throw new BizException(e.Message);
  1442. }
  1443. }
  1444. else
  1445. {
  1446. List<ExamInfo> info = await FindExamInfoRedis(dict, "FindExamInfo");
  1447. builder.Data(info);
  1448. }
  1449. return builder.build();
  1450. }
  1451. public async Task<List<ExamInfo>> FindExamInfoRedis(Dictionary<string, object> dict,string method)
  1452. {
  1453. try {
  1454. List<ExamInfo> info = await azureCosmosDBRepository.FindByDict<ExamInfo>(dict);
  1455. if (RedisHelper.Instance != null)
  1456. {
  1457. if (!RedisHelper.Exists(CacheCosmosPrefix + method))
  1458. {
  1459. await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), info);
  1460. }
  1461. else
  1462. {
  1463. await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), info);
  1464. await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
  1465. }
  1466. }
  1467. return info;
  1468. } catch (Exception e) {
  1469. throw new BizException(e.Message);
  1470. }
  1471. }
  1472. [HttpPost("FindExamPaper")]
  1473. public BaseResponse FindExamPaper(JsonElement request)
  1474. {
  1475. Dictionary<string, object> dict = new Dictionary<string, object>();
  1476. var emobj = request.EnumerateObject();
  1477. while (emobj.MoveNext())
  1478. {
  1479. dict[emobj.Current.Name] = emobj.Current.Value;
  1480. }
  1481. dict.TryGetValue("subjectCode", out object subjectCode);
  1482. dict.TryGetValue("code", out object code);
  1483. ResponseBuilder builder = ResponseBuilder.custom();
  1484. /*if (RedisHelper.Instance != null)
  1485. {
  1486. List<Paper> info = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + request.method,
  1487. ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(request.@params)), timeoutSeconds, () => { return FindExamPaperRedis(request.@params, request.method); });
  1488. builder.Data(info);
  1489. }
  1490. else
  1491. {
  1492. List<Paper> info = await FindExamPaperRedis(request.@params, request.method);
  1493. builder.Data(info);
  1494. }*/
  1495. List<Paper> paper = new List<Paper>();
  1496. if (RedisHelper.Exists(CacheCosmosPrefix + "paperInfo" + subjectCode.ToString()))
  1497. {
  1498. Paper paper1 = RedisHelper.HGet<Paper>(CacheCosmosPrefix + "paperInfo" + subjectCode.ToString(), ShaHashHelper.GetSHA1(code.ToString()));
  1499. paper.Add(paper1);
  1500. builder.Data(paper);
  1501. }
  1502. return builder.build();
  1503. }
  1504. public async Task<List<Paper>> FindExamPaperRedis(Dictionary<string, object> dict, string method)
  1505. {
  1506. try
  1507. {
  1508. List<Paper> info = await azureCosmosDBRepository.FindByDict<Paper>(dict);
  1509. if (RedisHelper.Instance != null)
  1510. {
  1511. if (!RedisHelper.Exists(CacheCosmosPrefix + method))
  1512. {
  1513. await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), info);
  1514. }
  1515. else
  1516. {
  1517. await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), info);
  1518. await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
  1519. }
  1520. }
  1521. return info;
  1522. }
  1523. catch (Exception e)
  1524. {
  1525. throw new BizException(e.Message);
  1526. }
  1527. }
  1528. [HttpPost("FindExamAnswer")]
  1529. public BaseResponse FindExamAnswer(JsonElement request)
  1530. {
  1531. Dictionary<string, object> dict = new Dictionary<string, object>();
  1532. var emobj = request.EnumerateObject();
  1533. while (emobj.MoveNext())
  1534. {
  1535. dict[emobj.Current.Name] = emobj.Current.Value;
  1536. }
  1537. dict.TryGetValue("subjectCode", out object subjectCode);
  1538. dict.TryGetValue("code", out object code);
  1539. ResponseBuilder builder = ResponseBuilder.custom();
  1540. List<ExamAnswer> exams = new List<ExamAnswer>();
  1541. if (RedisHelper.Exists(CacheCosmosPrefix + "examAnswer" + subjectCode.ToString()))
  1542. {
  1543. ExamAnswer exam = RedisHelper.HGet<ExamAnswer>(CacheCosmosPrefix + "examAnswer" + subjectCode.ToString(), ShaHashHelper.GetSHA1(code.ToString()));
  1544. exams.Add(exam);
  1545. builder.Data(exams);
  1546. }
  1547. return builder.build();
  1548. }
  1549. public async Task<List<ExamAnswer>> FindExamAnswerRedis(Dictionary<string, object> dict, string method)
  1550. {
  1551. try
  1552. {
  1553. List<ExamAnswer> info = await azureCosmosDBRepository.FindByDict<ExamAnswer>(dict);
  1554. if (RedisHelper.Instance != null)
  1555. {
  1556. if (!RedisHelper.Exists(CacheCosmosPrefix + method))
  1557. {
  1558. await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), info);
  1559. }
  1560. else
  1561. {
  1562. await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), info);
  1563. await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
  1564. }
  1565. }
  1566. return info;
  1567. }
  1568. catch (Exception e)
  1569. {
  1570. throw new BizException(e.Message);
  1571. }
  1572. }
  1573. public async Task<List<ExamAnswer>> FindExamAnswerRedis(Dictionary<string, object> dict)
  1574. {
  1575. try
  1576. {
  1577. List<ExamAnswer> info = await azureCosmosDBRepository.FindByDict<ExamAnswer>(dict);
  1578. if (RedisHelper.Instance != null)
  1579. {
  1580. if (!RedisHelper.Exists(CacheCosmosPrefix + "FindExamAnswer"))
  1581. {
  1582. await RedisHelper.HSetAsync(CacheCosmosPrefix + "FindExamAnswer", ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), info);
  1583. }
  1584. else
  1585. {
  1586. await RedisHelper.HSetAsync(CacheCosmosPrefix + "FindExamAnswer", ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), info);
  1587. await RedisHelper.ExpireAsync(CacheCosmosPrefix + "FindExamAnswer", timeoutSeconds);
  1588. }
  1589. }
  1590. return info;
  1591. }
  1592. catch (Exception e)
  1593. {
  1594. throw new BizException(e.Message);
  1595. }
  1596. }
  1597. [HttpPost("HomeStatistics")]
  1598. public async Task<BaseResponse> HomeStatistics(JsonElement request)
  1599. {
  1600. ResponseBuilder builder = ResponseBuilder.custom();
  1601. Dictionary<string, object> dict = new Dictionary<string, object>();
  1602. var emobj = request.EnumerateObject();
  1603. while (emobj.MoveNext())
  1604. {
  1605. dict[emobj.Current.Name] = emobj.Current.Value;
  1606. }
  1607. List<Dictionary<string, dynamic>> info = new List<Dictionary<string, dynamic>>();
  1608. if (RedisHelper.Instance != null)
  1609. {
  1610. info = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "HomeStatistics",
  1611. ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), timeoutSeconds, () => { return FindHomeStatisticsRedis(dict, "HomeStatistics"); });
  1612. //数据从redis读取过后进行转换格式
  1613. builder.Data(JsonApiHelper.FromApiJson<System.Text.Json.JsonElement>(info.ToJson()));
  1614. }
  1615. else
  1616. {
  1617. info = await FindHomeStatisticsRedis(dict, "HomeStatistics");
  1618. builder.Data(JsonApiHelper.FromApiJson<System.Text.Json.JsonElement>(info.ToJson()));
  1619. }
  1620. return builder.build();
  1621. }
  1622. public async Task<List<Dictionary<string, dynamic>>> FindHomeStatisticsRedis(Dictionary<string, object> dict, string method) {
  1623. //request.@params.TryGetValue("subjectCode", out object subjectCode);
  1624. dict.TryGetValue("schoolCode", out object schoolCode);
  1625. dict.TryGetValue("code", out object code);
  1626. Dictionary<string, object> eMap = new Dictionary<string, object>
  1627. {
  1628. { "code", code.ToString()},
  1629. { "type","normal"}
  1630. };
  1631. Dictionary<string, object> SCMap = new Dictionary<string, object>
  1632. {
  1633. { "schoolCode", schoolCode.ToString()},
  1634. };
  1635. //await SaveRedisInfoAsync(eMap);
  1636. //说明 同学校、同类型考试数据
  1637. //List<ExamInfo> exams = await azureCosmosDBRepository.FindByDict<ExamInfo>(eMap);
  1638. List<ExamInfo> exams = new List<ExamInfo>();
  1639. if (RedisHelper.Instance != null)
  1640. {
  1641. exams = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "FindExamInfo",
  1642. ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(eMap)), timeoutSeconds, () => { return FindExamInfoRedis(eMap, "FindExamInfo"); });
  1643. }
  1644. else
  1645. {
  1646. exams = await FindExamInfoRedis(eMap, "FindExamInfo");
  1647. }
  1648. List<ExamInfo> newInfo = new List<ExamInfo>();
  1649. //获取各个学段最新的考试信息
  1650. foreach (IGrouping<string, ExamInfo> group in exams.GroupBy(c => c.conditions.period))
  1651. {
  1652. ExamInfo examInfo = group.ToList().OrderByDescending(e => e.createTime).ToList().FirstOrDefault();
  1653. newInfo.Add(examInfo);
  1654. };
  1655. //newInfo.Select(e => e.type.Equals("union"));
  1656. //List<ExamInfo> unionInfo = newInfo.Where(e => e.type.Equals("union")).ToList();
  1657. //exams.GroupBy(e => e.conditions.period);
  1658. //ExamInfo info = exams.OrderByDescending(e => e.createTime).ToList().FirstOrDefault();
  1659. //查询学校对应的年级信息
  1660. //List<School> schools = await azureCosmosDBRepository.FindByDict<School>(SCMap);
  1661. List<School> schools = new List<School>();
  1662. if (RedisHelper.Exists(CacheCosmosPrefix + "schoolInfo"))
  1663. {
  1664. School sc = RedisHelper.HGet<School>(CacheCosmosPrefix + "schoolInfo",
  1665. ShaHashHelper.GetSHA1(schoolCode.ToString()));
  1666. schools.Add(sc);
  1667. }
  1668. HashSet<string> classList = new HashSet<string>();
  1669. HashSet<string> subjectList = new HashSet<string>();
  1670. List<List<List<string>>> AllPoint = new List<List<List<string>>>();
  1671. List<List<List<string>>> AllPointAverage = new List<List<List<string>>>();
  1672. List<List<List<string>>> AllKeyLine = new List<List<List<string>>>();
  1673. string Period = "";
  1674. string Grade = "";
  1675. List<double> CoreAverage = new List<double>();
  1676. double weightSum = 0;
  1677. try
  1678. {
  1679. List<Period> periods = new List<Period>();
  1680. List<Grade> grades = new List<Grade>();
  1681. foreach (School s in schools)
  1682. {
  1683. periods = s.period;
  1684. }
  1685. periods.ForEach(p =>
  1686. {
  1687. if (p.periodName.Equals("初中"))
  1688. {
  1689. grades = p.grades;
  1690. }
  1691. else if (p.periodName.Equals("高中"))
  1692. {
  1693. grades = p.grades;
  1694. }
  1695. else
  1696. {
  1697. grades = p.grades;
  1698. }
  1699. });
  1700. List<Dictionary<string, object>> map = new List<Dictionary<string, object>>();
  1701. //循环处理不同年级考试信息
  1702. foreach (Grade g in grades)
  1703. {
  1704. for (int i = 0; i < newInfo.Count; i++)
  1705. {
  1706. if (g.gradeCode.Equals(newInfo[i].conditions.grade))
  1707. {
  1708. List<ExamResult> simples = new List<ExamResult>();
  1709. for (int j = 0; j < newInfo[i].conditions.subject.Count; j++)
  1710. {
  1711. ExamResult result = new ExamResult();
  1712. if (RedisHelper.Exists(CacheCosmosPrefix + "examResult" + newInfo[i].conditions.subject[j]))
  1713. {
  1714. result = RedisHelper.HGet<ExamResult>(CacheCosmosPrefix + "examResult" + newInfo[i].conditions.subject[j],
  1715. ShaHashHelper.GetSHA1(newInfo[i].examCode));
  1716. simples.Add(result);
  1717. }
  1718. }
  1719. //List<ExamResult> examResults = new List<ExamResult>();
  1720. /*Dictionary<string, object> sub = new Dictionary<string, object>
  1721. {
  1722. { "code", newInfo[i].id}
  1723. };*/
  1724. Period = newInfo[i].conditions.period;
  1725. Grade = newInfo[i].conditions.grade;
  1726. List<string> subjects = new List<string>();
  1727. List<List<string>> SubjectClassAverage = new List<List<string>>();
  1728. List<List<string>> SubjectAverage = new List<List<string>>();
  1729. //List<List<string>> SubjectClassAverage = new List<List<string>>();
  1730. //List<ExamResult> simples = await azureCosmosDBRepository.FindByDict<ExamResult>(sub);
  1731. // 学生总分
  1732. double coreSum = 0;
  1733. int stuCount = newInfo[i].stuCount;
  1734. //初始化进行人数
  1735. double iPersons = 0;
  1736. //获取进线人数
  1737. iPersons = stuCount * 0.4;
  1738. //
  1739. List<List<double>> subSum = new List<List<double>>();
  1740. if (simples.IsEmpty()) continue;
  1741. double weight = 0.5;
  1742. weightSum += weight;
  1743. int classLen = simples[0].classes.Count;
  1744. for (int cls = 0; cls < classLen; cls++)
  1745. {
  1746. if (simples[0].classes[cls].TryGetValue(simples[0].classes[cls].Keys.ToArray<string>()[0], out int[] indexs))
  1747. {
  1748. List<double> stuScore = new List<double>();
  1749. int stdLen = indexs[1] - indexs[0] + 1;
  1750. for (int n = 0; n < stdLen; n++)
  1751. {
  1752. stuScore.Add(0);
  1753. }
  1754. subSum.Add(stuScore);
  1755. }
  1756. }
  1757. simples.ForEach(s =>
  1758. {
  1759. subjectList.Add(s.subjectCode);
  1760. //计算试卷总分
  1761. double sum = s.point.Sum();
  1762. //int stuSum = 0;
  1763. int classIndex = 0;
  1764. List<string> ClassAverage = new List<string>();
  1765. List<string> Average = new List<string>();
  1766. List<string> passList = new List<string>();
  1767. s.classes.ForEach(c =>
  1768. {
  1769. List<List<string>> classPRL = new List<List<string>>();
  1770. //初始化班级总分
  1771. double classPoint = 0;
  1772. //初始化班级缺考人数
  1773. int classCount = 0;
  1774. //初始化班级平均得分率
  1775. double points = 0;
  1776. //初始化班级平均得分率
  1777. double AveragePoints = 0;
  1778. //初始化各班参考人数
  1779. int counts = 0;
  1780. //c.Keys遍历key值
  1781. foreach (string key in c.Keys)
  1782. {
  1783. classList.Add(key);
  1784. }
  1785. //每个班级平均分
  1786. foreach (int[] value in c.Values)
  1787. {
  1788. for (int i = value[0]; i <= value[1]; i++)
  1789. {
  1790. //初始化学生单科个人得分
  1791. double stuPoints = s.result[i].Sum();
  1792. subSum[classIndex][i - value[0]] = stuPoints + subSum[classIndex][i - value[0]];
  1793. classPoint += s.result[i].Sum();
  1794. coreSum += s.result[i].Sum();
  1795. if (s.result[i].Sum() == 0)
  1796. {
  1797. classCount++;
  1798. }
  1799. }
  1800. //每个班级实际参考人数
  1801. counts = value[1] - value[0] - classCount + 1;
  1802. //stuSum += counts;
  1803. points = Convert.ToDouble(classPoint) / counts / sum;
  1804. //计算每个班级平均得分
  1805. AveragePoints = Convert.ToDouble(classPoint) / counts;
  1806. ClassAverage.Add(points.ToString("0.000"));
  1807. Average.Add(AveragePoints.ToString());
  1808. }
  1809. classIndex += 1;
  1810. });
  1811. SubjectClassAverage.Add(ClassAverage);
  1812. SubjectAverage.Add(Average);
  1813. //subAverage = subjectPoint / ClassAverage.Count();
  1814. //subjectAverage.Add(subAverage.ToString("0.00"));
  1815. });
  1816. double core = coreSum / stuCount * weight;
  1817. CoreAverage.Add(core);
  1818. AllPoint.Add(SubjectClassAverage);
  1819. AllPointAverage.Add(SubjectAverage);
  1820. //处理人数为整
  1821. string ip = iPersons.ToString("0");
  1822. //初始化进线分数
  1823. int ipoint = 0;
  1824. List<int> AllPoints = new List<int>();
  1825. foreach (List<double> points in subSum)
  1826. {
  1827. foreach (int po in points)
  1828. {
  1829. AllPoints.Add(po);
  1830. }
  1831. }
  1832. for (int sn = 0; sn < subSum.Count; sn++)
  1833. {
  1834. for (int j = 0; j < subSum[sn].Count; j++)
  1835. {
  1836. if (subSum[sn][j].Equals("0"))
  1837. {
  1838. subSum[sn].Remove(subSum[sn][j]);
  1839. }
  1840. }
  1841. }
  1842. //计算成绩年级排名
  1843. AllPoints.Sort(delegate (int s1, int s2) { return s2.CompareTo(s1); });
  1844. ipoint = AllPoints[int.Parse(ip)];
  1845. int m = 0;
  1846. List<List<string>> KeyLine = new List<List<string>>();
  1847. foreach (List<double> points in subSum)
  1848. {
  1849. List<string> detail = new List<string>();
  1850. double sum = points.Count;
  1851. int l = 0;
  1852. for (int mq = 0; mq < points.Count; mq++)
  1853. {
  1854. if (points[i] > ipoint)
  1855. {
  1856. l++;
  1857. }
  1858. }
  1859. double Lines = l;
  1860. detail.Add(Lines.ToString());
  1861. detail.Add(points.Count.ToString());
  1862. var t3 = Math.Floor(Math.Round(decimal.Parse((Lines / sum).ToString("0.000")), 2) * 100);
  1863. detail.Add(t3.ToString());
  1864. KeyLine.Add(detail);
  1865. m++;
  1866. }
  1867. AllKeyLine.Add(KeyLine);
  1868. }
  1869. //年级成就指标
  1870. if (weightSum == 0)
  1871. {
  1872. weightSum = 1;
  1873. }
  1874. double index = CoreAverage.Sum() / weightSum;
  1875. List<List<double>> AveragePoint = new List<List<double>>();
  1876. List<List<double>> AverageClassPoint = new List<List<double>>();
  1877. //List<double> ClassCore = new List<double>();
  1878. int k = AllPoint.Count;
  1879. if (k > 0)
  1880. {
  1881. for (int m = 0; m < AllPoint[0].Count; m++)
  1882. {
  1883. List<double> SubjectAverage = new List<double>();
  1884. for (int n = 0; n < AllPoint[0][m].Count; n++)
  1885. {
  1886. double startPoint = 0;
  1887. for (int f = 0; f < k; f++)
  1888. {
  1889. startPoint = double.Parse(AllPoint[f][m][n]) + startPoint;
  1890. }
  1891. SubjectAverage.Add(startPoint / k);
  1892. }
  1893. AveragePoint.Add(SubjectAverage);
  1894. }
  1895. }
  1896. //每个班级成就指标
  1897. int p = AllPointAverage.Count;
  1898. if (p > 0)
  1899. {
  1900. for (int m = 0; m < AllPointAverage[0].Count; m++)
  1901. {
  1902. List<double> SubjectAverage = new List<double>();
  1903. for (int n = 0; n < AllPointAverage[0][m].Count; n++)
  1904. {
  1905. double startPoint = 0;
  1906. for (int f = 0; f < k; f++)
  1907. {
  1908. startPoint = double.Parse(AllPointAverage[f][m][n]) + startPoint;
  1909. }
  1910. SubjectAverage.Add(startPoint / k);
  1911. }
  1912. AverageClassPoint.Add(SubjectAverage);
  1913. }
  1914. }
  1915. int c = AverageClassPoint.Count;
  1916. List<double> ClassCore = new List<double>();
  1917. if (c > 0)
  1918. {
  1919. for (int j = 0; j < AverageClassPoint[0].Count; j++)
  1920. {
  1921. double startAverage = 0;
  1922. for (int f = 0; f < c; f++)
  1923. {
  1924. startAverage = AverageClassPoint[f][j] + startAverage;
  1925. }
  1926. ClassCore.Add(startAverage / weightSum);
  1927. }
  1928. }
  1929. //班级平均进线率
  1930. int ExamCount = AllKeyLine.Count;
  1931. List<List<double>> KeyLines = new List<List<double>>();
  1932. if (ExamCount > 0)
  1933. {
  1934. for (int m = 0; m < AllKeyLine[0].Count; m++)
  1935. {
  1936. List<double> ClassLine = new List<double>();
  1937. for (int n = 0; n < AllKeyLine[0][m].Count; n++)
  1938. {
  1939. double startPoint = 0;
  1940. for (int f = 0; f < ExamCount; f++)
  1941. {
  1942. startPoint = double.Parse(AllKeyLine[f][m][n]) + startPoint;
  1943. }
  1944. ClassLine.Add(startPoint / ExamCount);
  1945. }
  1946. KeyLines.Add(ClassLine);
  1947. }
  1948. }
  1949. Dictionary<string, object> AveragePointMap = new Dictionary<string, object>
  1950. {
  1951. { "Period",Period},
  1952. { "Grade",Grade},
  1953. { "index", index},
  1954. { "className", classList },
  1955. { "subjectName", subjectList },
  1956. { "AveragePoint", AveragePoint },
  1957. //{ "AverageClassPoint", AverageClassPoint },
  1958. { "ClassCore", ClassCore },
  1959. { "KeyLines",KeyLines}
  1960. };
  1961. map.Add(AveragePointMap);
  1962. }
  1963. }
  1964. //Redis处理结果集
  1965. if (RedisHelper.Instance != null)
  1966. {
  1967. if (!RedisHelper.Exists(CacheCosmosPrefix + method))
  1968. {
  1969. await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), map);
  1970. }
  1971. else
  1972. {
  1973. await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), map);
  1974. await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
  1975. }
  1976. }
  1977. return map;
  1978. }
  1979. catch (Exception e)
  1980. {
  1981. throw new BizException(e.Message);
  1982. }
  1983. }
  1984. }
  1985. }