LessonETLService.cs 159 KB

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