AchievementController.cs 73 KB

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