LessonETLService.cs 168 KB

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