AchievementController.cs 85 KB

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