AchievementController.cs 154 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300
  1. using ClouDASLibx;
  2. using Microsoft.AspNetCore.Mvc;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text.Json;
  7. using System.Threading.Tasks;
  8. using TEAMModelOS.SDK.Models;
  9. using TEAMModelOS.SDK;
  10. using TEAMModelOS.SDK.DI;
  11. using TEAMModelOS.SDK.Extension;
  12. using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
  13. using TEAMModelOS.SDK.Helper.Common.StringHelper;
  14. using TEAMModelOS.SDK.Helper.Security.ShaHash;
  15. using TEAMModelOS.Services.Analysis;
  16. using Microsoft.Extensions.Options;
  17. using TEAMModelOS.Models;
  18. using Azure.Cosmos;
  19. using TEAMModelOS.SDK.Models.Cosmos.Student;
  20. using static TEAMModelOS.SDK.Models.Cosmos.Student.StudentAnalysis;
  21. using TEAMModelOS.SDK.Models.Cosmos.School;
  22. using static TEAMModelOS.SDK.Models.Cosmos.School.ClassAnalysis;
  23. using static TEAMModelOS.SDK.Models.Cosmos.School.GradeAnalysis;
  24. using TEAMModelOS.Models.Dto;
  25. namespace TEAMModelOS.Controllers.Analysis
  26. {
  27. [Route("analysis")]
  28. [ApiController]
  29. public class AchievementController : Controller
  30. {
  31. private readonly AzureCosmosFactory _azureCosmos;
  32. private readonly DingDing _dingDing;
  33. private readonly Option _option;
  34. private const string CacheCosmosPrefix = "Analysis:";
  35. private const int timeoutSeconds = 3600;
  36. public readonly AzureStorageFactory _azureStorage;
  37. public AchievementController(AzureCosmosFactory azureCosmos, DingDing dingDing, IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage)
  38. {
  39. _azureCosmos = azureCosmos;
  40. _dingDing = dingDing;
  41. _option = option?.Value;
  42. _azureStorage = azureStorage;
  43. }
  44. [HttpPost("Achievement")]
  45. public async Task<BaseResponse> FindExam(JsonElement request)
  46. {
  47. ResponseBuilder builder = ResponseBuilder.custom();
  48. Dictionary<string, object> dict = new Dictionary<string, object>();
  49. var emobj = request.EnumerateObject();
  50. while (emobj.MoveNext())
  51. {
  52. dict[emobj.Current.Name] = emobj.Current.Value;
  53. }
  54. Dictionary<string, dynamic> info = new Dictionary<string, dynamic>();
  55. if (RedisHelper.Instance != null)
  56. {
  57. info = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "Achievement",
  58. ShaHashHelper.GetSHA1(dict.ToJsonString()), timeoutSeconds, () => { return FindExamRedis(dict, "Achievement"); });
  59. //数据从redis读取过后进行转换格式
  60. builder.Data(info);
  61. }
  62. else
  63. {
  64. info = await FindExamRedis(dict, "Achievement");
  65. builder.Data(info);
  66. }
  67. return builder.build();
  68. }
  69. public async Task<List<ExamResult>> FindExamResultRedis(Dictionary<string, object> dict, string method)
  70. {
  71. return new List<ExamResult>();
  72. //try
  73. //{
  74. // List<ExamResult> info = await _azureCosmos.FindByDict<ExamResult>(dict);
  75. // if (RedisHelper.Instance != null)
  76. // {
  77. // if (!RedisHelper.Exists(CacheCosmosPrefix + method))
  78. // {
  79. // await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), info);
  80. // }
  81. // else
  82. // {
  83. // await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), info);
  84. // await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
  85. // }
  86. // }
  87. // return info;
  88. //}
  89. //catch (Exception e)
  90. //{
  91. // throw new BizException(e.Message);
  92. //}
  93. }
  94. public async Task<Dictionary<string, dynamic>> FindExamRedis(Dictionary<string, object> dict, string method)
  95. {
  96. ResponseBuilder builder = ResponseBuilder.custom();
  97. //Console.WriteLine(DateTimeOffset.Now.Second);
  98. //
  99. dict.TryGetValue("subjectCode", out object subjectCode);
  100. dict.TryGetValue("code", out object code);
  101. dict.TryGetValue("schoolCode", out object schoolCode);
  102. List<ExamResultDto> exams = new List<ExamResultDto>();
  103. /*if (RedisHelper.Instance != null)
  104. {
  105. exams = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "FindExamResultRedis",
  106. ShaHashHelper.GetSHA1(dict.ToJsonString()), timeoutSeconds, () => { return FindExamResultRedis(dict, "FindExamResultRedis"); });
  107. }
  108. else
  109. {
  110. exams = await FindExamResultRedis(dict, "FindExamResultRedis");
  111. }*/
  112. List<string> subjectCouns = JsonExtensions.ToObject<List<string>>(subjectCode.ToJsonString());
  113. for (int i = 0; i < subjectCouns.Count; i++)
  114. {
  115. if (RedisHelper.Exists(CacheCosmosPrefix + "examResult" + subjectCouns[i]))
  116. {
  117. ExamResultDto result = RedisHelper.HGet<ExamResultDto>(CacheCosmosPrefix + "examResult" + subjectCouns[i], ShaHashHelper.GetSHA1(code.ToString()));
  118. //builder.Data(info);
  119. exams.Add(result);
  120. }
  121. }
  122. Dictionary<string, object> stuMap = new Dictionary<string, object>
  123. {
  124. { "schoolCode", "Habook" }
  125. };
  126. //声明进行标准用来设置进线标准,权重等参数
  127. dict.TryGetValue("Standard", out object Standard);
  128. //List<Student> students = await _azureCosmos.FindByDict<Student>(stuMap);
  129. List<OldStudent> students = null;
  130. if (RedisHelper.Exists(CacheCosmosPrefix + "students"))
  131. {
  132. students = RedisHelper.HGet<List<OldStudent>>(CacheCosmosPrefix + "students", ShaHashHelper.GetSHA1(schoolCode.ToString()));
  133. //builder.Data(info);
  134. //students.Add(student);
  135. }
  136. //Console.WriteLine(DateTimeOffset.Now.Second);
  137. List<Dictionary<string, object>> examList = new List<Dictionary<string, object>>();
  138. HashSet<string> classList = new HashSet<string>();
  139. HashSet<string> classId = new HashSet<string>();
  140. List<string> subjectAverage = new List<string>();
  141. List<List<string>> subjectPoints = new List<List<string>>();
  142. Dictionary<string, object> Average = new Dictionary<string, object>();
  143. Dictionary<string, object> entryTable = new Dictionary<string, object>();
  144. Dictionary<string, dynamic> achievementAnalysis = new Dictionary<string, dynamic>();
  145. List<string> arrSubject = new List<string>();
  146. List<string> keys = new List<string>();
  147. List<string> person = new List<string>();
  148. List<List<double>> subSum = new List<List<double>>();
  149. List<string> gAverage = new List<string>();
  150. List<string> cAverage = new List<string>();
  151. Dictionary<string, object> AclassAverage = new Dictionary<string, object>();
  152. Dictionary<string, object> passRateMap = new Dictionary<string, object>();
  153. List<List<string>> passALL = new List<List<string>>();
  154. List<string> gradeList = new List<string>();
  155. List<string> areaList = new List<string>();
  156. List<string> sbujectsList = new List<string>();
  157. if (exams.IsNotEmpty())
  158. {
  159. //存放进线情况统计key值
  160. keys.Add("name");
  161. keys.Add("className");
  162. keys.Add("gradeRank");
  163. keys.Add("score");
  164. //初始化进行人数
  165. double iPersons = 0;
  166. if (exams.IsNotEmpty())
  167. {
  168. int classLen = exams[0].classes.Count;
  169. for (int cls = 0; cls < classLen; cls++)
  170. {
  171. if (exams[0].classes[cls].TryGetValue(exams[0].classes[cls].Keys.ToArray<string>()[0], out int[] index))
  172. {
  173. List<double> stuScore = new List<double>();
  174. int stdLen = index[1] - index[0] + 1;
  175. for (int i = 0; i < stdLen; i++)
  176. {
  177. stuScore.Add(0);
  178. }
  179. subSum.Add(stuScore);
  180. }
  181. }
  182. }
  183. int xx = 0;
  184. //初始化总分
  185. double sumPoint = 0;
  186. int sumperson = exams[0].ids.Count;
  187. for (int i = 0; i < exams[0].ids.Count; i++)
  188. {
  189. if (exams[0].ids[i].Equals("0"))
  190. {
  191. sumperson--;
  192. }
  193. }
  194. exams.ForEach(e =>
  195. {
  196. //获取总分数
  197. e.result.ForEach(r =>
  198. {
  199. sumPoint += r.Sum();
  200. });
  201. });
  202. var gradeAverage = sumPoint / sumperson;
  203. //存放年级平均
  204. gAverage.Add(gradeAverage.ToString());
  205. //任意一次考试数据提取班级信息
  206. List<Dictionary<string, int[]>> classToName = exams[0].classes;
  207. //任意一次考试数据提取学生ID信息
  208. List<string> idToName = exams[0].ids;
  209. //var gradeAverage = Math.Floor(Math.Round(decimal.Parse((10 / 3).ToString("0.000")), 2));
  210. List<string> subjects = new List<string>();
  211. exams.ForEach(e =>
  212. {
  213. int peopleCount = 0;
  214. Dictionary<string, object> detail = new Dictionary<string, object>
  215. {
  216. { "name", e.subjectCode }
  217. };
  218. subjects.Add(e.subjectCode);
  219. List<string> ClassAverage = new List<string>();
  220. //计算试卷总分
  221. double sum = e.point.Sum();
  222. //及格分数
  223. double passRate = sum * 0.6;
  224. int gradeCount = 0;
  225. //初始化科目总分
  226. double subjectPoint = 0;
  227. //科目平均分
  228. double subAverage = 0;
  229. //计算班级平均分
  230. int classIndex = 0;
  231. List<string> passList = new List<string>();
  232. e.classes.ForEach(c =>
  233. {
  234. List<List<string>> classPRL = new List<List<string>>();
  235. //初始化班级总分
  236. double classPoint = 0;
  237. //初始化班级缺考人数
  238. int classCount = 0;
  239. //初始化班级平均分
  240. double points = 0;
  241. double passPoint = 0;
  242. //初始化及格人数
  243. int passCount = 0;
  244. //初始化各班参考人数
  245. int counts = 0;
  246. //c.Keys遍历key值
  247. foreach (string key in c.Keys)
  248. {
  249. classList.Add(key);
  250. }
  251. //每个班级平均分
  252. foreach (int[] value in c.Values)
  253. {
  254. for (int i = value[0]; i <= value[1]; i++)
  255. {
  256. //初始化学生单科个人得分
  257. double stuPoints = e.result[i].Sum();
  258. //Console.WriteLine("xx: "+xx+" classIndex:" + classIndex + ",i:" + i + " value[0]:" + value[0]+ " value[0]:" + value[1]);
  259. subSum[classIndex][i - value[0]] = stuPoints + subSum[classIndex][i - value[0]];
  260. if (stuPoints > passRate)
  261. {
  262. passCount++;
  263. gradeCount++;
  264. }
  265. classPoint += e.result[i].Sum();
  266. if (e.result[i].Sum() == 0)
  267. {
  268. classCount++;
  269. }
  270. }
  271. //每个班级实际参考人数
  272. counts = value[1] - value[0] - classCount + 1;
  273. points = Convert.ToDouble(classPoint) / counts;
  274. ClassAverage.Add(points.ToString("0.00"));
  275. person.Add(counts + "");
  276. }
  277. passPoint = Convert.ToDouble(passCount) / counts;
  278. passList.Add(passPoint.ToString("0.00"));
  279. //classPRM.Add(classPRL);
  280. classIndex += 1;
  281. });
  282. //科目平均分
  283. ClassAverage.ForEach(a =>
  284. {
  285. subjectPoint += Convert.ToDouble(a);
  286. });
  287. subAverage = subjectPoint / ClassAverage.Count();
  288. subjectAverage.Add(subAverage.ToString("0.00"));
  289. detail.Add("schoolAverage", subAverage.ToString("0.00"));
  290. detail.Add("areaAverage", subAverage.ToString("0.00"));
  291. detail.Add("score", ClassAverage);
  292. examList.Add(detail);
  293. //获取实际参考总人数
  294. e.ids.ForEach(i =>
  295. {
  296. if (!i.Equals("0"))
  297. {
  298. peopleCount++;
  299. }
  300. });
  301. //班级及格率
  302. passALL.Add(passList);
  303. //年级及格率
  304. double gradePass = Convert.ToDouble(gradeCount) / peopleCount;
  305. gradeList.Add(gradePass.ToString("0.00"));
  306. //passALL.Add(gradeList);
  307. //区级及格率
  308. //passALL.Add(areaList);
  309. //获取进线人数
  310. iPersons = peopleCount * 0.4;
  311. //计算每个学生单科成绩
  312. for (int i = 0; i < e.ids.Count(); i++)
  313. {
  314. List<string> info = new List<string>();
  315. //info = new List<string>();
  316. info.Add(e.ids[i]);
  317. info.Add(e.subjectCode);
  318. info.Add(e.result[i].Sum() + "");
  319. //classId.Add(e.Ids[i]);
  320. subjectPoints.Add(info);
  321. }
  322. keys.Add(e.subjectCode);
  323. xx += 1;
  324. //subjectPoints = GetMark(e.Result,e.Ids);
  325. });
  326. //subjectPoints.ForEach(f => f.GroupBy(f[0]));
  327. //进线情况统计
  328. Dictionary<string, List<List<string>>> dicts = new Dictionary<string, List<List<string>>>();
  329. foreach (IGrouping<string, List<string>> group in subjectPoints.GroupBy(c => c[0]))
  330. {
  331. dicts.Add(group.Key, group.ToList());
  332. };
  333. Average.Add("classList", classList);
  334. List<List<string>> sp = new List<List<string>>();
  335. //Dictionary<string, int> rankScore = new Dictionary<string, int>();
  336. List<double> rankScore = new List<double>();
  337. foreach (string key in dicts.Keys)
  338. {
  339. double score = 0;
  340. List<string> values = new List<string>();
  341. keys.ForEach(x =>
  342. {
  343. values.Add("-");
  344. });
  345. foreach (List<string> val in dicts[key])
  346. {
  347. int index = keys.IndexOf(val[1]);
  348. values[index] = val[2];
  349. values[keys.IndexOf("name")] = val[0];
  350. score += double.Parse(val[2]);
  351. values[keys.IndexOf("score")] = score + "";
  352. }
  353. rankScore.Add(score);
  354. sp.Add(values);
  355. }
  356. AchievementService.ReName(sp, idToName, classToName, students);
  357. //处理人数为整
  358. string ip = iPersons.ToString("0");
  359. //初始化进线分数
  360. double ipoint = 0;
  361. //计算成绩年级排名
  362. rankScore.Sort(delegate (double s1, double s2) { return s2.CompareTo(s1); });
  363. ipoint = rankScore[int.Parse(ip)];
  364. foreach (List<string> rank in sp)
  365. {
  366. int index = rankScore.IndexOf(double.Parse(rank[3]));
  367. rank[2] = (index + 1) + "";
  368. }
  369. //排除成绩为零的选手
  370. for (int i = sp.Count - 1; i >= 0; i--)
  371. {
  372. if (sp[i][0].Equals("0"))
  373. {
  374. sp.Remove(sp[i]);
  375. }
  376. }
  377. entryTable.Add("keys", keys);
  378. entryTable.Add("datas", sp);
  379. //封装进线人数统计
  380. List<string> keyLine = new List<string>
  381. {
  382. "gradeRank",
  383. "name",
  384. "entryNum",
  385. "totalNum",
  386. "overAverageRate"
  387. };
  388. Dictionary<string, object> entryLineBar = new Dictionary<string, object>();
  389. //存放班级信息
  390. List<string> className = new List<string>();
  391. foreach (string cla in classList)
  392. {
  393. className.Add(cla);
  394. }
  395. List<List<string>> datas = new List<List<string>>();
  396. //记录各个班级进线率占比
  397. List<string> persent = new List<string>();
  398. int m = 0;
  399. foreach (List<double> points in subSum)
  400. {
  401. List<string> detail = new List<string>();
  402. keyLine.ForEach(x =>
  403. {
  404. detail.Add("-");
  405. });
  406. double sum = points.Count;
  407. int j = 0;
  408. for (int i = 0; i < points.Count; i++)
  409. {
  410. if (points[i] > ipoint)
  411. {
  412. j++;
  413. }
  414. }
  415. double Lines = j;
  416. detail[1] = className[m].ToString();
  417. detail[2] = j.ToString();
  418. detail[3] = points.Count.ToString();
  419. var t3 = Math.Floor(Math.Round(decimal.Parse((Lines / sum).ToString("0.000")), 2) * 100);
  420. persent.Add(t3.ToString());
  421. detail[4] = t3.ToString();
  422. datas.Add(detail);
  423. m++;
  424. }
  425. persent.Sort(delegate (string s1, string s2) { return int.Parse(s2).CompareTo(int.Parse(s1)); });
  426. //存放班级的年级排名
  427. List<string> ranks = new List<string>();
  428. foreach (List<string> des in datas)
  429. {
  430. int index = persent.IndexOf(des[4]);
  431. des[0] = (index + 1).ToString();
  432. ranks.Add((index + 1).ToString());
  433. }
  434. //预警统计
  435. Dictionary<string, object> early = new Dictionary<string, object>();
  436. List<List<string>> earlyWarning = new List<List<string>>();
  437. List<string> keyWarning = new List<string>
  438. {
  439. "classId",
  440. "totalNum",
  441. "average",
  442. "standardDeviation",
  443. "overAverageRate",
  444. "gradeRank"
  445. };
  446. int n = 0;
  447. foreach (List<double> points in subSum)
  448. {
  449. double sum = 0;
  450. List<string> classInfo = new List<string>();
  451. classInfo.Add(className[n]);
  452. classInfo.Add(points.Count.ToString());
  453. foreach (int point in points)
  454. {
  455. sum += point;
  456. }
  457. double Aver = sum / points.Count;
  458. classInfo.Add(Aver.ToString());
  459. //存放班级平均
  460. cAverage.Add(Aver.ToString());
  461. //标准差
  462. double powSum = 0;
  463. foreach (int point in points)
  464. {
  465. powSum += Math.Pow(point - Aver, 2);
  466. }
  467. var pow = Math.Pow(powSum / points.Count, 0.5);
  468. classInfo.Add(pow.ToString("0.00"));
  469. //超均率
  470. var super = (sum - (sum - 100)) / (sum - 100);
  471. classInfo.Add(super.ToString("0.00"));
  472. //年级排名
  473. classInfo.Add(ranks[n]);
  474. earlyWarning.Add(classInfo);
  475. n++;
  476. }
  477. //sbujectsList.Add(subjects);
  478. passRateMap.Add("subjects", subjects);
  479. passRateMap.Add("class", passALL);
  480. passRateMap.Add("grade", gradeList);
  481. passRateMap.Add("area", areaList);
  482. //passRate.Add("passRate", passALL);
  483. early.Add("keys", keyWarning);
  484. early.Add("datas", earlyWarning);
  485. AclassAverage = AchievementService.GetAverage(exams, gAverage, cAverage, subSum, students);
  486. List<Dictionary<string, object>> rankPR = AchievementService.GetPR(exams, subSum, students);
  487. entryLineBar.Add("keys", keyLine);
  488. entryLineBar.Add("datas", datas);
  489. //sp.Sort(delegate (string s1, string s2) { return int.Parse(s1).CompareTo(int.Parse(s2)); });
  490. Average.Add("subjectAverage", subjectAverage);
  491. Average.Add("datas", examList);
  492. achievementAnalysis.Add("passRate", passRateMap);
  493. achievementAnalysis.Add("average", Average);
  494. achievementAnalysis.Add("entryLineBar", entryLineBar);
  495. achievementAnalysis.Add("entryTable", entryTable);
  496. achievementAnalysis.Add("earlyWarning", early);
  497. achievementAnalysis.Add("rankPR", rankPR);
  498. achievementAnalysis.Add("stuAverage", AclassAverage);
  499. //Redis处理结果集
  500. if (RedisHelper.Instance != null)
  501. {
  502. if (!RedisHelper.Exists(CacheCosmosPrefix + method))
  503. {
  504. await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), achievementAnalysis);
  505. }
  506. else
  507. {
  508. await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), achievementAnalysis);
  509. await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
  510. }
  511. }
  512. return achievementAnalysis;
  513. }
  514. else return achievementAnalysis;
  515. }
  516. /* public List<string> GetMark(List<List<int>> point,List<string> ids) {
  517. List<string> info = null;
  518. for (int i = 0;i <= ids.Count();i++) {
  519. info = new List<string>();
  520. info.Add(ids[i]);
  521. info.Add(point[i].Sum()+"");
  522. }
  523. return info;
  524. }*/
  525. [HttpPost("PointAnalysis")]
  526. public async Task<BaseResponse> PointAnalysis(JsonElement request)
  527. {
  528. ResponseBuilder builder = ResponseBuilder.custom();
  529. /*Dictionary<string, object> dict = new Dictionary<string, object>();
  530. var emobj = request.EnumerateObject();
  531. while (emobj.MoveNext())
  532. {
  533. dict[emobj.Current.Name] = emobj.Current.Value;
  534. }
  535. List<Dictionary<string, dynamic>> info = new List<Dictionary<string, dynamic>>();
  536. if (RedisHelper.Instance != null)
  537. {
  538. info = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "PointAnalysis",
  539. ShaHashHelper.GetSHA1(dict.ToJsonString()), timeoutSeconds, () => { return FindPointAnalysisRedis(dict, "PointAnalysis"); });
  540. //数据从redis读取过后进行转换格式
  541. builder.Data(info);
  542. }
  543. else
  544. {
  545. info = await FindPointAnalysisRedis(dict, "PointAnalysis");
  546. builder.Data(info);
  547. }*/
  548. return builder.build();
  549. }
  550. [HttpPost("ExerciseScatter")]
  551. public async Task<BaseResponse> ExerciseScatter(JsonElement request)
  552. {
  553. /* ResponseBuilder builder = ResponseBuilder.custom();
  554. Dictionary<string, object> dict = new Dictionary<string, object>();
  555. var emobj = request.EnumerateObject();
  556. while (emobj.MoveNext())
  557. {
  558. dict[emobj.Current.Name] = emobj.Current.Value;
  559. }
  560. List<Dictionary<string, dynamic>> info = new List<Dictionary<string, dynamic>>();
  561. if (RedisHelper.Instance != null)
  562. {
  563. info = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "ExerciseScatter",
  564. ShaHashHelper.GetSHA1(dict.ToJsonString()), timeoutSeconds, () => { return FindExerciseScatterRedis(dict, "ExerciseScatter"); });
  565. //数据从redis读取过后进行转换格式
  566. builder.Data(info);
  567. }
  568. else
  569. {
  570. info = await FindExerciseScatterRedis(dict, "ExerciseScatter");
  571. builder.Data(info);
  572. }*/
  573. return null;
  574. }
  575. public async Task<Dictionary<string, dynamic>> FindKnowledgePointRedis(Dictionary<string, object> dict, string method)
  576. {
  577. //ResponseBuilder builder = ResponseBuilder.custom();
  578. dict.TryGetValue("subjectCode", out object subjectCode);
  579. dict.TryGetValue("schoolCode", out object schoolCode);
  580. dict.TryGetValue("code", out object code);
  581. //dict.TryGetValue("scopeCode", out object scopeCode);
  582. /* Dictionary<string, object> sub = new Dictionary<string, object>
  583. {
  584. { "subjectCode", subjectCode.ToString()},
  585. { "code",code.ToString()}
  586. };
  587. Dictionary<string, object> examMap = new Dictionary<string, object>
  588. {
  589. { "schoolCode", schoolCode.ToString()},
  590. { "code", code.ToString()},
  591. { "subjectCode", subjectCode.ToString()}
  592. };*/
  593. List<ExamResultDto> exams = new List<ExamResultDto>();
  594. if (RedisHelper.Exists(CacheCosmosPrefix + "examResult" + subjectCode.ToString()))
  595. {
  596. ExamResultDto res = RedisHelper.HGet<ExamResultDto>(CacheCosmosPrefix + "examResult" + subjectCode.ToString(), ShaHashHelper.GetSHA1(code.ToString()));
  597. exams.Add(res);
  598. }
  599. List<PaperDto> paper = new List<PaperDto>();
  600. if (RedisHelper.Exists(CacheCosmosPrefix + "paperInfo" + subjectCode.ToString()))
  601. {
  602. PaperDto papers = RedisHelper.HGet<PaperDto>(CacheCosmosPrefix + "paperInfo" + subjectCode.ToString(), ShaHashHelper.GetSHA1(code.ToString()));
  603. paper.Add(papers);
  604. }
  605. Dictionary<string, object> stuMap = new Dictionary<string, object>
  606. {
  607. { "schoolCode", "Habook" }
  608. };
  609. //List<Student> students = await azureCosmosDBRepository.FindByDict<Student>(stuMap);
  610. List<OldStudent> students = null;
  611. if (RedisHelper.Exists(CacheCosmosPrefix + "students"))
  612. {
  613. students = RedisHelper.HGet<List<OldStudent>>(CacheCosmosPrefix + "students", ShaHashHelper.GetSHA1(schoolCode.ToString()));
  614. //builder.Data(info);
  615. //students.Add(student);
  616. }
  617. HashSet<string> knowledge = new HashSet<string>();
  618. HashSet<string> area = new HashSet<string>();
  619. List<double> point = new List<double>();
  620. List<List<double>> result = new List<List<double>>();
  621. List<Dictionary<string, int[]>> classes = new List<Dictionary<string, int[]>>();
  622. List<string> ids = new List<string>();
  623. //string Type = "";
  624. if (dict.TryGetValue("type", out object Type))
  625. {
  626. /*paper.ForEach(p =>
  627. {
  628. p.item.ForEach(i =>
  629. {
  630. knowledge.Add(i.field);
  631. area.Add(i.field);
  632. });
  633. });*/
  634. knowledge.Add("知识");
  635. knowledge.Add("理解");
  636. knowledge.Add("应用");
  637. knowledge.Add("分析");
  638. knowledge.Add("综合");
  639. knowledge.Add("评鉴");
  640. area.Add("知识");
  641. area.Add("理解");
  642. area.Add("应用");
  643. area.Add("分析");
  644. area.Add("综合");
  645. area.Add("评鉴");
  646. }
  647. else
  648. {
  649. paper.ForEach(p =>
  650. {
  651. p.item.ForEach(i =>
  652. {
  653. i.points.ForEach(o =>
  654. {
  655. knowledge.Add(o);
  656. });
  657. area.Add(i.field);
  658. });
  659. });
  660. }
  661. double Qnum = 0;
  662. //确定高分组 低分组人数
  663. List<List<double>> re = exams[0].result;
  664. List<double> resultSum = new List<double>();
  665. foreach (List<double> data in re)
  666. {
  667. resultSum.Add(data.Sum());
  668. }
  669. //确定高分组 最低分数
  670. resultSum.Sort(delegate (double s1, double s2) { return s2.CompareTo(s1); });
  671. for (int i = resultSum.Count - 1; i >= 0; i--)
  672. {
  673. if (resultSum[i] == 0)
  674. {
  675. resultSum.Remove(resultSum[i]);
  676. }
  677. }
  678. double rhwCount = resultSum.Count * 0.27;
  679. double rhw = resultSum[int.Parse(rhwCount.ToString("0"))];
  680. //确定低分组 最高分数
  681. resultSum.Sort(delegate (double s1, double s2) { return s1.CompareTo(s2); });
  682. double rhlCount = resultSum.Count * 0.27;
  683. double rhl = resultSum[int.Parse(rhwCount.ToString("0"))];
  684. foreach (ExamResultDto ex in exams)
  685. {
  686. point = ex.point;
  687. result = ex.result;
  688. classes = ex.classes;
  689. ids = ex.ids;
  690. }
  691. /* exams.ForEach(e =>
  692. {
  693. point = e.Point;
  694. result = e.Result;
  695. classes = e.Classes;
  696. ids = e.Ids;
  697. });*/
  698. List<string> knowledgeName = new List<string>();
  699. foreach (string cla in knowledge)
  700. {
  701. knowledgeName.Add(cla);
  702. }
  703. for (int k = 0; k < knowledgeName.Count; k++)
  704. {
  705. if (null == knowledgeName[k])
  706. {
  707. knowledgeName.Remove(knowledgeName[k]);
  708. }
  709. }
  710. List<string> areaName = new List<string>();
  711. foreach (string cla in area)
  712. {
  713. areaName.Add(cla);
  714. }
  715. for (int k = 0; k < areaName.Count; k++)
  716. {
  717. if (null == areaName[k])
  718. {
  719. areaName.Remove(areaName[k]);
  720. }
  721. }
  722. //初始化年级总分
  723. double total = 0;
  724. //处理年级单个知识点得分率
  725. foreach (List<double> grade in result)
  726. {
  727. total += grade.Sum();
  728. }
  729. foreach (string id in ids)
  730. {
  731. if (!id.Equals("0"))
  732. {
  733. Qnum++;
  734. }
  735. }
  736. //试卷总分
  737. double TotalPoint = point.Sum();
  738. //计算认知层次占比
  739. List<string> fper = new List<string>();
  740. for (int a = 0; a < areaName.Count; a++)
  741. {
  742. double fieldPoint = 0;
  743. paper.ForEach(p =>
  744. {
  745. int n = 0;
  746. p.item.ForEach(i =>
  747. {
  748. if (i.field != null && i.field.Contains(areaName[a]))
  749. {
  750. fieldPoint += point[n];
  751. }
  752. n++;
  753. });
  754. });
  755. double fieldPersent = fieldPoint / TotalPoint;
  756. fper.Add(fieldPersent.ToString("0.00"));
  757. }
  758. //求单个知识点所占分数
  759. List<string> per = new List<string>();
  760. List<string> gper = new List<string>();
  761. List<string> knowPer = new List<string>();
  762. List<Dictionary<string, double>> eper = new List<Dictionary<string, double>>();
  763. Dictionary<string, object> knowledgeALL = new Dictionary<string, object>();
  764. Dictionary<string, object> knowledgeMap = new Dictionary<string, object>();
  765. Dictionary<string, object> classMap = new Dictionary<string, object>();
  766. Dictionary<string, object> wrongMap = new Dictionary<string, object>();
  767. HashSet<string> className = new HashSet<string>();
  768. List<List<string>> wrongPersent = new List<List<string>>();
  769. List<string> key = new List<string>
  770. {
  771. "id",
  772. "className",
  773. "seatNO",
  774. "point",
  775. "anwPoint",
  776. "persent"
  777. };
  778. List<string> keyWrong = new List<string>
  779. {
  780. "name",
  781. "point",
  782. "itemNO",
  783. "persent",
  784. "wrong",
  785. "rhw",
  786. "rlw"
  787. };
  788. for (int k = 0; k < knowledgeName.Count; k++)
  789. {
  790. List<string> knowledgeClass = new List<string>();
  791. List<List<string>> stuPersent = new List<List<string>>();
  792. double OnePoint = 0;
  793. //获取每个知识点占有多少分值
  794. double ePoint = 0;
  795. double anwGPoint = 0;
  796. double poG = 0;
  797. int m = 0;
  798. List<string> valuew = new List<string>();
  799. List<string> itemNo = new List<string>();
  800. keyWrong.ForEach(x =>
  801. {
  802. valuew.Add("-");
  803. });
  804. int wrongCount = 0;
  805. valuew[0] = knowledgeName[k];
  806. paper.ForEach(p =>
  807. {
  808. int n = 0;
  809. if (dict.TryGetValue("type", out object Type))
  810. {
  811. p.item.ForEach(i =>
  812. {
  813. if (i.field != null && i.field.Contains(knowledgeName[k]))
  814. {
  815. OnePoint += point[n];
  816. itemNo.Add((n + 1).ToString());
  817. }
  818. n++;
  819. });
  820. }
  821. else
  822. {
  823. p.item.ForEach(i =>
  824. {
  825. if (i.points != null && i.points.Contains(knowledgeName[k]))
  826. {
  827. OnePoint += 1 / Convert.ToDouble(i.points.Count) * point[n];
  828. itemNo.Add((n + 1).ToString());
  829. }
  830. n++;
  831. });
  832. }
  833. valuew[1] = OnePoint.ToString();
  834. string itemNos = "";
  835. if (itemNo.Count > 0)
  836. {
  837. foreach (string index in itemNo)
  838. {
  839. itemNos += index + ",";
  840. }
  841. valuew[2] = itemNos[0..^1];
  842. }
  843. else
  844. {
  845. valuew[2] = itemNos;
  846. }
  847. });
  848. int rhwC = 0;
  849. int rhlC = 0;
  850. foreach (string id in ids)
  851. {
  852. if (id.Equals("0") || result[m].Sum() == 0)
  853. {
  854. m++;
  855. continue;
  856. }
  857. List<string> values = new List<string>();
  858. key.ForEach(x =>
  859. {
  860. values.Add("-");
  861. });
  862. foreach (OldStudent info in students)
  863. {
  864. if (info.studentId.Equals(id))
  865. {
  866. values[2] = info.seatNo.ToString();
  867. break;
  868. }
  869. }
  870. //List<string> stu = new List<string>();
  871. values[0] = id;
  872. values[1] = "-";
  873. //List<List<string>> stuItem = new List<List<string>>();
  874. int statuCount = 0;
  875. paper.ForEach(p =>
  876. {
  877. int n = 0;
  878. double anwPoint = 0;
  879. double po = 0;
  880. p.item.ForEach(i =>
  881. {
  882. if (dict.TryGetValue("type", out object Type))
  883. {
  884. if (i.field != null && i.field.Contains(knowledgeName[k]))
  885. {
  886. //Dictionary<string, double> mapkeyItem = new Dictionary<string, double>();
  887. //OnePoint += 1 / Convert.ToDouble(i.points.Count) * point[n];
  888. //当前认知层次在该题占比多少
  889. ePoint = 1;
  890. anwPoint += result[m][n] * ePoint;
  891. //所有学生单个认知层次得分情况
  892. anwGPoint += result[m][n] * ePoint;
  893. po += point[n] * ePoint;
  894. //认知层次所占分数
  895. poG += point[n] * ePoint;
  896. if (result[m][n] == 0 && statuCount == 0)
  897. {
  898. statuCount++;
  899. wrongCount++;
  900. if (result[m].Sum() >= rhw)
  901. {
  902. rhwC++;
  903. }
  904. if (result[m].Sum() <= rhl)
  905. {
  906. rhlC++;
  907. }
  908. }
  909. }
  910. n++;
  911. }
  912. else
  913. {
  914. if (i.points != null && i.points.Contains(knowledgeName[k]))
  915. {
  916. //Dictionary<string, double> mapkeyItem = new Dictionary<string, double>();
  917. //OnePoint += 1 / Convert.ToDouble(i.points.Count) * point[n];
  918. //当前知识点在该题占比多少
  919. ePoint = 1 / Convert.ToDouble(i.points.Count);
  920. anwPoint += result[m][n] * ePoint;
  921. //所有学生单个知识点得分情况
  922. anwGPoint += result[m][n] * ePoint;
  923. po += point[n] * ePoint;
  924. //知识点所占分数
  925. poG += point[n] * ePoint;
  926. if (result[m][n] == 0 && statuCount == 0)
  927. {
  928. statuCount++;
  929. wrongCount++;
  930. if (result[m].Sum() >= rhw)
  931. {
  932. rhwC++;
  933. }
  934. if (result[m].Sum() <= rhl)
  935. {
  936. rhlC++;
  937. }
  938. }
  939. }
  940. n++;
  941. }
  942. });
  943. if (po == 0)
  944. {
  945. values[3] = "0";
  946. values[4] = "0";
  947. values[5] = "0";
  948. }
  949. else
  950. {
  951. double stuPser = anwPoint / po;
  952. values[3] = po.ToString();
  953. values[4] = anwPoint.ToString();
  954. values[5] = stuPser.ToString("0.00");
  955. }
  956. //stuItem.Add(values);
  957. });
  958. stuPersent.Add(values);
  959. m++;
  960. }
  961. AchievementService.ReName(stuPersent, ids, classes, students);
  962. double knowPser = 0;
  963. if (poG == 0)
  964. {
  965. knowPer.Add("0");
  966. }
  967. else
  968. {
  969. knowPser = anwGPoint / poG;
  970. knowPer.Add(knowPser.ToString("0.00"));
  971. }
  972. //错题关系表
  973. valuew[3] = knowPser.ToString("0.00");
  974. valuew[4] = wrongCount.ToString();
  975. valuew[5] = rhwC.ToString();
  976. valuew[6] = rhlC.ToString();
  977. wrongPersent.Add(valuew);
  978. knowledgeMap.Add(knowledgeName[k], stuPersent);
  979. //知识点占比
  980. double persent = OnePoint / TotalPoint;
  981. foreach (Dictionary<string, int[]> map in classes)
  982. {
  983. List<string> classPoints = new List<string>();
  984. //初始化班级得分
  985. double anwCPoint = 0;
  986. double cpo = 0;
  987. foreach (KeyValuePair<string, int[]> kvp in map)
  988. {
  989. className.Add(kvp.Key);
  990. for (int n = kvp.Value[0]; n < kvp.Value[1]; n++)
  991. {
  992. if (result[n].Sum() == 0) continue;
  993. paper.ForEach(p =>
  994. {
  995. int x = 0;
  996. p.item.ForEach(i =>
  997. {
  998. if (dict.TryGetValue("type", out object Type))
  999. {
  1000. if (i.field != null && i.field.Contains(knowledgeName[k]))
  1001. {
  1002. //当前认知层次在该题占比多少
  1003. ePoint = 1;
  1004. anwCPoint += result[n][x] * ePoint;
  1005. cpo += point[x] * ePoint;
  1006. }
  1007. x++;
  1008. }
  1009. else
  1010. {
  1011. if (i.points != null && i.points.Contains(knowledgeName[k]))
  1012. {
  1013. //当前知识点在该题占比多少
  1014. ePoint = 1 / Convert.ToDouble(i.points.Count);
  1015. anwCPoint += result[n][x] * ePoint;
  1016. cpo += point[x] * ePoint;
  1017. }
  1018. x++;
  1019. }
  1020. });
  1021. });
  1022. }
  1023. }
  1024. if (cpo == 0)
  1025. {
  1026. //double classPser = anwCPoint / cpo;
  1027. knowledgeClass.Add("0");
  1028. }
  1029. else
  1030. {
  1031. double classPser = anwCPoint / cpo;
  1032. knowledgeClass.Add(classPser.ToString("0.00"));
  1033. }
  1034. }
  1035. classMap.Add(knowledgeName[k], knowledgeClass);
  1036. per.Add(persent.ToString("0.00"));
  1037. }
  1038. knowledgeMap.Add("grade", knowPer);
  1039. knowledgeMap.Add("keys", key);
  1040. classMap.Add("className", className);
  1041. wrongMap.Add("keys", keyWrong);
  1042. wrongMap.Add("datas", wrongPersent);
  1043. knowledgeALL.Add("pointList", knowledgeName);
  1044. knowledgeALL.Add("per", per);
  1045. knowledgeALL.Add("level", areaName);
  1046. knowledgeALL.Add("fper", fper);
  1047. knowledgeALL.Add("stupercent", knowledgeMap);
  1048. knowledgeALL.Add("classpercent", classMap);
  1049. knowledgeALL.Add("wrong", wrongMap);
  1050. //builder.Data(knowledgeALL);
  1051. //Redis处理结果集
  1052. if (RedisHelper.Instance != null)
  1053. {
  1054. if (!RedisHelper.Exists(CacheCosmosPrefix + method))
  1055. {
  1056. await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), knowledgeALL);
  1057. }
  1058. else
  1059. {
  1060. await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), knowledgeALL);
  1061. await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
  1062. }
  1063. }
  1064. return knowledgeALL;
  1065. }
  1066. [HttpPost("knowledgePoint")]
  1067. public async Task<BaseResponse> KnowledgePoint(JsonElement request)
  1068. {
  1069. ResponseBuilder builder = ResponseBuilder.custom();
  1070. Dictionary<string, object> dict = new Dictionary<string, object>();
  1071. var emobj = request.EnumerateObject();
  1072. while (emobj.MoveNext())
  1073. {
  1074. dict[emobj.Current.Name] = emobj.Current.Value;
  1075. }
  1076. Dictionary<string, dynamic> info = new Dictionary<string, dynamic>();
  1077. if (RedisHelper.Instance != null)
  1078. {
  1079. info = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "knowledgePoint",
  1080. ShaHashHelper.GetSHA1(dict.ToJsonString()), timeoutSeconds, () => { return FindKnowledgePointRedis(dict, "knowledgePoint"); });
  1081. //数据从redis读取过后进行转换格式
  1082. builder.Data(info);
  1083. }
  1084. else
  1085. {
  1086. info = await FindKnowledgePointRedis(dict, "knowledgePoint");
  1087. builder.Data(info);
  1088. }
  1089. return builder.build();
  1090. }
  1091. [HttpPost("FindExamInfo")]
  1092. public async Task<BaseResponse> FindExamInfo(JsonElement request)
  1093. {
  1094. ResponseBuilder builder = ResponseBuilder.custom();
  1095. Dictionary<string, object> dict = new Dictionary<string, object>();
  1096. var emobj = request.EnumerateObject();
  1097. while (emobj.MoveNext())
  1098. {
  1099. dict[emobj.Current.Name] = emobj.Current.Value;
  1100. }
  1101. if (RedisHelper.Instance != null)
  1102. {
  1103. try
  1104. {
  1105. ///RedisHelper.Instance.CurrentSerialize = obj => System.Text.Json.JsonSerializer.Serialize(obj);
  1106. /// RedisHelper.Instance.CurrentDeserialize = (json, type) => System.Text.Json.JsonSerializer.Deserialize(json, type);
  1107. List<ExamInfoDto> info = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "FindExamInfo",
  1108. ShaHashHelper.GetSHA1(dict.ToJsonString()), timeoutSeconds, () => { return FindExamInfoRedis(dict, "FindExamInfo"); });
  1109. builder.Data(info);
  1110. }
  1111. catch (Exception e)
  1112. {
  1113. // throw new BizException(e.Message);
  1114. }
  1115. }
  1116. else
  1117. {
  1118. List<ExamInfoDto> info = await FindExamInfoRedis(dict, "FindExamInfo");
  1119. builder.Data(info);
  1120. }
  1121. return builder.build();
  1122. }
  1123. public async Task<List<ExamInfoDto>> FindExamInfoRedis(Dictionary<string, object> dict, string method)
  1124. {
  1125. return new List<ExamInfoDto>();
  1126. //{
  1127. // List<ExamInfoDto> info = await _azureCosmos.FindByDict<ExamInfoDto>(dict);
  1128. // List<ExamResultDto> exams = new List<ExamResultDto>();
  1129. // for (int i = 0; i < info.Count; i++) {
  1130. // for (int j = 0; j < info[i].conditions.subject.Count; j++)
  1131. // {
  1132. // if (RedisHelper.Exists(CacheCosmosPrefix + "examResult" + info[i].conditions.subject[j]))
  1133. // {
  1134. // ExamResultDto result = RedisHelper.HGet<ExamResultDto>(CacheCosmosPrefix + "examResult" + info[i].conditions.subject[j], ShaHashHelper.GetSHA1(info[i].examCode.ToString()));
  1135. // //builder.Data(info);
  1136. // exams.Add(result);
  1137. // }
  1138. // }
  1139. // //初始化总分
  1140. // double sumPoint = 0;
  1141. // for (int k = 0; k < exams.Count; k++) {
  1142. // for (int n = exams[k].ids.Count - 1; n >= 0;n--)
  1143. // {
  1144. // if (exams[k].ids[n].Equals("0"))
  1145. // {
  1146. // exams[k].ids.Remove(exams[k].ids[n]);
  1147. // }
  1148. // }
  1149. // //获取总分数
  1150. // exams[k].result.ForEach(r =>
  1151. // {
  1152. // sumPoint += r.Sum();
  1153. // });
  1154. // info[i].realCount = exams[k].ids.Count;
  1155. // }
  1156. // info[i].piont = sumPoint / info[i].realCount;
  1157. // //目前单次考试权重关系和权重次数
  1158. // info[i].index = info[i].piont * 1 / 1;
  1159. // }
  1160. // if (RedisHelper.Instance != null)
  1161. // {
  1162. // if (!RedisHelper.Exists(CacheCosmosPrefix + method))
  1163. // {
  1164. // await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), info);
  1165. // }
  1166. // else
  1167. // {
  1168. // await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), info);
  1169. // await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
  1170. // }
  1171. // }
  1172. // return info;
  1173. //}
  1174. //catch (Exception e)
  1175. //{
  1176. // throw new BizException(e.Message);
  1177. //}
  1178. }
  1179. [HttpPost("FindExamPaper")]
  1180. public BaseResponse FindExamPaper(JsonElement request)
  1181. {
  1182. //Dictionary<string, object> dict = new Dictionary<string, object>();
  1183. /* var emobj = request.EnumerateObject();
  1184. while (emobj.MoveNext())
  1185. {
  1186. dict[emobj.Current.Name] = emobj.Current.Value;
  1187. }*/
  1188. request.TryGetProperty("subjectCode", out JsonElement subjectCode);
  1189. request.TryGetProperty("code", out JsonElement code);
  1190. /*dict.TryGetValue("subjectCode", out object subjectCode);
  1191. dict.TryGetValue("code", out object code);*/
  1192. ResponseBuilder builder = ResponseBuilder.custom();
  1193. /*if (RedisHelper.Instance != null)
  1194. {
  1195. List<Paper> info = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + request.method,
  1196. ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(request.@params)), timeoutSeconds, () => { return FindExamPaperRedis(request.@params, request.method); });
  1197. builder.Data(info);
  1198. }
  1199. else
  1200. {
  1201. List<Paper> info = await FindExamPaperRedis(request.@params, request.method);
  1202. builder.Data(info);
  1203. }*/
  1204. List<PaperDto> paper = new List<PaperDto>();
  1205. if (RedisHelper.Exists(CacheCosmosPrefix + "paperInfo" + subjectCode.ToString()))
  1206. {
  1207. PaperDto paper1 = RedisHelper.HGet<PaperDto>(CacheCosmosPrefix + "paperInfo" + subjectCode.ToString(), ShaHashHelper.GetSHA1(code.ToString()));
  1208. paper.Add(paper1);
  1209. builder.Data(paper);
  1210. }
  1211. return builder.build();
  1212. }
  1213. /* public async Task<List<Paper>> FindExamPaperRedis(Dictionary<string, object> dict, string method)
  1214. {
  1215. try
  1216. {
  1217. List<Paper> info = await _azureCosmos.FindByDict<Paper>(dict);
  1218. if (RedisHelper.Instance != null)
  1219. {
  1220. if (!RedisHelper.Exists(CacheCosmosPrefix + method))
  1221. {
  1222. await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), info);
  1223. }
  1224. else
  1225. {
  1226. await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), info);
  1227. await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
  1228. }
  1229. }
  1230. return info;
  1231. }
  1232. catch (Exception e)
  1233. {
  1234. throw new BizException(e.Message);
  1235. }
  1236. }*/
  1237. [HttpPost("FindExamAnswer")]
  1238. public BaseResponse FindExamAnswer(JsonElement request)
  1239. {
  1240. request.TryGetProperty("subjectCode", out JsonElement subjectCode);
  1241. request.TryGetProperty("code", out JsonElement code);
  1242. ResponseBuilder builder = ResponseBuilder.custom();
  1243. List<ExamAnswer> exams = new List<ExamAnswer>();
  1244. if (RedisHelper.Exists(CacheCosmosPrefix + "examAnswer" + subjectCode.ToString()))
  1245. {
  1246. ExamAnswer exam = RedisHelper.HGet<ExamAnswer>(CacheCosmosPrefix + "examAnswer" + subjectCode.ToString(), ShaHashHelper.GetSHA1(code.ToString()));
  1247. exams.Add(exam);
  1248. builder.Data(exams);
  1249. }
  1250. return builder.build();
  1251. }
  1252. public async Task<List<ExamAnswer>> FindExamAnswerRedis(Dictionary<string, object> dict, string method)
  1253. {
  1254. return new List<ExamAnswer>();
  1255. //try
  1256. //{
  1257. // List<ExamAnswer> info = await _azureCosmos.FindByDict<ExamAnswer>(dict);
  1258. // if (RedisHelper.Instance != null)
  1259. // {
  1260. // if (!RedisHelper.Exists(CacheCosmosPrefix + method))
  1261. // {
  1262. // await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), info);
  1263. // }
  1264. // else
  1265. // {
  1266. // await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), info);
  1267. // await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
  1268. // }
  1269. // }
  1270. // return info;
  1271. //}
  1272. //catch (Exception e)
  1273. //{
  1274. // throw new BizException(e.Message);
  1275. //}
  1276. }
  1277. public async Task<List<ExamAnswer>> FindExamAnswerRedis(Dictionary<string, object> dict)
  1278. {
  1279. return new List<ExamAnswer>();
  1280. //try
  1281. //{
  1282. // List<ExamAnswer> info = await _azureCosmos.FindByDict<ExamAnswer>(dict);
  1283. // if (RedisHelper.Instance != null)
  1284. // {
  1285. // if (!RedisHelper.Exists(CacheCosmosPrefix + "FindExamAnswer"))
  1286. // {
  1287. // await RedisHelper.HSetAsync(CacheCosmosPrefix + "FindExamAnswer", ShaHashHelper.GetSHA1(dict.ToJsonString()), info);
  1288. // }
  1289. // else
  1290. // {
  1291. // await RedisHelper.HSetAsync(CacheCosmosPrefix + "FindExamAnswer", ShaHashHelper.GetSHA1(dict.ToJsonString()), info);
  1292. // await RedisHelper.ExpireAsync(CacheCosmosPrefix + "FindExamAnswer", timeoutSeconds);
  1293. // }
  1294. // }
  1295. // return info;
  1296. //}
  1297. //catch (Exception e)
  1298. //{
  1299. // throw new BizException(e.Message);
  1300. //}
  1301. }
  1302. [HttpPost("HomeStatistics")]
  1303. public async Task<BaseResponse> HomeStatistics(JsonElement request)
  1304. {
  1305. ResponseBuilder builder = ResponseBuilder.custom();
  1306. Dictionary<string, object> dict = new Dictionary<string, object>();
  1307. var emobj = request.EnumerateObject();
  1308. while (emobj.MoveNext())
  1309. {
  1310. dict[emobj.Current.Name] = emobj.Current.Value;
  1311. }
  1312. List<Dictionary<string, dynamic>> info = new List<Dictionary<string, dynamic>>();
  1313. if (RedisHelper.Instance != null)
  1314. {
  1315. info = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "HomeStatistics",
  1316. ShaHashHelper.GetSHA1(dict.ToJsonString()), timeoutSeconds, () => { return FindHomeStatisticsRedis(dict, "HomeStatistics"); });
  1317. //数据从redis读取过后进行转换格式
  1318. builder.Data(info);
  1319. }
  1320. else
  1321. {
  1322. info = await FindHomeStatisticsRedis(dict, "HomeStatistics");
  1323. builder.Data(info);
  1324. }
  1325. return builder.build();
  1326. }
  1327. public async Task<List<Dictionary<string, dynamic>>> FindHomeStatisticsRedis(Dictionary<string, object> dict, string method)
  1328. {
  1329. return new List<Dictionary<string, dynamic>>();
  1330. //request.@params.TryGetValue("subjectCode", out object subjectCode);
  1331. // dict.TryGetValue("schoolCode", out object schoolCode);
  1332. // dict.TryGetValue("code", out object code);
  1333. // Dictionary<string, object> eMap = new Dictionary<string, object>
  1334. // {
  1335. // { "code", code.ToString()}
  1336. // };
  1337. // Dictionary<string, object> SCMap = new Dictionary<string, object>
  1338. // {
  1339. // { "id", schoolCode.ToString()},
  1340. // };
  1341. // //说明 同学校、同类型考试数据
  1342. // //List<ExamInfo> exams = await azureCosmosDBRepository.FindByDict<ExamInfo>(eMap);
  1343. // List<ExamInfoDto> exams = new List<ExamInfoDto>();
  1344. // if (RedisHelper.Instance != null)
  1345. // {
  1346. // exams = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "FindExamInfo",
  1347. // ShaHashHelper.GetSHA1(eMap.ToJsonString()), timeoutSeconds, () => { return FindExamInfoRedis(eMap, "FindExamInfo"); });
  1348. // }
  1349. // else
  1350. // {
  1351. // exams = await FindExamInfoRedis(eMap, "FindExamInfo");
  1352. // }
  1353. // List<ExamInfoDto> newInfo = new List<ExamInfoDto>();
  1354. // //获取各个学段最新的考试信息
  1355. // foreach (IGrouping<string, ExamInfoDto> group in exams.GroupBy(c => c.conditions.grade))
  1356. // {
  1357. // ExamInfoDto examInfo = group.ToList().OrderByDescending(e => e.createTime).ToList().FirstOrDefault();
  1358. // newInfo.Add(examInfo);
  1359. // };
  1360. // //newInfo.Select(e => e.type.Equals("union"));
  1361. // //List<ExamInfo> unionInfo = newInfo.Where(e => e.type.Equals("union")).ToList();
  1362. // //exams.GroupBy(e => e.conditions.period);
  1363. // //ExamInfo info = exams.OrderByDescending(e => e.createTime).ToList().FirstOrDefault();
  1364. // //查询学校对应的年级信息
  1365. // List<School> schools = await _azureCosmos.FindByDict<School>(SCMap);
  1366. // //List<School> schools = new List<School>();
  1367. ///* if (RedisHelper.Exists(CacheCosmosPrefix + "schoolInfo"))
  1368. // {
  1369. // School sc = RedisHelper.HGet<School>(CacheCosmosPrefix + "schoolInfo",
  1370. // ShaHashHelper.GetSHA1(schoolCode.ToString()));
  1371. // schools.Add(sc);
  1372. // }*/
  1373. // string Period = "";
  1374. // string Grade = "";
  1375. // //List<double> CoreAverage = new List<double>();
  1376. // try
  1377. // {
  1378. // List<Period> periods = new List<Period>();
  1379. // List<Grade> grades = new List<Grade>();
  1380. // foreach (School s in schools)
  1381. // {
  1382. // periods = s.period;
  1383. // }
  1384. // periods.ForEach(p =>
  1385. // {
  1386. // p.grades.ForEach(g => {
  1387. // grades.Add(g);
  1388. // });
  1389. // /*if (p.periodCode.Equals("初中"))
  1390. // {
  1391. // grades = p.grades;
  1392. // }
  1393. // else if (p.periodCode.Equals("高中"))
  1394. // {
  1395. // grades = p.grades;
  1396. // }
  1397. // else
  1398. // {
  1399. // grades = p.grades;
  1400. // }*/
  1401. // });
  1402. // List<Dictionary<string, object>> map = new List<Dictionary<string, object>>();
  1403. // //循环处理不同年级考试信息
  1404. // foreach (Grade g in grades)
  1405. // {
  1406. // double weightSum = 0;
  1407. // List<double> CoreAverage = new List<double>();
  1408. // List<List<List<string>>> AllPoint = new List<List<List<string>>>();
  1409. // List<List<List<string>>> AllPointAverage = new List<List<List<string>>>();
  1410. // List<List<List<string>>> AllKeyLine = new List<List<List<string>>>();
  1411. // HashSet<string> classList = new HashSet<string>();
  1412. // HashSet<string> subjectList = new HashSet<string>();
  1413. // for (int i = 0; i < newInfo.Count; i++)
  1414. // {
  1415. // if (g.id.Equals(newInfo[i].conditions.grade))
  1416. // {
  1417. // List<ExamResultDto> simples = new List<ExamResultDto>();
  1418. // for (int j = 0; j < newInfo[i].conditions.subject.Count; j++)
  1419. // {
  1420. // ExamResultDto result = new ExamResultDto();
  1421. // if (RedisHelper.Exists(CacheCosmosPrefix + "examResult" + newInfo[i].conditions.subject[j]))
  1422. // {
  1423. // result = RedisHelper.HGet<ExamResultDto>(CacheCosmosPrefix + "examResult" + newInfo[i].conditions.subject[j],
  1424. // ShaHashHelper.GetSHA1(newInfo[i].examCode));
  1425. // simples.Add(result);
  1426. // }
  1427. // }
  1428. // //List<ExamResult> examResults = new List<ExamResult>();
  1429. // /*Dictionary<string, object> sub = new Dictionary<string, object>
  1430. // {
  1431. // { "code", newInfo[i].id}
  1432. // };*/
  1433. // Period = newInfo[i].conditions.period;
  1434. // Grade = newInfo[i].conditions.grade;
  1435. // List<string> subjects = new List<string>();
  1436. // List<List<string>> SubjectClassAverage = new List<List<string>>();
  1437. // List<List<string>> SubjectAverage = new List<List<string>>();
  1438. // //List<List<string>> SubjectClassAverage = new List<List<string>>();
  1439. // //List<ExamResult> simples = await azureCosmosDBRepository.FindByDict<ExamResult>(sub);
  1440. // // 学生总分
  1441. // double coreSum = 0;
  1442. // int stuCount = newInfo[i].stuCount;
  1443. // //int stuCount = 0;
  1444. // //初始化进行人数
  1445. // double iPersons = 0;
  1446. // //
  1447. // List<List<double>> subSum = new List<List<double>>();
  1448. // if (simples.IsEmpty()) continue;
  1449. // double weight = 0.5;
  1450. // weightSum += weight;
  1451. // int classLen = simples[0].classes.Count;
  1452. // for (int cls = 0; cls < classLen; cls++)
  1453. // {
  1454. // if (simples[0].classes[cls].TryGetValue(simples[0].classes[cls].Keys.ToArray<string>()[0], out int[] indexs))
  1455. // {
  1456. // List<double> stuScore = new List<double>();
  1457. // int stdLen = indexs[1] - indexs[0] + 1;
  1458. // for (int n = 0; n < stdLen; n++)
  1459. // {
  1460. // stuScore.Add(0);
  1461. // }
  1462. // subSum.Add(stuScore);
  1463. // }
  1464. // }
  1465. // simples.ForEach(s =>
  1466. // {
  1467. // subjectList.Add(s.subjectCode);
  1468. // //计算试卷总分
  1469. // double sum = s.point.Sum();
  1470. // //int stuSum = 0;
  1471. // int classIndex = 0;
  1472. // List<string> ClassAverage = new List<string>();
  1473. // List<string> Average = new List<string>();
  1474. // List<string> passList = new List<string>();
  1475. // s.classes.ForEach(c =>
  1476. // {
  1477. // List<List<string>> classPRL = new List<List<string>>();
  1478. // //初始化班级总分
  1479. // double classPoint = 0;
  1480. // //初始化班级缺考人数
  1481. // int classCount = 0;
  1482. // //初始化班级平均得分率
  1483. // double points = 0;
  1484. // //初始化班级平均得分率
  1485. // double AveragePoints = 0;
  1486. // //初始化各班参考人数
  1487. // int counts = 0;
  1488. // //c.Keys遍历key值
  1489. // foreach (string key in c.Keys)
  1490. // {
  1491. // classList.Add(key);
  1492. // }
  1493. // //每个班级平均分
  1494. // foreach (int[] value in c.Values)
  1495. // {
  1496. // for (int i = value[0]; i <= value[1]; i++)
  1497. // {
  1498. // //初始化学生单科个人得分
  1499. // double stuPoints = s.result[i].Sum();
  1500. // subSum[classIndex][i - value[0]] = stuPoints + subSum[classIndex][i - value[0]];
  1501. // classPoint += s.result[i].Sum();
  1502. // coreSum += s.result[i].Sum();
  1503. // if (s.result[i].Sum() == 0)
  1504. // {
  1505. // classCount++;
  1506. // }
  1507. // }
  1508. // //每个班级实际参考人数
  1509. // counts = value[1] - value[0] + 1;
  1510. // //stuSum += counts;
  1511. // //stuCount += counts;
  1512. // points = Convert.ToDouble(classPoint) / counts / sum;
  1513. // //计算每个班级平均得分
  1514. // AveragePoints = Convert.ToDouble(classPoint) / counts;
  1515. // ClassAverage.Add(points.ToString("0.000"));
  1516. // Average.Add(AveragePoints.ToString());
  1517. // }
  1518. // classIndex += 1;
  1519. // });
  1520. // SubjectClassAverage.Add(ClassAverage);
  1521. // SubjectAverage.Add(Average);
  1522. // //subAverage = subjectPoint / ClassAverage.Count();
  1523. // //subjectAverage.Add(subAverage.ToString("0.00"));
  1524. // });
  1525. // //获取进线人数
  1526. // iPersons = stuCount / classList.Count * 0.4;
  1527. // //权重配分 学生总平均分 * 权重配分
  1528. // double core = coreSum / stuCount * weight;
  1529. // CoreAverage.Add(core);
  1530. // AllPoint.Add(SubjectClassAverage);
  1531. // AllPointAverage.Add(SubjectAverage);
  1532. // //处理人数为整
  1533. // string ip = iPersons.ToString("0");
  1534. // //初始化进线分数
  1535. // int ipoint = 0;
  1536. // List<int> AllPoints = new List<int>();
  1537. // foreach (List<double> points in subSum)
  1538. // {
  1539. // foreach (int po in points)
  1540. // {
  1541. // AllPoints.Add(po);
  1542. // }
  1543. // }
  1544. // for (int sn = 0; sn < subSum.Count; sn++)
  1545. // {
  1546. // for (int j = 0; j < subSum[sn].Count; j++)
  1547. // {
  1548. // if (subSum[sn][j].Equals("0"))
  1549. // {
  1550. // subSum[sn].Remove(subSum[sn][j]);
  1551. // }
  1552. // }
  1553. // }
  1554. // //计算成绩年级排名
  1555. // AllPoints.Sort(delegate (int s1, int s2) { return s2.CompareTo(s1); });
  1556. // ipoint = AllPoints[int.Parse(ip)];
  1557. // int m = 0;
  1558. // List<List<string>> KeyLine = new List<List<string>>();
  1559. // foreach (List<double> points in subSum)
  1560. // {
  1561. // List<string> detail = new List<string>();
  1562. // double sum = points.Count;
  1563. // int l = 0;
  1564. // for (int mq = 0; mq < points.Count; mq++)
  1565. // {
  1566. // if (points[mq] >= ipoint)
  1567. // {
  1568. // l++;
  1569. // }
  1570. // }
  1571. // double Lines = l;
  1572. // detail.Add(Lines.ToString());
  1573. // detail.Add(points.Count.ToString());
  1574. // var t3 = Math.Floor(Math.Round(decimal.Parse((Lines / sum).ToString("0.000")), 2) * 100);
  1575. // detail.Add(t3.ToString());
  1576. // KeyLine.Add(detail);
  1577. // m++;
  1578. // }
  1579. // AllKeyLine.Add(KeyLine);
  1580. // }
  1581. // else {
  1582. // continue;
  1583. // }
  1584. // //年级成就指标
  1585. // if (weightSum == 0)
  1586. // {
  1587. // weightSum = 1;
  1588. // }
  1589. // double index = CoreAverage.Sum() / weightSum;
  1590. // List<List<double>> AveragePoint = new List<List<double>>();
  1591. // List<List<double>> AverageClassPoint = new List<List<double>>();
  1592. // //List<double> ClassCore = new List<double>();
  1593. // int k = AllPoint.Count;
  1594. // if (k > 0)
  1595. // {
  1596. // for (int m = 0; m < AllPoint[0].Count; m++)
  1597. // {
  1598. // List<double> SubjectAverage = new List<double>();
  1599. // for (int n = 0; n < AllPoint[0][m].Count; n++)
  1600. // {
  1601. // double startPoint = 0;
  1602. // for (int f = 0; f < k; f++)
  1603. // {
  1604. // startPoint = double.Parse(AllPoint[f][m][n]) + startPoint;
  1605. // }
  1606. // SubjectAverage.Add(startPoint / k);
  1607. // }
  1608. // AveragePoint.Add(SubjectAverage);
  1609. // }
  1610. // }
  1611. // //每个班级成就指标
  1612. // int p = AllPointAverage.Count;
  1613. // if (p > 0)
  1614. // {
  1615. // for (int m = 0; m < AllPointAverage[0].Count; m++)
  1616. // {
  1617. // List<double> SubjectAverage = new List<double>();
  1618. // for (int n = 0; n < AllPointAverage[0][m].Count; n++)
  1619. // {
  1620. // double startPoint = 0;
  1621. // for (int f = 0; f < k; f++)
  1622. // {
  1623. // startPoint = double.Parse(AllPointAverage[f][m][n]) + startPoint;
  1624. // }
  1625. // SubjectAverage.Add(startPoint / k);
  1626. // }
  1627. // AverageClassPoint.Add(SubjectAverage);
  1628. // }
  1629. // }
  1630. // int c = AverageClassPoint.Count;
  1631. // List<double> ClassCore = new List<double>();
  1632. // if (c > 0)
  1633. // {
  1634. // for (int j = 0; j < AverageClassPoint[0].Count; j++)
  1635. // {
  1636. // double startAverage = 0;
  1637. // for (int f = 0; f < c; f++)
  1638. // {
  1639. // startAverage = AverageClassPoint[f][j] + startAverage;
  1640. // }
  1641. // ClassCore.Add(startAverage / c / weightSum);
  1642. // }
  1643. // }
  1644. // //班级平均进线率
  1645. // int ExamCount = AllKeyLine.Count;
  1646. // List<List<double>> KeyLines = new List<List<double>>();
  1647. // if (ExamCount > 0)
  1648. // {
  1649. // for (int m = 0; m < AllKeyLine[0].Count; m++)
  1650. // {
  1651. // List<double> ClassLine = new List<double>();
  1652. // for (int n = 0; n < AllKeyLine[0][m].Count; n++)
  1653. // {
  1654. // double startPoint = 0;
  1655. // for (int f = 0; f < ExamCount; f++)
  1656. // {
  1657. // startPoint = double.Parse(AllKeyLine[f][m][n]) + startPoint;
  1658. // }
  1659. // ClassLine.Add(startPoint / ExamCount);
  1660. // }
  1661. // KeyLines.Add(ClassLine);
  1662. // }
  1663. // }
  1664. // Dictionary<string, object> AveragePointMap = new Dictionary<string, object>
  1665. // {
  1666. // { "Period",Period},
  1667. // { "Grade",Grade},
  1668. // { "index", index},
  1669. // { "className", classList },
  1670. // { "subjectName", subjectList },
  1671. // { "AveragePoint", AveragePoint },
  1672. // //{ "AverageClassPoint", AverageClassPoint },
  1673. // { "ClassCore", ClassCore },
  1674. // { "KeyLines",KeyLines}
  1675. // };
  1676. // map.Add(AveragePointMap);
  1677. // }
  1678. // }
  1679. // //Redis处理结果集
  1680. // if (RedisHelper.Instance != null)
  1681. // {
  1682. // if (!RedisHelper.Exists(CacheCosmosPrefix + method))
  1683. // {
  1684. // await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), map);
  1685. // }
  1686. // else
  1687. // {
  1688. // await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), map);
  1689. // await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
  1690. // }
  1691. // }
  1692. // return map;
  1693. // }
  1694. // catch (Exception e)
  1695. // {
  1696. // throw new BizException(e.Message);
  1697. // }
  1698. }
  1699. [HttpPost("getAnalysis")]
  1700. public async Task<IActionResult> getAnalysis(JsonElement request)
  1701. {
  1702. //获取评测的ID
  1703. if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
  1704. if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
  1705. try
  1706. {
  1707. var client = _azureCosmos.GetCosmosClient();
  1708. //获取本次评测所有科目结算结果
  1709. ExamInfo info = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"Exam-{code}"));
  1710. School school = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<School>(code.ToString(), new PartitionKey($"Base"));
  1711. List<ExamResult> examResults = new List<ExamResult>();
  1712. var query = $"select c.id,c.name,c.subjectId,c.studentScores,c.studentIds,c.paper,c.classes from c where c.examId = '{id}' ";
  1713. await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<ExamResult>(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamResult-{id}") }))
  1714. {
  1715. /*using var json = await JsonDocument.ParseAsync(item.ContentStream);
  1716. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  1717. {
  1718. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  1719. {
  1720. examResults.Add(obj.ToObject<ExamResult>());
  1721. }
  1722. }*/
  1723. examResults.Add(item);
  1724. }
  1725. //获取本次评测所有班级作答结果
  1726. List<ExamClassResult> examClassResults = new List<ExamClassResult>();
  1727. var queryClass = $"select c.id,c.name,c.subjectId,c.studentScores,c.studentIds,c.gradeId,c.info from c where c.examId = '{id}' and c.progress = true ";
  1728. await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<ExamClassResult>(queryText: queryClass, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{code}") }))
  1729. {
  1730. examClassResults.Add(item);
  1731. /*using var json = await JsonDocument.ParseAsync(item.ContentStream);
  1732. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  1733. {
  1734. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  1735. {
  1736. examClassResults.Add(obj.ToObject<ExamClassResult>());
  1737. }
  1738. }*/
  1739. }
  1740. //获取进线标准
  1741. int touch = 0;
  1742. foreach (Period period in school.period)
  1743. {
  1744. if (info.period.id.Equals(period.id))
  1745. {
  1746. touch = period.analysis.touch;
  1747. }
  1748. }
  1749. //获取进线人数
  1750. int personCount = (int)System.Math.Round(info.stuCount * (touch / 100.0), MidpointRounding.AwayFromZero);
  1751. StudentAnalysis analysis = new StudentAnalysis();
  1752. List<ClassAnalysis> classAnalyses = new List<ClassAnalysis>();
  1753. /* //声明年级所有科目总分
  1754. List<double> total = new List<double>();*/
  1755. //以班级为单位
  1756. List<double> stuTotals = new List<double>();
  1757. List<dynamic> classes = new List<dynamic>();
  1758. HashSet<string> idName = new HashSet<string>();
  1759. foreach (ExamResult examResult in examResults)
  1760. {
  1761. foreach (string ids in examResult.studentIds)
  1762. {
  1763. idName.Add(ids);
  1764. }
  1765. }
  1766. foreach (string s in info.targetClassIds)
  1767. {
  1768. //存放每个班级学生总分
  1769. List<double> totalClass = new List<double>();
  1770. ClassAnalysis classAnalysis = new ClassAnalysis();
  1771. classAnalysis.classId = s;
  1772. var sresponse = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(s, new PartitionKey($"Class-{code}"));
  1773. if (sresponse.Status == 200)
  1774. {
  1775. using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
  1776. Class classroom = json.ToObject<Class>();
  1777. classes.Add(new { name = classroom.name, id = s });
  1778. //初始化参考人数
  1779. int count = 0;
  1780. foreach (StudentSimple stu in classroom.students)
  1781. {
  1782. if (idName.Contains(stu.id))
  1783. {
  1784. count++;
  1785. }
  1786. else
  1787. {
  1788. continue;
  1789. }
  1790. classAnalysis.studentIds.Add(stu.id);
  1791. analysis.names.Add(stu.name);
  1792. analysis.ids.Add(stu.id);
  1793. //计算学生多科考试成绩总分
  1794. double stuTotal = 0;
  1795. foreach (ExamResult examResult in examResults)
  1796. {
  1797. int index = examResult.studentIds.IndexOf(stu.id);
  1798. if (index >= 0)
  1799. {
  1800. stuTotal = stuTotal + examResult.studentScores[index].Sum();
  1801. }
  1802. }
  1803. classAnalysis.total.Add(stuTotal);
  1804. analysis.total.Add(stuTotal);
  1805. stuTotals.Add(stuTotal);
  1806. totalClass.Add(stuTotal);
  1807. //total.Add(stuTotal);
  1808. }
  1809. classAnalysis.stuCount = count;
  1810. }
  1811. /* //声明单个班级单科总分
  1812. double subjectTotal = 0;*/
  1813. info.subjects.ForEach(sub =>
  1814. {
  1815. //初始化及格人数
  1816. int i = 0;
  1817. //初始化单科总分
  1818. double sumClass = 0;
  1819. //记录每个科目数据
  1820. SubjectScore subjectScore = new SubjectScore();
  1821. subjectScore.id = sub.id;
  1822. double subjectSum = 0;
  1823. double passScore = 0;
  1824. //计算单科评测总分
  1825. foreach (ExamResult examResult in examResults)
  1826. {
  1827. if (sub.id.Equals(examResult.subjectId))
  1828. {
  1829. subjectSum = examResult.paper.point.Sum();
  1830. }
  1831. }
  1832. //单科及格率分数
  1833. passScore = subjectSum * 0.6;
  1834. //存放学生单科记录
  1835. Score score = new Score();
  1836. score.subjectId = sub.id;
  1837. List<double> subjectTotal = new List<double>();
  1838. //处理每个班级各个学生各科总分
  1839. foreach (ExamClassResult result in examClassResults)
  1840. {
  1841. if (sub.id.Equals(result.subjectId) && s.Equals(result.info.id))
  1842. {
  1843. foreach (List<double> scores in result.studentScores)
  1844. {
  1845. //添加每个学生各科总分
  1846. score.csc.Add(scores.Sum());
  1847. //计算大于及格分数的人数
  1848. if (scores.Sum() >= passScore)
  1849. {
  1850. i++;
  1851. }
  1852. //totalClass.Add(scores.Sum());
  1853. subjectTotal.Add(scores.Sum());
  1854. sumClass = sumClass + scores.Sum();
  1855. }
  1856. //处理班级及格率以及均分
  1857. double percentClass = i / (result.studentIds.Count * 1.0);
  1858. double averageClass = sumClass / (result.studentIds.Count * 1.0);
  1859. //total += averageClass;
  1860. subjectScore.passPercent = percentClass;
  1861. subjectScore.averageScore = averageClass;
  1862. classAnalysis.subjects.Add(subjectScore);
  1863. //analysis.scores.Add(score);
  1864. }
  1865. }
  1866. //处理单科科班级PR
  1867. subjectTotal.Sort(delegate (double s1, double s2) { return s2.CompareTo(s1); });
  1868. foreach (double sc in score.csc)
  1869. {
  1870. int index = subjectTotal.IndexOf(sc);
  1871. double CPR = 100 - (100 * (index + 1) - 50) / score.csc.Count;
  1872. score.cdpr.Add(CPR);
  1873. }
  1874. analysis.scores.Add(score);
  1875. });
  1876. //处理全科班级PR
  1877. totalClass.Sort(delegate (double s1, double s2) { return s2.CompareTo(s1); });
  1878. foreach (double pr in classAnalysis.total)
  1879. {
  1880. int index = totalClass.IndexOf(pr);
  1881. double CPR = 100 - (100 * (index + 1) - 50) / classAnalysis.total.Count;
  1882. analysis.cpr.Add(CPR);
  1883. }
  1884. classAnalyses.Add(classAnalysis);
  1885. }
  1886. /*info.targetClassIds.ForEach( async s => {
  1887. });*/
  1888. //初始化进线分数
  1889. double ipoint = 0;
  1890. stuTotals.Sort(delegate (double s1, double s2) { return s2.CompareTo(s1); });
  1891. ipoint = stuTotals[personCount];
  1892. //补充班级总平均分/进行人数/标准差
  1893. foreach (ClassAnalysis classAnalysis in classAnalyses)
  1894. {
  1895. //初始化进线人数
  1896. int i = 0;
  1897. //初始化班级总分
  1898. double score = 0;
  1899. //标准差
  1900. double powSum = 0;
  1901. foreach (double sc in classAnalysis.total)
  1902. {
  1903. if (sc > ipoint)
  1904. {
  1905. i++;
  1906. }
  1907. score = score + sc;
  1908. }
  1909. //总平均分
  1910. double totalAverage = 0;
  1911. totalAverage = score / classAnalysis.stuCount;
  1912. //计算标准差
  1913. foreach (double sc in classAnalysis.total)
  1914. {
  1915. powSum += Math.Pow(sc - totalAverage, 2);
  1916. }
  1917. var pow = Math.Pow(powSum / classAnalysis.stuCount, 0.5);
  1918. classAnalysis.standardDeviation = pow;
  1919. classAnalysis.totalAverage = totalAverage;
  1920. classAnalysis.lineCount = i;
  1921. }
  1922. //处理全科年级PR值
  1923. foreach (double no in analysis.total)
  1924. {
  1925. int index = stuTotals.IndexOf(no);
  1926. int GPR = 100 - (100 * (index + 1) - 50) / analysis.total.Count;
  1927. analysis.gpr.Add(GPR);
  1928. }
  1929. List<GradeAnalysis> gradeAnalyses = new List<GradeAnalysis>();
  1930. List<Dictionary<string, dynamic>> PointAnalysis = new List<Dictionary<string, dynamic>>();
  1931. List<Dictionary<string, dynamic>> exerciseScatter = new List<Dictionary<string, dynamic>>();
  1932. List<Dictionary<string, dynamic>> KnowledgePoint = new List<Dictionary<string, dynamic>>();
  1933. if (info.grades.Count > 0)
  1934. {
  1935. gradeAnalyses = GetGradeAnalyses(info, examResults, examClassResults, analysis);
  1936. PointAnalysis = getPointAnalysis(examResults, info);
  1937. exerciseScatter = getExerciseScatter(examResults, info);
  1938. KnowledgePoint = getKnowledgePoint(examResults, info);
  1939. }
  1940. return Ok(new { analysis, classAnalyses, gradeAnalyses, PointAnalysis, exerciseScatter, KnowledgePoint });
  1941. }
  1942. catch (Exception e)
  1943. {
  1944. await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/getAnalysis()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
  1945. return BadRequest();
  1946. }
  1947. }
  1948. private List<GradeAnalysis> GetGradeAnalyses(ExamInfo info, List<ExamResult> examResults, List<ExamClassResult> examClassResults, StudentAnalysis analysis)
  1949. {
  1950. List<GradeAnalysis> gradeAnalyses = new List<GradeAnalysis>();
  1951. info.grades.ForEach(g =>
  1952. {
  1953. GradeAnalysis gradeAnalysis = new GradeAnalysis();
  1954. gradeAnalysis.gradeId = g.id;
  1955. //初始化单个年级总分
  1956. double gradeScore = 0;
  1957. info.subjects.ForEach(sub =>
  1958. {
  1959. //初始化及格人数
  1960. int i = 0;
  1961. //初始化年级人数
  1962. int count = 0;
  1963. //初始化单科总分
  1964. double sumClass = 0;
  1965. //记录每个科目数据
  1966. GradeSubjectScore subjectScore = new GradeSubjectScore();
  1967. subjectScore.id = sub.id;
  1968. double subjectSum = 0;
  1969. double passScore = 0;
  1970. //计算单科评测总分
  1971. foreach (ExamResult examResult in examResults)
  1972. {
  1973. if (sub.id.Equals(examResult.subjectId))
  1974. {
  1975. subjectSum = examResult.paper.point.Sum();
  1976. }
  1977. }
  1978. //单科及格率分数
  1979. passScore = subjectSum * 0.6;
  1980. List<double> subjectTotal = new List<double>();
  1981. //存放单科每个班级学生总分
  1982. List<double> totalClass = new List<double>();
  1983. //存放学生单科记录
  1984. foreach (Score score in analysis.scores)
  1985. {
  1986. if (score.subjectId.Equals(sub.id))
  1987. {
  1988. //处理每个班级各个学生各科总分
  1989. foreach (ExamClassResult result in examClassResults)
  1990. {
  1991. if (sub.id.Equals(result.subjectId) && g.id.Equals(result.gradeId))
  1992. {
  1993. foreach (List<double> scores in result.studentScores)
  1994. {
  1995. //添加每个学生各科总分
  1996. score.gsc.Add(scores.Sum());
  1997. //计算大于及格分数的人数
  1998. if (scores.Sum() >= passScore)
  1999. {
  2000. i++;
  2001. }
  2002. subjectTotal.Add(scores.Sum());
  2003. sumClass = sumClass + scores.Sum();
  2004. }
  2005. count += result.studentIds.Count;
  2006. }
  2007. }
  2008. //处理班级及格率以及均分
  2009. double persentClass = i / (count * 1.0);
  2010. double averageClass = sumClass / (count * 1.0);
  2011. gradeScore += averageClass;
  2012. subjectScore.passPercent = persentClass;
  2013. subjectScore.averageScore = averageClass;
  2014. gradeAnalysis.subjects.Add(subjectScore);
  2015. gradeAnalyses.Add(gradeAnalysis);
  2016. //处理单科科年级PR
  2017. subjectTotal.Sort(delegate (double s1, double s2) { return s2.CompareTo(s1); });
  2018. foreach (double sc in score.gsc)
  2019. {
  2020. int index = subjectTotal.IndexOf(sc);
  2021. double GPR = 100 - (100 * (index + 1) - 50) / score.gsc.Count;
  2022. score.gdpr.Add(GPR);
  2023. //analysis.gpr.Add(GPR);
  2024. }
  2025. //analysis.scores.Add(score);
  2026. }
  2027. }
  2028. });
  2029. foreach (GradeAnalysis grade in gradeAnalyses)
  2030. {
  2031. grade.GradeaverageScore = gradeScore / grade.subjects.Count;
  2032. }
  2033. });
  2034. return gradeAnalyses;
  2035. }
  2036. //落点分析
  2037. private List<Dictionary<string, dynamic>> getPointAnalysis(List<ExamResult> exams, ExamInfo exam)
  2038. {
  2039. List<Dictionary<string, dynamic>> scatterAnalysis = new List<Dictionary<string, dynamic>>();
  2040. List<string> key = new List<string>
  2041. {
  2042. "name",
  2043. "className",
  2044. "x",
  2045. "y",
  2046. "memberId",
  2047. "score",
  2048. "trueNum",
  2049. "falseNum",
  2050. "hardList",
  2051. "carefulList",
  2052. "scatter"
  2053. };
  2054. //key.Add("areaName");
  2055. if (exams.Count > 0)
  2056. {
  2057. /* //提取班级信息
  2058. List<Dictionary<string, int[]>> classToName = exams[0].classes;
  2059. //提取学生ID信息
  2060. List<string> idToName = exams[0].ids;*/
  2061. exams.ForEach(e =>
  2062. {
  2063. Dictionary<string, object> detail = new Dictionary<string, object>
  2064. {
  2065. { "keys", key }
  2066. };
  2067. List<List<string>> datas = new List<List<string>>();
  2068. Dictionary<string, object> subject = new Dictionary<string, object>
  2069. {
  2070. { "name", e.subjectId }
  2071. };
  2072. double[] point = StringHelper.ListTodouble(e.paper.point);
  2073. double[,] result = StringHelper.ListToDouble(e.studentScores);
  2074. try
  2075. {
  2076. var cdm = new ClouDASMatrix(result, point);
  2077. //学生通过率
  2078. List<double> pass = cdm.PassingRate;
  2079. //学生稳定度
  2080. List<double> sta = cdm.StabilityRate;
  2081. //落点区域
  2082. List<string> stu = cdm.StuFallArea;
  2083. //需努力的题型
  2084. List<int[]> strive = cdm.StriveTopic;
  2085. //需小心的题型
  2086. List<int[]> careful = cdm.CarefulTopic;
  2087. int i = 0;
  2088. for (int k = e.studentIds.Count - 1; k >= 0; k--)
  2089. {
  2090. if (e.studentIds[k].Equals("0"))
  2091. {
  2092. e.studentIds.Remove(e.studentIds[k]);
  2093. }
  2094. }
  2095. e.studentIds.ForEach(s =>
  2096. {
  2097. if (e.studentScores[i].Sum() != 0)
  2098. {
  2099. List<string> info = new List<string>
  2100. {
  2101. s,
  2102. "-",
  2103. sta[i].ToString(),
  2104. pass[i].ToString(),
  2105. i + 1 + "",
  2106. e.studentScores[i].Sum().ToString()
  2107. };
  2108. int right = 0;
  2109. int wrong = 0;
  2110. foreach (int p in e.studentScores[i])
  2111. {
  2112. if (p > 0)
  2113. {
  2114. right++;
  2115. }
  2116. else
  2117. {
  2118. wrong++;
  2119. }
  2120. }
  2121. info.Add(right + "");
  2122. info.Add(wrong + "");
  2123. int[] str = strive[i];
  2124. string striveAll = "";
  2125. foreach (int n in str)
  2126. {
  2127. striveAll += n.ToString() + ",";
  2128. }
  2129. int[] care = careful[i];
  2130. string careAll = "";
  2131. foreach (int n in care)
  2132. {
  2133. careAll += n.ToString() + ",";
  2134. }
  2135. if (string.IsNullOrEmpty(striveAll))
  2136. {
  2137. info.Add("无");
  2138. }
  2139. else
  2140. {
  2141. info.Add(striveAll.Substring(0, striveAll.Length - 1));
  2142. }
  2143. if (string.IsNullOrEmpty(careAll))
  2144. {
  2145. info.Add("无");
  2146. }
  2147. else
  2148. {
  2149. info.Add(careAll.Substring(0, careAll.Length - 1)); ;
  2150. }
  2151. info.Add(stu[i].ToString());
  2152. datas.Add(info);
  2153. }
  2154. i++;
  2155. });
  2156. //AchievementService.ReName(datas, idToName, classToName, students);
  2157. detail.Add("datas", datas);
  2158. subject.Add("scatter", detail);
  2159. scatterAnalysis.Add(subject);
  2160. }
  2161. catch (Exception ex)
  2162. {
  2163. //builder.Data(exams);
  2164. //ex.Message;
  2165. Console.WriteLine("---------------------" + ex.Message + "--------------------------");
  2166. }
  2167. });
  2168. return scatterAnalysis;
  2169. }
  2170. else return scatterAnalysis;
  2171. }
  2172. private List<Dictionary<string, dynamic>> getExerciseScatter(List<ExamResult> exams, ExamInfo exam)
  2173. {
  2174. /* ResponseBuilder builder = ResponseBuilder.custom();*/
  2175. List<string> classList = new List<string>();
  2176. List<Dictionary<string, object>> exerciseScatter = new List<Dictionary<string, object>>();
  2177. //Dictionary<string, object> scatterAnalysis = new Dictionary<string, object>();
  2178. classList = exam.targetClassIds;
  2179. List<string> key = new List<string>
  2180. {
  2181. "id",
  2182. "type",
  2183. "areaName",
  2184. "score",
  2185. "diff",
  2186. "identify",
  2187. "classScoreRate",
  2188. "gradeScoreRate",
  2189. "areaScoreRate",
  2190. "highScoreRate",
  2191. "lowScoreRate",
  2192. "knowledgePoint",
  2193. "R1",
  2194. "R2",
  2195. "R3",
  2196. "R4",
  2197. "R5",
  2198. "R6",
  2199. "PH",
  2200. "PL",
  2201. "X",
  2202. "Y",
  2203. "knowledge"
  2204. };
  2205. if (exams.IsNotEmpty())
  2206. {
  2207. exams.ForEach(e =>
  2208. {
  2209. List<double> gradeAnswer = new List<double>();
  2210. List<string> grasdepersent = new List<string>();
  2211. for (int n = 0; n < e.paper.point.Count; n++)
  2212. {
  2213. gradeAnswer.Add(0);
  2214. }
  2215. //参考人数
  2216. double Qnum = 0;
  2217. e.studentIds.ForEach(i =>
  2218. {
  2219. if (!i.Equals("0"))
  2220. {
  2221. Qnum++;
  2222. }
  2223. });
  2224. /* Dictionary<string, object> detail = new Dictionary<string, object>
  2225. {
  2226. { "keys", key }
  2227. };*/
  2228. List<List<string>> datas = new List<List<string>>();
  2229. List<string[]> itemAnalysis = new List<string[]>();
  2230. Dictionary<string, object> subject = new Dictionary<string, object>
  2231. {
  2232. { "name", e.subjectId }
  2233. };
  2234. Dictionary<string, object> classPersent = new Dictionary<string, object>();
  2235. List<List<string>> classdatas = new List<List<string>>();
  2236. try
  2237. {
  2238. e.classes.ForEach(c =>
  2239. {
  2240. //初始化每题得分情况
  2241. List<int> answerCount = new List<int>();
  2242. List<string> persent = new List<string>();
  2243. double peopleCount = 0;
  2244. for (int n = 0; n < e.paper.point.Count; n++)
  2245. {
  2246. answerCount.Add(0);
  2247. }
  2248. int qCount = 0;
  2249. //int right = 0;
  2250. /* //c.Keys遍历key值
  2251. foreach (string keys in c.Keys)
  2252. {
  2253. classList.Add(keys);
  2254. }*/
  2255. //每个班级得分占比
  2256. for (int i = c.range[0]; i <= c.range[1]; i++)
  2257. {
  2258. if (e.studentScores[i].Sum() > 0)
  2259. {
  2260. for (int j = 0; j < e.studentScores[i].Count; j++)
  2261. {
  2262. if (e.studentScores[i][j] > 0)
  2263. {
  2264. //记录班级每题得分数
  2265. answerCount[j] = answerCount[j] + 1;
  2266. //记录年级每题得分数
  2267. gradeAnswer[j] = gradeAnswer[j] + 1;
  2268. //right++;
  2269. }
  2270. }
  2271. }
  2272. else
  2273. {
  2274. qCount++;
  2275. }
  2276. peopleCount = c.range[1] - c.range[0] + 1 - qCount;
  2277. }
  2278. foreach (int p in answerCount)
  2279. {
  2280. var t = Math.Floor(Math.Round(decimal.Parse((p * 1.0 / peopleCount).ToString("0.000")), 2) * 100);
  2281. persent.Add(t.ToString());
  2282. }
  2283. classdatas.Add(persent);
  2284. });
  2285. classPersent.Add("classList", classList);
  2286. classPersent.Add("datas", classdatas);
  2287. exerciseScatter.Add(classPersent);
  2288. double[] point = StringHelper.ListTodouble(e.paper.point);
  2289. double[,] result = StringHelper.ListToDouble(e.studentScores);
  2290. var cdm = new ClouDASMatrix(result, point);
  2291. //试题Y
  2292. List<double> answer = cdm.AnswerRate;
  2293. //试题X
  2294. List<double> quality = cdm.QualityRate;
  2295. //试题区域
  2296. List<string> topic = cdm.TopicFallArea;
  2297. //试题相关分析结果
  2298. List<(double Diff, double Identify, double R1, double R2, double R3, double R4, double R5, double R6, double RH, double RL)> rs = cdm.RS;
  2299. for (int i = 0; i < rs.Count; i++)
  2300. {
  2301. string[] ex = new string[] { };
  2302. string ss = rs[i].ToString()[1..^1];
  2303. ex = ss.Split(",");
  2304. itemAnalysis.Add(ex);
  2305. }
  2306. foreach (int p in gradeAnswer)
  2307. {
  2308. var t = Math.Floor(Math.Round(decimal.Parse((p / Qnum).ToString("0.000")), 2) * 100);
  2309. grasdepersent.Add(t.ToString());
  2310. }
  2311. for (int k = 0; k < e.paper.point.Count; k++)
  2312. {
  2313. List<string> values = new List<string>();
  2314. key.ForEach(x =>
  2315. {
  2316. values.Add("-");
  2317. });
  2318. values[0] = (k + 1).ToString();
  2319. values[1] = "";
  2320. values[2] = topic[k].ToString();
  2321. values[3] = e.paper.point[k].ToString();
  2322. if (itemAnalysis.Count > 0)
  2323. {
  2324. values[4] = itemAnalysis[k][0];
  2325. values[5] = itemAnalysis[k][1];
  2326. values[12] = itemAnalysis[k][2];
  2327. values[13] = itemAnalysis[k][3];
  2328. values[14] = itemAnalysis[k][4];
  2329. values[15] = itemAnalysis[k][5];
  2330. values[16] = itemAnalysis[k][6];
  2331. values[17] = itemAnalysis[k][7];
  2332. values[18] = itemAnalysis[k][8];
  2333. values[19] = itemAnalysis[k][9];
  2334. }
  2335. else
  2336. {
  2337. values[4] = "-";
  2338. values[5] = "-";
  2339. values[12] = "-";
  2340. values[13] = "-";
  2341. values[14] = "-";
  2342. values[15] = "-";
  2343. values[16] = "-";
  2344. values[17] = "-";
  2345. values[18] = "-";
  2346. values[19] = "-";
  2347. }
  2348. values[7] = grasdepersent[k];
  2349. values[8] = grasdepersent[k];
  2350. values[20] = quality[k].ToString();
  2351. values[21] = answer[k].ToString();
  2352. string pointName = "";
  2353. /*if (paper[0].item[k].points.Count == 1)
  2354. {
  2355. foreach (string index in paper[0].item[k].points)
  2356. {
  2357. pointName = index;
  2358. }
  2359. }
  2360. else if (paper[0].item[k].points.Count > 1)
  2361. {
  2362. foreach (string index in paper[0].item[k].points)
  2363. {
  2364. pointName += index + ",";
  2365. }
  2366. }*/
  2367. values[22] = pointName;
  2368. datas.Add(values);
  2369. }
  2370. subject.Add("keys", key);
  2371. subject.Add("datas", datas);
  2372. exerciseScatter.Add(subject);
  2373. }
  2374. catch (Exception ex)
  2375. {
  2376. // throw new BizException(ex.Message);
  2377. }
  2378. });
  2379. return exerciseScatter;
  2380. }
  2381. else return exerciseScatter;
  2382. }
  2383. [HttpPost("answer")]
  2384. public async Task<IActionResult> answer(JsonElement request)
  2385. {
  2386. //获取评测的ID
  2387. if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
  2388. if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
  2389. try
  2390. {
  2391. var client = _azureCosmos.GetCosmosClient();
  2392. //获取本次评测所有科目结算结果
  2393. ExamInfo info = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"Exam-{code}"));
  2394. School school = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<School>(code.ToString(), new PartitionKey($"Base"));
  2395. List<ExamResult> examResults = new List<ExamResult>();
  2396. var query = $"select c.id,c.name,c.subjectId,c.studentScores,c.studentIds,c.paper,c.classes from c where c.examId = '{id}' ";
  2397. await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<ExamResult>(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamResult-{id}") }))
  2398. {
  2399. /*using var json = await JsonDocument.ParseAsync(item.ContentStream);
  2400. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  2401. {
  2402. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  2403. {
  2404. examResults.Add(obj.ToObject<ExamResult>());
  2405. }
  2406. }*/
  2407. examResults.Add(item);
  2408. }
  2409. //获取本次评测所有班级作答结果
  2410. List<ExamClassResult> examClassResults = new List<ExamClassResult>();
  2411. var queryClass = $"select c.id,c.code,c.name,c.school,c.examId,c.year,c.scope,c.pk,c.subjectId,c.studentScores,c.studentIds,c.gradeId,c.info,c.studentAnswers,c.sum,c.progress from c where c.examId = '{id}' ";
  2412. await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<ExamClassResult>(queryText: queryClass, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{code}") }))
  2413. {
  2414. examClassResults.Add(item);
  2415. /*using var json = await JsonDocument.ParseAsync(item.ContentStream);
  2416. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  2417. {
  2418. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  2419. {
  2420. examClassResults.Add(obj.ToObject<ExamClassResult>());
  2421. }
  2422. }*/
  2423. }
  2424. int m = 0;
  2425. foreach (ExamSubject subject in info.subjects) {
  2426. foreach (ExamClassResult classResult in examClassResults)
  2427. {
  2428. if (subject.id.Equals(classResult.subjectId)) {
  2429. int k = 0;
  2430. foreach (string stu in classResult.studentIds)
  2431. {
  2432. if (classResult.studentAnswers[k].Count > 0) {
  2433. k++;
  2434. continue;
  2435. }
  2436. int n = 0;
  2437. List<List<string>> ans = new List<List<string>>();
  2438. foreach (List<string> simple in info.papers[m].answers) {
  2439. List<string> option = new List<string>();
  2440. if (simple.Count > 0)
  2441. {
  2442. List<string> opt = new List<string>{ "A", "B", "C", "D" };
  2443. int rd=new Random().Next(0,3);
  2444. if (rd == 1 || rd == 2)
  2445. {
  2446. option.AddRange(simple);
  2447. classResult.studentScores[k][n] = info.papers[m].point[n];
  2448. }
  2449. else {
  2450. simple.ForEach(x => { opt.Remove(x); });
  2451. option.Add(opt[new Random().Next(0, opt.Count-1)]);
  2452. classResult.studentScores[k][n] = 0;
  2453. }
  2454. ans.Add(option);
  2455. }
  2456. else {
  2457. //classResult.studentScores[k][n] = new Random().Next(0, (int)info.papers[m].point[n]) * 1.0;
  2458. ans.Add(new List<string> { "测试作答数据一","测试作答数据二"});
  2459. }
  2460. n++;
  2461. }
  2462. string FileName = classResult.examId + "/" + classResult.subjectId + "/" + stu;
  2463. string blob = await _azureStorage.UploadFileByContainer(code.ToString(), ans.ToJsonString(), "exam", FileName + "/" + "ans.json");
  2464. classResult.studentAnswers[k].Add(blob);
  2465. classResult.sum[k] = classResult.studentScores[k].Sum();
  2466. k++;
  2467. }
  2468. //await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(classResult, classResult.id, new PartitionKey($"ExamClassResult-{code}"));
  2469. if (!classResult.progress) {
  2470. bool flag = true;
  2471. foreach (List<double> scores in classResult.studentScores)
  2472. {
  2473. foreach (double score in scores)
  2474. {
  2475. if (score == -1)
  2476. {
  2477. flag = false;
  2478. break;
  2479. }
  2480. }
  2481. }
  2482. if (flag)
  2483. {
  2484. classResult.progress = true;
  2485. info.subjects[m].classCount += 1;
  2486. }
  2487. }
  2488. await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(classResult, classResult.id, new PartitionKey($"ExamClassResult-{code}"));
  2489. }
  2490. }
  2491. m++;
  2492. }
  2493. await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(info, id.ToString(), new PartitionKey($"Exam-{code}"));
  2494. return Ok(new { examClassResults });
  2495. }
  2496. catch (Exception e)
  2497. {
  2498. await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/answer()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
  2499. return BadRequest();
  2500. }
  2501. }
  2502. [HttpPost("scoring")]
  2503. public async Task<IActionResult> Scoring(JsonElement request)
  2504. {
  2505. //获取评测的ID
  2506. if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
  2507. if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
  2508. try
  2509. {
  2510. var client = _azureCosmos.GetCosmosClient();
  2511. //获取本次评测所有科目结算结果
  2512. ExamInfo info = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"Exam-{code}"));
  2513. School school = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<School>(code.ToString(), new PartitionKey($"Base"));
  2514. List<ExamResult> examResults = new List<ExamResult>();
  2515. var query = $"select c.id,c.name,c.subjectId,c.studentScores,c.studentIds,c.paper,c.classes from c where c.examId = '{id}' ";
  2516. await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<ExamResult>(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamResult-{id}") }))
  2517. {
  2518. examResults.Add(item);
  2519. }
  2520. //获取本次评测所有班级作答结果
  2521. List<ExamClassResult> examClassResults = new List<ExamClassResult>();
  2522. var queryClass = $"select c.id,c.code,c.name,c.school,c.examId,c.year,c.scope,c.pk,c.subjectId,c.studentScores,c.studentIds,c.gradeId,c.info,c.studentAnswers,c.sum,c.progress from c where c.examId = '{id}' ";
  2523. await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<ExamClassResult>(queryText: queryClass, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{code}") }))
  2524. {
  2525. examClassResults.Add(item);
  2526. }
  2527. int m = 0;
  2528. foreach (ExamSubject subject in info.subjects)
  2529. {
  2530. foreach (ExamClassResult classResult in examClassResults)
  2531. {
  2532. if (subject.id.Equals(classResult.subjectId))
  2533. {
  2534. int k = 0;
  2535. foreach (string stu in classResult.studentIds)
  2536. {
  2537. int n = 0;
  2538. List<List<string>> ans = new List<List<string>>();
  2539. foreach (List<string> simple in info.papers[m].answers)
  2540. {
  2541. List<string> option = new List<string>();
  2542. if (simple.Count == 0)
  2543. {
  2544. classResult.studentScores[k][n] = new Random().Next(0, (int)info.papers[m].point[n]) * 1.0;
  2545. }
  2546. n++;
  2547. }
  2548. classResult.sum[k] = classResult.studentScores[k].Sum();
  2549. k++;
  2550. }
  2551. if (!classResult.progress)
  2552. {
  2553. bool flag = true;
  2554. foreach (List<double> scores in classResult.studentScores)
  2555. {
  2556. foreach (double score in scores)
  2557. {
  2558. if (score == -1)
  2559. {
  2560. flag = false;
  2561. break;
  2562. }
  2563. }
  2564. }
  2565. if (flag)
  2566. {
  2567. classResult.progress = true;
  2568. info.subjects[m].classCount += 1;
  2569. }
  2570. }
  2571. else {
  2572. info.updateTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  2573. }
  2574. await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(classResult, classResult.id, new PartitionKey($"ExamClassResult-{code}"));
  2575. }
  2576. }
  2577. m++;
  2578. }
  2579. await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(info, id.ToString(), new PartitionKey($"Exam-{code}"));
  2580. return Ok(new { examClassResults });
  2581. }
  2582. catch (Exception e)
  2583. {
  2584. await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/scoring()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
  2585. return BadRequest();
  2586. }
  2587. }
  2588. [HttpPost("import")]
  2589. public async Task<IActionResult> importIES3(JsonElement request)
  2590. {
  2591. //获取评测的ID
  2592. if (!request.TryGetProperty("exam", out JsonElement exam)) return BadRequest();
  2593. //if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
  2594. try
  2595. {
  2596. var client = _azureCosmos.GetCosmosClient();
  2597. ExamDto examDtos = new ExamDto();
  2598. examDtos = exam.ToObject<ExamDto>();
  2599. ExamInfo info = new ExamInfo();
  2600. info.code = info.pk + "-hbcn";
  2601. info.progress = "pending";
  2602. info.id = examDtos.id;
  2603. info.name = examDtos.name;
  2604. info.grades = examDtos.grades;
  2605. info.subjects = examDtos.subjects;
  2606. info.period = examDtos.period;
  2607. examDtos.targetClasses.ForEach(e => {
  2608. info.targetClassIds.Add(e.id);
  2609. });
  2610. examDtos.papers.ForEach(p => {
  2611. PaperSimple simple = new PaperSimple();
  2612. simple.id = p.id;
  2613. simple.name = p.name;
  2614. p.points.ForEach(po => {
  2615. simple.point.Add(double.Parse(po));
  2616. });
  2617. p.answers.ForEach(an =>
  2618. {
  2619. List<string> ans = new List<string>();
  2620. if (an.Length > 1)
  2621. {
  2622. char[] aa = an.ToCharArray();
  2623. foreach (char a in aa) {
  2624. switch (a)
  2625. {
  2626. case '1':
  2627. ans.Add("A");
  2628. break;
  2629. case '2':
  2630. ans.Add("B");
  2631. break;
  2632. case '3':
  2633. ans.Add("C");
  2634. break;
  2635. case '4':
  2636. ans.Add("D");
  2637. break;
  2638. default:
  2639. ans.Add("");
  2640. break;
  2641. }
  2642. }
  2643. }
  2644. else {
  2645. switch (an) {
  2646. case "1":
  2647. ans.Add("A");
  2648. break;
  2649. case "2":
  2650. ans.Add("B");
  2651. break;
  2652. case "3":
  2653. ans.Add("C");
  2654. break;
  2655. case "4":
  2656. ans.Add("D");
  2657. break;
  2658. default:
  2659. ans.Add("");
  2660. break;
  2661. }
  2662. }
  2663. simple.answers.Add(ans);
  2664. });
  2665. info.papers.Add(simple);
  2666. });
  2667. await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(info, new PartitionKey("Exam-hbcn"));
  2668. return Ok(new { info });
  2669. }
  2670. catch (Exception e)
  2671. {
  2672. await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/scoring()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
  2673. return BadRequest();
  2674. }
  2675. }
  2676. [HttpPost("importResult")]
  2677. public async Task<IActionResult> importClassResult(JsonElement request)
  2678. {
  2679. //获取评测的ID
  2680. if (!request.TryGetProperty("classResult", out JsonElement classResult)) return BadRequest();
  2681. if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
  2682. try
  2683. {
  2684. var client = _azureCosmos.GetCosmosClient();
  2685. List<ExamClassResultDto> examClassResultDto = new List<ExamClassResultDto>();
  2686. examClassResultDto = classResult.ToObject<List<ExamClassResultDto>>();
  2687. //获取本次评测所有班级作答结果
  2688. List<ExamClassResult> examClassResults = new List<ExamClassResult>();
  2689. var queryClass = $"select value(c) from c where c.examId = '{id}'";
  2690. await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<ExamClassResult>(queryText: queryClass, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("ExamClassResult-hbcn") }))
  2691. {
  2692. examClassResults.Add(item);
  2693. }
  2694. foreach (ExamClassResultDto e in examClassResultDto) {
  2695. foreach (ExamClassResult ex in examClassResults)
  2696. {
  2697. if (e.subject.Equals(ex.subjectId))
  2698. {
  2699. foreach (ClassResults examClass in e.examClassResult)
  2700. {
  2701. if (examClass.classInfo.id.Equals(ex.info.id))
  2702. {
  2703. ex.studentIds = examClass.studentIds;
  2704. List<List<double>> newScores = new List<List<double>>();
  2705. examClass.studentScores.ForEach(sc =>
  2706. {
  2707. List<double> scores = new List<double>();
  2708. if (sc.Count == 0)
  2709. {
  2710. for (int i =0;i< ex.studentScores[0].Count;i++) {
  2711. scores.Add(0);
  2712. }
  2713. }
  2714. else
  2715. {
  2716. sc.ForEach(s =>
  2717. {
  2718. scores.Add(double.Parse(s));
  2719. });
  2720. }
  2721. newScores.Add(scores);
  2722. });
  2723. ex.studentScores = newScores;
  2724. int index = 0;
  2725. List<Task<string>> tasks = new List<Task<string>>();
  2726. foreach (List<string> an in examClass.studentAnswers)
  2727. {
  2728. List<string> ans = new List<string>();
  2729. an.ForEach(aa =>
  2730. {
  2731. if (aa.Length > 1)
  2732. {
  2733. char[] str = aa.ToCharArray();
  2734. foreach (char a in aa)
  2735. {
  2736. switch (a)
  2737. {
  2738. case '1':
  2739. ans.Add("A");
  2740. break;
  2741. case '2':
  2742. ans.Add("B");
  2743. break;
  2744. case '3':
  2745. ans.Add("C");
  2746. break;
  2747. case '4':
  2748. ans.Add("D");
  2749. break;
  2750. default:
  2751. ans.Add("");
  2752. break;
  2753. }
  2754. }
  2755. }
  2756. else
  2757. {
  2758. switch (aa)
  2759. {
  2760. case "1":
  2761. ans.Add("A");
  2762. break;
  2763. case "2":
  2764. ans.Add("B");
  2765. break;
  2766. case "3":
  2767. ans.Add("C");
  2768. break;
  2769. case "4":
  2770. ans.Add("D");
  2771. break;
  2772. default:
  2773. ans.Add("");
  2774. break;
  2775. }
  2776. }
  2777. });
  2778. string FileName = ex.examId + "/" + ex.subjectId + "/" + examClass.studentIds[index];
  2779. string blob = FileName + "/" + "ans.json";
  2780. tasks.Add(_azureStorage.UploadFileByContainer(ex.school.ToString(), ans.ToJsonString(), "exam", FileName + "/" + "ans.json"));
  2781. ex.studentAnswers[index].Add(blob);
  2782. index++;
  2783. }
  2784. await Task.WhenAll(tasks);
  2785. }
  2786. }
  2787. }
  2788. }
  2789. }
  2790. foreach (ExamClassResult result in examClassResults) {
  2791. await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(result, result.id, new PartitionKey($"{result.code}"));
  2792. }
  2793. return Ok(new { examClassResults });
  2794. }
  2795. catch (Exception e)
  2796. {
  2797. await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/importResult()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
  2798. return BadRequest();
  2799. }
  2800. }
  2801. private List<Dictionary<string, dynamic>> getKnowledgePoint(List<ExamResult> examResults, ExamInfo info)
  2802. {
  2803. Dictionary<string, object> stuMap = new Dictionary<string, object>
  2804. {
  2805. { "schoolCode", "Habook" }
  2806. };
  2807. List<Dictionary<string, object>> keyValues = new List<Dictionary<string, object>>();
  2808. HashSet<string> knowledge = new HashSet<string>();
  2809. HashSet<string> area = new HashSet<string>();
  2810. List<double> point = new List<double>();
  2811. List<List<double>> result = new List<List<double>>();
  2812. List<ClassRange> classes = new List<ClassRange>();
  2813. List<string> ids = new List<string>();
  2814. examResults.ForEach(e =>
  2815. {
  2816. //定位试卷信息
  2817. int index = 0;
  2818. foreach (ExamSubject subject in info.subjects)
  2819. {
  2820. if (subject.id.Equals(e.subjectId))
  2821. {
  2822. break;
  2823. }
  2824. else
  2825. {
  2826. index++;
  2827. }
  2828. }
  2829. info.papers[index].knowledge.ForEach(k =>
  2830. {
  2831. k.ForEach(e =>
  2832. {
  2833. knowledge.Add(e);
  2834. });
  2835. });
  2836. info.papers[index].field.ForEach(f =>
  2837. {
  2838. area.Add(f.ToString());
  2839. });
  2840. double Qnum = 0;
  2841. point = info.papers[index].point;
  2842. result = e.studentScores;
  2843. classes = e.classes;
  2844. ids = e.studentIds;
  2845. //确定高分组 低分组人数
  2846. List<List<double>> re = e.studentScores;
  2847. List<double> resultSum = new List<double>();
  2848. foreach (List<double> data in re)
  2849. {
  2850. resultSum.Add(data.Sum());
  2851. }
  2852. //确定高分组 最低分数
  2853. resultSum.Sort(delegate (double s1, double s2) { return s2.CompareTo(s1); });
  2854. for (int i = resultSum.Count - 1; i >= 0; i--)
  2855. {
  2856. if (resultSum[i] == 0)
  2857. {
  2858. resultSum.Remove(resultSum[i]);
  2859. }
  2860. }
  2861. double rhwCount = resultSum.Count * 0.27;
  2862. double rhw = resultSum[int.Parse(rhwCount.ToString("0"))];
  2863. //确定低分组 最高分数
  2864. resultSum.Sort(delegate (double s1, double s2) { return s1.CompareTo(s2); });
  2865. double rhlCount = resultSum.Count * 0.27;
  2866. double rhl = resultSum[int.Parse(rhwCount.ToString("0"))];
  2867. List<string> knowledgeName = new List<string>();
  2868. foreach (string cla in knowledge)
  2869. {
  2870. knowledgeName.Add(cla);
  2871. }
  2872. for (int k = 0; k < knowledgeName.Count; k++)
  2873. {
  2874. if (null == knowledgeName[k])
  2875. {
  2876. knowledgeName.Remove(knowledgeName[k]);
  2877. }
  2878. }
  2879. List<string> areaName = new List<string>();
  2880. foreach (string cla in area)
  2881. {
  2882. areaName.Add(cla);
  2883. }
  2884. for (int k = 0; k < areaName.Count; k++)
  2885. {
  2886. if (null == areaName[k])
  2887. {
  2888. areaName.Remove(areaName[k]);
  2889. }
  2890. }
  2891. //初始化年级总分
  2892. double total = 0;
  2893. //处理年级单个知识点得分率
  2894. foreach (List<double> grade in result)
  2895. {
  2896. total += grade.Sum();
  2897. }
  2898. foreach (string id in ids)
  2899. {
  2900. if (!id.Equals("0"))
  2901. {
  2902. Qnum++;
  2903. }
  2904. }
  2905. //试卷总分
  2906. double TotalPoint = point.Sum();
  2907. //计算认知层次占比
  2908. List<string> fper = new List<string>();
  2909. for (int a = 0; a < areaName.Count; a++)
  2910. {
  2911. double fieldPoint = 0;
  2912. int no = 0;
  2913. info.papers[index].field.ForEach(f =>
  2914. {
  2915. if (f.ToString().Equals(areaName[a], StringComparison.OrdinalIgnoreCase))
  2916. {
  2917. e.studentScores.ForEach(s =>
  2918. {
  2919. fieldPoint += s[no];
  2920. });
  2921. }
  2922. no++;
  2923. });
  2924. double fieldPersent = fieldPoint / TotalPoint;
  2925. fper.Add(fieldPersent.ToString("0.00"));
  2926. }
  2927. //求单个知识点所占分数
  2928. List<string> per = new List<string>();
  2929. List<string> gper = new List<string>();
  2930. List<string> knowPer = new List<string>();
  2931. List<Dictionary<string, double>> eper = new List<Dictionary<string, double>>();
  2932. Dictionary<string, object> knowledgeALL = new Dictionary<string, object>();
  2933. Dictionary<string, object> knowledgeMap = new Dictionary<string, object>();
  2934. Dictionary<string, object> classMap = new Dictionary<string, object>();
  2935. Dictionary<string, object> wrongMap = new Dictionary<string, object>();
  2936. HashSet<string> className = new HashSet<string>();
  2937. List<List<string>> wrongPersent = new List<List<string>>();
  2938. List<string> key = new List<string>
  2939. {
  2940. "id",
  2941. "className",
  2942. "seatNO",
  2943. "point",
  2944. "anwPoint",
  2945. "persent"
  2946. };
  2947. List<string> keyWrong = new List<string>
  2948. {
  2949. "name",
  2950. "point",
  2951. "itemNO",
  2952. "persent",
  2953. "wrong",
  2954. "rhw",
  2955. "rlw"
  2956. };
  2957. for (int k = 0; k < knowledgeName.Count; k++)
  2958. {
  2959. List<string> knowledgeClass = new List<string>();
  2960. List<List<string>> stuPersent = new List<List<string>>();
  2961. double OnePoint = 0;
  2962. //获取每个知识点占有多少分值
  2963. double ePoint = 0;
  2964. double anwGPoint = 0;
  2965. double poG = 0;
  2966. int m = 0;
  2967. List<string> valuew = new List<string>();
  2968. List<string> itemNo = new List<string>();
  2969. keyWrong.ForEach(x =>
  2970. {
  2971. valuew.Add("-");
  2972. });
  2973. int wrongCount = 0;
  2974. valuew[0] = knowledgeName[k];
  2975. int n = 0;
  2976. info.papers[index].knowledge.ForEach(kno =>
  2977. {
  2978. if (kno.Contains(knowledgeName[k]))
  2979. {
  2980. OnePoint += point[n];
  2981. itemNo.Add((n + 1).ToString());
  2982. }
  2983. valuew[1] = OnePoint.ToString();
  2984. string itemNos = "";
  2985. if (itemNo.Count > 0)
  2986. {
  2987. foreach (string np in itemNo)
  2988. {
  2989. itemNos += np + ",";
  2990. }
  2991. valuew[2] = itemNos[0..^1];
  2992. }
  2993. else
  2994. {
  2995. valuew[2] = itemNos;
  2996. }
  2997. n++;
  2998. });
  2999. int rhwC = 0;
  3000. int rhlC = 0;
  3001. foreach (string id in ids)
  3002. {
  3003. if (id.Equals("0") || result[m].Sum() == 0)
  3004. {
  3005. m++;
  3006. continue;
  3007. }
  3008. List<string> values = new List<string>();
  3009. key.ForEach(x =>
  3010. {
  3011. values.Add("-");
  3012. });
  3013. /* foreach (OldStudent info in students)
  3014. {
  3015. if (info.studentId.Equals(id))
  3016. {
  3017. values[2] = info.seatNo.ToString();
  3018. break;
  3019. }
  3020. }*/
  3021. //List<string> stu = new List<string>();
  3022. values[0] = id;
  3023. values[1] = "-";
  3024. //List<List<string>> stuItem = new List<List<string>>();
  3025. int statuCount = 0;
  3026. info.papers[index].knowledge.ForEach(kno => {
  3027. int sno = 0;
  3028. double anwPoint = 0;
  3029. double po = 0;
  3030. if (kno.Contains(knowledgeName[k])) {
  3031. //当前认知层次在该题占比多少
  3032. ePoint = 1;
  3033. anwPoint += result[m][sno] * ePoint;
  3034. //所有学生单个认知层次得分情况
  3035. anwGPoint += result[m][sno] * ePoint;
  3036. po += point[sno] * ePoint;
  3037. //认知层次所占分数
  3038. poG += point[sno] * ePoint;
  3039. if (result[m][sno] == 0 && statuCount == 0)
  3040. {
  3041. statuCount++;
  3042. wrongCount++;
  3043. if (result[m].Sum() >= rhw)
  3044. {
  3045. rhwC++;
  3046. }
  3047. if (result[m].Sum() <= rhl)
  3048. {
  3049. rhlC++;
  3050. }
  3051. }
  3052. if (po == 0)
  3053. {
  3054. values[3] = "0";
  3055. values[4] = "0";
  3056. values[5] = "0";
  3057. }
  3058. else
  3059. {
  3060. double stuPser = anwPoint / po;
  3061. values[3] = po.ToString();
  3062. values[4] = anwPoint.ToString();
  3063. values[5] = stuPser.ToString("0.00");
  3064. }
  3065. }
  3066. });
  3067. stuPersent.Add(values);
  3068. m++;
  3069. }
  3070. //AchievementService.ReName(stuPersent, ids, classes, students);
  3071. double knowPser = 0;
  3072. if (poG == 0)
  3073. {
  3074. knowPer.Add("0");
  3075. }
  3076. else
  3077. {
  3078. knowPser = anwGPoint / poG;
  3079. knowPer.Add(knowPser.ToString("0.00"));
  3080. }
  3081. //错题关系表
  3082. valuew[3] = knowPser.ToString("0.00");
  3083. valuew[4] = wrongCount.ToString();
  3084. valuew[5] = rhwC.ToString();
  3085. valuew[6] = rhlC.ToString();
  3086. wrongPersent.Add(valuew);
  3087. knowledgeMap.Add(knowledgeName[k], stuPersent);
  3088. //知识点占比
  3089. double persent = OnePoint / TotalPoint;
  3090. foreach (ClassRange classRange in e.classes) {
  3091. List<string> classPoints = new List<string>();
  3092. //初始化班级得分
  3093. double anwCPoint = 0;
  3094. double cpo = 0;
  3095. for (int stuIndex = classRange.range[0]; stuIndex < classRange.range[1]; stuIndex++)
  3096. {
  3097. if (result[stuIndex].Sum() == 0) continue;
  3098. info.papers[index].knowledge.ForEach(kno => {
  3099. int x = 0;
  3100. if (kno.Contains(knowledgeName[k])) {
  3101. //当前认知层次在该题占比多少
  3102. ePoint = 1;
  3103. anwCPoint += result[stuIndex][x] * ePoint;
  3104. cpo += point[x] * ePoint;
  3105. }
  3106. });
  3107. }
  3108. if (cpo == 0)
  3109. {
  3110. //double classPser = anwCPoint / cpo;
  3111. knowledgeClass.Add("0");
  3112. }
  3113. else
  3114. {
  3115. double classPser = anwCPoint / cpo;
  3116. knowledgeClass.Add(classPser.ToString("0.00"));
  3117. }
  3118. }
  3119. classMap.Add(knowledgeName[k], knowledgeClass);
  3120. per.Add(persent.ToString("0.00"));
  3121. }
  3122. knowledgeMap.Add("grade", knowPer);
  3123. knowledgeMap.Add("keys", key);
  3124. classMap.Add("className", className);
  3125. wrongMap.Add("keys", keyWrong);
  3126. wrongMap.Add("datas", wrongPersent);
  3127. knowledgeALL.Add("pointList", knowledgeName);
  3128. knowledgeALL.Add("per", per);
  3129. knowledgeALL.Add("level", areaName);
  3130. knowledgeALL.Add("fper", fper);
  3131. knowledgeALL.Add("stupercent", knowledgeMap);
  3132. knowledgeALL.Add("classpercent", classMap);
  3133. knowledgeALL.Add("wrong", wrongMap);
  3134. keyValues.Add(knowledgeALL);
  3135. });
  3136. return keyValues;
  3137. }
  3138. }
  3139. }