LessonETLService.cs 205 KB

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