AchievementController.cs 94 KB

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