AchievementController.cs 244 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892
  1. using ClouDASLibx;
  2. using Microsoft.AspNetCore.Mvc;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text.Json;
  7. using System.Threading.Tasks;
  8. using TEAMModelOS.SDK.Models;
  9. using TEAMModelOS.SDK;
  10. using TEAMModelOS.SDK.DI;
  11. using TEAMModelOS.SDK.Extension;
  12. using Microsoft.Extensions.Options;
  13. using TEAMModelOS.Models;
  14. using Microsoft.Azure.Cosmos;
  15. using TEAMModelOS.Models.Dto;
  16. using System.Text;
  17. using Microsoft.AspNetCore.Http;
  18. using HTEXLib.Translator;
  19. namespace TEAMModelOS.Controllers.Analysis
  20. {
  21. [Route("analysis")]
  22. [ApiController]
  23. public class AchievementController : ControllerBase
  24. {
  25. private readonly AzureCosmosFactory _azureCosmos;
  26. private readonly DingDing _dingDing;
  27. private readonly Option _option;
  28. private const string CacheCosmosPrefix = "Analysis:";
  29. private const int timeoutSeconds = 3600;
  30. public readonly AzureStorageFactory _azureStorage;
  31. public DOXC2HTMLTranslator _DOXC2HTMLTranslator { get; set; }
  32. //public PPTX2HTEXTranslator _PPTX2HTEXTranslator { get; set; }
  33. public HTML2ITEMV3Translator _HTML2ITEMV3Translator { get; set; }
  34. public AchievementController(DOXC2HTMLTranslator DOXC2HTMLTranslator, HTML2ITEMV3Translator HTML2ITEMV3Translator,AzureCosmosFactory azureCosmos, DingDing dingDing, IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage)
  35. {
  36. _azureCosmos = azureCosmos;
  37. _dingDing = dingDing;
  38. _option = option?.Value;
  39. _azureStorage = azureStorage;
  40. _DOXC2HTMLTranslator = DOXC2HTMLTranslator;
  41. _HTML2ITEMV3Translator = HTML2ITEMV3Translator;
  42. }
  43. // [HttpPost("Achievement")]
  44. // public async Task<BaseResponse> FindExam(JsonElement request)
  45. // {
  46. // ResponseBuilder builder = ResponseBuilder.custom();
  47. // Dictionary<string, object> dict = new Dictionary<string, object>();
  48. // var emobj = request.EnumerateObject();
  49. // while (emobj.MoveNext())
  50. // {
  51. // dict[emobj.Current.Name] = emobj.Current.Value;
  52. // }
  53. // Dictionary<string, dynamic> info = new Dictionary<string, dynamic>();
  54. // if (RedisHelper.Instance != null)
  55. // {
  56. // info = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "Achievement",
  57. // ShaHashHelper.GetSHA1(dict.ToJsonString()), timeoutSeconds, () => { return FindExamRedis(dict, "Achievement"); });
  58. // //数据从redis读取过后进行转换格式
  59. // builder.Data(info);
  60. // }
  61. // else
  62. // {
  63. // info = await FindExamRedis(dict, "Achievement");
  64. // builder.Data(info);
  65. // }
  66. // return builder.build();
  67. // }
  68. // public async Task<List<ExamResult>> FindExamResultRedis(Dictionary<string, object> dict, string method)
  69. // {
  70. // return new List<ExamResult>();
  71. // //try
  72. // //{
  73. // // List<ExamResult> info = await _azureCosmos.FindByDict<ExamResult>(dict);
  74. // // if (RedisHelper.Instance != null)
  75. // // {
  76. // // if (!RedisHelper.Exists(CacheCosmosPrefix + method))
  77. // // {
  78. // // await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), info);
  79. // // }
  80. // // else
  81. // // {
  82. // // await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), info);
  83. // // await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
  84. // // }
  85. // // }
  86. // // return info;
  87. // //}
  88. // //catch (Exception e)
  89. // //{
  90. // // throw new BizException(e.Message);
  91. // //}
  92. // }
  93. // public async Task<Dictionary<string, dynamic>> FindExamRedis(Dictionary<string, object> dict, string method)
  94. // {
  95. // ResponseBuilder builder = ResponseBuilder.custom();
  96. // //Console.WriteLine(DateTimeOffset.Now.Second);
  97. // //
  98. // dict.TryGetValue("subjectCode", out object subjectCode);
  99. // dict.TryGetValue("code", out object code);
  100. // dict.TryGetValue("schoolCode", out object schoolCode);
  101. // List<ExamResultDto> exams = new List<ExamResultDto>();
  102. // /*if (RedisHelper.Instance != null)
  103. // {
  104. // exams = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "FindExamResultRedis",
  105. // ShaHashHelper.GetSHA1(dict.ToJsonString()), timeoutSeconds, () => { return FindExamResultRedis(dict, "FindExamResultRedis"); });
  106. // }
  107. // else
  108. // {
  109. // exams = await FindExamResultRedis(dict, "FindExamResultRedis");
  110. // }*/
  111. // List<string> subjectCouns = JsonExtensions.ToObject<List<string>>(subjectCode.ToJsonString());
  112. // for (int i = 0; i < subjectCouns.Count; i++)
  113. // {
  114. // if (RedisHelper.Exists(CacheCosmosPrefix + "examResult" + subjectCouns[i]))
  115. // {
  116. // ExamResultDto result = RedisHelper.HGet<ExamResultDto>(CacheCosmosPrefix + "examResult" + subjectCouns[i], ShaHashHelper.GetSHA1(code.ToString()));
  117. // //builder.Data(info);
  118. // exams.Add(result);
  119. // }
  120. // }
  121. // }
  122. // Dictionary<string, object> stuMap = new Dictionary<string, object>
  123. // {
  124. // { "schoolCode", "Habook" }
  125. // };
  126. // //声明进行标准用来设置进线标准,权重等参数
  127. // dict.TryGetValue("Standard", out object Standard);
  128. // //List<Student> students = await _azureCosmos.FindByDict<Student>(stuMap);
  129. // List<OldStudent> students = null;
  130. // if (RedisHelper.Exists(CacheCosmosPrefix + "students"))
  131. // {
  132. // students = RedisHelper.HGet<List<OldStudent>>(CacheCosmosPrefix + "students", ShaHashHelper.GetSHA1(schoolCode.ToString()));
  133. // //builder.Data(info);
  134. // //students.Add(student);
  135. // }
  136. // //Console.WriteLine(DateTimeOffset.Now.Second);
  137. // List<Dictionary<string, object>> examList = new List<Dictionary<string, object>>();
  138. // HashSet<string> classList = new HashSet<string>();
  139. // HashSet<string> classId = new HashSet<string>();
  140. // List<string> subjectAverage = new List<string>();
  141. // List<List<string>> subjectPoints = new List<List<string>>();
  142. // Dictionary<string, object> Average = new Dictionary<string, object>();
  143. // Dictionary<string, object> entryTable = new Dictionary<string, object>();
  144. // Dictionary<string, dynamic> achievementAnalysis = new Dictionary<string, dynamic>();
  145. // List<string> arrSubject = new List<string>();
  146. // List<string> keys = new List<string>();
  147. // List<string> person = new List<string>();
  148. // List<List<double>> subSum = new List<List<double>>();
  149. // List<string> gAverage = new List<string>();
  150. // List<string> cAverage = new List<string>();
  151. // Dictionary<string, object> AclassAverage = new Dictionary<string, object>();
  152. // Dictionary<string, object> passRateMap = new Dictionary<string, object>();
  153. // List<List<string>> passALL = new List<List<string>>();
  154. // List<string> gradeList = new List<string>();
  155. // List<string> areaList = new List<string>();
  156. // List<string> sbujectsList = new List<string>();
  157. // if (exams.IsNotEmpty())
  158. // {
  159. // //存放进线情况统计key值
  160. // keys.Add("name");
  161. // keys.Add("className");
  162. // keys.Add("gradeRank");
  163. // keys.Add("score");
  164. // //初始化进行人数
  165. // double iPersons = 0;
  166. // if (exams.IsNotEmpty())
  167. // {
  168. // int classLen = exams[0].classes.Count;
  169. // for (int cls = 0; cls<classLen; cls++)
  170. // {
  171. // if (exams[0].classes[cls].TryGetValue(exams[0].classes[cls].Keys.ToArray<string>()[0], out int[] index))
  172. // {
  173. // List<double> stuScore = new List<double>();
  174. // int stdLen = index[1] - index[0] + 1;
  175. // for (int i = 0; i<stdLen; i++)
  176. // {
  177. // stuScore.Add(0);
  178. // }
  179. //subSum.Add(stuScore);
  180. // }
  181. // }
  182. // }
  183. // int xx = 0;
  184. ////初始化总分
  185. //double sumPoint = 0;
  186. //int sumperson = exams[0].ids.Count;
  187. //for (int i = 0; i < exams[0].ids.Count; i++)
  188. //{
  189. // if (exams[0].ids[i].Equals("0"))
  190. // {
  191. // sumperson--;
  192. // }
  193. //}
  194. //exams.ForEach(e =>
  195. //{
  196. // //获取总分数
  197. // e.result.ForEach(r =>
  198. // {
  199. // sumPoint += r.Sum();
  200. // });
  201. //});
  202. //var gradeAverage = sumPoint / sumperson;
  203. ////存放年级平均
  204. //gAverage.Add(gradeAverage.ToString());
  205. ////任意一次考试数据提取班级信息
  206. //List<Dictionary<string, int[]>> classToName = exams[0].classes;
  207. ////任意一次考试数据提取学生ID信息
  208. //List<string> idToName = exams[0].ids;
  209. ////var gradeAverage = Math.Floor(Math.Round(decimal.Parse((10 / 3).ToString("0.000")), 2));
  210. //List<string> subjects = new List<string>();
  211. //exams.ForEach(e =>
  212. //{
  213. // int peopleCount = 0;
  214. // Dictionary<string, object> detail = new Dictionary<string, object>
  215. // {
  216. // { "name", e.subjectCode }
  217. // };
  218. // subjects.Add(e.subjectCode);
  219. // List<string> ClassAverage = new List<string>();
  220. // //计算试卷总分
  221. // double sum = e.point.Sum();
  222. // //及格分数
  223. // double passRate = sum * 0.6;
  224. // int gradeCount = 0;
  225. // //初始化科目总分
  226. // double subjectPoint = 0;
  227. // //科目平均分
  228. // double subAverage = 0;
  229. // //计算班级平均分
  230. // int classIndex = 0;
  231. // List<string> passList = new List<string>();
  232. // e.classes.ForEach(c =>
  233. // {
  234. // List<List<string>> classPRL = new List<List<string>>();
  235. // //初始化班级总分
  236. // double classPoint = 0;
  237. // //初始化班级缺考人数
  238. // int classCount = 0;
  239. // //初始化班级平均分
  240. // double points = 0;
  241. // double passPoint = 0;
  242. // //初始化及格人数
  243. // int passCount = 0;
  244. // //初始化各班参考人数
  245. // int counts = 0;
  246. // //c.Keys遍历key值
  247. // foreach (string key in c.Keys)
  248. // {
  249. // classList.Add(key);
  250. // }
  251. // //每个班级平均分
  252. // foreach (int[] value in c.Values)
  253. // {
  254. // for (int i = value[0]; i <= value[1]; i++)
  255. // {
  256. // //初始化学生单科个人得分
  257. // double stuPoints = e.result[i].Sum();
  258. // //Console.WriteLine("xx: "+xx+" classIndex:" + classIndex + ",i:" + i + " value[0]:" + value[0]+ " value[0]:" + value[1]);
  259. // subSum[classIndex][i - value[0]] = stuPoints + subSum[classIndex][i - value[0]];
  260. // if (stuPoints > passRate)
  261. // {
  262. // passCount++;
  263. // gradeCount++;
  264. // }
  265. // classPoint += e.result[i].Sum();
  266. // if (e.result[i].Sum() == 0)
  267. // {
  268. // classCount++;
  269. // }
  270. // }
  271. // //每个班级实际参考人数
  272. // counts = value[1] - value[0] - classCount + 1;
  273. // points = Convert.ToDouble(classPoint) / counts;
  274. // ClassAverage.Add(points.ToString("0.00"));
  275. // person.Add(counts + "");
  276. // }
  277. // passPoint = Convert.ToDouble(passCount) / counts;
  278. // passList.Add(passPoint.ToString("0.00"));
  279. // //classPRM.Add(classPRL);
  280. // classIndex += 1;
  281. // });
  282. // //科目平均分
  283. // ClassAverage.ForEach(a =>
  284. // {
  285. // subjectPoint += Convert.ToDouble(a);
  286. // });
  287. // subAverage = subjectPoint / ClassAverage.Count();
  288. // subjectAverage.Add(subAverage.ToString("0.00"));
  289. // detail.Add("schoolAverage", subAverage.ToString("0.00"));
  290. // detail.Add("areaAverage", subAverage.ToString("0.00"));
  291. // detail.Add("score", ClassAverage);
  292. // examList.Add(detail);
  293. // //获取实际参考总人数
  294. // e.ids.ForEach(i =>
  295. // {
  296. // if (!i.Equals("0"))
  297. // {
  298. // peopleCount++;
  299. // }
  300. // });
  301. // //班级及格率
  302. // passALL.Add(passList);
  303. // //年级及格率
  304. // double gradePass = Convert.ToDouble(gradeCount) / peopleCount;
  305. // gradeList.Add(gradePass.ToString("0.00"));
  306. // //passALL.Add(gradeList);
  307. // //区级及格率
  308. // //passALL.Add(areaList);
  309. // //获取进线人数
  310. // iPersons = peopleCount * 0.4;
  311. // //计算每个学生单科成绩
  312. // for (int i = 0; i < e.ids.Count(); i++)
  313. // {
  314. // List<string> info = new List<string>();
  315. // //info = new List<string>();
  316. // info.Add(e.ids[i]);
  317. // info.Add(e.subjectCode);
  318. // info.Add(e.result[i].Sum() + "");
  319. // //classId.Add(e.Ids[i]);
  320. // subjectPoints.Add(info);
  321. // }
  322. // keys.Add(e.subjectCode);
  323. // xx += 1;
  324. // //subjectPoints = GetMark(e.Result,e.Ids);
  325. // });
  326. ////subjectPoints.ForEach(f => f.GroupBy(f[0]));
  327. ////进线情况统计
  328. //Dictionary<string, List<List<string>>> dicts = new Dictionary<string, List<List<string>>>();
  329. //foreach (IGrouping<string, List<string>> group in subjectPoints.GroupBy(c => c[0]))
  330. //{
  331. // dicts.Add(group.Key, group.ToList());
  332. //};
  333. //Average.Add("classList", classList);
  334. //List<List<string>> sp = new List<List<string>>();
  335. ////Dictionary<string, int> rankScore = new Dictionary<string, int>();
  336. //List<double> rankScore = new List<double>();
  337. //foreach (string key in dicts.Keys)
  338. //{
  339. // double score = 0;
  340. // List<string> values = new List<string>();
  341. // keys.ForEach(x =>
  342. // {
  343. // values.Add("-");
  344. // });
  345. // foreach (List<string> val in dicts[key])
  346. // {
  347. // int index = keys.IndexOf(val[1]);
  348. // values[index] = val[2];
  349. // values[keys.IndexOf("name")] = val[0];
  350. // score += double.Parse(val[2]);
  351. // values[keys.IndexOf("score")] = score + "";
  352. // }
  353. // rankScore.Add(score);
  354. // sp.Add(values);
  355. //}
  356. //AchievementService.ReName(sp, idToName, classToName, students);
  357. ////处理人数为整
  358. //string ip = iPersons.ToString("0");
  359. ////初始化进线分数
  360. //double ipoint = 0;
  361. ////计算成绩年级排名
  362. //rankScore.Sort(delegate (double s1, double s2) { return s2.CompareTo(s1); });
  363. //ipoint = rankScore[int.Parse(ip)];
  364. //foreach (List<string> rank in sp)
  365. //{
  366. // int index = rankScore.IndexOf(double.Parse(rank[3]));
  367. // rank[2] = (index + 1) + "";
  368. //}
  369. ////排除成绩为零的选手
  370. //for (int i = sp.Count - 1; i >= 0; i--)
  371. //{
  372. // if (sp[i][0].Equals("0"))
  373. // {
  374. // sp.Remove(sp[i]);
  375. // }
  376. //}
  377. //entryTable.Add("keys", keys);
  378. //entryTable.Add("datas", sp);
  379. ////封装进线人数统计
  380. //List<string> keyLine = new List<string>
  381. // {
  382. // "gradeRank",
  383. // "name",
  384. // "entryNum",
  385. // "totalNum",
  386. // "overAverageRate"
  387. // };
  388. //Dictionary<string, object> entryLineBar = new Dictionary<string, object>();
  389. ////存放班级信息
  390. //List<string> className = new List<string>();
  391. //foreach (string cla in classList)
  392. //{
  393. // className.Add(cla);
  394. //}
  395. //List<List<string>> datas = new List<List<string>>();
  396. ////记录各个班级进线率占比
  397. //List<string> persent = new List<string>();
  398. //int m = 0;
  399. //foreach (List<double> points in subSum)
  400. //{
  401. // List<string> detail = new List<string>();
  402. // keyLine.ForEach(x =>
  403. // {
  404. // detail.Add("-");
  405. // });
  406. // double sum = points.Count;
  407. // int j = 0;
  408. // for (int i = 0; i < points.Count; i++)
  409. // {
  410. // if (points[i] > ipoint)
  411. // {
  412. // j++;
  413. // }
  414. // }
  415. // double Lines = j;
  416. // detail[1] = className[m].ToString();
  417. // detail[2] = j.ToString();
  418. // detail[3] = points.Count.ToString();
  419. // var t3 = Math.Floor(Math.Round(decimal.Parse((Lines / sum).ToString("0.000")), 2) * 100);
  420. // persent.Add(t3.ToString());
  421. // detail[4] = t3.ToString();
  422. // datas.Add(detail);
  423. // m++;
  424. //}
  425. //persent.Sort(delegate (string s1, string s2) { return int.Parse(s2).CompareTo(int.Parse(s1)); });
  426. ////存放班级的年级排名
  427. //List<string> ranks = new List<string>();
  428. //foreach (List<string> des in datas)
  429. //{
  430. // int index = persent.IndexOf(des[4]);
  431. // des[0] = (index + 1).ToString();
  432. // ranks.Add((index + 1).ToString());
  433. //}
  434. ////预警统计
  435. //Dictionary<string, object> early = new Dictionary<string, object>();
  436. //List<List<string>> earlyWarning = new List<List<string>>();
  437. //List<string> keyWarning = new List<string>
  438. // {
  439. // "classId",
  440. // "totalNum",
  441. // "average",
  442. // "standardDeviation",
  443. // "overAverageRate",
  444. // "gradeRank"
  445. // };
  446. //int n = 0;
  447. //foreach (List<double> points in subSum)
  448. //{
  449. // double sum = 0;
  450. // List<string> classInfo = new List<string>();
  451. // classInfo.Add(className[n]);
  452. // classInfo.Add(points.Count.ToString());
  453. // foreach (int point in points)
  454. // {
  455. // sum += point;
  456. // }
  457. // double Aver = sum / points.Count;
  458. // classInfo.Add(Aver.ToString());
  459. // //存放班级平均
  460. // cAverage.Add(Aver.ToString());
  461. // //标准差
  462. // double powSum = 0;
  463. // foreach (int point in points)
  464. // {
  465. // powSum += Math.Pow(point - Aver, 2);
  466. // }
  467. // var pow = Math.Pow(powSum / points.Count, 0.5);
  468. // classInfo.Add(pow.ToString("0.00"));
  469. // //超均率
  470. // var super = (sum - (sum - 100)) / (sum - 100);
  471. // classInfo.Add(super.ToString("0.00"));
  472. // //年级排名
  473. // classInfo.Add(ranks[n]);
  474. // earlyWarning.Add(classInfo);
  475. // n++;
  476. //}
  477. ////sbujectsList.Add(subjects);
  478. //passRateMap.Add("subjects", subjects);
  479. //passRateMap.Add("class", passALL);
  480. //passRateMap.Add("grade", gradeList);
  481. //passRateMap.Add("area", areaList);
  482. ////passRate.Add("passRate", passALL);
  483. //early.Add("keys", keyWarning);
  484. //early.Add("datas", earlyWarning);
  485. //AclassAverage = AchievementService.GetAverage(exams, gAverage, cAverage, subSum, students);
  486. //List<Dictionary<string, object>> rankPR = AchievementService.GetPR(exams, subSum, students);
  487. //entryLineBar.Add("keys", keyLine);
  488. //entryLineBar.Add("datas", datas);
  489. ////sp.Sort(delegate (string s1, string s2) { return int.Parse(s1).CompareTo(int.Parse(s2)); });
  490. //Average.Add("subjectAverage", subjectAverage);
  491. //Average.Add("datas", examList);
  492. //achievementAnalysis.Add("passRate", passRateMap);
  493. //achievementAnalysis.Add("average", Average);
  494. //achievementAnalysis.Add("entryLineBar", entryLineBar);
  495. //achievementAnalysis.Add("entryTable", entryTable);
  496. //achievementAnalysis.Add("earlyWarning", early);
  497. //achievementAnalysis.Add("rankPR", rankPR);
  498. //achievementAnalysis.Add("stuAverage", AclassAverage);
  499. ////Redis处理结果集
  500. //if (RedisHelper.Instance != null)
  501. //{
  502. // if (!RedisHelper.Exists(CacheCosmosPrefix + method))
  503. // {
  504. // await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), achievementAnalysis);
  505. // }
  506. // else
  507. // {
  508. // await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), achievementAnalysis);
  509. // await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
  510. // }
  511. //}
  512. //return achievementAnalysis;
  513. // }
  514. // else return achievementAnalysis;
  515. // }
  516. // /* public List<string> GetMark(List<List<int>> point,List<string> ids) {
  517. // List<string> info = null;
  518. // for (int i = 0;i <= ids.Count();i++) {
  519. // info = new List<string>();
  520. // info.Add(ids[i]);
  521. // info.Add(point[i].Sum()+"");
  522. // }
  523. // return info;
  524. // }*/
  525. // [HttpPost("PointAnalysis")]
  526. //public async Task<BaseResponse> PointAnalysis(JsonElement request)
  527. //{
  528. // ResponseBuilder builder = ResponseBuilder.custom();
  529. // /*Dictionary<string, object> dict = new Dictionary<string, object>();
  530. // var emobj = request.EnumerateObject();
  531. // while (emobj.MoveNext())
  532. // {
  533. // dict[emobj.Current.Name] = emobj.Current.Value;
  534. // }
  535. // List<Dictionary<string, dynamic>> info = new List<Dictionary<string, dynamic>>();
  536. // if (RedisHelper.Instance != null)
  537. // {
  538. // info = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "PointAnalysis",
  539. // ShaHashHelper.GetSHA1(dict.ToJsonString()), timeoutSeconds, () => { return FindPointAnalysisRedis(dict, "PointAnalysis"); });
  540. // //数据从redis读取过后进行转换格式
  541. // builder.Data(info);
  542. // }
  543. // else
  544. // {
  545. // info = await FindPointAnalysisRedis(dict, "PointAnalysis");
  546. // builder.Data(info);
  547. // }*/
  548. // return builder.build();
  549. //}
  550. //[HttpPost("ExerciseScatter")]
  551. //public async Task<BaseResponse> ExerciseScatter(JsonElement request)
  552. //{
  553. // /* ResponseBuilder builder = ResponseBuilder.custom();
  554. // Dictionary<string, object> dict = new Dictionary<string, object>();
  555. // var emobj = request.EnumerateObject();
  556. // while (emobj.MoveNext())
  557. // {
  558. // dict[emobj.Current.Name] = emobj.Current.Value;
  559. // }
  560. // List<Dictionary<string, dynamic>> info = new List<Dictionary<string, dynamic>>();
  561. // if (RedisHelper.Instance != null)
  562. // {
  563. // info = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "ExerciseScatter",
  564. // ShaHashHelper.GetSHA1(dict.ToJsonString()), timeoutSeconds, () => { return FindExerciseScatterRedis(dict, "ExerciseScatter"); });
  565. // //数据从redis读取过后进行转换格式
  566. // builder.Data(info);
  567. // }
  568. // else
  569. // {
  570. // info = await FindExerciseScatterRedis(dict, "ExerciseScatter");
  571. // builder.Data(info);
  572. // }*/
  573. // return null;
  574. //}
  575. //public async Task<Dictionary<string, dynamic>> FindKnowledgePointRedis(Dictionary<string, object> dict, string method)
  576. //{
  577. // //ResponseBuilder builder = ResponseBuilder.custom();
  578. // dict.TryGetValue("subjectCode", out object subjectCode);
  579. // dict.TryGetValue("schoolCode", out object schoolCode);
  580. // dict.TryGetValue("code", out object code);
  581. // //dict.TryGetValue("scopeCode", out object scopeCode);
  582. // /* Dictionary<string, object> sub = new Dictionary<string, object>
  583. // {
  584. // { "subjectCode", subjectCode.ToString()},
  585. // { "code",code.ToString()}
  586. // };
  587. // Dictionary<string, object> examMap = new Dictionary<string, object>
  588. // {
  589. // { "schoolCode", schoolCode.ToString()},
  590. // { "code", code.ToString()},
  591. // { "subjectCode", subjectCode.ToString()}
  592. // };*/
  593. // List<ExamResultDto> exams = new List<ExamResultDto>();
  594. // if (RedisHelper.Exists(CacheCosmosPrefix + "examResult" + subjectCode.ToString()))
  595. // {
  596. // ExamResultDto res = RedisHelper.HGet<ExamResultDto>(CacheCosmosPrefix + "examResult" + subjectCode.ToString(), ShaHashHelper.GetSHA1(code.ToString()));
  597. // exams.Add(res);
  598. // }
  599. // List<PaperDto> paper = new List<PaperDto>();
  600. // if (RedisHelper.Exists(CacheCosmosPrefix + "paperInfo" + subjectCode.ToString()))
  601. // {
  602. // PaperDto papers = RedisHelper.HGet<PaperDto>(CacheCosmosPrefix + "paperInfo" + subjectCode.ToString(), ShaHashHelper.GetSHA1(code.ToString()));
  603. // paper.Add(papers);
  604. // }
  605. // Dictionary<string, object> stuMap = new Dictionary<string, object>
  606. // {
  607. // { "schoolCode", "Habook" }
  608. // };
  609. // //List<Student> students = await azureCosmosDBRepository.FindByDict<Student>(stuMap);
  610. // List<OldStudent> students = null;
  611. // if (RedisHelper.Exists(CacheCosmosPrefix + "students"))
  612. // {
  613. // students = RedisHelper.HGet<List<OldStudent>>(CacheCosmosPrefix + "students", ShaHashHelper.GetSHA1(schoolCode.ToString()));
  614. // //builder.Data(info);
  615. // //students.Add(student);
  616. // }
  617. // HashSet<string> knowledge = new HashSet<string>();
  618. // HashSet<string> area = new HashSet<string>();
  619. // List<double> point = new List<double>();
  620. // List<List<double>> result = new List<List<double>>();
  621. // List<Dictionary<string, int[]>> classes = new List<Dictionary<string, int[]>>();
  622. // List<string> ids = new List<string>();
  623. // //string Type = "";
  624. // if (dict.TryGetValue("type", out object Type))
  625. // {
  626. // /*paper.ForEach(p =>
  627. // {
  628. // p.item.ForEach(i =>
  629. // {
  630. // knowledge.Add(i.field);
  631. // area.Add(i.field);
  632. // });
  633. // });*/
  634. // knowledge.Add("知识");
  635. // knowledge.Add("理解");
  636. // knowledge.Add("应用");
  637. // knowledge.Add("分析");
  638. // knowledge.Add("综合");
  639. // knowledge.Add("评鉴");
  640. // area.Add("知识");
  641. // area.Add("理解");
  642. // area.Add("应用");
  643. // area.Add("分析");
  644. // area.Add("综合");
  645. // area.Add("评鉴");
  646. // }
  647. // else
  648. // {
  649. // paper.ForEach(p =>
  650. // {
  651. // p.item.ForEach(i =>
  652. // {
  653. // i.points.ForEach(o =>
  654. // {
  655. // knowledge.Add(o);
  656. // });
  657. // area.Add(i.field);
  658. // });
  659. // });
  660. // }
  661. // double Qnum = 0;
  662. // //确定高分组 低分组人数
  663. // List<List<double>> re = exams[0].result;
  664. // List<double> resultSum = new List<double>();
  665. // foreach (List<double> data in re)
  666. // {
  667. // resultSum.Add(data.Sum());
  668. // }
  669. // //确定高分组 最低分数
  670. // resultSum.Sort(delegate (double s1, double s2) { return s2.CompareTo(s1); });
  671. // for (int i = resultSum.Count - 1; i >= 0; i--)
  672. // {
  673. // if (resultSum[i] == 0)
  674. // {
  675. // resultSum.Remove(resultSum[i]);
  676. // }
  677. // }
  678. // double rhwCount = resultSum.Count * 0.27;
  679. // double rhw = resultSum[int.Parse(rhwCount.ToString("0"))];
  680. // //确定低分组 最高分数
  681. // resultSum.Sort(delegate (double s1, double s2) { return s1.CompareTo(s2); });
  682. // double rhlCount = resultSum.Count * 0.27;
  683. // double rhl = resultSum[int.Parse(rhwCount.ToString("0"))];
  684. // foreach (ExamResultDto ex in exams)
  685. // {
  686. // point = ex.point;
  687. // result = ex.result;
  688. // classes = ex.classes;
  689. // ids = ex.ids;
  690. // }
  691. // /* exams.ForEach(e =>
  692. // {
  693. // point = e.Point;
  694. // result = e.Result;
  695. // classes = e.Classes;
  696. // ids = e.Ids;
  697. // });*/
  698. // List<string> knowledgeName = new List<string>();
  699. // foreach (string cla in knowledge)
  700. // {
  701. // knowledgeName.Add(cla);
  702. // }
  703. // for (int k = 0; k < knowledgeName.Count; k++)
  704. // {
  705. // if (null == knowledgeName[k])
  706. // {
  707. // knowledgeName.Remove(knowledgeName[k]);
  708. // }
  709. // }
  710. // List<string> areaName = new List<string>();
  711. // foreach (string cla in area)
  712. // {
  713. // areaName.Add(cla);
  714. // }
  715. // for (int k = 0; k < areaName.Count; k++)
  716. // {
  717. // if (null == areaName[k])
  718. // {
  719. // areaName.Remove(areaName[k]);
  720. // }
  721. // }
  722. // //初始化年级总分
  723. // double total = 0;
  724. // //处理年级单个知识点得分率
  725. // foreach (List<double> grade in result)
  726. // {
  727. // total += grade.Sum();
  728. // }
  729. // foreach (string id in ids)
  730. // {
  731. // if (!id.Equals("0"))
  732. // {
  733. // Qnum++;
  734. // }
  735. // }
  736. // //试卷总分
  737. // double TotalPoint = point.Sum();
  738. // //计算认知层次占比
  739. // List<string> fper = new List<string>();
  740. // for (int a = 0; a < areaName.Count; a++)
  741. // {
  742. // double fieldPoint = 0;
  743. // paper.ForEach(p =>
  744. // {
  745. // int n = 0;
  746. // p.item.ForEach(i =>
  747. // {
  748. // if (i.field != null && i.field.Contains(areaName[a]))
  749. // {
  750. // fieldPoint += point[n];
  751. // }
  752. // n++;
  753. // });
  754. // });
  755. // double fieldPersent = fieldPoint / TotalPoint;
  756. // fper.Add(fieldPersent.ToString("0.00"));
  757. // }
  758. // //求单个知识点所占分数
  759. // List<string> per = new List<string>();
  760. // List<string> gper = new List<string>();
  761. // List<string> knowPer = new List<string>();
  762. // List<Dictionary<string, double>> eper = new List<Dictionary<string, double>>();
  763. // Dictionary<string, object> knowledgeALL = new Dictionary<string, object>();
  764. // Dictionary<string, object> knowledgeMap = new Dictionary<string, object>();
  765. // Dictionary<string, object> classMap = new Dictionary<string, object>();
  766. // Dictionary<string, object> wrongMap = new Dictionary<string, object>();
  767. // HashSet<string> className = new HashSet<string>();
  768. // List<List<string>> wrongPersent = new List<List<string>>();
  769. // List<string> key = new List<string>
  770. // {
  771. // "id",
  772. // "className",
  773. // "seatNO",
  774. // "point",
  775. // "anwPoint",
  776. // "persent"
  777. // };
  778. // List<string> keyWrong = new List<string>
  779. // {
  780. // "name",
  781. // "point",
  782. // "itemNO",
  783. // "persent",
  784. // "wrong",
  785. // "rhw",
  786. // "rlw"
  787. // };
  788. // for (int k = 0; k < knowledgeName.Count; k++)
  789. // {
  790. // List<string> knowledgeClass = new List<string>();
  791. // List<List<string>> stuPersent = new List<List<string>>();
  792. // double OnePoint = 0;
  793. // //获取每个知识点占有多少分值
  794. // double ePoint = 0;
  795. // double anwGPoint = 0;
  796. // double poG = 0;
  797. // int m = 0;
  798. // List<string> valuew = new List<string>();
  799. // List<string> itemNo = new List<string>();
  800. // keyWrong.ForEach(x =>
  801. // {
  802. // valuew.Add("-");
  803. // });
  804. // int wrongCount = 0;
  805. // valuew[0] = knowledgeName[k];
  806. // paper.ForEach(p =>
  807. // {
  808. // int n = 0;
  809. // if (dict.TryGetValue("type", out object Type))
  810. // {
  811. // p.item.ForEach(i =>
  812. // {
  813. // if (i.field != null && i.field.Contains(knowledgeName[k]))
  814. // {
  815. // OnePoint += point[n];
  816. // itemNo.Add((n + 1).ToString());
  817. // }
  818. // n++;
  819. // });
  820. // }
  821. // else
  822. // {
  823. // p.item.ForEach(i =>
  824. // {
  825. // if (i.points != null && i.points.Contains(knowledgeName[k]))
  826. // {
  827. // OnePoint += 1 / Convert.ToDouble(i.points.Count) * point[n];
  828. // itemNo.Add((n + 1).ToString());
  829. // }
  830. // n++;
  831. // });
  832. // }
  833. // valuew[1] = OnePoint.ToString();
  834. // string itemNos = "";
  835. // if (itemNo.Count > 0)
  836. // {
  837. // foreach (string index in itemNo)
  838. // {
  839. // itemNos += index + ",";
  840. // }
  841. // valuew[2] = itemNos[0..^1];
  842. // }
  843. // else
  844. // {
  845. // valuew[2] = itemNos;
  846. // }
  847. // });
  848. // int rhwC = 0;
  849. // int rhlC = 0;
  850. // foreach (string id in ids)
  851. // {
  852. // if (id.Equals("0") || result[m].Sum() == 0)
  853. // {
  854. // m++;
  855. // continue;
  856. // }
  857. // List<string> values = new List<string>();
  858. // key.ForEach(x =>
  859. // {
  860. // values.Add("-");
  861. // });
  862. // foreach (OldStudent info in students)
  863. // {
  864. // if (info.studentId.Equals(id))
  865. // {
  866. // values[2] = info.seatNo.ToString();
  867. // break;
  868. // }
  869. // }
  870. // //List<string> stu = new List<string>();
  871. // values[0] = id;
  872. // values[1] = "-";
  873. // //List<List<string>> stuItem = new List<List<string>>();
  874. // int statuCount = 0;
  875. // paper.ForEach(p =>
  876. // {
  877. // int n = 0;
  878. // double anwPoint = 0;
  879. // double po = 0;
  880. // p.item.ForEach(i =>
  881. // {
  882. // if (dict.TryGetValue("type", out object Type))
  883. // {
  884. // if (i.field != null && i.field.Contains(knowledgeName[k]))
  885. // {
  886. // //Dictionary<string, double> mapkeyItem = new Dictionary<string, double>();
  887. // //OnePoint += 1 / Convert.ToDouble(i.points.Count) * point[n];
  888. // //当前认知层次在该题占比多少
  889. // ePoint = 1;
  890. // anwPoint += result[m][n] * ePoint;
  891. // //所有学生单个认知层次得分情况
  892. // anwGPoint += result[m][n] * ePoint;
  893. // po += point[n] * ePoint;
  894. // //认知层次所占分数
  895. // poG += point[n] * ePoint;
  896. // if (result[m][n] == 0 && statuCount == 0)
  897. // {
  898. // statuCount++;
  899. // wrongCount++;
  900. // if (result[m].Sum() >= rhw)
  901. // {
  902. // rhwC++;
  903. // }
  904. // if (result[m].Sum() <= rhl)
  905. // {
  906. // rhlC++;
  907. // }
  908. // }
  909. // }
  910. // n++;
  911. // }
  912. // else
  913. // {
  914. // if (i.points != null && i.points.Contains(knowledgeName[k]))
  915. // {
  916. // {
  917. // //Dictionary<string, double> mapkeyItem = new Dictionary<string, double>();
  918. // //OnePoint += 1 / Convert.ToDouble(i.points.Count) * point[n];
  919. // //当前知识点在该题占比多少
  920. // ePoint = 1 / Convert.ToDouble(i.points.Count);
  921. // anwPoint += result[m][n] * ePoint;
  922. // //所有学生单个知识点得分情况
  923. // anwGPoint += result[m][n] * ePoint;
  924. // po += point[n] * ePoint;
  925. // //知识点所占分数
  926. // poG += point[n] * ePoint;
  927. // if (result[m][n] == 0 && statuCount == 0)
  928. // {
  929. // statuCount++;
  930. // wrongCount++;
  931. // if (result[m].Sum() >= rhw)
  932. // {
  933. // rhwC++;
  934. // }
  935. // if (result[m].Sum() <= rhl)
  936. // {
  937. // rhlC++;
  938. // }
  939. // }
  940. // }
  941. // n++;
  942. // }
  943. // });
  944. // if (po == 0)
  945. // {
  946. // values[3] = "0";
  947. // values[4] = "0";
  948. // values[5] = "0";
  949. // }
  950. // else
  951. // {
  952. // double stuPser = anwPoint / po;
  953. // values[3] = po.ToString();
  954. // values[4] = anwPoint.ToString();
  955. // values[5] = stuPser.ToString("0.00");
  956. // }
  957. // //stuItem.Add(values);
  958. // });
  959. // stuPersent.Add(values);
  960. // m++;
  961. // }
  962. // AchievementService.ReName(stuPersent, ids, classes, students);
  963. // double knowPser = 0;
  964. // if (poG == 0)
  965. // {
  966. // knowPer.Add("0");
  967. // }
  968. // else
  969. // {
  970. // knowPser = anwGPoint / poG;
  971. // knowPer.Add(knowPser.ToString("0.00"));
  972. // }
  973. // values[5] = stuPser.ToString("0.00");
  974. // //错题关系表
  975. // valuew[3] = knowPser.ToString("0.00");
  976. // valuew[4] = wrongCount.ToString();
  977. // valuew[5] = rhwC.ToString();
  978. // valuew[6] = rhlC.ToString();
  979. // wrongPersent.Add(valuew);
  980. // knowledgeMap.Add(knowledgeName[k], stuPersent);
  981. // //知识点占比
  982. // double persent = OnePoint / TotalPoint;
  983. // foreach (Dictionary<string, int[]> map in classes)
  984. // {
  985. // List<string> classPoints = new List<string>();
  986. // //初始化班级得分
  987. // double anwCPoint = 0;
  988. // double cpo = 0;
  989. // foreach (KeyValuePair<string, int[]> kvp in map)
  990. // {
  991. // className.Add(kvp.Key);
  992. // for (int n = kvp.Value[0]; n < kvp.Value[1]; n++)
  993. // {
  994. // if (result[n].Sum() == 0) continue;
  995. // paper.ForEach(p =>
  996. // {
  997. // int x = 0;
  998. // wrongPersent.Add(valuew);
  999. // knowledgeMap.Add(knowledgeName[k], stuPersent);
  1000. // p.item.ForEach(i =>
  1001. // {
  1002. // if (dict.TryGetValue("type", out object Type))
  1003. // {
  1004. // if (i.field != null && i.field.Contains(knowledgeName[k]))
  1005. // {
  1006. // //当前认知层次在该题占比多少
  1007. // ePoint = 1;
  1008. // anwCPoint += result[n][x] * ePoint;
  1009. // cpo += point[x] * ePoint;
  1010. // }
  1011. // x++;
  1012. // }
  1013. // else
  1014. // {
  1015. // if (i.points != null && i.points.Contains(knowledgeName[k]))
  1016. // {
  1017. // //当前知识点在该题占比多少
  1018. // ePoint = 1 / Convert.ToDouble(i.points.Count);
  1019. // anwCPoint += result[n][x] * ePoint;
  1020. // cpo += point[x] * ePoint;
  1021. // }
  1022. // x++;
  1023. // }
  1024. // });
  1025. // });
  1026. // }
  1027. // }
  1028. // if (cpo == 0)
  1029. // {
  1030. // //double classPser = anwCPoint / cpo;
  1031. // knowledgeClass.Add("0");
  1032. // }
  1033. // else
  1034. // {
  1035. // double classPser = anwCPoint / cpo;
  1036. // knowledgeClass.Add(classPser.ToString("0.00"));
  1037. // }
  1038. // classMap.Add(knowledgeName[k], knowledgeClass);
  1039. // per.Add(persent.ToString("0.00"));
  1040. // }
  1041. // knowledgeMap.Add("grade", knowPer);
  1042. // knowledgeMap.Add("keys", key);
  1043. // classMap.Add("className", className);
  1044. // wrongMap.Add("keys", keyWrong);
  1045. // wrongMap.Add("datas", wrongPersent);
  1046. // knowledgeALL.Add("pointList", knowledgeName);
  1047. // knowledgeALL.Add("per", per);
  1048. // knowledgeALL.Add("level", areaName);
  1049. // knowledgeALL.Add("fper", fper);
  1050. // knowledgeALL.Add("stupercent", knowledgeMap);
  1051. // knowledgeALL.Add("classpercent", classMap);
  1052. // knowledgeALL.Add("wrong", wrongMap);
  1053. // //builder.Data(knowledgeALL);
  1054. // classMap.Add(knowledgeName[k], knowledgeClass);
  1055. // per.Add(persent.ToString("0.00"));
  1056. // //Redis处理结果集
  1057. // if (RedisHelper.Instance != null)
  1058. // {
  1059. // if (!RedisHelper.Exists(CacheCosmosPrefix + method))
  1060. // {
  1061. // await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), knowledgeALL);
  1062. // }
  1063. // else
  1064. // {
  1065. // await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), knowledgeALL);
  1066. // await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
  1067. // }
  1068. // }
  1069. // return knowledgeALL;
  1070. // }
  1071. // [HttpPost("knowledgePoint")]
  1072. // public async Task<BaseResponse> KnowledgePoint(JsonElement request)
  1073. // {
  1074. // ResponseBuilder builder = ResponseBuilder.custom();
  1075. // Dictionary<string, object> dict = new Dictionary<string, object>();
  1076. // var emobj = request.EnumerateObject();
  1077. // while (emobj.MoveNext())
  1078. // {
  1079. // dict[emobj.Current.Name] = emobj.Current.Value;
  1080. // }
  1081. // Dictionary<string, dynamic> info = new Dictionary<string, dynamic>();
  1082. // if (RedisHelper.Instance != null)
  1083. // {
  1084. // info = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "knowledgePoint",
  1085. // ShaHashHelper.GetSHA1(dict.ToJsonString()), timeoutSeconds, () => { return FindKnowledgePointRedis(dict, "knowledgePoint"); });
  1086. // //数据从redis读取过后进行转换格式
  1087. // }
  1088. // else
  1089. // {
  1090. // info = await FindKnowledgePointRedis(dict, "knowledgePoint");
  1091. // builder.Data(info);
  1092. // }
  1093. // return builder.build();
  1094. // }
  1095. // [HttpPost("FindExamInfo")]
  1096. // public async Task<BaseResponse> FindExamInfo(JsonElement request)
  1097. // {
  1098. // ResponseBuilder builder = ResponseBuilder.custom();
  1099. // Dictionary<string, object> dict = new Dictionary<string, object>();
  1100. // var emobj = request.EnumerateObject();
  1101. // while (emobj.MoveNext())
  1102. // {
  1103. // dict[emobj.Current.Name] = emobj.Current.Value;
  1104. // }
  1105. // if (RedisHelper.Instance != null)
  1106. // {
  1107. // try
  1108. // {
  1109. // ///RedisHelper.Instance.CurrentSerialize = obj => System.Text.Json.JsonSerializer.Serialize(obj);
  1110. // /// RedisHelper.Instance.CurrentDeserialize = (json, type) => System.Text.Json.JsonSerializer.Deserialize(json, type);
  1111. // List<ExamInfoDto> info = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "FindExamInfo",
  1112. // ShaHashHelper.GetSHA1(dict.ToJsonString()), timeoutSeconds, () => { return FindExamInfoRedis(dict, "FindExamInfo"); });
  1113. // builder.Data(info);
  1114. // }
  1115. // catch (Exception e)
  1116. // {
  1117. // // throw new BizException(e.Message);
  1118. // }
  1119. // }
  1120. // else
  1121. // {
  1122. // List<ExamInfoDto> info = await FindExamInfoRedis(dict, "FindExamInfo");
  1123. // builder.Data(info);
  1124. // }
  1125. // return builder.build();
  1126. // }
  1127. // //目前单次考试权重关系和权重次数
  1128. // info[i].index = info[i].piont * 1 / 1;
  1129. // public async Task<List<ExamInfoDto>> FindExamInfoRedis(Dictionary<string, object> dict, string method)
  1130. // {
  1131. // return new List<ExamInfoDto>();
  1132. // //{
  1133. // // List<ExamInfoDto> info = await _azureCosmos.FindByDict<ExamInfoDto>(dict);
  1134. // // List<ExamResultDto> exams = new List<ExamResultDto>();
  1135. // // for (int i = 0; i < info.Count; i++) {
  1136. // // for (int j = 0; j < info[i].conditions.subject.Count; j++)
  1137. // // {
  1138. // // if (RedisHelper.Exists(CacheCosmosPrefix + "examResult" + info[i].conditions.subject[j]))
  1139. // // {
  1140. // // ExamResultDto result = RedisHelper.HGet<ExamResultDto>(CacheCosmosPrefix + "examResult" + info[i].conditions.subject[j], ShaHashHelper.GetSHA1(info[i].examCode.ToString()));
  1141. // // //builder.Data(info);
  1142. // // exams.Add(result);
  1143. // // }
  1144. // // }
  1145. // // //初始化总分
  1146. // // double sumPoint = 0;
  1147. // // for (int k = 0; k < exams.Count; k++) {
  1148. // // for (int n = exams[k].ids.Count - 1; n >= 0;n--)
  1149. // // {
  1150. // // if (exams[k].ids[n].Equals("0"))
  1151. // // {
  1152. // // exams[k].ids.Remove(exams[k].ids[n]);
  1153. // // }
  1154. // // }
  1155. // // //获取总分数
  1156. // // exams[k].result.ForEach(r =>
  1157. // // {
  1158. // // sumPoint += r.Sum();
  1159. // // });
  1160. // // info[i].realCount = exams[k].ids.Count;
  1161. // // }
  1162. // // info[i].piont = sumPoint / info[i].realCount;
  1163. // // //目前单次考试权重关系和权重次数
  1164. // // info[i].index = info[i].piont * 1 / 1;
  1165. // // }
  1166. // // if (RedisHelper.Instance != null)
  1167. // // {
  1168. // // if (!RedisHelper.Exists(CacheCosmosPrefix + method))
  1169. // // {
  1170. // // await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), info);
  1171. // // }
  1172. // // else
  1173. // // {
  1174. // // await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), info);
  1175. // // await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
  1176. // // }
  1177. // // }
  1178. // // return info;
  1179. // //}
  1180. // //catch (Exception e)
  1181. // //{
  1182. // // throw new BizException(e.Message);
  1183. // //}
  1184. // }
  1185. // [HttpPost("FindExamPaper")]
  1186. // public BaseResponse FindExamPaper(JsonElement request)
  1187. // {
  1188. // //Dictionary<string, object> dict = new Dictionary<string, object>();
  1189. // /* var emobj = request.EnumerateObject();
  1190. // while (emobj.MoveNext())
  1191. // {
  1192. // dict[emobj.Current.Name] = emobj.Current.Value;
  1193. // }*/
  1194. // request.TryGetProperty("subjectCode", out JsonElement subjectCode);
  1195. // request.TryGetProperty("code", out JsonElement code);
  1196. // /*dict.TryGetValue("subjectCode", out object subjectCode);
  1197. // dict.TryGetValue("code", out object code);*/
  1198. // ResponseBuilder builder = ResponseBuilder.custom();
  1199. // /*if (RedisHelper.Instance != null)
  1200. // {
  1201. // List<Paper> info = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + request.method,
  1202. // ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(request.@params)), timeoutSeconds, () => { return FindExamPaperRedis(request.@params, request.method); });
  1203. // }
  1204. // else
  1205. // {
  1206. // List<Paper> info = await FindExamPaperRedis(request.@params, request.method);
  1207. // builder.Data(info);
  1208. // }*/
  1209. // List<PaperDto> paper = new List<PaperDto>();
  1210. // if (RedisHelper.Exists(CacheCosmosPrefix + "paperInfo" + subjectCode.ToString()))
  1211. // {
  1212. // PaperDto paper1 = RedisHelper.HGet<PaperDto>(CacheCosmosPrefix + "paperInfo" + subjectCode.ToString(), ShaHashHelper.GetSHA1(code.ToString()));
  1213. // paper.Add(paper1);
  1214. // builder.Data(paper);
  1215. // }
  1216. // {
  1217. // return builder.build();
  1218. // }
  1219. // /* public async Task<List<Paper>> FindExamPaperRedis(Dictionary<string, object> dict, string method)
  1220. // {
  1221. // try
  1222. // {
  1223. // List<Paper> info = await _azureCosmos.FindByDict<Paper>(dict);
  1224. // if (RedisHelper.Instance != null)
  1225. // {
  1226. // if (!RedisHelper.Exists(CacheCosmosPrefix + method))
  1227. // {
  1228. // await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), info);
  1229. // }
  1230. // else
  1231. // {
  1232. // await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), info);
  1233. // await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
  1234. // }
  1235. // }
  1236. // return info;
  1237. // }
  1238. // catch (Exception e)
  1239. // {
  1240. // throw new BizException(e.Message);
  1241. // builder.Data(exams);
  1242. // }
  1243. // }
  1244. // }*/
  1245. // [HttpPost("FindExamAnswer")]
  1246. // public BaseResponse FindExamAnswer(JsonElement request)
  1247. // {
  1248. // request.TryGetProperty("subjectCode", out JsonElement subjectCode);
  1249. // request.TryGetProperty("code", out JsonElement code);
  1250. // ResponseBuilder builder = ResponseBuilder.custom();
  1251. // List<ExamAnswer> exams = new List<ExamAnswer>();
  1252. // if (RedisHelper.Exists(CacheCosmosPrefix + "examAnswer" + subjectCode.ToString()))
  1253. // {
  1254. // ExamAnswer exam = RedisHelper.HGet<ExamAnswer>(CacheCosmosPrefix + "examAnswer" + subjectCode.ToString(), ShaHashHelper.GetSHA1(code.ToString()));
  1255. // exams.Add(exam);
  1256. // builder.Data(exams);
  1257. // }
  1258. // return builder.build();
  1259. // }
  1260. // public async Task<List<ExamAnswer>> FindExamAnswerRedis(Dictionary<string, object> dict, string method)
  1261. // {
  1262. // return new List<ExamAnswer>();
  1263. // //try
  1264. // //{
  1265. // // List<ExamAnswer> info = await _azureCosmos.FindByDict<ExamAnswer>(dict);
  1266. // // if (RedisHelper.Instance != null)
  1267. // // {
  1268. // // if (!RedisHelper.Exists(CacheCosmosPrefix + method))
  1269. // // {
  1270. // // await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), info);
  1271. // // }
  1272. // // else
  1273. // // {
  1274. // // await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), info);
  1275. // // await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
  1276. // // }
  1277. // // }
  1278. // // return info;
  1279. // //}
  1280. // //catch (Exception e)
  1281. // //{
  1282. // // throw new BizException(e.Message);
  1283. // //}
  1284. // }
  1285. // public async Task<List<ExamAnswer>> FindExamAnswerRedis(Dictionary<string, object> dict)
  1286. // {
  1287. // return new List<ExamAnswer>();
  1288. // //try
  1289. // //{
  1290. // // List<ExamAnswer> info = await _azureCosmos.FindByDict<ExamAnswer>(dict);
  1291. // // if (RedisHelper.Instance != null)
  1292. // // {
  1293. // // if (!RedisHelper.Exists(CacheCosmosPrefix + "FindExamAnswer"))
  1294. // // {
  1295. // // await RedisHelper.HSetAsync(CacheCosmosPrefix + "FindExamAnswer", ShaHashHelper.GetSHA1(dict.ToJsonString()), info);
  1296. // // }
  1297. // // else
  1298. // // {
  1299. // // await RedisHelper.HSetAsync(CacheCosmosPrefix + "FindExamAnswer", ShaHashHelper.GetSHA1(dict.ToJsonString()), info);
  1300. // // await RedisHelper.ExpireAsync(CacheCosmosPrefix + "FindExamAnswer", timeoutSeconds);
  1301. // // }
  1302. // // }
  1303. // // return info;
  1304. // //}
  1305. // //catch (Exception e)
  1306. // //{
  1307. // // throw new BizException(e.Message);
  1308. // //}
  1309. // }
  1310. // [HttpPost("HomeStatistics")]
  1311. // public async Task<BaseResponse> HomeStatistics(JsonElement request)
  1312. // {
  1313. // ResponseBuilder builder = ResponseBuilder.custom();
  1314. // Dictionary<string, object> dict = new Dictionary<string, object>();
  1315. // var emobj = request.EnumerateObject();
  1316. // while (emobj.MoveNext())
  1317. // {
  1318. // dict[emobj.Current.Name] = emobj.Current.Value;
  1319. // }
  1320. // List<Dictionary<string, dynamic>> info = new List<Dictionary<string, dynamic>>();
  1321. // if (RedisHelper.Instance != null)
  1322. // {
  1323. // info = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "HomeStatistics",
  1324. // ShaHashHelper.GetSHA1(dict.ToJsonString()), timeoutSeconds, () => { return FindHomeStatisticsRedis(dict, "HomeStatistics"); });
  1325. // //数据从redis读取过后进行转换格式
  1326. // builder.Data(info);
  1327. // }
  1328. // else
  1329. // {
  1330. // info = await FindHomeStatisticsRedis(dict, "HomeStatistics");
  1331. // builder.Data(info);
  1332. // }
  1333. // return builder.build();
  1334. // }
  1335. // public async Task<List<Dictionary<string, dynamic>>> FindHomeStatisticsRedis(Dictionary<string, object> dict, string method)
  1336. // {
  1337. // return new List<Dictionary<string, dynamic>>();
  1338. // //request.@params.TryGetValue("subjectCode", out object subjectCode);
  1339. // // dict.TryGetValue("schoolCode", out object schoolCode);
  1340. // // dict.TryGetValue("code", out object code);
  1341. // // Dictionary<string, object> eMap = new Dictionary<string, object>
  1342. // // {
  1343. // // { "code", code.ToString()}
  1344. // // };
  1345. // // Dictionary<string, object> SCMap = new Dictionary<string, object>
  1346. // // {
  1347. // // { "id", schoolCode.ToString()},
  1348. // // };
  1349. // // //说明 同学校、同类型考试数据
  1350. // // //List<ExamInfo> exams = await azureCosmosDBRepository.FindByDict<ExamInfo>(eMap);
  1351. // // List<ExamInfoDto> exams = new List<ExamInfoDto>();
  1352. // // if (RedisHelper.Instance != null)
  1353. // // {
  1354. // // exams = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "FindExamInfo",
  1355. // // ShaHashHelper.GetSHA1(eMap.ToJsonString()), timeoutSeconds, () => { return FindExamInfoRedis(eMap, "FindExamInfo"); });
  1356. // // }
  1357. // // else
  1358. // // {
  1359. // // exams = await FindExamInfoRedis(eMap, "FindExamInfo");
  1360. // // }
  1361. // // List<ExamInfoDto> newInfo = new List<ExamInfoDto>();
  1362. // // //获取各个学段最新的考试信息
  1363. // // foreach (IGrouping<string, ExamInfoDto> group in exams.GroupBy(c => c.conditions.grade))
  1364. // // {
  1365. // // ExamInfoDto examInfo = group.ToList().OrderByDescending(e => e.createTime).ToList().FirstOrDefault();
  1366. // // newInfo.Add(examInfo);
  1367. // // };
  1368. // // //newInfo.Select(e => e.type.Equals("union"));
  1369. // // //List<ExamInfo> unionInfo = newInfo.Where(e => e.type.Equals("union")).ToList();
  1370. // // //exams.GroupBy(e => e.conditions.period);
  1371. // // //ExamInfo info = exams.OrderByDescending(e => e.createTime).ToList().FirstOrDefault();
  1372. // // //查询学校对应的年级信息
  1373. // // List<School> schools = await _azureCosmos.FindByDict<School>(SCMap);
  1374. // // //List<School> schools = new List<School>();
  1375. // ///* if (RedisHelper.Exists(CacheCosmosPrefix + "schoolInfo"))
  1376. // // {
  1377. // // School sc = RedisHelper.HGet<School>(CacheCosmosPrefix + "schoolInfo",
  1378. // // ShaHashHelper.GetSHA1(schoolCode.ToString()));
  1379. // // schools.Add(sc);
  1380. // // }*/
  1381. // // string Period = "";
  1382. // // string Grade = "";
  1383. // // //List<double> CoreAverage = new List<double>();
  1384. // // try
  1385. // // {
  1386. // // List<Period> periods = new List<Period>();
  1387. // // List<Grade> grades = new List<Grade>();
  1388. // // foreach (School s in schools)
  1389. // // {
  1390. // // periods = s.period;
  1391. // // }
  1392. // // periods.ForEach(p =>
  1393. // // {
  1394. // // p.grades.ForEach(g => {
  1395. // // grades.Add(g);
  1396. // // });
  1397. // // /*if (p.periodCode.Equals("初中"))
  1398. // // {
  1399. // // grades = p.grades;
  1400. // // }
  1401. // // else if (p.periodCode.Equals("高中"))
  1402. // // {
  1403. // // grades = p.grades;
  1404. // // }
  1405. // // else
  1406. // // {
  1407. // // grades = p.grades;
  1408. // // }*/
  1409. // // });
  1410. // // List<Dictionary<string, object>> map = new List<Dictionary<string, object>>();
  1411. // // //循环处理不同年级考试信息
  1412. // // foreach (Grade g in grades)
  1413. // // {
  1414. // // double weightSum = 0;
  1415. // // List<double> CoreAverage = new List<double>();
  1416. // // List<List<List<string>>> AllPoint = new List<List<List<string>>>();
  1417. // // List<List<List<string>>> AllPointAverage = new List<List<List<string>>>();
  1418. // // List<List<List<string>>> AllKeyLine = new List<List<List<string>>>();
  1419. // // HashSet<string> classList = new HashSet<string>();
  1420. // // HashSet<string> subjectList = new HashSet<string>();
  1421. // // for (int i = 0; i < newInfo.Count; i++)
  1422. // // {
  1423. // // if (g.id.Equals(newInfo[i].conditions.grade))
  1424. // // {
  1425. // // List<ExamResultDto> simples = new List<ExamResultDto>();
  1426. // // for (int j = 0; j < newInfo[i].conditions.subject.Count; j++)
  1427. // // {
  1428. // // ExamResultDto result = new ExamResultDto();
  1429. // // if (RedisHelper.Exists(CacheCosmosPrefix + "examResult" + newInfo[i].conditions.subject[j]))
  1430. // // {
  1431. // // result = RedisHelper.HGet<ExamResultDto>(CacheCosmosPrefix + "examResult" + newInfo[i].conditions.subject[j],
  1432. // // ShaHashHelper.GetSHA1(newInfo[i].examCode));
  1433. // // simples.Add(result);
  1434. // // }
  1435. // // //List<ExamResult> examResults = new List<ExamResult>();
  1436. // // /*Dictionary<string, object> sub = new Dictionary<string, object>
  1437. // // {
  1438. // // { "code", newInfo[i].id}
  1439. // // };*/
  1440. // // Period = newInfo[i].conditions.period;
  1441. // // Grade = newInfo[i].conditions.grade;
  1442. // // List<string> subjects = new List<string>();
  1443. // // List<List<string>> SubjectClassAverage = new List<List<string>>();
  1444. // // List<List<string>> SubjectAverage = new List<List<string>>();
  1445. // // //List<List<string>> SubjectClassAverage = new List<List<string>>();
  1446. // // //List<ExamResult> simples = await azureCosmosDBRepository.FindByDict<ExamResult>(sub);
  1447. // }
  1448. // }
  1449. // // // 学生总分
  1450. // // double coreSum = 0;
  1451. // // int stuCount = newInfo[i].stuCount;
  1452. // // //int stuCount = 0;
  1453. // // //初始化进行人数
  1454. // // double iPersons = 0;
  1455. // // //
  1456. // // List<List<double>> subSum = new List<List<double>>();
  1457. // // if (simples.IsEmpty()) continue;
  1458. // // double weight = 0.5;
  1459. // // weightSum += weight;
  1460. // // int classLen = simples[0].classes.Count;
  1461. // // for (int cls = 0; cls < classLen; cls++)
  1462. // // {
  1463. // // if (simples[0].classes[cls].TryGetValue(simples[0].classes[cls].Keys.ToArray<string>()[0], out int[] indexs))
  1464. // // {
  1465. // // List<double> stuScore = new List<double>();
  1466. // // int stdLen = indexs[1] - indexs[0] + 1;
  1467. // // for (int n = 0; n < stdLen; n++)
  1468. // // {
  1469. // // stuScore.Add(0);
  1470. // // }
  1471. // // subSum.Add(stuScore);
  1472. // // }
  1473. // // }
  1474. // // simples.ForEach(s =>
  1475. // // {
  1476. // // subjectList.Add(s.subjectCode);
  1477. // // //计算试卷总分
  1478. // // double sum = s.point.Sum();
  1479. // // //int stuSum = 0;
  1480. // // int classIndex = 0;
  1481. // // List<string> ClassAverage = new List<string>();
  1482. // // List<string> Average = new List<string>();
  1483. // // List<string> passList = new List<string>();
  1484. // // s.classes.ForEach(c =>
  1485. // // {
  1486. // // List<List<string>> classPRL = new List<List<string>>();
  1487. // // //初始化班级总分
  1488. // // double classPoint = 0;
  1489. // // //初始化班级缺考人数
  1490. // // int classCount = 0;
  1491. // // //初始化班级平均得分率
  1492. // // double points = 0;
  1493. // // //初始化班级平均得分率
  1494. // // double AveragePoints = 0;
  1495. // // //初始化各班参考人数
  1496. // // int counts = 0;
  1497. // // //c.Keys遍历key值
  1498. // // foreach (string key in c.Keys)
  1499. // // {
  1500. // // classList.Add(key);
  1501. // // }
  1502. // // //每个班级平均分
  1503. // // foreach (int[] value in c.Values)
  1504. // // {
  1505. // // for (int i = value[0]; i <= value[1]; i++)
  1506. // // {
  1507. // // //初始化学生单科个人得分
  1508. // // double stuPoints = s.result[i].Sum();
  1509. // // subSum[classIndex][i - value[0]] = stuPoints + subSum[classIndex][i - value[0]];
  1510. // // classPoint += s.result[i].Sum();
  1511. // // coreSum += s.result[i].Sum();
  1512. // // if (s.result[i].Sum() == 0)
  1513. // // {
  1514. // // classCount++;
  1515. // // }
  1516. // // }
  1517. // // //每个班级实际参考人数
  1518. // // counts = value[1] - value[0] + 1;
  1519. // // //stuSum += counts;
  1520. // // //stuCount += counts;
  1521. // // points = Convert.ToDouble(classPoint) / counts / sum;
  1522. // // //计算每个班级平均得分
  1523. // // AveragePoints = Convert.ToDouble(classPoint) / counts;
  1524. // // ClassAverage.Add(points.ToString("0.000"));
  1525. // // Average.Add(AveragePoints.ToString());
  1526. // // }
  1527. // // classIndex += 1;
  1528. // // });
  1529. // // SubjectClassAverage.Add(ClassAverage);
  1530. // // SubjectAverage.Add(Average);
  1531. // // //subAverage = subjectPoint / ClassAverage.Count();
  1532. // // //subjectAverage.Add(subAverage.ToString("0.00"));
  1533. // // });
  1534. // // //获取进线人数
  1535. // // iPersons = stuCount / classList.Count * 0.4;
  1536. // // //权重配分 学生总平均分 * 权重配分
  1537. // // double core = coreSum / stuCount * weight;
  1538. // // CoreAverage.Add(core);
  1539. // // AllPoint.Add(SubjectClassAverage);
  1540. // // AllPointAverage.Add(SubjectAverage);
  1541. // // //处理人数为整
  1542. // // string ip = iPersons.ToString("0");
  1543. // // //初始化进线分数
  1544. // // int ipoint = 0;
  1545. // // List<int> AllPoints = new List<int>();
  1546. // // foreach (List<double> points in subSum)
  1547. // // {
  1548. // // foreach (int po in points)
  1549. // // {
  1550. // // AllPoints.Add(po);
  1551. // // }
  1552. // // }
  1553. // // for (int sn = 0; sn < subSum.Count; sn++)
  1554. // // {
  1555. // // for (int j = 0; j < subSum[sn].Count; j++)
  1556. // // {
  1557. // // if (subSum[sn][j].Equals("0"))
  1558. // // {
  1559. // // subSum[sn].Remove(subSum[sn][j]);
  1560. // // }
  1561. // // }
  1562. // // }
  1563. // // //计算成绩年级排名
  1564. // // AllPoints.Sort(delegate (int s1, int s2) { return s2.CompareTo(s1); });
  1565. // // ipoint = AllPoints[int.Parse(ip)];
  1566. // // int m = 0;
  1567. // // List<List<string>> KeyLine = new List<List<string>>();
  1568. // // foreach (List<double> points in subSum)
  1569. // // {
  1570. // // List<string> detail = new List<string>();
  1571. // // double sum = points.Count;
  1572. // // int l = 0;
  1573. // // for (int mq = 0; mq < points.Count; mq++)
  1574. // // {
  1575. // // if (points[mq] >= ipoint)
  1576. // // {
  1577. // // l++;
  1578. // // }
  1579. // // }
  1580. // // double Lines = l;
  1581. // // detail.Add(Lines.ToString());
  1582. // // detail.Add(points.Count.ToString());
  1583. // // var t3 = Math.Floor(Math.Round(decimal.Parse((Lines / sum).ToString("0.000")), 2) * 100);
  1584. // // detail.Add(t3.ToString());
  1585. // // KeyLine.Add(detail);
  1586. // // m++;
  1587. // // }
  1588. // // AllKeyLine.Add(KeyLine);
  1589. // // }
  1590. // // else {
  1591. // // continue;
  1592. // // }
  1593. // // //年级成就指标
  1594. // // if (weightSum == 0)
  1595. // // {
  1596. // // weightSum = 1;
  1597. // // }
  1598. // // double index = CoreAverage.Sum() / weightSum;
  1599. // // List<List<double>> AveragePoint = new List<List<double>>();
  1600. // // List<List<double>> AverageClassPoint = new List<List<double>>();
  1601. // // //List<double> ClassCore = new List<double>();
  1602. // // int k = AllPoint.Count;
  1603. // // if (k > 0)
  1604. // // {
  1605. // // for (int m = 0; m < AllPoint[0].Count; m++)
  1606. // // {
  1607. // // List<double> SubjectAverage = new List<double>();
  1608. // // for (int n = 0; n < AllPoint[0][m].Count; n++)
  1609. // // {
  1610. // // double startPoint = 0;
  1611. // // for (int f = 0; f < k; f++)
  1612. // // {
  1613. // // startPoint = double.Parse(AllPoint[f][m][n]) + startPoint;
  1614. // // }
  1615. // // SubjectAverage.Add(startPoint / k);
  1616. // // }
  1617. // // AveragePoint.Add(SubjectAverage);
  1618. // // }
  1619. // // }
  1620. // // //每个班级成就指标
  1621. // // int p = AllPointAverage.Count;
  1622. // // if (p > 0)
  1623. // // {
  1624. // // for (int m = 0; m < AllPointAverage[0].Count; m++)
  1625. // // {
  1626. // // List<double> SubjectAverage = new List<double>();
  1627. // // for (int n = 0; n < AllPointAverage[0][m].Count; n++)
  1628. // // {
  1629. // // double startPoint = 0;
  1630. // // for (int f = 0; f < k; f++)
  1631. // // {
  1632. // // startPoint = double.Parse(AllPointAverage[f][m][n]) + startPoint;
  1633. // // }
  1634. // // SubjectAverage.Add(startPoint / k);
  1635. // // }
  1636. // // AverageClassPoint.Add(SubjectAverage);
  1637. // // }
  1638. // // }
  1639. // // int c = AverageClassPoint.Count;
  1640. // // List<double> ClassCore = new List<double>();
  1641. // // if (c > 0)
  1642. // // {
  1643. // // for (int j = 0; j < AverageClassPoint[0].Count; j++)
  1644. // // {
  1645. // // double startAverage = 0;
  1646. // // for (int f = 0; f < c; f++)
  1647. // // {
  1648. // // startAverage = AverageClassPoint[f][j] + startAverage;
  1649. // // }
  1650. // // ClassCore.Add(startAverage / c / weightSum);
  1651. // // }
  1652. // // }
  1653. // // //班级平均进线率
  1654. // // int ExamCount = AllKeyLine.Count;
  1655. // // List<List<double>> KeyLines = new List<List<double>>();
  1656. // // if (ExamCount > 0)
  1657. // // {
  1658. // // for (int m = 0; m < AllKeyLine[0].Count; m++)
  1659. // // {
  1660. // // List<double> ClassLine = new List<double>();
  1661. // // for (int n = 0; n < AllKeyLine[0][m].Count; n++)
  1662. // // {
  1663. // // double startPoint = 0;
  1664. // // for (int f = 0; f < ExamCount; f++)
  1665. // // {
  1666. // // startPoint = double.Parse(AllKeyLine[f][m][n]) + startPoint;
  1667. // // }
  1668. // // ClassLine.Add(startPoint / ExamCount);
  1669. // // }
  1670. // // KeyLines.Add(ClassLine);
  1671. // // }
  1672. // // }
  1673. // // Dictionary<string, object> AveragePointMap = new Dictionary<string, object>
  1674. // // {
  1675. // // { "Period",Period},
  1676. // // { "Grade",Grade},
  1677. // // { "index", index},
  1678. // // { "className", classList },
  1679. // // { "subjectName", subjectList },
  1680. // // { "AveragePoint", AveragePoint },
  1681. // // //{ "AverageClassPoint", AverageClassPoint },
  1682. // // { "ClassCore", ClassCore },
  1683. // // { "KeyLines",KeyLines}
  1684. // // };
  1685. // // map.Add(AveragePointMap);
  1686. // // }
  1687. // // }
  1688. // // //Redis处理结果集
  1689. // // if (RedisHelper.Instance != null)
  1690. // // {
  1691. // // if (!RedisHelper.Exists(CacheCosmosPrefix + method))
  1692. // // {
  1693. // // await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), map);
  1694. // // }
  1695. // // else
  1696. // // {
  1697. // // await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(dict.ToJsonString()), map);
  1698. // // await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
  1699. // // }
  1700. // // }
  1701. // // return map;
  1702. // // }
  1703. // // catch (Exception e)
  1704. // // {
  1705. // // throw new BizException(e.Message);
  1706. // // }
  1707. //}
  1708. //[HttpPost("getAnalysis")]
  1709. //public async Task<IActionResult> getAnalysis(JsonElement request)
  1710. //{
  1711. // //获取评测的ID
  1712. // if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
  1713. // if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
  1714. // try
  1715. // {
  1716. // var client = _azureCosmos.GetCosmosClient();
  1717. // //获取本次评测所有科目结算结果
  1718. // ExamInfo info = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"Exam-{code}"));
  1719. // School school = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(code.ToString(), new PartitionKey($"Base"));
  1720. // List<ExamResult> examResults = new List<ExamResult>();
  1721. // var query = $"select c.id,c.name,c.subjectId,c.studentScores,c.studentIds,c.paper,c.classes from c where c.examId = '{id}' ";
  1722. // await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIteratorSql<ExamResult>(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamResult-{id}") }))
  1723. // {
  1724. // /*using var json = await JsonDocument.ParseAsync(item.Content);
  1725. // if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  1726. // {
  1727. // foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  1728. // {
  1729. // examResults.Add(obj.ToObject<ExamResult>());
  1730. // }
  1731. // }*/
  1732. // examResults.Add(item);
  1733. // }
  1734. // //获取本次评测所有班级作答结果
  1735. // List<ExamClassResult> examClassResults = new List<ExamClassResult>();
  1736. // 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 ";
  1737. // await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIteratorSql<ExamClassResult>(queryText: queryClass, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{code}") }))
  1738. // {
  1739. // examClassResults.Add(item);
  1740. // /*using var json = await JsonDocument.ParseAsync(item.Content);
  1741. // if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  1742. // {
  1743. // foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  1744. // {
  1745. // examClassResults.Add(obj.ToObject<ExamClassResult>());
  1746. // }
  1747. // }*/
  1748. // }
  1749. // //获取进线标准
  1750. // int touch = 0;
  1751. // foreach (Period period in school.period)
  1752. // {
  1753. // if (info.period.id.Equals(period.id))
  1754. // {
  1755. // touch = period.analysis.touch;
  1756. // }
  1757. // }
  1758. // int personCount = (int)System.Math.Round(info.stuCount * (touch / 100.0), MidpointRounding.AwayFromZero);
  1759. // if (info.period.id.Equals(period.id))
  1760. // StudentAnalysis analysis = new StudentAnalysis();
  1761. // List<ClassAnalysis> classAnalyses = new List<ClassAnalysis>();
  1762. // /* //声明年级所有科目总分
  1763. // List<double> total = new List<double>();*/
  1764. // //以班级为单位
  1765. // List<double> stuTotals = new List<double>();
  1766. // List<dynamic> classes = new List<dynamic>();
  1767. // HashSet<string> idName = new HashSet<string>();
  1768. // foreach (ExamResult examResult in examResults)
  1769. // {
  1770. // foreach (string ids in examResult.studentIds)
  1771. // {
  1772. // idName.Add(ids);
  1773. // }
  1774. // }
  1775. // foreach (string s in info.classes)
  1776. // {
  1777. // //存放每个班级学生总分
  1778. // List<double> totalClass = new List<double>();
  1779. // ClassAnalysis classAnalysis = new ClassAnalysis();
  1780. // classAnalysis.classId = s;
  1781. // var sresponse = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(s, new PartitionKey($"Class-{code}"));
  1782. // if (sresponse.StatusCode==System.Net.HttpStatusCode.OK)
  1783. // {
  1784. // using var json = await JsonDocument.ParseAsync(sresponse.Content);
  1785. // Class classroom = json.ToObject<Class>();
  1786. // classes.Add(new { name = classroom.name, id = s });
  1787. // //初始化参考人数
  1788. // int count = 0;
  1789. // //处理班级学生名单
  1790. // List<Student> students = new List<Student>();
  1791. // await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIteratorSql<Student>(queryText: $"select c.id from c where c.classId = '{classroom.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{code}") }))
  1792. // {
  1793. // students.Add(item);
  1794. // }
  1795. // foreach (Student stu in students)
  1796. // {
  1797. // if (idName.Contains(stu.id))
  1798. // {
  1799. // count++;
  1800. // }
  1801. // else
  1802. // {
  1803. // continue;
  1804. // }
  1805. // classAnalysis.studentIds.Add(stu.id);
  1806. // analysis.names.Add(stu.name);
  1807. // analysis.ids.Add(stu.id);
  1808. // //计算学生多科考试成绩总分
  1809. // double stuTotal = 0;
  1810. // foreach (ExamResult examResult in examResults)
  1811. // {
  1812. // int index = examResult.studentIds.IndexOf(stu.id);
  1813. // if (index >= 0)
  1814. // {
  1815. // stuTotal = stuTotal + examResult.studentScores[index].Sum();
  1816. // }
  1817. // }
  1818. // classAnalysis.total.Add(stuTotal);
  1819. // analysis.total.Add(stuTotal);
  1820. // stuTotals.Add(stuTotal);
  1821. // totalClass.Add(stuTotal);
  1822. // //total.Add(stuTotal);
  1823. // }
  1824. // classAnalysis.stuCount = count;
  1825. // }
  1826. // /* //声明单个班级单科总分
  1827. // double subjectTotal = 0;*/
  1828. // info.subjects.ForEach(sub =>
  1829. // {
  1830. // //初始化及格人数
  1831. // int i = 0;
  1832. // //初始化单科总分
  1833. // double sumClass = 0;
  1834. // //记录每个科目数据
  1835. // SubjectScore subjectScore = new SubjectScore();
  1836. // subjectScore.id = sub.id;
  1837. // double subjectSum = 0;
  1838. // double passScore = 0;
  1839. // //计算单科评测总分
  1840. // foreach (ExamResult examResult in examResults)
  1841. // {
  1842. // if (sub.id.Equals(examResult.subjectId))
  1843. // {
  1844. // subjectSum = examResult.paper.point.Sum();
  1845. // }
  1846. // }
  1847. // //单科及格率分数
  1848. // passScore = subjectSum * 0.6;
  1849. // //存放学生单科记录
  1850. // Score score = new Score();
  1851. // score.subjectId = sub.id;
  1852. // List<double> subjectTotal = new List<double>();
  1853. // //处理每个班级各个学生各科总分
  1854. // foreach (ExamClassResult result in examClassResults)
  1855. // {
  1856. // if (sub.id.Equals(result.subjectId) && s.Equals(result.info.id))
  1857. // {
  1858. // foreach (List<double> scores in result.studentScores)
  1859. // {
  1860. // //添加每个学生各科总分
  1861. // score.csc.Add(scores.Sum());
  1862. // //计算大于及格分数的人数
  1863. // if (scores.Sum() >= passScore)
  1864. // {
  1865. // i++;
  1866. // }
  1867. // //totalClass.Add(scores.Sum());
  1868. // subjectTotal.Add(scores.Sum());
  1869. // sumClass = sumClass + scores.Sum();
  1870. // }
  1871. // //处理班级及格率以及均分
  1872. // double percentClass = i / (result.studentIds.Count * 1.0);
  1873. // double averageClass = sumClass / (result.studentIds.Count * 1.0);
  1874. // //total += averageClass;
  1875. // subjectScore.passPercent = percentClass;
  1876. // subjectScore.averageScore = averageClass;
  1877. // classAnalysis.subjects.Add(subjectScore);
  1878. // //analysis.scores.Add(score);
  1879. // }
  1880. // }
  1881. // //处理单科科班级PR
  1882. // subjectTotal.Sort(delegate (double s1, double s2) { return s2.CompareTo(s1); });
  1883. // foreach (double sc in score.csc)
  1884. // {
  1885. // int index = subjectTotal.IndexOf(sc);
  1886. // double CPR = 100 - (100 * (index + 1) - 50) / score.csc.Count;
  1887. // score.cdpr.Add(CPR);
  1888. // {
  1889. // }
  1890. // analysis.scores.Add(score);
  1891. // });
  1892. // //处理全科班级PR
  1893. // totalClass.Sort(delegate (double s1, double s2) { return s2.CompareTo(s1); });
  1894. // foreach (double pr in classAnalysis.total)
  1895. // {
  1896. // int index = totalClass.IndexOf(pr);
  1897. // double CPR = 100 - (100 * (index + 1) - 50) / classAnalysis.total.Count;
  1898. // analysis.cpr.Add(CPR);
  1899. // }
  1900. // classAnalyses.Add(classAnalysis);
  1901. // }
  1902. // /*info.targetClassIds.ForEach( async s => {
  1903. // });*/
  1904. // //初始化进线分数
  1905. // double ipoint = 0;
  1906. // stuTotals.Sort(delegate (double s1, double s2) { return s2.CompareTo(s1); });
  1907. // ipoint = stuTotals[personCount];
  1908. // //补充班级总平均分/进行人数/标准差
  1909. // foreach (ClassAnalysis classAnalysis in classAnalyses)
  1910. // {
  1911. // //初始化进线人数
  1912. // int i = 0;
  1913. // //初始化班级总分
  1914. // double score = 0;
  1915. // //标准差
  1916. // double powSum = 0;
  1917. // foreach (double sc in classAnalysis.total)
  1918. // {
  1919. // if (sc > ipoint)
  1920. // {
  1921. // i++;
  1922. // }
  1923. // score = score + sc;
  1924. // }
  1925. // //总平均分
  1926. // double totalAverage = 0;
  1927. // totalAverage = score / classAnalysis.stuCount;
  1928. // //计算标准差
  1929. // foreach (double sc in classAnalysis.total)
  1930. // {
  1931. // powSum += Math.Pow(sc - totalAverage, 2);
  1932. // }
  1933. // var pow = Math.Pow(powSum / classAnalysis.stuCount, 0.5);
  1934. // classAnalysis.standardDeviation = pow;
  1935. // classAnalysis.totalAverage = totalAverage;
  1936. // classAnalysis.lineCount = i;
  1937. // }
  1938. // //处理全科年级PR值
  1939. // foreach (double no in analysis.total)
  1940. // {
  1941. // int index = stuTotals.IndexOf(no);
  1942. // int GPR = 100 - (100 * (index + 1) - 50) / analysis.total.Count;
  1943. // analysis.gpr.Add(GPR);
  1944. // }
  1945. // List<GradeAnalysis> gradeAnalyses = new List<GradeAnalysis>();
  1946. // List<Dictionary<string, dynamic>> PointAnalysis = new List<Dictionary<string, dynamic>>();
  1947. // List<Dictionary<string, dynamic>> exerciseScatter = new List<Dictionary<string, dynamic>>();
  1948. // List<Dictionary<string, dynamic>> KnowledgePoint = new List<Dictionary<string, dynamic>>();
  1949. // if (info.grades.Count > 0)
  1950. // {
  1951. // gradeAnalyses = GetGradeAnalyses(info, examResults, examClassResults, analysis);
  1952. // PointAnalysis = getPointAnalysis(examResults, info);
  1953. // exerciseScatter = getExerciseScatter(examResults, info);
  1954. // KnowledgePoint = getKnowledgePoint(examResults, info);
  1955. // }
  1956. // return Ok(new { analysis, classAnalyses, gradeAnalyses, PointAnalysis, exerciseScatter, KnowledgePoint });
  1957. // }
  1958. // catch (Exception e)
  1959. // {
  1960. // await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/getAnalysis()\n{e.Message}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
  1961. // return BadRequest();
  1962. // }
  1963. // foreach (double sc in classAnalysis.total)
  1964. // KnowledgePoint = getKnowledgePoint(examResults, info);
  1965. //}
  1966. //private List<GradeAnalysis> GetGradeAnalyses(ExamInfo info, List<ExamResult> examResults, List<ExamClassResult> examClassResults, StudentAnalysis analysis)
  1967. //{
  1968. // List<GradeAnalysis> gradeAnalyses = new List<GradeAnalysis>();
  1969. // info.grades.ForEach(g =>
  1970. // {
  1971. // GradeAnalysis gradeAnalysis = new GradeAnalysis();
  1972. // gradeAnalysis.gradeId = g.id;
  1973. // //初始化单个年级总分
  1974. // double gradeScore = 0;
  1975. // info.subjects.ForEach(sub =>
  1976. // {
  1977. // //初始化及格人数
  1978. // int i = 0;
  1979. // //初始化年级人数
  1980. // int count = 0;
  1981. // //初始化单科总分
  1982. // double sumClass = 0;
  1983. // //记录每个科目数据
  1984. // GradeSubjectScore subjectScore = new GradeSubjectScore();
  1985. // subjectScore.id = sub.id;
  1986. // double subjectSum = 0;
  1987. // double passScore = 0;
  1988. // //计算单科评测总分
  1989. // foreach (ExamResult examResult in examResults)
  1990. // {
  1991. // if (sub.id.Equals(examResult.subjectId))
  1992. // {
  1993. // subjectSum = examResult.paper.point.Sum();
  1994. // }
  1995. // }
  1996. // //单科及格率分数
  1997. // passScore = subjectSum * 0.6;
  1998. // List<double> subjectTotal = new List<double>();
  1999. // //存放单科每个班级学生总分
  2000. // List<double> totalClass = new List<double>();
  2001. // //存放学生单科记录
  2002. // foreach (Score score in analysis.scores)
  2003. // {
  2004. // if (score.subjectId.Equals(sub.id))
  2005. // {
  2006. // //处理每个班级各个学生各科总分
  2007. // foreach (ExamClassResult result in examClassResults)
  2008. // {
  2009. // if (sub.id.Equals(result.subjectId) && g.id.Equals(result.gradeId))
  2010. // {
  2011. // foreach (List<double> scores in result.studentScores)
  2012. // {
  2013. // //添加每个学生各科总分
  2014. // score.gsc.Add(scores.Sum());
  2015. // //计算大于及格分数的人数
  2016. // if (scores.Sum() >= passScore)
  2017. // {
  2018. // i++;
  2019. // }
  2020. // subjectTotal.Add(scores.Sum());
  2021. // sumClass = sumClass + scores.Sum();
  2022. // if (sub.id.Equals(result.subjectId) && g.id.Equals(result.gradeId))
  2023. // }
  2024. // count += result.studentIds.Count;
  2025. // }
  2026. // }
  2027. // //处理班级及格率以及均分
  2028. // double persentClass = i / (count * 1.0);
  2029. // double averageClass = sumClass / (count * 1.0);
  2030. // gradeScore += averageClass;
  2031. // subjectScore.passPercent = persentClass;
  2032. // subjectScore.averageScore = averageClass;
  2033. // gradeAnalysis.subjects.Add(subjectScore);
  2034. // gradeAnalyses.Add(gradeAnalysis);
  2035. // //处理单科科年级PR
  2036. // subjectTotal.Sort(delegate (double s1, double s2) { return s2.CompareTo(s1); });
  2037. // foreach (double sc in score.gsc)
  2038. // {
  2039. // int index = subjectTotal.IndexOf(sc);
  2040. // double GPR = 100 - (100 * (index + 1) - 50) / score.gsc.Count;
  2041. // score.gdpr.Add(GPR);
  2042. // //analysis.gpr.Add(GPR);
  2043. // }
  2044. // //analysis.scores.Add(score);
  2045. // }
  2046. // }
  2047. // });
  2048. // foreach (GradeAnalysis grade in gradeAnalyses)
  2049. // {
  2050. // grade.GradeaverageScore = gradeScore / grade.subjects.Count;
  2051. // }
  2052. // });
  2053. // return gradeAnalyses;
  2054. //}
  2055. //analysis.gpr.Add(GPR);
  2056. // }
  2057. // //落点分析
  2058. // private List<Dictionary<string, dynamic>> getPointAnalysis(List<ExamResult> exams, ExamInfo exam)
  2059. //{
  2060. // List<Dictionary<string, dynamic>> scatterAnalysis = new List<Dictionary<string, dynamic>>();
  2061. // List<string> key = new List<string>
  2062. // {
  2063. // "name",
  2064. // "className",
  2065. // "x",
  2066. // "y",
  2067. // "memberId",
  2068. // "score",
  2069. // "trueNum",
  2070. // "falseNum",
  2071. // "hardList",
  2072. // "carefulList",
  2073. // "scatter"
  2074. // };
  2075. // //key.Add("areaName");
  2076. // if (exams.Count > 0)
  2077. // {
  2078. // /* //提取班级信息
  2079. // List<Dictionary<string, int[]>> classToName = exams[0].classes;
  2080. // //提取学生ID信息
  2081. // List<string> idToName = exams[0].ids;*/
  2082. // exams.ForEach(e =>
  2083. // {
  2084. // Dictionary<string, object> detail = new Dictionary<string, object>
  2085. // {
  2086. // { "keys", key }
  2087. // };
  2088. // List<List<string>> datas = new List<List<string>>();
  2089. // Dictionary<string, object> subject = new Dictionary<string, object>
  2090. // {
  2091. // { "name", e.subjectId }
  2092. // };
  2093. // double[] point = StringHelper.ListTodouble(e.paper.point);
  2094. // double[,] result = StringHelper.ListToDouble(e.studentScores);
  2095. // try
  2096. // {
  2097. // var cdm = new ClouDASMatrix(result, point);
  2098. // //学生通过率
  2099. // List<double> pass = cdm.PassingRate;
  2100. // //学生稳定度
  2101. // List<double> sta = cdm.StabilityRate;
  2102. // //落点区域
  2103. // List<string> stu = cdm.StuFallArea;
  2104. // //需努力的题型
  2105. // List<int[]> strive = cdm.StriveTopic;
  2106. // //需小心的题型
  2107. // List<int[]> careful = cdm.CarefulTopic;
  2108. // int i = 0;
  2109. // for (int k = e.studentIds.Count - 1; k >= 0; k--)
  2110. // {
  2111. // if (e.studentIds[k].Equals("0"))
  2112. // {
  2113. // e.studentIds.Remove(e.studentIds[k]);
  2114. // }
  2115. // }
  2116. // e.studentIds.ForEach(s =>
  2117. // {
  2118. // if (e.studentScores[i].Sum() != 0)
  2119. // {
  2120. // List<string> info = new List<string>
  2121. // {
  2122. // s,
  2123. // "-",
  2124. // sta[i].ToString(),
  2125. // pass[i].ToString(),
  2126. // i + 1 + "",
  2127. // e.studentScores[i].Sum().ToString()
  2128. // };
  2129. // int right = 0;
  2130. // int wrong = 0;
  2131. // foreach (int p in e.studentScores[i])
  2132. // {
  2133. // if (p > 0)
  2134. // {
  2135. // right++;
  2136. // }
  2137. // else
  2138. // {
  2139. // wrong++;
  2140. // }
  2141. // }
  2142. // info.Add(right + "");
  2143. // info.Add(wrong + "");
  2144. // int[] str = strive[i];
  2145. // string striveAll = "";
  2146. // if (p > 0)
  2147. // {
  2148. // right++;
  2149. // }
  2150. // else
  2151. // {
  2152. // wrong++;
  2153. // }
  2154. // }
  2155. // info.Add(right + "");
  2156. // info.Add(wrong + "");
  2157. // int[] str = strive[i];
  2158. // string striveAll = "";
  2159. // foreach (int n in str)
  2160. // {
  2161. // striveAll += n.ToString() + ",";
  2162. // }
  2163. // int[] care = careful[i];
  2164. // string careAll = "";
  2165. // foreach (int n in care)
  2166. // {
  2167. // careAll += n.ToString() + ",";
  2168. // }
  2169. // if (string.IsNullOrEmpty(striveAll))
  2170. // {
  2171. // info.Add("无");
  2172. // }
  2173. // else
  2174. // {
  2175. // info.Add(striveAll.Substring(0, striveAll.Length - 1));
  2176. // }
  2177. // if (string.IsNullOrEmpty(careAll))
  2178. // {
  2179. // info.Add("无");
  2180. // }
  2181. // else
  2182. // {
  2183. // info.Add(careAll.Substring(0, careAll.Length - 1)); ;
  2184. // }
  2185. // info.Add(stu[i].ToString());
  2186. // datas.Add(info);
  2187. // }
  2188. // i++;
  2189. // });
  2190. // });
  2191. //return scatterAnalysis;
  2192. // }
  2193. // else return scatterAnalysis;
  2194. // }
  2195. // catch (Exception ex)
  2196. // private List<Dictionary<string, dynamic>> getExerciseScatter(List<ExamResult> exams, ExamInfo exam)
  2197. //{
  2198. // /* ResponseBuilder builder = ResponseBuilder.custom();*/
  2199. // List<string> classList = new List<string>();
  2200. // List<Dictionary<string, object>> exerciseScatter = new List<Dictionary<string, object>>();
  2201. // //Dictionary<string, object> scatterAnalysis = new Dictionary<string, object>();
  2202. // classList = exam.classes;
  2203. // List<string> key = new List<string>
  2204. // {
  2205. // "id",
  2206. // "type",
  2207. // "areaName",
  2208. // "score",
  2209. // "diff",
  2210. // "identify",
  2211. // "classScoreRate",
  2212. // "gradeScoreRate",
  2213. // "areaScoreRate",
  2214. // "highScoreRate",
  2215. // "lowScoreRate",
  2216. // "knowledgePoint",
  2217. // "R1",
  2218. // "R2",
  2219. // "R3",
  2220. // "R4",
  2221. // "R5",
  2222. // "R6",
  2223. // "PH",
  2224. // "PL",
  2225. // "X",
  2226. // "Y",
  2227. // "knowledge"
  2228. // };
  2229. // if (exams.IsNotEmpty())
  2230. // {
  2231. // exams.ForEach(e =>
  2232. // {
  2233. // List<double> gradeAnswer = new List<double>();
  2234. // List<string> grasdepersent = new List<string>();
  2235. // for (int n = 0; n < e.paper.point.Count; n++)
  2236. // {
  2237. // gradeAnswer.Add(0);
  2238. // }
  2239. // //参考人数
  2240. // double Qnum = 0;
  2241. // e.studentIds.ForEach(i =>
  2242. // {
  2243. // if (!i.Equals("0"))
  2244. // {
  2245. // Qnum++;
  2246. // }
  2247. // });
  2248. // /* Dictionary<string, object> detail = new Dictionary<string, object>
  2249. // {
  2250. // { "keys", key }
  2251. // };*/
  2252. // List<List<string>> datas = new List<List<string>>();
  2253. // List<string[]> itemAnalysis = new List<string[]>();
  2254. // Dictionary<string, object> subject = new Dictionary<string, object>
  2255. // {
  2256. // { "name", e.subjectId }
  2257. // };
  2258. // Dictionary<string, object> classPersent = new Dictionary<string, object>();
  2259. // List<List<string>> classdatas = new List<List<string>>();
  2260. // try
  2261. // {
  2262. // e.classes.ForEach(c =>
  2263. // {
  2264. // //初始化每题得分情况
  2265. // List<int> answerCount = new List<int>();
  2266. // List<string> persent = new List<string>();
  2267. // double peopleCount = 0;
  2268. // for (int n = 0; n < e.paper.point.Count; n++)
  2269. // {
  2270. // answerCount.Add(0);
  2271. // }
  2272. // int qCount = 0;
  2273. // //int right = 0;
  2274. // /* //c.Keys遍历key值
  2275. // foreach (string keys in c.Keys)
  2276. // {
  2277. // classList.Add(keys);
  2278. // }*/
  2279. // //每个班级得分占比
  2280. // double peopleCount = 0;
  2281. // for (int i = c.range[0]; i <= c.range[1]; i++)
  2282. // {
  2283. // if (e.studentScores[i].Sum() > 0)
  2284. // {
  2285. // for (int j = 0; j < e.studentScores[i].Count; j++)
  2286. // {
  2287. // if (e.studentScores[i][j] > 0)
  2288. // {
  2289. // //记录班级每题得分数
  2290. // answerCount[j] = answerCount[j] + 1;
  2291. // //记录年级每题得分数
  2292. // gradeAnswer[j] = gradeAnswer[j] + 1;
  2293. // //right++;
  2294. // }
  2295. // }
  2296. // }
  2297. // else
  2298. // {
  2299. // qCount++;
  2300. // }
  2301. // 记录班级每题得分数
  2302. // peopleCount = c.range[1] - c.range[0] + 1 - qCount;
  2303. // }
  2304. // foreach (int p in answerCount)
  2305. // {
  2306. // var t = Math.Floor(Math.Round(decimal.Parse((p * 1.0 / peopleCount).ToString("0.000")), 2) * 100);
  2307. // persent.Add(t.ToString());
  2308. // }
  2309. // }
  2310. // else
  2311. // {
  2312. // qCount++;
  2313. // }
  2314. // peopleCount = c.range[1] - c.range[0] + 1 - qCount;
  2315. // }
  2316. // double[] point = StringHelper.ListTodouble(e.paper.point);
  2317. // double[,] result = StringHelper.ListToDouble(e.studentScores);
  2318. // var cdm = new ClouDASMatrix(result, point);
  2319. // //试题Y
  2320. // List<double> answer = cdm.AnswerRate;
  2321. // //试题X
  2322. // List<double> quality = cdm.QualityRate;
  2323. // //试题区域
  2324. // List<string> topic = cdm.TopicFallArea;
  2325. // //试题相关分析结果
  2326. // List<(double Diff, double Identify, double R1, double R2, double R3, double R4, double R5, double R6, double RH, double RL)> rs = cdm.RS;
  2327. // for (int i = 0; i < rs.Count; i++)
  2328. // {
  2329. // string[] ex = new string[] { };
  2330. // string ss = rs[i].ToString()[1..^1];
  2331. // ex = ss.Split(",");
  2332. // itemAnalysis.Add(ex);
  2333. // }
  2334. // foreach (int p in gradeAnswer)
  2335. // {
  2336. // var t = Math.Floor(Math.Round(decimal.Parse((p / Qnum).ToString("0.000")), 2) * 100);
  2337. // grasdepersent.Add(t.ToString());
  2338. // }
  2339. // for (int k = 0; k < e.paper.point.Count; k++)
  2340. // {
  2341. // List<string> values = new List<string>();
  2342. // key.ForEach(x =>
  2343. // {
  2344. // values.Add("-");
  2345. // });
  2346. // values[0] = (k + 1).ToString();
  2347. // values[1] = "";
  2348. // values[2] = topic[k].ToString();
  2349. // values[3] = e.paper.point[k].ToString();
  2350. // if (itemAnalysis.Count > 0)
  2351. // {
  2352. // values[4] = itemAnalysis[k][0];
  2353. // values[5] = itemAnalysis[k][1];
  2354. // values[12] = itemAnalysis[k][2];
  2355. // values[13] = itemAnalysis[k][3];
  2356. // values[14] = itemAnalysis[k][4];
  2357. // values[15] = itemAnalysis[k][5];
  2358. // values[16] = itemAnalysis[k][6];
  2359. // values[17] = itemAnalysis[k][7];
  2360. // values[18] = itemAnalysis[k][8];
  2361. // values[19] = itemAnalysis[k][9];
  2362. // }
  2363. // else
  2364. // {
  2365. // values[4] = "-";
  2366. // values[5] = "-";
  2367. // values[12] = "-";
  2368. // values[13] = "-";
  2369. // values[14] = "-";
  2370. // values[15] = "-";
  2371. // values[16] = "-";
  2372. // values[17] = "-";
  2373. // values[18] = "-";
  2374. // values[19] = "-";
  2375. // }
  2376. // values[7] = grasdepersent[k];
  2377. // values[8] = grasdepersent[k];
  2378. // values[20] = quality[k].ToString();
  2379. // values[21] = answer[k].ToString();
  2380. // string pointName = "";
  2381. // /*if (paper[0].item[k].points.Count == 1)
  2382. // {
  2383. // foreach (string index in paper[0].item[k].points)
  2384. // {
  2385. // pointName = index;
  2386. // }
  2387. // }
  2388. // else if (paper[0].item[k].points.Count > 1)
  2389. // {
  2390. // foreach (string index in paper[0].item[k].points)
  2391. // {
  2392. // pointName += index + ",";
  2393. // }
  2394. // }*/
  2395. // values[22] = pointName;
  2396. // datas.Add(values);
  2397. // {
  2398. // pointName = index;
  2399. // }
  2400. // }
  2401. // else if (paper[0].item[k].points.Count > 1)
  2402. // {
  2403. // foreach (string index in paper[0].item[k].points)
  2404. // {
  2405. // pointName += index + ",";
  2406. // }
  2407. // }
  2408. // */
  2409. // values[22] = pointName;
  2410. // datas.Add(values);
  2411. // });
  2412. // return exerciseScatter;
  2413. // }
  2414. // else return exerciseScatter;
  2415. //}
  2416. //[HttpPost("answer")]
  2417. //public async Task<IActionResult> answer(JsonElement request)
  2418. //{
  2419. // //获取评测的ID
  2420. // if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
  2421. // if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
  2422. // try
  2423. // {
  2424. // var client = _azureCosmos.GetCosmosClient();
  2425. // //获取本次评测所有科目结算结果
  2426. // ExamInfo info = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"Exam-{code}"));
  2427. // School school = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(code.ToString(), new PartitionKey($"Base"));
  2428. // List<ExamResult> examResults = new List<ExamResult>();
  2429. // var query = $"select c.id,c.name,c.subjectId,c.studentScores,c.studentIds,c.paper,c.classes from c where c.examId = '{id}' ";
  2430. // await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIteratorSql<ExamResult>(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamResult-{id}") }))
  2431. // {
  2432. // /*using var json = await JsonDocument.ParseAsync(item.Content);
  2433. // if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  2434. // {
  2435. // foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  2436. // {
  2437. // examResults.Add(obj.ToObject<ExamResult>());
  2438. // }
  2439. // }*/
  2440. // examResults.Add(item);
  2441. // }
  2442. // //获取本次评测所有班级作答结果
  2443. // List<ExamClassResult> examClassResults = new List<ExamClassResult>();
  2444. // 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}' ";
  2445. // await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIteratorSql<ExamClassResult>(queryText: queryClass, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{code}") }))
  2446. // {
  2447. // examClassResults.Add(item);
  2448. // /*using var json = await JsonDocument.ParseAsync(item.Content);
  2449. // if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  2450. // {
  2451. // foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  2452. // {
  2453. // examClassResults.Add(obj.ToObject<ExamClassResult>());
  2454. // }
  2455. // }*/
  2456. // }
  2457. // int m = 0;
  2458. // foreach (ExamSubject subject in info.subjects)
  2459. // {
  2460. // foreach (ExamClassResult classResult in examClassResults)
  2461. // {
  2462. // if (subject.id.Equals(classResult.subjectId))
  2463. // {
  2464. // int k = 0;
  2465. // foreach (string stu in classResult.studentIds)
  2466. // {
  2467. // if (classResult.studentAnswers[k].Count > 0)
  2468. // {
  2469. // k++;
  2470. // continue;
  2471. // }
  2472. // int n = 0;
  2473. // List<List<string>> ans = new List<List<string>>();
  2474. // foreach (List<string> simple in info.papers[m].answers)
  2475. // {
  2476. // List<string> option = new List<string>();
  2477. // if (simple.Count > 0)
  2478. // {
  2479. // List<string> opt = new List<string> { "A", "B", "C", "D" };
  2480. // int rd = new Random().Next(0, 3);
  2481. // if (rd == 1 || rd == 2)
  2482. // {
  2483. // option.AddRange(simple);
  2484. // classResult.studentScores[k][n] = info.papers[m].point[n];
  2485. // }
  2486. // else
  2487. // {
  2488. // simple.ForEach(x => { opt.Remove(x); });
  2489. // option.Add(opt[new Random().Next(0, opt.Count - 1)]);
  2490. // classResult.studentScores[k][n] = 0;
  2491. // }
  2492. // ans.Add(option);
  2493. // }
  2494. // else
  2495. // {
  2496. // //classResult.studentScores[k][n] = new Random().Next(0, (int)info.papers[m].point[n]) * 1.0;
  2497. // ans.Add(new List<string> { "测试作答数据一", "测试作答数据二" });
  2498. // }
  2499. // n++;
  2500. // }
  2501. // /* StringBuilder builder = new StringBuilder();
  2502. // builder.Append(classResult.examId + "/");
  2503. // builder.Append(classResult.subjectId + "/");
  2504. // builder.Append(stu + "/");
  2505. // builder.Append("ans.json");*/
  2506. // string FileName = classResult.examId + "/" + classResult.subjectId + "/" + stu;
  2507. // string blob = FileName + "/" + "ans.json";
  2508. // await _azureStorage.UploadFileByContainer(code.ToString(), ans.ToJsonString(), "exam", FileName + "/" + "ans.json");
  2509. // classResult.studentAnswers[k].Add(blob);
  2510. // classResult.sum[k] = classResult.studentScores[k].Sum();
  2511. // k++;
  2512. // }
  2513. // //await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new PartitionKey($"ExamClassResult-{code}"));
  2514. // if (!classResult.progress)
  2515. // {
  2516. // bool flag = true;
  2517. // foreach (List<double> scores in classResult.studentScores)
  2518. // {
  2519. // foreach (double score in scores)
  2520. // {
  2521. // if (score == -1)
  2522. // {
  2523. // flag = false;
  2524. // break;
  2525. // }
  2526. // }
  2527. // }
  2528. // if (flag)
  2529. // {
  2530. // classResult.progress = true;
  2531. // info.subjects[m].classCount += 1;
  2532. // }
  2533. // }
  2534. // await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new PartitionKey($"ExamClassResult-{code}"));
  2535. // }
  2536. // }
  2537. // m++;
  2538. // }
  2539. // await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(info, id.ToString(), new PartitionKey($"Exam-{code}"));
  2540. // return Ok(new { examClassResults });
  2541. // }
  2542. // catch (Exception e)
  2543. // {
  2544. // await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/answer()\n{e.Message}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
  2545. // return BadRequest();
  2546. // }
  2547. //}
  2548. //[HttpPost("scoring")]
  2549. //public async Task<IActionResult> Scoring(JsonElement request)
  2550. //{
  2551. // //获取评测的ID
  2552. // if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
  2553. // if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
  2554. // try
  2555. // {
  2556. // var client = _azureCosmos.GetCosmosClient();
  2557. // //获取本次评测所有科目结算结果
  2558. // ExamInfo info = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"Exam-{code}"));
  2559. // School school = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(code.ToString(), new PartitionKey($"Base"));
  2560. // List<ExamResult> examResults = new List<ExamResult>();
  2561. // var query = $"select c.id,c.name,c.subjectId,c.studentScores,c.studentIds,c.paper,c.classes from c where c.examId = '{id}' ";
  2562. // await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIteratorSql<ExamResult>(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamResult-{id}") }))
  2563. // {
  2564. // examResults.Add(item);
  2565. // }
  2566. // //获取本次评测所有班级作答结果
  2567. // List<ExamClassResult> examClassResults = new List<ExamClassResult>();
  2568. // 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}' ";
  2569. // await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIteratorSql<ExamClassResult>(queryText: queryClass, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{code}") }))
  2570. // {
  2571. // examClassResults.Add(item);
  2572. // }
  2573. // int m = 0;
  2574. // foreach (ExamSubject subject in info.subjects)
  2575. // {
  2576. // foreach (ExamClassResult classResult in examClassResults)
  2577. // {
  2578. // if (subject.id.Equals(classResult.subjectId))
  2579. // {
  2580. // int k = 0;
  2581. // foreach (string stu in classResult.studentIds)
  2582. // {
  2583. // int n = 0;
  2584. // List<List<string>> ans = new List<List<string>>();
  2585. // foreach (List<string> simple in info.papers[m].answers)
  2586. // {
  2587. // List<string> option = new List<string>();
  2588. // if (simple.Count == 0)
  2589. // {
  2590. // classResult.studentScores[k][n] = new Random().Next(0, (int)info.papers[m].point[n]) * 1.0;
  2591. // }
  2592. // n++;
  2593. // }
  2594. // classResult.sum[k] = classResult.studentScores[k].Sum();
  2595. // k++;
  2596. // }
  2597. // if (!classResult.progress)
  2598. // {
  2599. // bool flag = true;
  2600. // foreach (List<double> scores in classResult.studentScores)
  2601. // {
  2602. // foreach (double score in scores)
  2603. // {
  2604. // if (score == -1)
  2605. // {
  2606. // flag = false;
  2607. // break;
  2608. // }
  2609. // }
  2610. // }
  2611. // if (flag)
  2612. // {
  2613. // classResult.progress = true;
  2614. // info.subjects[m].classCount += 1;
  2615. // }
  2616. // }
  2617. // else
  2618. // {
  2619. // info.updateTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  2620. // }
  2621. // await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new PartitionKey($"ExamClassResult-{code}"));
  2622. // }
  2623. // }
  2624. // m++;
  2625. // }
  2626. // await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(info, id.ToString(), new PartitionKey($"Exam-{code}"));
  2627. // return Ok(new { examClassResults });
  2628. // }
  2629. // catch (Exception e)
  2630. // {
  2631. // await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/scoring()\n{e.Message}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
  2632. // return BadRequest();
  2633. // }
  2634. //}
  2635. //[HttpPost("import")]
  2636. //public async Task<IActionResult> importIES3(JsonElement request)
  2637. //{
  2638. // //获取评测的ID
  2639. // if (!request.TryGetProperty("exam", out JsonElement exam)) return BadRequest();
  2640. // //if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
  2641. // try
  2642. // {
  2643. // var client = _azureCosmos.GetCosmosClient();
  2644. // ExamDto examDtos = new ExamDto();
  2645. // examDtos = exam.ToObject<ExamDto>();
  2646. // ExamInfo info = new ExamInfo();
  2647. // info.code = info.pk + "-hbcn";
  2648. // info.progress = "pending";
  2649. // info.id = examDtos.id;
  2650. // info.name = examDtos.name;
  2651. // info.grades = examDtos.grades;
  2652. // info.subjects = examDtos.subjects;
  2653. // info.period = examDtos.period;
  2654. // examDtos.targetClasses.ForEach(e =>
  2655. // {
  2656. // info.classes.Add(e.id);
  2657. // });
  2658. // examDtos.papers.ForEach(p =>
  2659. // {
  2660. // PaperSimple simple = new PaperSimple();
  2661. // simple.id = p.id;
  2662. // simple.name = p.name;
  2663. // p.points.ForEach(po =>
  2664. // {
  2665. // simple.point.Add(double.Parse(po));
  2666. // });
  2667. // p.answers.ForEach(an =>
  2668. // {
  2669. // List<string> ans = new List<string>();
  2670. // if (an.Length > 1)
  2671. // {
  2672. // char[] aa = an.ToCharArray();
  2673. // foreach (char a in aa)
  2674. // {
  2675. // switch (a)
  2676. // {
  2677. // case '1':
  2678. // ans.Add("A");
  2679. // break;
  2680. // case '2':
  2681. // ans.Add("B");
  2682. // break;
  2683. // case '3':
  2684. // ans.Add("C");
  2685. // break;
  2686. // case '4':
  2687. // ans.Add("D");
  2688. // break;
  2689. // default:
  2690. // ans.Add("");
  2691. // break;
  2692. // }
  2693. // }
  2694. // }
  2695. // else
  2696. // {
  2697. // switch (an)
  2698. // {
  2699. // case "1":
  2700. // ans.Add("A");
  2701. // break;
  2702. // case "2":
  2703. // ans.Add("B");
  2704. // break;
  2705. // case "3":
  2706. // ans.Add("C");
  2707. // break;
  2708. // case "4":
  2709. // ans.Add("D");
  2710. // break;
  2711. // default:
  2712. // ans.Add("");
  2713. // break;
  2714. // }
  2715. // }
  2716. // simple.answers.Add(ans);
  2717. // });
  2718. // info.papers.Add(simple);
  2719. // });
  2720. // await client.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync(info, new PartitionKey("Exam-hbcn"));
  2721. // return Ok(new { info });
  2722. // }
  2723. // catch (Exception e)
  2724. // {
  2725. // await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/scoring()\n{e.Message}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
  2726. // return BadRequest();
  2727. // }
  2728. //}
  2729. //[HttpPost("importResult")]
  2730. //public async Task<IActionResult> importClassResult(JsonElement request)
  2731. //{
  2732. // //获取评测的ID
  2733. // if (!request.TryGetProperty("classResult", out JsonElement classResult)) return BadRequest();
  2734. // if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
  2735. // try
  2736. // {
  2737. // var client = _azureCosmos.GetCosmosClient();
  2738. // List<ExamClassResultDto> examClassResultDto = new List<ExamClassResultDto>();
  2739. // examClassResultDto = classResult.ToObject<List<ExamClassResultDto>>();
  2740. // //获取本次评测所有班级作答结果
  2741. // List<ExamClassResult> examClassResults = new List<ExamClassResult>();
  2742. // var queryClass = $"select value(c) from c where c.examId = '{id}'";
  2743. // await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIteratorSql<ExamClassResult>(queryText: queryClass, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("ExamClassResult-hbcn") }))
  2744. // {
  2745. // examClassResults.Add(item);
  2746. // }
  2747. // foreach (ExamClassResultDto e in examClassResultDto)
  2748. // {
  2749. // foreach (ExamClassResult ex in examClassResults)
  2750. // {
  2751. // if (e.subject.Equals(ex.subjectId))
  2752. // {
  2753. // foreach (ClassResults examClass in e.examClassResult)
  2754. // {
  2755. // if (examClass.classInfo.id.Equals(ex.info.id))
  2756. // {
  2757. // ex.studentIds = examClass.studentIds;
  2758. // List<List<double>> newScores = new List<List<double>>();
  2759. // examClass.studentScores.ForEach(sc =>
  2760. // {
  2761. // List<double> scores = new List<double>();
  2762. // if (sc.Count == 0)
  2763. // {
  2764. // for (int i = 0; i < ex.studentScores[0].Count; i++)
  2765. // {
  2766. // scores.Add(0);
  2767. // }
  2768. // }
  2769. // else
  2770. // {
  2771. // sc.ForEach(s =>
  2772. // {
  2773. // scores.Add(double.Parse(s));
  2774. // });
  2775. // }
  2776. // newScores.Add(scores);
  2777. // });
  2778. // ex.studentScores = newScores;
  2779. // int index = 0;
  2780. // List<Task<string>> tasks = new List<Task<string>>();
  2781. // List<List<string>> answers = new List<List<string>>();
  2782. // foreach (List<string> an in examClass.studentAnswers)
  2783. // {
  2784. // //List<List<string>> stuAns = new List<List<string>>();
  2785. // an.ForEach(aa =>
  2786. // {
  2787. // List<string> ans = new List<string>();
  2788. // if (aa.Length > 1)
  2789. // {
  2790. // char[] str = aa.ToCharArray();
  2791. // foreach (char a in aa)
  2792. // {
  2793. // switch (a)
  2794. // {
  2795. // case '1':
  2796. // ans.Add("A");
  2797. // break;
  2798. // case '2':
  2799. // ans.Add("B");
  2800. // break;
  2801. // case '3':
  2802. // ans.Add("C");
  2803. // break;
  2804. // case '4':
  2805. // ans.Add("D");
  2806. // break;
  2807. // default:
  2808. // ans.Add("");
  2809. // break;
  2810. // }
  2811. // answers.Add(ans);
  2812. // }
  2813. // }
  2814. // else
  2815. // {
  2816. // switch (aa)
  2817. // {
  2818. // case "1":
  2819. // ans.Add("A");
  2820. // break;
  2821. // case "2":
  2822. // ans.Add("B");
  2823. // break;
  2824. // case "3":
  2825. // ans.Add("C");
  2826. // break;
  2827. // case "4":
  2828. // ans.Add("D");
  2829. // break;
  2830. // default:
  2831. // ans.Add("");
  2832. // break;
  2833. // }
  2834. // answers.Add(ans);
  2835. // }
  2836. // //answers.Add(stuAns);
  2837. // });
  2838. // string FileName = ex.examId + "/" + ex.subjectId + "/" + examClass.studentIds[index];
  2839. // string blob = FileName + "/" + "ans.json";
  2840. // tasks.Add(_azureStorage.UploadFileByContainer(ex.school.ToString(), answers.ToJsonString(), "exam", FileName + "/" + "ans.json"));
  2841. // ex.studentAnswers[index].Add(blob);
  2842. // index++;
  2843. // }
  2844. // await Task.WhenAll(tasks);
  2845. // }
  2846. // }
  2847. // }
  2848. // }
  2849. // }
  2850. // foreach (ExamClassResult result in examClassResults)
  2851. // {
  2852. // result.progress = true;
  2853. // await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(result, result.id, new PartitionKey($"{result.code}"));
  2854. // }
  2855. // return Ok(new { examClassResults });
  2856. // }
  2857. // catch (Exception e)
  2858. // {
  2859. // await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/importResult()\n{e.Message}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
  2860. // return BadRequest();
  2861. // }
  2862. //}
  2863. //private List<Dictionary<string, dynamic>> getKnowledgePoint(List<ExamResult> examResults, ExamInfo info)
  2864. //{
  2865. // Dictionary<string, object> stuMap = new Dictionary<string, object>
  2866. // {
  2867. // { "schoolCode", "Habook" }
  2868. // };
  2869. // List<Dictionary<string, object>> keyValues = new List<Dictionary<string, object>>();
  2870. // HashSet<string> knowledge = new HashSet<string>();
  2871. // HashSet<string> area = new HashSet<string>();
  2872. // List<double> point = new List<double>();
  2873. // List<List<double>> result = new List<List<double>>();
  2874. // List<ClassRange> classes = new List<ClassRange>();
  2875. // List<string> ids = new List<string>();
  2876. // examResults.ForEach(e =>
  2877. // {
  2878. // //定位试卷信息
  2879. // int index = 0;
  2880. // foreach (ExamSubject subject in info.subjects)
  2881. // {
  2882. // if (subject.id.Equals(e.subjectId))
  2883. // {
  2884. // break;
  2885. // }
  2886. // else
  2887. // {
  2888. // index++;
  2889. // }
  2890. // }
  2891. // info.papers[index].knowledge.ForEach(k =>
  2892. // {
  2893. // k.ForEach(e =>
  2894. // {
  2895. // knowledge.Add(e);
  2896. // });
  2897. // });
  2898. // info.papers[index].field.ForEach(f =>
  2899. // {
  2900. // area.Add(f.ToString());
  2901. // });
  2902. // double Qnum = 0;
  2903. // point = info.papers[index].point;
  2904. // result = e.studentScores;
  2905. // classes = e.classes;
  2906. // ids = e.studentIds;
  2907. // //确定高分组 低分组人数
  2908. // List<List<double>> re = e.studentScores;
  2909. // List<double> resultSum = new List<double>();
  2910. // foreach (List<double> data in re)
  2911. // {
  2912. // resultSum.Add(data.Sum());
  2913. // }
  2914. // //确定高分组 最低分数
  2915. // resultSum.Sort(delegate (double s1, double s2) { return s2.CompareTo(s1); });
  2916. // for (int i = resultSum.Count - 1; i >= 0; i--)
  2917. // {
  2918. // if (resultSum[i] == 0)
  2919. // {
  2920. // resultSum.Remove(resultSum[i]);
  2921. // }
  2922. // }
  2923. // double rhwCount = resultSum.Count * 0.27;
  2924. // double rhw = resultSum[int.Parse(rhwCount.ToString("0"))];
  2925. // //确定低分组 最高分数
  2926. // resultSum.Sort(delegate (double s1, double s2) { return s1.CompareTo(s2); });
  2927. // double rhlCount = resultSum.Count * 0.27;
  2928. // double rhl = resultSum[int.Parse(rhwCount.ToString("0"))];
  2929. // List<string> knowledgeName = new List<string>();
  2930. // foreach (string cla in knowledge)
  2931. // {
  2932. // knowledgeName.Add(cla);
  2933. // }
  2934. // for (int k = 0; k < knowledgeName.Count; k++)
  2935. // {
  2936. // if (null == knowledgeName[k])
  2937. // {
  2938. // knowledgeName.Remove(knowledgeName[k]);
  2939. // }
  2940. // }
  2941. // List<string> areaName = new List<string>();
  2942. // foreach (string cla in area)
  2943. // {
  2944. // areaName.Add(cla);
  2945. // }
  2946. // for (int k = 0; k < areaName.Count; k++)
  2947. // {
  2948. // if (null == areaName[k])
  2949. // {
  2950. // areaName.Remove(areaName[k]);
  2951. // }
  2952. // }
  2953. // //初始化年级总分
  2954. // double total = 0;
  2955. // //处理年级单个知识点得分率
  2956. // foreach (List<double> grade in result)
  2957. // {
  2958. // total += grade.Sum();
  2959. // }
  2960. // foreach (string id in ids)
  2961. // {
  2962. // if (!id.Equals("0"))
  2963. // {
  2964. // Qnum++;
  2965. // }
  2966. // }
  2967. // //试卷总分
  2968. // double TotalPoint = point.Sum();
  2969. // //计算认知层次占比
  2970. // List<string> fper = new List<string>();
  2971. // for (int a = 0; a < areaName.Count; a++)
  2972. // {
  2973. // double fieldPoint = 0;
  2974. // int no = 0;
  2975. // info.papers[index].field.ForEach(f =>
  2976. // {
  2977. // if (f.ToString().Equals(areaName[a], StringComparison.OrdinalIgnoreCase))
  2978. // {
  2979. // e.studentScores.ForEach(s =>
  2980. // {
  2981. // fieldPoint += s[no];
  2982. // });
  2983. // }
  2984. // no++;
  2985. // });
  2986. // double fieldPersent = fieldPoint / TotalPoint;
  2987. // fper.Add(fieldPersent.ToString("0.00"));
  2988. // }
  2989. // //求单个知识点所占分数
  2990. // List<string> per = new List<string>();
  2991. // List<string> gper = new List<string>();
  2992. // List<string> knowPer = new List<string>();
  2993. // List<Dictionary<string, double>> eper = new List<Dictionary<string, double>>();
  2994. // Dictionary<string, object> knowledgeALL = new Dictionary<string, object>();
  2995. // Dictionary<string, object> knowledgeMap = new Dictionary<string, object>();
  2996. // Dictionary<string, object> classMap = new Dictionary<string, object>();
  2997. // Dictionary<string, object> wrongMap = new Dictionary<string, object>();
  2998. // HashSet<string> className = new HashSet<string>();
  2999. // List<List<string>> wrongPersent = new List<List<string>>();
  3000. // List<string> key = new List<string>
  3001. // {
  3002. // "id",
  3003. // "className",
  3004. // "seatNO",
  3005. // "point",
  3006. // "anwPoint",
  3007. // "persent"
  3008. // };
  3009. // List<string> keyWrong = new List<string>
  3010. // {
  3011. // "name",
  3012. // "point",
  3013. // "itemNO",
  3014. // "persent",
  3015. // "wrong",
  3016. // "rhw",
  3017. // "rlw"
  3018. // };
  3019. // for (int k = 0; k < knowledgeName.Count; k++)
  3020. // {
  3021. // List<string> knowledgeClass = new List<string>();
  3022. // List<List<string>> stuPersent = new List<List<string>>();
  3023. // double OnePoint = 0;
  3024. // //获取每个知识点占有多少分值
  3025. // double ePoint = 0;
  3026. // double anwGPoint = 0;
  3027. // double poG = 0;
  3028. // int m = 0;
  3029. // List<string> valuew = new List<string>();
  3030. // List<string> itemNo = new List<string>();
  3031. // keyWrong.ForEach(x =>
  3032. // {
  3033. // valuew.Add("-");
  3034. // });
  3035. // int wrongCount = 0;
  3036. // valuew[0] = knowledgeName[k];
  3037. // int n = 0;
  3038. // info.papers[index].knowledge.ForEach(kno =>
  3039. // {
  3040. // if (kno.Contains(knowledgeName[k]))
  3041. // {
  3042. // OnePoint += point[n];
  3043. // itemNo.Add((n + 1).ToString());
  3044. // }
  3045. // valuew[1] = OnePoint.ToString();
  3046. // string itemNos = "";
  3047. // if (itemNo.Count > 0)
  3048. // {
  3049. // foreach (string np in itemNo)
  3050. // {
  3051. // itemNos += np + ",";
  3052. // }
  3053. // valuew[2] = itemNos[0..^1];
  3054. // }
  3055. // else
  3056. // {
  3057. // valuew[2] = itemNos;
  3058. // }
  3059. // n++;
  3060. // });
  3061. // int rhwC = 0;
  3062. // int rhlC = 0;
  3063. // foreach (string id in ids)
  3064. // {
  3065. // if (id.Equals("0") || result[m].Sum() == 0)
  3066. // {
  3067. // m++;
  3068. // continue;
  3069. // }
  3070. // List<string> values = new List<string>();
  3071. // key.ForEach(x =>
  3072. // {
  3073. // values.Add("-");
  3074. // });
  3075. // /* foreach (OldStudent info in students)
  3076. // {
  3077. // if (info.studentId.Equals(id))
  3078. // {
  3079. // values[2] = info.seatNo.ToString();
  3080. // break;
  3081. // }
  3082. // }*/
  3083. // //List<string> stu = new List<string>();
  3084. // values[0] = id;
  3085. // values[1] = "-";
  3086. // //List<List<string>> stuItem = new List<List<string>>();
  3087. // int statuCount = 0;
  3088. // info.papers[index].knowledge.ForEach(kno =>
  3089. // {
  3090. // int sno = 0;
  3091. // double anwPoint = 0;
  3092. // double po = 0;
  3093. // if (kno.Contains(knowledgeName[k]))
  3094. // {
  3095. // //当前认知层次在该题占比多少
  3096. // ePoint = 1;
  3097. // anwPoint += result[m][sno] * ePoint;
  3098. // //所有学生单个认知层次得分情况
  3099. // anwGPoint += result[m][sno] * ePoint;
  3100. // po += point[sno] * ePoint;
  3101. // //认知层次所占分数
  3102. // poG += point[sno] * ePoint;
  3103. // if (result[m][sno] == 0 && statuCount == 0)
  3104. // {
  3105. // statuCount++;
  3106. // wrongCount++;
  3107. // if (result[m].Sum() >= rhw)
  3108. // {
  3109. // rhwC++;
  3110. // }
  3111. // if (result[m].Sum() <= rhl)
  3112. // {
  3113. // rhlC++;
  3114. // }
  3115. // }
  3116. // if (po == 0)
  3117. // {
  3118. // values[3] = "0";
  3119. // values[4] = "0";
  3120. // values[5] = "0";
  3121. // }
  3122. // else
  3123. // {
  3124. // double stuPser = anwPoint / po;
  3125. // values[3] = po.ToString();
  3126. // values[4] = anwPoint.ToString();
  3127. // values[5] = stuPser.ToString("0.00");
  3128. // }
  3129. // }
  3130. // });
  3131. // stuPersent.Add(values);
  3132. // m++;
  3133. // }
  3134. // //AchievementService.ReName(stuPersent, ids, classes, students);
  3135. // double knowPser = 0;
  3136. // if (poG == 0)
  3137. // {
  3138. // knowPer.Add("0");
  3139. // }
  3140. // else
  3141. // {
  3142. // knowPser = anwGPoint / poG;
  3143. // knowPer.Add(knowPser.ToString("0.00"));
  3144. // }
  3145. // //错题关系表
  3146. // valuew[3] = knowPser.ToString("0.00");
  3147. // valuew[4] = wrongCount.ToString();
  3148. // valuew[5] = rhwC.ToString();
  3149. // valuew[6] = rhlC.ToString();
  3150. // wrongPersent.Add(valuew);
  3151. // knowledgeMap.Add(knowledgeName[k], stuPersent);
  3152. // //知识点占比
  3153. // double persent = OnePoint / TotalPoint;
  3154. // foreach (ClassRange classRange in e.classes)
  3155. // {
  3156. // List<string> classPoints = new List<string>();
  3157. // //初始化班级得分
  3158. // double anwCPoint = 0;
  3159. // double cpo = 0;
  3160. // for (int stuIndex = classRange.range[0]; stuIndex < classRange.range[1]; stuIndex++)
  3161. // {
  3162. // if (result[stuIndex].Sum() == 0) continue;
  3163. // info.papers[index].knowledge.ForEach(kno =>
  3164. // {
  3165. // int x = 0;
  3166. // if (kno.Contains(knowledgeName[k]))
  3167. // {
  3168. // //当前认知层次在该题占比多少
  3169. // ePoint = 1;
  3170. // anwCPoint += result[stuIndex][x] * ePoint;
  3171. // cpo += point[x] * ePoint;
  3172. // }
  3173. // });
  3174. // }
  3175. // if (cpo == 0)
  3176. // {
  3177. // //double classPser = anwCPoint / cpo;
  3178. // knowledgeClass.Add("0");
  3179. // }
  3180. // else
  3181. // {
  3182. // double classPser = anwCPoint / cpo;
  3183. // knowledgeClass.Add(classPser.ToString("0.00"));
  3184. // }
  3185. // }
  3186. // classMap.Add(knowledgeName[k], knowledgeClass);
  3187. // per.Add(persent.ToString("0.00"));
  3188. // }
  3189. // knowledgeMap.Add("grade", knowPer);
  3190. // knowledgeMap.Add("keys", key);
  3191. // classMap.Add("className", className);
  3192. // wrongMap.Add("keys", keyWrong);
  3193. // wrongMap.Add("datas", wrongPersent);
  3194. // knowledgeALL.Add("pointList", knowledgeName);
  3195. // knowledgeALL.Add("per", per);
  3196. // knowledgeALL.Add("level", areaName);
  3197. // knowledgeALL.Add("fper", fper);
  3198. // knowledgeALL.Add("stupercent", knowledgeMap);
  3199. // knowledgeALL.Add("classpercent", classMap);
  3200. // knowledgeALL.Add("wrong", wrongMap);
  3201. // keyValues.Add(knowledgeALL);
  3202. // });
  3203. // return keyValues;
  3204. //}
  3205. //}
  3206. //}
  3207. // knowledgeALL.Add("pointList", knowledgeName);
  3208. //knowledgeALL.Add("per", per);
  3209. //knowledgeALL.Add("level", areaName);
  3210. //knowledgeALL.Add("fper", fper);
  3211. //knowledgeALL.Add("stupercent", knowledgeMap);
  3212. //knowledgeALL.Add("classpercent", classMap);
  3213. //knowledgeALL.Add("wrong", wrongMap);
  3214. //keyValues.Add(knowledgeALL);
  3215. // });
  3216. //return keyValues;
  3217. // }
  3218. // [HttpPost("answer")]
  3219. //public async Task<IActionResult> answer(JsonElement request)
  3220. //{
  3221. // 获取评测的ID
  3222. // if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
  3223. // if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
  3224. // try
  3225. // {
  3226. // var client = _azureCosmos.GetCosmosClient();
  3227. // 获取本次评测所有科目结算结果
  3228. // ExamInfo info = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"Exam-{code}"));
  3229. // School school = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(code.ToString(), new PartitionKey($"Base"));
  3230. // List<ExamResult> examResults = new List<ExamResult>();
  3231. // var query = $"select c.id,c.name,c.subjectId,c.studentScores,c.studentIds,c.paper,c.classes from c where c.examId = '{id}' ";
  3232. // await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIteratorSql<ExamResult>(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamResult-{id}") }))
  3233. // {
  3234. // /*using var json = await JsonDocument.ParseAsync(item.Content);
  3235. // if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  3236. // {
  3237. // foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  3238. // {
  3239. // examResults.Add(obj.ToObject<ExamResult>());
  3240. // }
  3241. // }*/
  3242. // examResults.Add(item);
  3243. // }
  3244. // 获取本次评测所有班级作答结果
  3245. // List<ExamClassResult> examClassResults = new List<ExamClassResult>();
  3246. // 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}' ";
  3247. // await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIteratorSql<ExamClassResult>(queryText: queryClass, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{code}") }))
  3248. // {
  3249. // examClassResults.Add(item);
  3250. // /*using var json = await JsonDocument.ParseAsync(item.Content);
  3251. // if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  3252. // {
  3253. // foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  3254. // {
  3255. // examClassResults.Add(obj.ToObject<ExamClassResult>());
  3256. // }
  3257. // }*/
  3258. // }
  3259. // int m = 0;
  3260. // foreach (ExamSubject subject in info.subjects)
  3261. // {
  3262. // foreach (ExamClassResult classResult in examClassResults)
  3263. // {
  3264. // if (subject.id.Equals(classResult.subjectId))
  3265. // {
  3266. // int k = 0;
  3267. // foreach (string stu in classResult.studentIds)
  3268. // {
  3269. // if (classResult.studentAnswers[k].Count > 0)
  3270. // {
  3271. // k++;
  3272. // continue;
  3273. // }
  3274. // int n = 0;
  3275. // List<List<string>> ans = new List<List<string>>();
  3276. // foreach (List<string> simple in info.papers[m].answers)
  3277. // {
  3278. // List<string> option = new List<string>();
  3279. // if (simple.Count > 0)
  3280. // {
  3281. // List<string> opt = new List<string> { "A", "B", "C", "D" };
  3282. // int rd = new Random().Next(0, 3);
  3283. // if (rd == 1 || rd == 2)
  3284. // {
  3285. // option.AddRange(simple);
  3286. // classResult.studentScores[k][n] = info.papers[m].point[n];
  3287. // }
  3288. // else
  3289. // {
  3290. // simple.ForEach(x => { opt.Remove(x); });
  3291. // option.Add(opt[new Random().Next(0, opt.Count - 1)]);
  3292. // classResult.studentScores[k][n] = 0;
  3293. // }
  3294. // ans.Add(option);
  3295. // }
  3296. // else
  3297. // {
  3298. // classResult.studentScores[k][n] = new Random().Next(0, (int)info.papers[m].point[n]) * 1.0;
  3299. // ans.Add(new List<string> { "测试作答数据一", "测试作答数据二" });
  3300. // }
  3301. // n++;
  3302. // }
  3303. // /* StringBuilder builder = new StringBuilder();
  3304. // builder.Append(classResult.examId + "/");
  3305. // builder.Append(classResult.subjectId + "/");
  3306. // builder.Append(stu + "/");
  3307. // builder.Append("ans.json");*/
  3308. // string FileName = classResult.examId + "/" + classResult.subjectId + "/" + stu;
  3309. // string blob = FileName + "/" + "ans.json";
  3310. // await _azureStorage.UploadFileByContainer(code.ToString(), ans.ToJsonString(), "exam", FileName + "/" + "ans.json");
  3311. // classResult.studentAnswers[k].Add(blob);
  3312. // classResult.sum[k] = classResult.studentScores[k].Sum();
  3313. // k++;
  3314. // }
  3315. // await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new PartitionKey($"ExamClassResult-{code}"));
  3316. // if (!classResult.progress)
  3317. // {
  3318. // bool flag = true;
  3319. // foreach (List<double> scores in classResult.studentScores)
  3320. // {
  3321. // foreach (double score in scores)
  3322. // {
  3323. // if (score == -1)
  3324. // {
  3325. // flag = false;
  3326. // break;
  3327. // }
  3328. // }
  3329. // }
  3330. // if (flag)
  3331. // {
  3332. // classResult.progress = true;
  3333. // info.subjects[m].classCount += 1;
  3334. // }
  3335. // }
  3336. // await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new PartitionKey($"ExamClassResult-{code}"));
  3337. // }
  3338. // }
  3339. // m++;
  3340. // }
  3341. // await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(info, id.ToString(), new PartitionKey($"Exam-{code}"));
  3342. // return Ok(new { examClassResults });
  3343. // }
  3344. // catch (Exception e)
  3345. // {
  3346. // await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/answer()\n{e.Message}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
  3347. // return BadRequest();
  3348. // }
  3349. //}
  3350. //[HttpPost("scoring")]
  3351. //public async Task<IActionResult> Scoring(JsonElement request)
  3352. //{
  3353. // 获取评测的ID
  3354. // if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
  3355. // if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
  3356. // try
  3357. // {
  3358. // var client = _azureCosmos.GetCosmosClient();
  3359. // 获取本次评测所有科目结算结果
  3360. // ExamInfo info = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"Exam-{code}"));
  3361. // School school = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(code.ToString(), new PartitionKey($"Base"));
  3362. // List<ExamResult> examResults = new List<ExamResult>();
  3363. // var query = $"select c.id,c.name,c.subjectId,c.studentScores,c.studentIds,c.paper,c.classes from c where c.examId = '{id}' ";
  3364. // await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIteratorSql<ExamResult>(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamResult-{id}") }))
  3365. // {
  3366. // examResults.Add(item);
  3367. // }
  3368. // 获取本次评测所有班级作答结果
  3369. // List<ExamClassResult> examClassResults = new List<ExamClassResult>();
  3370. // 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}' ";
  3371. // await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIteratorSql<ExamClassResult>(queryText: queryClass, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{code}") }))
  3372. // {
  3373. // examClassResults.Add(item);
  3374. // }
  3375. // int m = 0;
  3376. // foreach (ExamSubject subject in info.subjects)
  3377. // {
  3378. // foreach (ExamClassResult classResult in examClassResults)
  3379. // {
  3380. // if (subject.id.Equals(classResult.subjectId))
  3381. // {
  3382. // int k = 0;
  3383. // foreach (string stu in classResult.studentIds)
  3384. // {
  3385. // int n = 0;
  3386. // List<List<string>> ans = new List<List<string>>();
  3387. // foreach (List<string> simple in info.papers[m].answers)
  3388. // {
  3389. // List<string> option = new List<string>();
  3390. // if (simple.Count == 0)
  3391. // {
  3392. // classResult.studentScores[k][n] = new Random().Next(0, (int)info.papers[m].point[n]) * 1.0;
  3393. // }
  3394. // n++;
  3395. // }
  3396. // classResult.sum[k] = classResult.studentScores[k].Sum();
  3397. // k++;
  3398. // }
  3399. // if (!classResult.progress)
  3400. // {
  3401. // bool flag = true;
  3402. // foreach (List<double> scores in classResult.studentScores)
  3403. // {
  3404. // foreach (double score in scores)
  3405. // {
  3406. // if (score == -1)
  3407. // {
  3408. // flag = false;
  3409. // break;
  3410. // }
  3411. // }
  3412. // }
  3413. // if (flag)
  3414. // {
  3415. // classResult.progress = true;
  3416. // info.subjects[m].classCount += 1;
  3417. // }
  3418. // }
  3419. // else
  3420. // {
  3421. // info.updateTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  3422. // }
  3423. // await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new PartitionKey($"ExamClassResult-{code}"));
  3424. // }
  3425. // }
  3426. // m++;
  3427. // }
  3428. // await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(info, id.ToString(), new PartitionKey($"Exam-{code}"));
  3429. // return Ok(new { examClassResults });
  3430. // }
  3431. // catch (Exception e)
  3432. // {
  3433. // await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/scoring()\n{e.Message}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
  3434. // return BadRequest();
  3435. // }
  3436. //}
  3437. [HttpPost("import")]
  3438. public async Task<IActionResult> importIES3(JsonElement request)
  3439. {
  3440. //获取评测的ID
  3441. if (!request.TryGetProperty("exam", out JsonElement exam)) return BadRequest();
  3442. if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
  3443. if (!request.TryGetProperty("classResult", out JsonElement classResult)) return BadRequest();
  3444. //if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
  3445. try
  3446. {
  3447. var client = _azureCosmos.GetCosmosClient();
  3448. ExamDto examDtos = new ExamDto();
  3449. examDtos = exam.ToObject<ExamDto>();
  3450. ExamInfo info = new ExamInfo();
  3451. info.code = info.pk + "-" + code;
  3452. info.progress = "finish";
  3453. info.id = Guid.NewGuid().ToString();
  3454. info.name = examDtos.name;
  3455. info.grades = examDtos.grades;
  3456. info.subjects = examDtos.subjects;
  3457. info.period = examDtos.period;
  3458. examDtos.targetClasses.ForEach(e =>
  3459. {
  3460. info.classes.Add(e);
  3461. });
  3462. info.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  3463. info.startTime = examDtos.startTime;
  3464. info.endTime = examDtos.endTime;
  3465. info.school = code.GetString();
  3466. info.type = examDtos.type;
  3467. info.scope = "school";
  3468. info.examType = examDtos.examType;
  3469. await client.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync(info, new PartitionKey($"Exam-{code}"));
  3470. return Ok(new { info });
  3471. }
  3472. catch (Exception e)
  3473. {
  3474. await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/import()\n{e.Message}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
  3475. return BadRequest();
  3476. }
  3477. }
  3478. public class FileDto
  3479. {
  3480. public string periodId { get; set; }
  3481. public string code { get; set; }
  3482. public string name { get; set; }
  3483. public int multipleRule { get; set; }
  3484. public string examId { get; set; }
  3485. public string subjectId { get; set; }
  3486. public List<string> gradeIds { get; set; }
  3487. public IFormFile file { get; set; }
  3488. }
  3489. [HttpPost("parse-word")]
  3490. public async Task<IActionResult> ParseWord([FromForm] FileDto fileDto)
  3491. {
  3492. if (!FileType.GetExtention(fileDto.file.FileName).ToLower().Equals("docx"))
  3493. {
  3494. return BadRequest(new Dictionary<string, object> { { "msg", "type is not docx!" }, { "code", ResponseCode.FAILED } });
  3495. }
  3496. try
  3497. {
  3498. var client = _azureCosmos.GetCosmosClient();
  3499. var response = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemStreamAsync(fileDto.examId, new PartitionKey($"Exam-{fileDto.code}"));
  3500. ExamInfo examInfo;
  3501. if (response.StatusCode == System.Net.HttpStatusCode.OK)
  3502. {
  3503. using var json = await JsonDocument.ParseAsync(response.Content);
  3504. examInfo = json.ToObject<ExamInfo>();
  3505. }
  3506. else
  3507. {
  3508. return Ok(new { error = 404, msg = "请先导入评测信息" });
  3509. }
  3510. foreach (PaperSimple paper in examInfo.papers)
  3511. {
  3512. if (paper.id.Contains(fileDto.subjectId))
  3513. {
  3514. return Ok(new { error = 500, msg = "该试卷信息已存在" });
  3515. }
  3516. }
  3517. PaperSimple simple = new();
  3518. var doc = _DOXC2HTMLTranslator.Translate(fileDto.file.OpenReadStream());
  3519. (List<HTEXLib.DOCX.Models.ItemInfo> tests, List<string> error) = _HTML2ITEMV3Translator.Translate(doc);
  3520. List<Task<string>> tasks = new List<Task<string>>();
  3521. PaperDto paperDto = new()
  3522. {
  3523. id = Guid.NewGuid().ToString(),
  3524. name = fileDto.name,
  3525. code = fileDto.code,
  3526. scope = "school",
  3527. multipleRule = fileDto.multipleRule,
  3528. gradeIds = fileDto.gradeIds,
  3529. subjectId = fileDto.subjectId,
  3530. periodId = fileDto.periodId
  3531. };
  3532. foreach (HTEXLib.DOCX.Models.ItemInfo item in tests)
  3533. {
  3534. Slides slides = new();
  3535. ItemDto dto = new();
  3536. TEAMModelOS.SDK.Models.Scoring scoring = new();
  3537. dto.id = Guid.NewGuid().ToString();
  3538. dto.exercise.answer = item.answer;
  3539. dto.exercise.explain = item.explain;
  3540. dto.exercise.type = item.type;
  3541. dto.exercise.opts = item.option.Count;
  3542. dto.exercise.knowledge = item.knowledge;
  3543. dto.exercise.field = item.field;
  3544. dto.exercise.level = item.level;
  3545. dto.exercise.subjectId = fileDto.subjectId;
  3546. dto.exercise.periodId = fileDto.periodId;
  3547. dto.exercise.gradeIds = fileDto.gradeIds;
  3548. slides.url = dto.id + ".json";
  3549. slides.type = dto.exercise.type;
  3550. scoring.ans = dto.exercise.answer;
  3551. scoring.score = dto.exercise.score;
  3552. scoring.knowledge = dto.exercise.knowledge;
  3553. scoring.field = dto.exercise.field;
  3554. slides.scoring = scoring;
  3555. //添加试卷信息
  3556. paperDto.slides.Add(slides);
  3557. if (!slides.type.Equals("compose"))
  3558. {
  3559. simple.point.Add(dto.exercise.score);
  3560. simple.answers.Add(dto.exercise.answer);
  3561. simple.knowledge.Add(dto.exercise.knowledge);
  3562. simple.type.Add(dto.exercise.type);
  3563. simple.field.Add((int)dto.exercise.field);
  3564. }
  3565. if (item.children.Count > 0)
  3566. {
  3567. foreach (HTEXLib.DOCX.Models.ItemInfo its in item.children)
  3568. {
  3569. Slides cslides = new();
  3570. TEAMModelOS.SDK.Models.Scoring cscoring = new();
  3571. ItemDto dtoChildren = new ItemDto();
  3572. dtoChildren.id = Guid.NewGuid().ToString();
  3573. dtoChildren.pid = dto.id;
  3574. dtoChildren.exercise.answer = its.answer;
  3575. dtoChildren.exercise.explain = its.explain;
  3576. dtoChildren.exercise.type = its.type;
  3577. dtoChildren.exercise.opts = its.option.Count;
  3578. dtoChildren.exercise.knowledge = its.knowledge;
  3579. dtoChildren.exercise.field = its.field;
  3580. dtoChildren.exercise.level = its.level;
  3581. dtoChildren.exercise.scope = "school";
  3582. dtoChildren.exercise.score = its.score;
  3583. dtoChildren.exercise.subjectId = fileDto.subjectId;
  3584. dtoChildren.exercise.periodId = fileDto.periodId;
  3585. dtoChildren.exercise.gradeIds = fileDto.gradeIds;
  3586. dtoChildren.exercise.children.Add(dtoChildren.id);
  3587. info info1 = new();
  3588. info1.uid = dtoChildren.id;
  3589. info1.question = its.question;
  3590. info1.option = JsonSerializer.Deserialize<List<TEAMModelOS.Models.Dto.CodeValue>>(its.option.ToJsonString());
  3591. dtoChildren.item.Add(info1);
  3592. dto.exercise.children.Add(dtoChildren.id);
  3593. //处理子题的slides
  3594. cslides.url = dtoChildren.id + ".json";
  3595. cslides.type = dtoChildren.exercise.type;
  3596. cscoring.ans = dtoChildren.exercise.answer;
  3597. cscoring.score = dtoChildren.exercise.score;
  3598. cscoring.knowledge = dtoChildren.exercise.knowledge;
  3599. cscoring.field = dtoChildren.exercise.field;
  3600. cslides.scoring = scoring;
  3601. paperDto.slides.Add(cslides);
  3602. //添加试卷信息
  3603. simple.point.Add(dtoChildren.exercise.score);
  3604. simple.answers.Add(dto.exercise.answer);
  3605. simple.knowledge.Add(dto.exercise.knowledge);
  3606. simple.type.Add(dto.exercise.type);
  3607. simple.field.Add((int)dto.exercise.field);
  3608. StringBuilder stringBuilder = new StringBuilder();
  3609. stringBuilder.Append(fileDto.examId).Append("/");
  3610. stringBuilder.Append("paper").Append("/");
  3611. stringBuilder.Append(fileDto.subjectId).Append("/");
  3612. stringBuilder.Append(dtoChildren.id + ".json");
  3613. tasks.Add(_azureStorage.GetBlobContainerClient(fileDto.code).UploadFileByContainer(dtoChildren.ToJsonString(), "exam", stringBuilder.ToString(), false));
  3614. }
  3615. }
  3616. info @info = new();
  3617. @info.uid = dto.id;
  3618. @info.question = item.question;
  3619. @info.option = JsonSerializer.Deserialize<List<TEAMModelOS.Models.Dto. CodeValue>>(item.option.ToJsonString());
  3620. dto.item.Add(@info);
  3621. dto.exercise.scope = "school";
  3622. dto.exercise.score = item.score;
  3623. StringBuilder builder = new StringBuilder();
  3624. builder.Append(fileDto.examId).Append('/');
  3625. builder.Append("paper").Append('/');
  3626. builder.Append(fileDto.subjectId).Append('/');
  3627. builder.Append(dto.id + ".json");
  3628. tasks.Add(_azureStorage.GetBlobContainerClient(fileDto.code).UploadFileByContainer(dto.ToJsonString(), "exam", builder.ToString(), false));
  3629. }
  3630. StringBuilder paperBuilder = new StringBuilder();
  3631. paperBuilder.Append(fileDto.examId).Append('/');
  3632. paperBuilder.Append("paper").Append('/');
  3633. paperBuilder.Append(fileDto.subjectId).Append('/');
  3634. paperBuilder.Append("index.json");
  3635. tasks.Add(_azureStorage.GetBlobContainerClient(fileDto.code).UploadFileByContainer(paperDto.ToJsonString(), "exam", paperBuilder.ToString(), false));
  3636. //开始给ExamInfo paper赋值
  3637. simple.id = fileDto.subjectId;
  3638. simple.code = "Paper-" + fileDto.code;
  3639. simple.name = fileDto.name;
  3640. simple.blob = paperBuilder.ToString().Replace("index.json", "");
  3641. simple.scope = "school";
  3642. simple.multipleRule = fileDto.multipleRule;
  3643. examInfo.papers.Add(simple);
  3644. await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(examInfo, examInfo.id, new PartitionKey($"{examInfo.code}"));
  3645. await Task.WhenAll(tasks);
  3646. return Ok(new { code = 200 });
  3647. }
  3648. catch (Exception e)
  3649. {
  3650. await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/word()\n{e.Message}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
  3651. return BadRequest();
  3652. }
  3653. }
  3654. [HttpPost("importResult")]
  3655. [RequestSizeLimit(100_000_000)]//最大允许100M
  3656. public async Task<IActionResult> importClassResult(JsonElement request)
  3657. {
  3658. //获取评测的ID
  3659. if (!request.TryGetProperty("classResult", out JsonElement classResult)) return BadRequest();
  3660. if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
  3661. if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
  3662. try
  3663. {
  3664. var client = _azureCosmos.GetCosmosClient();
  3665. List<ExamClassResultDto> examClassResultDto = new List<ExamClassResultDto>();
  3666. examClassResultDto = classResult.ToObject<List<ExamClassResultDto>>();
  3667. //获取本次评测所有班级作答结果
  3668. List<ExamClassResult> examClassResults = new List<ExamClassResult>();
  3669. var queryClass = $"select value(c) from c where c.examId = '{id}'";
  3670. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIteratorSql<ExamClassResult>(queryText: queryClass, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{code}") }))
  3671. {
  3672. examClassResults.Add(item);
  3673. }
  3674. ExamInfo info = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"Exam-{code}"));
  3675. if (info == null)
  3676. {
  3677. return Ok(new { code = 404, msg = "请先录入评测数据" });
  3678. }
  3679. else
  3680. {
  3681. foreach (ExamClassResultDto e in examClassResultDto)
  3682. {
  3683. int no = 0;
  3684. foreach (ExamSubject sub in info.subjects)
  3685. {
  3686. if (!sub.id.Equals(e.subject))
  3687. {
  3688. no++;
  3689. }
  3690. }
  3691. //获取标准答案
  3692. List<List<string>> standard = new();
  3693. standard = info.papers[no].answers;
  3694. foreach (ExamClassResult ex in examClassResults)
  3695. {
  3696. if (e.subject.Equals(ex.subjectId))
  3697. {
  3698. foreach (ClassResults examClass in e.examClassResult)
  3699. {
  3700. if (examClass.classInfo.id.Equals(ex.info.id))
  3701. {
  3702. ex.studentIds = examClass.studentIds;
  3703. List<List<double>> newScores = new List<List<double>>();
  3704. examClass.studentScores.ForEach(sc =>
  3705. {
  3706. List<double> scores = new List<double>();
  3707. if (sc.Count == 0)
  3708. {
  3709. for (int i = 0; i < ex.studentScores[0].Count; i++)
  3710. {
  3711. scores.Add(0);
  3712. }
  3713. }
  3714. else
  3715. {
  3716. sc.ForEach(s =>
  3717. {
  3718. scores.Add(s);
  3719. });
  3720. }
  3721. newScores.Add(scores);
  3722. });
  3723. ex.studentScores = newScores;
  3724. int index = 0;
  3725. List<Task<string>> tasks = new List<Task<string>>();
  3726. foreach (List<string> an in examClass.studentAnswers)
  3727. {
  3728. List<List<string>> answers = new List<List<string>>();
  3729. //存放客观题答案
  3730. List<List<string>> objective = new List<List<string>>();
  3731. int index_item = 0;
  3732. an.ForEach(aa =>
  3733. {
  3734. List<string> ans = new List<string>();
  3735. List<string> oans = new List<string>();
  3736. //判断此题是否为主观题作答
  3737. if (standard[index_item].Count == 0)
  3738. {
  3739. ans.Add(aa);
  3740. oans.Add("");
  3741. answers.Add(ans);
  3742. objective.Add(oans);
  3743. }
  3744. else
  3745. {
  3746. if (aa.Length > 1)
  3747. {
  3748. char[] str = aa.ToCharArray();
  3749. foreach (char a in aa)
  3750. {
  3751. ans.Add(a.ToString());
  3752. oans.Add(a.ToString());
  3753. }
  3754. objective.Add(oans);
  3755. answers.Add(ans);
  3756. }
  3757. else
  3758. {
  3759. ans.Add(aa);
  3760. oans.Add(aa);
  3761. objective.Add(oans);
  3762. answers.Add(ans);
  3763. }
  3764. }
  3765. index_item++;
  3766. //answers.Add(stuAns);
  3767. });
  3768. ex.ans[index] = objective;
  3769. string FileName = ex.examId + "/" + ex.subjectId + "/" + examClass.studentIds[index];
  3770. string blob = FileName + "/" + "ans.json";
  3771. tasks.Add(_azureStorage.GetBlobContainerClient(ex.school.ToString()).UploadFileByContainer(answers.ToJsonString(), "exam", FileName + "/" + "ans.json"));
  3772. ex.studentAnswers[index].Clear();
  3773. ex.studentAnswers[index].Add(blob);
  3774. index++;
  3775. }
  3776. await Task.WhenAll(tasks);
  3777. }
  3778. }
  3779. }
  3780. }
  3781. }
  3782. }
  3783. foreach (ExamClassResult result in examClassResults)
  3784. {
  3785. result.progress = true;
  3786. await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(result, result.id, new PartitionKey($"{result.code}"));
  3787. }
  3788. return Ok(new { examClassResults });
  3789. }
  3790. catch (Exception e)
  3791. {
  3792. await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/importResult()\n", GroupNames.醍摩豆服務運維群組);
  3793. return BadRequest();
  3794. }
  3795. }
  3796. //获取学校简易基础信息
  3797. [HttpPost("getSchoolInfo")]
  3798. public async Task<IActionResult> getInfoSchool(JsonElement request)
  3799. {
  3800. if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
  3801. try
  3802. {
  3803. var client = _azureCosmos.GetCosmosClient();
  3804. List<object> info = new List<object>();
  3805. var query = $"select c.period,c.id,c.campuses from c where c.id = '{code}'";
  3806. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIteratorSql(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
  3807. {
  3808. using var json = await JsonDocument.ParseAsync(item.Content);
  3809. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  3810. {
  3811. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  3812. {
  3813. info.Add(obj.ToObject<object>());
  3814. }
  3815. }
  3816. }
  3817. return Ok(new { info });
  3818. }
  3819. catch (Exception e)
  3820. {
  3821. await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/getSchoolInfo()\n{e.Message}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
  3822. return BadRequest();
  3823. }
  3824. }
  3825. //获取学校某学段班级信息
  3826. [HttpPost("getClassInfo")]
  3827. public async Task<IActionResult> getClassInfo(JsonElement request)
  3828. {
  3829. if (!request.TryGetProperty("periodId", out JsonElement periodId)) return BadRequest();
  3830. if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
  3831. try
  3832. {
  3833. var client = _azureCosmos.GetCosmosClient();
  3834. List<object> classInfo = new List<object>();
  3835. var query = $"select c.id,c.name from c where c.periodId = '{periodId}'";
  3836. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIteratorSql(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Class-{code}") }))
  3837. {
  3838. using var json = await JsonDocument.ParseAsync(item.Content);
  3839. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  3840. {
  3841. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  3842. {
  3843. classInfo.Add(obj.ToObject<object>());
  3844. }
  3845. }
  3846. }
  3847. return Ok(new { classInfo });
  3848. }
  3849. catch (Exception e)
  3850. {
  3851. await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/getClassInfo()\n{e.Message}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
  3852. return BadRequest();
  3853. }
  3854. }
  3855. //获取学校某学段班级信息
  3856. [HttpPost("getClass")]
  3857. public async Task<IActionResult> getClass(JsonElement request)
  3858. {
  3859. if (!request.TryGetProperty("periodId", out JsonElement periodId)) return BadRequest();
  3860. if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
  3861. try
  3862. {
  3863. var client = _azureCosmos.GetCosmosClient();
  3864. List<Class> classInfo = new List<Class>();
  3865. School school = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(code.ToString(), new PartitionKey("Base"));
  3866. var query = $"select value(c) from c where c.periodId = '{periodId}'";
  3867. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIteratorSql<Class>(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Class-{code}") }))
  3868. {
  3869. classInfo.Add(item);
  3870. }
  3871. foreach (Class @class in classInfo)
  3872. {
  3873. foreach (Period period in school.period)
  3874. {
  3875. if (period.id.Equals(@class.periodId))
  3876. {
  3877. //switch (period.name)
  3878. //{
  3879. // case "小学":
  3880. // foreach (Grade grade in period.grades)
  3881. // {
  3882. // if (@class.gradeId.Equals(grade.id))
  3883. // {
  3884. // switch (grade.name)
  3885. // {
  3886. // case "一年级":
  3887. // @class.year = DateTimeOffset.UtcNow.Year - 1;
  3888. // break;
  3889. // case "二年级":
  3890. // @class.year = DateTimeOffset.UtcNow.Year - 2;
  3891. // break;
  3892. // case "三年级":
  3893. // @class.year = DateTimeOffset.UtcNow.Year - 3;
  3894. // break;
  3895. // case "四年级":
  3896. // @class.year = DateTimeOffset.UtcNow.Year - 4;
  3897. // break;
  3898. // case "五年级":
  3899. // @class.year = DateTimeOffset.UtcNow.Year - 5;
  3900. // break;
  3901. // case "六年级":
  3902. // @class.year = DateTimeOffset.UtcNow.Year - 6;
  3903. // break;
  3904. // }
  3905. // }
  3906. // }
  3907. // break;
  3908. // case "初中":
  3909. // foreach (Grade grade in period.grades)
  3910. // {
  3911. // if (@class.gradeId.Equals(grade.id))
  3912. // {
  3913. // switch (grade.name)
  3914. // {
  3915. // case "七年级":
  3916. // @class.year = DateTimeOffset.UtcNow.Year - 1;
  3917. // break;
  3918. // case "八年级":
  3919. // @class.year = DateTimeOffset.UtcNow.Year - 2;
  3920. // break;
  3921. // case "九年级":
  3922. // @class.year = DateTimeOffset.UtcNow.Year - 3;
  3923. // break;
  3924. // }
  3925. // }
  3926. // }
  3927. // break;
  3928. // case "高中":
  3929. // foreach (Grade grade in period.grades)
  3930. // {
  3931. // if (@class.gradeId.Equals(grade.id))
  3932. // {
  3933. // switch (grade.name)
  3934. // {
  3935. // case "十年级":
  3936. // @class.year = DateTimeOffset.UtcNow.Year - 1;
  3937. // break;
  3938. // case "十一年级":
  3939. // @class.year = DateTimeOffset.UtcNow.Year - 2;
  3940. // break;
  3941. // case "十二年级":
  3942. // @class.year = DateTimeOffset.UtcNow.Year - 3;
  3943. // break;
  3944. // default:
  3945. // @class.year = DateTimeOffset.UtcNow.Year;
  3946. // break;
  3947. // }
  3948. // }
  3949. // }
  3950. // break;
  3951. //}
  3952. }
  3953. }
  3954. }
  3955. return Ok(new { classInfo });
  3956. }
  3957. catch (Exception e)
  3958. {
  3959. await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/getClassInfo()\n{e.Message}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
  3960. return BadRequest();
  3961. }
  3962. }
  3963. [HttpPost("import-exam")]
  3964. public async Task<IActionResult> importExam(JsonElement request)
  3965. {
  3966. //获取评测的ID
  3967. if (!request.TryGetProperty("exam", out JsonElement exam)) return BadRequest();
  3968. if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
  3969. try
  3970. {
  3971. var client = _azureCosmos.GetCosmosClient();
  3972. ExamInfo info = exam.ToObject<ExamInfo>();
  3973. info.progress = "going";
  3974. await client.GetContainer(Constant.TEAMModelOS, "Common").UpsertItemAsync(info, new PartitionKey($"Exam-{code}"));
  3975. return Ok(new { info });
  3976. }
  3977. catch (Exception e)
  3978. {
  3979. await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/import-exam()\n{e.Message}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
  3980. return BadRequest();
  3981. }
  3982. }
  3983. [HttpPost("import-result")]
  3984. public async Task<IActionResult> importResult(JsonElement request)
  3985. {
  3986. //获取评测的ID
  3987. if (!request.TryGetProperty("classResult", out JsonElement classResult)) return BadRequest();
  3988. if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
  3989. if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
  3990. try
  3991. {
  3992. var client = _azureCosmos.GetCosmosClient();
  3993. List<ExamClassResultDto> examClassResultDto = new();
  3994. examClassResultDto = classResult.ToObject<List<ExamClassResultDto>>();
  3995. //获取本次评测所有班级作答结果
  3996. List<ExamClassResult> examClassResults = new();
  3997. var queryClass = $"select value(c) from c where c.examId = '{id}'";
  3998. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIteratorSql<ExamClassResult>(queryText: queryClass, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{code}") }))
  3999. {
  4000. examClassResults.Add(item);
  4001. }
  4002. try
  4003. {
  4004. ExamInfo info = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"Exam-{code}"));
  4005. }
  4006. catch (Exception)
  4007. {
  4008. return Ok(new { code = 404, msg = "请先检查该评测数据" });
  4009. }
  4010. List<Task<ItemResponse<ExamClassResult>>> tasks = new();
  4011. foreach (ExamClassResultDto e in examClassResultDto)
  4012. {
  4013. foreach (ExamClassResult ex in examClassResults)
  4014. {
  4015. if (e.subject.Equals(ex.subjectId))
  4016. {
  4017. foreach (ClassResults examClass in e.examClassResult)
  4018. {
  4019. if (examClass.classInfo.id.Equals(ex.info.id))
  4020. {
  4021. ex.studentIds = examClass.studentIds;
  4022. //ex.studentScores = examClass.studentScores;
  4023. ex.studentAnswers = examClass.studentAnswers;
  4024. ex.ans = examClass.ans;
  4025. }
  4026. }
  4027. tasks.Add(client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(ex, ex.id, new PartitionKey($"{ex.code}")));
  4028. }
  4029. }
  4030. }
  4031. await Task.WhenAll(tasks);
  4032. return Ok(new { examClassResults });
  4033. }
  4034. catch (Exception e)
  4035. {
  4036. await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/import-result()\n", GroupNames.醍摩豆服務運維群組);
  4037. return BadRequest();
  4038. }
  4039. }
  4040. //查询名单
  4041. [ProducesDefaultResponseType]
  4042. //[AuthToken(Roles = "teacher")]
  4043. [HttpPost("set-no-list")]
  4044. public async Task<IActionResult> setNo()
  4045. {
  4046. try
  4047. {
  4048. var client = _azureCosmos.GetCosmosClient();
  4049. List<GroupList> stuSchool = new List<GroupList>();
  4050. List<GroupList> stuTeacher = new List<GroupList>();
  4051. var query = $"select value(c) from c where c.pk = 'GroupList'";
  4052. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIteratorSql<GroupList>(queryText: query))
  4053. {
  4054. stuSchool.Add(item);
  4055. }
  4056. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIteratorSql<GroupList>(queryText: query))
  4057. {
  4058. stuTeacher.Add(item);
  4059. }
  4060. foreach (GroupList stu in stuSchool)
  4061. {
  4062. if (string.IsNullOrEmpty(stu.no))
  4063. {
  4064. string channelnum = $"{_option.LocationNum}{Utils.CreatSaltString(6, "123456789")}";
  4065. stu.no = channelnum;
  4066. }
  4067. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync(stu, stu.id);
  4068. }
  4069. foreach (GroupList stu in stuTeacher)
  4070. {
  4071. if (string.IsNullOrEmpty(stu.no))
  4072. {
  4073. string channelnum = $"{_option.LocationNum}{Utils.CreatSaltString(6, "123456789")}";
  4074. stu.no = channelnum;
  4075. }
  4076. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync(stu, stu.id);
  4077. }
  4078. return Ok(new { code = 200 });
  4079. }
  4080. catch (Exception ex)
  4081. {
  4082. await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/setNo()\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
  4083. return BadRequest();
  4084. }
  4085. }
  4086. [ProducesDefaultResponseType]
  4087. [HttpPost("upsert-record")]
  4088. public async Task<IActionResult> upsertRecord(JsonElement request)
  4089. {
  4090. if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
  4091. if (!request.TryGetProperty("students", out JsonElement students)) return BadRequest();
  4092. if (!request.TryGetProperty("subjectId", out JsonElement subjectId)) return BadRequest();
  4093. //根据不同评测的类型返回对应的编码
  4094. if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
  4095. try
  4096. {
  4097. var client = _azureCosmos.GetCosmosClient();
  4098. //List<string> ids = students.ToObject<List<string>>();
  4099. List<students> stus = students.ToObject<List<students>>();
  4100. ExamInfo info = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(id.GetString(), new PartitionKey($"Exam-{code}"));
  4101. string classCode = info.scope.Equals("school") ? info.school : info.creatorId;
  4102. List<ExamClassResult> examClassResults = new();
  4103. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIteratorSql<ExamClassResult>(
  4104. queryText: $"select value(c) from c where c.examId = '{id}' and c.subjectId = '{subjectId}'",
  4105. requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{classCode}") }))
  4106. {
  4107. examClassResults.Add(item);
  4108. }
  4109. int n = 0;
  4110. foreach (ExamSubject subject in info.subjects)
  4111. {
  4112. if (!subject.id.Equals(subjectId.GetString()))
  4113. {
  4114. n++;
  4115. }
  4116. else {
  4117. break;
  4118. }
  4119. }
  4120. //获取试卷信息
  4121. PaperSimple standerAnswers = new PaperSimple();
  4122. List<List<string>> standard = new List<List<string>>();
  4123. List<double> points = new List<double>();
  4124. standerAnswers = info.papers[n];
  4125. standard = standerAnswers.answers;
  4126. points = standerAnswers.point;
  4127. int rule = standerAnswers.multipleRule;
  4128. List<string> value = new List<string>() ;
  4129. await foreach (var s in stuTask(stus, examClassResults, standard, points, rule, info, subjectId.GetString(), client)) {
  4130. if (s.code == 1) {
  4131. value.Add(s.value);
  4132. }
  4133. }
  4134. if (value.Count > 0)
  4135. {
  4136. return Ok(new { code = 1, msg = "学生ID异常", value = value });
  4137. }
  4138. else {
  4139. return Ok(new { code = 0 });
  4140. }
  4141. }
  4142. catch (Exception e)
  4143. {
  4144. await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/upsert-record()\n{e.Message}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
  4145. return BadRequest();
  4146. }
  4147. }
  4148. private async IAsyncEnumerable<(int code,string value)> stuTask(List<students> stus,List<ExamClassResult> examClassResults, List<List<string>> standard,
  4149. List<double> points, int rule,ExamInfo info,string subjectId, CosmosClient client) {
  4150. foreach(var s in stus)
  4151. {
  4152. string value = "";
  4153. int code = 0;
  4154. List<List<string>> ans = s.answer;
  4155. bool isExist = examClassResults.Exists(e => e.studentIds.Contains(s.id));
  4156. if (!isExist)
  4157. {
  4158. value = s.id;
  4159. code = 1;
  4160. }
  4161. else
  4162. {
  4163. foreach (ExamClassResult result in examClassResults)
  4164. {
  4165. if (!result.studentIds.Contains(s.id))
  4166. {
  4167. continue;
  4168. }
  4169. else
  4170. {
  4171. int newIndex = result.studentIds.IndexOf(s.id);
  4172. StringBuilder builder = new StringBuilder();
  4173. builder.Append(result.examId).Append('/');
  4174. builder.Append(result.subjectId).Append('/');
  4175. builder.Append(s.id).Append('/');
  4176. builder.Append("ans.json");
  4177. result.studentAnswers[newIndex].Clear();
  4178. result.studentAnswers[newIndex].Add(builder.ToString());
  4179. result.status[newIndex] = 0;
  4180. for (int i = 0; i < ans.Count; i++)
  4181. {
  4182. if (ans[i] == null)
  4183. {
  4184. continue;
  4185. //ans[i] = new List<string>();
  4186. }
  4187. var ac = ans[i].Count;
  4188. var sc = standard[i].Count;
  4189. //记录次数
  4190. int n = 0;
  4191. //算分处理
  4192. if (sc > 0)
  4193. {
  4194. result.ans[newIndex][i] = ans[i];
  4195. if (ac == sc && sc == 1)
  4196. {
  4197. foreach (string right in ans[i])
  4198. {
  4199. if (standard[i].Contains(right))
  4200. {
  4201. result.studentScores[newIndex][i] = points[i];
  4202. }
  4203. else
  4204. {
  4205. result.studentScores[newIndex][i] = 0;
  4206. }
  4207. }
  4208. }
  4209. else
  4210. {
  4211. if (rule > 0)
  4212. {
  4213. int falseCount = 0;
  4214. if (ac > 0)
  4215. {
  4216. foreach (string obj in ans[i])
  4217. {
  4218. if (!standard[i].Contains(obj))
  4219. {
  4220. falseCount++;
  4221. }
  4222. }
  4223. switch (rule)
  4224. {
  4225. case 1:
  4226. if (ac == sc)
  4227. {
  4228. if (falseCount == 0)
  4229. {
  4230. result.studentScores[newIndex][i] = points[i];
  4231. }
  4232. else
  4233. {
  4234. result.studentScores[newIndex][i] = 0;
  4235. }
  4236. }
  4237. else
  4238. {
  4239. result.studentScores[newIndex][i] = 0;
  4240. }
  4241. break;
  4242. case 2:
  4243. if (falseCount > 0)
  4244. {
  4245. result.studentScores[newIndex][i] = 0;
  4246. }
  4247. else
  4248. {
  4249. if (ac == sc)
  4250. {
  4251. result.studentScores[newIndex][i] = points[i];
  4252. }
  4253. else
  4254. {
  4255. result.studentScores[newIndex][i] = points[i] / 2;
  4256. }
  4257. }
  4258. break;
  4259. case 3:
  4260. if (falseCount > 0)
  4261. {
  4262. result.studentScores[newIndex][i] = 0;
  4263. }
  4264. else
  4265. {
  4266. if (ac == sc)
  4267. {
  4268. result.studentScores[newIndex][i] = points[i];
  4269. }
  4270. else
  4271. {
  4272. result.studentScores[newIndex][i] = System.Math.Round((double)ac / sc * points[i], 1);
  4273. }
  4274. }
  4275. break;
  4276. case 4:
  4277. if (ac == sc)
  4278. {
  4279. result.studentScores[newIndex][i] = points[i];
  4280. }
  4281. else
  4282. {
  4283. double persent = (double)(sc - 2 * falseCount) / sc;
  4284. if (persent <= 0)
  4285. {
  4286. result.studentScores[newIndex][i] = 0;
  4287. }
  4288. else
  4289. {
  4290. result.studentScores[newIndex][i] = System.Math.Round(persent * points[i], 1);
  4291. }
  4292. }
  4293. break;
  4294. }
  4295. }
  4296. else
  4297. {
  4298. result.studentScores[newIndex][i] = 0;
  4299. }
  4300. }
  4301. }
  4302. }
  4303. }
  4304. bool flag = true;
  4305. foreach (List<double> scores in result.studentScores)
  4306. {
  4307. foreach (double score in scores)
  4308. {
  4309. if (score == -1)
  4310. {
  4311. flag = false;
  4312. break;
  4313. }
  4314. }
  4315. }
  4316. if (flag)
  4317. {
  4318. result.progress = true;
  4319. info.subjects.ForEach(s =>
  4320. {
  4321. if (s.id.Equals(subjectId.ToString()))
  4322. {
  4323. s.classCount += 1;
  4324. }
  4325. });
  4326. await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(info, info.id.ToString(), new PartitionKey($"{info.code}"));
  4327. }
  4328. result.sum[newIndex] = result.studentScores[newIndex].Sum();
  4329. await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(result, result.id, new PartitionKey($"{result.code}"));
  4330. break;
  4331. }
  4332. }
  4333. }
  4334. yield return (code, value);
  4335. }
  4336. }
  4337. private class students {
  4338. public string id { get; set; }
  4339. public List<List<string>> answer { get; set; }
  4340. }
  4341. }
  4342. }
  4343. //private List<Dictionary<string, dynamic>> getKnowledgePoint(List<ExamResult> examResults, ExamInfo info)
  4344. //{
  4345. // Dictionary<string, object> stuMap = new Dictionary<string, object>
  4346. // {
  4347. // { "schoolCode", "Habook" }
  4348. // };
  4349. // List<Dictionary<string, object>> keyValues = new List<Dictionary<string, object>>();
  4350. // HashSet<string> knowledge = new HashSet<string>();
  4351. // HashSet<string> area = new HashSet<string>();
  4352. // List<double> point = new List<double>();
  4353. // List<List<double>> result = new List<List<double>>();
  4354. // List<ClassRange> classes = new List<ClassRange>();
  4355. // List<string> ids = new List<string>();
  4356. // examResults.ForEach(e =>
  4357. // {
  4358. // 定位试卷信息
  4359. // int index = 0;
  4360. // foreach (ExamSubject subject in info.subjects)
  4361. // {
  4362. // if (subject.id.Equals(e.subjectId))
  4363. // {
  4364. // break;
  4365. // }
  4366. // else
  4367. // {
  4368. // index++;
  4369. // }
  4370. // }
  4371. // info.papers[index].knowledge.ForEach(k =>
  4372. // {
  4373. // k.ForEach(e =>
  4374. // {
  4375. // knowledge.Add(e);
  4376. // });
  4377. // });
  4378. // info.papers[index].field.ForEach(f =>
  4379. // {
  4380. // area.Add(f.ToString());
  4381. // });
  4382. // double Qnum = 0;
  4383. // point = info.papers[index].point;
  4384. // result = e.studentScores;
  4385. // classes = e.classes;
  4386. // ids = e.studentIds;
  4387. // 确定高分组 低分组人数
  4388. // List<List<double>> re = e.studentScores;
  4389. // List<double> resultSum = new List<double>();
  4390. // foreach (List<double> data in re)
  4391. // {
  4392. // resultSum.Add(data.Sum());
  4393. // }
  4394. // 确定高分组 最低分数
  4395. // resultSum.Sort(delegate (double s1, double s2) { return s2.CompareTo(s1); });
  4396. // for (int i = resultSum.Count - 1; i >= 0; i--)
  4397. // {
  4398. // if (resultSum[i] == 0)
  4399. // {
  4400. // resultSum.Remove(resultSum[i]);
  4401. // }
  4402. // }
  4403. // double rhwCount = resultSum.Count * 0.27;
  4404. // double rhw = resultSum[int.Parse(rhwCount.ToString("0"))];
  4405. // 确定低分组 最高分数
  4406. // resultSum.Sort(delegate (double s1, double s2) { return s1.CompareTo(s2); });
  4407. // double rhlCount = resultSum.Count * 0.27;
  4408. // double rhl = resultSum[int.Parse(rhwCount.ToString("0"))];
  4409. // List<string> knowledgeName = new List<string>();
  4410. // foreach (string cla in knowledge)
  4411. // {
  4412. // knowledgeName.Add(cla);
  4413. // }
  4414. // for (int k = 0; k < knowledgeName.Count; k++)
  4415. // {
  4416. // if (null == knowledgeName[k])
  4417. // {
  4418. // knowledgeName.Remove(knowledgeName[k]);
  4419. // }
  4420. // }
  4421. // List<string> areaName = new List<string>();
  4422. // foreach (string cla in area)
  4423. // {
  4424. // areaName.Add(cla);
  4425. // }
  4426. // for (int k = 0; k < areaName.Count; k++)
  4427. // {
  4428. // if (null == areaName[k])
  4429. // {
  4430. // areaName.Remove(areaName[k]);
  4431. // }
  4432. // }
  4433. // 初始化年级总分
  4434. // double total = 0;
  4435. // 处理年级单个知识点得分率
  4436. // foreach (List<double> grade in result)
  4437. // {
  4438. // total += grade.Sum();
  4439. // }
  4440. // foreach (string id in ids)
  4441. // {
  4442. // if (!id.Equals("0"))
  4443. // {
  4444. // Qnum++;
  4445. // }
  4446. // }
  4447. // 试卷总分
  4448. // double TotalPoint = point.Sum();
  4449. // 计算认知层次占比
  4450. // List<string> fper = new List<string>();
  4451. // for (int a = 0; a < areaName.Count; a++)
  4452. // {
  4453. // double fieldPoint = 0;
  4454. // int no = 0;
  4455. // info.papers[index].field.ForEach(f =>
  4456. // {
  4457. // if (f.ToString().Equals(areaName[a], StringComparison.OrdinalIgnoreCase))
  4458. // {
  4459. // e.studentScores.ForEach(s =>
  4460. // {
  4461. // fieldPoint += s[no];
  4462. // });
  4463. // }
  4464. // no++;
  4465. // });
  4466. // double fieldPersent = fieldPoint / TotalPoint;
  4467. // fper.Add(fieldPersent.ToString("0.00"));
  4468. // }
  4469. // 求单个知识点所占分数
  4470. // List<string> per = new List<string>();
  4471. // List<string> gper = new List<string>();
  4472. // List<string> knowPer = new List<string>();
  4473. // List<Dictionary<string, double>> eper = new List<Dictionary<string, double>>();
  4474. // Dictionary<string, object> knowledgeALL = new Dictionary<string, object>();
  4475. // Dictionary<string, object> knowledgeMap = new Dictionary<string, object>();
  4476. // Dictionary<string, object> classMap = new Dictionary<string, object>();
  4477. // Dictionary<string, object> wrongMap = new Dictionary<string, object>();
  4478. // HashSet<string> className = new HashSet<string>();
  4479. // List<List<string>> wrongPersent = new List<List<string>>();
  4480. // List<string> key = new List<string>
  4481. // {
  4482. // "id",
  4483. // "className",
  4484. // "seatNO",
  4485. // "point",
  4486. // "anwPoint",
  4487. // "persent"
  4488. // };
  4489. // List<string> keyWrong = new List<string>
  4490. // {
  4491. // "name",
  4492. // "point",
  4493. // "itemNO",
  4494. // "persent",
  4495. // "wrong",
  4496. // "rhw",
  4497. // "rlw"
  4498. // };
  4499. // for (int k = 0; k < knowledgeName.Count; k++)
  4500. // {
  4501. // List<string> knowledgeClass = new List<string>();
  4502. // List<List<string>> stuPersent = new List<List<string>>();
  4503. // double OnePoint = 0;
  4504. // 获取每个知识点占有多少分值
  4505. // double ePoint = 0;
  4506. // double anwGPoint = 0;
  4507. // double poG = 0;
  4508. // int m = 0;
  4509. // List<string> valuew = new List<string>();
  4510. // List<string> itemNo = new List<string>();
  4511. // keyWrong.ForEach(x =>
  4512. // {
  4513. // valuew.Add("-");
  4514. // });
  4515. // int wrongCount = 0;
  4516. // valuew[0] = knowledgeName[k];
  4517. // int n = 0;
  4518. // info.papers[index].knowledge.ForEach(kno =>
  4519. // {
  4520. // if (kno.Contains(knowledgeName[k]))
  4521. // {
  4522. // OnePoint += point[n];
  4523. // itemNo.Add((n + 1).ToString());
  4524. // }
  4525. // valuew[1] = OnePoint.ToString();
  4526. // string itemNos = "";
  4527. // if (itemNo.Count > 0)
  4528. // {
  4529. // foreach (string np in itemNo)
  4530. // {
  4531. // itemNos += np + ",";
  4532. // }
  4533. // valuew[2] = itemNos[0..^1];
  4534. // }
  4535. // else
  4536. // {
  4537. // valuew[2] = itemNos;
  4538. // }
  4539. // n++;
  4540. // });
  4541. // int rhwC = 0;
  4542. // int rhlC = 0;
  4543. // foreach (string id in ids)
  4544. // {
  4545. // if (id.Equals("0") || result[m].Sum() == 0)
  4546. // {
  4547. // m++;
  4548. // continue;
  4549. // }
  4550. // List<string> values = new List<string>();
  4551. // key.ForEach(x =>
  4552. // {
  4553. // values.Add("-");
  4554. // });
  4555. // /* foreach (OldStudent info in students)
  4556. // {
  4557. // if (info.studentId.Equals(id))
  4558. // {
  4559. // values[2] = info.seatNo.ToString();
  4560. // break;
  4561. // }
  4562. // }*/
  4563. // List<string> stu = new List<string>();
  4564. // values[0] = id;
  4565. // values[1] = "-";
  4566. // List<List<string>> stuItem = new List<List<string>>();
  4567. // int statuCount = 0;
  4568. // info.papers[index].knowledge.ForEach(kno =>
  4569. // {
  4570. // int sno = 0;
  4571. // double anwPoint = 0;
  4572. // double po = 0;
  4573. // if (kno.Contains(knowledgeName[k]))
  4574. // {
  4575. // 当前认知层次在该题占比多少
  4576. // ePoint = 1;
  4577. // anwPoint += result[m][sno] * ePoint;
  4578. // 所有学生单个认知层次得分情况
  4579. // anwGPoint += result[m][sno] * ePoint;
  4580. // po += point[sno] * ePoint;
  4581. // 认知层次所占分数
  4582. // poG += point[sno] * ePoint;
  4583. // if (result[m][sno] == 0 && statuCount == 0)
  4584. // {
  4585. // statuCount++;
  4586. // wrongCount++;
  4587. // if (result[m].Sum() >= rhw)
  4588. // {
  4589. // rhwC++;
  4590. // }
  4591. // if (result[m].Sum() <= rhl)
  4592. // {
  4593. // rhlC++;
  4594. // }
  4595. // }
  4596. // if (po == 0)
  4597. // {
  4598. // values[3] = "0";
  4599. // values[4] = "0";
  4600. // values[5] = "0";
  4601. // }
  4602. // else
  4603. // {
  4604. // double stuPser = anwPoint / po;
  4605. // values[3] = po.ToString();
  4606. // values[4] = anwPoint.ToString();
  4607. // values[5] = stuPser.ToString("0.00");
  4608. // }
  4609. // }
  4610. // });
  4611. // stuPersent.Add(values);
  4612. // m++;
  4613. // }
  4614. // AchievementService.ReName(stuPersent, ids, classes, students);
  4615. // double knowPser = 0;
  4616. // if (poG == 0)
  4617. // {
  4618. // knowPer.Add("0");
  4619. // }
  4620. // else
  4621. // {
  4622. // knowPser = anwGPoint / poG;
  4623. // knowPer.Add(knowPser.ToString("0.00"));
  4624. // }
  4625. // 错题关系表
  4626. // valuew[3] = knowPser.ToString("0.00");
  4627. // valuew[4] = wrongCount.ToString();
  4628. // valuew[5] = rhwC.ToString();
  4629. // valuew[6] = rhlC.ToString();
  4630. // wrongPersent.Add(valuew);
  4631. // knowledgeMap.Add(knowledgeName[k], stuPersent);
  4632. // 知识点占比
  4633. // double persent = OnePoint / TotalPoint;
  4634. // foreach (ClassRange classRange in e.classes)
  4635. // {
  4636. // List<string> classPoints = new List<string>();
  4637. // 初始化班级得分
  4638. // double anwCPoint = 0;
  4639. // double cpo = 0;
  4640. // for (int stuIndex = classRange.range[0]; stuIndex < classRange.range[1]; stuIndex++)
  4641. // {
  4642. // if (result[stuIndex].Sum() == 0) continue;
  4643. // info.papers[index].knowledge.ForEach(kno =>
  4644. // {
  4645. // int x = 0;
  4646. // if (kno.Contains(knowledgeName[k]))
  4647. // {
  4648. // 当前认知层次在该题占比多少
  4649. // ePoint = 1;
  4650. // anwCPoint += result[stuIndex][x] * ePoint;
  4651. // cpo += point[x] * ePoint;
  4652. // }
  4653. // });
  4654. // }
  4655. // if (cpo == 0)
  4656. // {
  4657. // double classPser = anwCPoint / cpo;
  4658. // knowledgeClass.Add("0");
  4659. // }
  4660. // else
  4661. // {
  4662. // double classPser = anwCPoint / cpo;
  4663. // knowledgeClass.Add(classPser.ToString("0.00"));
  4664. // }
  4665. // }
  4666. // classMap.Add(knowledgeName[k], knowledgeClass);
  4667. // per.Add(persent.ToString("0.00"));
  4668. // }
  4669. // knowledgeMap.Add("grade", knowPer);
  4670. // knowledgeMap.Add("keys", key);
  4671. // classMap.Add("className", className);
  4672. // wrongMap.Add("keys", keyWrong);
  4673. // wrongMap.Add("datas", wrongPersent);
  4674. // knowledgeALL.Add("pointList", knowledgeName);
  4675. // knowledgeALL.Add("per", per);
  4676. // knowledgeALL.Add("level", areaName);
  4677. // knowledgeALL.Add("fper", fper);
  4678. // knowledgeALL.Add("stupercent", knowledgeMap);
  4679. // knowledgeALL.Add("classpercent", classMap);
  4680. // knowledgeALL.Add("wrong", wrongMap);
  4681. // keyValues.Add(knowledgeALL);
  4682. // });
  4683. // return keyValues;
  4684. //}
  4685. // }
  4686. //}