123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300 |
- using ClouDASLibx;
- using Microsoft.AspNetCore.Mvc;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.Json;
- using System.Threading.Tasks;
- using TEAMModelOS.SDK.Models;
- using TEAMModelOS.SDK;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK.Extension;
- using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
- using TEAMModelOS.SDK.Helper.Common.StringHelper;
- using TEAMModelOS.SDK.Helper.Security.ShaHash;
- using TEAMModelOS.Services.Analysis;
- using Microsoft.Extensions.Options;
- using TEAMModelOS.Models;
- using Azure.Cosmos;
- using TEAMModelOS.SDK.Models.Cosmos.Student;
- using static TEAMModelOS.SDK.Models.Cosmos.Student.StudentAnalysis;
- using TEAMModelOS.SDK.Models.Cosmos.School;
- using static TEAMModelOS.SDK.Models.Cosmos.School.ClassAnalysis;
- using static TEAMModelOS.SDK.Models.Cosmos.School.GradeAnalysis;
- using TEAMModelOS.Models.Dto;
- namespace TEAMModelOS.Controllers.Analysis
- {
- [Route("analysis")]
- [ApiController]
- public class AchievementController : Controller
- {
- private readonly AzureCosmosFactory _azureCosmos;
- private readonly DingDing _dingDing;
- private readonly Option _option;
- private const string CacheCosmosPrefix = "Analysis:";
- private const int timeoutSeconds = 3600;
- public readonly AzureStorageFactory _azureStorage;
- public AchievementController(AzureCosmosFactory azureCosmos, DingDing dingDing, IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage)
- {
- _azureCosmos = azureCosmos;
- _dingDing = dingDing;
- _option = option?.Value;
- _azureStorage = azureStorage;
- }
- [HttpPost("Achievement")]
- public async Task<BaseResponse> FindExam(JsonElement request)
- {
- ResponseBuilder builder = ResponseBuilder.custom();
- Dictionary<string, object> dict = new Dictionary<string, object>();
- var emobj = request.EnumerateObject();
- while (emobj.MoveNext())
- {
- dict[emobj.Current.Name] = emobj.Current.Value;
- }
- Dictionary<string, dynamic> info = new Dictionary<string, dynamic>();
- if (RedisHelper.Instance != null)
- {
- info = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "Achievement",
- ShaHashHelper.GetSHA1(dict.ToJsonString()), timeoutSeconds, () => { return FindExamRedis(dict, "Achievement"); });
- //数据从redis读取过后进行转换格式
- builder.Data(info);
- }
- else
- {
- info = await FindExamRedis(dict, "Achievement");
- builder.Data(info);
- }
- return builder.build();
- }
- public async Task<List<ExamResult>> FindExamResultRedis(Dictionary<string, object> dict, string method)
- {
- return new List<ExamResult>();
- //try
- //{
- // List<ExamResult> info = await _azureCosmos.FindByDict<ExamResult>(dict);
- // if (RedisHelper.Instance != null)
- // {
- // if (!RedisHelper.Exists(CacheCosmosPrefix + method))
- // {
- // await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), info);
- // }
- // else
- // {
- // await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), info);
- // await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
- // }
- // }
- // return info;
- //}
- //catch (Exception e)
- //{
- // throw new BizException(e.Message);
- //}
- }
- public async Task<Dictionary<string, dynamic>> FindExamRedis(Dictionary<string, object> dict, string method)
- {
- ResponseBuilder builder = ResponseBuilder.custom();
- //Console.WriteLine(DateTimeOffset.Now.Second);
- //
- dict.TryGetValue("subjectCode", out object subjectCode);
- dict.TryGetValue("code", out object code);
- dict.TryGetValue("schoolCode", out object schoolCode);
- List<ExamResultDto> exams = new List<ExamResultDto>();
- /*if (RedisHelper.Instance != null)
- {
- exams = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "FindExamResultRedis",
- ShaHashHelper.GetSHA1(dict.ToJsonString()), timeoutSeconds, () => { return FindExamResultRedis(dict, "FindExamResultRedis"); });
- }
- else
- {
- exams = await FindExamResultRedis(dict, "FindExamResultRedis");
- }*/
- List<string> subjectCouns = JsonExtensions.ToObject<List<string>>(subjectCode.ToJsonString());
- for (int i = 0; i < subjectCouns.Count; i++)
- {
- if (RedisHelper.Exists(CacheCosmosPrefix + "examResult" + subjectCouns[i]))
- {
- ExamResultDto result = RedisHelper.HGet<ExamResultDto>(CacheCosmosPrefix + "examResult" + subjectCouns[i], ShaHashHelper.GetSHA1(code.ToString()));
- //builder.Data(info);
- exams.Add(result);
- }
- }
- Dictionary<string, object> stuMap = new Dictionary<string, object>
- {
- { "schoolCode", "Habook" }
- };
- //声明进行标准用来设置进线标准,权重等参数
- dict.TryGetValue("Standard", out object Standard);
- //List<Student> students = await _azureCosmos.FindByDict<Student>(stuMap);
- List<OldStudent> students = null;
- if (RedisHelper.Exists(CacheCosmosPrefix + "students"))
- {
- students = RedisHelper.HGet<List<OldStudent>>(CacheCosmosPrefix + "students", ShaHashHelper.GetSHA1(schoolCode.ToString()));
- //builder.Data(info);
- //students.Add(student);
- }
- //Console.WriteLine(DateTimeOffset.Now.Second);
- List<Dictionary<string, object>> examList = new List<Dictionary<string, object>>();
- HashSet<string> classList = new HashSet<string>();
- HashSet<string> classId = new HashSet<string>();
- List<string> subjectAverage = new List<string>();
- List<List<string>> subjectPoints = new List<List<string>>();
- Dictionary<string, object> Average = new Dictionary<string, object>();
- Dictionary<string, object> entryTable = new Dictionary<string, object>();
- Dictionary<string, dynamic> achievementAnalysis = new Dictionary<string, dynamic>();
- List<string> arrSubject = new List<string>();
- List<string> keys = new List<string>();
- List<string> person = new List<string>();
- List<List<double>> subSum = new List<List<double>>();
- List<string> gAverage = new List<string>();
- List<string> cAverage = new List<string>();
- Dictionary<string, object> AclassAverage = new Dictionary<string, object>();
- Dictionary<string, object> passRateMap = new Dictionary<string, object>();
- List<List<string>> passALL = new List<List<string>>();
- List<string> gradeList = new List<string>();
- List<string> areaList = new List<string>();
- List<string> sbujectsList = new List<string>();
- if (exams.IsNotEmpty())
- {
- //存放进线情况统计key值
- keys.Add("name");
- keys.Add("className");
- keys.Add("gradeRank");
- keys.Add("score");
- //初始化进行人数
- double iPersons = 0;
- if (exams.IsNotEmpty())
- {
- int classLen = exams[0].classes.Count;
- for (int cls = 0; cls < classLen; cls++)
- {
- if (exams[0].classes[cls].TryGetValue(exams[0].classes[cls].Keys.ToArray<string>()[0], out int[] index))
- {
- List<double> stuScore = new List<double>();
- int stdLen = index[1] - index[0] + 1;
- for (int i = 0; i < stdLen; i++)
- {
- stuScore.Add(0);
- }
- subSum.Add(stuScore);
- }
- }
- }
- int xx = 0;
- //初始化总分
- double sumPoint = 0;
- int sumperson = exams[0].ids.Count;
- for (int i = 0; i < exams[0].ids.Count; i++)
- {
- if (exams[0].ids[i].Equals("0"))
- {
- sumperson--;
- }
- }
- exams.ForEach(e =>
- {
- //获取总分数
- e.result.ForEach(r =>
- {
- sumPoint += r.Sum();
- });
- });
- var gradeAverage = sumPoint / sumperson;
- //存放年级平均
- gAverage.Add(gradeAverage.ToString());
- //任意一次考试数据提取班级信息
- List<Dictionary<string, int[]>> classToName = exams[0].classes;
- //任意一次考试数据提取学生ID信息
- List<string> idToName = exams[0].ids;
- //var gradeAverage = Math.Floor(Math.Round(decimal.Parse((10 / 3).ToString("0.000")), 2));
- List<string> subjects = new List<string>();
- exams.ForEach(e =>
- {
- int peopleCount = 0;
- Dictionary<string, object> detail = new Dictionary<string, object>
- {
- { "name", e.subjectCode }
- };
- subjects.Add(e.subjectCode);
- List<string> ClassAverage = new List<string>();
- //计算试卷总分
- double sum = e.point.Sum();
- //及格分数
- double passRate = sum * 0.6;
- int gradeCount = 0;
- //初始化科目总分
- double subjectPoint = 0;
- //科目平均分
- double subAverage = 0;
- //计算班级平均分
- int classIndex = 0;
- List<string> passList = new List<string>();
- e.classes.ForEach(c =>
- {
- List<List<string>> classPRL = new List<List<string>>();
- //初始化班级总分
- double classPoint = 0;
- //初始化班级缺考人数
- int classCount = 0;
- //初始化班级平均分
- double points = 0;
- double passPoint = 0;
- //初始化及格人数
- int passCount = 0;
- //初始化各班参考人数
- int counts = 0;
- //c.Keys遍历key值
- foreach (string key in c.Keys)
- {
- classList.Add(key);
- }
- //每个班级平均分
- foreach (int[] value in c.Values)
- {
- for (int i = value[0]; i <= value[1]; i++)
- {
- //初始化学生单科个人得分
- double stuPoints = e.result[i].Sum();
- //Console.WriteLine("xx: "+xx+" classIndex:" + classIndex + ",i:" + i + " value[0]:" + value[0]+ " value[0]:" + value[1]);
- subSum[classIndex][i - value[0]] = stuPoints + subSum[classIndex][i - value[0]];
- if (stuPoints > passRate)
- {
- passCount++;
- gradeCount++;
- }
- classPoint += e.result[i].Sum();
- if (e.result[i].Sum() == 0)
- {
- classCount++;
- }
- }
- //每个班级实际参考人数
- counts = value[1] - value[0] - classCount + 1;
- points = Convert.ToDouble(classPoint) / counts;
- ClassAverage.Add(points.ToString("0.00"));
- person.Add(counts + "");
- }
- passPoint = Convert.ToDouble(passCount) / counts;
- passList.Add(passPoint.ToString("0.00"));
- //classPRM.Add(classPRL);
- classIndex += 1;
- });
- //科目平均分
- ClassAverage.ForEach(a =>
- {
- subjectPoint += Convert.ToDouble(a);
- });
- subAverage = subjectPoint / ClassAverage.Count();
- subjectAverage.Add(subAverage.ToString("0.00"));
- detail.Add("schoolAverage", subAverage.ToString("0.00"));
- detail.Add("areaAverage", subAverage.ToString("0.00"));
- detail.Add("score", ClassAverage);
- examList.Add(detail);
- //获取实际参考总人数
- e.ids.ForEach(i =>
- {
- if (!i.Equals("0"))
- {
- peopleCount++;
- }
- });
- //班级及格率
- passALL.Add(passList);
- //年级及格率
- double gradePass = Convert.ToDouble(gradeCount) / peopleCount;
- gradeList.Add(gradePass.ToString("0.00"));
- //passALL.Add(gradeList);
- //区级及格率
- //passALL.Add(areaList);
- //获取进线人数
- iPersons = peopleCount * 0.4;
- //计算每个学生单科成绩
- for (int i = 0; i < e.ids.Count(); i++)
- {
- List<string> info = new List<string>();
- //info = new List<string>();
- info.Add(e.ids[i]);
- info.Add(e.subjectCode);
- info.Add(e.result[i].Sum() + "");
- //classId.Add(e.Ids[i]);
- subjectPoints.Add(info);
- }
- keys.Add(e.subjectCode);
- xx += 1;
- //subjectPoints = GetMark(e.Result,e.Ids);
- });
- //subjectPoints.ForEach(f => f.GroupBy(f[0]));
- //进线情况统计
- Dictionary<string, List<List<string>>> dicts = new Dictionary<string, List<List<string>>>();
- foreach (IGrouping<string, List<string>> group in subjectPoints.GroupBy(c => c[0]))
- {
- dicts.Add(group.Key, group.ToList());
- };
- Average.Add("classList", classList);
- List<List<string>> sp = new List<List<string>>();
- //Dictionary<string, int> rankScore = new Dictionary<string, int>();
- List<double> rankScore = new List<double>();
- foreach (string key in dicts.Keys)
- {
- double score = 0;
- List<string> values = new List<string>();
- keys.ForEach(x =>
- {
- values.Add("-");
- });
- foreach (List<string> val in dicts[key])
- {
- int index = keys.IndexOf(val[1]);
- values[index] = val[2];
- values[keys.IndexOf("name")] = val[0];
- score += double.Parse(val[2]);
- values[keys.IndexOf("score")] = score + "";
- }
- rankScore.Add(score);
- sp.Add(values);
- }
- AchievementService.ReName(sp, idToName, classToName, students);
- //处理人数为整
- string ip = iPersons.ToString("0");
- //初始化进线分数
- double ipoint = 0;
- //计算成绩年级排名
- rankScore.Sort(delegate (double s1, double s2) { return s2.CompareTo(s1); });
- ipoint = rankScore[int.Parse(ip)];
- foreach (List<string> rank in sp)
- {
- int index = rankScore.IndexOf(double.Parse(rank[3]));
- rank[2] = (index + 1) + "";
- }
- //排除成绩为零的选手
- for (int i = sp.Count - 1; i >= 0; i--)
- {
- if (sp[i][0].Equals("0"))
- {
- sp.Remove(sp[i]);
- }
- }
- entryTable.Add("keys", keys);
- entryTable.Add("datas", sp);
- //封装进线人数统计
- List<string> keyLine = new List<string>
- {
- "gradeRank",
- "name",
- "entryNum",
- "totalNum",
- "overAverageRate"
- };
- Dictionary<string, object> entryLineBar = new Dictionary<string, object>();
- //存放班级信息
- List<string> className = new List<string>();
- foreach (string cla in classList)
- {
- className.Add(cla);
- }
- List<List<string>> datas = new List<List<string>>();
- //记录各个班级进线率占比
- List<string> persent = new List<string>();
- int m = 0;
- foreach (List<double> points in subSum)
- {
- List<string> detail = new List<string>();
- keyLine.ForEach(x =>
- {
- detail.Add("-");
- });
- double sum = points.Count;
- int j = 0;
- for (int i = 0; i < points.Count; i++)
- {
- if (points[i] > ipoint)
- {
- j++;
- }
- }
- double Lines = j;
- detail[1] = className[m].ToString();
- detail[2] = j.ToString();
- detail[3] = points.Count.ToString();
- var t3 = Math.Floor(Math.Round(decimal.Parse((Lines / sum).ToString("0.000")), 2) * 100);
- persent.Add(t3.ToString());
- detail[4] = t3.ToString();
- datas.Add(detail);
- m++;
- }
- persent.Sort(delegate (string s1, string s2) { return int.Parse(s2).CompareTo(int.Parse(s1)); });
- //存放班级的年级排名
- List<string> ranks = new List<string>();
- foreach (List<string> des in datas)
- {
- int index = persent.IndexOf(des[4]);
- des[0] = (index + 1).ToString();
- ranks.Add((index + 1).ToString());
- }
- //预警统计
- Dictionary<string, object> early = new Dictionary<string, object>();
- List<List<string>> earlyWarning = new List<List<string>>();
- List<string> keyWarning = new List<string>
- {
- "classId",
- "totalNum",
- "average",
- "standardDeviation",
- "overAverageRate",
- "gradeRank"
- };
- int n = 0;
- foreach (List<double> points in subSum)
- {
- double sum = 0;
- List<string> classInfo = new List<string>();
- classInfo.Add(className[n]);
- classInfo.Add(points.Count.ToString());
- foreach (int point in points)
- {
- sum += point;
- }
- double Aver = sum / points.Count;
- classInfo.Add(Aver.ToString());
- //存放班级平均
- cAverage.Add(Aver.ToString());
- //标准差
- double powSum = 0;
- foreach (int point in points)
- {
- powSum += Math.Pow(point - Aver, 2);
- }
- var pow = Math.Pow(powSum / points.Count, 0.5);
- classInfo.Add(pow.ToString("0.00"));
- //超均率
- var super = (sum - (sum - 100)) / (sum - 100);
- classInfo.Add(super.ToString("0.00"));
- //年级排名
- classInfo.Add(ranks[n]);
- earlyWarning.Add(classInfo);
- n++;
- }
- //sbujectsList.Add(subjects);
- passRateMap.Add("subjects", subjects);
- passRateMap.Add("class", passALL);
- passRateMap.Add("grade", gradeList);
- passRateMap.Add("area", areaList);
- //passRate.Add("passRate", passALL);
- early.Add("keys", keyWarning);
- early.Add("datas", earlyWarning);
- AclassAverage = AchievementService.GetAverage(exams, gAverage, cAverage, subSum, students);
- List<Dictionary<string, object>> rankPR = AchievementService.GetPR(exams, subSum, students);
- entryLineBar.Add("keys", keyLine);
- entryLineBar.Add("datas", datas);
- //sp.Sort(delegate (string s1, string s2) { return int.Parse(s1).CompareTo(int.Parse(s2)); });
- Average.Add("subjectAverage", subjectAverage);
- Average.Add("datas", examList);
- achievementAnalysis.Add("passRate", passRateMap);
- achievementAnalysis.Add("average", Average);
- achievementAnalysis.Add("entryLineBar", entryLineBar);
- achievementAnalysis.Add("entryTable", entryTable);
- achievementAnalysis.Add("earlyWarning", early);
- achievementAnalysis.Add("rankPR", rankPR);
- achievementAnalysis.Add("stuAverage", AclassAverage);
- //Redis处理结果集
- if (RedisHelper.Instance != null)
- {
- if (!RedisHelper.Exists(CacheCosmosPrefix + method))
- {
- await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), achievementAnalysis);
- }
- else
- {
- await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), achievementAnalysis);
- await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
- }
- }
- return achievementAnalysis;
- }
- else return achievementAnalysis;
- }
- /* public List<string> GetMark(List<List<int>> point,List<string> ids) {
- List<string> info = null;
- for (int i = 0;i <= ids.Count();i++) {
- info = new List<string>();
- info.Add(ids[i]);
- info.Add(point[i].Sum()+"");
- }
- return info;
- }*/
- [HttpPost("PointAnalysis")]
- public async Task<BaseResponse> PointAnalysis(JsonElement request)
- {
- ResponseBuilder builder = ResponseBuilder.custom();
- /*Dictionary<string, object> dict = new Dictionary<string, object>();
- var emobj = request.EnumerateObject();
- while (emobj.MoveNext())
- {
- dict[emobj.Current.Name] = emobj.Current.Value;
- }
- List<Dictionary<string, dynamic>> info = new List<Dictionary<string, dynamic>>();
- if (RedisHelper.Instance != null)
- {
- info = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "PointAnalysis",
- ShaHashHelper.GetSHA1(dict.ToJsonString()), timeoutSeconds, () => { return FindPointAnalysisRedis(dict, "PointAnalysis"); });
- //数据从redis读取过后进行转换格式
- builder.Data(info);
- }
- else
- {
- info = await FindPointAnalysisRedis(dict, "PointAnalysis");
- builder.Data(info);
- }*/
- return builder.build();
- }
- [HttpPost("ExerciseScatter")]
- public async Task<BaseResponse> ExerciseScatter(JsonElement request)
- {
- /* ResponseBuilder builder = ResponseBuilder.custom();
- Dictionary<string, object> dict = new Dictionary<string, object>();
- var emobj = request.EnumerateObject();
- while (emobj.MoveNext())
- {
- dict[emobj.Current.Name] = emobj.Current.Value;
- }
- List<Dictionary<string, dynamic>> info = new List<Dictionary<string, dynamic>>();
- if (RedisHelper.Instance != null)
- {
- info = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "ExerciseScatter",
- ShaHashHelper.GetSHA1(dict.ToJsonString()), timeoutSeconds, () => { return FindExerciseScatterRedis(dict, "ExerciseScatter"); });
- //数据从redis读取过后进行转换格式
- builder.Data(info);
- }
- else
- {
- info = await FindExerciseScatterRedis(dict, "ExerciseScatter");
- builder.Data(info);
- }*/
- return null;
- }
- public async Task<Dictionary<string, dynamic>> FindKnowledgePointRedis(Dictionary<string, object> dict, string method)
- {
- //ResponseBuilder builder = ResponseBuilder.custom();
- dict.TryGetValue("subjectCode", out object subjectCode);
- dict.TryGetValue("schoolCode", out object schoolCode);
- dict.TryGetValue("code", out object code);
- //dict.TryGetValue("scopeCode", out object scopeCode);
- /* Dictionary<string, object> sub = new Dictionary<string, object>
- {
- { "subjectCode", subjectCode.ToString()},
- { "code",code.ToString()}
- };
- Dictionary<string, object> examMap = new Dictionary<string, object>
- {
- { "schoolCode", schoolCode.ToString()},
- { "code", code.ToString()},
- { "subjectCode", subjectCode.ToString()}
- };*/
- List<ExamResultDto> exams = new List<ExamResultDto>();
- if (RedisHelper.Exists(CacheCosmosPrefix + "examResult" + subjectCode.ToString()))
- {
- ExamResultDto res = RedisHelper.HGet<ExamResultDto>(CacheCosmosPrefix + "examResult" + subjectCode.ToString(), ShaHashHelper.GetSHA1(code.ToString()));
- exams.Add(res);
- }
- List<PaperDto> paper = new List<PaperDto>();
- if (RedisHelper.Exists(CacheCosmosPrefix + "paperInfo" + subjectCode.ToString()))
- {
- PaperDto papers = RedisHelper.HGet<PaperDto>(CacheCosmosPrefix + "paperInfo" + subjectCode.ToString(), ShaHashHelper.GetSHA1(code.ToString()));
- paper.Add(papers);
- }
- Dictionary<string, object> stuMap = new Dictionary<string, object>
- {
- { "schoolCode", "Habook" }
- };
- //List<Student> students = await azureCosmosDBRepository.FindByDict<Student>(stuMap);
- List<OldStudent> students = null;
- if (RedisHelper.Exists(CacheCosmosPrefix + "students"))
- {
- students = RedisHelper.HGet<List<OldStudent>>(CacheCosmosPrefix + "students", ShaHashHelper.GetSHA1(schoolCode.ToString()));
- //builder.Data(info);
- //students.Add(student);
- }
- HashSet<string> knowledge = new HashSet<string>();
- HashSet<string> area = new HashSet<string>();
- List<double> point = new List<double>();
- List<List<double>> result = new List<List<double>>();
- List<Dictionary<string, int[]>> classes = new List<Dictionary<string, int[]>>();
- List<string> ids = new List<string>();
- //string Type = "";
- if (dict.TryGetValue("type", out object Type))
- {
- /*paper.ForEach(p =>
- {
- p.item.ForEach(i =>
- {
- knowledge.Add(i.field);
- area.Add(i.field);
- });
- });*/
- knowledge.Add("知识");
- knowledge.Add("理解");
- knowledge.Add("应用");
- knowledge.Add("分析");
- knowledge.Add("综合");
- knowledge.Add("评鉴");
- area.Add("知识");
- area.Add("理解");
- area.Add("应用");
- area.Add("分析");
- area.Add("综合");
- area.Add("评鉴");
- }
- else
- {
- paper.ForEach(p =>
- {
- p.item.ForEach(i =>
- {
- i.points.ForEach(o =>
- {
- knowledge.Add(o);
- });
- area.Add(i.field);
- });
- });
- }
- double Qnum = 0;
- //确定高分组 低分组人数
- List<List<double>> re = exams[0].result;
- List<double> resultSum = new List<double>();
- foreach (List<double> data in re)
- {
- resultSum.Add(data.Sum());
- }
- //确定高分组 最低分数
- resultSum.Sort(delegate (double s1, double s2) { return s2.CompareTo(s1); });
- for (int i = resultSum.Count - 1; i >= 0; i--)
- {
- if (resultSum[i] == 0)
- {
- resultSum.Remove(resultSum[i]);
- }
- }
- double rhwCount = resultSum.Count * 0.27;
- double rhw = resultSum[int.Parse(rhwCount.ToString("0"))];
- //确定低分组 最高分数
- resultSum.Sort(delegate (double s1, double s2) { return s1.CompareTo(s2); });
- double rhlCount = resultSum.Count * 0.27;
- double rhl = resultSum[int.Parse(rhwCount.ToString("0"))];
- foreach (ExamResultDto ex in exams)
- {
- point = ex.point;
- result = ex.result;
- classes = ex.classes;
- ids = ex.ids;
- }
- /* exams.ForEach(e =>
- {
- point = e.Point;
- result = e.Result;
- classes = e.Classes;
- ids = e.Ids;
- });*/
- List<string> knowledgeName = new List<string>();
- foreach (string cla in knowledge)
- {
- knowledgeName.Add(cla);
- }
- for (int k = 0; k < knowledgeName.Count; k++)
- {
- if (null == knowledgeName[k])
- {
- knowledgeName.Remove(knowledgeName[k]);
- }
- }
- List<string> areaName = new List<string>();
- foreach (string cla in area)
- {
- areaName.Add(cla);
- }
- for (int k = 0; k < areaName.Count; k++)
- {
- if (null == areaName[k])
- {
- areaName.Remove(areaName[k]);
- }
- }
- //初始化年级总分
- double total = 0;
- //处理年级单个知识点得分率
- foreach (List<double> grade in result)
- {
- total += grade.Sum();
- }
- foreach (string id in ids)
- {
- if (!id.Equals("0"))
- {
- Qnum++;
- }
- }
- //试卷总分
- double TotalPoint = point.Sum();
- //计算认知层次占比
- List<string> fper = new List<string>();
- for (int a = 0; a < areaName.Count; a++)
- {
- double fieldPoint = 0;
- paper.ForEach(p =>
- {
- int n = 0;
- p.item.ForEach(i =>
- {
- if (i.field != null && i.field.Contains(areaName[a]))
- {
- fieldPoint += point[n];
- }
- n++;
- });
- });
- double fieldPersent = fieldPoint / TotalPoint;
- fper.Add(fieldPersent.ToString("0.00"));
- }
- //求单个知识点所占分数
- List<string> per = new List<string>();
- List<string> gper = new List<string>();
- List<string> knowPer = new List<string>();
- List<Dictionary<string, double>> eper = new List<Dictionary<string, double>>();
- Dictionary<string, object> knowledgeALL = new Dictionary<string, object>();
- Dictionary<string, object> knowledgeMap = new Dictionary<string, object>();
- Dictionary<string, object> classMap = new Dictionary<string, object>();
- Dictionary<string, object> wrongMap = new Dictionary<string, object>();
- HashSet<string> className = new HashSet<string>();
- List<List<string>> wrongPersent = new List<List<string>>();
- List<string> key = new List<string>
- {
- "id",
- "className",
- "seatNO",
- "point",
- "anwPoint",
- "persent"
- };
- List<string> keyWrong = new List<string>
- {
- "name",
- "point",
- "itemNO",
- "persent",
- "wrong",
- "rhw",
- "rlw"
- };
- for (int k = 0; k < knowledgeName.Count; k++)
- {
- List<string> knowledgeClass = new List<string>();
- List<List<string>> stuPersent = new List<List<string>>();
- double OnePoint = 0;
- //获取每个知识点占有多少分值
- double ePoint = 0;
- double anwGPoint = 0;
- double poG = 0;
- int m = 0;
- List<string> valuew = new List<string>();
- List<string> itemNo = new List<string>();
- keyWrong.ForEach(x =>
- {
- valuew.Add("-");
- });
- int wrongCount = 0;
- valuew[0] = knowledgeName[k];
- paper.ForEach(p =>
- {
- int n = 0;
- if (dict.TryGetValue("type", out object Type))
- {
- p.item.ForEach(i =>
- {
- if (i.field != null && i.field.Contains(knowledgeName[k]))
- {
- OnePoint += point[n];
- itemNo.Add((n + 1).ToString());
- }
- n++;
- });
- }
- else
- {
- p.item.ForEach(i =>
- {
- if (i.points != null && i.points.Contains(knowledgeName[k]))
- {
- OnePoint += 1 / Convert.ToDouble(i.points.Count) * point[n];
- itemNo.Add((n + 1).ToString());
- }
- n++;
- });
- }
- valuew[1] = OnePoint.ToString();
- string itemNos = "";
- if (itemNo.Count > 0)
- {
- foreach (string index in itemNo)
- {
- itemNos += index + ",";
- }
- valuew[2] = itemNos[0..^1];
- }
- else
- {
- valuew[2] = itemNos;
- }
- });
- int rhwC = 0;
- int rhlC = 0;
- foreach (string id in ids)
- {
- if (id.Equals("0") || result[m].Sum() == 0)
- {
- m++;
- continue;
- }
- List<string> values = new List<string>();
- key.ForEach(x =>
- {
- values.Add("-");
- });
- foreach (OldStudent info in students)
- {
- if (info.studentId.Equals(id))
- {
- values[2] = info.seatNo.ToString();
- break;
- }
- }
- //List<string> stu = new List<string>();
- values[0] = id;
- values[1] = "-";
- //List<List<string>> stuItem = new List<List<string>>();
- int statuCount = 0;
- paper.ForEach(p =>
- {
- int n = 0;
- double anwPoint = 0;
- double po = 0;
- p.item.ForEach(i =>
- {
- if (dict.TryGetValue("type", out object Type))
- {
- if (i.field != null && i.field.Contains(knowledgeName[k]))
- {
- //Dictionary<string, double> mapkeyItem = new Dictionary<string, double>();
- //OnePoint += 1 / Convert.ToDouble(i.points.Count) * point[n];
- //当前认知层次在该题占比多少
- ePoint = 1;
- anwPoint += result[m][n] * ePoint;
- //所有学生单个认知层次得分情况
- anwGPoint += result[m][n] * ePoint;
- po += point[n] * ePoint;
- //认知层次所占分数
- poG += point[n] * ePoint;
- if (result[m][n] == 0 && statuCount == 0)
- {
- statuCount++;
- wrongCount++;
- if (result[m].Sum() >= rhw)
- {
- rhwC++;
- }
- if (result[m].Sum() <= rhl)
- {
- rhlC++;
- }
- }
- }
- n++;
- }
- else
- {
- if (i.points != null && i.points.Contains(knowledgeName[k]))
- {
- //Dictionary<string, double> mapkeyItem = new Dictionary<string, double>();
- //OnePoint += 1 / Convert.ToDouble(i.points.Count) * point[n];
- //当前知识点在该题占比多少
- ePoint = 1 / Convert.ToDouble(i.points.Count);
- anwPoint += result[m][n] * ePoint;
- //所有学生单个知识点得分情况
- anwGPoint += result[m][n] * ePoint;
- po += point[n] * ePoint;
- //知识点所占分数
- poG += point[n] * ePoint;
- if (result[m][n] == 0 && statuCount == 0)
- {
- statuCount++;
- wrongCount++;
- if (result[m].Sum() >= rhw)
- {
- rhwC++;
- }
- if (result[m].Sum() <= rhl)
- {
- rhlC++;
- }
- }
- }
- n++;
- }
- });
- if (po == 0)
- {
- values[3] = "0";
- values[4] = "0";
- values[5] = "0";
- }
- else
- {
- double stuPser = anwPoint / po;
- values[3] = po.ToString();
- values[4] = anwPoint.ToString();
- values[5] = stuPser.ToString("0.00");
- }
- //stuItem.Add(values);
- });
- stuPersent.Add(values);
- m++;
- }
- AchievementService.ReName(stuPersent, ids, classes, students);
- double knowPser = 0;
- if (poG == 0)
- {
- knowPer.Add("0");
- }
- else
- {
- knowPser = anwGPoint / poG;
- knowPer.Add(knowPser.ToString("0.00"));
- }
- //错题关系表
- valuew[3] = knowPser.ToString("0.00");
- valuew[4] = wrongCount.ToString();
- valuew[5] = rhwC.ToString();
- valuew[6] = rhlC.ToString();
- wrongPersent.Add(valuew);
- knowledgeMap.Add(knowledgeName[k], stuPersent);
- //知识点占比
- double persent = OnePoint / TotalPoint;
- foreach (Dictionary<string, int[]> map in classes)
- {
- List<string> classPoints = new List<string>();
- //初始化班级得分
- double anwCPoint = 0;
- double cpo = 0;
- foreach (KeyValuePair<string, int[]> kvp in map)
- {
- className.Add(kvp.Key);
- for (int n = kvp.Value[0]; n < kvp.Value[1]; n++)
- {
- if (result[n].Sum() == 0) continue;
- paper.ForEach(p =>
- {
- int x = 0;
- p.item.ForEach(i =>
- {
- if (dict.TryGetValue("type", out object Type))
- {
- if (i.field != null && i.field.Contains(knowledgeName[k]))
- {
- //当前认知层次在该题占比多少
- ePoint = 1;
- anwCPoint += result[n][x] * ePoint;
- cpo += point[x] * ePoint;
- }
- x++;
- }
- else
- {
- if (i.points != null && i.points.Contains(knowledgeName[k]))
- {
- //当前知识点在该题占比多少
- ePoint = 1 / Convert.ToDouble(i.points.Count);
- anwCPoint += result[n][x] * ePoint;
- cpo += point[x] * ePoint;
- }
- x++;
- }
- });
- });
- }
- }
- if (cpo == 0)
- {
- //double classPser = anwCPoint / cpo;
- knowledgeClass.Add("0");
- }
- else
- {
- double classPser = anwCPoint / cpo;
- knowledgeClass.Add(classPser.ToString("0.00"));
- }
- }
- classMap.Add(knowledgeName[k], knowledgeClass);
- per.Add(persent.ToString("0.00"));
- }
- knowledgeMap.Add("grade", knowPer);
- knowledgeMap.Add("keys", key);
- classMap.Add("className", className);
- wrongMap.Add("keys", keyWrong);
- wrongMap.Add("datas", wrongPersent);
- knowledgeALL.Add("pointList", knowledgeName);
- knowledgeALL.Add("per", per);
- knowledgeALL.Add("level", areaName);
- knowledgeALL.Add("fper", fper);
- knowledgeALL.Add("stupercent", knowledgeMap);
- knowledgeALL.Add("classpercent", classMap);
- knowledgeALL.Add("wrong", wrongMap);
- //builder.Data(knowledgeALL);
- //Redis处理结果集
- if (RedisHelper.Instance != null)
- {
- if (!RedisHelper.Exists(CacheCosmosPrefix + method))
- {
- await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), knowledgeALL);
- }
- else
- {
- await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), knowledgeALL);
- await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
- }
- }
- return knowledgeALL;
- }
- [HttpPost("knowledgePoint")]
- public async Task<BaseResponse> KnowledgePoint(JsonElement request)
- {
- ResponseBuilder builder = ResponseBuilder.custom();
- Dictionary<string, object> dict = new Dictionary<string, object>();
- var emobj = request.EnumerateObject();
- while (emobj.MoveNext())
- {
- dict[emobj.Current.Name] = emobj.Current.Value;
- }
- Dictionary<string, dynamic> info = new Dictionary<string, dynamic>();
- if (RedisHelper.Instance != null)
- {
- info = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "knowledgePoint",
- ShaHashHelper.GetSHA1(dict.ToJsonString()), timeoutSeconds, () => { return FindKnowledgePointRedis(dict, "knowledgePoint"); });
- //数据从redis读取过后进行转换格式
- builder.Data(info);
- }
- else
- {
- info = await FindKnowledgePointRedis(dict, "knowledgePoint");
- builder.Data(info);
- }
- return builder.build();
- }
- [HttpPost("FindExamInfo")]
- public async Task<BaseResponse> FindExamInfo(JsonElement request)
- {
- ResponseBuilder builder = ResponseBuilder.custom();
- Dictionary<string, object> dict = new Dictionary<string, object>();
- var emobj = request.EnumerateObject();
- while (emobj.MoveNext())
- {
- dict[emobj.Current.Name] = emobj.Current.Value;
- }
- if (RedisHelper.Instance != null)
- {
- try
- {
- ///RedisHelper.Instance.CurrentSerialize = obj => System.Text.Json.JsonSerializer.Serialize(obj);
- /// RedisHelper.Instance.CurrentDeserialize = (json, type) => System.Text.Json.JsonSerializer.Deserialize(json, type);
- List<ExamInfoDto> info = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "FindExamInfo",
- ShaHashHelper.GetSHA1(dict.ToJsonString()), timeoutSeconds, () => { return FindExamInfoRedis(dict, "FindExamInfo"); });
- builder.Data(info);
- }
- catch (Exception e)
- {
- // throw new BizException(e.Message);
- }
- }
- else
- {
- List<ExamInfoDto> info = await FindExamInfoRedis(dict, "FindExamInfo");
- builder.Data(info);
- }
- return builder.build();
- }
- public async Task<List<ExamInfoDto>> FindExamInfoRedis(Dictionary<string, object> dict, string method)
- {
- return new List<ExamInfoDto>();
- //{
- // List<ExamInfoDto> info = await _azureCosmos.FindByDict<ExamInfoDto>(dict);
- // List<ExamResultDto> exams = new List<ExamResultDto>();
- // for (int i = 0; i < info.Count; i++) {
- // for (int j = 0; j < info[i].conditions.subject.Count; j++)
- // {
- // if (RedisHelper.Exists(CacheCosmosPrefix + "examResult" + info[i].conditions.subject[j]))
- // {
- // ExamResultDto result = RedisHelper.HGet<ExamResultDto>(CacheCosmosPrefix + "examResult" + info[i].conditions.subject[j], ShaHashHelper.GetSHA1(info[i].examCode.ToString()));
- // //builder.Data(info);
- // exams.Add(result);
- // }
- // }
- // //初始化总分
- // double sumPoint = 0;
- // for (int k = 0; k < exams.Count; k++) {
- // for (int n = exams[k].ids.Count - 1; n >= 0;n--)
- // {
- // if (exams[k].ids[n].Equals("0"))
- // {
- // exams[k].ids.Remove(exams[k].ids[n]);
- // }
- // }
- // //获取总分数
- // exams[k].result.ForEach(r =>
- // {
- // sumPoint += r.Sum();
- // });
- // info[i].realCount = exams[k].ids.Count;
- // }
- // info[i].piont = sumPoint / info[i].realCount;
- // //目前单次考试权重关系和权重次数
- // info[i].index = info[i].piont * 1 / 1;
- // }
- // if (RedisHelper.Instance != null)
- // {
- // if (!RedisHelper.Exists(CacheCosmosPrefix + method))
- // {
- // await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), info);
- // }
- // else
- // {
- // await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), info);
- // await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
- // }
- // }
- // return info;
- //}
- //catch (Exception e)
- //{
- // throw new BizException(e.Message);
- //}
- }
- [HttpPost("FindExamPaper")]
- public BaseResponse FindExamPaper(JsonElement request)
- {
- //Dictionary<string, object> dict = new Dictionary<string, object>();
- /* var emobj = request.EnumerateObject();
- while (emobj.MoveNext())
- {
- dict[emobj.Current.Name] = emobj.Current.Value;
- }*/
- request.TryGetProperty("subjectCode", out JsonElement subjectCode);
- request.TryGetProperty("code", out JsonElement code);
- /*dict.TryGetValue("subjectCode", out object subjectCode);
- dict.TryGetValue("code", out object code);*/
- ResponseBuilder builder = ResponseBuilder.custom();
- /*if (RedisHelper.Instance != null)
- {
- List<Paper> info = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + request.method,
- ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(request.@params)), timeoutSeconds, () => { return FindExamPaperRedis(request.@params, request.method); });
- builder.Data(info);
- }
- else
- {
- List<Paper> info = await FindExamPaperRedis(request.@params, request.method);
- builder.Data(info);
- }*/
- List<PaperDto> paper = new List<PaperDto>();
- if (RedisHelper.Exists(CacheCosmosPrefix + "paperInfo" + subjectCode.ToString()))
- {
- PaperDto paper1 = RedisHelper.HGet<PaperDto>(CacheCosmosPrefix + "paperInfo" + subjectCode.ToString(), ShaHashHelper.GetSHA1(code.ToString()));
- paper.Add(paper1);
- builder.Data(paper);
- }
- return builder.build();
- }
- /* public async Task<List<Paper>> FindExamPaperRedis(Dictionary<string, object> dict, string method)
- {
- try
- {
- List<Paper> info = await _azureCosmos.FindByDict<Paper>(dict);
- if (RedisHelper.Instance != null)
- {
- if (!RedisHelper.Exists(CacheCosmosPrefix + method))
- {
- await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), info);
- }
- else
- {
- await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), info);
- await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
- }
- }
- return info;
- }
- catch (Exception e)
- {
- throw new BizException(e.Message);
- }
- }*/
- [HttpPost("FindExamAnswer")]
- public BaseResponse FindExamAnswer(JsonElement request)
- {
- request.TryGetProperty("subjectCode", out JsonElement subjectCode);
- request.TryGetProperty("code", out JsonElement code);
- ResponseBuilder builder = ResponseBuilder.custom();
- List<ExamAnswer> exams = new List<ExamAnswer>();
- if (RedisHelper.Exists(CacheCosmosPrefix + "examAnswer" + subjectCode.ToString()))
- {
- ExamAnswer exam = RedisHelper.HGet<ExamAnswer>(CacheCosmosPrefix + "examAnswer" + subjectCode.ToString(), ShaHashHelper.GetSHA1(code.ToString()));
- exams.Add(exam);
- builder.Data(exams);
- }
- return builder.build();
- }
- public async Task<List<ExamAnswer>> FindExamAnswerRedis(Dictionary<string, object> dict, string method)
- {
- return new List<ExamAnswer>();
- //try
- //{
- // List<ExamAnswer> info = await _azureCosmos.FindByDict<ExamAnswer>(dict);
- // if (RedisHelper.Instance != null)
- // {
- // if (!RedisHelper.Exists(CacheCosmosPrefix + method))
- // {
- // await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), info);
- // }
- // else
- // {
- // await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), info);
- // await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
- // }
- // }
- // return info;
- //}
- //catch (Exception e)
- //{
- // throw new BizException(e.Message);
- //}
- }
- public async Task<List<ExamAnswer>> FindExamAnswerRedis(Dictionary<string, object> dict)
- {
- return new List<ExamAnswer>();
- //try
- //{
- // List<ExamAnswer> info = await _azureCosmos.FindByDict<ExamAnswer>(dict);
- // if (RedisHelper.Instance != null)
- // {
- // if (!RedisHelper.Exists(CacheCosmosPrefix + "FindExamAnswer"))
- // {
- // await RedisHelper.HSetAsync(CacheCosmosPrefix + "FindExamAnswer", ShaHashHelper.GetSHA1(dict.ToJsonString()), info);
- // }
- // else
- // {
- // await RedisHelper.HSetAsync(CacheCosmosPrefix + "FindExamAnswer", ShaHashHelper.GetSHA1(dict.ToJsonString()), info);
- // await RedisHelper.ExpireAsync(CacheCosmosPrefix + "FindExamAnswer", timeoutSeconds);
- // }
- // }
- // return info;
- //}
- //catch (Exception e)
- //{
- // throw new BizException(e.Message);
- //}
- }
- [HttpPost("HomeStatistics")]
- public async Task<BaseResponse> HomeStatistics(JsonElement request)
- {
- ResponseBuilder builder = ResponseBuilder.custom();
- Dictionary<string, object> dict = new Dictionary<string, object>();
- var emobj = request.EnumerateObject();
- while (emobj.MoveNext())
- {
- dict[emobj.Current.Name] = emobj.Current.Value;
- }
- List<Dictionary<string, dynamic>> info = new List<Dictionary<string, dynamic>>();
- if (RedisHelper.Instance != null)
- {
- info = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "HomeStatistics",
- ShaHashHelper.GetSHA1(dict.ToJsonString()), timeoutSeconds, () => { return FindHomeStatisticsRedis(dict, "HomeStatistics"); });
- //数据从redis读取过后进行转换格式
- builder.Data(info);
- }
- else
- {
- info = await FindHomeStatisticsRedis(dict, "HomeStatistics");
- builder.Data(info);
- }
- return builder.build();
- }
- public async Task<List<Dictionary<string, dynamic>>> FindHomeStatisticsRedis(Dictionary<string, object> dict, string method)
- {
- return new List<Dictionary<string, dynamic>>();
- //request.@params.TryGetValue("subjectCode", out object subjectCode);
- // dict.TryGetValue("schoolCode", out object schoolCode);
- // dict.TryGetValue("code", out object code);
- // Dictionary<string, object> eMap = new Dictionary<string, object>
- // {
- // { "code", code.ToString()}
- // };
- // Dictionary<string, object> SCMap = new Dictionary<string, object>
- // {
- // { "id", schoolCode.ToString()},
- // };
- // //说明 同学校、同类型考试数据
- // //List<ExamInfo> exams = await azureCosmosDBRepository.FindByDict<ExamInfo>(eMap);
- // List<ExamInfoDto> exams = new List<ExamInfoDto>();
- // if (RedisHelper.Instance != null)
- // {
- // exams = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "FindExamInfo",
- // ShaHashHelper.GetSHA1(eMap.ToJsonString()), timeoutSeconds, () => { return FindExamInfoRedis(eMap, "FindExamInfo"); });
- // }
- // else
- // {
- // exams = await FindExamInfoRedis(eMap, "FindExamInfo");
- // }
- // List<ExamInfoDto> newInfo = new List<ExamInfoDto>();
- // //获取各个学段最新的考试信息
- // foreach (IGrouping<string, ExamInfoDto> group in exams.GroupBy(c => c.conditions.grade))
- // {
- // ExamInfoDto examInfo = group.ToList().OrderByDescending(e => e.createTime).ToList().FirstOrDefault();
- // newInfo.Add(examInfo);
- // };
- // //newInfo.Select(e => e.type.Equals("union"));
- // //List<ExamInfo> unionInfo = newInfo.Where(e => e.type.Equals("union")).ToList();
- // //exams.GroupBy(e => e.conditions.period);
- // //ExamInfo info = exams.OrderByDescending(e => e.createTime).ToList().FirstOrDefault();
- // //查询学校对应的年级信息
- // List<School> schools = await _azureCosmos.FindByDict<School>(SCMap);
- // //List<School> schools = new List<School>();
- ///* if (RedisHelper.Exists(CacheCosmosPrefix + "schoolInfo"))
- // {
- // School sc = RedisHelper.HGet<School>(CacheCosmosPrefix + "schoolInfo",
- // ShaHashHelper.GetSHA1(schoolCode.ToString()));
- // schools.Add(sc);
- // }*/
- // string Period = "";
- // string Grade = "";
- // //List<double> CoreAverage = new List<double>();
- // try
- // {
- // List<Period> periods = new List<Period>();
- // List<Grade> grades = new List<Grade>();
- // foreach (School s in schools)
- // {
- // periods = s.period;
- // }
- // periods.ForEach(p =>
- // {
- // p.grades.ForEach(g => {
- // grades.Add(g);
- // });
- // /*if (p.periodCode.Equals("初中"))
- // {
- // grades = p.grades;
- // }
- // else if (p.periodCode.Equals("高中"))
- // {
- // grades = p.grades;
- // }
- // else
- // {
- // grades = p.grades;
- // }*/
- // });
- // List<Dictionary<string, object>> map = new List<Dictionary<string, object>>();
- // //循环处理不同年级考试信息
- // foreach (Grade g in grades)
- // {
- // double weightSum = 0;
- // List<double> CoreAverage = new List<double>();
- // List<List<List<string>>> AllPoint = new List<List<List<string>>>();
- // List<List<List<string>>> AllPointAverage = new List<List<List<string>>>();
- // List<List<List<string>>> AllKeyLine = new List<List<List<string>>>();
- // HashSet<string> classList = new HashSet<string>();
- // HashSet<string> subjectList = new HashSet<string>();
- // for (int i = 0; i < newInfo.Count; i++)
- // {
- // if (g.id.Equals(newInfo[i].conditions.grade))
- // {
- // List<ExamResultDto> simples = new List<ExamResultDto>();
- // for (int j = 0; j < newInfo[i].conditions.subject.Count; j++)
- // {
- // ExamResultDto result = new ExamResultDto();
- // if (RedisHelper.Exists(CacheCosmosPrefix + "examResult" + newInfo[i].conditions.subject[j]))
- // {
- // result = RedisHelper.HGet<ExamResultDto>(CacheCosmosPrefix + "examResult" + newInfo[i].conditions.subject[j],
- // ShaHashHelper.GetSHA1(newInfo[i].examCode));
- // simples.Add(result);
- // }
- // }
- // //List<ExamResult> examResults = new List<ExamResult>();
- // /*Dictionary<string, object> sub = new Dictionary<string, object>
- // {
- // { "code", newInfo[i].id}
- // };*/
- // Period = newInfo[i].conditions.period;
- // Grade = newInfo[i].conditions.grade;
- // List<string> subjects = new List<string>();
- // List<List<string>> SubjectClassAverage = new List<List<string>>();
- // List<List<string>> SubjectAverage = new List<List<string>>();
- // //List<List<string>> SubjectClassAverage = new List<List<string>>();
- // //List<ExamResult> simples = await azureCosmosDBRepository.FindByDict<ExamResult>(sub);
- // // 学生总分
- // double coreSum = 0;
- // int stuCount = newInfo[i].stuCount;
- // //int stuCount = 0;
- // //初始化进行人数
- // double iPersons = 0;
- // //
- // List<List<double>> subSum = new List<List<double>>();
- // if (simples.IsEmpty()) continue;
- // double weight = 0.5;
- // weightSum += weight;
- // int classLen = simples[0].classes.Count;
- // for (int cls = 0; cls < classLen; cls++)
- // {
- // if (simples[0].classes[cls].TryGetValue(simples[0].classes[cls].Keys.ToArray<string>()[0], out int[] indexs))
- // {
- // List<double> stuScore = new List<double>();
- // int stdLen = indexs[1] - indexs[0] + 1;
- // for (int n = 0; n < stdLen; n++)
- // {
- // stuScore.Add(0);
- // }
- // subSum.Add(stuScore);
- // }
- // }
- // simples.ForEach(s =>
- // {
- // subjectList.Add(s.subjectCode);
- // //计算试卷总分
- // double sum = s.point.Sum();
- // //int stuSum = 0;
- // int classIndex = 0;
- // List<string> ClassAverage = new List<string>();
- // List<string> Average = new List<string>();
- // List<string> passList = new List<string>();
- // s.classes.ForEach(c =>
- // {
- // List<List<string>> classPRL = new List<List<string>>();
- // //初始化班级总分
- // double classPoint = 0;
- // //初始化班级缺考人数
- // int classCount = 0;
- // //初始化班级平均得分率
- // double points = 0;
- // //初始化班级平均得分率
- // double AveragePoints = 0;
- // //初始化各班参考人数
- // int counts = 0;
- // //c.Keys遍历key值
- // foreach (string key in c.Keys)
- // {
- // classList.Add(key);
- // }
- // //每个班级平均分
- // foreach (int[] value in c.Values)
- // {
- // for (int i = value[0]; i <= value[1]; i++)
- // {
- // //初始化学生单科个人得分
- // double stuPoints = s.result[i].Sum();
- // subSum[classIndex][i - value[0]] = stuPoints + subSum[classIndex][i - value[0]];
- // classPoint += s.result[i].Sum();
- // coreSum += s.result[i].Sum();
- // if (s.result[i].Sum() == 0)
- // {
- // classCount++;
- // }
- // }
- // //每个班级实际参考人数
- // counts = value[1] - value[0] + 1;
- // //stuSum += counts;
- // //stuCount += counts;
- // points = Convert.ToDouble(classPoint) / counts / sum;
- // //计算每个班级平均得分
- // AveragePoints = Convert.ToDouble(classPoint) / counts;
- // ClassAverage.Add(points.ToString("0.000"));
- // Average.Add(AveragePoints.ToString());
- // }
- // classIndex += 1;
- // });
- // SubjectClassAverage.Add(ClassAverage);
- // SubjectAverage.Add(Average);
- // //subAverage = subjectPoint / ClassAverage.Count();
- // //subjectAverage.Add(subAverage.ToString("0.00"));
- // });
- // //获取进线人数
- // iPersons = stuCount / classList.Count * 0.4;
- // //权重配分 学生总平均分 * 权重配分
- // double core = coreSum / stuCount * weight;
- // CoreAverage.Add(core);
- // AllPoint.Add(SubjectClassAverage);
- // AllPointAverage.Add(SubjectAverage);
- // //处理人数为整
- // string ip = iPersons.ToString("0");
- // //初始化进线分数
- // int ipoint = 0;
- // List<int> AllPoints = new List<int>();
- // foreach (List<double> points in subSum)
- // {
- // foreach (int po in points)
- // {
- // AllPoints.Add(po);
- // }
- // }
- // for (int sn = 0; sn < subSum.Count; sn++)
- // {
- // for (int j = 0; j < subSum[sn].Count; j++)
- // {
- // if (subSum[sn][j].Equals("0"))
- // {
- // subSum[sn].Remove(subSum[sn][j]);
- // }
- // }
- // }
- // //计算成绩年级排名
- // AllPoints.Sort(delegate (int s1, int s2) { return s2.CompareTo(s1); });
- // ipoint = AllPoints[int.Parse(ip)];
- // int m = 0;
- // List<List<string>> KeyLine = new List<List<string>>();
- // foreach (List<double> points in subSum)
- // {
- // List<string> detail = new List<string>();
- // double sum = points.Count;
- // int l = 0;
- // for (int mq = 0; mq < points.Count; mq++)
- // {
- // if (points[mq] >= ipoint)
- // {
- // l++;
- // }
- // }
- // double Lines = l;
- // detail.Add(Lines.ToString());
- // detail.Add(points.Count.ToString());
- // var t3 = Math.Floor(Math.Round(decimal.Parse((Lines / sum).ToString("0.000")), 2) * 100);
- // detail.Add(t3.ToString());
- // KeyLine.Add(detail);
- // m++;
- // }
- // AllKeyLine.Add(KeyLine);
- // }
- // else {
- // continue;
- // }
- // //年级成就指标
- // if (weightSum == 0)
- // {
- // weightSum = 1;
- // }
- // double index = CoreAverage.Sum() / weightSum;
- // List<List<double>> AveragePoint = new List<List<double>>();
- // List<List<double>> AverageClassPoint = new List<List<double>>();
- // //List<double> ClassCore = new List<double>();
- // int k = AllPoint.Count;
- // if (k > 0)
- // {
- // for (int m = 0; m < AllPoint[0].Count; m++)
- // {
- // List<double> SubjectAverage = new List<double>();
- // for (int n = 0; n < AllPoint[0][m].Count; n++)
- // {
- // double startPoint = 0;
- // for (int f = 0; f < k; f++)
- // {
- // startPoint = double.Parse(AllPoint[f][m][n]) + startPoint;
- // }
- // SubjectAverage.Add(startPoint / k);
- // }
- // AveragePoint.Add(SubjectAverage);
- // }
- // }
- // //每个班级成就指标
- // int p = AllPointAverage.Count;
- // if (p > 0)
- // {
- // for (int m = 0; m < AllPointAverage[0].Count; m++)
- // {
- // List<double> SubjectAverage = new List<double>();
- // for (int n = 0; n < AllPointAverage[0][m].Count; n++)
- // {
- // double startPoint = 0;
- // for (int f = 0; f < k; f++)
- // {
- // startPoint = double.Parse(AllPointAverage[f][m][n]) + startPoint;
- // }
- // SubjectAverage.Add(startPoint / k);
- // }
- // AverageClassPoint.Add(SubjectAverage);
- // }
- // }
- // int c = AverageClassPoint.Count;
- // List<double> ClassCore = new List<double>();
- // if (c > 0)
- // {
- // for (int j = 0; j < AverageClassPoint[0].Count; j++)
- // {
- // double startAverage = 0;
- // for (int f = 0; f < c; f++)
- // {
- // startAverage = AverageClassPoint[f][j] + startAverage;
- // }
- // ClassCore.Add(startAverage / c / weightSum);
- // }
- // }
- // //班级平均进线率
- // int ExamCount = AllKeyLine.Count;
- // List<List<double>> KeyLines = new List<List<double>>();
- // if (ExamCount > 0)
- // {
- // for (int m = 0; m < AllKeyLine[0].Count; m++)
- // {
- // List<double> ClassLine = new List<double>();
- // for (int n = 0; n < AllKeyLine[0][m].Count; n++)
- // {
- // double startPoint = 0;
- // for (int f = 0; f < ExamCount; f++)
- // {
- // startPoint = double.Parse(AllKeyLine[f][m][n]) + startPoint;
- // }
- // ClassLine.Add(startPoint / ExamCount);
- // }
- // KeyLines.Add(ClassLine);
- // }
- // }
- // Dictionary<string, object> AveragePointMap = new Dictionary<string, object>
- // {
- // { "Period",Period},
- // { "Grade",Grade},
- // { "index", index},
- // { "className", classList },
- // { "subjectName", subjectList },
- // { "AveragePoint", AveragePoint },
- // //{ "AverageClassPoint", AverageClassPoint },
- // { "ClassCore", ClassCore },
- // { "KeyLines",KeyLines}
- // };
- // map.Add(AveragePointMap);
- // }
- // }
- // //Redis处理结果集
- // if (RedisHelper.Instance != null)
- // {
- // if (!RedisHelper.Exists(CacheCosmosPrefix + method))
- // {
- // await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), map);
- // }
- // else
- // {
- // await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), map);
- // await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
- // }
- // }
- // return map;
- // }
- // catch (Exception e)
- // {
- // throw new BizException(e.Message);
- // }
- }
- [HttpPost("getAnalysis")]
- public async Task<IActionResult> getAnalysis(JsonElement request)
- {
- //获取评测的ID
- if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
- if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
- try
- {
- var client = _azureCosmos.GetCosmosClient();
- //获取本次评测所有科目结算结果
- ExamInfo info = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"Exam-{code}"));
- School school = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<School>(code.ToString(), new PartitionKey($"Base"));
- List<ExamResult> examResults = new List<ExamResult>();
- var query = $"select c.id,c.name,c.subjectId,c.studentScores,c.studentIds,c.paper,c.classes from c where c.examId = '{id}' ";
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<ExamResult>(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamResult-{id}") }))
- {
- /*using var json = await JsonDocument.ParseAsync(item.ContentStream);
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
- {
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
- {
- examResults.Add(obj.ToObject<ExamResult>());
- }
- }*/
- examResults.Add(item);
- }
- //获取本次评测所有班级作答结果
- List<ExamClassResult> examClassResults = new List<ExamClassResult>();
- 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 ";
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<ExamClassResult>(queryText: queryClass, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{code}") }))
- {
- examClassResults.Add(item);
- /*using var json = await JsonDocument.ParseAsync(item.ContentStream);
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
- {
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
- {
- examClassResults.Add(obj.ToObject<ExamClassResult>());
- }
- }*/
- }
- //获取进线标准
- int touch = 0;
- foreach (Period period in school.period)
- {
- if (info.period.id.Equals(period.id))
- {
- touch = period.analysis.touch;
- }
- }
- //获取进线人数
- int personCount = (int)System.Math.Round(info.stuCount * (touch / 100.0), MidpointRounding.AwayFromZero);
- StudentAnalysis analysis = new StudentAnalysis();
- List<ClassAnalysis> classAnalyses = new List<ClassAnalysis>();
- /* //声明年级所有科目总分
- List<double> total = new List<double>();*/
- //以班级为单位
- List<double> stuTotals = new List<double>();
- List<dynamic> classes = new List<dynamic>();
- HashSet<string> idName = new HashSet<string>();
- foreach (ExamResult examResult in examResults)
- {
- foreach (string ids in examResult.studentIds)
- {
- idName.Add(ids);
- }
- }
- foreach (string s in info.targetClassIds)
- {
- //存放每个班级学生总分
- List<double> totalClass = new List<double>();
- ClassAnalysis classAnalysis = new ClassAnalysis();
- classAnalysis.classId = s;
- var sresponse = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(s, new PartitionKey($"Class-{code}"));
- if (sresponse.Status == 200)
- {
- using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
- Class classroom = json.ToObject<Class>();
- classes.Add(new { name = classroom.name, id = s });
- //初始化参考人数
- int count = 0;
- foreach (StudentSimple stu in classroom.students)
- {
- if (idName.Contains(stu.id))
- {
- count++;
- }
- else
- {
- continue;
- }
- classAnalysis.studentIds.Add(stu.id);
- analysis.names.Add(stu.name);
- analysis.ids.Add(stu.id);
- //计算学生多科考试成绩总分
- double stuTotal = 0;
- foreach (ExamResult examResult in examResults)
- {
- int index = examResult.studentIds.IndexOf(stu.id);
- if (index >= 0)
- {
- stuTotal = stuTotal + examResult.studentScores[index].Sum();
- }
- }
- classAnalysis.total.Add(stuTotal);
- analysis.total.Add(stuTotal);
- stuTotals.Add(stuTotal);
- totalClass.Add(stuTotal);
- //total.Add(stuTotal);
- }
- classAnalysis.stuCount = count;
- }
- /* //声明单个班级单科总分
- double subjectTotal = 0;*/
- info.subjects.ForEach(sub =>
- {
- //初始化及格人数
- int i = 0;
- //初始化单科总分
- double sumClass = 0;
- //记录每个科目数据
- SubjectScore subjectScore = new SubjectScore();
- subjectScore.id = sub.id;
- double subjectSum = 0;
- double passScore = 0;
- //计算单科评测总分
- foreach (ExamResult examResult in examResults)
- {
- if (sub.id.Equals(examResult.subjectId))
- {
- subjectSum = examResult.paper.point.Sum();
- }
- }
- //单科及格率分数
- passScore = subjectSum * 0.6;
- //存放学生单科记录
- Score score = new Score();
- score.subjectId = sub.id;
- List<double> subjectTotal = new List<double>();
- //处理每个班级各个学生各科总分
- foreach (ExamClassResult result in examClassResults)
- {
- if (sub.id.Equals(result.subjectId) && s.Equals(result.info.id))
- {
- foreach (List<double> scores in result.studentScores)
- {
- //添加每个学生各科总分
- score.csc.Add(scores.Sum());
- //计算大于及格分数的人数
- if (scores.Sum() >= passScore)
- {
- i++;
- }
- //totalClass.Add(scores.Sum());
- subjectTotal.Add(scores.Sum());
- sumClass = sumClass + scores.Sum();
- }
- //处理班级及格率以及均分
- double percentClass = i / (result.studentIds.Count * 1.0);
- double averageClass = sumClass / (result.studentIds.Count * 1.0);
- //total += averageClass;
- subjectScore.passPercent = percentClass;
- subjectScore.averageScore = averageClass;
- classAnalysis.subjects.Add(subjectScore);
- //analysis.scores.Add(score);
- }
- }
- //处理单科科班级PR
- subjectTotal.Sort(delegate (double s1, double s2) { return s2.CompareTo(s1); });
- foreach (double sc in score.csc)
- {
- int index = subjectTotal.IndexOf(sc);
- double CPR = 100 - (100 * (index + 1) - 50) / score.csc.Count;
- score.cdpr.Add(CPR);
- }
- analysis.scores.Add(score);
- });
- //处理全科班级PR
- totalClass.Sort(delegate (double s1, double s2) { return s2.CompareTo(s1); });
- foreach (double pr in classAnalysis.total)
- {
- int index = totalClass.IndexOf(pr);
- double CPR = 100 - (100 * (index + 1) - 50) / classAnalysis.total.Count;
- analysis.cpr.Add(CPR);
- }
- classAnalyses.Add(classAnalysis);
- }
- /*info.targetClassIds.ForEach( async s => {
-
- });*/
- //初始化进线分数
- double ipoint = 0;
- stuTotals.Sort(delegate (double s1, double s2) { return s2.CompareTo(s1); });
- ipoint = stuTotals[personCount];
- //补充班级总平均分/进行人数/标准差
- foreach (ClassAnalysis classAnalysis in classAnalyses)
- {
- //初始化进线人数
- int i = 0;
- //初始化班级总分
- double score = 0;
- //标准差
- double powSum = 0;
- foreach (double sc in classAnalysis.total)
- {
- if (sc > ipoint)
- {
- i++;
- }
- score = score + sc;
- }
- //总平均分
- double totalAverage = 0;
- totalAverage = score / classAnalysis.stuCount;
- //计算标准差
- foreach (double sc in classAnalysis.total)
- {
- powSum += Math.Pow(sc - totalAverage, 2);
- }
- var pow = Math.Pow(powSum / classAnalysis.stuCount, 0.5);
- classAnalysis.standardDeviation = pow;
- classAnalysis.totalAverage = totalAverage;
- classAnalysis.lineCount = i;
- }
- //处理全科年级PR值
- foreach (double no in analysis.total)
- {
- int index = stuTotals.IndexOf(no);
- int GPR = 100 - (100 * (index + 1) - 50) / analysis.total.Count;
- analysis.gpr.Add(GPR);
- }
- List<GradeAnalysis> gradeAnalyses = new List<GradeAnalysis>();
- List<Dictionary<string, dynamic>> PointAnalysis = new List<Dictionary<string, dynamic>>();
- List<Dictionary<string, dynamic>> exerciseScatter = new List<Dictionary<string, dynamic>>();
- List<Dictionary<string, dynamic>> KnowledgePoint = new List<Dictionary<string, dynamic>>();
- if (info.grades.Count > 0)
- {
- gradeAnalyses = GetGradeAnalyses(info, examResults, examClassResults, analysis);
- PointAnalysis = getPointAnalysis(examResults, info);
- exerciseScatter = getExerciseScatter(examResults, info);
- KnowledgePoint = getKnowledgePoint(examResults, info);
- }
- return Ok(new { analysis, classAnalyses, gradeAnalyses, PointAnalysis, exerciseScatter, KnowledgePoint });
- }
- catch (Exception e)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/getAnalysis()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
- return BadRequest();
- }
- }
- private List<GradeAnalysis> GetGradeAnalyses(ExamInfo info, List<ExamResult> examResults, List<ExamClassResult> examClassResults, StudentAnalysis analysis)
- {
- List<GradeAnalysis> gradeAnalyses = new List<GradeAnalysis>();
- info.grades.ForEach(g =>
- {
- GradeAnalysis gradeAnalysis = new GradeAnalysis();
- gradeAnalysis.gradeId = g.id;
- //初始化单个年级总分
- double gradeScore = 0;
- info.subjects.ForEach(sub =>
- {
- //初始化及格人数
- int i = 0;
- //初始化年级人数
- int count = 0;
- //初始化单科总分
- double sumClass = 0;
- //记录每个科目数据
- GradeSubjectScore subjectScore = new GradeSubjectScore();
- subjectScore.id = sub.id;
- double subjectSum = 0;
- double passScore = 0;
- //计算单科评测总分
- foreach (ExamResult examResult in examResults)
- {
- if (sub.id.Equals(examResult.subjectId))
- {
- subjectSum = examResult.paper.point.Sum();
- }
- }
- //单科及格率分数
- passScore = subjectSum * 0.6;
- List<double> subjectTotal = new List<double>();
- //存放单科每个班级学生总分
- List<double> totalClass = new List<double>();
- //存放学生单科记录
- foreach (Score score in analysis.scores)
- {
- if (score.subjectId.Equals(sub.id))
- {
- //处理每个班级各个学生各科总分
- foreach (ExamClassResult result in examClassResults)
- {
- if (sub.id.Equals(result.subjectId) && g.id.Equals(result.gradeId))
- {
- foreach (List<double> scores in result.studentScores)
- {
- //添加每个学生各科总分
- score.gsc.Add(scores.Sum());
- //计算大于及格分数的人数
- if (scores.Sum() >= passScore)
- {
- i++;
- }
- subjectTotal.Add(scores.Sum());
- sumClass = sumClass + scores.Sum();
- }
- count += result.studentIds.Count;
- }
- }
- //处理班级及格率以及均分
- double persentClass = i / (count * 1.0);
- double averageClass = sumClass / (count * 1.0);
- gradeScore += averageClass;
- subjectScore.passPercent = persentClass;
- subjectScore.averageScore = averageClass;
- gradeAnalysis.subjects.Add(subjectScore);
- gradeAnalyses.Add(gradeAnalysis);
- //处理单科科年级PR
- subjectTotal.Sort(delegate (double s1, double s2) { return s2.CompareTo(s1); });
- foreach (double sc in score.gsc)
- {
- int index = subjectTotal.IndexOf(sc);
- double GPR = 100 - (100 * (index + 1) - 50) / score.gsc.Count;
- score.gdpr.Add(GPR);
- //analysis.gpr.Add(GPR);
- }
- //analysis.scores.Add(score);
- }
- }
- });
- foreach (GradeAnalysis grade in gradeAnalyses)
- {
- grade.GradeaverageScore = gradeScore / grade.subjects.Count;
- }
- });
- return gradeAnalyses;
- }
- //落点分析
- private List<Dictionary<string, dynamic>> getPointAnalysis(List<ExamResult> exams, ExamInfo exam)
- {
- List<Dictionary<string, dynamic>> scatterAnalysis = new List<Dictionary<string, dynamic>>();
- List<string> key = new List<string>
- {
- "name",
- "className",
- "x",
- "y",
- "memberId",
- "score",
- "trueNum",
- "falseNum",
- "hardList",
- "carefulList",
- "scatter"
- };
- //key.Add("areaName");
- if (exams.Count > 0)
- {
- /* //提取班级信息
- List<Dictionary<string, int[]>> classToName = exams[0].classes;
- //提取学生ID信息
- List<string> idToName = exams[0].ids;*/
- exams.ForEach(e =>
- {
- Dictionary<string, object> detail = new Dictionary<string, object>
- {
- { "keys", key }
- };
- List<List<string>> datas = new List<List<string>>();
- Dictionary<string, object> subject = new Dictionary<string, object>
- {
- { "name", e.subjectId }
- };
- double[] point = StringHelper.ListTodouble(e.paper.point);
- double[,] result = StringHelper.ListToDouble(e.studentScores);
- try
- {
- var cdm = new ClouDASMatrix(result, point);
- //学生通过率
- List<double> pass = cdm.PassingRate;
- //学生稳定度
- List<double> sta = cdm.StabilityRate;
- //落点区域
- List<string> stu = cdm.StuFallArea;
- //需努力的题型
- List<int[]> strive = cdm.StriveTopic;
- //需小心的题型
- List<int[]> careful = cdm.CarefulTopic;
- int i = 0;
- for (int k = e.studentIds.Count - 1; k >= 0; k--)
- {
- if (e.studentIds[k].Equals("0"))
- {
- e.studentIds.Remove(e.studentIds[k]);
- }
- }
- e.studentIds.ForEach(s =>
- {
- if (e.studentScores[i].Sum() != 0)
- {
- List<string> info = new List<string>
- {
- s,
- "-",
- sta[i].ToString(),
- pass[i].ToString(),
- i + 1 + "",
- e.studentScores[i].Sum().ToString()
- };
- int right = 0;
- int wrong = 0;
- foreach (int p in e.studentScores[i])
- {
- if (p > 0)
- {
- right++;
- }
- else
- {
- wrong++;
- }
- }
- info.Add(right + "");
- info.Add(wrong + "");
- int[] str = strive[i];
- string striveAll = "";
- foreach (int n in str)
- {
- striveAll += n.ToString() + ",";
- }
- int[] care = careful[i];
- string careAll = "";
- foreach (int n in care)
- {
- careAll += n.ToString() + ",";
- }
- if (string.IsNullOrEmpty(striveAll))
- {
- info.Add("无");
- }
- else
- {
- info.Add(striveAll.Substring(0, striveAll.Length - 1));
- }
- if (string.IsNullOrEmpty(careAll))
- {
- info.Add("无");
- }
- else
- {
- info.Add(careAll.Substring(0, careAll.Length - 1)); ;
- }
- info.Add(stu[i].ToString());
- datas.Add(info);
- }
- i++;
- });
- //AchievementService.ReName(datas, idToName, classToName, students);
- detail.Add("datas", datas);
- subject.Add("scatter", detail);
- scatterAnalysis.Add(subject);
- }
- catch (Exception ex)
- {
- //builder.Data(exams);
- //ex.Message;
- Console.WriteLine("---------------------" + ex.Message + "--------------------------");
- }
- });
- return scatterAnalysis;
- }
- else return scatterAnalysis;
- }
- private List<Dictionary<string, dynamic>> getExerciseScatter(List<ExamResult> exams, ExamInfo exam)
- {
- /* ResponseBuilder builder = ResponseBuilder.custom();*/
- List<string> classList = new List<string>();
- List<Dictionary<string, object>> exerciseScatter = new List<Dictionary<string, object>>();
- //Dictionary<string, object> scatterAnalysis = new Dictionary<string, object>();
- classList = exam.targetClassIds;
- List<string> key = new List<string>
- {
- "id",
- "type",
- "areaName",
- "score",
- "diff",
- "identify",
- "classScoreRate",
- "gradeScoreRate",
- "areaScoreRate",
- "highScoreRate",
- "lowScoreRate",
- "knowledgePoint",
- "R1",
- "R2",
- "R3",
- "R4",
- "R5",
- "R6",
- "PH",
- "PL",
- "X",
- "Y",
- "knowledge"
- };
- if (exams.IsNotEmpty())
- {
- exams.ForEach(e =>
- {
- List<double> gradeAnswer = new List<double>();
- List<string> grasdepersent = new List<string>();
- for (int n = 0; n < e.paper.point.Count; n++)
- {
- gradeAnswer.Add(0);
- }
- //参考人数
- double Qnum = 0;
- e.studentIds.ForEach(i =>
- {
- if (!i.Equals("0"))
- {
- Qnum++;
- }
- });
- /* Dictionary<string, object> detail = new Dictionary<string, object>
- {
- { "keys", key }
- };*/
- List<List<string>> datas = new List<List<string>>();
- List<string[]> itemAnalysis = new List<string[]>();
- Dictionary<string, object> subject = new Dictionary<string, object>
- {
- { "name", e.subjectId }
- };
- Dictionary<string, object> classPersent = new Dictionary<string, object>();
- List<List<string>> classdatas = new List<List<string>>();
- try
- {
- e.classes.ForEach(c =>
- {
- //初始化每题得分情况
- List<int> answerCount = new List<int>();
- List<string> persent = new List<string>();
- double peopleCount = 0;
- for (int n = 0; n < e.paper.point.Count; n++)
- {
- answerCount.Add(0);
- }
- int qCount = 0;
- //int right = 0;
- /* //c.Keys遍历key值
- foreach (string keys in c.Keys)
- {
- classList.Add(keys);
- }*/
- //每个班级得分占比
- for (int i = c.range[0]; i <= c.range[1]; i++)
- {
- if (e.studentScores[i].Sum() > 0)
- {
- for (int j = 0; j < e.studentScores[i].Count; j++)
- {
- if (e.studentScores[i][j] > 0)
- {
- //记录班级每题得分数
- answerCount[j] = answerCount[j] + 1;
- //记录年级每题得分数
- gradeAnswer[j] = gradeAnswer[j] + 1;
- //right++;
- }
- }
- }
- else
- {
- qCount++;
- }
- peopleCount = c.range[1] - c.range[0] + 1 - qCount;
- }
- foreach (int p in answerCount)
- {
- var t = Math.Floor(Math.Round(decimal.Parse((p * 1.0 / peopleCount).ToString("0.000")), 2) * 100);
- persent.Add(t.ToString());
- }
- classdatas.Add(persent);
- });
- classPersent.Add("classList", classList);
- classPersent.Add("datas", classdatas);
- exerciseScatter.Add(classPersent);
- double[] point = StringHelper.ListTodouble(e.paper.point);
- double[,] result = StringHelper.ListToDouble(e.studentScores);
- var cdm = new ClouDASMatrix(result, point);
- //试题Y
- List<double> answer = cdm.AnswerRate;
- //试题X
- List<double> quality = cdm.QualityRate;
- //试题区域
- List<string> topic = cdm.TopicFallArea;
- //试题相关分析结果
- List<(double Diff, double Identify, double R1, double R2, double R3, double R4, double R5, double R6, double RH, double RL)> rs = cdm.RS;
- for (int i = 0; i < rs.Count; i++)
- {
- string[] ex = new string[] { };
- string ss = rs[i].ToString()[1..^1];
- ex = ss.Split(",");
- itemAnalysis.Add(ex);
- }
- foreach (int p in gradeAnswer)
- {
- var t = Math.Floor(Math.Round(decimal.Parse((p / Qnum).ToString("0.000")), 2) * 100);
- grasdepersent.Add(t.ToString());
- }
- for (int k = 0; k < e.paper.point.Count; k++)
- {
- List<string> values = new List<string>();
- key.ForEach(x =>
- {
- values.Add("-");
- });
- values[0] = (k + 1).ToString();
- values[1] = "";
- values[2] = topic[k].ToString();
- values[3] = e.paper.point[k].ToString();
- if (itemAnalysis.Count > 0)
- {
- values[4] = itemAnalysis[k][0];
- values[5] = itemAnalysis[k][1];
- values[12] = itemAnalysis[k][2];
- values[13] = itemAnalysis[k][3];
- values[14] = itemAnalysis[k][4];
- values[15] = itemAnalysis[k][5];
- values[16] = itemAnalysis[k][6];
- values[17] = itemAnalysis[k][7];
- values[18] = itemAnalysis[k][8];
- values[19] = itemAnalysis[k][9];
- }
- else
- {
- values[4] = "-";
- values[5] = "-";
- values[12] = "-";
- values[13] = "-";
- values[14] = "-";
- values[15] = "-";
- values[16] = "-";
- values[17] = "-";
- values[18] = "-";
- values[19] = "-";
- }
- values[7] = grasdepersent[k];
- values[8] = grasdepersent[k];
- values[20] = quality[k].ToString();
- values[21] = answer[k].ToString();
- string pointName = "";
- /*if (paper[0].item[k].points.Count == 1)
- {
- foreach (string index in paper[0].item[k].points)
- {
- pointName = index;
- }
- }
- else if (paper[0].item[k].points.Count > 1)
- {
- foreach (string index in paper[0].item[k].points)
- {
- pointName += index + ",";
- }
- }*/
- values[22] = pointName;
- datas.Add(values);
- }
- subject.Add("keys", key);
- subject.Add("datas", datas);
- exerciseScatter.Add(subject);
- }
- catch (Exception ex)
- {
- // throw new BizException(ex.Message);
- }
- });
- return exerciseScatter;
- }
- else return exerciseScatter;
- }
- [HttpPost("answer")]
- public async Task<IActionResult> answer(JsonElement request)
- {
- //获取评测的ID
- if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
- if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
- try
- {
- var client = _azureCosmos.GetCosmosClient();
- //获取本次评测所有科目结算结果
- ExamInfo info = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"Exam-{code}"));
- School school = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<School>(code.ToString(), new PartitionKey($"Base"));
- List<ExamResult> examResults = new List<ExamResult>();
- var query = $"select c.id,c.name,c.subjectId,c.studentScores,c.studentIds,c.paper,c.classes from c where c.examId = '{id}' ";
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<ExamResult>(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamResult-{id}") }))
- {
- /*using var json = await JsonDocument.ParseAsync(item.ContentStream);
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
- {
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
- {
- examResults.Add(obj.ToObject<ExamResult>());
- }
- }*/
- examResults.Add(item);
- }
- //获取本次评测所有班级作答结果
- List<ExamClassResult> examClassResults = new List<ExamClassResult>();
- 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}' ";
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<ExamClassResult>(queryText: queryClass, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{code}") }))
- {
- examClassResults.Add(item);
- /*using var json = await JsonDocument.ParseAsync(item.ContentStream);
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
- {
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
- {
- examClassResults.Add(obj.ToObject<ExamClassResult>());
- }
- }*/
- }
- int m = 0;
- foreach (ExamSubject subject in info.subjects) {
- foreach (ExamClassResult classResult in examClassResults)
- {
- if (subject.id.Equals(classResult.subjectId)) {
- int k = 0;
- foreach (string stu in classResult.studentIds)
- {
- if (classResult.studentAnswers[k].Count > 0) {
- k++;
- continue;
- }
- int n = 0;
- List<List<string>> ans = new List<List<string>>();
- foreach (List<string> simple in info.papers[m].answers) {
- List<string> option = new List<string>();
- if (simple.Count > 0)
- {
- List<string> opt = new List<string>{ "A", "B", "C", "D" };
- int rd=new Random().Next(0,3);
- if (rd == 1 || rd == 2)
- {
- option.AddRange(simple);
- classResult.studentScores[k][n] = info.papers[m].point[n];
- }
- else {
- simple.ForEach(x => { opt.Remove(x); });
- option.Add(opt[new Random().Next(0, opt.Count-1)]);
- classResult.studentScores[k][n] = 0;
- }
- ans.Add(option);
- }
- else {
- //classResult.studentScores[k][n] = new Random().Next(0, (int)info.papers[m].point[n]) * 1.0;
- ans.Add(new List<string> { "测试作答数据一","测试作答数据二"});
- }
- n++;
- }
- string FileName = classResult.examId + "/" + classResult.subjectId + "/" + stu;
- string blob = await _azureStorage.UploadFileByContainer(code.ToString(), ans.ToJsonString(), "exam", FileName + "/" + "ans.json");
- classResult.studentAnswers[k].Add(blob);
- classResult.sum[k] = classResult.studentScores[k].Sum();
- k++;
- }
- //await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(classResult, classResult.id, new PartitionKey($"ExamClassResult-{code}"));
- if (!classResult.progress) {
- bool flag = true;
- foreach (List<double> scores in classResult.studentScores)
- {
- foreach (double score in scores)
- {
- if (score == -1)
- {
- flag = false;
- break;
- }
- }
- }
- if (flag)
- {
- classResult.progress = true;
- info.subjects[m].classCount += 1;
- }
- }
- await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(classResult, classResult.id, new PartitionKey($"ExamClassResult-{code}"));
- }
-
- }
- m++;
- }
- await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(info, id.ToString(), new PartitionKey($"Exam-{code}"));
- return Ok(new { examClassResults });
- }
- catch (Exception e)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/answer()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
- return BadRequest();
- }
- }
- [HttpPost("scoring")]
- public async Task<IActionResult> Scoring(JsonElement request)
- {
- //获取评测的ID
- if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
- if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
- try
- {
- var client = _azureCosmos.GetCosmosClient();
- //获取本次评测所有科目结算结果
- ExamInfo info = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"Exam-{code}"));
- School school = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<School>(code.ToString(), new PartitionKey($"Base"));
- List<ExamResult> examResults = new List<ExamResult>();
- var query = $"select c.id,c.name,c.subjectId,c.studentScores,c.studentIds,c.paper,c.classes from c where c.examId = '{id}' ";
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<ExamResult>(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamResult-{id}") }))
- {
- examResults.Add(item);
- }
- //获取本次评测所有班级作答结果
- List<ExamClassResult> examClassResults = new List<ExamClassResult>();
- 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}' ";
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<ExamClassResult>(queryText: queryClass, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{code}") }))
- {
- examClassResults.Add(item);
- }
- int m = 0;
- foreach (ExamSubject subject in info.subjects)
- {
- foreach (ExamClassResult classResult in examClassResults)
- {
- if (subject.id.Equals(classResult.subjectId))
- {
- int k = 0;
- foreach (string stu in classResult.studentIds)
- {
- int n = 0;
- List<List<string>> ans = new List<List<string>>();
- foreach (List<string> simple in info.papers[m].answers)
- {
- List<string> option = new List<string>();
- if (simple.Count == 0)
- {
- classResult.studentScores[k][n] = new Random().Next(0, (int)info.papers[m].point[n]) * 1.0;
- }
- n++;
- }
- classResult.sum[k] = classResult.studentScores[k].Sum();
- k++;
- }
- if (!classResult.progress)
- {
- bool flag = true;
- foreach (List<double> scores in classResult.studentScores)
- {
- foreach (double score in scores)
- {
- if (score == -1)
- {
- flag = false;
- break;
- }
- }
- }
- if (flag)
- {
- classResult.progress = true;
- info.subjects[m].classCount += 1;
- }
- }
- else {
- info.updateTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
- }
- await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(classResult, classResult.id, new PartitionKey($"ExamClassResult-{code}"));
- }
- }
- m++;
- }
- await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(info, id.ToString(), new PartitionKey($"Exam-{code}"));
- return Ok(new { examClassResults });
- }
- catch (Exception e)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/scoring()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
- return BadRequest();
- }
- }
- [HttpPost("import")]
- public async Task<IActionResult> importIES3(JsonElement request)
- {
- //获取评测的ID
- if (!request.TryGetProperty("exam", out JsonElement exam)) return BadRequest();
- //if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
- try
- {
- var client = _azureCosmos.GetCosmosClient();
- ExamDto examDtos = new ExamDto();
- examDtos = exam.ToObject<ExamDto>();
- ExamInfo info = new ExamInfo();
- info.code = info.pk + "-hbcn";
- info.progress = "pending";
- info.id = examDtos.id;
- info.name = examDtos.name;
- info.grades = examDtos.grades;
- info.subjects = examDtos.subjects;
- info.period = examDtos.period;
- examDtos.targetClasses.ForEach(e => {
- info.targetClassIds.Add(e.id);
- });
- examDtos.papers.ForEach(p => {
- PaperSimple simple = new PaperSimple();
- simple.id = p.id;
- simple.name = p.name;
- p.points.ForEach(po => {
- simple.point.Add(double.Parse(po));
- });
- p.answers.ForEach(an =>
- {
- List<string> ans = new List<string>();
- if (an.Length > 1)
- {
- char[] aa = an.ToCharArray();
- foreach (char a in aa) {
- switch (a)
- {
- case '1':
- ans.Add("A");
- break;
- case '2':
- ans.Add("B");
- break;
- case '3':
- ans.Add("C");
- break;
- case '4':
- ans.Add("D");
- break;
- default:
- ans.Add("");
- break;
- }
- }
- }
- else {
- switch (an) {
- case "1":
- ans.Add("A");
- break;
- case "2":
- ans.Add("B");
- break;
- case "3":
- ans.Add("C");
- break;
- case "4":
- ans.Add("D");
- break;
- default:
- ans.Add("");
- break;
- }
- }
- simple.answers.Add(ans);
- });
- info.papers.Add(simple);
- });
- await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(info, new PartitionKey("Exam-hbcn"));
- return Ok(new { info });
- }
- catch (Exception e)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/scoring()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
- return BadRequest();
- }
- }
- [HttpPost("importResult")]
- public async Task<IActionResult> importClassResult(JsonElement request)
- {
- //获取评测的ID
- if (!request.TryGetProperty("classResult", out JsonElement classResult)) return BadRequest();
- if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
- try
- {
- var client = _azureCosmos.GetCosmosClient();
- List<ExamClassResultDto> examClassResultDto = new List<ExamClassResultDto>();
- examClassResultDto = classResult.ToObject<List<ExamClassResultDto>>();
- //获取本次评测所有班级作答结果
- List<ExamClassResult> examClassResults = new List<ExamClassResult>();
- var queryClass = $"select value(c) from c where c.examId = '{id}'";
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<ExamClassResult>(queryText: queryClass, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("ExamClassResult-hbcn") }))
- {
- examClassResults.Add(item);
- }
- foreach (ExamClassResultDto e in examClassResultDto) {
- foreach (ExamClassResult ex in examClassResults)
- {
- if (e.subject.Equals(ex.subjectId))
- {
- foreach (ClassResults examClass in e.examClassResult)
- {
- if (examClass.classInfo.id.Equals(ex.info.id))
- {
- ex.studentIds = examClass.studentIds;
- List<List<double>> newScores = new List<List<double>>();
- examClass.studentScores.ForEach(sc =>
- {
- List<double> scores = new List<double>();
- if (sc.Count == 0)
- {
- for (int i =0;i< ex.studentScores[0].Count;i++) {
- scores.Add(0);
- }
- }
- else
- {
- sc.ForEach(s =>
- {
- scores.Add(double.Parse(s));
- });
- }
- newScores.Add(scores);
- });
- ex.studentScores = newScores;
- int index = 0;
- List<Task<string>> tasks = new List<Task<string>>();
- foreach (List<string> an in examClass.studentAnswers)
- {
- List<string> ans = new List<string>();
- an.ForEach(aa =>
- {
- if (aa.Length > 1)
- {
- char[] str = aa.ToCharArray();
- foreach (char a in aa)
- {
- switch (a)
- {
- case '1':
- ans.Add("A");
- break;
- case '2':
- ans.Add("B");
- break;
- case '3':
- ans.Add("C");
- break;
- case '4':
- ans.Add("D");
- break;
- default:
- ans.Add("");
- break;
- }
- }
- }
- else
- {
- switch (aa)
- {
- case "1":
- ans.Add("A");
- break;
- case "2":
- ans.Add("B");
- break;
- case "3":
- ans.Add("C");
- break;
- case "4":
- ans.Add("D");
- break;
- default:
- ans.Add("");
- break;
- }
- }
- });
- string FileName = ex.examId + "/" + ex.subjectId + "/" + examClass.studentIds[index];
- string blob = FileName + "/" + "ans.json";
- tasks.Add(_azureStorage.UploadFileByContainer(ex.school.ToString(), ans.ToJsonString(), "exam", FileName + "/" + "ans.json"));
- ex.studentAnswers[index].Add(blob);
- index++;
- }
- await Task.WhenAll(tasks);
- }
- }
- }
- }
- }
- foreach (ExamClassResult result in examClassResults) {
- await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(result, result.id, new PartitionKey($"{result.code}"));
- }
- return Ok(new { examClassResults });
- }
- catch (Exception e)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/importResult()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
- return BadRequest();
- }
- }
- private List<Dictionary<string, dynamic>> getKnowledgePoint(List<ExamResult> examResults, ExamInfo info)
- {
- Dictionary<string, object> stuMap = new Dictionary<string, object>
- {
- { "schoolCode", "Habook" }
- };
- List<Dictionary<string, object>> keyValues = new List<Dictionary<string, object>>();
- HashSet<string> knowledge = new HashSet<string>();
- HashSet<string> area = new HashSet<string>();
- List<double> point = new List<double>();
- List<List<double>> result = new List<List<double>>();
- List<ClassRange> classes = new List<ClassRange>();
- List<string> ids = new List<string>();
- examResults.ForEach(e =>
- {
- //定位试卷信息
- int index = 0;
- foreach (ExamSubject subject in info.subjects)
- {
- if (subject.id.Equals(e.subjectId))
- {
- break;
- }
- else
- {
- index++;
- }
- }
- info.papers[index].knowledge.ForEach(k =>
- {
- k.ForEach(e =>
- {
- knowledge.Add(e);
- });
- });
- info.papers[index].field.ForEach(f =>
- {
- area.Add(f.ToString());
- });
- double Qnum = 0;
- point = info.papers[index].point;
- result = e.studentScores;
- classes = e.classes;
- ids = e.studentIds;
- //确定高分组 低分组人数
- List<List<double>> re = e.studentScores;
- List<double> resultSum = new List<double>();
- foreach (List<double> data in re)
- {
- resultSum.Add(data.Sum());
- }
- //确定高分组 最低分数
- resultSum.Sort(delegate (double s1, double s2) { return s2.CompareTo(s1); });
- for (int i = resultSum.Count - 1; i >= 0; i--)
- {
- if (resultSum[i] == 0)
- {
- resultSum.Remove(resultSum[i]);
- }
- }
- double rhwCount = resultSum.Count * 0.27;
- double rhw = resultSum[int.Parse(rhwCount.ToString("0"))];
- //确定低分组 最高分数
- resultSum.Sort(delegate (double s1, double s2) { return s1.CompareTo(s2); });
- double rhlCount = resultSum.Count * 0.27;
- double rhl = resultSum[int.Parse(rhwCount.ToString("0"))];
- List<string> knowledgeName = new List<string>();
- foreach (string cla in knowledge)
- {
- knowledgeName.Add(cla);
- }
- for (int k = 0; k < knowledgeName.Count; k++)
- {
- if (null == knowledgeName[k])
- {
- knowledgeName.Remove(knowledgeName[k]);
- }
- }
- List<string> areaName = new List<string>();
- foreach (string cla in area)
- {
- areaName.Add(cla);
- }
- for (int k = 0; k < areaName.Count; k++)
- {
- if (null == areaName[k])
- {
- areaName.Remove(areaName[k]);
- }
- }
- //初始化年级总分
- double total = 0;
- //处理年级单个知识点得分率
- foreach (List<double> grade in result)
- {
- total += grade.Sum();
- }
- foreach (string id in ids)
- {
- if (!id.Equals("0"))
- {
- Qnum++;
- }
- }
- //试卷总分
- double TotalPoint = point.Sum();
- //计算认知层次占比
- List<string> fper = new List<string>();
- for (int a = 0; a < areaName.Count; a++)
- {
- double fieldPoint = 0;
- int no = 0;
- info.papers[index].field.ForEach(f =>
- {
- if (f.ToString().Equals(areaName[a], StringComparison.OrdinalIgnoreCase))
- {
- e.studentScores.ForEach(s =>
- {
- fieldPoint += s[no];
- });
- }
- no++;
- });
- double fieldPersent = fieldPoint / TotalPoint;
- fper.Add(fieldPersent.ToString("0.00"));
- }
- //求单个知识点所占分数
- List<string> per = new List<string>();
- List<string> gper = new List<string>();
- List<string> knowPer = new List<string>();
- List<Dictionary<string, double>> eper = new List<Dictionary<string, double>>();
- Dictionary<string, object> knowledgeALL = new Dictionary<string, object>();
- Dictionary<string, object> knowledgeMap = new Dictionary<string, object>();
- Dictionary<string, object> classMap = new Dictionary<string, object>();
- Dictionary<string, object> wrongMap = new Dictionary<string, object>();
- HashSet<string> className = new HashSet<string>();
- List<List<string>> wrongPersent = new List<List<string>>();
- List<string> key = new List<string>
- {
- "id",
- "className",
- "seatNO",
- "point",
- "anwPoint",
- "persent"
- };
- List<string> keyWrong = new List<string>
- {
- "name",
- "point",
- "itemNO",
- "persent",
- "wrong",
- "rhw",
- "rlw"
- };
- for (int k = 0; k < knowledgeName.Count; k++)
- {
- List<string> knowledgeClass = new List<string>();
- List<List<string>> stuPersent = new List<List<string>>();
- double OnePoint = 0;
- //获取每个知识点占有多少分值
- double ePoint = 0;
- double anwGPoint = 0;
- double poG = 0;
- int m = 0;
- List<string> valuew = new List<string>();
- List<string> itemNo = new List<string>();
- keyWrong.ForEach(x =>
- {
- valuew.Add("-");
- });
- int wrongCount = 0;
- valuew[0] = knowledgeName[k];
- int n = 0;
- info.papers[index].knowledge.ForEach(kno =>
- {
- if (kno.Contains(knowledgeName[k]))
- {
- OnePoint += point[n];
- itemNo.Add((n + 1).ToString());
- }
- valuew[1] = OnePoint.ToString();
- string itemNos = "";
- if (itemNo.Count > 0)
- {
- foreach (string np in itemNo)
- {
- itemNos += np + ",";
- }
- valuew[2] = itemNos[0..^1];
- }
- else
- {
- valuew[2] = itemNos;
- }
- n++;
- });
- int rhwC = 0;
- int rhlC = 0;
- foreach (string id in ids)
- {
- if (id.Equals("0") || result[m].Sum() == 0)
- {
- m++;
- continue;
- }
- List<string> values = new List<string>();
- key.ForEach(x =>
- {
- values.Add("-");
- });
- /* foreach (OldStudent info in students)
- {
- if (info.studentId.Equals(id))
- {
- values[2] = info.seatNo.ToString();
- break;
- }
- }*/
- //List<string> stu = new List<string>();
- values[0] = id;
- values[1] = "-";
- //List<List<string>> stuItem = new List<List<string>>();
- int statuCount = 0;
- info.papers[index].knowledge.ForEach(kno => {
- int sno = 0;
- double anwPoint = 0;
- double po = 0;
- if (kno.Contains(knowledgeName[k])) {
- //当前认知层次在该题占比多少
- ePoint = 1;
- anwPoint += result[m][sno] * ePoint;
- //所有学生单个认知层次得分情况
- anwGPoint += result[m][sno] * ePoint;
- po += point[sno] * ePoint;
- //认知层次所占分数
- poG += point[sno] * ePoint;
- if (result[m][sno] == 0 && statuCount == 0)
- {
- statuCount++;
- wrongCount++;
- if (result[m].Sum() >= rhw)
- {
- rhwC++;
- }
- if (result[m].Sum() <= rhl)
- {
- rhlC++;
- }
- }
- if (po == 0)
- {
- values[3] = "0";
- values[4] = "0";
- values[5] = "0";
- }
- else
- {
- double stuPser = anwPoint / po;
- values[3] = po.ToString();
- values[4] = anwPoint.ToString();
- values[5] = stuPser.ToString("0.00");
- }
- }
- });
- stuPersent.Add(values);
- m++;
- }
- //AchievementService.ReName(stuPersent, ids, classes, students);
- double knowPser = 0;
- if (poG == 0)
- {
- knowPer.Add("0");
- }
- else
- {
- knowPser = anwGPoint / poG;
- knowPer.Add(knowPser.ToString("0.00"));
- }
- //错题关系表
- valuew[3] = knowPser.ToString("0.00");
- valuew[4] = wrongCount.ToString();
- valuew[5] = rhwC.ToString();
- valuew[6] = rhlC.ToString();
- wrongPersent.Add(valuew);
- knowledgeMap.Add(knowledgeName[k], stuPersent);
- //知识点占比
- double persent = OnePoint / TotalPoint;
- foreach (ClassRange classRange in e.classes) {
- List<string> classPoints = new List<string>();
- //初始化班级得分
- double anwCPoint = 0;
- double cpo = 0;
- for (int stuIndex = classRange.range[0]; stuIndex < classRange.range[1]; stuIndex++)
- {
- if (result[stuIndex].Sum() == 0) continue;
- info.papers[index].knowledge.ForEach(kno => {
- int x = 0;
- if (kno.Contains(knowledgeName[k])) {
- //当前认知层次在该题占比多少
- ePoint = 1;
- anwCPoint += result[stuIndex][x] * ePoint;
- cpo += point[x] * ePoint;
- }
- });
- }
- if (cpo == 0)
- {
- //double classPser = anwCPoint / cpo;
- knowledgeClass.Add("0");
- }
- else
- {
- double classPser = anwCPoint / cpo;
- knowledgeClass.Add(classPser.ToString("0.00"));
- }
- }
- classMap.Add(knowledgeName[k], knowledgeClass);
- per.Add(persent.ToString("0.00"));
- }
- knowledgeMap.Add("grade", knowPer);
- knowledgeMap.Add("keys", key);
- classMap.Add("className", className);
- wrongMap.Add("keys", keyWrong);
- wrongMap.Add("datas", wrongPersent);
- knowledgeALL.Add("pointList", knowledgeName);
- knowledgeALL.Add("per", per);
- knowledgeALL.Add("level", areaName);
- knowledgeALL.Add("fper", fper);
- knowledgeALL.Add("stupercent", knowledgeMap);
- knowledgeALL.Add("classpercent", classMap);
- knowledgeALL.Add("wrong", wrongMap);
- keyValues.Add(knowledgeALL);
- });
- return keyValues;
- }
- }
- }
|