LessonETLService.cs 175 KB

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