LessonETLService.cs 192 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597
  1. using Azure;
  2. using Azure.Storage.Blobs.Models;
  3. using DocumentFormat.OpenXml.Drawing.Charts;
  4. using DocumentFormat.OpenXml.Office2010.Excel;
  5. using DocumentFormat.OpenXml.Office2013.Drawing.ChartStyle;
  6. using DocumentFormat.OpenXml.Office2016.Drawing.ChartDrawing;
  7. using MathNet.Numerics;
  8. using MathNet.Numerics.Distributions;
  9. using Microsoft.Azure.Cosmos;
  10. using Microsoft.Azure.Cosmos.Linq;
  11. using Microsoft.Extensions.Configuration;
  12. using Microsoft.Extensions.Logging;
  13. using OfficeOpenXml;
  14. using OpenXmlPowerTools;
  15. using System;
  16. using System.Collections.Generic;
  17. using System.IO;
  18. using System.Linq;
  19. using System.Reflection;
  20. using System.Text;
  21. using System.Text.Json;
  22. using System.Text.RegularExpressions;
  23. using System.Threading.Tasks;
  24. using System.Xml;
  25. using TEAMModelOS.SDK;
  26. using TEAMModelOS.SDK.DI;
  27. using TEAMModelOS.SDK.Extension;
  28. using TEAMModelOS.SDK.Models;
  29. using TEAMModelOS.SDK.Models.Cosmos.Common;
  30. using TEAMModelOS.SDK.Models.Cosmos.OpenEntity;
  31. using TEAMModelOS.SDK.Models.Dtos;
  32. using static TEAMModelOS.SDK.Models.ThirdService;
  33. namespace HTEX.Lib.ETL.Lesson
  34. {
  35. public class LessonETLService
  36. {
  37. public static List<CodeBool> GetCodeBools (List<StudentLessonData> studentLessonDatas) {
  38. List<CodeBool> codeBools = new List<CodeBool>() {
  39. new CodeBool { code="hd",value=false },//互动
  40. new CodeBool { code="pc",value=false },//评测
  41. new CodeBool { code="rw",value=false },//任务
  42. new CodeBool { code="pj",value=false },//评价
  43. new CodeBool { code="tp",value=false },//投票
  44. new CodeBool { code="xg",value=false },//星光
  45. new CodeBool { code="hp",value=false },//互评
  46. new CodeBool { code="xz",value=false },//协作
  47. new CodeBool { code="tr",value=false },//挑人
  48. new CodeBool { code="xztr",value=false },//小组挑人
  49. new CodeBool { code="xzxz",value=false },//小组协作
  50. new CodeBool { code="xzrw",value=false },//小组任务
  51. };
  52. foreach (var studentLessonData in studentLessonDatas)
  53. {
  54. if (studentLessonData.interactRecord.interactRecords.Count>0)
  55. {
  56. codeBools.Find(x => x.code.Equals("hd"))!.value=true;
  57. }
  58. if (studentLessonData.examRecords.Count>0)
  59. {
  60. codeBools.Find(x => x.code.Equals("pc"))!.value=true;
  61. }
  62. if (studentLessonData.taskRecord.itemRecords.Count>0 || studentLessonData.uploadCount.Count>0)
  63. {
  64. codeBools.Find(x => x.code.Equals("rw"))!.value=true;
  65. if (studentLessonData.taskRecord.itemRecords.FindAll(x => x.isGroup==true).IsNotEmpty())
  66. {
  67. codeBools.Find(x => x.code.Equals("xzrw"))!.value=true;
  68. }
  69. }
  70. if (studentLessonData.rateingRecord.itemRecords.Count>0)
  71. {
  72. codeBools.Find(x => x.code.Equals("pj"))!.value=true;
  73. if (studentLessonData.rateingRecord.itemRecords.FindAll(x => x.itemType!.Equals("GrandRating")).IsNotEmpty())
  74. {
  75. codeBools.Find(x => x.code.Equals("xg"))!.value=true;
  76. }
  77. if (studentLessonData.rateingRecord.itemRecords.FindAll(x => x.itemType!.Equals("Voting")).IsNotEmpty())
  78. {
  79. codeBools.Find(x => x.code.Equals("tp"))!.value=true;
  80. }
  81. if (studentLessonData.rateingRecord.itemRecords.FindAll(x => x.itemType!.Equals("PeerAssessment")).IsNotEmpty())
  82. {
  83. codeBools.Find(x => x.code.Equals("hp"))!.value=true;
  84. }
  85. }
  86. if (studentLessonData.coworkRecord.itemRecords.Count>0 || studentLessonData.coworkScore.Count>0 || studentLessonData.group_coworkScore.Count>0)
  87. {
  88. codeBools.Find(x => x.code.Equals("xz"))!.value=true;
  89. if (studentLessonData.group_coworkScore.Count>0)
  90. {
  91. codeBools.Find(x => x.code.Equals("xzxz"))!.value=true;
  92. }
  93. }
  94. if (studentLessonData.pickups.FindAll(x => x.Contains("grp", StringComparison.OrdinalIgnoreCase)).IsNotEmpty())
  95. {
  96. codeBools.Find(x => x.code.Equals("xztr"))!.value=true;
  97. }
  98. if (studentLessonData.pickups.IsNotEmpty())
  99. {
  100. codeBools.Find(x => x.code.Equals("tr"))!.value=true;
  101. }
  102. }
  103. return codeBools;
  104. }
  105. /// <summary>
  106. /// 生成学生student-analysis.json
  107. /// </summary>
  108. /// <param name="objectiveTypes"></param>
  109. /// <param name="azureStorage"></param>
  110. /// <param name="lessonLocal"></param>
  111. /// <returns></returns>
  112. public static async Task<(List<StudentLessonData> studentLessonDatas, List<StudentLessonItem> lessonItems, List<CodeBool> codeBools)>
  113. DoStudentLessonData(List<string> objectiveTypes, AzureStorageFactory azureStorage, LessonLocal lessonLocal,DingDing _dingDing,
  114. CosmosClient client,string location ,AzureRedisFactory azureRedis, List<StudentSemesterRecord> studentSemesterRecords, List<OverallEducation> overallEducations,
  115. LessonDataAnalysisModel lessonDataAnalysis, List<Student> studentsBase,List<School> schools )
  116. {
  117. List<StudentLessonData> studentLessonDatas = lessonLocal.studentLessonDatas.ToJsonString().ToObject<List<StudentLessonData>>();
  118. studentLessonDatas = LessonETLService.GetBaseInfo(lessonLocal.lessonBase!, studentLessonDatas, lessonLocal?.lessonRecord?.id);
  119. studentLessonDatas = LessonETLService.GetIRSData(lessonLocal.lessonBase!, lessonLocal.timeLineData!, lessonLocal.irsDatas, studentLessonDatas, lessonLocal.examDatas, lessonLocal?.lessonRecord?.id);
  120. studentLessonDatas = LessonETLService.GetCoworkData(lessonLocal.lessonBase!, lessonLocal.timeLineData!, lessonLocal.coworkDatas, studentLessonDatas, lessonLocal.lessonRecord.id);
  121. studentLessonDatas = LessonETLService.GetExamData(lessonLocal.lessonBase!, lessonLocal.timeLineData!, lessonLocal.examDatas, studentLessonDatas, objectiveTypes, lessonLocal.lessonRecord.id);
  122. studentLessonDatas = LessonETLService.GetSmartRatingData(lessonLocal.lessonBase!, lessonLocal.timeLineData!, lessonLocal.smartRatingDatas, studentLessonDatas, lessonLocal.lessonRecord.id);
  123. studentLessonDatas = LessonETLService.GetTaskData(lessonLocal.lessonBase!, lessonLocal.timeLineData!, lessonLocal.taskDatas, studentLessonDatas, lessonLocal.lessonRecord.id);
  124. var pickupData = LessonETLService.GetPickupData(lessonLocal.lessonBase!, lessonLocal. timeLineData!, studentLessonDatas, lessonLocal.lessonRecord.id);
  125. studentLessonDatas= pickupData.studentLessonDatas;
  126. var codeBools= GetCodeBools(studentLessonDatas);
  127. List<StudentLessonItem> lessonItems = new List<StudentLessonItem>();
  128. string owner = lessonLocal.lessonRecord.scope.Equals("school") ? lessonLocal.lessonRecord.school : lessonLocal.lessonRecord.tmdid;
  129. if (codeBools.FindAll(x => x.value).IsNotEmpty())
  130. {
  131. #if !DEBUG
  132. try
  133. {
  134. bool exists = await azureStorage.GetBlobContainerClient("0-public").GetBlobClient($"/lesson/analysis/analysis-model.json").ExistsAsync();
  135. if (exists)
  136. {
  137. if (lessonDataAnalysis==null)
  138. {
  139. BlobDownloadResult blobDownload = await azureStorage.GetBlobContainerClient("0-public").GetBlobClient($"/lesson/analysis/analysis-model.json").DownloadContentAsync();
  140. lessonDataAnalysis = blobDownload.Content.ToObjectFromJson<LessonDataAnalysisModel>();
  141. }
  142. XmlDocument xmlDocument = new XmlDocument();
  143. var runtimePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
  144. xmlDocument.Load($"{runtimePath}\\summary.xml");
  145. // 获取类的属性
  146. PropertyInfo[] properties = typeof(StudentLessonItem).GetProperties();
  147. List<string> summaryes= new List<string>();
  148. for (int i = 0; i < properties.Length; i++)
  149. {
  150. string summary = Regex.Replace(LessonETLService.GetPropertySummary(properties[i], xmlDocument), @"\s+", "");
  151. summaryes.Add(summary);
  152. }
  153. await LessonETLService.ExportToExcelAzureBlob(lessonItems, azureStorage, owner, $"{lessonLocal.lessonRecord.id}/student-analysis.xlsx", xmlDocument,summaryes,properties);
  154. }
  155. }
  156. catch (Exception ex)
  157. {
  158. if (!ex.Message.Contains("The specified blob does not exist"))
  159. {
  160. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")},lesson/analysis/analysis-model.json转换异常,{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
  161. }
  162. }
  163. await azureStorage.GetBlobContainerClient(owner).UploadFileByContainer(studentLessonDatas.ToJsonString(), "records", $"{lessonLocal.lessonRecord.id}/student-analysis.json");
  164. #else
  165. lessonItems = LessonETLService.ProcessStudentDataV2(studentLessonDatas, lessonDataAnalysis, codeBools);
  166. #endif
  167. if (lessonLocal.lessonRecord.scope.Equals("school")&& !string.IsNullOrWhiteSpace(lessonLocal.lessonRecord.school) && location.Equals("China", StringComparison.OrdinalIgnoreCase))
  168. {
  169. School school = schools.Find(x => x.id.Equals(lessonLocal.lessonRecord.school));
  170. if (school==null)
  171. {
  172. ResponseMessage response = await client.GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemStreamAsync(lessonLocal.lessonRecord.school, new PartitionKey("Base"));
  173. if (response.IsSuccessStatusCode)
  174. {
  175. school = JsonDocument.Parse(response.Content).RootElement.ToObject<School>();
  176. schools.Add(school);
  177. }
  178. }
  179. if (school!=null)
  180. {
  181. #if !DEBUG
  182. var sdtus = studentLessonDatas.Where(y => !studentsBase.Where(z => z.schoolId.Equals(school.id)).Select(x => x.id).Contains(y.id));
  183. if (sdtus!=null && sdtus.Count()>0)
  184. {
  185. var result = await client.GetContainer(Constant.TEAMModelOS, Constant.Student).GetList<Student>($"select value c from c where c.id in ({string.Join(",", sdtus.Select(d => $"'{d.id}'"))})", $"Base-{school.id}");
  186. if (result.list.Any())
  187. {
  188. studentsBase.AddRange(result.list);
  189. }
  190. }
  191. #endif
  192. string? periodId = !string.IsNullOrWhiteSpace(lessonLocal.lessonRecord.periodId) ? lessonLocal.lessonRecord.periodId : school.period.FirstOrDefault()?.id;
  193. var period = school.period.Find(x => x.id.Equals(periodId));
  194. if (period!=null)
  195. {
  196. var semester = SchoolService.GetSemester(period, lessonLocal.lessonRecord.startTime);
  197. string pre_id = $"{semester.studyYear}-{semester.currSemester.id}";
  198. string code = $"StudentSemesterRecord-{school.id}";
  199. foreach (var studentLessonData in studentLessonDatas)
  200. {
  201. StudentSemesterRecord studentSemester = studentSemesterRecords.Find(x => x.id.Equals($"{pre_id}-{studentLessonData.id}") && x.code.Equals(code));
  202. if (studentSemester==null)
  203. {
  204. #if !DEBUG
  205. ResponseMessage responseMessage = await client.GetContainer(Constant.TEAMModelOS, Constant.Student).ReadItemStreamAsync($"{pre_id}-{studentLessonData.id}", new PartitionKey(code));
  206. if (responseMessage.IsSuccessStatusCode)
  207. {
  208. studentSemester= JsonDocument.Parse(responseMessage.Content).ToObject<StudentSemesterRecord>();
  209. }
  210. else
  211. {
  212. studentSemester= new StudentSemesterRecord
  213. {
  214. id= $"{pre_id}-{studentLessonData.id}",
  215. code=code,
  216. stuid= studentLessonData.id,
  217. userType=Constant.ScopeStudent,
  218. school=school.id,
  219. studyYear=semester.studyYear,
  220. semesterId=semester.currSemester.id,
  221. period= period?.id,
  222. pk="StudentSemesterRecord"
  223. };
  224. }
  225. #else
  226. studentSemester= new StudentSemesterRecord
  227. {
  228. id= $"{pre_id}-{studentLessonData.id}",
  229. code=code,
  230. stuid= studentLessonData.id,
  231. userType=Constant.ScopeStudent,
  232. school=school.id,
  233. studyYear=semester.studyYear,
  234. semesterId=semester.currSemester.id,
  235. period= period?.id,
  236. pk="StudentSemesterRecord"
  237. };
  238. #endif
  239. studentSemesterRecords.Add(studentSemester);
  240. }
  241. var les = studentSemester.les.Find(x => x.id.Equals(lessonLocal.lessonRecord.id));
  242. if (les==null)
  243. {
  244. les = new StuLesson()
  245. {
  246. id= lessonLocal.lessonRecord.id,
  247. time= lessonLocal.lessonRecord.startTime,
  248. attend=0
  249. };
  250. studentSemester.les.Add(les);
  251. }
  252. else
  253. {
  254. les.time= lessonLocal.lessonRecord.startTime;
  255. }
  256. var lesson = studentSemester.lessons.Find(x => x.id.Equals(lessonLocal.lessonRecord.id));
  257. if (lesson!=null)
  258. {
  259. if (studentLessonData.cooperation>0 || studentLessonData.achieve>0|| studentLessonData.attitude>0 || studentLessonData.cowork>0 || studentLessonData.appraise>0)
  260. {
  261. les.attend=1;
  262. lesson.tmdid = lessonLocal.lessonRecord.tmdid;
  263. lesson.sid = lessonLocal.lessonRecord.subjectId;
  264. lesson.cid = lessonLocal.lessonRecord.courseId;
  265. lesson.hrate = studentLessonData.cooperation;
  266. lesson.crate = studentLessonData.achieve;
  267. lesson.trate = studentLessonData.attitude;
  268. lesson.xrate = studentLessonData.cowork;
  269. lesson.prate = studentLessonData.appraise;
  270. }
  271. else
  272. {
  273. if (studentLessonData.attend==1)
  274. {
  275. les.attend=1;
  276. }
  277. else
  278. {
  279. les.attend=0;
  280. }
  281. }
  282. }
  283. else
  284. {
  285. if (studentLessonData.cooperation>0 || studentLessonData.achieve>0|| studentLessonData.attitude>0 || studentLessonData.cowork>0 || studentLessonData.appraise>0)
  286. {
  287. les.attend=1;
  288. lesson = new StuLessonLite
  289. {
  290. id=lessonLocal.lessonRecord.id,
  291. tmdid=lessonLocal.lessonRecord.tmdid,
  292. sid= lessonLocal.lessonRecord.subjectId,
  293. cid= lessonLocal.lessonRecord.courseId,
  294. hrate=studentLessonData.cooperation,
  295. crate=studentLessonData.achieve,
  296. trate=studentLessonData.attitude,
  297. xrate=studentLessonData.cowork,
  298. prate=studentLessonData.appraise
  299. };
  300. studentSemester.lessons.Add(lesson);
  301. }
  302. else
  303. {
  304. if (studentLessonData.attend==1)
  305. {
  306. les.attend=1;
  307. }
  308. else
  309. {
  310. les.attend=0;
  311. }
  312. }
  313. }
  314. //await client.GetContainer(Constant.TEAMModelOS, Constant.Student).UpsertItemAsync(studentSemester, new PartitionKey(studentSemester.code));
  315. string oid = $"{semester.studyYear}-{semester.currSemester.id}-{studentSemester.stuid}";
  316. string ocode = $"OverallEducation-{school.id}";
  317. var student = studentsBase.Find(x => x.id.Equals(studentSemester.stuid));
  318. if (student!=null)
  319. {
  320. OverallEducation overallEducation = overallEducations.Find(x => x.id.Equals(oid) && x.code.Equals(ocode));
  321. if (overallEducation== null)
  322. {
  323. #if !DEBUG
  324. ResponseMessage oresponse = await client.GetContainer(Constant.TEAMModelOS, Constant.Student).ReadItemStreamAsync(oid, new PartitionKey(ocode));
  325. if (!oresponse.IsSuccessStatusCode)
  326. {
  327. overallEducation = new OverallEducation
  328. {
  329. id =oid,
  330. code = $"OverallEducation-{school.id}",
  331. pk = "OverallEducation",
  332. ttl = -1,
  333. name = student.name,
  334. classId = student?.classId,
  335. schoolCode = $"{school.id}",
  336. semesterId = semester.currSemester.id,
  337. year = semester.studyYear,
  338. periodId = $"{period.id}",
  339. stuYear = student.year,
  340. studentId = student.id,
  341. lessonScore= new List<StudentLessonRecord>()
  342. };
  343. }
  344. else
  345. {
  346. overallEducation = JsonDocument.Parse(oresponse.Content).RootElement.ToObject<OverallEducation>();
  347. }
  348. #else
  349. overallEducation = new OverallEducation
  350. {
  351. id =oid,
  352. code = $"OverallEducation-{school.id}",
  353. pk = "OverallEducation",
  354. ttl = -1,
  355. name = student.name,
  356. classId = student?.classId,
  357. schoolCode = $"{school.id}",
  358. semesterId = semester.currSemester.id,
  359. year = semester.studyYear,
  360. periodId = $"{period.id}",
  361. stuYear = student.year,
  362. studentId = student.id,
  363. lessonScore= new List<StudentLessonRecord>()
  364. };
  365. #endif
  366. overallEducations.Add(overallEducation);
  367. }
  368. var hasrecord = overallEducation.lessonScore.Find(x => x.lessonId.Equals(lessonLocal.lessonRecord.id));
  369. if (hasrecord==null)
  370. {
  371. hasrecord= new StudentLessonRecord();
  372. overallEducation.lessonScore.Add(hasrecord);
  373. }
  374. hasrecord.gscore = studentLessonData.gscore;
  375. hasrecord.pscore = studentLessonData.pscore;
  376. hasrecord.tscore = studentLessonData.tscore;
  377. hasrecord.tmdid = lessonLocal.lessonRecord.tmdid;
  378. hasrecord.school = school.id;
  379. hasrecord.scope = lessonLocal.lessonRecord.scope;
  380. hasrecord.lessonId = lessonLocal.lessonRecord.id;
  381. hasrecord.courseId = lessonLocal.lessonRecord.courseId;
  382. periodId = period?.id;
  383. hasrecord.subjectId = lessonLocal.lessonRecord.subjectId;
  384. hasrecord.time= lessonLocal.lessonRecord.startTime;
  385. hasrecord.attend=les.attend;
  386. if (lesson!=null)
  387. {
  388. hasrecord.hrate=lesson.hrate;
  389. hasrecord.crate=lesson.crate;
  390. hasrecord.trate=lesson.trate;
  391. hasrecord.xrate=lesson.xrate;
  392. hasrecord.prate=lesson.prate;
  393. }
  394. //if (overallEducation!=null)
  395. //{
  396. // await client.GetContainer(Constant.TEAMModelOS, Constant.Student).UpsertItemAsync(overallEducation, partitionKey: new PartitionKey(overallEducation.code));
  397. // string key = $"OverallEducation:{school.id}:{period.id}:{semester.studyYear}:{semester.currSemester.id}:{student?.classId}";
  398. // await azureRedis.GetRedisClient(8).HashSetAsync(key, studentLessonData.id, overallEducation.ToJsonString());
  399. // await azureRedis.GetRedisClient(8).KeyExpireAsync(key, new TimeSpan(180 *24, 0, 0));
  400. //}
  401. }
  402. }
  403. }
  404. }
  405. }
  406. }
  407. return (studentLessonDatas, lessonItems, codeBools);
  408. }
  409. public static async Task GenAnalysisData(string pathAnalysis, long newest, List<TechCount> techCounts,AzureStorageFactory azureStorage)
  410. {
  411. var yearMonthDatas = techCounts.GroupBy(x => x.yearMonth).Select(x => new { key = x.Key, list = x.ToList() });
  412. // lessonDataAnalysisMonths = new List<LessonDataAnalysisMonth>();
  413. LessonDataAnalysisCluster lessonDataAnalysisCluster = new LessonDataAnalysisCluster();
  414. foreach (var yearMonthData in yearMonthDatas)
  415. {
  416. if (string.IsNullOrWhiteSpace(yearMonthData.key))
  417. {
  418. Console.WriteLine(yearMonthData.list.Select(x => x.lessonId).ToJsonString());
  419. }
  420. LessonDataAnalysisMonth lessonDataAnalysisMonth = new LessonDataAnalysisMonth() { updateTime= newest, yearMonth= yearMonthData.key };
  421. lessonDataAnalysisMonth.pscore = yearMonthData.list.SelectMany(x => x.pscore).ToList();
  422. lessonDataAnalysisMonth.tscore = yearMonthData.list.SelectMany(x => x.tscore).ToList();
  423. lessonDataAnalysisMonth.gscore = yearMonthData.list.SelectMany(x => x.gscore).ToList();
  424. lessonDataAnalysisMonth.irs= yearMonthData.list.Where(x => x.irsCount>0).Select(x => (double)x.irsCount).ToList();
  425. lessonDataAnalysisMonth.interactNormal= yearMonthData.list.Where(x => x.interactNormalCount > 0).Select(x => (double)x.interactNormalCount).ToList();
  426. lessonDataAnalysisMonth.task = yearMonthData.list.Where(x => x.taskCount > 0).Select(x => (double)x.taskCount).ToList();
  427. lessonDataAnalysisMonth.stuCowork=yearMonthData.list.SelectMany(x => x.stuCowork).ToList();
  428. lessonDataAnalysisMonth.groupCowork=yearMonthData.list.SelectMany(x => x.groupCowork).ToList();
  429. lessonDataAnalysisMonth.pickup= yearMonthData.list.Where(x => x.pickup.Count()>0).Select(x=>x.pickup).ToList();
  430. System.IO.File.WriteAllText(Path.Combine(pathAnalysis, $"{yearMonthData.key}-m-analysis.json"), lessonDataAnalysisMonth.ToJsonString());
  431. // lessonDataAnalysisMonths.Add( lessonDataAnalysisMonth);
  432. if (lessonDataAnalysisMonth.task.IsNotEmpty())
  433. {
  434. lessonDataAnalysisCluster.task.AddRange(lessonDataAnalysisMonth.task);
  435. }
  436. if (lessonDataAnalysisMonth.irs.IsNotEmpty())
  437. {
  438. lessonDataAnalysisCluster.irs.AddRange(lessonDataAnalysisMonth.irs);
  439. }
  440. if (lessonDataAnalysisMonth.interactNormal.IsNotEmpty())
  441. {
  442. lessonDataAnalysisCluster.interactNormal.AddRange(lessonDataAnalysisMonth.interactNormal);
  443. }
  444. if (lessonDataAnalysisMonth.pscore.IsNotEmpty())
  445. {
  446. lessonDataAnalysisCluster.pscore.AddRange(lessonDataAnalysisMonth.pscore);
  447. }
  448. if (lessonDataAnalysisMonth.gscore.IsNotEmpty())
  449. {
  450. lessonDataAnalysisCluster.gscore.AddRange(lessonDataAnalysisMonth.gscore);
  451. }
  452. if (lessonDataAnalysisMonth.tscore.IsNotEmpty())
  453. {
  454. lessonDataAnalysisCluster.tscore.AddRange(lessonDataAnalysisMonth.tscore);
  455. }
  456. if (lessonDataAnalysisMonth.stuCowork.IsNotEmpty())
  457. {
  458. lessonDataAnalysisCluster.stuCowork.AddRange(lessonDataAnalysisMonth.stuCowork);
  459. }
  460. if (lessonDataAnalysisMonth.groupCowork.IsNotEmpty())
  461. {
  462. lessonDataAnalysisCluster.groupCowork.AddRange(lessonDataAnalysisMonth.groupCowork);
  463. }
  464. lessonDataAnalysisCluster.pickup.AddRange(lessonDataAnalysisMonth.pickup);
  465. }
  466. //标准差偏差N倍,视为异常数据
  467. int thresholdMultiplier = 2;
  468. lessonDataAnalysisCluster.task= LessonETLService.CleanDataBySDThreshold(lessonDataAnalysisCluster.task.OrderBy(x => x), thresholdMultiplier);
  469. lessonDataAnalysisCluster.pscore= LessonETLService.CleanDataBySDThreshold(lessonDataAnalysisCluster.pscore.OrderBy(x => x), thresholdMultiplier);
  470. lessonDataAnalysisCluster.gscore= LessonETLService.CleanDataBySDThreshold(lessonDataAnalysisCluster.gscore.OrderBy(x => x), thresholdMultiplier);
  471. lessonDataAnalysisCluster.tscore= LessonETLService.CleanDataBySDThreshold(lessonDataAnalysisCluster.tscore.OrderBy(x => x), thresholdMultiplier);
  472. lessonDataAnalysisCluster.irs = LessonETLService.CleanDataBySDThreshold(lessonDataAnalysisCluster.irs.OrderBy(x => x), thresholdMultiplier);
  473. lessonDataAnalysisCluster.interactNormal=LessonETLService.CleanDataBySDThreshold(lessonDataAnalysisCluster.interactNormal.OrderBy(x => x), thresholdMultiplier);
  474. lessonDataAnalysisCluster.stuCowork=LessonETLService.CleanDataBySDThreshold(lessonDataAnalysisCluster.stuCowork.OrderBy(x => x), thresholdMultiplier);
  475. lessonDataAnalysisCluster.groupCowork=LessonETLService.CleanDataBySDThreshold(lessonDataAnalysisCluster.groupCowork.OrderBy(x => x), thresholdMultiplier);
  476. var all = lessonDataAnalysisCluster.interactNormal.OrderBy(x => x).ToArray();
  477. //超过60 80的
  478. double n = all.Max()+1;
  479. //var clusterInteract = HTEX.Lib.ETL.KMeansService.KMeansOptimized(d, 3);
  480. //foreach (var item in clusterInteract.OrderBy(x => x.Key))
  481. //{
  482. // lessonDataAnalysisCluster.clustersInteract.Add(new KeyValuePair<double, List<double>>(item.Value.Average(), item.Value));
  483. // Console.WriteLine($"dp:{item.Key} ,avg: {item.Value.Average()}, count: {item.Value.Count}, min:{item.Value.Min()}, max:{item.Value.Max()},weight:{item.Value.Count*1.0/d.Count()}");
  484. //}
  485. //IEnumerable<double> all = lessonDataAnalysisCluster.clustersInteract.SelectMany(x => x.Value);
  486. int pass = 0;
  487. for (var i = 1; i<n; i++)
  488. {
  489. var p = LessonETLService.GetPersent(all, i);
  490. if (p.persent>=60)
  491. {
  492. pass = i;
  493. break;
  494. }
  495. }
  496. var low = all.Where(x => x<pass).Average();
  497. int good = 0;
  498. for (var i = 1; i<n; i++)
  499. {
  500. var p = LessonETLService.GetPersent(all, i);
  501. if (p.persent>=80)
  502. {
  503. good = i;
  504. break;
  505. }
  506. }
  507. var medium = all.Where(x => x>=pass &&x<good).Average();
  508. var high = all.Where(x => x>=good).Average();
  509. lessonDataAnalysisCluster.interactGood=good;
  510. lessonDataAnalysisCluster.interactPass=pass;
  511. lessonDataAnalysisCluster.interactHigh=high;
  512. lessonDataAnalysisCluster.interactMedium=medium;
  513. lessonDataAnalysisCluster.interactLow=low;
  514. List<KeyValuePair<double, List<double>>> levelInteract = new List<KeyValuePair<double, List<double>>>()
  515. {
  516. new KeyValuePair<double, List<double>>(low, new List<double> { all.Where(x => x<pass).Min(), all.Where(x => x<pass).Max() }),
  517. new KeyValuePair<double, List<double>>(medium, new List<double> { all.Where(x => x>=pass &&x<good).Min(), all.Where(x => x>=pass &&x<good).Max() }),
  518. new KeyValuePair<double, List<double>>(high, new List<double> { all.Where(x => x>=good).Min(), all.Where(x => x>=good).Max() })
  519. };
  520. lessonDataAnalysisCluster.levelInteract= levelInteract;
  521. //// 设置0 为自动规划聚类,11 则为自动规划后得到的数字。
  522. //var clusterInteract = KMeansService.KMeansOptimized(d,11,10);
  523. ////foreach (var item in clusterInteract)
  524. ////{
  525. //// Console.WriteLine($"dp:{item.Key} ,avg: {item.Value.Average()}, count: {item.Value.Count}, min:{item.Value.Min()}, max:{item.Value.Max()}");
  526. ////}
  527. //foreach (var item in clusterInteract.OrderBy(x => x.Key))
  528. //{
  529. // lessonDataAnalysisCluster.clustersInteract.Add(new KeyValuePair<double, List<double>>(item.Value.Average(), item.Value));
  530. // //Console.WriteLine($"dp:{item.Key} ,avg: {item.Value.Average()}, count: {item.Value.Count}, min:{item.Value.Min()}, max:{item.Value.Max()},weight:{item.Value.Count*1.0/d.Count()}");
  531. //}
  532. //await azureStorage.GetBlobContainerClient("0-public").UploadFileByContainer(lessonDataAnalysisCluster.ToJsonString(), "lesson", $"analysis/analysis.json");
  533. //System.IO.File.WriteAllText(Path.Combine(pathAnalysis, "analysis.json"), lessonDataAnalysisCluster.ToJsonString());
  534. LessonDataAnalysisModel analysisModel = new LessonDataAnalysisModel();
  535. analysisModel.task= lessonDataAnalysisCluster.task.GroupBy(x =>Math.Ceiling(x)).Select(x => new KeyValuePair<double, int>(x.Key, x.ToList().Count)).ToList();
  536. analysisModel.irs= lessonDataAnalysisCluster.irs.GroupBy(x => Math.Ceiling(x)).Select(x => new KeyValuePair<double, int>(x.Key, x.ToList().Count)).ToList();
  537. analysisModel.interactNormal= lessonDataAnalysisCluster.interactNormal.GroupBy(x => Math.Ceiling(x)).Select(x => new KeyValuePair<double, int>(x.Key, x.ToList().Count)).ToList();
  538. analysisModel.pscore= lessonDataAnalysisCluster.pscore.GroupBy(x => Math.Ceiling(x)).Select(x => new KeyValuePair<double, int>(x.Key, x.ToList().Count)).ToList();
  539. analysisModel.gscore= lessonDataAnalysisCluster.gscore.GroupBy(x => Math.Ceiling(x)).Select(x => new KeyValuePair<double, int>(x.Key, x.ToList().Count)).ToList();
  540. analysisModel.tscore= lessonDataAnalysisCluster.tscore.GroupBy(x => Math.Ceiling(x)).Select(x => new KeyValuePair<double, int>(x.Key, x.ToList().Count)).ToList();
  541. analysisModel.stuCowork= lessonDataAnalysisCluster.stuCowork.GroupBy(x => Math.Ceiling(x)).Select(x => new KeyValuePair<double, int>(x.Key, x.ToList().Count)).ToList();
  542. analysisModel.groupCowork= lessonDataAnalysisCluster.groupCowork.GroupBy(x => Math.Ceiling(x)).Select(x => new KeyValuePair<double, int>(x.Key, x.ToList().Count)).ToList();
  543. analysisModel.interactPass= lessonDataAnalysisCluster.interactPass;
  544. analysisModel.interactGood= lessonDataAnalysisCluster.interactGood;
  545. analysisModel.interactLow= lessonDataAnalysisCluster.interactLow;
  546. analysisModel.interactMedium= lessonDataAnalysisCluster.interactMedium;
  547. analysisModel.interactHigh= lessonDataAnalysisCluster.interactHigh;
  548. analysisModel.levelInteract= lessonDataAnalysisCluster.levelInteract;
  549. await azureStorage.GetBlobContainerClient("0-public").UploadFileByContainer(analysisModel.ToJsonString(), "lesson", $"analysis/analysis-model.json");
  550. System.IO.File.WriteAllText(Path.Combine(pathAnalysis, "analysis-model.json"), analysisModel.ToJsonString());
  551. }
  552. /// <summary>
  553. ///
  554. /// </summary>
  555. /// <param name="azureCosmos"></param>
  556. /// <param name="item"></param>
  557. /// <param name="pathLessons"></param>
  558. /// <param name="ignore"></param>
  559. /// <param name="objectiveTypes"></param>
  560. /// <param name="azureStorage"></param>
  561. /// <param name="force"></param>
  562. /// <returns></returns>
  563. public static async Task<TechCount> GetTeachCount(AzureCosmosFactory azureCosmos, string item, string pathLessons, List<string> ignore, List<string> objectiveTypes, AzureStorageFactory azureStorage, bool force)
  564. {
  565. List<TechCount> techCounts = new List<TechCount>();
  566. if (item.EndsWith("-local.json"))
  567. {
  568. string lessonId = item.Split("\\").Last().Replace("-local.json", "");
  569. string countFile = item.Replace("-local.json", "-count.json");
  570. TechCount count = null;
  571. if (!force)
  572. {
  573. if (System.IO.File.Exists(countFile))
  574. {
  575. string contjson = await System.IO.File.ReadAllTextAsync(countFile);
  576. count = contjson.ToObject<TechCount>();
  577. }
  578. else
  579. {
  580. force=true;
  581. }
  582. }
  583. if (force)
  584. {
  585. string localjson = await System.IO.File.ReadAllTextAsync(item);
  586. var lessonLocal = localjson.ToObject<LessonLocal>();
  587. List<StudentLessonData> studentLessonDatas = lessonLocal.studentLessonDatas.ToJsonString().ToObject<List<StudentLessonData>>();
  588. studentLessonDatas = LessonETLService.GetBaseInfo(lessonLocal.lessonBase!, studentLessonDatas, lessonLocal?.lessonRecord?.id);
  589. studentLessonDatas = LessonETLService.GetIRSData(lessonLocal.lessonBase!, lessonLocal.timeLineData!, lessonLocal.irsDatas, studentLessonDatas, lessonLocal.examDatas, lessonLocal.lessonRecord.id);
  590. studentLessonDatas = LessonETLService.GetCoworkData(lessonLocal.lessonBase!, lessonLocal.timeLineData!, lessonLocal.coworkDatas, studentLessonDatas, lessonLocal.lessonRecord.id);
  591. studentLessonDatas = LessonETLService.GetExamData(lessonLocal.lessonBase!, lessonLocal.timeLineData!, lessonLocal.examDatas, studentLessonDatas, objectiveTypes, lessonLocal.lessonRecord.id);
  592. studentLessonDatas = LessonETLService.GetSmartRatingData(lessonLocal.lessonBase!, lessonLocal.timeLineData!, lessonLocal.smartRatingDatas, studentLessonDatas, lessonLocal.lessonRecord.id);
  593. studentLessonDatas = LessonETLService.GetTaskData(lessonLocal.lessonBase!, lessonLocal.timeLineData!, lessonLocal.taskDatas, studentLessonDatas, lessonLocal.lessonRecord.id);
  594. var pickupData = LessonETLService.GetPickupData(lessonLocal.lessonBase!, lessonLocal.timeLineData!, studentLessonDatas, lessonLocal.lessonRecord.id);
  595. studentLessonDatas= pickupData.studentLessonDatas;
  596. var codeBools = LessonETLService.GetCodeBools(studentLessonDatas);
  597. string yearMonth = DateTimeOffset.FromUnixTimeMilliseconds(lessonLocal.lessonRecord.startTime).ToString("yyyyMM");
  598. if (codeBools.FindAll(x => x.value).IsNotEmpty())
  599. {
  600. if (count==null) { count= new TechCount(); }
  601. count.lessonId=item.Split("\\").Last().Replace("-local.json", "");
  602. count.examCount= lessonLocal.examDatas.Count;
  603. count.taskCount= lessonLocal.taskDatas.Count;
  604. count.irsCount= lessonLocal.irsDatas.Count;
  605. count.interactNormalCount=count.irsCount;
  606. count.coworkCount= lessonLocal.coworkDatas.Count;
  607. count.smartRatingCount= lessonLocal.smartRatingDatas.Count;
  608. count.timeCount=lessonLocal.sokratesDatas.Where(x => !ignore.Contains(x.Event) && !x.Event.Contains("End", StringComparison.OrdinalIgnoreCase)).GroupBy(x => x.Event).Select(x => new CodeLong() { code=x.Key, value= x.ToList().Count }).ToList();
  609. if (lessonLocal.lessonRecord!=null)
  610. {
  611. count.yearMonth=yearMonth;
  612. if (lessonLocal?.lessonBase?.summary!=null)
  613. {
  614. count.smartRatingCountBase=lessonLocal.lessonBase.summary.smartRatingCount;
  615. count.irsCountBase=lessonLocal.lessonBase.summary.interactionCount;
  616. count.taskCountBase=lessonLocal.lessonBase.summary.collateTaskCount;
  617. count.coworkCountBase=lessonLocal.lessonBase.summary.coworkTaskCount;
  618. count.examCountBase=lessonLocal.lessonBase.summary.examCount;
  619. count.interactNormalCountBase= count.interactNormalCount;
  620. }
  621. if (lessonLocal?.lessonBase?.report?.clientSummaryList!=null)
  622. {
  623. count.pscore= lessonLocal.lessonBase.report.clientSummaryList.Where(x => x.score>0).Select(x => x.score);
  624. count.gscore= lessonLocal.lessonBase.report.clientSummaryList.Where(x => x.groupScore>0).Select(x => x.groupScore);
  625. count.tscore= lessonLocal.lessonBase.report.clientSummaryList.Where(x => x.interactScore>0).Select(x => x.interactScore);
  626. }
  627. {
  628. count.pickup= pickupData.pickup;
  629. // var techCount = techCounts.Find(x => !string.IsNullOrWhiteSpace(x.lessonId) && !string.IsNullOrWhiteSpace(lessonLocal?.lessonRecord?.id) && x.lessonId.Equals(lessonLocal.lessonRecord.id));
  630. int sumUpload = 0;
  631. int taskCount = 0;
  632. int maxUpload = 0;
  633. HashSet<string> pickUp = new HashSet<string>();
  634. foreach (var stu in studentLessonDatas)
  635. {
  636. var countS = stu.taskRecord.itemRecords.Where(x => x.optCount>0);
  637. if (countS.Count()>0)
  638. {
  639. int stuUploadmax = stu.taskRecord.itemRecords.Where(x => x.optCount>0).Max(x => x.optCount);
  640. if (stuUploadmax> maxUpload)
  641. {
  642. maxUpload=stuUploadmax;
  643. }
  644. }
  645. int stuUpload = stu.taskRecord.itemRecords.Where(x => x.optCount>0).Sum(x => x.optCount);
  646. sumUpload+=stuUpload;
  647. if (stu.taskRecord.itemRecords.Count()> taskCount)
  648. {
  649. taskCount=stu.taskRecord.itemRecords.Count();
  650. }
  651. var stu_scores = stu.coworkRecord.itemRecords.Where(x => x.itemScore>0).Select(x => x.itemScore);
  652. if (stu_scores!=null && stu_scores.Count()>0)
  653. {
  654. count.stuCowork.AddRange(stu_scores);
  655. }
  656. var grp_scores = stu.group_coworkScore.Where(x => x>0);
  657. if (grp_scores!=null && grp_scores.Count()>0)
  658. {
  659. count.groupCowork.AddRange(grp_scores);
  660. }
  661. //if (stu.pickups.IsNotEmpty())
  662. //{
  663. // foreach (var pickup in stu.pickups)
  664. // {
  665. // pickUp.Add(pickup);
  666. // }
  667. //}
  668. }
  669. if (studentLessonDatas.Count>0&& taskCount>0 && maxUpload>0)
  670. {
  671. var avgUpload = sumUpload*1.0/(studentLessonDatas.Count *taskCount);
  672. count.upload.Add(new List<double>() { avgUpload, maxUpload });
  673. }
  674. //if (pickUp.Count>0)
  675. //{
  676. // count.pickup.AddRange(pickUp.ToList());
  677. //}
  678. string owner = lessonLocal.lessonRecord.scope.Equals("school") ? lessonLocal.lessonRecord.school : lessonLocal.lessonRecord.tmdid;
  679. await System.IO.File.WriteAllTextAsync($"{pathLessons}\\MM{count.yearMonth}\\{lessonLocal.lessonRecord.id}-count.json", count.ToJsonString());
  680. //if (force)
  681. //{
  682. //}
  683. //else
  684. //{
  685. // if (lessonRecords.FindAll(x => x.id.Equals(lessonLocal.lessonRecord.id)).IsNotEmpty())
  686. // {
  687. // // await System.IO.File.WriteAllTextAsync($"{pathLessons}\\MM{count.yearMonth}\\{lessonLocal.lessonRecord.id}-stu.json", studentLessonDatas.ToJsonString());
  688. // //只有不是强制更新的时候再去刷新线上的json文件。
  689. // await azureStorage.GetBlobContainerClient(owner).UploadFileByContainer(studentLessonDatas.ToJsonString(), "records", $"{lessonLocal.lessonRecord.id}/student-analysis.json");
  690. // await System.IO.File.WriteAllTextAsync($"{pathLessons}\\MM{count.yearMonth}\\{lessonLocal.lessonRecord.id}-count.json", count.ToJsonString());
  691. // }
  692. //}
  693. }
  694. }
  695. }
  696. else
  697. {
  698. lessonLocal.lessonRecord.analysis=-1;
  699. if (lessonLocal.lessonRecord.scope.Equals("school"))
  700. {
  701. await azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).UpsertItemAsync(lessonLocal.lessonRecord, new PartitionKey(lessonLocal.lessonRecord.code));
  702. }
  703. else
  704. {
  705. await azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(lessonLocal.lessonRecord, new PartitionKey(lessonLocal.lessonRecord.code));
  706. }
  707. try
  708. {
  709. System.IO.File.Delete($"{pathLessons}\\MM{yearMonth}\\{lessonLocal.lessonRecord!.id}-local.json");
  710. }
  711. catch (Exception ex) { }
  712. try
  713. {
  714. System.IO.File.Delete($"{pathLessons}\\MM{yearMonth}\\{lessonLocal.lessonRecord!.id}-count.json");
  715. }
  716. catch (Exception ex) { }
  717. }
  718. }
  719. if (count!=null)
  720. {
  721. return count;
  722. }
  723. }
  724. return null;
  725. }
  726. public static async IAsyncEnumerable<TechCount> GetTeachCount(AzureCosmosFactory azureCosmos,List<LessonRecord> lessonRecords, List<string> filesLessons, string pathLessons, List<string> ignore, List<string> objectiveTypes, AzureStorageFactory azureStorage,bool force)
  727. {
  728. List<TechCount> techCounts = new List<TechCount>();
  729. foreach (var item in filesLessons)
  730. {
  731. if (item.EndsWith("-local.json"))
  732. {
  733. string lessonId = item.Split("\\").Last().Replace("-local.json", "");
  734. string countFile = item.Replace("-local.json", "-count.json");
  735. TechCount count = null;
  736. if (!force)
  737. {
  738. if (System.IO.File.Exists(countFile))
  739. {
  740. string contjson = await System.IO.File.ReadAllTextAsync(countFile);
  741. count = contjson.ToObject<TechCount>();
  742. }
  743. else
  744. {
  745. force=true;
  746. }
  747. }
  748. if (force)
  749. {
  750. string localjson = await System.IO.File.ReadAllTextAsync(item);
  751. var lessonLocal = localjson.ToObject<LessonLocal>();
  752. List<StudentLessonData> studentLessonDatas = lessonLocal.studentLessonDatas.ToJsonString().ToObject<List<StudentLessonData>>();
  753. studentLessonDatas = LessonETLService.GetBaseInfo(lessonLocal.lessonBase!, studentLessonDatas, lessonLocal?.lessonRecord?.id);
  754. studentLessonDatas = LessonETLService.GetIRSData(lessonLocal.lessonBase!, lessonLocal.timeLineData!, lessonLocal.irsDatas, studentLessonDatas, lessonLocal.examDatas, lessonLocal.lessonRecord.id);
  755. studentLessonDatas = LessonETLService.GetCoworkData(lessonLocal.lessonBase!, lessonLocal.timeLineData!, lessonLocal.coworkDatas, studentLessonDatas, lessonLocal.lessonRecord.id);
  756. studentLessonDatas = LessonETLService.GetExamData(lessonLocal.lessonBase!, lessonLocal.timeLineData!, lessonLocal.examDatas, studentLessonDatas, objectiveTypes, lessonLocal.lessonRecord.id);
  757. studentLessonDatas = LessonETLService.GetSmartRatingData(lessonLocal.lessonBase!, lessonLocal.timeLineData!, lessonLocal.smartRatingDatas, studentLessonDatas, lessonLocal.lessonRecord.id);
  758. studentLessonDatas = LessonETLService.GetTaskData(lessonLocal.lessonBase!, lessonLocal.timeLineData!, lessonLocal.taskDatas, studentLessonDatas, lessonLocal.lessonRecord.id);
  759. var pickupData = LessonETLService.GetPickupData(lessonLocal.lessonBase!, lessonLocal.timeLineData!, studentLessonDatas, lessonLocal.lessonRecord.id);
  760. studentLessonDatas= pickupData.studentLessonDatas;
  761. var codeBools = LessonETLService.GetCodeBools(studentLessonDatas);
  762. string yearMonth=DateTimeOffset.FromUnixTimeMilliseconds(lessonLocal.lessonRecord.startTime).ToString("yyyyMM");
  763. if (codeBools.FindAll(x => x.value).IsNotEmpty())
  764. {
  765. if (count==null) { count= new TechCount(); }
  766. count.lessonId=item.Split("\\").Last().Replace("-local.json", "");
  767. count.examCount= lessonLocal.examDatas.Count;
  768. count.taskCount= lessonLocal.taskDatas.Count;
  769. count.irsCount= lessonLocal.irsDatas.Count;
  770. count.interactNormalCount=count.irsCount;
  771. count.coworkCount= lessonLocal.coworkDatas.Count;
  772. count.smartRatingCount= lessonLocal.smartRatingDatas.Count;
  773. count.timeCount=lessonLocal.sokratesDatas.Where(x => !ignore.Contains(x.Event) && !x.Event.Contains("End", StringComparison.OrdinalIgnoreCase)).GroupBy(x => x.Event).Select(x => new CodeLong() { code=x.Key, value= x.ToList().Count }).ToList();
  774. if (lessonLocal.lessonRecord!=null)
  775. {
  776. count.yearMonth=yearMonth;
  777. if (lessonLocal?.lessonBase?.summary!=null)
  778. {
  779. count.smartRatingCountBase=lessonLocal.lessonBase.summary.smartRatingCount;
  780. count.irsCountBase=lessonLocal.lessonBase.summary.interactionCount;
  781. count.taskCountBase=lessonLocal.lessonBase.summary.collateTaskCount;
  782. count.coworkCountBase=lessonLocal.lessonBase.summary.coworkTaskCount;
  783. count.examCountBase=lessonLocal.lessonBase.summary.examCount;
  784. count.interactNormalCountBase= count.interactNormalCount;
  785. }
  786. if (lessonLocal?.lessonBase?.report?.clientSummaryList!=null)
  787. {
  788. count.pscore= lessonLocal.lessonBase.report.clientSummaryList.Where(x => x.score>0).Select(x => x.score);
  789. count.gscore= lessonLocal.lessonBase.report.clientSummaryList.Where(x => x.groupScore>0).Select(x => x.groupScore);
  790. count.tscore= lessonLocal.lessonBase.report.clientSummaryList.Where(x => x.interactScore>0).Select(x => x.interactScore);
  791. }
  792. {
  793. count.pickup= pickupData.pickup;
  794. // var techCount = techCounts.Find(x => !string.IsNullOrWhiteSpace(x.lessonId) && !string.IsNullOrWhiteSpace(lessonLocal?.lessonRecord?.id) && x.lessonId.Equals(lessonLocal.lessonRecord.id));
  795. int sumUpload = 0;
  796. int taskCount = 0;
  797. int maxUpload = 0;
  798. HashSet<string> pickUp = new HashSet<string>();
  799. foreach (var stu in studentLessonDatas)
  800. {
  801. var countS = stu.taskRecord.itemRecords.Where(x => x.optCount>0);
  802. if (countS.Count()>0)
  803. {
  804. int stuUploadmax = stu.taskRecord.itemRecords.Where(x => x.optCount>0).Max(x => x.optCount);
  805. if (stuUploadmax> maxUpload)
  806. {
  807. maxUpload=stuUploadmax;
  808. }
  809. }
  810. int stuUpload = stu.taskRecord.itemRecords.Where(x => x.optCount>0).Sum(x => x.optCount);
  811. sumUpload+=stuUpload;
  812. if (stu.taskRecord.itemRecords.Count()> taskCount)
  813. {
  814. taskCount=stu.taskRecord.itemRecords.Count();
  815. }
  816. var stu_scores = stu.coworkRecord.itemRecords.Where(x => x.itemScore>0).Select(x => x.itemScore);
  817. if (stu_scores!=null && stu_scores.Count()>0)
  818. {
  819. count.stuCowork.AddRange(stu_scores);
  820. }
  821. var grp_scores = stu.group_coworkScore.Where(x => x>0);
  822. if (grp_scores!=null && grp_scores.Count()>0)
  823. {
  824. count.groupCowork.AddRange(grp_scores);
  825. }
  826. //if (stu.pickups.IsNotEmpty())
  827. //{
  828. // foreach (var pickup in stu.pickups)
  829. // {
  830. // pickUp.Add(pickup);
  831. // }
  832. //}
  833. }
  834. if (studentLessonDatas.Count>0&& taskCount>0 && maxUpload>0)
  835. {
  836. var avgUpload = sumUpload*1.0/(studentLessonDatas.Count *taskCount);
  837. count.upload.Add(new List<double>() { avgUpload, maxUpload });
  838. }
  839. //if (pickUp.Count>0)
  840. //{
  841. // count.pickup.AddRange(pickUp.ToList());
  842. //}
  843. string owner = lessonLocal.lessonRecord.scope.Equals("school") ? lessonLocal.lessonRecord.school : lessonLocal.lessonRecord.tmdid;
  844. await System.IO.File.WriteAllTextAsync($"{pathLessons}\\MM{count.yearMonth}\\{lessonLocal.lessonRecord.id}-count.json", count.ToJsonString());
  845. //if (force)
  846. //{
  847. //}
  848. //else
  849. //{
  850. // if (lessonRecords.FindAll(x => x.id.Equals(lessonLocal.lessonRecord.id)).IsNotEmpty())
  851. // {
  852. // // await System.IO.File.WriteAllTextAsync($"{pathLessons}\\MM{count.yearMonth}\\{lessonLocal.lessonRecord.id}-stu.json", studentLessonDatas.ToJsonString());
  853. // //只有不是强制更新的时候再去刷新线上的json文件。
  854. // await azureStorage.GetBlobContainerClient(owner).UploadFileByContainer(studentLessonDatas.ToJsonString(), "records", $"{lessonLocal.lessonRecord.id}/student-analysis.json");
  855. // await System.IO.File.WriteAllTextAsync($"{pathLessons}\\MM{count.yearMonth}\\{lessonLocal.lessonRecord.id}-count.json", count.ToJsonString());
  856. // }
  857. //}
  858. }
  859. }
  860. }
  861. else
  862. {
  863. lessonLocal.lessonRecord.analysis=-1;
  864. if (lessonLocal.lessonRecord.scope.Equals("school"))
  865. {
  866. await azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).UpsertItemAsync(lessonLocal.lessonRecord, new PartitionKey(lessonLocal.lessonRecord.code));
  867. }
  868. else
  869. {
  870. await azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(lessonLocal.lessonRecord, new PartitionKey(lessonLocal.lessonRecord.code));
  871. }
  872. try
  873. {
  874. System.IO.File.Delete($"{pathLessons}\\MM{yearMonth}\\{lessonLocal.lessonRecord!.id}-local.json");
  875. }
  876. catch (Exception ex) { }
  877. try
  878. {
  879. System.IO.File.Delete($"{pathLessons}\\MM{yearMonth}\\{lessonLocal.lessonRecord!.id}-count.json");
  880. }
  881. catch (Exception ex) { }
  882. }
  883. }
  884. if (count!=null)
  885. {
  886. yield return count;
  887. }
  888. }
  889. }
  890. }
  891. public static List<StudentLessonData> GetBaseInfo(LessonBase lessonBase, List<StudentLessonData> studentLessonDatas, string? id)
  892. {
  893. if (lessonBase?.report?.clientSummaryList !=null && lessonBase.report.clientSummaryList.IsNotEmpty())
  894. {
  895. foreach (var item in lessonBase.report.clientSummaryList)
  896. {
  897. var student = studentLessonDatas.Find(x => x.seatID!=null && x.seatID.Equals($"{item.seatID}"));
  898. if (student!= null)
  899. {
  900. student.gscore= item.groupScore;
  901. student.tscore= item.interactScore;
  902. student.pscore= item.score;
  903. }
  904. }
  905. }
  906. return studentLessonDatas;
  907. }
  908. /// <summary>
  909. ///
  910. /// </summary>
  911. /// <param name="lessonRecord"></param>
  912. /// <param name="localIds"></param>
  913. /// <param name="_azureStorage"></param>
  914. /// <param name="pathLessons"></param>
  915. /// <returns></returns>
  916. public static async Task<LessonLocal> GetLessonLocal(LessonRecord lessonRecord, List<string> localIds, AzureStorageFactory _azureStorage, string pathLessons)
  917. {
  918. string scope = lessonRecord.scope;
  919. string owner = lessonRecord.scope.Equals("school") ? lessonRecord.school : lessonRecord.tmdid;
  920. string yearMonthPath = DateTimeOffset.FromUnixTimeMilliseconds(lessonRecord.startTime).ToString("yyyyMM");
  921. LessonLocal lessonLocal = null;
  922. if (System.IO.File.Exists($"{pathLessons}\\MM{yearMonthPath}\\{lessonRecord.id}-local.json"))
  923. {
  924. string jsonp = await System.IO.File.ReadAllTextAsync($"{pathLessons}\\MM{yearMonthPath}\\{lessonRecord.id}-local.json");
  925. lessonLocal = jsonp.ToObject<LessonLocal>();
  926. }
  927. else
  928. {
  929. lessonLocal= new LessonLocal { lessonRecord=lessonRecord };
  930. List<string> files = new List<string>()
  931. {
  932. $"/records/{lessonRecord.id}/IES/TimeLine.json",
  933. $"/records/{lessonRecord.id}/IES/base.json",
  934. $"/records/{lessonRecord.id}/IES/Task.json",
  935. $"/records/{lessonRecord.id}/IES/SmartRating.json",
  936. $"/records/{lessonRecord.id}/IES/IRS.json",
  937. $"/records/{lessonRecord.id}/IES/Cowork.json",
  938. $"/records/{lessonRecord.id}/Sokrates/SokratesRecords.json",
  939. };
  940. lessonLocal = new LessonLocal { lessonRecord=lessonRecord };
  941. lessonLocal = await GetLessonFiles(lessonLocal, files, owner, _azureStorage);
  942. if (lessonLocal.lessonBase!=null && lessonLocal.lessonBase.student!=null)
  943. {
  944. var baseData = GetBaseData(lessonLocal.lessonBase!);
  945. lessonLocal.studentLessonDatas= baseData.studentLessonDatas;
  946. List<ExamData> examDatas = await GetExamInfo(lessonRecord, lessonLocal.timeLineData, _azureStorage, owner);
  947. lessonLocal.examDatas = examDatas;
  948. lessonLocal.sokratesDatas= lessonLocal.sokratesDatas.IsNotEmpty() ? lessonLocal.sokratesDatas : lessonLocal.timeLineData!=null ? lessonLocal.timeLineData.events : new List<TimeLineEvent>();
  949. }
  950. }
  951. return lessonLocal;
  952. }
  953. public static async IAsyncEnumerable<LessonLocal> GetLessonLocal(List<LessonRecord> lessonRecords, List<string> localIds, AzureStorageFactory _azureStorage, string pathLessons)
  954. {
  955. foreach (var lessonRecord in lessonRecords)
  956. {
  957. string scope = lessonRecord.scope;
  958. string owner = lessonRecord.scope.Equals("school") ? lessonRecord.school : lessonRecord.tmdid;
  959. string yearMonthPath = DateTimeOffset.FromUnixTimeMilliseconds(lessonRecord.startTime).ToString("yyyyMM");
  960. LessonLocal lessonLocal = new LessonLocal { lessonRecord=lessonRecord };
  961. if (System.IO.File.Exists($"{pathLessons}\\MM{yearMonthPath}\\{lessonRecord.id}-local.json"))
  962. {
  963. string jsonp = await System.IO.File.ReadAllTextAsync($"{pathLessons}\\MM{yearMonthPath}\\{lessonRecord.id}-local.json");
  964. lessonLocal = jsonp.ToObject<LessonLocal>();
  965. }
  966. else
  967. {
  968. List<string> files = new List<string>()
  969. {
  970. $"/records/{lessonRecord.id}/IES/TimeLine.json",
  971. $"/records/{lessonRecord.id}/IES/base.json",
  972. $"/records/{lessonRecord.id}/IES/Task.json",
  973. $"/records/{lessonRecord.id}/IES/SmartRating.json",
  974. $"/records/{lessonRecord.id}/IES/IRS.json",
  975. $"/records/{lessonRecord.id}/IES/Cowork.json",
  976. $"/records/{lessonRecord.id}/Sokrates/SokratesRecords.json",
  977. };
  978. lessonLocal = new LessonLocal { lessonRecord=lessonRecord };
  979. lessonLocal = await GetLessonFiles(lessonLocal, files, owner, _azureStorage);
  980. if (lessonLocal.lessonBase!=null && lessonLocal.lessonBase.student!=null)
  981. {
  982. var baseData = GetBaseData(lessonLocal.lessonBase!);
  983. lessonLocal.studentLessonDatas= baseData.studentLessonDatas;
  984. List<ExamData> examDatas = await GetExamInfo(lessonRecord, lessonLocal.timeLineData, _azureStorage, owner);
  985. lessonLocal.examDatas = examDatas;
  986. lessonLocal.sokratesDatas= lessonLocal.sokratesDatas.IsNotEmpty() ? lessonLocal.sokratesDatas : lessonLocal.timeLineData!=null ? lessonLocal.timeLineData.events : new List<TimeLineEvent>();
  987. }
  988. }
  989. yield return lessonLocal;
  990. }
  991. }
  992. private static async Task<LessonLocal> GetLessonFiles(LessonLocal lessonLocal, List<string> files, string owner, AzureStorageFactory _azureStorage)
  993. {
  994. await Parallel.ForEachAsync(files, async (file, _) =>
  995. {
  996. try
  997. {
  998. var exists = _azureStorage.GetBlobContainerClient(owner).GetBlobClient(file).Exists();
  999. if (exists)
  1000. {
  1001. BlobDownloadResult blobDownloadResult = await _azureStorage.GetBlobContainerClient(owner).GetBlobClient(file).DownloadContentAsync();
  1002. switch (true)
  1003. {
  1004. case bool when file.Contains("IES/TimeLine.json"):
  1005. lessonLocal.timeLineData= blobDownloadResult.Content.ToObjectFromJson<TimeLineData>();
  1006. break;
  1007. case bool when file.Contains("IES/base.json"):
  1008. lessonLocal.lessonBase= blobDownloadResult.Content.ToObjectFromJson<LessonBase>();
  1009. break;
  1010. case bool when file.Contains("IES/Task.json"):
  1011. lessonLocal.taskDatas= blobDownloadResult.Content.ToObjectFromJson<List<TaskData>>();
  1012. break;
  1013. case bool when file.Contains("IES/SmartRating.json"):
  1014. lessonLocal.smartRatingDatas= blobDownloadResult.Content.ToObjectFromJson<List<SmartRatingData>>();
  1015. break;
  1016. case bool when file.Contains("IES/IRS.json"):
  1017. lessonLocal.irsDatas= blobDownloadResult.Content.ToObjectFromJson<List<IRSData>>();
  1018. break;
  1019. case bool when file.Contains("IES/Cowork.json"):
  1020. lessonLocal.coworkDatas= blobDownloadResult.Content.ToObjectFromJson<List<CoworkData>>();
  1021. break;
  1022. case bool when file.Contains("Sokrates/SokratesRecords.json"):
  1023. lessonLocal.sokratesDatas= blobDownloadResult.Content.ToObjectFromJson<List<TimeLineEvent>>();
  1024. break;
  1025. }
  1026. }
  1027. }
  1028. catch (RequestFailedException ex)
  1029. {
  1030. Console.WriteLine($"{file},{ex.Message},{ex.StackTrace}");
  1031. }
  1032. catch (Exception ex)
  1033. {
  1034. Console.WriteLine($"{file},{ex.Message},{ex.StackTrace}");
  1035. }
  1036. });
  1037. return lessonLocal;
  1038. }
  1039. /// <summary>
  1040. /// 处理base.json的数据
  1041. /// </summary>
  1042. /// <param name="lessonRecord"></param>
  1043. /// <param name="lessonBase"></param>
  1044. /// <returns></returns>
  1045. public static (LessonBase lessonBase, List<LocalStudent> studentLessonDatas) GetBaseData(LessonBase lessonBase)
  1046. {
  1047. //处理学生定位数据
  1048. List<LocalStudent> studentLessonDatas = new List<LocalStudent>();
  1049. int index = 0;
  1050. try
  1051. {
  1052. if (lessonBase!=null)
  1053. {
  1054. lessonBase.student.ForEach(x =>
  1055. {
  1056. int attend = 0;
  1057. var client = lessonBase.report.clientSummaryList.Find(y => y.seatID == x.seatID);
  1058. if (client!=null)
  1059. {
  1060. attend=client.attendState;
  1061. }
  1062. studentLessonDatas.Add(new LocalStudent()
  1063. {
  1064. id = x.id,
  1065. index = index,
  1066. seatID =$"{x.seatID}",
  1067. groupId = x.groupId,
  1068. attend= attend
  1069. });
  1070. index++;
  1071. });
  1072. }
  1073. }
  1074. catch (Exception ex)
  1075. {
  1076. Console.WriteLine(lessonBase.ToJsonString());
  1077. }
  1078. return (lessonBase, studentLessonDatas);
  1079. }
  1080. /// <summary>
  1081. ///单独处理挑人的逻辑
  1082. ///是否从小组里面挑人。
  1083. ///不需要去重页面,直接获取挑人大类 PickupResult
  1084. ///小类处理:PickupRight , PickupOption , PickupNthGrp ,PickupEachGrp ,PickupDiff , PickupResult 挑人算不算互动?? 读取PickupMemberId "[\r\n 35\r\n]"
  1085. /// </summary>
  1086. /// <param name="lessonBase"></param>
  1087. /// <param name="timeLineData"></param>
  1088. /// <param name="studentLessonDatas"></param>
  1089. /// <param name="lessonId"></param>
  1090. /// <returns></returns>
  1091. public static (List<StudentLessonData> studentLessonDatas, List<string> pickup) GetPickupData(LessonBase lessonBase, TimeLineData timeLineData, List<StudentLessonData> studentLessonDatas, string lessonId)
  1092. {
  1093. var enventsPickup = timeLineData?.events.Where(x => !string.IsNullOrWhiteSpace(x.Pgid) && x.Event.Equals("PickupResult"));
  1094. List<string> pickup = new List<string>();
  1095. if (enventsPickup.IsNotEmpty())
  1096. {
  1097. foreach (var item in enventsPickup)
  1098. {
  1099. List<int> mbrs = item.PickupMemberId.ToObject<List<int>>();
  1100. // 挑人挑中 TT ,没有挑中 T1
  1101. foreach (var studentLessonData in studentLessonDatas)
  1102. {
  1103. var mbr = mbrs.FindAll(x => studentLessonData.seatID!.Equals($"{x}"));
  1104. if (mbr.IsNotEmpty())
  1105. {
  1106. foreach (var m in mbr)
  1107. {
  1108. studentLessonData.attend=1;
  1109. //studentLessonData.interactRecord.interactRecords.Add(new ItemRecord()
  1110. //{
  1111. // resultWeight = InteractWeight.TT,
  1112. // resultType=InteractReultType.TT,
  1113. // itemType = string.IsNullOrWhiteSpace(item.PickupType) ? "PickupResult" : item.PickupType
  1114. //});
  1115. studentLessonData.pickups.Add(string.IsNullOrWhiteSpace(item.PickupType) ? "1--PickupResult" : $"1--{item.PickupType}");
  1116. }
  1117. }
  1118. else
  1119. {
  1120. //处理未挑中的
  1121. if (studentLessonData.attend==1)
  1122. {
  1123. studentLessonData.pickups.Add(string.IsNullOrWhiteSpace(item.PickupType) ? "0--PickupResult" : $"0--{item.PickupType}");
  1124. }
  1125. }
  1126. }
  1127. pickup.Add(item.PickupType);
  1128. }
  1129. }
  1130. return (studentLessonDatas, pickup);
  1131. }
  1132. /// <summary>
  1133. ///读取互动信息
  1134. ///Event 过滤类型 'PopQuesLoad', 'ReAtmpAnsStrt', 'BuzrAns','BuzrLoad'
  1135. /// 在IRS.json处理 'PopQuesLoad'互动问答 , 'ReAtmpAnsStrt' 二次作答 , 'BuzrAns' 抢权(新), 'BuzrLoad'抢权(旧)
  1136. ///TimeLine.json 中找到对应类型,根据Pgid 去 IRS.json 中找到对应数据,从clientAnswers 的下标对应 base.json 中的 student 找到对应学生信息 clientAnswers.length > 1 则表示有二次作答
  1137. ///读取IRS.json
  1138. /// </summary>
  1139. /// <param name="lessonBase"></param>
  1140. /// <param name="timeLineData"></param>
  1141. /// <param name="irsDatas"></param>
  1142. /// <param name="studentLessonDatas"></param>
  1143. /// <param name="examDatas"></param>
  1144. /// <param name="itemFiles"></param>
  1145. /// <returns></returns>
  1146. public static List<StudentLessonData> GetIRSData(LessonBase lessonBase, TimeLineData timeLineData, List<IRSData> irsDatas, List<StudentLessonData> studentLessonDatas, List<ExamData> examDatas, string lessonId)
  1147. {
  1148. List<string> interactTypes = new List<string>() { "PopQuesLoad", "ReAtmpAnsStrt", "BuzrAns", "BuzrLoad" };
  1149. //去重页面
  1150. var enventsInteract = timeLineData?.events?.Where(x => !string.IsNullOrWhiteSpace(x.Pgid) && interactTypes.Contains(x.Event)).GroupBy(x => x.Pgid).Select(x => new { key = x.Key, list = x.ToList() });
  1151. if (enventsInteract!= null && enventsInteract.Count()>0)
  1152. {
  1153. var keys = enventsInteract.Select(x => x.key).ToList();
  1154. foreach (var item in enventsInteract)
  1155. {
  1156. ProcessIRSPageData(irsDatas, studentLessonDatas, examDatas, item);
  1157. }
  1158. //处理其他,评测类型的互动,因为有可能不会记录在TimeLine.json中
  1159. var envents_other = timeLineData.events.Where(x => !string.IsNullOrWhiteSpace(x.Pgid) && !keys.Contains(x.Pgid)).GroupBy(x => x.Pgid).Select(x => new { key = x.Key, list = x.ToList() });
  1160. if (envents_other!=null && envents_other.Count()>0)
  1161. {
  1162. foreach (var item in envents_other)
  1163. {
  1164. ProcessIRSPageData(irsDatas, studentLessonDatas, examDatas, item);
  1165. }
  1166. }
  1167. }
  1168. else
  1169. {
  1170. //处理其他,评测类型的互动,因为有可能不会记录在TimeLine.json中
  1171. if (timeLineData!=null)
  1172. {
  1173. var envents_other = timeLineData.events.Where(x => !string.IsNullOrWhiteSpace(x.Pgid)).GroupBy(x => x.Pgid).Select(x => new { key = x.Key, list = x.ToList() });
  1174. if (envents_other!=null && envents_other.Count()>0)
  1175. {
  1176. foreach (var item in envents_other)
  1177. {
  1178. ProcessIRSPageData(irsDatas, studentLessonDatas, examDatas, item);
  1179. }
  1180. }
  1181. }
  1182. else
  1183. {
  1184. foreach (var item in irsDatas.Select(x => x.pageID))
  1185. {
  1186. ProcessIRSPageData(irsDatas, studentLessonDatas, examDatas, new { key = item });
  1187. }
  1188. }
  1189. }
  1190. return studentLessonDatas;
  1191. }
  1192. private static List<StudentLessonData> ProcessIRSPageData(List<IRSData> irsDatas, List<StudentLessonData> studentLessonDatas, List<ExamData> examDatas, dynamic item)
  1193. {
  1194. var irsDataPages = irsDatas.Where(y => item.key.Equals(y.pageID));
  1195. foreach (var irsDataPage in irsDataPages)
  1196. {
  1197. //检查是否设置正确答案。
  1198. var answers_q = irsDataPage.question?["exercise"]?["answer"]?.ToJsonString().ToObject<List<string>>();
  1199. //根据题去找对应的试卷和评测信息
  1200. var question_id = $"{irsDataPage.question?["id"]}";
  1201. var examData = examDatas.Where(x => x.paper!=null && x.paper.slides.Exists(x => !string.IsNullOrWhiteSpace(x.url) && x.url.Equals($"{question_id}.json"))).FirstOrDefault();
  1202. List<string> answers = new List<string>();
  1203. answers_q?.ForEach(x => {
  1204. if (!string.IsNullOrWhiteSpace(x))
  1205. {
  1206. answers.Add(x);
  1207. }
  1208. });
  1209. var _objective = irsDataPage.question?["exercise"]?["objective"];
  1210. var scoreNode = irsDataPage.question?["exercise"]?["score"];
  1211. var _type = irsDataPage.question?["exercise"]?["type"];
  1212. var _answerType = irsDataPage.question?["exercise"]?["answerType"];//file,audio,text,image
  1213. var qitem = irsDataPage.question?["item"]?.AsArray();
  1214. if (qitem!=null && qitem.Count()>0)
  1215. {
  1216. for (var i = 0; i<qitem.Count(); i++)
  1217. {
  1218. qitem[i]!["question"]="";
  1219. }
  1220. }
  1221. double questionScore = 0;
  1222. bool objective = false;
  1223. if (_objective!=null)
  1224. {
  1225. objective = _objective.GetValue<bool>();
  1226. }
  1227. //题型
  1228. string type = string.Empty;
  1229. if (_type!=null)
  1230. {
  1231. //题型
  1232. type = _type.GetValue<string>();
  1233. List<string> types = new List<string>() { "single", "multiple", "judge", "sortmultiple" };
  1234. if (types.Contains(type))
  1235. {
  1236. objective = true;
  1237. }
  1238. else
  1239. {
  1240. objective = false;
  1241. }
  1242. }
  1243. if (_answerType!=null)
  1244. {
  1245. _answerType.GetValue<string>();
  1246. //暂不处理,可能存在依然传文字的情况
  1247. //不是文本作答的处理,题目不是客观题,答案不记录
  1248. //if (!_answerType.Equals("text"))
  1249. //{
  1250. // objective=false;
  1251. // answers=new List<string>();
  1252. //}
  1253. }
  1254. if (scoreNode!=null)
  1255. {
  1256. double.TryParse(scoreNode.ToString(), out questionScore);
  1257. }
  1258. string interactType = string.Empty;
  1259. if (irsDataPage.clientAnswers.IsNotEmpty())
  1260. {
  1261. //第一个list是几轮,一次作答,二次作答, 第二个list是学生的下标, 第三个list是 答案
  1262. List<List<List<string>>> clientAnswers = new List<List<List<string>>>();
  1263. foreach (var key in irsDataPage.clientAnswers.Keys)
  1264. {
  1265. clientAnswers.Add(irsDataPage.clientAnswers[key]);
  1266. }
  1267. // 获取第一个列表的长度作为比较基准
  1268. int firstListLength = clientAnswers.First().Count;
  1269. bool isSameLength = true;
  1270. // 遍历剩余的列表并检查它们的长度是否与第一个列表相同
  1271. foreach (var innerList in clientAnswers.Skip(1))
  1272. {
  1273. if (innerList.Count != firstListLength)
  1274. {
  1275. isSameLength = false;
  1276. break;
  1277. }
  1278. }
  1279. //并检查学生集合的长度是否与第一个列表相同
  1280. if (isSameLength && studentLessonDatas.Count()==firstListLength)
  1281. {
  1282. for (int index = 0; index< clientAnswers[0].Count; index++)
  1283. {
  1284. var student = studentLessonDatas[index];
  1285. double studentScore = 0;
  1286. if (examData!=null && examData.examClassResult.IsNotEmpty())
  1287. {
  1288. var examResultIndex = examData.examClassResult.First().studentIds.IndexOf(student.id);
  1289. var questionIndex = examData.paper.slides.Select(x => x.url).ToList().IndexOf($"{question_id}.json");
  1290. if (examResultIndex>=0
  1291. && examData.examClassResult.First().studentScores.Count>=(examResultIndex+1) //防止索引越界
  1292. && examData.examClassResult.First().studentScores[examResultIndex].Count>=(questionIndex+1)) //防止索引越界
  1293. {
  1294. //获取index学生在questionIndex题的分数
  1295. studentScore = examData.examClassResult.First().studentScores[examResultIndex][questionIndex];
  1296. }
  1297. }
  1298. //index 代表学生下标
  1299. List<ItemRecord> interactRecords = new List<ItemRecord>();
  1300. if (clientAnswers.Count==1)
  1301. {
  1302. //即问即答
  1303. interactType = "PopQuesLoad";
  1304. var ans0 = clientAnswers[0][index];
  1305. var IS0 = GetInteractResultHasAnswer(answers, ans0, objective, type, questionScore, studentScore);
  1306. interactRecords.Add(new ItemRecord()
  1307. {
  1308. resultWeight = IS0.weight,
  1309. resultType=IS0.reultType,
  1310. itemType= interactType,
  1311. criterion= questionScore,
  1312. itemScore= IS0.interactScore
  1313. });
  1314. }
  1315. if (clientAnswers.Count==2)
  1316. {
  1317. //二次作答
  1318. interactType="ReAtmpAnsStrt";
  1319. var ans1 = clientAnswers[1][index];
  1320. var IS1 = GetInteractResultHasAnswer(answers, ans1, objective, type, questionScore, studentScore);
  1321. interactRecords.Add(new ItemRecord()
  1322. {
  1323. resultWeight = IS1.weight,
  1324. resultType=IS1.reultType,
  1325. itemType= interactType,
  1326. criterion= questionScore,
  1327. itemScore= IS1.interactScore
  1328. });
  1329. }
  1330. if (clientAnswers.Count>2)
  1331. {
  1332. //三次作答
  1333. interactType="TeAtmpAnsStrt";
  1334. var ans2 = clientAnswers[2][index];
  1335. var IS2 = GetInteractResultHasAnswer(answers, ans2, objective, type, questionScore, studentScore);
  1336. interactRecords.Add(new ItemRecord()
  1337. {
  1338. resultWeight = IS2.weight,
  1339. resultType=IS2.reultType,
  1340. itemType= interactType,
  1341. criterion= questionScore,
  1342. itemScore= IS2.interactScore
  1343. });
  1344. }
  1345. if (studentLessonDatas[index].attend==1)
  1346. {
  1347. studentLessonDatas[index].interactRecord.interactRecords.AddRange(interactRecords);
  1348. }
  1349. }
  1350. }
  1351. }
  1352. //是否抢权作答的模式
  1353. if (irsDataPage.isBuzz)
  1354. {
  1355. interactType = "BuzrAns";
  1356. //处理参与抢权的
  1357. Dictionary<string, ItemRecord> buzzParticipants = new Dictionary<string, ItemRecord>();
  1358. foreach (var buzzParticipant in irsDataPage.buzzParticipants)
  1359. {
  1360. var studentData = studentLessonDatas.Find(x => x.seatID!.Equals(buzzParticipant));
  1361. if (studentData != null)
  1362. {
  1363. buzzParticipants[buzzParticipant]=new ItemRecord() { resultWeight = InteractWeight.T1, itemType= interactType, resultType= InteractReultType.T1 };
  1364. }
  1365. }
  1366. //处理抢权成功的
  1367. foreach (var buzzClient in irsDataPage.buzzClients)
  1368. {
  1369. buzzParticipants[buzzClient]=new ItemRecord() { resultWeight = InteractWeight.TT, itemType= interactType, resultType= InteractReultType.TT };
  1370. }
  1371. foreach (var studentLessonData in studentLessonDatas)
  1372. {
  1373. if (buzzParticipants.ContainsKey(studentLessonData.seatID!))
  1374. {
  1375. //处理已经有抢权结果的数据
  1376. studentLessonData.attend=1;
  1377. studentLessonData.interactRecord.interactRecords.Add(buzzParticipants[studentLessonData.seatID!]);
  1378. }
  1379. else
  1380. {
  1381. if (studentLessonData.attend==1)
  1382. {
  1383. //处理未参与抢权的
  1384. studentLessonData.interactRecord.interactRecords.Add(new ItemRecord() { resultWeight = InteractWeight.T0, itemType = interactType, resultType= InteractReultType.T0 });
  1385. }
  1386. }
  1387. }
  1388. }
  1389. }
  1390. return studentLessonDatas;
  1391. }
  1392. private static (double weight, string reultType, double interactScore) GetInteractResultHasAnswer(List<string>? answers, List<string> ans0, bool objective, string type, double questionScore, double studentScore)
  1393. {
  1394. //List<string> ans0 = new List<string>();
  1395. //ans?.ForEach(x => {
  1396. // if (!string.IsNullOrWhiteSpace(x))
  1397. // {
  1398. // ans0.Add(x);
  1399. // }
  1400. // else { ans.Add("");}
  1401. //});
  1402. double weight = InteractWeight.T0;
  1403. string reultType = InteractReultType.T0;
  1404. double interactScore = 0;
  1405. if (answers.IsNotEmpty())
  1406. {
  1407. if (ans0.IsNotEmpty())
  1408. {
  1409. if (objective) //客观题
  1410. {
  1411. //标准答案等于作答的结果
  1412. if (answers!.Count == ans0.Count)
  1413. {
  1414. if (answers.All(item => ans0.Contains(item)))
  1415. {
  1416. //完全正确
  1417. weight= InteractWeight.TT;
  1418. reultType= InteractReultType.TT;
  1419. interactScore= studentScore==0 ? questionScore : studentScore;
  1420. }
  1421. else
  1422. {
  1423. //作答错误
  1424. weight= InteractWeight.T1;
  1425. reultType = InteractReultType.T1;
  1426. interactScore= studentScore;
  1427. }
  1428. }
  1429. //标准答案比作答的结果多
  1430. else if (answers!.Count > ans0.Count)
  1431. {
  1432. if (ans0.All(item => answers.Contains(item)))
  1433. {
  1434. //部分正确
  1435. weight= InteractWeight.TP;
  1436. reultType = InteractReultType.TP;
  1437. // 2 * 0.3 * 10= 6
  1438. interactScore= studentScore==0 ? 1/(InteractWeight.TT-InteractWeight.T1) * (InteractWeight.TP-InteractWeight.T1) * questionScore : studentScore;
  1439. }
  1440. else
  1441. {
  1442. //作答错误
  1443. weight= InteractWeight.T1;
  1444. reultType = InteractReultType.T1;
  1445. interactScore= studentScore;
  1446. }
  1447. }
  1448. //标准答案比作答结果少
  1449. else
  1450. {
  1451. //作答错误
  1452. weight= InteractWeight.T1;
  1453. reultType = InteractReultType.T1;
  1454. interactScore= studentScore;
  1455. }
  1456. }
  1457. else
  1458. {
  1459. //填空题
  1460. if ("complete".Equals(type) && answers!.Count==ans0.Count)
  1461. {
  1462. bool hasT = false;
  1463. bool hasF = false;
  1464. for (int i = 0; i < answers!.Count; i++)
  1465. {
  1466. if (answers[i].Equals(ans0[i]))
  1467. {
  1468. hasT=true;
  1469. }
  1470. else
  1471. {
  1472. hasF=true;
  1473. }
  1474. }
  1475. if (hasT && !hasF)
  1476. {
  1477. //完全正确
  1478. weight= InteractWeight.TT;
  1479. reultType = InteractReultType.TT;
  1480. interactScore= studentScore==0 ? questionScore : studentScore;
  1481. }
  1482. else if (hasT && hasF)
  1483. {
  1484. //部分正确
  1485. weight= InteractWeight.TP;
  1486. reultType = InteractReultType.TP;
  1487. // 2 * 0.3 * 10= 6
  1488. interactScore= studentScore==0 ? 1/(InteractWeight.TT-InteractWeight.T1) * (InteractWeight.TP-InteractWeight.T1) * questionScore : studentScore;
  1489. }
  1490. else if (!hasT && hasF)
  1491. {
  1492. //没有正确的,但有错误的,代表参与了
  1493. weight= InteractWeight.T1;
  1494. reultType = InteractReultType.T1;
  1495. interactScore= studentScore;
  1496. }
  1497. else if (!hasT && !hasF)
  1498. {
  1499. //没有正确的,也没有错误的,代表没有作答
  1500. weight= InteractWeight.T0;
  1501. reultType = InteractReultType.T0;
  1502. interactScore= studentScore;
  1503. }
  1504. }
  1505. else
  1506. {
  1507. //主观题,完全匹配的
  1508. if (answers!.All(item => ans0.Contains(item)))
  1509. {
  1510. //完全正确
  1511. weight= InteractWeight.TT;
  1512. reultType = InteractReultType.TT;
  1513. interactScore= studentScore==0 ? questionScore : studentScore;
  1514. }
  1515. else
  1516. { // 使用LINQ查询来判断是否有匹配的答案
  1517. bool hasMatchingAnswer = answers!.Intersect(ans0).Any();
  1518. if (hasMatchingAnswer)
  1519. {
  1520. //主观题回答正确即为完全正确
  1521. weight= InteractWeight.TT;
  1522. reultType = InteractReultType.TT;
  1523. interactScore= studentScore==0 ? questionScore : studentScore;
  1524. }
  1525. else
  1526. {
  1527. //优先根据得分与标准分的占比算出得分率,如果没有得分率,如果是直接从互动,不知道是评测的 需要先去评测找作答得分。,则采用Levenshtein距离来评估两个字符串的相似度
  1528. //没有匹配上答案,则采用Levenshtein距离来评估两个字符串的相似度
  1529. if (questionScore>0)
  1530. {
  1531. if (studentScore>0)
  1532. {
  1533. weight = studentScore * 1.0 / questionScore* (InteractWeight.TT-InteractWeight.T1);
  1534. if (weight==InteractWeight.T1)
  1535. {
  1536. reultType = InteractReultType.T1;
  1537. interactScore=studentScore;
  1538. }
  1539. else if (weight>InteractWeight.TT)
  1540. {
  1541. reultType = InteractReultType.TT;
  1542. interactScore=studentScore==0 ? questionScore : studentScore;
  1543. }
  1544. else
  1545. {
  1546. reultType = InteractReultType.TP;
  1547. // 2 * 0.3 * 10= 6
  1548. interactScore= studentScore==0 ? 1/(InteractWeight.TT-InteractWeight.T1) * (InteractWeight.TP-InteractWeight.T1) * questionScore : studentScore;
  1549. }
  1550. }
  1551. else
  1552. {
  1553. weight=InteractWeight.T1+(CalculateSimilarity(answers![0], ans0[0]) *(InteractWeight.TT-InteractWeight.T1));
  1554. if (weight==InteractWeight.T1)
  1555. {
  1556. reultType = InteractReultType.T1;
  1557. interactScore=studentScore;
  1558. }
  1559. else if (weight>InteractWeight.TT)
  1560. {
  1561. reultType = InteractReultType.TT;
  1562. interactScore=studentScore==0 ? questionScore : studentScore;
  1563. }
  1564. else
  1565. {
  1566. reultType = InteractReultType.TP;
  1567. // 2 * 0.3 * 10= 6
  1568. interactScore= studentScore==0 ? 1/(InteractWeight.TT-InteractWeight.T1) * (InteractWeight.TP-InteractWeight.T1) * questionScore : studentScore;
  1569. }
  1570. }
  1571. }
  1572. else
  1573. {
  1574. weight=InteractWeight.T1+(CalculateSimilarity(answers![0], ans0[0]) *(InteractWeight.TT-InteractWeight.T1));
  1575. if (weight==InteractWeight.T1)
  1576. {
  1577. reultType = InteractReultType.T1;
  1578. interactScore=studentScore;
  1579. }
  1580. else if (weight>InteractWeight.TT)
  1581. {
  1582. reultType = InteractReultType.TT;
  1583. interactScore=studentScore==0 ? questionScore : studentScore;
  1584. }
  1585. else
  1586. {
  1587. reultType = InteractReultType.TP;
  1588. // 2 * 0.3 * 10= 6
  1589. interactScore= studentScore==0 ? 1/(InteractWeight.TT-InteractWeight.T1) * (InteractWeight.TP-InteractWeight.T1) * questionScore : studentScore;
  1590. }
  1591. }
  1592. }
  1593. }
  1594. }
  1595. }
  1596. }
  1597. else
  1598. {
  1599. //没有作答
  1600. weight= InteractWeight.T0;
  1601. reultType = InteractReultType.T0;
  1602. interactScore=studentScore;
  1603. }
  1604. }
  1605. else
  1606. {
  1607. //没有标准答案的情况
  1608. if (ans0.IsNotEmpty())
  1609. {
  1610. bool hasAns = false;
  1611. ans0.ForEach(x => {
  1612. if (!string.IsNullOrWhiteSpace(x))
  1613. {
  1614. hasAns = true;
  1615. }
  1616. });
  1617. if (hasAns)
  1618. {
  1619. //作答了
  1620. weight= InteractWeight.T1;
  1621. reultType = InteractReultType.T1;
  1622. interactScore=studentScore;
  1623. }
  1624. else
  1625. {
  1626. //没有作答
  1627. weight= InteractWeight.T0;
  1628. reultType = InteractReultType.T0;
  1629. interactScore=studentScore;
  1630. }
  1631. }
  1632. else
  1633. {
  1634. //没有作答
  1635. weight= InteractWeight.T0;
  1636. reultType = InteractReultType.T0;
  1637. interactScore=studentScore;
  1638. }
  1639. //如果教师手动给了分或AI评分
  1640. if (questionScore>0 && studentScore>0)
  1641. {
  1642. weight = studentScore * 1.0 / questionScore* (InteractWeight.TT-InteractWeight.T1);
  1643. if (weight==InteractWeight.T1)
  1644. {
  1645. reultType = InteractReultType.T1;
  1646. interactScore=studentScore;
  1647. }
  1648. else if (weight>InteractWeight.TT)
  1649. {
  1650. reultType = InteractReultType.TT;
  1651. interactScore=studentScore==0 ? questionScore : studentScore;
  1652. }
  1653. else
  1654. {
  1655. reultType = InteractReultType.TP;
  1656. interactScore= studentScore==0 ? 1/(InteractWeight.TT-InteractWeight.T1) * (InteractWeight.TP-InteractWeight.T1) * questionScore : studentScore;
  1657. }
  1658. }
  1659. }
  1660. return (weight, reultType, interactScore);
  1661. }
  1662. /// <summary>
  1663. /// C# 代码 如何判断两句话是否一个意思,非机器学习的算法。使用Levenshtein距离来评估两个字符串的相似度,但是不能判断它们是否表达了同一个意思,后续借助AI实现
  1664. /// </summary>
  1665. /// <param name="s1"></param>
  1666. /// <param name="s2"></param>
  1667. /// <returns></returns>
  1668. public static double CalculateSimilarity(string s1, string s2)
  1669. {
  1670. int n = s1.Length;
  1671. int m = s2.Length;
  1672. int[,] d = new int[n + 1, m + 1];
  1673. for (int i = 0; i <= n; i++)
  1674. {
  1675. d[i, 0] = i;
  1676. }
  1677. for (int j = 0; j <= m; j++)
  1678. {
  1679. d[0, j] = j;
  1680. }
  1681. for (int i = 1; i <= n; i++)
  1682. {
  1683. for (int j = 1; j <= m; j++)
  1684. {
  1685. int cost = (s1[i - 1] == s2[j - 1]) ? 0 : 1;
  1686. d[i, j] = Math.Min(Math.Min(d[i - 1, j] + 1, d[i, j - 1] + 1), d[i - 1, j - 1] + cost);
  1687. }
  1688. }
  1689. return (1.0 - ((double)d[n, m] / Math.Max(s1.Length, s2.Length)));
  1690. }
  1691. public static async Task<List<ExamData>> GetExamInfo(LessonRecord item, TimeLineData? timeLineData, AzureStorageFactory _azureStorage/*,ILogger<LessonETLService> _logger*/, string owner)
  1692. {
  1693. //读取ExamData
  1694. List<ExamData> examDatas = new List<ExamData>();
  1695. try
  1696. {
  1697. var examPages = timeLineData?.events.Where(x => !string.IsNullOrWhiteSpace(x.Pgid) && !string.IsNullOrWhiteSpace(x.ExamId));
  1698. if (examPages!=null && examPages.Count()>0)
  1699. {
  1700. var examsFiles = await _azureStorage.GetBlobContainerClient(owner).List($"records/{item.id}/Exam");
  1701. var paperFiles = await _azureStorage.GetBlobContainerClient(owner).List($"records/{item.id}/ExamPaper");
  1702. foreach (var examsFile in examsFiles)
  1703. {
  1704. if (examsFile.EndsWith("Exam.json"))
  1705. {
  1706. ExamData? examData = null;
  1707. try
  1708. {
  1709. BlobDownloadResult examDataDownload = await _azureStorage.GetBlobContainerClient(owner).GetBlobClient(examsFile).DownloadContentAsync();
  1710. var str = examDataDownload.Content.ToString().Replace("\r\n", "").Replace("\ufeff", "").Replace("\"publish\": \"0\"", "\"publish\": 0").Replace("\"publish\": \"1\"", "\"publish\": 1");
  1711. examData= str.ToObject<ExamData>();
  1712. // examData = examDataDownload.Content.ToObjectFromJson<ExamData>();
  1713. }
  1714. catch (Exception ex)
  1715. {
  1716. if (!ex.Message.Contains("The specified blob does not exist"))
  1717. {
  1718. // _logger.LogError(ex, $"文件不存在:{examsFile}");
  1719. }
  1720. }
  1721. if (examData!=null && examData.exam.papers.IsNotEmpty())
  1722. {
  1723. string paperId = examData.exam.papers.First().id;
  1724. if (_azureStorage.GetBlobContainerClient(owner).GetBlobClient($"/records/{item.id}/ExamPaper/{paperId}/index.json").Exists())
  1725. {
  1726. LessonPaper lessonPaper = null;
  1727. try
  1728. {
  1729. BlobDownloadResult paperblobDownload = await _azureStorage.GetBlobContainerClient(owner).GetBlobClient($"/records/{item.id}/ExamPaper/{paperId}/index.json").DownloadContentAsync();
  1730. lessonPaper = paperblobDownload.Content.ToObjectFromJson<LessonPaper>();
  1731. examData.paper = lessonPaper;
  1732. }
  1733. catch (Exception ex)
  1734. {
  1735. if (!ex.Message.Contains("The specified blob does not exist"))
  1736. {
  1737. // _logger.LogError(ex, $"文件不存在:/records/{item.id}/ExamPaper/{paperId}/index.json");
  1738. }
  1739. }
  1740. }
  1741. examDatas.Add(examData);
  1742. }
  1743. }
  1744. }
  1745. }
  1746. }
  1747. catch (Exception ex)
  1748. {
  1749. // _logger.LogError(ex, ex.Message);
  1750. }
  1751. return examDatas;
  1752. }
  1753. /// <summary>
  1754. /// 获取课中评测数据
  1755. /// </summary>
  1756. /// <param name="lessonBase"></param>
  1757. /// <param name="timeLineData"></param>
  1758. /// <param name="examDatas"></param>
  1759. /// <param name="studentLessonDatas"></param>
  1760. /// <param name="objectiveTypes"></param>
  1761. /// <returns></returns>
  1762. public static List<StudentLessonData> GetExamData(LessonBase lessonBase, TimeLineData timeLineData, List<ExamData> examDatas, List<StudentLessonData> studentLessonDatas, List<string> objectiveTypes, string lessonId)
  1763. {
  1764. foreach (var examData in examDatas)
  1765. {
  1766. //直接取第一个元素的试卷,因为在HiTeach中,只会是一个试卷(一个科目),一个班参与。
  1767. var allocation = examData?.exam?.papers?.FirstOrDefault()?.point?.Sum();
  1768. var answersStd = examData?.exam?.papers?.FirstOrDefault()?.answers;
  1769. List<List<string>> answers = new List<List<string>>();
  1770. if (answersStd!=null)
  1771. {
  1772. answersStd.ForEach(x => //去除[""]此种类型的标准答案,转为[]
  1773. {
  1774. List<string> ans = new List<string>();
  1775. if (x.Count!=0)
  1776. {
  1777. if (x.Count==1)
  1778. {
  1779. if (string.IsNullOrWhiteSpace(x[0]))
  1780. {
  1781. answers.Add(ans);
  1782. }
  1783. else
  1784. {
  1785. answers.Add(x);
  1786. }
  1787. }
  1788. else
  1789. {
  1790. answers.Add(x);
  1791. }
  1792. }
  1793. else
  1794. {
  1795. answers.Add(ans);
  1796. }
  1797. });
  1798. }
  1799. examData?.examClassResult?.ForEach(item => {
  1800. //学生下标
  1801. int index = 0;
  1802. if (item.studentAnswersArray.Count()>0
  1803. && item.studentAnswersArray.Count() == item.studentIds.Count() //学生作答数量和学生id数量一致
  1804. && item.studentScores.Count()==item.studentIds.Count()) //学生分数和学生id数量一致
  1805. {
  1806. item.studentAnswersArray.ForEach(stu => {
  1807. var student = studentLessonDatas.Find(x => x.id!.Equals(item.studentIds[index]));
  1808. if (student!=null && student.attend==1)
  1809. {
  1810. //是否要判断主观题或者客观题, 多套试卷,有主观题的
  1811. //,如果没获得结果,
  1812. //主观题有回答的:608942756458532864\Clients\18782481024\Ans\27-4341670635487887360-examExchangeAnswerlist
  1813. //27 从1开始的学生序号-4341670635487887360评测编号,内容qNo 是从1开始的题号。
  1814. if (stu.IsNotEmpty() && answers.Count()==stu.Count && examData.exam.papers[0].type.Count()==answers.Count)
  1815. {
  1816. StudentExamRecord studentExam = new StudentExamRecord();
  1817. var studentScore = item.studentScores[index];
  1818. List<ItemRecord> answerRecords = new List<ItemRecord>();
  1819. //题目下标
  1820. int itemIndex = 0;
  1821. stu.ForEach(ans =>
  1822. {
  1823. bool objective = objectiveTypes.Contains(examData.exam.papers[0].type[itemIndex]);
  1824. var questionScore = examData.exam.papers[0].point[itemIndex];
  1825. string type = examData.exam.papers[0].type[itemIndex];
  1826. var res = GetInteractResultHasAnswer(answers[itemIndex], ans, objective, type, questionScore, studentScore[itemIndex]);
  1827. ItemRecord interactRecord = new ItemRecord()
  1828. {
  1829. itemType="SPQStrt",//类型
  1830. resultType=res.reultType,//作答结果类型
  1831. resultWeight=res.weight,//得分权重
  1832. criterion= questionScore,//标准分
  1833. itemScore= studentScore[itemIndex]//得分
  1834. };
  1835. answerRecords.Add(interactRecord);
  1836. itemIndex++;
  1837. });
  1838. studentExam.score= answerRecords.Where(x => x.itemScore>=0).Select(x => x.itemScore).Sum();//得分
  1839. studentExam.scoreRate= allocation.HasValue && allocation.Value>0 ? studentExam.score * 1.0/allocation.Value : 0;//得分率
  1840. studentExam.answerRate= answerRecords.Where(x => x.resultWeight>0).Count()*1.0/studentScore.Count();//作答率
  1841. studentExam.examId=examData.exam.id;
  1842. studentExam.itemRecords=answerRecords;
  1843. student.examRecords.Add(studentExam);
  1844. }
  1845. }
  1846. index++;
  1847. });
  1848. }
  1849. });
  1850. }
  1851. return studentLessonDatas;
  1852. }
  1853. /// <summary>
  1854. /// 协作参与率 态度计算
  1855. /// </summary>
  1856. /// <param name="lessonBase"></param>
  1857. /// <param name="timeLineData"></param>
  1858. /// <param name="coworkDatas"></param>
  1859. /// <param name="studentLessonDatas"></param>
  1860. /// <param name="lessonId"></param>
  1861. /// <returns></returns>
  1862. public static List<StudentLessonData> GetCoworkData(LessonBase lessonBase, TimeLineData timeLineData, List<CoworkData> coworkDatas, List<StudentLessonData> studentLessonDatas, string lessonId)
  1863. {
  1864. int p = 0;
  1865. foreach (var coworkData in coworkDatas)
  1866. {
  1867. var keys = coworkData.participateLevelList.Keys;
  1868. foreach (var key in keys)
  1869. {
  1870. var student = studentLessonDatas.Find(x => x.seatID!.Equals(key));
  1871. if (student!=null && student.attend==1)
  1872. {
  1873. var score = coworkData.participateLevelList[key];//协作得分,是否是经过指数计算的
  1874. var itemRecord = new ItemRecord { criterion=-1, itemType= coworkData.coworkType, itemScore=score, isGroup= coworkData.coworkType.Equals("Group") ? true : false };
  1875. //不能完全依赖
  1876. if (score>0)
  1877. {
  1878. student.coworkScore.Add(score);
  1879. itemRecord.resultWeight = InteractWeight.TP;
  1880. itemRecord.resultType = InteractReultType.TP;
  1881. }
  1882. else
  1883. {
  1884. itemRecord.resultWeight = InteractWeight.T0;
  1885. itemRecord.resultType = InteractReultType.T0;
  1886. }
  1887. student.coworkRecord.itemRecords.Add(itemRecord);
  1888. }
  1889. if (key.Contains("g", StringComparison.OrdinalIgnoreCase))
  1890. {
  1891. string groupId = key.Replace("g", "").Replace("G", "");
  1892. var score = coworkData.participateLevelList[key];
  1893. if (score>0)
  1894. {
  1895. var groupStu = studentLessonDatas.FindAll(x => x.attend==1 && !string.IsNullOrWhiteSpace(x.groupId) && x.groupId.Equals(groupId));
  1896. if (groupStu.IsNotEmpty())
  1897. {
  1898. foreach (var stu in groupStu)
  1899. {
  1900. stu.group_coworkScore.Add(score);
  1901. stu.coworkRecord.itemRecords[p].itemScore+=score;
  1902. stu.coworkRecord.itemRecords[p].resultWeight=InteractWeight.TP;
  1903. stu.coworkRecord.itemRecords[p].resultType=InteractReultType.TP;
  1904. }
  1905. }
  1906. }
  1907. }
  1908. }
  1909. var order = studentLessonDatas.Where(x => x.attend==1).OrderByDescending(x => x.coworkRecord.itemRecords[p].itemScore);
  1910. var maxItems = studentLessonDatas.FindAll(x => x.attend==1&& x.coworkRecord.itemRecords[p].itemScore==order.First().coworkRecord.itemRecords[p].itemScore);
  1911. double max = 0;
  1912. if (studentLessonDatas.FindAll(x => x.attend==1&& x.coworkRecord.itemRecords[p].itemScore==order.First().coworkRecord.itemRecords[p].itemScore).IsNotEmpty())
  1913. {
  1914. max=studentLessonDatas.FindAll(x => x.attend==1&& x.coworkRecord.itemRecords[p].itemScore==order.First().coworkRecord.itemRecords[p].itemScore).First().coworkRecord.itemRecords[p].itemScore;
  1915. }
  1916. double min = 0;
  1917. if (studentLessonDatas.FindAll(x => x.attend==1&& x.coworkRecord.itemRecords[p].itemScore==order.Last().coworkRecord.itemRecords[p].itemScore).IsNotEmpty())
  1918. {
  1919. min= studentLessonDatas.FindAll(x => x.attend==1&& x.coworkRecord.itemRecords[p].itemScore==order.Last().coworkRecord.itemRecords[p].itemScore).First().coworkRecord.itemRecords[p].itemScore;
  1920. }
  1921. double sum = 0;
  1922. if (studentLessonDatas.FindAll(x => x.attend==1).IsNotEmpty())
  1923. {
  1924. sum= studentLessonDatas.FindAll(x => x.attend==1).Sum(x => x.coworkRecord.itemRecords[p].itemScore);
  1925. }
  1926. foreach (var student in studentLessonDatas)
  1927. {
  1928. if (student.attend==1 && student.coworkRecord.itemRecords.Count>=p+1 && student.coworkRecord.itemRecords[p].itemScore>0)
  1929. {
  1930. student.coworkRecord.itemRecords[p].resultType=InteractReultType.TP;
  1931. var data = MinMaxNormalization(min, max, student.coworkRecord.itemRecords[p].itemScore);
  1932. student.coworkRecord.itemRecords[p].resultWeight=InteractWeight.T1+ data * 1.0 / 100 * (InteractWeight.TT-InteractWeight.T1);
  1933. if (maxItems.Select(x => x.seatID).Contains(student.seatID))
  1934. {
  1935. student.coworkRecord.itemRecords[p].resultType= InteractReultType.TT;
  1936. student.coworkRecord.itemRecords[p].resultWeight= InteractWeight.TT;
  1937. }
  1938. }
  1939. }
  1940. p++;
  1941. }
  1942. return studentLessonDatas;
  1943. }
  1944. /// <summary>
  1945. /// 处理学生回推数据,并将回推纳入学习态度计算。
  1946. /// </summary>
  1947. /// <param name="lessonBase"></param>
  1948. /// <param name="timeLineData"></param>
  1949. /// <param name="taskDatas"></param>
  1950. /// <param name="studentLessonDatas"></param>
  1951. /// <returns></returns>
  1952. public static List<StudentLessonData> GetTaskData(LessonBase lessonBase, TimeLineData timeLineData, List<TaskData> taskDatas, List<StudentLessonData> studentLessonDatas, string lessonId)
  1953. {
  1954. //协作也算任务的一种,'WrkSpaceLoad' 作品收集, "isGroupItem": false,
  1955. int indexTask = 0;
  1956. foreach (var taskData in taskDatas)
  1957. {
  1958. //作品收集是全部人员都要参加
  1959. foreach (var student in studentLessonDatas)
  1960. {
  1961. if (student.attend==1)
  1962. {
  1963. var work = taskData.clientWorks.Find(x => $"{x.seatID}".Equals(student.seatID));
  1964. if (work!= null)
  1965. {
  1966. if (work.blobFiles.Count>0)
  1967. {
  1968. student.uploadCount.Add(work.blobFiles.Count);
  1969. }
  1970. student.taskRecord.itemRecords.Add(new ItemRecord { itemType="WrkSpaceLoad", itemScore=work.blobFiles.Count *10, resultWeight=InteractWeight.TT, resultType=InteractReultType.TT, isGroup= work.isGroupItem, optCount=work.blobFiles.Count });
  1971. }
  1972. else
  1973. {
  1974. student.taskRecord.itemRecords.Add(new ItemRecord { itemType="WrkSpaceLoad", itemScore=0, resultWeight=InteractWeight.T0, resultType=InteractReultType.T0, isGroup= false });
  1975. }
  1976. }
  1977. }
  1978. ////////
  1979. ///需要处理小组的情况,当前人员没有提交作品,但是有可能是小组其他人员提交了,需要判断一下。
  1980. ///
  1981. var students = studentLessonDatas.FindAll(x => x.attend==1 && x.taskRecord.itemRecords[indexTask].isGroup==true);
  1982. foreach (var student in students)
  1983. {
  1984. var groupStudents = studentLessonDatas.FindAll(x => x.id!=student.id && x.attend==1 && !string.IsNullOrWhiteSpace(x.groupId) && x.groupId.Equals(student.groupId));
  1985. foreach (var groupstudent in groupStudents)
  1986. {
  1987. groupstudent.taskRecord.itemRecords[indexTask].isGroup=true;
  1988. groupstudent.taskRecord.itemRecords[indexTask].optCount=student.taskRecord.itemRecords[indexTask].optCount;
  1989. groupstudent.taskRecord.itemRecords[indexTask].itemScore=student.taskRecord.itemRecords[indexTask].itemScore;
  1990. groupstudent.taskRecord.itemRecords[indexTask].resultWeight=student.taskRecord.itemRecords[indexTask].resultWeight;
  1991. groupstudent.taskRecord.itemRecords[indexTask].resultType=student.taskRecord.itemRecords[indexTask].resultType;
  1992. }
  1993. }
  1994. var groupDatas = taskData.clientWorks.FindAll(x => x.seatID==0 && x.isGroupItem);
  1995. foreach (var groupData in groupDatas)
  1996. {
  1997. var groupStudents = studentLessonDatas.FindAll(x => x.attend==1 && !string.IsNullOrWhiteSpace(x.groupId) && x.groupId.Equals(groupData.groupID));
  1998. foreach (var student in groupStudents)
  1999. {
  2000. student.taskRecord.itemRecords[indexTask].isGroup=true;
  2001. student.taskRecord.itemRecords[indexTask].optCount=groupData.blobFiles.Count;
  2002. student.taskRecord.itemRecords[indexTask].itemScore= 10* groupData.blobFiles.Count;
  2003. if (groupData.blobFiles.Count>0)
  2004. {
  2005. student.taskRecord.itemRecords[indexTask].resultWeight=InteractWeight.TT;
  2006. student.taskRecord.itemRecords[indexTask].resultType=InteractReultType.TT;
  2007. }
  2008. else
  2009. {
  2010. student.taskRecord.itemRecords[indexTask].resultWeight=InteractWeight.T0;
  2011. student.taskRecord.itemRecords[indexTask].resultType=InteractReultType.T0;
  2012. }
  2013. }
  2014. }
  2015. indexTask++;
  2016. }
  2017. return studentLessonDatas;
  2018. }
  2019. /// <summary>
  2020. ///评分参与率 态度计算
  2021. ///读取互评信息
  2022. ///评分相关 在SmartRating.json 处理 GrandRating 星光大评分, 投票Voting 和 PeerAssessment(All每人多件评分,Two随机分配互评, Self自评)
  2023. ///Event 过滤类型 'RatingStart'
  2024. ///smartRateSummary.mutualSummary.mutualType 互评【All(每人多件评分) Two(随机分配互评) Self(自评)】 smartRateSummary.meteor_VoteSummary 投票
  2025. ///读取SmartRating.json
  2026. /// </summary>
  2027. /// <param name="lessonBase"></param>
  2028. /// <param name="timeLineData"></param>
  2029. /// <param name="smartRatingDatas"></param>
  2030. /// <param name="studentLessonDatas"></param>
  2031. /// <returns></returns>
  2032. public static List<StudentLessonData> GetSmartRatingData(LessonBase lessonBase, TimeLineData timeLineData, List<SmartRatingData> smartRatingDatas, List<StudentLessonData> studentLessonDatas, string lessonId)
  2033. {
  2034. int index = 0;
  2035. foreach (var smartRatingData in smartRatingDatas)
  2036. {
  2037. string type = "";
  2038. //投票类型的
  2039. var keys_vote = smartRatingData.smartRateSummary?.meteor_VoteSummary?.Keys?.ToList();
  2040. if (keys_vote.IsNotEmpty())
  2041. {
  2042. type="Voting";
  2043. bool addData = false;
  2044. foreach (var key in keys_vote!)
  2045. {
  2046. try
  2047. {
  2048. //问题数据F:\lesson-local\632424798693232640-local.json pclxxx
  2049. if (smartRatingData.smartRateSummary!.voteDetailResult.TryGetValue(key, out var value))
  2050. {
  2051. var voteDetailResults = smartRatingData.smartRateSummary!.voteDetailResult[key];
  2052. foreach (var student in studentLessonDatas)
  2053. {
  2054. if (student.attend==1)
  2055. {
  2056. //投票是全员参与
  2057. var datasS = voteDetailResults.FindAll(x => x.id.Equals(student.seatID));
  2058. if (datasS.IsNotEmpty())
  2059. {
  2060. //T1,只有评论别人,没被别人评论 或者是评论了别人,但是没有被别人评论,
  2061. student.rateingRecord.itemRecords.Add(new ItemRecord { itemType=type, resultType=InteractReultType.T1, resultWeight = InteractWeight.T1 });
  2062. addData=true;
  2063. }
  2064. else
  2065. { //T0 是没有评论别人,也没被别人评论,
  2066. student.rateingRecord.itemRecords.Add(new ItemRecord { itemType=type, resultType=InteractReultType.T0, resultWeight = InteractWeight.T0 });
  2067. addData=true;
  2068. }
  2069. //T0 是没有评论别人,也没被别人评论,
  2070. //T1,只有评论别人,没被别人评论 或者是评论了别人,但是没有被别人评论,
  2071. //TP 有被别人评论,且评论了别人,
  2072. //TT是评论了别人,且被别人评论次数最高,或者分值最高。
  2073. }
  2074. }
  2075. }
  2076. }
  2077. catch (Exception ex)
  2078. {
  2079. throw new Exception($"{lessonId}\n{ex.Message}\n{ex.StackTrace}");
  2080. }
  2081. var meteor_VoteSummary = smartRatingData.smartRateSummary!.meteor_VoteSummary[key];
  2082. var order = meteor_VoteSummary.OrderByDescending(x => x.result);
  2083. var maxItems = meteor_VoteSummary.FindAll(x => x.result==order.First().result);
  2084. double max = 0;
  2085. if (maxItems.IsNotEmpty())
  2086. {
  2087. max = meteor_VoteSummary.FindAll(x => x.result==order.First().result).First().result;
  2088. }
  2089. double min = 0;
  2090. if (meteor_VoteSummary.FindAll(x => x.result==order.Last().result).IsNotEmpty())
  2091. {
  2092. min = meteor_VoteSummary.FindAll(x => x.result==order.Last().result).First().result;
  2093. }
  2094. double sum = 0;
  2095. if (meteor_VoteSummary.IsNotEmpty())
  2096. {
  2097. sum = meteor_VoteSummary.Sum(x => x.result);
  2098. }
  2099. //排名指数计算=( 当前值分数- 298) / (9992 - 298) * (99 - 60) + 60
  2100. //将每个人的积分转化为60-100
  2101. //排名 = (积分 - 最低积分) / (最高积分 - 最低积分) * (最大排名 - 最小排名) + 最小排名
  2102. foreach (var datasD in meteor_VoteSummary)
  2103. {
  2104. //有被人评论或投票
  2105. var student = studentLessonDatas.Find(x => x.seatID!.Equals(datasD.id));
  2106. if (student!=null)
  2107. {
  2108. if (index<student.rateingRecord.itemRecords.Count && student.rateingRecord.itemRecords[index].itemType!.Equals(type))
  2109. {
  2110. if (student.rateingRecord.itemRecords[index].resultType!.Equals(InteractReultType.T0))
  2111. {
  2112. //T1,只有评论别人,没被别人评论 或者是评论了别人,但是没有被别人评论,
  2113. student.rateingRecord.itemRecords[index].resultType= InteractReultType.T1;
  2114. student.rateingRecord.itemRecords[index].resultWeight= InteractWeight.T1;
  2115. }
  2116. else if (student.rateingRecord.itemRecords[index].resultType!.Equals(InteractReultType.T1))
  2117. {
  2118. //TP 有被别人评论,且评论了别人,
  2119. student.rateingRecord.itemRecords[index].resultType= InteractReultType.TP;
  2120. var data = MinMaxNormalization(min, max, datasD.result);
  2121. //student.rateingRecord.itemRecords[index].resultWeight= InteractWeight.TP;
  2122. student.rateingRecord.itemRecords[index].resultWeight=InteractWeight.T1+ data * 1.0 / 100 * (InteractWeight.TT-InteractWeight.T1);
  2123. //获得的票数
  2124. student.rateingRecord.itemRecords[index].itemScore=datasD.result;
  2125. //TT是评论了别人,且被别人评论次数最高,或者分值最高。
  2126. if (maxItems.Select(x => x.id).Contains(student.seatID))
  2127. {
  2128. student.rateingRecord.itemRecords[index].resultType= InteractReultType.TT;
  2129. student.rateingRecord.itemRecords[index].resultWeight= InteractWeight.TT;
  2130. }
  2131. }
  2132. }
  2133. }
  2134. }
  2135. if (addData)
  2136. {
  2137. index++;
  2138. }
  2139. }
  2140. }
  2141. //星光大评分,全员评分
  2142. var keys_GrandRating = smartRatingData.smartRateSummary?.scoreDetailResult?.Keys?.ToList();
  2143. if (keys_GrandRating.IsNotEmpty() && smartRatingData.smartRateSummary!=null && smartRatingData.smartRateSummary.meteor_ScoreSummary.IsNotEmpty())
  2144. {
  2145. bool addData = false;
  2146. type="GrandRating";
  2147. foreach (var student in studentLessonDatas)
  2148. {
  2149. if (student.attend==1)
  2150. {
  2151. if (keys_GrandRating!.Contains(student.seatID!))
  2152. {
  2153. //T1,只有评论别人,没被别人评论 或者是评论了别人,但是没有被别人评论,
  2154. student.rateingRecord.itemRecords.Add(new ItemRecord { itemType=type, resultType=InteractReultType.T1, resultWeight = InteractWeight.T1 });
  2155. addData = true;
  2156. }
  2157. else
  2158. {
  2159. //T0 是没有评论别人,也没被别人评论,
  2160. student.rateingRecord.itemRecords.Add(new ItemRecord { itemType=type, resultType=InteractReultType.T0, resultWeight = InteractWeight.T0 });
  2161. addData = true;
  2162. }
  2163. }
  2164. }
  2165. var order = smartRatingData.smartRateSummary.meteor_ScoreSummary.Where(x => x.result>0||!string.IsNullOrWhiteSpace(x.comment)).OrderByDescending(x => x.result);
  2166. if (order.Count()>0)
  2167. {
  2168. var maxItems = smartRatingData.smartRateSummary.meteor_ScoreSummary.FindAll(x => x.result==order.First().result);
  2169. double max = 0;
  2170. if (maxItems.IsNotEmpty())
  2171. {
  2172. max = smartRatingData.smartRateSummary.meteor_ScoreSummary.FindAll(x => x.result==order.First().result).First().result;
  2173. }
  2174. double min = 0;
  2175. if (smartRatingData.smartRateSummary.meteor_ScoreSummary.FindAll(x => x.result==order.Last().result).IsNotEmpty())
  2176. {
  2177. min = smartRatingData.smartRateSummary.meteor_ScoreSummary.FindAll(x => x.result==order.Last().result).First().result;
  2178. }
  2179. var sum = smartRatingData.smartRateSummary.meteor_ScoreSummary.Sum(x => x.result);
  2180. foreach (var meteor_ScoreSummary in smartRatingData.smartRateSummary.meteor_ScoreSummary)
  2181. {
  2182. var student = studentLessonDatas.Find(x => x.seatID!.Equals(meteor_ScoreSummary.id));
  2183. if (student!=null)
  2184. {
  2185. if (index<student.rateingRecord.itemRecords.Count && student.rateingRecord.itemRecords[index].itemType!.Equals(type))
  2186. {
  2187. if (student.rateingRecord.itemRecords[index].resultType!.Equals(InteractReultType.T0))
  2188. {
  2189. //T1,只有评论别人,没被别人评论 或者是评论了别人,但是没有被别人评论,
  2190. student.rateingRecord.itemRecords[index].resultType= InteractReultType.T1;
  2191. student.rateingRecord.itemRecords[index].resultWeight= InteractWeight.T1;
  2192. }
  2193. else if (student.rateingRecord.itemRecords[index].resultType!.Equals(InteractReultType.T1))
  2194. {
  2195. //TP 有被别人评论,且评论了别人,
  2196. student.rateingRecord.itemRecords[index].resultType= InteractReultType.TP;
  2197. var data = MinMaxNormalization(min, max, meteor_ScoreSummary.result);
  2198. //student.rateingRecord.itemRecords[index].resultWeight= InteractWeight.TP;
  2199. student.rateingRecord.itemRecords[index].resultWeight= InteractWeight.T1+ data * 1.0 / 100 * (InteractWeight.TT-InteractWeight.T1);
  2200. //被评论次数
  2201. student.rateingRecord.itemRecords[index].itemScore=meteor_ScoreSummary.result;
  2202. //TT是评论了别人,且被别人评论次数最高,或者分值最高。
  2203. if (maxItems.Select(x => x.id).Contains(student.seatID) &&student.rateingRecord.itemRecords[index].itemScore>0)
  2204. {
  2205. student.rateingRecord.itemRecords[index].resultType= InteractReultType.TT;
  2206. student.rateingRecord.itemRecords[index].resultWeight= InteractWeight.TT;
  2207. }
  2208. }
  2209. }
  2210. }
  2211. }
  2212. }
  2213. if (addData)
  2214. {
  2215. index++;
  2216. }
  2217. }
  2218. // 互评 PeerAssessment(All每人多件评分,Two随机分配互评, Self自评)
  2219. var keys_PeerAssessment = smartRatingData.smartRateSummary?.mutualDetailSummary?.Keys?.ToList();
  2220. if (keys_PeerAssessment.IsNotEmpty() && smartRatingData.smartRateSummary?.mutualSummary!=null
  2221. && smartRatingData.smartRateSummary.mutualSummary.mutualResults.IsNotEmpty()
  2222. && smartRatingData.smartRateSummary.mutualSummary.materialInfos.IsNotEmpty())
  2223. {
  2224. bool addData = false;
  2225. type="PeerAssessment";
  2226. foreach (var student in studentLessonDatas)
  2227. {
  2228. if (student.attend==1)
  2229. {
  2230. if (keys_PeerAssessment!.Contains(student.seatID!))
  2231. {
  2232. //T1,只有评论别人,没被别人评论 或者是评论了别人,但是没有被别人评论,
  2233. student.rateingRecord.itemRecords.Add(new ItemRecord { itemType=type, resultType=InteractReultType.T1, resultWeight = InteractWeight.T1 });
  2234. addData = true;
  2235. }
  2236. else
  2237. {
  2238. //T0 是没有评论别人,也没被别人评论,
  2239. student.rateingRecord.itemRecords.Add(new ItemRecord { itemType=type, resultType=InteractReultType.T0, resultWeight = InteractWeight.T0 });
  2240. addData = true;
  2241. }
  2242. }
  2243. }
  2244. var order = smartRatingData.smartRateSummary.mutualSummary.mutualResults.Where(x => x.result>0).OrderByDescending(x => x.result);
  2245. var maxItems = smartRatingData.smartRateSummary.mutualSummary.mutualResults.FindAll(x => x.result==order.First().result);
  2246. double max = 0;
  2247. if (maxItems.IsNotEmpty())
  2248. {
  2249. max = smartRatingData.smartRateSummary.mutualSummary.mutualResults.FindAll(x => x.result==order.First().result).First().result;
  2250. }
  2251. double min = 0;
  2252. if (smartRatingData.smartRateSummary.mutualSummary.mutualResults.FindAll(x => x.result==order.Last().result).IsNotEmpty())
  2253. {
  2254. min = smartRatingData.smartRateSummary.mutualSummary.mutualResults.FindAll(x => x.result==order.Last().result).First().result;
  2255. }
  2256. var sum = smartRatingData.smartRateSummary.mutualSummary.mutualResults.Sum(x => x.result);
  2257. foreach (var mutualResult in smartRatingData.smartRateSummary.mutualSummary.mutualResults)
  2258. {
  2259. var student = studentLessonDatas.Find(x => x.seatID!.Equals(mutualResult.id));
  2260. if (student!=null)
  2261. {
  2262. if (index<student.rateingRecord.itemRecords.Count && student.rateingRecord.itemRecords[index].itemType!.Equals(type))
  2263. {
  2264. if (student.rateingRecord.itemRecords[index].resultType!.Equals(InteractReultType.T0))
  2265. {
  2266. //T1,只有评论别人,没被别人评论 或者是评论了别人,但是没有被别人评论,
  2267. student.rateingRecord.itemRecords[index].resultType= InteractReultType.T1;
  2268. student.rateingRecord.itemRecords[index].resultWeight= InteractWeight.T1;
  2269. }
  2270. else if (student.rateingRecord.itemRecords[index].resultType!.Equals(InteractReultType.T1))
  2271. {
  2272. //TP 有被别人评论,且评论了别人,
  2273. //最高分和最低分,票数最多和票数最少的占比来计算TP的占比
  2274. student.rateingRecord.itemRecords[index].resultType= InteractReultType.TP;
  2275. var data = MinMaxNormalization(min, max, mutualResult.result);
  2276. //student.rateingRecord.itemRecords[index].resultWeight= InteractWeight.TP;
  2277. student.rateingRecord.itemRecords[index].resultWeight= InteractWeight.T1+ data * 1.0 / 100 * (InteractWeight.TT-InteractWeight.T1);
  2278. student.rateingRecord.itemRecords[index].itemScore=mutualResult.result;
  2279. //TT是评论了别人,且被别人评论次数最高,或者分值最高。
  2280. if (maxItems.Select(x => x.id).Contains(student.seatID))
  2281. {
  2282. student.rateingRecord.itemRecords[index].resultType= InteractReultType.TT;
  2283. student.rateingRecord.itemRecords[index].resultWeight= InteractWeight.TT;
  2284. }
  2285. }
  2286. }
  2287. }
  2288. }
  2289. if (addData)
  2290. {
  2291. index++;
  2292. }
  2293. }
  2294. }
  2295. return studentLessonDatas;
  2296. }
  2297. /// <summary>
  2298. /// 最小-最大归一化(Min-Max Normalization)算法。这种算法通常用于将数据的特征值缩放到一个指定的范围内,通常是0到1之间,或者任何其他指定的范围。
  2299. /// </summary>
  2300. /// <returns></returns>
  2301. public static double MinMaxNormalization(double min, double max, double x, double minRank = 1, double maxRank = 100)
  2302. {
  2303. //排名指数计算=( 当前值分数- 298) / (9992 - 298) * (99 - 60) + 60
  2304. //将每个人的积分转化为60-100
  2305. //排名 = (积分 - 最低积分) / (最高积分 - 最低积分) * (最大排名 - 最小排名) + 最小排名
  2306. return x==0 ? 0 : max-min!=0 ? (x - min)*1.0 / (max - min) * (maxRank - minRank) + minRank : (x)*1.0 / (max) * (maxRank - minRank) + minRank;
  2307. }
  2308. /// <summary>
  2309. /// 处理学生课中数据
  2310. /// </summary>
  2311. /// <param name="studentLessonDatas"></param>
  2312. /// <param name="lessonDataAnalysis"></param>
  2313. /// <returns></returns>
  2314. public static List<StudentLessonItem> ProcessStudentDataV2(List<StudentLessonData> studentLessonDatas, LessonDataAnalysisModel lessonDataAnalysis, List<CodeBool> codeBools)
  2315. {
  2316. //历史记录的个人计分集合,通过“2倍标准差规则”移除异常值后得到的集合
  2317. //var max_q = lessonDataAnalysis.pscore.Max();
  2318. //历史记录的互动计分集合,通过“2倍标准差规则”移除异常值后得到的集合
  2319. //var max_t = lessonDataAnalysis.tscore.Max();
  2320. //历史记录的小组计分集合,通过“2倍标准差规则”移除异常值后得到的集合
  2321. // var max_h = lessonDataAnalysis.gscore.Max();
  2322. var j = InteractWeight.T1;
  2323. double t = InteractWeight.TT;
  2324. List<StudentLessonItem> lessonItems = new List<StudentLessonItem>();
  2325. foreach (var studentLessonData in studentLessonDatas)
  2326. {
  2327. StudentLessonItem lessonItem = new StudentLessonItem() { studentId= studentLessonData.id! };
  2328. double u = 0.0;
  2329. if (studentLessonData.attend==1)
  2330. {
  2331. u=100.0;
  2332. }
  2333. //c个人计分指数,d互动计分指数,e小组计分指数
  2334. double d = 0, e = 0;
  2335. //本节课教师手动给学生的个人计分
  2336. var s = studentLessonData.pscore;
  2337. //个人计分指数
  2338. double c = GetPersent(lessonDataAnalysis.pscore, s).persent;// s*1.0/max_q;
  2339. {
  2340. //智慧挑人
  2341. var zhPicks = studentLessonData.pickups.Where(x => x.StartsWith("1--"));
  2342. int memberCount = studentLessonDatas.Count;
  2343. var zhPickCount = zhPicks.Count();
  2344. double pickRate = 0;
  2345. foreach (var grppick in zhPicks)
  2346. {
  2347. pickRate+= 1.0 * (1.0/memberCount)* 100;
  2348. }
  2349. if (zhPickCount>0)
  2350. {
  2351. pickRate=100- Math.Round(pickRate/zhPickCount, 4);
  2352. lessonItem.pt_tr=zhPickCount;
  2353. lessonItem.zh_tr=pickRate;
  2354. }
  2355. }
  2356. {
  2357. //互动相关的计分
  2358. //课例互动次数
  2359. double n = studentLessonData.interactRecord.interactRecords.Count()*1.0;
  2360. if (n>0)
  2361. {
  2362. //是IES大陆正式站历史课例数据,自2024-03-01至2024-10-08日,互动指数或学法指数黄灯或绿灯,不包含醍摩豆学校及测试学校,课例时长超过5分钟的有效课例(10,680笔数据) 的IRS互动+抢权+挑人的次数集合,
  2363. //通过“2倍标准差规则” 移除异常值后得到的集合,再通过K-Means聚类算法得到高低位阶互动频次两个集合,并根据当前课例互动次数位阶的集合的质心值,该值定为m值
  2364. IEnumerable<double> all = lessonDataAnalysis.levelInteract.SelectMany(x => x.Value);
  2365. var currMacth = lessonDataAnalysis.levelInteract.FindAll(x => x.Value.Min()<=n && x.Value.Max()>=n);
  2366. KeyValuePair<double, List<double>> curr = new KeyValuePair<double, List<double>>();
  2367. if (currMacth!=null && currMacth.Count()>0)
  2368. {
  2369. curr = currMacth.MinBy(x => x.Key);
  2370. }
  2371. else
  2372. {
  2373. curr = lessonDataAnalysis.levelInteract.MaxBy(x => x.Key);
  2374. }
  2375. var p = LessonETLService.GetPersent(all, n);
  2376. var l = n<lessonDataAnalysis.interactPass ? lessonDataAnalysis.interactLow : n>lessonDataAnalysis.interactGood ? lessonDataAnalysis.interactHigh : lessonDataAnalysis.interactMedium;
  2377. //出题系数=当前互动次数与互动通过次数之间的比例*当前互动次数与互动中位数之间的比例*当前互动次数与互动高阶互动频次的比例
  2378. var m = (n*1.0/l) *(p.persent/100) * (curr.Value.Count*1.0/all.Count());
  2379. //学生作答次数
  2380. var w = studentLessonData.interactRecord.interactRecords.Where(x => x.resultWeight>=InteractWeight.T1).Count()*1.0;
  2381. //作答正确数(包括部分正确)
  2382. var r = studentLessonData.interactRecord.interactRecords.Where(x => x.resultWeight>InteractWeight.T1).Count()*1.0;
  2383. //有参与的权重集合60≤k(x)≤100
  2384. var kw = studentLessonData.interactRecord.interactRecords.Where(x => x.resultWeight>=InteractWeight.T1).Sum(x => x.resultWeight*1.0);
  2385. //有得分的权重集合60<e(x)≤100
  2386. var er = studentLessonData.interactRecord.interactRecords.Where(x => x.resultWeight>InteractWeight.T1).Sum(x => x.resultWeight*1.0);
  2387. //本节课的所有互动计分
  2388. var i = studentLessonData.interactRecord.interactRecords.Sum(x => x.itemScore*1.0);
  2389. //互动计分指数
  2390. d = GetPersent(lessonDataAnalysis.tscore, i).persent; //i*1.0/max_t;
  2391. //互动成效指数
  2392. var a = 1.0;
  2393. if (w==0)
  2394. {
  2395. a = kw/10/n;
  2396. }
  2397. else
  2398. {
  2399. if (r==0)
  2400. {
  2401. a = (kw/(10*w))*(w/n);
  2402. }
  2403. else
  2404. {
  2405. a = (kw/(10*w))*(w/n)+er/(r*10)*(r/w);
  2406. }
  2407. }
  2408. //c+a= 个人计分指数+ 个人互动成效指数
  2409. //互动成效
  2410. var f1 = Math.Round(190*1.0/(1+Math.Exp(-(a*m)))-95, 4);
  2411. if (f1==0)
  2412. {
  2413. if (d>0 && c==0)
  2414. {
  2415. f1=d*0.6;
  2416. }
  2417. else if (d==0 && c>0)
  2418. {
  2419. f1=c*0.6;
  2420. }
  2421. else
  2422. {
  2423. f1=(d*0.6+c*0.6)/2;
  2424. }
  2425. }
  2426. else
  2427. {
  2428. //如果有互动计分,则互动成效指数取0.8 0.2
  2429. var dy = (95-f1)/95/2;
  2430. if (dy>0.2)
  2431. {
  2432. dy=0.2;
  2433. }
  2434. if (dy<0.1) {
  2435. dy=0.1;
  2436. }
  2437. f1=f1*(dy>0.1? 1-dy : 1-dy*2)+d*dy+c*dy;
  2438. }
  2439. if (f1>95)
  2440. {
  2441. f1=95;
  2442. }
  2443. if (f1>0)
  2444. {
  2445. //智慧挑人有被挑中的
  2446. if (lessonItem.zh_tr>0)
  2447. {
  2448. f1=f1+lessonItem.zh_tr/2;
  2449. }
  2450. }
  2451. else
  2452. {
  2453. //智慧挑人有被挑中的
  2454. if (lessonItem.zh_tr>0)
  2455. {
  2456. f1=lessonItem.zh_tr*0.8;
  2457. }
  2458. }
  2459. //var f1 = Math.Round(a*m);
  2460. lessonItem.hd_cx=f1;
  2461. //互动专注指数
  2462. // var b = ((w*w/n)+(r*r/w))*1.0*m;
  2463. // var f2 = Math.Round(200*1.0/(1+Math.Exp(-(b)))-100, 4);
  2464. double f2 = 0;
  2465. //if (w>0)
  2466. //{
  2467. // double xs = m/n>0.1 ? m/n/10 : m/n;
  2468. // if (xs>0.05)
  2469. // {
  2470. // xs=xs/3;
  2471. // }
  2472. // lessonItem.hd_xs=Math.Round(xs, 4);
  2473. // var b = xs* ((w/n)*0.8+ 0.2 * (w/n)* (r/w));
  2474. // f2 = Math.Round(200*1.0/(1+Math.Exp(-(b)))-100, 4);
  2475. // if (f2>1)
  2476. // {
  2477. // f2=100;
  2478. // }
  2479. // else
  2480. // {
  2481. // f2=f2*100;
  2482. // }
  2483. //}
  2484. if (w>0) {
  2485. //作答正确的也算在参与度中,只是占比比作答率占比更小,占20%,即 0.2 * (w/n)* (r/w)*100,计算结果可能会大于100,则强制限定
  2486. f2=(w/n)*100+ 0.2 * (w/n)* (r/w)*100;
  2487. if (f2>100) { f2=100; }
  2488. //智慧挑人有被挑中的
  2489. if (f2>0)
  2490. {
  2491. if (lessonItem.zh_tr>0)
  2492. {
  2493. f2=f2+lessonItem.zh_tr/2;
  2494. }
  2495. }
  2496. else{
  2497. if (lessonItem.zh_tr>0)
  2498. {
  2499. f2=lessonItem.zh_tr*0.8;
  2500. }
  2501. }
  2502. }
  2503. lessonItem.hd_cy=f2;
  2504. lessonItem.hd_cyc=w;
  2505. lessonItem.hd_fqc=n;
  2506. lessonItem.hd_zqc=r;
  2507. lessonItem.gr_jf=s;
  2508. }
  2509. //studentLessonData.achieve=f1;
  2510. //studentLessonData.attitude=f2;
  2511. // _logger.LogInformation($"{studentLessonData.id}=>学习成效:{f1}\t学习态度:{f2}\t互动次数:{n}\t参与次数:{w}\t正确次数:{r}\t个人计分:{s}\t{Math.Round(c, 2)}\t互动计分:{i}\t{Math.Round(d, 2)}");
  2512. }
  2513. {
  2514. //评测相关指数
  2515. double n = studentLessonData.examRecords.Count()*1.0;
  2516. if (n>0)
  2517. {
  2518. //题目数量
  2519. double nq = studentLessonData.examRecords.Sum(x => x.qcount)*1.0;
  2520. // double max_e = lessonDataAnalysis.exam.Max();
  2521. //得分率
  2522. double sum_s = studentLessonData.examRecords.Sum(x => x.scoreRate);
  2523. //作答率
  2524. double sum_a = studentLessonData.examRecords.Sum(x => x.answerRate);
  2525. double f8 = Math.Round(sum_s/n*100, 4);
  2526. double f9 = Math.Round(sum_a/n*100, 4);
  2527. lessonItem.pc_df=f8;
  2528. lessonItem.pc_zd=f9;
  2529. }
  2530. // _logger.LogInformation($"{studentLessonData.id}=>评测指数:{f8}\t得分率:{Math.Round(sum_s/n,4)}\t专注指数:{f9}\t作答率:{Math.Round(sum_a/n,4)}");
  2531. }
  2532. {
  2533. //小组相关指数
  2534. /* PickupNameLst
  2535. * PickupOption
  2536. * PickupNthGrp
  2537. * PickupGrp
  2538. * PickupRange
  2539. * PickupEachGrp
  2540. * PickupDiff
  2541. * PickupWrong
  2542. * PickupNoDiff
  2543. * PickupRight
  2544. * PickupGener
  2545. * PickupWtoW
  2546. * PickupWtoR
  2547. * PickupLSA_WordFreq
  2548. * PickupLSA_Classify
  2549. * Pickup0_49
  2550. */
  2551. var grpPicks = studentLessonData.pickups.Where(x => x.StartsWith("1--") && x.Contains("Grp", StringComparison.OrdinalIgnoreCase));
  2552. var groups= studentLessonDatas.Where(x => !string.IsNullOrWhiteSpace(x.groupId)).Select(x => x.groupId).Distinct();
  2553. int groupCount = 1;
  2554. int memberCount = studentLessonDatas.Count;
  2555. if (groups!=null &&groups.Count()>0)
  2556. {
  2557. groupCount=groups.Count();
  2558. var members = studentLessonDatas.Where(x => !string.IsNullOrWhiteSpace(x.groupId) && !string.IsNullOrWhiteSpace(studentLessonData.groupId)&&x.groupId.Equals(studentLessonData.groupId));
  2559. if (members!=null && members.Count()>0)
  2560. {
  2561. memberCount= members.Count();
  2562. }
  2563. }
  2564. var grpPickCount = grpPicks.Count();
  2565. double pickRate = 0;
  2566. double groupType = 0;
  2567. foreach (var grppick in grpPicks)
  2568. {
  2569. pickRate+= (1.0/groupCount) * (1.0/memberCount)* 100 ;
  2570. }
  2571. if (grpPickCount>0)
  2572. {
  2573. pickRate=100- Math.Round(pickRate/grpPickCount,4);
  2574. groupType+=1;
  2575. lessonItem.xz_tr=grpPickCount;
  2576. }
  2577. double coworkRate = 0;
  2578. if (studentLessonData.group_coworkScore.IsNotEmpty())
  2579. {
  2580. double coworkGrp = studentLessonData.group_coworkScore.Average();
  2581. var coworkData = GetPersent(lessonDataAnalysis.groupCowork, coworkGrp);
  2582. coworkRate= coworkData.persent;
  2583. groupType+=1;
  2584. lessonItem.xz_xz=studentLessonData.group_coworkScore.Sum();
  2585. }
  2586. double gscoreRate = 0;
  2587. if (studentLessonData.gscore>0)
  2588. {
  2589. var gscoreData = GetPersent(lessonDataAnalysis.gscore, studentLessonData.gscore);
  2590. gscoreRate= gscoreData.persent;
  2591. groupType+=1;
  2592. lessonItem.xz_jf=studentLessonData.gscore;
  2593. }
  2594. double groupTask = 0;
  2595. var groupTasks= studentLessonData.taskRecord.itemRecords.Where(x => x.isGroup);
  2596. if(groupTasks!=null && groupTasks.Count()>0)
  2597. {
  2598. double score = CalculateScore(groupTasks.Sum(x=>x.optCount));
  2599. groupType+=1;
  2600. lessonItem.xz_sc=groupTasks.Count();
  2601. }
  2602. double fxGrp = 0;
  2603. if (groupType>0) {
  2604. fxGrp = (pickRate+coworkRate+gscoreRate+groupTask)/groupType; }
  2605. if (groupType==2 &&(pickRate>0 && gscoreRate>0) )
  2606. {
  2607. fxGrp = (pickRate*0.8+coworkRate+gscoreRate*0.8+groupTask)/groupType;
  2608. }
  2609. if (groupType==1)
  2610. {
  2611. fxGrp=(pickRate+coworkRate+gscoreRate+groupTask)*0.8/groupType;
  2612. }
  2613. lessonItem.hz_nl=Math.Round(fxGrp,4);
  2614. }
  2615. {
  2616. //任务相关指数
  2617. double n = studentLessonData.taskRecord.itemRecords.Count()*1.0;
  2618. if (n>0)
  2619. {
  2620. double max_m = lessonDataAnalysis.task.Select(x=>x.Key).Max();
  2621. double w = studentLessonData.taskRecord.itemRecords.Where(x => x.resultWeight>0).Count()*1.0;
  2622. double y = (10 *w/n+(j/t) *w)/max_m;
  2623. double l = max_m*(w*w/n+(j/t) * w)/n;
  2624. double f4 = Math.Round(190*1.0/(1+Math.Exp(-(y)))-95, 4);
  2625. double f5 = Math.Round(200*1.0/(1+Math.Exp(-(l)))-100, 4);
  2626. lessonItem.rw_fqc =n;
  2627. lessonItem.rw_cyc =w;
  2628. lessonItem.rw_zpc =studentLessonData.taskRecord.itemRecords.Sum(x=>x.optCount);
  2629. lessonItem.rw_cx =f4;
  2630. lessonItem.rw_cy =f5;
  2631. double score = 0;
  2632. if (w>0)
  2633. {
  2634. foreach (var item in studentLessonData.taskRecord.itemRecords)
  2635. {
  2636. score += CalculateScore(item.optCount);
  2637. }
  2638. }
  2639. lessonItem.rw_cx =score*1.0/n;
  2640. }
  2641. // _logger.LogInformation($"{studentLessonData.id}=>任务指数:{f4}\t专注指数:{f5}\t任务次数:{n}\t参与次数:{w}\t");
  2642. }
  2643. {
  2644. //评价相关指数
  2645. double n = studentLessonData.rateingRecord.itemRecords.Count()*1.0;
  2646. if (n>0)
  2647. {
  2648. var v = studentLessonData.rateingRecord.itemRecords.Where(x => x.itemType.Equals("Voting"));
  2649. double vc = v.Count()*1.0;
  2650. var g = studentLessonData.rateingRecord.itemRecords.Where(x => x.itemType.Equals("GrandRating"));
  2651. double gc = g.Count()*1.0;
  2652. var p = studentLessonData.rateingRecord.itemRecords.Where(x => x.itemType.Equals("PeerAssessment"));
  2653. double pc = p.Count()*1.0;
  2654. var vg = v.Sum(x => x.itemScore);
  2655. var vo = v.Sum(x => x.optCount);
  2656. double vs = vc/n* (vg+ vo);
  2657. var gg = g.Sum(x => x.itemScore);
  2658. var go = g.Sum(x => x.optCount);
  2659. double gs = gc/n* (gg+ go);
  2660. var pg = p.Sum(x => x.itemScore);
  2661. var po = p.Sum(x => x.optCount);
  2662. double ps = pc/n* (pg+ po);
  2663. double h = vs+ps+gs;
  2664. double f3 = Math.Round(190*1.0/(1+Math.Exp(-(h)))-95, 4);
  2665. studentLessonData.appraise=f3;
  2666. // _logger.LogInformation($"{studentLessonData.id}=>评价能力:{f3}\t评价次数:{n}\t投票次数:{vc}-{vg}-{vo}\t星光次数:{gc}-{gg}-{go}\t互评次数:{pc}-{pg}-{po}");
  2667. lessonItem.pj_nl =f3;
  2668. lessonItem.pj_cs =n;
  2669. lessonItem.pj_vc =vc;
  2670. lessonItem.pj_vg =vg;
  2671. lessonItem.pj_vo =vo;
  2672. lessonItem.pj_gc =gc;
  2673. lessonItem.pj_gg =gg;
  2674. lessonItem.pj_go =go;
  2675. lessonItem.pj_pc =pc;
  2676. lessonItem.pj_pg =pg;
  2677. lessonItem.pj_po =po;
  2678. }
  2679. }
  2680. {
  2681. //协作相关指数
  2682. var n = studentLessonData.coworkRecord.itemRecords.Count()*1.0;
  2683. if (n>0)
  2684. {
  2685. //总的协作成果数
  2686. var w = studentLessonData.coworkRecord.itemRecords.Where(x => x.resultWeight>0);
  2687. double ss = w.Sum(x => x.itemScore)*1.0;
  2688. double sw = w.Sum(x => x.resultWeight)*1.0;
  2689. double wc = w.Count()*1.0;
  2690. double x = 0.0;
  2691. if (wc>0)
  2692. {
  2693. x=sw/(j *wc);
  2694. }
  2695. double max_xzcg = 40;
  2696. double k = (wc*wc/n+x)/n+ wc*(ss/max_xzcg)* (wc/n);
  2697. double f6 = Math.Round(190*1.0/(1+Math.Exp(-(k)))-95, 4);
  2698. double f7 = Math.Round(200*1.0/(1+Math.Exp(-(k)))-100, 4);
  2699. lessonItem.xz_fqc =n;
  2700. lessonItem.xz_cyc =wc;
  2701. lessonItem.xz_cgf =ss;
  2702. lessonItem.xz_cx =f6;
  2703. lessonItem.xz_cy =f7;
  2704. }
  2705. //_logger.LogInformation($"{studentLessonData.id}=>协作指数:{f6}\t专注指数:{f7}\t协作次数:{n}\t参与次数:{wc}\t协作成果分数:{ss}\t{k}");
  2706. }
  2707. double xx_cx = 0, xx_cy = 0;
  2708. int avg_cx = 0, avg_cy = 0;
  2709. if (lessonItem.xz_cx>0 && codeBools.FindAll(x=>x.code.Equals("xz") && x.value==true).IsNotEmpty())
  2710. {
  2711. avg_cx+=1;
  2712. }
  2713. if (lessonItem.pj_nl>0 && codeBools.FindAll(x => x.code.Equals("pj") && x.value==true).IsNotEmpty())
  2714. {
  2715. avg_cx+=1;
  2716. }
  2717. if (lessonItem.rw_cx>0 && codeBools.FindAll(x => x.code.Equals("rw") && x.value==true).IsNotEmpty())
  2718. {
  2719. avg_cx+=1;
  2720. }
  2721. if (lessonItem.pc_df>0 && codeBools.FindAll(x => x.code.Equals("pc") && x.value==true).IsNotEmpty())
  2722. {
  2723. avg_cx+=1;
  2724. }
  2725. if (lessonItem.hd_cx > 0 && codeBools.FindAll(x => x.code.Equals("hd") && x.value == true).IsNotEmpty())
  2726. {
  2727. avg_cx+=1;
  2728. }
  2729. if (lessonItem.hz_nl>0 )
  2730. {
  2731. avg_cx+=1;
  2732. }
  2733. //if (lessonItem.zh_tr>0)
  2734. //{
  2735. // avg_cx+=1;
  2736. //}
  2737. if (avg_cx>0)
  2738. {
  2739. xx_cx+=Math.Round(lessonItem.hd_cx * 1.0/avg_cx+ lessonItem.pc_df* 1.0/avg_cx+ lessonItem.rw_cx* 1.0/avg_cx+ lessonItem.pj_nl* 1.0/avg_cx+ lessonItem.xz_cx* 1.0/avg_cx+ lessonItem.hz_nl* 1.0/avg_cx, 4);
  2740. }
  2741. if (lessonItem.xz_cy>0 && codeBools.FindAll(x => x.code.Equals("xz") && x.value==true).IsNotEmpty())
  2742. {
  2743. avg_cy+=1;
  2744. }
  2745. if (lessonItem.pj_nl>0 && codeBools.FindAll(x => x.code.Equals("pj") && x.value==true).IsNotEmpty())
  2746. {
  2747. avg_cy+=1;
  2748. }
  2749. if (lessonItem.rw_cy>0 && codeBools.FindAll(x => x.code.Equals("rw") && x.value==true).IsNotEmpty())
  2750. {
  2751. avg_cy+=1;
  2752. }
  2753. if (lessonItem.pc_zd>0 && codeBools.FindAll(x => x.code.Equals("pc") && x.value==true).IsNotEmpty())
  2754. {
  2755. avg_cy+=1;
  2756. }
  2757. if (lessonItem.hd_cy>0 && codeBools.FindAll(x => x.code.Equals("hd") && x.value==true).IsNotEmpty())
  2758. {
  2759. avg_cy+=1;
  2760. }
  2761. if (lessonItem.hz_nl>0)
  2762. {
  2763. avg_cy+=1;
  2764. }
  2765. //if (lessonItem.zh_tr>0)
  2766. //{
  2767. // avg_cy+=1;
  2768. //}
  2769. if (avg_cy>0)
  2770. {
  2771. xx_cy+=Math.Round(lessonItem.hd_cy * 1.0/avg_cy+ lessonItem.pc_zd* 1.0/avg_cy+ lessonItem.rw_cy* 1.0/avg_cy+ lessonItem.pj_nl* 1.0/avg_cy+ lessonItem.xz_cy* 1.0/avg_cy+ lessonItem.hz_nl* 1.0/avg_cy, 4);
  2772. }
  2773. lessonItem.xx_cx=xx_cx;
  2774. lessonItem.xx_cy=xx_cy;
  2775. lessonItems.Add(lessonItem);
  2776. studentLessonData.achieve= lessonItem.xx_cx;
  2777. studentLessonData.attitude= lessonItem.xx_cy;
  2778. studentLessonData.appraise= lessonItem.pj_nl;
  2779. studentLessonData.cowork= lessonItem.xz_cx;
  2780. studentLessonData.cooperation=lessonItem.hz_nl;
  2781. }
  2782. return lessonItems;
  2783. }
  2784. static double CalculateScore(int n, double k = 1)
  2785. {
  2786. if (n == 0)
  2787. {
  2788. return 0;
  2789. }
  2790. else
  2791. {
  2792. double score = 60 + (40 / (1 + Math.Exp(-k * (n - 1))));
  2793. return Math.Max(80, Math.Min(score, 100));
  2794. }
  2795. }
  2796. /// <summary>
  2797. /// 使用标准差定义异常值。如果一个数字与平均值的偏差超过某个标准差倍数(例如2倍或3倍),则可以认为它是异常的。
  2798. /// </summary>
  2799. /// <param name="array"></param>
  2800. /// <returns></returns>
  2801. public static List<double> CleanDataBySDThreshold(IEnumerable<double> array, double thresholdMultiplier = 2)
  2802. {
  2803. if (array.Count() == 0) return new List<double>();
  2804. double average = Math.Round(array.Sum()*1.0/array.Count(), 4);
  2805. double variance = array.Select(x => Math.Round(Math.Pow(x - average, 2), 4)).Sum()*1.0/array.Count();
  2806. double standardDeviation = Math.Sqrt(Math.Round(variance, 4));
  2807. double threshold = Math.Round(thresholdMultiplier * standardDeviation);
  2808. List<double> datas = new List<double>();
  2809. foreach (double value in array)
  2810. {
  2811. double deviation = Math.Round(Math.Abs(value - average), 4);
  2812. if (deviation <= threshold)
  2813. {
  2814. datas.Add(value);
  2815. }
  2816. }
  2817. return datas;
  2818. }
  2819. /// <summary>
  2820. ///
  2821. /// </summary>
  2822. /// <param name="items"></param>
  2823. /// <param name="filePath"></param>
  2824. /// <returns></returns>
  2825. public static async Task ExportToExcelAzureBlob(List<StudentLessonItem> items, AzureStorageFactory azureStorage,string owner , string path , XmlDocument xmlDocument,List<string> summarys, PropertyInfo[] properties)
  2826. {
  2827. ExcelPackage.LicenseContext = OfficeOpenXml.LicenseContext.NonCommercial;
  2828. using (var memoryStream = new MemoryStream())
  2829. {
  2830. using (ExcelPackage package = new ExcelPackage())
  2831. {
  2832. ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("学生课中数据");
  2833. // 添加表头
  2834. int currentRow = 1;
  2835. #if !DEBUG
  2836. // 获取类的属性
  2837. if(properties==null || properties.Length==0)
  2838. {
  2839. properties = typeof(StudentLessonItem).GetProperties();
  2840. }
  2841. for (int i = 0; i < properties.Length; i++)
  2842. {
  2843. string summary = Regex.Replace(GetPropertySummary(properties[i], xmlDocument), @"\s+", "");
  2844. worksheet.Cells[currentRow, i + 1].Value = summary;
  2845. }
  2846. #else
  2847. for (int i = 0; i < summarys.Count; i++)
  2848. {
  2849. worksheet.Cells[currentRow, i + 1].Value = summarys[i];
  2850. }
  2851. #endif
  2852. // 填充数据
  2853. currentRow = 2;
  2854. foreach (var item in items)
  2855. {
  2856. for (int i = 0; i < properties.Length; i++)
  2857. {
  2858. worksheet.Cells[currentRow, i + 1].Value = properties[i].GetValue(item);
  2859. }
  2860. currentRow++;
  2861. }
  2862. // 设置表格样式
  2863. worksheet.Cells[worksheet.Dimension.Address].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Left;
  2864. worksheet.Cells[worksheet.Dimension.Address].Style.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Top;
  2865. // 保存到文件流
  2866. await package.SaveAsAsync(memoryStream);
  2867. memoryStream.Position=0;
  2868. }
  2869. await azureStorage.GetBlobContainerClient(owner).UploadFileByContainer(memoryStream, "records", path);
  2870. }
  2871. }
  2872. /// <summary>
  2873. /// 导出Excel
  2874. /// </summary>
  2875. /// <param name="items"></param>
  2876. /// <param name="filePath"></param>
  2877. /// <returns></returns>
  2878. public static async Task ExportToExcelLocal(List<StudentLessonItem> items, string filePath, XmlDocument xmlDocument)
  2879. {
  2880. ExcelPackage.LicenseContext = OfficeOpenXml.LicenseContext.NonCommercial;
  2881. using (ExcelPackage package = new ExcelPackage())
  2882. {
  2883. ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("学生课中数据");
  2884. // 获取类的属性
  2885. PropertyInfo[] properties = typeof(StudentLessonItem).GetProperties();
  2886. // 添加表头
  2887. int currentRow = 1;
  2888. for (int i = 0; i < properties.Length; i++)
  2889. {
  2890. string summary = Regex.Replace(GetPropertySummary(properties[i], xmlDocument), @"\s+", "");
  2891. worksheet.Cells[currentRow, i + 1].Value = summary;
  2892. }
  2893. // 填充数据
  2894. currentRow = 2;
  2895. foreach (var item in items)
  2896. {
  2897. for (int i = 0; i < properties.Length; i++)
  2898. {
  2899. worksheet.Cells[currentRow, i + 1].Value = properties[i].GetValue(item);
  2900. }
  2901. currentRow++;
  2902. }
  2903. // 设置表格样式
  2904. worksheet.Cells[worksheet.Dimension.Address].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Left;
  2905. worksheet.Cells[worksheet.Dimension.Address].Style.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Top;
  2906. // 保存到文件
  2907. FileInfo fileInfo = new System.IO.FileInfo(filePath);
  2908. await package.SaveAsAsync(fileInfo);
  2909. }
  2910. }
  2911. public static string GetPropertySummary(PropertyInfo property, XmlDocument xmlDocument)
  2912. {
  2913. XmlNodeList? xmlNodeList = xmlDocument.DocumentElement?.SelectNodes("//member[@name='P:" + property.DeclaringType?.FullName + "." + property.Name + "']");
  2914. if (xmlNodeList!= null && xmlNodeList.Count > 0)
  2915. {
  2916. XmlNode? xmlNode = xmlNodeList[0];
  2917. if (xmlNode != null && xmlNode.FirstChild != null)
  2918. {
  2919. return xmlNode.FirstChild.InnerText;
  2920. }
  2921. }
  2922. return property.Name;
  2923. }
  2924. /// <summary>
  2925. /// 当前数超越集合的百分比
  2926. /// </summary>
  2927. /// <param name="nums"></param>
  2928. /// <param name="curr"></param>
  2929. /// <returns></returns>
  2930. public static (double persent, int count) GetPersent(List<KeyValuePair<double, int>> nums, double curr)
  2931. {
  2932. int count = 0;
  2933. foreach (var op in nums.Select(x=>x.Key).OrderBy(x => x))
  2934. {
  2935. if (op <= curr)
  2936. {
  2937. count+=nums.Find(x=>x.Key==op).Value;
  2938. }
  2939. else
  2940. {
  2941. break;
  2942. }
  2943. }
  2944. return (count *1.0/ nums.Select(x=>x.Value).Sum() * 100, count);
  2945. }
  2946. /// <summary>
  2947. /// 当前数超越集合的百分比
  2948. /// </summary>
  2949. /// <param name="nums"></param>
  2950. /// <param name="curr"></param>
  2951. /// <returns></returns>
  2952. public static (double persent, int count) GetPersent(IEnumerable<double> nums, double curr)
  2953. {
  2954. int count = 0;
  2955. foreach (var op in nums.OrderBy(x => x))
  2956. {
  2957. if (op <= curr)
  2958. {
  2959. count++;
  2960. }
  2961. else
  2962. {
  2963. break;
  2964. }
  2965. }
  2966. return (count *1.0/ nums.Count() * 100, count);
  2967. }
  2968. }
  2969. /// <summary>
  2970. /// 学生导出Excel的Entity
  2971. /// </summary>
  2972. public class StudentLessonItem
  2973. {
  2974. /// <summary>
  2975. /// 学生id
  2976. /// </summary>
  2977. public string? studentId { get; set; }
  2978. /// <summary>
  2979. /// 互动发起次数
  2980. /// </summary>
  2981. public double hd_fqc { get; set; } = 0;
  2982. /// <summary>
  2983. /// 互动参与次数
  2984. /// </summary>
  2985. public double hd_cyc { get; set; } = 0;
  2986. /// <summary>
  2987. /// 互动正确次数
  2988. /// </summary>
  2989. public double hd_zqc { get; set; } = 0;
  2990. /// <summary>
  2991. /// 普通挑人
  2992. /// </summary>
  2993. public double pt_tr { get; set; } = 0;
  2994. /// <summary>
  2995. /// 智慧挑人
  2996. /// </summary>
  2997. public double zh_tr { get; set; } = 0;
  2998. /// <summary>
  2999. /// 个人计分
  3000. /// </summary>
  3001. public double gr_jf { get; set; } = 0;
  3002. /// <summary>
  3003. /// 互动成效指数
  3004. /// </summary>
  3005. public double hd_cx { get; set; } = 0;
  3006. /// <summary>
  3007. /// 互动专注指数
  3008. /// </summary>
  3009. public double hd_cy { get; set; } = 0;
  3010. /// <summary>
  3011. /// 评测得分率
  3012. /// </summary>
  3013. public double pc_df { get; set; } = 0;
  3014. /// <summary>
  3015. /// 评测作答率
  3016. /// </summary>
  3017. public double pc_zd { get; set; } = 0;
  3018. /// <summary>
  3019. /// 任务发起次数
  3020. /// </summary>
  3021. public double rw_fqc { get; set; } = 0;
  3022. /// <summary>
  3023. /// 任务参与次数
  3024. /// </summary>
  3025. public double rw_cyc { get; set; } = 0;
  3026. /// <summary>
  3027. /// 任务作品数
  3028. /// </summary>
  3029. public double rw_zpc { get; set; } = 0;
  3030. /// <summary>
  3031. /// 任务成效指数
  3032. /// </summary>
  3033. public double rw_cx { get; set; } = 0;
  3034. /// <summary>
  3035. /// 任务专注指数
  3036. /// </summary>
  3037. public double rw_cy { get; set; } = 0;
  3038. /// <summary>
  3039. /// 评价发起次数
  3040. /// </summary>
  3041. public double pj_cs { get; set; } = 0;
  3042. /// <summary>
  3043. /// 投票发起次数
  3044. /// </summary>
  3045. public double pj_vc { get; set; } = 0;
  3046. /// <summary>
  3047. /// 投票得票数
  3048. /// </summary>
  3049. public double pj_vg { get; set; } = 0;
  3050. /// <summary>
  3051. /// 投票次数
  3052. /// </summary>
  3053. public double pj_vo { get; set; } = 0;
  3054. /// <summary>
  3055. /// 星光发起次数
  3056. /// </summary>
  3057. public double pj_gc { get; set; } = 0;
  3058. /// <summary>
  3059. /// 星光得分数
  3060. /// </summary>
  3061. public double pj_gg { get; set; } = 0;
  3062. /// <summary>
  3063. /// 星光评分次数
  3064. /// </summary>
  3065. public double pj_go { get; set; } = 0;
  3066. /// <summary>
  3067. /// 互评发起次数
  3068. /// </summary>
  3069. public double pj_pc { get; set; } = 0;
  3070. /// <summary>
  3071. /// 互评得分数
  3072. /// </summary>
  3073. public double pj_pg { get; set; } = 0;
  3074. /// <summary>
  3075. /// 互评评分次数
  3076. /// </summary>
  3077. public double pj_po { get; set; } = 0;
  3078. /// <summary>
  3079. /// 评价能力
  3080. /// </summary>
  3081. public double pj_nl { get; set; } = 0;
  3082. /// <summary>
  3083. /// 协作发起次数
  3084. /// </summary>
  3085. public double xz_fqc { get; set; } = 0;
  3086. /// <summary>
  3087. /// 协作参与次数
  3088. /// </summary>
  3089. public double xz_cyc { get; set; } = 0;
  3090. /// <summary>
  3091. /// 协作成果分数
  3092. /// </summary>
  3093. public double xz_cgf { get; set; } = 0;
  3094. /// <summary>
  3095. /// 协作能力指数
  3096. /// </summary>
  3097. public double xz_cx { get; set; } = 0;
  3098. /// <summary>
  3099. /// 协作专注指数
  3100. /// </summary>
  3101. public double xz_cy { get; set; } = 0;
  3102. /// <summary>
  3103. /// 小组挑人
  3104. /// </summary>
  3105. public double xz_tr { get; set; } = 0;
  3106. /// <summary>
  3107. /// 小组计分
  3108. /// </summary>
  3109. public double xz_jf { get; set; } = 0;
  3110. /// <summary>
  3111. /// 小组协作成果分
  3112. /// </summary>
  3113. public double xz_xz { get; set; } = 0;
  3114. /// <summary>
  3115. /// 组任务上传数
  3116. /// </summary>
  3117. public double xz_sc { get; set; } = 0;
  3118. /// <summary>
  3119. /// 合作能力
  3120. /// </summary>
  3121. public double hz_nl { get; set; } = 0;
  3122. /// <summary>
  3123. /// 学习成效
  3124. /// </summary>
  3125. public double xx_cx { get; set; } = 0;
  3126. /// <summary>
  3127. /// 学习专注度
  3128. /// </summary>
  3129. public double xx_cy { get; set; } = 0;
  3130. }
  3131. /// <summary>
  3132. ///
  3133. /// </summary>
  3134. public class LessonDataAnalysisModel {
  3135. /// <summary>
  3136. /// 任务模型
  3137. /// </summary>
  3138. public List<KeyValuePair<double, int>> task { get; set;}= new List<KeyValuePair<double, int>>();
  3139. /// <summary>
  3140. /// irs模型
  3141. /// </summary>
  3142. public List<KeyValuePair<double, int>> irs { get; set; } = new List<KeyValuePair<double, int>>();
  3143. /// <summary>
  3144. /// 互动模型
  3145. /// </summary>
  3146. public List<KeyValuePair<double, int>> interactNormal { get; set; } = new List<KeyValuePair<double, int>>();
  3147. /// <summary>
  3148. /// 个人计分模型
  3149. /// </summary>
  3150. public List<KeyValuePair<double, int>> pscore { get; set; } = new List<KeyValuePair<double, int>>();
  3151. /// <summary>
  3152. /// 小组计分模型
  3153. /// </summary>
  3154. public List<KeyValuePair<double, int>> gscore { get; set; } = new List<KeyValuePair<double, int>>();
  3155. /// <summary>
  3156. /// 互动计分模型
  3157. /// </summary>
  3158. public List<KeyValuePair<double, int>> tscore { get; set; } = new List<KeyValuePair<double, int>>();
  3159. /// <summary>
  3160. /// 学生个人协作模型
  3161. /// </summary>
  3162. public List<KeyValuePair<double, int>> stuCowork { get; set; } = new List<KeyValuePair<double, int>>();
  3163. /// <summary>
  3164. /// 学生小组协作模型
  3165. /// </summary>
  3166. public List<KeyValuePair<double, int>> groupCowork { get; set; } = new List<KeyValuePair<double, int>>();
  3167. /// <summary>
  3168. /// 互动次数及格线
  3169. /// </summary>
  3170. public double interactPass { get; set; }
  3171. /// <summary>
  3172. /// 互动次数良好线
  3173. /// </summary>
  3174. public double interactGood { get; set; }
  3175. /// <summary>
  3176. /// 互动次数差线
  3177. /// </summary>
  3178. public double interactLow { get; set; }
  3179. /// <summary>
  3180. /// 互动次数中线
  3181. /// </summary>
  3182. public double interactMedium { get; set; }
  3183. /// <summary>
  3184. /// 互动次数高线
  3185. /// </summary>
  3186. public double interactHigh { get; set; }
  3187. public List<KeyValuePair<double, List<double>>> levelInteract { get; set; } = new List<KeyValuePair<double, List<double>>>();
  3188. }
  3189. /// <summary>
  3190. /// 历史课例的关键数据模型
  3191. /// </summary>
  3192. public class LessonDataAnalysisCluster : LessonDataAnalysisBase
  3193. {
  3194. /// <summary>
  3195. ///
  3196. /// </summary>
  3197. // public List<KeyValuePair<double, List<double>>> clustersInteract { get; set; } = new List<KeyValuePair<double, List<double>>>();
  3198. ///// <summary>
  3199. /////
  3200. ///// </summary>
  3201. //public List<KeyValuePair<double, List<double>>> clustersPscore { get; set; } = new List<KeyValuePair<double, List<double>>>();
  3202. ///// <summary>
  3203. /////
  3204. ///// </summary>
  3205. //public List<KeyValuePair<double, List<double>>> clustersTscore { get; set; } = new List<KeyValuePair<double, List<double>>>();
  3206. ///// <summary>
  3207. /////
  3208. ///// </summary>
  3209. //public List<KeyValuePair<double, List<double>>> clustersGscore { get; set; } = new List<KeyValuePair<double, List<double>>>();
  3210. public List<KeyValuePair<double, List<double>>> levelInteract { get; set; } = new List<KeyValuePair<double, List<double>>>();
  3211. public double interactPass { get; set; }
  3212. public double interactGood { get; set; }
  3213. public double interactLow { get; set; }
  3214. public double interactMedium { get; set; }
  3215. public double interactHigh { get; set; }
  3216. }
  3217. /// <summary>
  3218. ///
  3219. /// </summary>
  3220. public abstract class LessonDataAnalysisBase
  3221. {
  3222. ///// <summary>
  3223. ///// 协作次数
  3224. ///// </summary>
  3225. //public IEnumerable<double> cowork { get; set; } = new List<double>();
  3226. ///// <summary>
  3227. /////
  3228. ///// </summary>
  3229. //public IEnumerable<double> coworkBase { get; set; } = new List<double>();
  3230. /// <summary>
  3231. ///
  3232. /// </summary>
  3233. public List<double> task { get; set; } = new List<double>();
  3234. ///// <summary>
  3235. /////
  3236. ///// </summary>
  3237. //public IEnumerable<double> taskBase { get; set; } = new List<double>();
  3238. ///// <summary>
  3239. /////
  3240. ///// </summary>
  3241. //public IEnumerable<double> exam { get; set; } = new List<double>();
  3242. ///// <summary>
  3243. /////
  3244. ///// </summary>
  3245. //public IEnumerable<double> examBase { get; set; } = new List<double>();
  3246. ///// <summary>
  3247. /////
  3248. ///// </summary>
  3249. //public IEnumerable<double> smartRating { get; set; } = new List<double>();
  3250. ///// <summary>
  3251. /////
  3252. ///// </summary>
  3253. //public IEnumerable<double> smartRatingBase { get; set; } = new List<double>();
  3254. /// <summary>
  3255. ///
  3256. /// </summary>
  3257. public List<double> irs { get; set; } = new List<double>();
  3258. /// <summary>
  3259. ///
  3260. /// </summary>
  3261. public List<double> interactNormal { get; set; } = new List<double>();
  3262. /// <summary>
  3263. /// 个人计分
  3264. /// </summary>
  3265. public List<double> pscore { get; set; } = new List<double>();
  3266. /// <summary>
  3267. /// 小组计分
  3268. /// </summary>
  3269. public List<double> gscore { get; set; } = new List<double>();
  3270. /// <summary>
  3271. /// 互动计分
  3272. /// </summary>
  3273. public List<double> tscore { get; set; } = new List<double>();
  3274. /// <summary>
  3275. /// 作品上传数
  3276. /// </summary>
  3277. public List<List<double>> upload { get; set; } = new List<List<double>>();
  3278. /// <summary>
  3279. /// 学生协作成果数
  3280. /// </summary>
  3281. public List<double> stuCowork { get; set; } = new List<double>();
  3282. /// <summary>
  3283. /// 小组协作成果数
  3284. /// </summary>
  3285. public List<double> groupCowork { get; set; } = new List<double>();
  3286. /// <summary>
  3287. /// 挑人集合
  3288. /// </summary>
  3289. public List<List<string>> pickup { get; set; } = new List<List<string>>();
  3290. ///// <summary>
  3291. ///// 挑人集合-小组
  3292. ///// </summary>
  3293. //public List<List<string>> pickup_group { get; set; } = new List<List<string>>();
  3294. }
  3295. /// <summary>
  3296. /// 每月的课例模型数据
  3297. /// </summary>
  3298. public class LessonDataAnalysisMonth : LessonDataAnalysisBase
  3299. {
  3300. /// <summary>
  3301. /// 时间戳
  3302. /// </summary>
  3303. public long updateTime { get; set; }
  3304. /// <summary>
  3305. /// yyyyMM
  3306. /// </summary>
  3307. public string? yearMonth { get; set; }
  3308. }
  3309. /// <summary>
  3310. ///
  3311. /// </summary>
  3312. public class LessonLocal
  3313. {
  3314. /// <summary>
  3315. ///
  3316. /// </summary>
  3317. public LessonBase? lessonBase { get; set; }
  3318. /// <summary>
  3319. ///
  3320. /// </summary>
  3321. public TimeLineData? timeLineData { get; set; }
  3322. /// <summary>
  3323. ///
  3324. /// </summary>
  3325. public LessonRecord? lessonRecord { get; set; }
  3326. /// <summary>
  3327. ///
  3328. /// </summary>
  3329. public List<LocalStudent> studentLessonDatas { get; set; } = new List<LocalStudent>();
  3330. /// <summary>
  3331. ///
  3332. /// </summary>
  3333. public List<TaskData> taskDatas { get; set; } = new List<TaskData>();
  3334. /// <summary>
  3335. ///
  3336. /// </summary>
  3337. public List<SmartRatingData> smartRatingDatas { get; set; } = new List<SmartRatingData>();
  3338. /// <summary>
  3339. ///
  3340. /// </summary>
  3341. public List<IRSData> irsDatas { get; set; } = new List<IRSData>();
  3342. /// <summary>
  3343. ///
  3344. /// </summary>
  3345. public List<CoworkData> coworkDatas { get; set; } = new List<CoworkData>();
  3346. /// <summary>
  3347. ///
  3348. /// </summary>
  3349. public List<ExamData> examDatas { get; set; } = new List<ExamData>();
  3350. /// <summary>
  3351. ///
  3352. /// </summary>
  3353. public List<TimeLineEvent> sokratesDatas { get; set; } = new List<TimeLineEvent>();
  3354. }
  3355. /// <summary>
  3356. ///
  3357. /// </summary>
  3358. public class TechCount
  3359. {
  3360. public string? yearMonth { get; set; }
  3361. /// <summary>
  3362. ///
  3363. /// </summary>
  3364. public string? lessonId { get; set; }
  3365. /// <summary>
  3366. /// 评测数量
  3367. /// </summary>
  3368. public int examCount { get; set; }
  3369. /// <summary>
  3370. /// 任务数量
  3371. /// </summary>
  3372. public int taskCount { get; set; }
  3373. /// <summary>
  3374. /// IRS次数
  3375. /// </summary>
  3376. public int irsCount { get; set; }
  3377. /// <summary>
  3378. /// 互动次数
  3379. /// </summary>
  3380. //public int interactExamCount { get; set; }
  3381. /// <summary>
  3382. /// 互动次数
  3383. /// </summary>
  3384. public int interactNormalCount { get; set; }
  3385. /// <summary>
  3386. /// 协作次数
  3387. /// </summary>
  3388. public int coworkCount { get; set; }
  3389. /// <summary>
  3390. /// 智能评分次数
  3391. /// </summary>
  3392. public int smartRatingCount { get; set; }
  3393. /// <summary>
  3394. ///
  3395. /// </summary>
  3396. public List<CodeLong> timeCount { get; set; } = new List<CodeLong>();
  3397. /// <summary>
  3398. ///
  3399. /// </summary>
  3400. public IEnumerable<double> pscore { get; set; } = new List<double>();
  3401. /// <summary>
  3402. ///
  3403. /// </summary>
  3404. public IEnumerable<double> gscore { get; set; } = new List<double>();
  3405. /// <summary>
  3406. ///
  3407. /// </summary>
  3408. public IEnumerable<double> tscore { get; set; } = new List<double>();
  3409. /// <summary>
  3410. /// 评测数量
  3411. /// </summary>
  3412. public int examCountBase { get; set; }
  3413. /// <summary>
  3414. /// 任务数量
  3415. /// </summary>
  3416. public int taskCountBase { get; set; }
  3417. /// <summary>
  3418. /// IRS次数
  3419. /// </summary>
  3420. public int irsCountBase { get; set; }
  3421. /// <summary>
  3422. /// 互动次数
  3423. /// </summary>
  3424. //public int interactExamCountBase { get; set; }
  3425. /// <summary>
  3426. /// 互动次数
  3427. /// </summary>
  3428. public int interactNormalCountBase { get; set; }
  3429. /// <summary>
  3430. /// 协作次数
  3431. /// </summary>
  3432. public int coworkCountBase { get; set; }
  3433. /// <summary>
  3434. /// 智能评分次数
  3435. /// </summary>
  3436. public int smartRatingCountBase { get; set; }
  3437. /// <summary>
  3438. /// 作品上传数
  3439. /// </summary>
  3440. public List<List<double>> upload { get; set; } = new List<List<double>>();
  3441. /// <summary>
  3442. /// 学生协作成果数
  3443. /// </summary>
  3444. public List<double> stuCowork { get; set; } = new List<double>();
  3445. /// <summary>
  3446. /// 小组协作成果数
  3447. /// </summary>
  3448. public List<double> groupCowork { get; set; } = new List<double>();
  3449. public List<string> pickup { get; set; } = new List<string>();
  3450. }
  3451. }