LessonETLService.cs 120 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369
  1. using Azure;
  2. using Azure.Storage.Blobs.Models;
  3. using Microsoft.Extensions.Logging;
  4. using OfficeOpenXml;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Reflection;
  10. using System.Text;
  11. using System.Text.RegularExpressions;
  12. using System.Threading.Tasks;
  13. using System.Xml;
  14. using TEAMModelOS.SDK;
  15. using TEAMModelOS.SDK.DI;
  16. using TEAMModelOS.SDK.Extension;
  17. using TEAMModelOS.SDK.Models;
  18. namespace HTEX.Lib.ETL.Lesson
  19. {
  20. public class LessonETLService
  21. {
  22. /// <summary>
  23. /// 生成学生student-analysis.json
  24. /// </summary>
  25. /// <param name="objectiveTypes"></param>
  26. /// <param name="azureStorage"></param>
  27. /// <param name="lessonLocal"></param>
  28. /// <returns></returns>
  29. public static async Task DoStudentLessonData(List<string> objectiveTypes, AzureStorageFactory azureStorage, LessonLocal? lessonLocal)
  30. {
  31. List<StudentLessonData> studentLessonDatas = lessonLocal.studentLessonDatas.ToJsonString().ToObject<List<StudentLessonData>>();
  32. studentLessonDatas = LessonETLService.GetIRSData(lessonLocal.lessonBase!, lessonLocal.timeLineData!, lessonLocal.irsDatas, studentLessonDatas, lessonLocal.examDatas,lessonLocal?.lessonRecord?.id);
  33. studentLessonDatas = LessonETLService.GetCoworkData(lessonLocal.lessonBase!, lessonLocal.timeLineData!, lessonLocal.coworkDatas, studentLessonDatas, lessonLocal.lessonRecord.id);
  34. studentLessonDatas = LessonETLService.GetExamData(lessonLocal.lessonBase!, lessonLocal.timeLineData!, lessonLocal.examDatas, studentLessonDatas, objectiveTypes, lessonLocal.lessonRecord.id);
  35. studentLessonDatas = LessonETLService.GetSmartRatingData(lessonLocal.lessonBase!, lessonLocal.timeLineData!, lessonLocal.smartRatingDatas, studentLessonDatas, lessonLocal.lessonRecord.id);
  36. studentLessonDatas = LessonETLService.GetTaskData(lessonLocal.lessonBase!, lessonLocal.timeLineData!, lessonLocal.taskDatas, studentLessonDatas, lessonLocal.lessonRecord.id);
  37. string owner = lessonLocal.lessonRecord.scope.Equals("school") ? lessonLocal.lessonRecord.school : lessonLocal.lessonRecord.tmdid;
  38. if (!azureStorage.GetBlobContainerClient(owner).GetBlobClient($"records/{lessonLocal.lessonRecord.id}/student-analysis.json").Exists())
  39. {
  40. await azureStorage.GetBlobContainerClient(owner).UploadFileByContainer(studentLessonDatas.ToJsonString(), "records", $"{lessonLocal.lessonRecord.id}/student-analysis.json");
  41. }
  42. }
  43. public static async IAsyncEnumerable<LessonLocal> GetLessonLocal(List<LessonRecord> lessonRecords, List<string> localIds, AzureStorageFactory _azureStorage,string pathLessons)
  44. {
  45. foreach (var lessonRecord in lessonRecords)
  46. {
  47. string scope = lessonRecord.scope;
  48. string owner = lessonRecord.scope.Equals("school") ? lessonRecord.school : lessonRecord.tmdid;
  49. if (localIds.Contains(lessonRecord.id))
  50. {
  51. continue;
  52. }
  53. string yearMonthPath = DateTimeOffset.FromUnixTimeMilliseconds(lessonRecord.startTime).ToString("yyyyMM");
  54. LessonLocal lessonLocal = new LessonLocal { lessonRecord=lessonRecord };
  55. if (System.IO.File.Exists($"{pathLessons}\\MM{yearMonthPath}\\{lessonRecord.id}-local.json"))
  56. {
  57. string jsonp = await System.IO.File.ReadAllTextAsync($"{pathLessons}\\MM{yearMonthPath}\\{lessonRecord.id}-local.json");
  58. lessonLocal = jsonp.ToObject<LessonLocal>();
  59. }
  60. else
  61. {
  62. List<string> files = new List<string>()
  63. {
  64. $"/records/{lessonRecord.id}/IES/TimeLine.json",
  65. $"/records/{lessonRecord.id}/IES/base.json",
  66. $"/records/{lessonRecord.id}/IES/Task.json",
  67. $"/records/{lessonRecord.id}/IES/SmartRating.json",
  68. $"/records/{lessonRecord.id}/IES/IRS.json",
  69. $"/records/{lessonRecord.id}/IES/Cowork.json",
  70. $"/records/{lessonRecord.id}/Sokrates/SokratesRecords.json",
  71. };
  72. lessonLocal = new LessonLocal { lessonRecord=lessonRecord };
  73. lessonLocal = await GetLessonFiles(lessonLocal, files, owner,_azureStorage);
  74. }
  75. if (lessonLocal.lessonBase!=null && lessonLocal.lessonBase.student!=null)
  76. {
  77. var baseData = GetBaseData(lessonLocal.lessonBase!);
  78. lessonLocal.studentLessonDatas= baseData.studentLessonDatas;
  79. List<ExamData> examDatas = await GetExamInfo(lessonRecord, lessonLocal.timeLineData,_azureStorage,owner );
  80. lessonLocal.examDatas = examDatas;
  81. lessonLocal.sokratesDatas= lessonLocal.sokratesDatas.IsNotEmpty() ? lessonLocal.sokratesDatas : lessonLocal.timeLineData!=null ? lessonLocal.timeLineData.events : new List<TimeLineEvent>();
  82. }
  83. yield return lessonLocal;
  84. }
  85. }
  86. private static async Task<LessonLocal> GetLessonFiles(LessonLocal lessonLocal, List<string> files, string owner, AzureStorageFactory _azureStorage)
  87. {
  88. await Parallel.ForEachAsync(files, async (file, _) =>
  89. {
  90. try
  91. {
  92. var exists = _azureStorage.GetBlobContainerClient(owner).GetBlobClient(file).Exists();
  93. if (exists)
  94. {
  95. BlobDownloadResult blobDownloadResult = await _azureStorage.GetBlobContainerClient(owner).GetBlobClient(file).DownloadContentAsync();
  96. switch (true)
  97. {
  98. case bool when file.Contains("IES/TimeLine.json"):
  99. lessonLocal.timeLineData= blobDownloadResult.Content.ToObjectFromJson<TimeLineData>();
  100. break;
  101. case bool when file.Contains("IES/base.json"):
  102. lessonLocal.lessonBase= blobDownloadResult.Content.ToObjectFromJson<LessonBase>();
  103. break;
  104. case bool when file.Contains("IES/Task.json"):
  105. lessonLocal.taskDatas= blobDownloadResult.Content.ToObjectFromJson<List<TaskData>>();
  106. break;
  107. case bool when file.Contains("IES/SmartRating.json"):
  108. lessonLocal.smartRatingDatas= blobDownloadResult.Content.ToObjectFromJson<List<SmartRatingData>>();
  109. break;
  110. case bool when file.Contains("IES/IRS.json"):
  111. lessonLocal.irsDatas= blobDownloadResult.Content.ToObjectFromJson<List<IRSData>>();
  112. break;
  113. case bool when file.Contains("IES/Cowork.json"):
  114. lessonLocal.coworkDatas= blobDownloadResult.Content.ToObjectFromJson<List<CoworkData>>();
  115. break;
  116. case bool when file.Contains("Sokrates/SokratesRecords.json"):
  117. lessonLocal.sokratesDatas= blobDownloadResult.Content.ToObjectFromJson<List<TimeLineEvent>>();
  118. break;
  119. }
  120. }
  121. }
  122. catch (RequestFailedException ex)
  123. {
  124. Console.WriteLine($"{file},{ex.Message},{ex.StackTrace}");
  125. }
  126. catch (Exception ex)
  127. {
  128. Console.WriteLine($"{file},{ex.Message},{ex.StackTrace}");
  129. }
  130. });
  131. return lessonLocal;
  132. }
  133. /// <summary>
  134. /// 处理base.json的数据
  135. /// </summary>
  136. /// <param name="lessonRecord"></param>
  137. /// <param name="lessonBase"></param>
  138. /// <returns></returns>
  139. public static (LessonBase lessonBase, List<LocalStudent> studentLessonDatas) GetBaseData(LessonBase lessonBase)
  140. {
  141. //处理学生定位数据
  142. List<LocalStudent> studentLessonDatas = new List<LocalStudent>();
  143. int index = 0;
  144. try
  145. {
  146. if (lessonBase!=null)
  147. {
  148. lessonBase.student.ForEach(x =>
  149. {
  150. int attend = 0;
  151. var client = lessonBase.report.clientSummaryList.Find(y => y.seatID == x.seatID);
  152. if (client!=null)
  153. {
  154. attend=client.attendState;
  155. }
  156. studentLessonDatas.Add(new LocalStudent()
  157. {
  158. id = x.id,
  159. index = index,
  160. seatID =$"{x.seatID}",
  161. groupId = x.groupId,
  162. attend= attend
  163. });
  164. index++;
  165. });
  166. }
  167. }
  168. catch (Exception ex)
  169. {
  170. Console.WriteLine(lessonBase.ToJsonString());
  171. }
  172. return (lessonBase, studentLessonDatas);
  173. }
  174. /// <summary>
  175. ///读取互动信息
  176. ///Event 过滤类型 'PopQuesLoad', 'ReAtmpAnsStrt', 'BuzrAns','BuzrLoad'
  177. /// 在IRS.json处理 'PopQuesLoad'互动问答 , 'ReAtmpAnsStrt' 二次作答 , 'BuzrAns' 抢权(新), 'BuzrLoad'抢权(旧)
  178. ///TimeLine.json 中找到对应类型,根据Pgid 去 IRS.json 中找到对应数据,从clientAnswers 的下标对应 base.json 中的 student 找到对应学生信息 clientAnswers.length > 1 则表示有二次作答
  179. ///读取IRS.json
  180. /// </summary>
  181. /// <param name="lessonBase"></param>
  182. /// <param name="timeLineData"></param>
  183. /// <param name="irsDatas"></param>
  184. /// <param name="studentLessonDatas"></param>
  185. /// <param name="examDatas"></param>
  186. /// <param name="itemFiles"></param>
  187. /// <returns></returns>
  188. public static List<StudentLessonData> GetIRSData(LessonBase lessonBase, TimeLineData timeLineData, List<IRSData> irsDatas, List<StudentLessonData> studentLessonDatas, List<ExamData> examDatas,string lessonId)
  189. {
  190. List<string> interactTypes = new List<string>() { "PopQuesLoad", "ReAtmpAnsStrt", "BuzrAns", "BuzrLoad" };
  191. //去重页面
  192. 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() });
  193. if (enventsInteract!= null && enventsInteract.Count()>0)
  194. {
  195. var keys = enventsInteract.Select(x => x.key).ToList();
  196. foreach (var item in enventsInteract)
  197. {
  198. ProcessIRSPageData(irsDatas, studentLessonDatas, examDatas, item);
  199. }
  200. //处理其他,评测类型的互动,因为有可能不会记录在TimeLine.json中
  201. 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() });
  202. if (envents_other!=null && envents_other.Count()>0)
  203. {
  204. foreach (var item in envents_other)
  205. {
  206. ProcessIRSPageData(irsDatas, studentLessonDatas, examDatas, item);
  207. }
  208. }
  209. }
  210. else
  211. {
  212. //处理其他,评测类型的互动,因为有可能不会记录在TimeLine.json中
  213. if (timeLineData!=null)
  214. {
  215. var envents_other = timeLineData.events.Where(x => !string.IsNullOrWhiteSpace(x.Pgid)).GroupBy(x => x.Pgid).Select(x => new { key = x.Key, list = x.ToList() });
  216. if (envents_other!=null && envents_other.Count()>0)
  217. {
  218. foreach (var item in envents_other)
  219. {
  220. ProcessIRSPageData(irsDatas, studentLessonDatas, examDatas, item);
  221. }
  222. }
  223. }
  224. else
  225. {
  226. foreach (var item in irsDatas.Select(x => x.pageID))
  227. {
  228. ProcessIRSPageData(irsDatas, studentLessonDatas, examDatas, new { key = item });
  229. }
  230. }
  231. }
  232. //单独处理挑人的逻辑
  233. //是否从小组里面挑人。
  234. //不需要去重页面,直接获取挑人大类 PickupResult
  235. //小类处理:PickupRight , PickupOption , PickupNthGrp ,PickupEachGrp ,PickupDiff , PickupResult 挑人算不算互动?? 读取PickupMemberId "[\r\n 35\r\n]"
  236. var enventsPickup = timeLineData?.events.Where(x => !string.IsNullOrWhiteSpace(x.Pgid) && x.Event.Equals("PickupResult"));
  237. if (enventsPickup.IsNotEmpty())
  238. {
  239. foreach (var item in enventsPickup)
  240. {
  241. List<int> mbrs = item.PickupMemberId.ToObject<List<int>>();
  242. // 挑人挑中 TT ,没有挑中 T1
  243. foreach (var studentLessonData in studentLessonDatas)
  244. {
  245. var mbr = mbrs.FindAll(x => studentLessonData.seatID!.Equals($"{x}"));
  246. if (mbr.IsNotEmpty())
  247. {
  248. foreach (var m in mbr)
  249. {
  250. studentLessonData.attend=1;
  251. //studentLessonData.interactRecord.interactRecords.Add(new ItemRecord()
  252. //{
  253. // resultWeight = InteractWeight.TT,
  254. // resultType=InteractReultType.TT,
  255. // itemType = string.IsNullOrWhiteSpace(item.PickupType) ? "PickupResult" : item.PickupType
  256. //});
  257. studentLessonData.pickups.Add(string.IsNullOrWhiteSpace(item.PickupType) ? "1--PickupResult" : $"1--{item.PickupType}");
  258. }
  259. }
  260. else
  261. {
  262. //处理未挑中的
  263. if (studentLessonData.attend==1)
  264. {
  265. studentLessonData.pickups.Add(string.IsNullOrWhiteSpace(item.PickupType) ? "0--PickupResult" : $"0--{item.PickupType}");
  266. }
  267. }
  268. }
  269. }
  270. }
  271. return studentLessonDatas;
  272. }
  273. private static List<StudentLessonData> ProcessIRSPageData(List<IRSData> irsDatas, List<StudentLessonData> studentLessonDatas, List<ExamData> examDatas, dynamic item)
  274. {
  275. var irsDataPages = irsDatas.Where(y => item.key.Equals(y.pageID));
  276. foreach (var irsDataPage in irsDataPages)
  277. {
  278. //检查是否设置正确答案。
  279. var answers_q = irsDataPage.question?["exercise"]?["answer"]?.ToJsonString().ToObject<List<string>>();
  280. //根据题去找对应的试卷和评测信息
  281. var question_id = $"{irsDataPage.question?["id"]}";
  282. var examData = examDatas.Where(x => x.paper!=null && x.paper.slides.Exists(x => !string.IsNullOrWhiteSpace(x.url) && x.url.Equals($"{question_id}.json"))).FirstOrDefault();
  283. List<string> answers = new List<string>();
  284. answers_q?.ForEach(x => {
  285. if (!string.IsNullOrWhiteSpace(x))
  286. {
  287. answers.Add(x);
  288. }
  289. });
  290. var _objective = irsDataPage.question?["exercise"]?["objective"];
  291. var scoreNode = irsDataPage.question?["exercise"]?["score"];
  292. var _type = irsDataPage.question?["exercise"]?["type"];
  293. var _answerType = irsDataPage.question?["exercise"]?["answerType"];//file,audio,text,image
  294. var qitem = irsDataPage.question?["item"]?.AsArray();
  295. if (qitem!=null && qitem.Count()>0)
  296. {
  297. for (var i = 0; i<qitem.Count(); i++)
  298. {
  299. qitem[i]!["question"]="";
  300. }
  301. }
  302. double questionScore = 0;
  303. bool objective = false;
  304. if (_objective!=null)
  305. {
  306. objective = _objective.GetValue<bool>();
  307. }
  308. //题型
  309. string type = string.Empty;
  310. if (_type!=null)
  311. {
  312. //题型
  313. type = _type.GetValue<string>();
  314. List<string> types = new List<string>() { "single", "multiple", "judge", "sortmultiple" };
  315. if (types.Contains(type))
  316. {
  317. objective = true;
  318. }
  319. else
  320. {
  321. objective = false;
  322. }
  323. }
  324. if (_answerType!=null)
  325. {
  326. _answerType.GetValue<string>();
  327. //暂不处理,可能存在依然传文字的情况
  328. //不是文本作答的处理,题目不是客观题,答案不记录
  329. //if (!_answerType.Equals("text"))
  330. //{
  331. // objective=false;
  332. // answers=new List<string>();
  333. //}
  334. }
  335. if (scoreNode!=null)
  336. {
  337. double.TryParse(scoreNode.ToString(), out questionScore);
  338. }
  339. string interactType = string.Empty;
  340. if (irsDataPage.clientAnswers.IsNotEmpty())
  341. {
  342. //第一个list是几轮,一次作答,二次作答, 第二个list是学生的下标, 第三个list是 答案
  343. List<List<List<string>>> clientAnswers = new List<List<List<string>>>();
  344. foreach (var key in irsDataPage.clientAnswers.Keys)
  345. {
  346. clientAnswers.Add(irsDataPage.clientAnswers[key]);
  347. }
  348. // 获取第一个列表的长度作为比较基准
  349. int firstListLength = clientAnswers.First().Count;
  350. bool isSameLength = true;
  351. // 遍历剩余的列表并检查它们的长度是否与第一个列表相同
  352. foreach (var innerList in clientAnswers.Skip(1))
  353. {
  354. if (innerList.Count != firstListLength)
  355. {
  356. isSameLength = false;
  357. break;
  358. }
  359. }
  360. //并检查学生集合的长度是否与第一个列表相同
  361. if (isSameLength && studentLessonDatas.Count()==firstListLength)
  362. {
  363. for (int index = 0; index< clientAnswers[0].Count; index++)
  364. {
  365. var student = studentLessonDatas[index];
  366. double studentScore = 0;
  367. if (examData!=null && examData.examClassResult.IsNotEmpty())
  368. {
  369. var examResultIndex = examData.examClassResult.First().studentIds.IndexOf(student.id);
  370. var questionIndex = examData.paper.slides.Select(x => x.url).ToList().IndexOf($"{question_id}.json");
  371. if (examResultIndex>=0
  372. && examData.examClassResult.First().studentScores.Count>=(examResultIndex+1) //防止索引越界
  373. && examData.examClassResult.First().studentScores[examResultIndex].Count>=(questionIndex+1)) //防止索引越界
  374. {
  375. //获取index学生在questionIndex题的分数
  376. studentScore = examData.examClassResult.First().studentScores[examResultIndex][questionIndex];
  377. }
  378. }
  379. //index 代表学生下标
  380. List<ItemRecord> interactRecords = new List<ItemRecord>();
  381. if (clientAnswers.Count==1)
  382. {
  383. //即问即答
  384. interactType = "PopQuesLoad";
  385. var ans0 = clientAnswers[0][index];
  386. var IS0 = GetInteractResultHasAnswer(answers, ans0, objective, type, questionScore, studentScore);
  387. interactRecords.Add(new ItemRecord()
  388. {
  389. resultWeight = IS0.weight,
  390. resultType=IS0.reultType,
  391. itemType= interactType,
  392. criterion= questionScore,
  393. itemScore= IS0.interactScore
  394. });
  395. }
  396. if (clientAnswers.Count==2)
  397. {
  398. //二次作答
  399. interactType="ReAtmpAnsStrt";
  400. var ans1 = clientAnswers[1][index];
  401. var IS1 = GetInteractResultHasAnswer(answers, ans1, objective, type, questionScore, studentScore);
  402. interactRecords.Add(new ItemRecord()
  403. {
  404. resultWeight = IS1.weight,
  405. resultType=IS1.reultType,
  406. itemType= interactType,
  407. criterion= questionScore,
  408. itemScore= IS1.interactScore
  409. });
  410. }
  411. if (clientAnswers.Count>2)
  412. {
  413. //三次作答
  414. interactType="TeAtmpAnsStrt";
  415. var ans2 = clientAnswers[2][index];
  416. var IS2 = GetInteractResultHasAnswer(answers, ans2, objective, type, questionScore, studentScore);
  417. interactRecords.Add(new ItemRecord()
  418. {
  419. resultWeight = IS2.weight,
  420. resultType=IS2.reultType,
  421. itemType= interactType,
  422. criterion= questionScore,
  423. itemScore= IS2.interactScore
  424. });
  425. }
  426. if (studentLessonDatas[index].attend==1)
  427. {
  428. studentLessonDatas[index].interactRecord.interactRecords.AddRange(interactRecords);
  429. }
  430. }
  431. }
  432. }
  433. //是否抢权作答的模式
  434. if (irsDataPage.isBuzz)
  435. {
  436. interactType = "BuzrAns";
  437. //处理参与抢权的
  438. Dictionary<string, ItemRecord> buzzParticipants = new Dictionary<string, ItemRecord>();
  439. foreach (var buzzParticipant in irsDataPage.buzzParticipants)
  440. {
  441. var studentData = studentLessonDatas.Find(x => x.seatID!.Equals(buzzParticipant));
  442. if (studentData != null)
  443. {
  444. buzzParticipants[buzzParticipant]=new ItemRecord() { resultWeight = InteractWeight.T1, itemType= interactType, resultType= InteractReultType.T1 };
  445. }
  446. }
  447. //处理抢权成功的
  448. foreach (var buzzClient in irsDataPage.buzzClients)
  449. {
  450. buzzParticipants[buzzClient]=new ItemRecord() { resultWeight = InteractWeight.TT, itemType= interactType, resultType= InteractReultType.TT };
  451. }
  452. foreach (var studentLessonData in studentLessonDatas)
  453. {
  454. if (buzzParticipants.ContainsKey(studentLessonData.seatID!))
  455. {
  456. //处理已经有抢权结果的数据
  457. studentLessonData.attend=1;
  458. studentLessonData.interactRecord.interactRecords.Add(buzzParticipants[studentLessonData.seatID!]);
  459. }
  460. else
  461. {
  462. if (studentLessonData.attend==1)
  463. {
  464. //处理未参与抢权的
  465. studentLessonData.interactRecord.interactRecords.Add(new ItemRecord() { resultWeight = InteractWeight.T0, itemType = interactType, resultType= InteractReultType.T0 });
  466. }
  467. }
  468. }
  469. }
  470. }
  471. return studentLessonDatas;
  472. }
  473. private static (double weight, string reultType, double interactScore) GetInteractResultHasAnswer(List<string>? answers, List<string> ans0, bool objective, string type, double questionScore, double studentScore)
  474. {
  475. //List<string> ans0 = new List<string>();
  476. //ans?.ForEach(x => {
  477. // if (!string.IsNullOrWhiteSpace(x))
  478. // {
  479. // ans0.Add(x);
  480. // }
  481. // else { ans.Add("");}
  482. //});
  483. double weight = InteractWeight.T0;
  484. string reultType = InteractReultType.T0;
  485. double interactScore = 0;
  486. if (answers.IsNotEmpty())
  487. {
  488. if (ans0.IsNotEmpty())
  489. {
  490. if (objective) //客观题
  491. {
  492. //标准答案等于作答的结果
  493. if (answers!.Count == ans0.Count)
  494. {
  495. if (answers.All(item => ans0.Contains(item)))
  496. {
  497. //完全正确
  498. weight= InteractWeight.TT;
  499. reultType= InteractReultType.TT;
  500. interactScore= studentScore==0 ? questionScore : studentScore;
  501. }
  502. else
  503. {
  504. //作答错误
  505. weight= InteractWeight.T1;
  506. reultType = InteractReultType.T1;
  507. interactScore= studentScore;
  508. }
  509. }
  510. //标准答案比作答的结果多
  511. else if (answers!.Count > ans0.Count)
  512. {
  513. if (ans0.All(item => answers.Contains(item)))
  514. {
  515. //部分正确
  516. weight= InteractWeight.TP;
  517. reultType = InteractReultType.TP;
  518. // 2 * 0.3 * 10= 6
  519. interactScore= studentScore==0 ? 1/(InteractWeight.TT-InteractWeight.T1) * (InteractWeight.TP-InteractWeight.T1) * questionScore : studentScore;
  520. }
  521. else
  522. {
  523. //作答错误
  524. weight= InteractWeight.T1;
  525. reultType = InteractReultType.T1;
  526. interactScore= studentScore;
  527. }
  528. }
  529. //标准答案比作答结果少
  530. else
  531. {
  532. //作答错误
  533. weight= InteractWeight.T1;
  534. reultType = InteractReultType.T1;
  535. interactScore= studentScore;
  536. }
  537. }
  538. else
  539. {
  540. //填空题
  541. if ("complete".Equals(type) && answers!.Count==ans0.Count)
  542. {
  543. bool hasT = false;
  544. bool hasF = false;
  545. for (int i = 0; i < answers!.Count; i++)
  546. {
  547. if (answers[i].Equals(ans0[i]))
  548. {
  549. hasT=true;
  550. }
  551. else
  552. {
  553. hasF=true;
  554. }
  555. }
  556. if (hasT && !hasF)
  557. {
  558. //完全正确
  559. weight= InteractWeight.TT;
  560. reultType = InteractReultType.TT;
  561. interactScore= studentScore==0 ? questionScore : studentScore;
  562. }
  563. else if (hasT && hasF)
  564. {
  565. //部分正确
  566. weight= InteractWeight.TP;
  567. reultType = InteractReultType.TP;
  568. // 2 * 0.3 * 10= 6
  569. interactScore= studentScore==0 ? 1/(InteractWeight.TT-InteractWeight.T1) * (InteractWeight.TP-InteractWeight.T1) * questionScore : studentScore;
  570. }
  571. else if (!hasT && hasF)
  572. {
  573. //没有正确的,但有错误的,代表参与了
  574. weight= InteractWeight.T1;
  575. reultType = InteractReultType.T1;
  576. interactScore= studentScore;
  577. }
  578. else if (!hasT && !hasF)
  579. {
  580. //没有正确的,也没有错误的,代表没有作答
  581. weight= InteractWeight.T0;
  582. reultType = InteractReultType.T0;
  583. interactScore= studentScore;
  584. }
  585. }
  586. else
  587. {
  588. //主观题,完全匹配的
  589. if (answers!.All(item => ans0.Contains(item)))
  590. {
  591. //完全正确
  592. weight= InteractWeight.TT;
  593. reultType = InteractReultType.TT;
  594. interactScore= studentScore==0 ? questionScore : studentScore;
  595. }
  596. else
  597. { // 使用LINQ查询来判断是否有匹配的答案
  598. bool hasMatchingAnswer = answers!.Intersect(ans0).Any();
  599. if (hasMatchingAnswer)
  600. {
  601. //主观题回答正确即为完全正确
  602. weight= InteractWeight.TT;
  603. reultType = InteractReultType.TT;
  604. interactScore= studentScore==0 ? questionScore : studentScore;
  605. }
  606. else
  607. {
  608. //优先根据得分与标准分的占比算出得分率,如果没有得分率,如果是直接从互动,不知道是评测的 需要先去评测找作答得分。,则采用Levenshtein距离来评估两个字符串的相似度
  609. //没有匹配上答案,则采用Levenshtein距离来评估两个字符串的相似度
  610. if (questionScore>0)
  611. {
  612. if (studentScore>0)
  613. {
  614. weight = studentScore * 1.0 / questionScore* (InteractWeight.TT-InteractWeight.T1);
  615. if (weight==InteractWeight.T1)
  616. {
  617. reultType = InteractReultType.T1;
  618. interactScore=studentScore;
  619. }
  620. else if (weight>InteractWeight.TT)
  621. {
  622. reultType = InteractReultType.TT;
  623. interactScore=studentScore==0 ? questionScore : studentScore;
  624. }
  625. else
  626. {
  627. reultType = InteractReultType.TP;
  628. // 2 * 0.3 * 10= 6
  629. interactScore= studentScore==0 ? 1/(InteractWeight.TT-InteractWeight.T1) * (InteractWeight.TP-InteractWeight.T1) * questionScore : studentScore;
  630. }
  631. }
  632. else
  633. {
  634. weight=InteractWeight.T1+(CalculateSimilarity(answers![0], ans0[0]) *(InteractWeight.TT-InteractWeight.T1));
  635. if (weight==InteractWeight.T1)
  636. {
  637. reultType = InteractReultType.T1;
  638. interactScore=studentScore;
  639. }
  640. else if (weight>InteractWeight.TT)
  641. {
  642. reultType = InteractReultType.TT;
  643. interactScore=studentScore==0 ? questionScore : studentScore;
  644. }
  645. else
  646. {
  647. reultType = InteractReultType.TP;
  648. // 2 * 0.3 * 10= 6
  649. interactScore= studentScore==0 ? 1/(InteractWeight.TT-InteractWeight.T1) * (InteractWeight.TP-InteractWeight.T1) * questionScore : studentScore;
  650. }
  651. }
  652. }
  653. else
  654. {
  655. weight=InteractWeight.T1+(CalculateSimilarity(answers![0], ans0[0]) *(InteractWeight.TT-InteractWeight.T1));
  656. if (weight==InteractWeight.T1)
  657. {
  658. reultType = InteractReultType.T1;
  659. interactScore=studentScore;
  660. }
  661. else if (weight>InteractWeight.TT)
  662. {
  663. reultType = InteractReultType.TT;
  664. interactScore=studentScore==0 ? questionScore : studentScore;
  665. }
  666. else
  667. {
  668. reultType = InteractReultType.TP;
  669. // 2 * 0.3 * 10= 6
  670. interactScore= studentScore==0 ? 1/(InteractWeight.TT-InteractWeight.T1) * (InteractWeight.TP-InteractWeight.T1) * questionScore : studentScore;
  671. }
  672. }
  673. }
  674. }
  675. }
  676. }
  677. }
  678. else
  679. {
  680. //没有作答
  681. weight= InteractWeight.T0;
  682. reultType = InteractReultType.T0;
  683. interactScore=studentScore;
  684. }
  685. }
  686. else
  687. {
  688. //没有标准答案的情况
  689. if (ans0.IsNotEmpty())
  690. {
  691. bool hasAns = false;
  692. ans0.ForEach(x => {
  693. if (!string.IsNullOrWhiteSpace(x))
  694. {
  695. hasAns = true;
  696. }
  697. });
  698. if (hasAns)
  699. {
  700. //作答了
  701. weight= InteractWeight.T1;
  702. reultType = InteractReultType.T1;
  703. interactScore=studentScore;
  704. }
  705. else
  706. {
  707. //没有作答
  708. weight= InteractWeight.T0;
  709. reultType = InteractReultType.T0;
  710. interactScore=studentScore;
  711. }
  712. }
  713. else
  714. {
  715. //没有作答
  716. weight= InteractWeight.T0;
  717. reultType = InteractReultType.T0;
  718. interactScore=studentScore;
  719. }
  720. //如果教师手动给了分或AI评分
  721. if (questionScore>0 && studentScore>0)
  722. {
  723. weight = studentScore * 1.0 / questionScore* (InteractWeight.TT-InteractWeight.T1);
  724. if (weight==InteractWeight.T1)
  725. {
  726. reultType = InteractReultType.T1;
  727. interactScore=studentScore;
  728. }
  729. else if (weight>InteractWeight.TT)
  730. {
  731. reultType = InteractReultType.TT;
  732. interactScore=studentScore==0 ? questionScore : studentScore;
  733. }
  734. else
  735. {
  736. reultType = InteractReultType.TP;
  737. interactScore= studentScore==0 ? 1/(InteractWeight.TT-InteractWeight.T1) * (InteractWeight.TP-InteractWeight.T1) * questionScore : studentScore;
  738. }
  739. }
  740. }
  741. return (weight, reultType, interactScore);
  742. }
  743. /// <summary>
  744. /// C# 代码 如何判断两句话是否一个意思,非机器学习的算法。使用Levenshtein距离来评估两个字符串的相似度,但是不能判断它们是否表达了同一个意思,后续借助AI实现
  745. /// </summary>
  746. /// <param name="s1"></param>
  747. /// <param name="s2"></param>
  748. /// <returns></returns>
  749. public static double CalculateSimilarity(string s1, string s2)
  750. {
  751. int n = s1.Length;
  752. int m = s2.Length;
  753. int[,] d = new int[n + 1, m + 1];
  754. for (int i = 0; i <= n; i++)
  755. {
  756. d[i, 0] = i;
  757. }
  758. for (int j = 0; j <= m; j++)
  759. {
  760. d[0, j] = j;
  761. }
  762. for (int i = 1; i <= n; i++)
  763. {
  764. for (int j = 1; j <= m; j++)
  765. {
  766. int cost = (s1[i - 1] == s2[j - 1]) ? 0 : 1;
  767. d[i, j] = Math.Min(Math.Min(d[i - 1, j] + 1, d[i, j - 1] + 1), d[i - 1, j - 1] + cost);
  768. }
  769. }
  770. return (1.0 - ((double)d[n, m] / Math.Max(s1.Length, s2.Length)));
  771. }
  772. public static async Task<List<ExamData>> GetExamInfo(LessonRecord item, TimeLineData? timeLineData, AzureStorageFactory _azureStorage/*,ILogger<LessonETLService> _logger*/,string owner )
  773. {
  774. //读取ExamData
  775. List<ExamData> examDatas = new List<ExamData>();
  776. try
  777. {
  778. var examPages = timeLineData?.events.Where(x => !string.IsNullOrWhiteSpace(x.Pgid) && !string.IsNullOrWhiteSpace(x.ExamId));
  779. if (examPages!=null && examPages.Count()>0)
  780. {
  781. var examsFiles = await _azureStorage.GetBlobContainerClient(owner).List($"records/{item.id}/Exam");
  782. var paperFiles = await _azureStorage.GetBlobContainerClient(owner).List($"records/{item.id}/ExamPaper");
  783. foreach (var examsFile in examsFiles)
  784. {
  785. if (examsFile.EndsWith("Exam.json"))
  786. {
  787. ExamData? examData = null;
  788. try
  789. {
  790. BlobDownloadResult examDataDownload = await _azureStorage.GetBlobContainerClient(owner).GetBlobClient(examsFile).DownloadContentAsync();
  791. var str = examDataDownload.Content.ToString().Replace("\r\n", "").Replace("\ufeff", "").Replace("\"publish\": \"0\"", "\"publish\": 0").Replace("\"publish\": \"1\"", "\"publish\": 1");
  792. examData= str.ToObject<ExamData>();
  793. // examData = examDataDownload.Content.ToObjectFromJson<ExamData>();
  794. }
  795. catch (Exception ex)
  796. {
  797. if (!ex.Message.Contains("The specified blob does not exist"))
  798. {
  799. // _logger.LogError(ex, $"文件不存在:{examsFile}");
  800. }
  801. }
  802. if (examData!=null && examData.exam.papers.IsNotEmpty())
  803. {
  804. string paperId = examData.exam.papers.First().id;
  805. if (_azureStorage.GetBlobContainerClient(owner).GetBlobClient($"/records/{item.id}/ExamPaper/{paperId}/index.json").Exists())
  806. {
  807. LessonPaper lessonPaper = null;
  808. try
  809. {
  810. BlobDownloadResult paperblobDownload = await _azureStorage.GetBlobContainerClient(owner).GetBlobClient($"/records/{item.id}/ExamPaper/{paperId}/index.json").DownloadContentAsync();
  811. lessonPaper = paperblobDownload.Content.ToObjectFromJson<LessonPaper>();
  812. examData.paper = lessonPaper;
  813. }
  814. catch (Exception ex)
  815. {
  816. if (!ex.Message.Contains("The specified blob does not exist"))
  817. {
  818. // _logger.LogError(ex, $"文件不存在:/records/{item.id}/ExamPaper/{paperId}/index.json");
  819. }
  820. }
  821. }
  822. examDatas.Add(examData);
  823. }
  824. }
  825. }
  826. }
  827. }
  828. catch (Exception ex)
  829. {
  830. // _logger.LogError(ex, ex.Message);
  831. }
  832. return examDatas;
  833. }
  834. /// <summary>
  835. /// 获取课中评测数据
  836. /// </summary>
  837. /// <param name="lessonBase"></param>
  838. /// <param name="timeLineData"></param>
  839. /// <param name="examDatas"></param>
  840. /// <param name="studentLessonDatas"></param>
  841. /// <param name="objectiveTypes"></param>
  842. /// <returns></returns>
  843. public static List<StudentLessonData> GetExamData(LessonBase lessonBase, TimeLineData timeLineData, List<ExamData> examDatas, List<StudentLessonData> studentLessonDatas, List<string> objectiveTypes, string lessonId)
  844. {
  845. foreach (var examData in examDatas)
  846. {
  847. //直接取第一个元素的试卷,因为在HiTeach中,只会是一个试卷(一个科目),一个班参与。
  848. var allocation = examData?.exam?.papers?.FirstOrDefault()?.point?.Sum();
  849. var answersStd = examData?.exam?.papers?.FirstOrDefault()?.answers;
  850. List<List<string>> answers = new List<List<string>>();
  851. if (answersStd!=null)
  852. {
  853. answersStd.ForEach(x => //去除[""]此种类型的标准答案,转为[]
  854. {
  855. List<string> ans = new List<string>();
  856. if (x.Count!=0)
  857. {
  858. if (x.Count==1)
  859. {
  860. if (string.IsNullOrWhiteSpace(x[0]))
  861. {
  862. answers.Add(ans);
  863. }
  864. else
  865. {
  866. answers.Add(x);
  867. }
  868. }
  869. else
  870. {
  871. answers.Add(x);
  872. }
  873. }
  874. else
  875. {
  876. answers.Add(ans);
  877. }
  878. });
  879. }
  880. examData?.examClassResult?.ForEach(item => {
  881. //学生下标
  882. int index = 0;
  883. if (item.studentAnswersArray.Count()>0
  884. && item.studentAnswersArray.Count() == item.studentIds.Count() //学生作答数量和学生id数量一致
  885. && item.studentScores.Count()==item.studentIds.Count()) //学生分数和学生id数量一致
  886. {
  887. item.studentAnswersArray.ForEach(stu => {
  888. var student = studentLessonDatas.Find(x => x.id!.Equals(item.studentIds[index]));
  889. if (student!=null && student.attend==1)
  890. {
  891. //是否要判断主观题或者客观题, 多套试卷,有主观题的
  892. //,如果没获得结果,
  893. //主观题有回答的:608942756458532864\Clients\18782481024\Ans\27-4341670635487887360-examExchangeAnswerlist
  894. //27 从1开始的学生序号-4341670635487887360评测编号,内容qNo 是从1开始的题号。
  895. if (stu.IsNotEmpty() && answers.Count()==stu.Count && examData.exam.papers[0].type.Count()==answers.Count)
  896. {
  897. StudentExamRecord studentExam = new StudentExamRecord();
  898. var studentScore = item.studentScores[index];
  899. List<ItemRecord> answerRecords = new List<ItemRecord>();
  900. //题目下标
  901. int itemIndex = 0;
  902. stu.ForEach(ans =>
  903. {
  904. bool objective = objectiveTypes.Contains(examData.exam.papers[0].type[itemIndex]);
  905. var questionScore = examData.exam.papers[0].point[itemIndex];
  906. string type = examData.exam.papers[0].type[itemIndex];
  907. var res = GetInteractResultHasAnswer(answers[itemIndex], ans, objective, type, questionScore, studentScore[itemIndex]);
  908. ItemRecord interactRecord = new ItemRecord()
  909. {
  910. itemType="SPQStrt",//类型
  911. resultType=res.reultType,//作答结果类型
  912. resultWeight=res.weight,//得分权重
  913. criterion= questionScore,//标准分
  914. itemScore= studentScore[itemIndex]//得分
  915. };
  916. answerRecords.Add(interactRecord);
  917. itemIndex++;
  918. });
  919. studentExam.score= answerRecords.Where(x => x.itemScore>=0).Select(x => x.itemScore).Sum();//得分
  920. studentExam.scoreRate= allocation.HasValue && allocation.Value>0 ? studentExam.score * 1.0/allocation.Value : 0;//得分率
  921. studentExam.answerRate= answerRecords.Where(x => x.resultWeight>0).Count()*1.0/studentScore.Count();//作答率
  922. studentExam.examId=examData.exam.id;
  923. studentExam.itemRecords=answerRecords;
  924. student.examRecords.Add(studentExam);
  925. }
  926. }
  927. index++;
  928. });
  929. }
  930. });
  931. }
  932. return studentLessonDatas;
  933. }
  934. /// <summary>
  935. /// 协作参与率 态度计算
  936. /// </summary>
  937. /// <param name="lessonBase"></param>
  938. /// <param name="timeLineData"></param>
  939. /// <param name="coworkDatas"></param>
  940. /// <param name="studentLessonDatas"></param>
  941. /// <param name="lessonId"></param>
  942. /// <returns></returns>
  943. public static List<StudentLessonData> GetCoworkData(LessonBase lessonBase, TimeLineData timeLineData, List<CoworkData> coworkDatas, List<StudentLessonData> studentLessonDatas,string lessonId)
  944. {
  945. int p = 0;
  946. foreach (var coworkData in coworkDatas)
  947. {
  948. var keys = coworkData.participateLevelList.Keys;
  949. foreach (var key in keys)
  950. {
  951. var student = studentLessonDatas.Find(x => x.seatID!.Equals(key));
  952. if (student!=null && student.attend==1)
  953. {
  954. var score = coworkData.participateLevelList[key];//协作得分,是否是经过指数计算的
  955. var itemRecord = new ItemRecord { criterion=-1, itemType= coworkData.coworkType, itemScore=score, isGroup= coworkData.coworkType.Equals("Group") ? true : false };
  956. //不能完全依赖
  957. if (score>0)
  958. {
  959. student.coworkScore.Add(score);
  960. itemRecord.resultWeight = InteractWeight.TP;
  961. itemRecord.resultType = InteractReultType.TP;
  962. }
  963. else
  964. {
  965. itemRecord.resultWeight = InteractWeight.T0;
  966. itemRecord.resultType = InteractReultType.T0;
  967. }
  968. student.coworkRecord.itemRecords.Add(itemRecord);
  969. }
  970. if (key.Contains("g", StringComparison.OrdinalIgnoreCase))
  971. {
  972. string groupId = key.Replace("g", "").Replace("G", "");
  973. var score = coworkData.participateLevelList[key];
  974. if (score>0)
  975. {
  976. var groupStu = studentLessonDatas.FindAll(x => x.attend==1 && !string.IsNullOrWhiteSpace(x.groupId) && x.groupId.Equals(groupId));
  977. if (groupStu.IsNotEmpty())
  978. {
  979. foreach (var stu in groupStu)
  980. {
  981. stu.group_coworkScore.Add(score);
  982. stu.coworkRecord.itemRecords[p].itemScore+=score;
  983. stu.coworkRecord.itemRecords[p].resultWeight=InteractWeight.TP;
  984. stu.coworkRecord.itemRecords[p].resultType=InteractReultType.TP;
  985. }
  986. }
  987. }
  988. }
  989. }
  990. var order = studentLessonDatas.Where(x => x.attend==1).OrderByDescending(x => x.coworkRecord.itemRecords[p].itemScore);
  991. var maxItems = studentLessonDatas.FindAll(x => x.attend==1&& x.coworkRecord.itemRecords[p].itemScore==order.First().coworkRecord.itemRecords[p].itemScore);
  992. var max = studentLessonDatas.FindAll(x => x.attend==1&& x.coworkRecord.itemRecords[p].itemScore==order.First().coworkRecord.itemRecords[p].itemScore).First().coworkRecord.itemRecords[p].itemScore;
  993. var min = studentLessonDatas.FindAll(x => x.attend==1&& x.coworkRecord.itemRecords[p].itemScore==order.Last().coworkRecord.itemRecords[p].itemScore).First().coworkRecord.itemRecords[p].itemScore;
  994. var sum = studentLessonDatas.Where(x => x.attend==1).Sum(x => x.coworkRecord.itemRecords[p].itemScore);
  995. foreach (var student in studentLessonDatas)
  996. {
  997. if (student.attend==1 && student.coworkRecord.itemRecords.Count>=p+1 && student.coworkRecord.itemRecords[p].itemScore>0)
  998. {
  999. student.coworkRecord.itemRecords[p].resultType=InteractReultType.TP;
  1000. var data = MinMaxNormalization(min, max, student.coworkRecord.itemRecords[p].itemScore);
  1001. student.coworkRecord.itemRecords[p].resultWeight=InteractWeight.T1+ data * 1.0 / 100 * (InteractWeight.TT-InteractWeight.T1);
  1002. if (maxItems.Select(x => x.seatID).Contains(student.seatID))
  1003. {
  1004. student.coworkRecord.itemRecords[p].resultType= InteractReultType.TT;
  1005. student.coworkRecord.itemRecords[p].resultWeight= InteractWeight.TT;
  1006. }
  1007. }
  1008. }
  1009. p++;
  1010. }
  1011. return studentLessonDatas;
  1012. }
  1013. /// <summary>
  1014. /// 处理学生回推数据,并将回推纳入学习态度计算。
  1015. /// </summary>
  1016. /// <param name="lessonBase"></param>
  1017. /// <param name="timeLineData"></param>
  1018. /// <param name="taskDatas"></param>
  1019. /// <param name="studentLessonDatas"></param>
  1020. /// <returns></returns>
  1021. public static List<StudentLessonData> GetTaskData(LessonBase lessonBase, TimeLineData timeLineData, List<TaskData> taskDatas, List<StudentLessonData> studentLessonDatas, string lessonId)
  1022. {
  1023. //协作也算任务的一种,'WrkSpaceLoad' 作品收集, "isGroupItem": false,
  1024. int indexTask = 0;
  1025. foreach (var taskData in taskDatas)
  1026. {
  1027. //作品收集是全部人员都要参加
  1028. foreach (var student in studentLessonDatas)
  1029. {
  1030. if (student.attend==1)
  1031. {
  1032. var work = taskData.clientWorks.Find(x => $"{x.seatID}".Equals(student.seatID));
  1033. if (work!= null)
  1034. {
  1035. if (work.blobFiles.Count>0)
  1036. {
  1037. student.uploadCount.Add(work.blobFiles.Count);
  1038. }
  1039. 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 });
  1040. }
  1041. else
  1042. {
  1043. student.taskRecord.itemRecords.Add(new ItemRecord { itemType="WrkSpaceLoad", itemScore=0, resultWeight=InteractWeight.T0, resultType=InteractReultType.T0, isGroup= false });
  1044. }
  1045. }
  1046. }
  1047. ////////
  1048. ///需要处理小组的情况,当前人员没有提交作品,但是有可能是小组其他人员提交了,需要判断一下。
  1049. ///
  1050. var students = studentLessonDatas.FindAll(x => x.attend==1 && x.taskRecord.itemRecords[indexTask].isGroup==true);
  1051. foreach (var student in students)
  1052. {
  1053. var groupStudents = studentLessonDatas.FindAll(x => x.id!=student.id && x.attend==1 && !string.IsNullOrWhiteSpace(x.groupId) && x.groupId.Equals(student.groupId));
  1054. foreach (var groupstudent in groupStudents)
  1055. {
  1056. groupstudent.taskRecord.itemRecords[indexTask].isGroup=true;
  1057. groupstudent.taskRecord.itemRecords[indexTask].optCount=student.taskRecord.itemRecords[indexTask].optCount;
  1058. groupstudent.taskRecord.itemRecords[indexTask].itemScore=student.taskRecord.itemRecords[indexTask].itemScore;
  1059. groupstudent.taskRecord.itemRecords[indexTask].resultWeight=student.taskRecord.itemRecords[indexTask].resultWeight;
  1060. groupstudent.taskRecord.itemRecords[indexTask].resultType=student.taskRecord.itemRecords[indexTask].resultType;
  1061. }
  1062. }
  1063. var groupDatas = taskData.clientWorks.FindAll(x => x.seatID==0 && x.isGroupItem);
  1064. foreach (var groupData in groupDatas)
  1065. {
  1066. var groupStudents = studentLessonDatas.FindAll(x => x.attend==1 && !string.IsNullOrWhiteSpace(x.groupId) && x.groupId.Equals(groupData.groupID));
  1067. foreach (var student in groupStudents)
  1068. {
  1069. student.taskRecord.itemRecords[indexTask].isGroup=true;
  1070. student.taskRecord.itemRecords[indexTask].optCount=groupData.blobFiles.Count;
  1071. student.taskRecord.itemRecords[indexTask].itemScore= 10* groupData.blobFiles.Count;
  1072. if (groupData.blobFiles.Count>0)
  1073. {
  1074. student.taskRecord.itemRecords[indexTask].resultWeight=InteractWeight.TT;
  1075. student.taskRecord.itemRecords[indexTask].resultType=InteractReultType.TT;
  1076. }
  1077. else
  1078. {
  1079. student.taskRecord.itemRecords[indexTask].resultWeight=InteractWeight.T0;
  1080. student.taskRecord.itemRecords[indexTask].resultType=InteractReultType.T0;
  1081. }
  1082. }
  1083. }
  1084. indexTask++;
  1085. }
  1086. return studentLessonDatas;
  1087. }
  1088. /// <summary>
  1089. ///评分参与率 态度计算
  1090. ///读取互评信息
  1091. ///评分相关 在SmartRating.json 处理 GrandRating 星光大评分, 投票Voting 和 PeerAssessment(All每人多件评分,Two随机分配互评, Self自评)
  1092. ///Event 过滤类型 'RatingStart'
  1093. ///smartRateSummary.mutualSummary.mutualType 互评【All(每人多件评分) Two(随机分配互评) Self(自评)】 smartRateSummary.meteor_VoteSummary 投票
  1094. ///读取SmartRating.json
  1095. /// </summary>
  1096. /// <param name="lessonBase"></param>
  1097. /// <param name="timeLineData"></param>
  1098. /// <param name="smartRatingDatas"></param>
  1099. /// <param name="studentLessonDatas"></param>
  1100. /// <returns></returns>
  1101. public static List<StudentLessonData> GetSmartRatingData(LessonBase lessonBase, TimeLineData timeLineData, List<SmartRatingData> smartRatingDatas, List<StudentLessonData> studentLessonDatas,string lessonId)
  1102. {
  1103. int index = 0;
  1104. foreach (var smartRatingData in smartRatingDatas)
  1105. {
  1106. string type = "";
  1107. //投票类型的
  1108. var keys_vote = smartRatingData.smartRateSummary?.meteor_VoteSummary?.Keys?.ToList();
  1109. if (keys_vote.IsNotEmpty())
  1110. {
  1111. type="Voting";
  1112. bool addData = false;
  1113. foreach (var key in keys_vote!)
  1114. {
  1115. try
  1116. {
  1117. //问题数据F:\lesson-local\632424798693232640-local.json pclxxx
  1118. if (smartRatingData.smartRateSummary!.voteDetailResult.TryGetValue(key, out var value))
  1119. {
  1120. var voteDetailResults = smartRatingData.smartRateSummary!.voteDetailResult[key];
  1121. foreach (var student in studentLessonDatas)
  1122. {
  1123. if (student.attend==1)
  1124. {
  1125. //投票是全员参与
  1126. var datasS = voteDetailResults.FindAll(x => x.id.Equals(student.seatID));
  1127. if (datasS.IsNotEmpty())
  1128. {
  1129. //T1,只有评论别人,没被别人评论 或者是评论了别人,但是没有被别人评论,
  1130. student.rateingRecord.itemRecords.Add(new ItemRecord { itemType=type, resultType=InteractReultType.T1, resultWeight = InteractWeight.T1 });
  1131. addData=true;
  1132. }
  1133. else
  1134. { //T0 是没有评论别人,也没被别人评论,
  1135. student.rateingRecord.itemRecords.Add(new ItemRecord { itemType=type, resultType=InteractReultType.T0, resultWeight = InteractWeight.T0 });
  1136. addData=true;
  1137. }
  1138. //T0 是没有评论别人,也没被别人评论,
  1139. //T1,只有评论别人,没被别人评论 或者是评论了别人,但是没有被别人评论,
  1140. //TP 有被别人评论,且评论了别人,
  1141. //TT是评论了别人,且被别人评论次数最高,或者分值最高。
  1142. }
  1143. }
  1144. }
  1145. }
  1146. catch (Exception ex)
  1147. {
  1148. throw new Exception($"{lessonId}\n{ex.Message}\n{ex.StackTrace}");
  1149. }
  1150. var meteor_VoteSummary = smartRatingData.smartRateSummary!.meteor_VoteSummary[key];
  1151. var order = meteor_VoteSummary.OrderByDescending(x => x.result);
  1152. var maxItems = meteor_VoteSummary.FindAll(x => x.result==order.First().result);
  1153. var max = meteor_VoteSummary.FindAll(x => x.result==order.First().result).First().result;
  1154. var min = meteor_VoteSummary.FindAll(x => x.result==order.Last().result).First().result;
  1155. var sum = meteor_VoteSummary.Sum(x => x.result);
  1156. //排名指数计算=( 当前值分数- 298) / (9992 - 298) * (99 - 60) + 60
  1157. //将每个人的积分转化为60-100
  1158. //排名 = (积分 - 最低积分) / (最高积分 - 最低积分) * (最大排名 - 最小排名) + 最小排名
  1159. foreach (var datasD in meteor_VoteSummary)
  1160. {
  1161. //有被人评论或投票
  1162. var student = studentLessonDatas.Find(x => x.seatID!.Equals(datasD.id));
  1163. if (student!=null)
  1164. {
  1165. if (index<student.rateingRecord.itemRecords.Count && student.rateingRecord.itemRecords[index].itemType!.Equals(type))
  1166. {
  1167. if (student.rateingRecord.itemRecords[index].resultType!.Equals(InteractReultType.T0))
  1168. {
  1169. //T1,只有评论别人,没被别人评论 或者是评论了别人,但是没有被别人评论,
  1170. student.rateingRecord.itemRecords[index].resultType= InteractReultType.T1;
  1171. student.rateingRecord.itemRecords[index].resultWeight= InteractWeight.T1;
  1172. }
  1173. else if (student.rateingRecord.itemRecords[index].resultType!.Equals(InteractReultType.T1))
  1174. {
  1175. //TP 有被别人评论,且评论了别人,
  1176. student.rateingRecord.itemRecords[index].resultType= InteractReultType.TP;
  1177. var data = MinMaxNormalization(min, max, datasD.result);
  1178. //student.rateingRecord.itemRecords[index].resultWeight= InteractWeight.TP;
  1179. student.rateingRecord.itemRecords[index].resultWeight=InteractWeight.T1+ data * 1.0 / 100 * (InteractWeight.TT-InteractWeight.T1);
  1180. //获得的票数
  1181. student.rateingRecord.itemRecords[index].itemScore=datasD.result;
  1182. //TT是评论了别人,且被别人评论次数最高,或者分值最高。
  1183. if (maxItems.Select(x => x.id).Contains(student.seatID))
  1184. {
  1185. student.rateingRecord.itemRecords[index].resultType= InteractReultType.TT;
  1186. student.rateingRecord.itemRecords[index].resultWeight= InteractWeight.TT;
  1187. }
  1188. }
  1189. }
  1190. }
  1191. }
  1192. if (addData)
  1193. {
  1194. index++;
  1195. }
  1196. }
  1197. }
  1198. //星光大评分,全员评分
  1199. var keys_GrandRating = smartRatingData.smartRateSummary?.scoreDetailResult?.Keys?.ToList();
  1200. if (keys_GrandRating.IsNotEmpty() && smartRatingData.smartRateSummary!=null && smartRatingData.smartRateSummary.meteor_ScoreSummary.IsNotEmpty())
  1201. {
  1202. bool addData = false;
  1203. type="GrandRating";
  1204. foreach (var student in studentLessonDatas)
  1205. {
  1206. if (student.attend==1)
  1207. {
  1208. if (keys_GrandRating!.Contains(student.seatID!))
  1209. {
  1210. //T1,只有评论别人,没被别人评论 或者是评论了别人,但是没有被别人评论,
  1211. student.rateingRecord.itemRecords.Add(new ItemRecord { itemType=type, resultType=InteractReultType.T1, resultWeight = InteractWeight.T1 });
  1212. addData = true;
  1213. }
  1214. else
  1215. {
  1216. //T0 是没有评论别人,也没被别人评论,
  1217. student.rateingRecord.itemRecords.Add(new ItemRecord { itemType=type, resultType=InteractReultType.T0, resultWeight = InteractWeight.T0 });
  1218. addData = true;
  1219. }
  1220. }
  1221. }
  1222. var order = smartRatingData.smartRateSummary.meteor_ScoreSummary.Where(x => x.result>0||!string.IsNullOrWhiteSpace(x.comment)).OrderByDescending(x => x.result);
  1223. if (order.Count()>0)
  1224. {
  1225. var maxItems = smartRatingData.smartRateSummary.meteor_ScoreSummary.FindAll(x => x.result==order.First().result);
  1226. var max = smartRatingData.smartRateSummary.meteor_ScoreSummary.FindAll(x => x.result==order.First().result).First().result;
  1227. var min = smartRatingData.smartRateSummary.meteor_ScoreSummary.FindAll(x => x.result==order.Last().result).First().result;
  1228. var sum = smartRatingData.smartRateSummary.meteor_ScoreSummary.Sum(x => x.result);
  1229. foreach (var meteor_ScoreSummary in smartRatingData.smartRateSummary.meteor_ScoreSummary)
  1230. {
  1231. var student = studentLessonDatas.Find(x => x.seatID!.Equals(meteor_ScoreSummary.id));
  1232. if (student!=null)
  1233. {
  1234. if (index<student.rateingRecord.itemRecords.Count && student.rateingRecord.itemRecords[index].itemType!.Equals(type))
  1235. {
  1236. if (student.rateingRecord.itemRecords[index].resultType!.Equals(InteractReultType.T0))
  1237. {
  1238. //T1,只有评论别人,没被别人评论 或者是评论了别人,但是没有被别人评论,
  1239. student.rateingRecord.itemRecords[index].resultType= InteractReultType.T1;
  1240. student.rateingRecord.itemRecords[index].resultWeight= InteractWeight.T1;
  1241. }
  1242. else if (student.rateingRecord.itemRecords[index].resultType!.Equals(InteractReultType.T1))
  1243. {
  1244. //TP 有被别人评论,且评论了别人,
  1245. student.rateingRecord.itemRecords[index].resultType= InteractReultType.TP;
  1246. var data = MinMaxNormalization(min, max, meteor_ScoreSummary.result);
  1247. //student.rateingRecord.itemRecords[index].resultWeight= InteractWeight.TP;
  1248. student.rateingRecord.itemRecords[index].resultWeight= InteractWeight.T1+ data * 1.0 / 100 * (InteractWeight.TT-InteractWeight.T1);
  1249. //被评论次数
  1250. student.rateingRecord.itemRecords[index].itemScore=meteor_ScoreSummary.result;
  1251. //TT是评论了别人,且被别人评论次数最高,或者分值最高。
  1252. if (maxItems.Select(x => x.id).Contains(student.seatID) &&student.rateingRecord.itemRecords[index].itemScore>0)
  1253. {
  1254. student.rateingRecord.itemRecords[index].resultType= InteractReultType.TT;
  1255. student.rateingRecord.itemRecords[index].resultWeight= InteractWeight.TT;
  1256. }
  1257. }
  1258. }
  1259. }
  1260. }
  1261. }
  1262. if (addData)
  1263. {
  1264. index++;
  1265. }
  1266. }
  1267. // 互评 PeerAssessment(All每人多件评分,Two随机分配互评, Self自评)
  1268. var keys_PeerAssessment = smartRatingData.smartRateSummary?.mutualDetailSummary?.Keys?.ToList();
  1269. if (keys_PeerAssessment.IsNotEmpty() && smartRatingData.smartRateSummary?.mutualSummary!=null
  1270. && smartRatingData.smartRateSummary.mutualSummary.mutualResults.IsNotEmpty()
  1271. && smartRatingData.smartRateSummary.mutualSummary.materialInfos.IsNotEmpty())
  1272. {
  1273. bool addData = false;
  1274. type="PeerAssessment";
  1275. foreach (var student in studentLessonDatas)
  1276. {
  1277. if (student.attend==1)
  1278. {
  1279. if (keys_PeerAssessment!.Contains(student.seatID!))
  1280. {
  1281. //T1,只有评论别人,没被别人评论 或者是评论了别人,但是没有被别人评论,
  1282. student.rateingRecord.itemRecords.Add(new ItemRecord { itemType=type, resultType=InteractReultType.T1, resultWeight = InteractWeight.T1 });
  1283. addData = true;
  1284. }
  1285. else
  1286. {
  1287. //T0 是没有评论别人,也没被别人评论,
  1288. student.rateingRecord.itemRecords.Add(new ItemRecord { itemType=type, resultType=InteractReultType.T0, resultWeight = InteractWeight.T0 });
  1289. addData = true;
  1290. }
  1291. }
  1292. }
  1293. var order = smartRatingData.smartRateSummary.mutualSummary.mutualResults.Where(x => x.result>0).OrderByDescending(x => x.result);
  1294. var maxItems = smartRatingData.smartRateSummary.mutualSummary.mutualResults.FindAll(x => x.result==order.First().result);
  1295. var max = smartRatingData.smartRateSummary.mutualSummary.mutualResults.FindAll(x => x.result==order.First().result).First().result;
  1296. var min = smartRatingData.smartRateSummary.mutualSummary.mutualResults.FindAll(x => x.result==order.Last().result).First().result;
  1297. var sum = smartRatingData.smartRateSummary.mutualSummary.mutualResults.Sum(x => x.result);
  1298. foreach (var mutualResult in smartRatingData.smartRateSummary.mutualSummary.mutualResults)
  1299. {
  1300. var student = studentLessonDatas.Find(x => x.seatID!.Equals(mutualResult.id));
  1301. if (student!=null)
  1302. {
  1303. if (index<student.rateingRecord.itemRecords.Count && student.rateingRecord.itemRecords[index].itemType!.Equals(type))
  1304. {
  1305. if (student.rateingRecord.itemRecords[index].resultType!.Equals(InteractReultType.T0))
  1306. {
  1307. //T1,只有评论别人,没被别人评论 或者是评论了别人,但是没有被别人评论,
  1308. student.rateingRecord.itemRecords[index].resultType= InteractReultType.T1;
  1309. student.rateingRecord.itemRecords[index].resultWeight= InteractWeight.T1;
  1310. }
  1311. else if (student.rateingRecord.itemRecords[index].resultType!.Equals(InteractReultType.T1))
  1312. {
  1313. //TP 有被别人评论,且评论了别人,
  1314. //最高分和最低分,票数最多和票数最少的占比来计算TP的占比
  1315. student.rateingRecord.itemRecords[index].resultType= InteractReultType.TP;
  1316. var data = MinMaxNormalization(min, max, mutualResult.result);
  1317. //student.rateingRecord.itemRecords[index].resultWeight= InteractWeight.TP;
  1318. student.rateingRecord.itemRecords[index].resultWeight= InteractWeight.T1+ data * 1.0 / 100 * (InteractWeight.TT-InteractWeight.T1);
  1319. student.rateingRecord.itemRecords[index].itemScore=mutualResult.result;
  1320. //TT是评论了别人,且被别人评论次数最高,或者分值最高。
  1321. if (maxItems.Select(x => x.id).Contains(student.seatID))
  1322. {
  1323. student.rateingRecord.itemRecords[index].resultType= InteractReultType.TT;
  1324. student.rateingRecord.itemRecords[index].resultWeight= InteractWeight.TT;
  1325. }
  1326. }
  1327. }
  1328. }
  1329. }
  1330. if (addData)
  1331. {
  1332. index++;
  1333. }
  1334. }
  1335. }
  1336. return studentLessonDatas;
  1337. }
  1338. /// <summary>
  1339. /// 最小-最大归一化(Min-Max Normalization)算法。这种算法通常用于将数据的特征值缩放到一个指定的范围内,通常是0到1之间,或者任何其他指定的范围。
  1340. /// </summary>
  1341. /// <returns></returns>
  1342. public static double MinMaxNormalization(double min, double max, double x, double minRank = 1, double maxRank = 100)
  1343. {
  1344. //排名指数计算=( 当前值分数- 298) / (9992 - 298) * (99 - 60) + 60
  1345. //将每个人的积分转化为60-100
  1346. //排名 = (积分 - 最低积分) / (最高积分 - 最低积分) * (最大排名 - 最小排名) + 最小排名
  1347. return x==0 ? 0 : max-min!=0 ? (x - min)*1.0 / (max - min) * (maxRank - minRank) + minRank : (x)*1.0 / (max) * (maxRank - minRank) + minRank;
  1348. }
  1349. public static List<StudentLessonItem> ProcessStudentDataV2(List<StudentLessonData> studentLessonDatas, LessonDataAnalysisCluster lessonDataAnalysis)
  1350. {
  1351. //历史记录的个人计分集合,通过“2倍标准差规则”移除异常值后得到的集合
  1352. var max_q = lessonDataAnalysis.pscore.Max();
  1353. //历史记录的互动计分集合,通过“2倍标准差规则”移除异常值后得到的集合
  1354. var max_t = lessonDataAnalysis.tscore.Max();
  1355. //历史记录的小组计分集合,通过“2倍标准差规则”移除异常值后得到的集合
  1356. var max_h = lessonDataAnalysis.gscore.Max();
  1357. var j = InteractWeight.T1;
  1358. double t = InteractWeight.TT;
  1359. List<StudentLessonItem> lessonItems = new List<StudentLessonItem>();
  1360. foreach (var studentLessonData in studentLessonDatas)
  1361. {
  1362. StudentLessonItem lessonItem = new StudentLessonItem() { studentId= studentLessonData.id! };
  1363. double u = 0.0;
  1364. if (studentLessonData.attend==1)
  1365. {
  1366. u=100.0;
  1367. }
  1368. //c个人计分指数,d互动计分指数,e小组计分指数
  1369. double c = 0, d = 0, e = 0;
  1370. {
  1371. //互动相关的计分
  1372. //课例互动次数
  1373. double n = studentLessonData.interactRecord.interactRecords.Count()*1.0;
  1374. if (n>0)
  1375. {
  1376. //是IES大陆正式站历史课例数据,自2024-03-01至2024-10-08日,互动指数或学法指数黄灯或绿灯,不包含醍摩豆学校及测试学校,课例时长超过5分钟的有效课例(10,680笔数据) 的IRS互动+抢权+挑人的次数集合,
  1377. //通过“2倍标准差规则” 移除异常值后得到的集合,再通过K-Means聚类算法得到高低位阶互动频次两个集合,并根据当前课例互动次数位阶的集合的质心值,该值定为m值
  1378. var m = n<=lessonDataAnalysis.clustersInteract.First().Value.Max() ? lessonDataAnalysis.clustersInteract.First().Value.Max()*1.0 : lessonDataAnalysis.clustersInteract.Last().Value.Max() *1.0;
  1379. //学生作答次数
  1380. var w = studentLessonData.interactRecord.interactRecords.Where(x => x.resultWeight>=InteractWeight.T1).Count()*1.0;
  1381. //作答正确数(包括部分正确)
  1382. var r = studentLessonData.interactRecord.interactRecords.Where(x => x.resultWeight>InteractWeight.T1).Count()*1.0;
  1383. //有参与的权重集合60≤k(x)≤100
  1384. var kw = studentLessonData.interactRecord.interactRecords.Where(x => x.resultWeight>=InteractWeight.T1).Sum(x => x.resultWeight*1.0);
  1385. //有得分的权重集合60<e(x)≤100
  1386. var er = studentLessonData.interactRecord.interactRecords.Where(x => x.resultWeight>InteractWeight.T1).Sum(x => x.resultWeight*1.0);
  1387. //本节课的所有互动计分
  1388. var i = studentLessonData.interactRecord.interactRecords.Sum(x => x.itemScore*1.0);
  1389. //本节课教师手动给学生的个人计分
  1390. var s = studentLessonData.pscore;
  1391. //个人计分指数
  1392. c = GetPersent(lessonDataAnalysis.pscore, s).persent/100;// s*1.0/max_q;
  1393. //互动计分指数
  1394. d = GetPersent(lessonDataAnalysis.tscore, i).persent/100; //i*1.0/max_t;
  1395. //互动成效指数
  1396. var a = (d+w*kw/(j*m)+r*er/(j*m))*1.0/n;
  1397. //互动参与指数
  1398. var b = ((w*w)/m+(r*r)/m)*1.0/n;
  1399. //c+a= 个人计分指数+ 个人互动成效指数
  1400. //学习成效
  1401. var f1 = Math.Round(190*1.0/(1+Math.Exp(-(c+a)))-95, 4);
  1402. lessonItem.hd_cx=f1;
  1403. var f2 = Math.Round(200*1.0/(1+Math.Exp(-(b+u/100)))-100, 4);
  1404. lessonItem.hd_cy=f2;
  1405. lessonItem.hd_cyc=w;
  1406. lessonItem.hd_fqc=n;
  1407. lessonItem.hd_zqc=r;
  1408. lessonItem.gr_jf=s;
  1409. }
  1410. //studentLessonData.achieve=f1;
  1411. //studentLessonData.attitude=f2;
  1412. // _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)}");
  1413. }
  1414. {
  1415. //评测相关指数
  1416. double n = studentLessonData.examRecords.Count()*1.0;
  1417. if (n>0)
  1418. {
  1419. //题目数量
  1420. double nq = studentLessonData.examRecords.Sum(x => x.qcount)*1.0;
  1421. // double max_e = lessonDataAnalysis.exam.Max();
  1422. //得分率
  1423. double sum_s = studentLessonData.examRecords.Sum(x => x.scoreRate);
  1424. //作答率
  1425. double sum_a = studentLessonData.examRecords.Sum(x => x.answerRate);
  1426. double f8 = Math.Round(sum_s/n*100, 4);
  1427. double f9 = Math.Round(sum_a/n*100, 4);
  1428. lessonItem.pc_df=f8;
  1429. lessonItem.pc_zd=f9;
  1430. }
  1431. // _logger.LogInformation($"{studentLessonData.id}=>评测指数:{f8}\t得分率:{Math.Round(sum_s/n,4)}\t参与指数:{f9}\t作答率:{Math.Round(sum_a/n,4)}");
  1432. }
  1433. {
  1434. //小组相关指数
  1435. }
  1436. {
  1437. //任务相关指数
  1438. double n = studentLessonData.taskRecord.itemRecords.Count()*1.0;
  1439. if (n>0)
  1440. {
  1441. double max_m = lessonDataAnalysis.task.Max();
  1442. double w = studentLessonData.taskRecord.itemRecords.Where(x => x.resultWeight>0).Count()*1.0;
  1443. double y = (10 *w/n+(j/t) *w)/max_m;
  1444. double l = max_m*(w*w/n+(j/t) * w)/n;
  1445. double f4 = Math.Round(190*1.0/(1+Math.Exp(-(y)))-95, 4);
  1446. double f5 = Math.Round(200*1.0/(1+Math.Exp(-(l)))-100, 4);
  1447. lessonItem.rw_fqc =n;
  1448. lessonItem.rw_cyc =w;
  1449. lessonItem.rw_cx =f4;
  1450. lessonItem.rw_cy =f5;
  1451. }
  1452. // _logger.LogInformation($"{studentLessonData.id}=>任务指数:{f4}\t参与指数:{f5}\t任务次数:{n}\t参与次数:{w}\t");
  1453. }
  1454. {
  1455. //评价相关指数
  1456. double n = studentLessonData.rateingRecord.itemRecords.Count()*1.0;
  1457. if (n>0)
  1458. {
  1459. var v = studentLessonData.rateingRecord.itemRecords.Where(x => x.itemType.Equals("Voting"));
  1460. double vc = v.Count()*1.0;
  1461. var g = studentLessonData.rateingRecord.itemRecords.Where(x => x.itemType.Equals("GrandRating"));
  1462. double gc = g.Count()*1.0;
  1463. var p = studentLessonData.rateingRecord.itemRecords.Where(x => x.itemType.Equals("PeerAssessment"));
  1464. double pc = p.Count()*1.0;
  1465. var vg = v.Sum(x => x.itemScore);
  1466. var vo = v.Sum(x => x.optCount);
  1467. double vs = vc/n* (vg+ vo);
  1468. var gg = g.Sum(x => x.itemScore);
  1469. var go = g.Sum(x => x.optCount);
  1470. double gs = gc/n* (gg+ go);
  1471. var pg = p.Sum(x => x.itemScore);
  1472. var po = p.Sum(x => x.optCount);
  1473. double ps = pc/n* (pg+ po);
  1474. double h = vs+ps+gs;
  1475. double f3 = Math.Round(190*1.0/(1+Math.Exp(-(h)))-95, 4);
  1476. studentLessonData.appraise=f3;
  1477. // _logger.LogInformation($"{studentLessonData.id}=>评价能力:{f3}\t评价次数:{n}\t投票次数:{vc}-{vg}-{vo}\t星光次数:{gc}-{gg}-{go}\t互评次数:{pc}-{pg}-{po}");
  1478. lessonItem.pj_nl =f3;
  1479. lessonItem.pj_cs =n;
  1480. lessonItem.pj_vc =vc;
  1481. lessonItem.pj_vg =vg;
  1482. lessonItem.pj_vo =vo;
  1483. lessonItem.pj_gc =gc;
  1484. lessonItem.pj_gg =gg;
  1485. lessonItem.pj_go =go;
  1486. lessonItem.pj_pc =pc;
  1487. lessonItem.pj_pg =pg;
  1488. lessonItem.pj_po =po;
  1489. }
  1490. }
  1491. {
  1492. //协作相关指数
  1493. var n = studentLessonData.coworkRecord.itemRecords.Count()*1.0;
  1494. if (n>0)
  1495. {
  1496. //总的协作成果数
  1497. var w = studentLessonData.coworkRecord.itemRecords.Where(x => x.resultWeight>0);
  1498. double ss = w.Sum(x => x.itemScore)*1.0;
  1499. double sw = w.Sum(x => x.resultWeight)*1.0;
  1500. double wc = w.Count()*1.0;
  1501. double x = 0.0;
  1502. if (wc>0)
  1503. {
  1504. x=sw/(j *wc);
  1505. }
  1506. double max_xzcg = 40;
  1507. double k = (wc*wc/n+x)/n+ wc*(ss/max_xzcg)* (wc/n);
  1508. double f6 = Math.Round(190*1.0/(1+Math.Exp(-(k)))-95, 4);
  1509. double f7 = Math.Round(200*1.0/(1+Math.Exp(-(k)))-100, 4);
  1510. lessonItem.xz_fqc =n;
  1511. lessonItem.xz_cyc =wc;
  1512. lessonItem.xz_cgf =ss;
  1513. lessonItem.xz_cx =f6;
  1514. lessonItem.xz_cy =f7;
  1515. }
  1516. //_logger.LogInformation($"{studentLessonData.id}=>协作指数:{f6}\t参与指数:{f7}\t协作次数:{n}\t参与次数:{wc}\t协作成果分数:{ss}\t{k}");
  1517. }
  1518. double xx_cx = 0, xx_cy = 0;
  1519. int avg_cx = 0, avg_cy = 0;
  1520. if (lessonItem.xz_cx>0)
  1521. {
  1522. avg_cx+=1;
  1523. }
  1524. if (lessonItem.pj_nl>0)
  1525. {
  1526. avg_cx+=1;
  1527. }
  1528. if (lessonItem.rw_cx>0)
  1529. {
  1530. avg_cx+=1;
  1531. }
  1532. if (lessonItem.pc_df>0)
  1533. {
  1534. avg_cx+=1;
  1535. }
  1536. if (lessonItem.hd_cx>0)
  1537. {
  1538. avg_cx+=1;
  1539. }
  1540. xx_cx+=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;
  1541. if (lessonItem.xz_cy>0)
  1542. {
  1543. avg_cy+=1;
  1544. }
  1545. if (lessonItem.pj_nl>0)
  1546. {
  1547. avg_cy+=1;
  1548. }
  1549. if (lessonItem.rw_cy>0)
  1550. {
  1551. avg_cy+=1;
  1552. }
  1553. if (lessonItem.pc_zd>0)
  1554. {
  1555. avg_cy+=1;
  1556. }
  1557. if (lessonItem.hd_cy>0)
  1558. {
  1559. avg_cy+=1;
  1560. }
  1561. xx_cy+=lessonItem.hd_cy * 1.0/avg_cy+ lessonItem.pc_zd* 1.0/avg_cy+ lessonItem.rw_cy* 1.0/avg_cy+ lessonItem.pj_nl* 1.0/avg_cy+ lessonItem.xz_cy* 1.0/avg_cy;
  1562. lessonItem.xx_cx=xx_cx;
  1563. lessonItem.xx_cy=xx_cy;
  1564. lessonItems.Add(lessonItem);
  1565. }
  1566. return lessonItems;
  1567. }
  1568. /// <summary>
  1569. /// 计算学生的学习成效,学习态度,合作能力,协作能力,评价能力
  1570. /// </summary>
  1571. /// <param name="studentLessonDatas"></param>
  1572. /// <param name="lessonDataAnalysis"></param>
  1573. /// <returns></returns>
  1574. public static List<StudentLessonItem> ProcessStudentDataV1(List<StudentLessonData> studentLessonDatas, LessonDataAnalysisCluster lessonDataAnalysis)
  1575. {
  1576. //历史记录的个人计分集合,通过“2倍标准差规则”移除异常值后得到的集合
  1577. var max_q = lessonDataAnalysis.pscore.Max();
  1578. //历史记录的互动计分集合,通过“2倍标准差规则”移除异常值后得到的集合
  1579. var max_t = lessonDataAnalysis.tscore.Max();
  1580. //历史记录的小组计分集合,通过“2倍标准差规则”移除异常值后得到的集合
  1581. var max_h = lessonDataAnalysis.gscore.Max();
  1582. var j = InteractWeight.T1;
  1583. double t = InteractWeight.TT;
  1584. List<StudentLessonItem> lessonItems = new List<StudentLessonItem>();
  1585. foreach (var studentLessonData in studentLessonDatas)
  1586. {
  1587. StudentLessonItem lessonItem = new StudentLessonItem() { studentId= studentLessonData.id! };
  1588. double u = 0.0;
  1589. if (studentLessonData.attend==1)
  1590. {
  1591. u=100.0;
  1592. }
  1593. //c个人计分指数,d互动计分指数,e小组计分指数
  1594. double c = 0, d = 0, e = 0;
  1595. {
  1596. //互动相关的计分
  1597. //课例互动次数
  1598. double n = studentLessonData.interactRecord.interactRecords.Count()*1.0;
  1599. if (n>0)
  1600. {
  1601. //是IES大陆正式站历史课例数据,自2024-03-01至2024-10-08日,互动指数或学法指数黄灯或绿灯,不包含醍摩豆学校及测试学校,课例时长超过5分钟的有效课例(10,680笔数据) 的IRS互动+抢权+挑人的次数集合,
  1602. //通过“2倍标准差规则” 移除异常值后得到的集合,再通过K-Means聚类算法得到高低位阶互动频次两个集合,并根据当前课例互动次数位阶的集合的质心值,该值定为m值
  1603. var m = n<=lessonDataAnalysis.clustersInteract.First().Value.Max() ? lessonDataAnalysis.clustersInteract.First().Key*1.0 : lessonDataAnalysis.clustersInteract.Last().Key *1.0;
  1604. //学生作答次数
  1605. var w = studentLessonData.interactRecord.interactRecords.Where(x => x.resultWeight>=InteractWeight.T1).Count()*1.0;
  1606. //作答正确数(包括部分正确)
  1607. var r = studentLessonData.interactRecord.interactRecords.Where(x => x.resultWeight>InteractWeight.T1).Count()*1.0;
  1608. //有参与的权重集合60≤k(x)≤100
  1609. var kw = studentLessonData.interactRecord.interactRecords.Where(x => x.resultWeight>=InteractWeight.T1).Sum(x => x.resultWeight*1.0);
  1610. //有得分的权重集合60<e(x)≤100
  1611. var er = studentLessonData.interactRecord.interactRecords.Where(x => x.resultWeight>InteractWeight.T1).Sum(x => x.resultWeight*1.0);
  1612. //本节课的所有互动计分
  1613. var i = studentLessonData.interactRecord.interactRecords.Sum(x => x.itemScore*1.0);
  1614. //本节课教师手动给学生的个人计分
  1615. var s = studentLessonData.pscore;
  1616. //个人计分指数
  1617. c = GetPersent(lessonDataAnalysis.pscore, s).persent/100;// s*1.0/max_q;
  1618. //互动计分指数
  1619. d = GetPersent(lessonDataAnalysis.tscore, i).persent/100; //i*1.0/max_t;
  1620. //互动成效指数
  1621. var a = (d+w*kw/(j*m)+r*er/(j*m))*1.0/n;
  1622. //互动参与指数
  1623. var b = ((w*w)/m+(r*r)/m)*1.0/n;
  1624. //c+a= 个人计分指数+ 个人互动成效指数
  1625. //学习成效
  1626. var f1 = Math.Round(190*1.0/(1+Math.Exp(-(c+a)))-95, 4);
  1627. lessonItem.hd_cx=f1;
  1628. var f2 = Math.Round(200*1.0/(1+Math.Exp(-(b+u/100)))-100, 4);
  1629. lessonItem.hd_cy=f2;
  1630. lessonItem.hd_cyc=w;
  1631. lessonItem.hd_fqc=n;
  1632. lessonItem.hd_zqc=r;
  1633. lessonItem.gr_jf=s;
  1634. }
  1635. //studentLessonData.achieve=f1;
  1636. //studentLessonData.attitude=f2;
  1637. // _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)}");
  1638. }
  1639. {
  1640. //评测相关指数
  1641. double n = studentLessonData.examRecords.Count()*1.0;
  1642. if (n>0)
  1643. {
  1644. //题目数量
  1645. double nq = studentLessonData.examRecords.Sum(x => x.qcount)*1.0;
  1646. // double max_e = lessonDataAnalysis.exam.Max();
  1647. //得分率
  1648. double sum_s = studentLessonData.examRecords.Sum(x => x.scoreRate);
  1649. //作答率
  1650. double sum_a = studentLessonData.examRecords.Sum(x => x.answerRate);
  1651. double f8 = Math.Round(sum_s/n*100, 4);
  1652. double f9 = Math.Round(sum_a/n*100, 4);
  1653. lessonItem.pc_df=f8;
  1654. lessonItem.pc_zd=f9;
  1655. }
  1656. // _logger.LogInformation($"{studentLessonData.id}=>评测指数:{f8}\t得分率:{Math.Round(sum_s/n,4)}\t参与指数:{f9}\t作答率:{Math.Round(sum_a/n,4)}");
  1657. }
  1658. {
  1659. //小组相关指数
  1660. }
  1661. {
  1662. //任务相关指数
  1663. double n = studentLessonData.taskRecord.itemRecords.Count()*1.0;
  1664. if (n>0)
  1665. {
  1666. double max_m = lessonDataAnalysis.task.Max();
  1667. double w = studentLessonData.taskRecord.itemRecords.Where(x => x.resultWeight>0).Count()*1.0;
  1668. double y = (10 *w/n+(j/t) *w)/max_m;
  1669. double l = max_m*(w*w/n+(j/t) * w)/n;
  1670. double f4 = Math.Round(190*1.0/(1+Math.Exp(-(y)))-95, 4);
  1671. double f5 = Math.Round(200*1.0/(1+Math.Exp(-(l)))-100, 4);
  1672. lessonItem.rw_fqc =n;
  1673. lessonItem.rw_cyc =w;
  1674. lessonItem.rw_cx =f4;
  1675. lessonItem.rw_cy =f5;
  1676. }
  1677. // _logger.LogInformation($"{studentLessonData.id}=>任务指数:{f4}\t参与指数:{f5}\t任务次数:{n}\t参与次数:{w}\t");
  1678. }
  1679. {
  1680. //评价相关指数
  1681. double n = studentLessonData.rateingRecord.itemRecords.Count()*1.0;
  1682. if (n>0)
  1683. {
  1684. var v = studentLessonData.rateingRecord.itemRecords.Where(x => x.itemType.Equals("Voting"));
  1685. double vc = v.Count()*1.0;
  1686. var g = studentLessonData.rateingRecord.itemRecords.Where(x => x.itemType.Equals("GrandRating"));
  1687. double gc = g.Count()*1.0;
  1688. var p = studentLessonData.rateingRecord.itemRecords.Where(x => x.itemType.Equals("PeerAssessment"));
  1689. double pc = p.Count()*1.0;
  1690. var vg = v.Sum(x => x.itemScore);
  1691. var vo = v.Sum(x => x.optCount);
  1692. double vs = vc/n* (vg+ vo);
  1693. var gg = g.Sum(x => x.itemScore);
  1694. var go = g.Sum(x => x.optCount);
  1695. double gs = gc/n* (gg+ go);
  1696. var pg = p.Sum(x => x.itemScore);
  1697. var po = p.Sum(x => x.optCount);
  1698. double ps = pc/n* (pg+ po);
  1699. double h = vs+ps+gs;
  1700. double f3 = Math.Round(190*1.0/(1+Math.Exp(-(h)))-95, 4);
  1701. studentLessonData.appraise=f3;
  1702. // _logger.LogInformation($"{studentLessonData.id}=>评价能力:{f3}\t评价次数:{n}\t投票次数:{vc}-{vg}-{vo}\t星光次数:{gc}-{gg}-{go}\t互评次数:{pc}-{pg}-{po}");
  1703. lessonItem.pj_nl =f3;
  1704. lessonItem.pj_cs =n;
  1705. lessonItem.pj_vc =vc;
  1706. lessonItem.pj_vg =vg;
  1707. lessonItem.pj_vo =vo;
  1708. lessonItem.pj_gc =gc;
  1709. lessonItem.pj_gg =gg;
  1710. lessonItem.pj_go =go;
  1711. lessonItem.pj_pc =pc;
  1712. lessonItem.pj_pg =pg;
  1713. lessonItem.pj_po =po;
  1714. }
  1715. }
  1716. {
  1717. //协作相关指数
  1718. var n = studentLessonData.coworkRecord.itemRecords.Count()*1.0;
  1719. if (n>0)
  1720. {
  1721. //总的协作成果数
  1722. var w = studentLessonData.coworkRecord.itemRecords.Where(x => x.resultWeight>0);
  1723. double ss = w.Sum(x => x.itemScore)*1.0;
  1724. double sw = w.Sum(x => x.resultWeight)*1.0;
  1725. double wc = w.Count()*1.0;
  1726. double x = 0.0;
  1727. if (wc>0)
  1728. {
  1729. x=sw/(j *wc);
  1730. }
  1731. double max_xzcg = 40;
  1732. double k = (wc*wc/n+x)/n+ wc*(ss/max_xzcg)* (wc/n);
  1733. double f6 = Math.Round(190*1.0/(1+Math.Exp(-(k)))-95, 4);
  1734. double f7 = Math.Round(200*1.0/(1+Math.Exp(-(k)))-100, 4);
  1735. lessonItem.xz_fqc =n;
  1736. lessonItem.xz_cyc =wc;
  1737. lessonItem.xz_cgf =ss;
  1738. lessonItem.xz_cx =f6;
  1739. lessonItem.xz_cy =f7;
  1740. }
  1741. //_logger.LogInformation($"{studentLessonData.id}=>协作指数:{f6}\t参与指数:{f7}\t协作次数:{n}\t参与次数:{wc}\t协作成果分数:{ss}\t{k}");
  1742. }
  1743. double xx_cx = 0, xx_cy = 0;
  1744. int avg_cx = 0, avg_cy = 0;
  1745. if (lessonItem.xz_cx>0)
  1746. {
  1747. avg_cx+=1;
  1748. }
  1749. if (lessonItem.pj_nl>0)
  1750. {
  1751. avg_cx+=1;
  1752. }
  1753. if (lessonItem.rw_cx>0)
  1754. {
  1755. avg_cx+=1;
  1756. }
  1757. if (lessonItem.pc_df>0)
  1758. {
  1759. avg_cx+=1;
  1760. }
  1761. if (lessonItem.hd_cx>0)
  1762. {
  1763. avg_cx+=1;
  1764. }
  1765. xx_cx+=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;
  1766. if (lessonItem.xz_cy>0)
  1767. {
  1768. avg_cy+=1;
  1769. }
  1770. if (lessonItem.pj_nl>0)
  1771. {
  1772. avg_cy+=1;
  1773. }
  1774. if (lessonItem.rw_cy>0)
  1775. {
  1776. avg_cy+=1;
  1777. }
  1778. if (lessonItem.pc_zd>0)
  1779. {
  1780. avg_cy+=1;
  1781. }
  1782. if (lessonItem.hd_cy>0)
  1783. {
  1784. avg_cy+=1;
  1785. }
  1786. xx_cy+=lessonItem.hd_cy * 1.0/avg_cy+ lessonItem.pc_zd* 1.0/avg_cy+ lessonItem.rw_cy* 1.0/avg_cy+ lessonItem.pj_nl* 1.0/avg_cy+ lessonItem.xz_cy* 1.0/avg_cy;
  1787. lessonItem.xx_cx=xx_cx;
  1788. lessonItem.xx_cy=xx_cy;
  1789. lessonItems.Add(lessonItem);
  1790. }
  1791. return lessonItems;
  1792. }
  1793. /// <summary>
  1794. /// 使用标准差定义异常值。如果一个数字与平均值的偏差超过某个标准差倍数(例如2倍或3倍),则可以认为它是异常的。
  1795. /// </summary>
  1796. /// <param name="array"></param>
  1797. /// <returns></returns>
  1798. public static List<double> CleanDataBySDThreshold(IEnumerable<double> array, double thresholdMultiplier = 2)
  1799. {
  1800. if (array.Count() == 0) return new List<double>();
  1801. double average = Math.Round(array.Sum()*1.0/array.Count(), 4);
  1802. double variance = array.Select(x => Math.Round(Math.Pow(x - average, 2), 4)).Sum()*1.0/array.Count();
  1803. double standardDeviation = Math.Sqrt(Math.Round(variance, 4));
  1804. double threshold = Math.Round(thresholdMultiplier * standardDeviation);
  1805. List<double> datas = new List<double>();
  1806. foreach (double value in array)
  1807. {
  1808. double deviation = Math.Round(Math.Abs(value - average), 4);
  1809. if (deviation <= threshold)
  1810. {
  1811. datas.Add(value);
  1812. }
  1813. }
  1814. return datas;
  1815. }
  1816. /// <summary>
  1817. /// 导出Excel
  1818. /// </summary>
  1819. /// <param name="items"></param>
  1820. /// <param name="filePath"></param>
  1821. /// <returns></returns>
  1822. public static async Task ExportToExcel(List<StudentLessonItem> items, string filePath, XmlDocument xmlDocument)
  1823. {
  1824. ExcelPackage.LicenseContext = OfficeOpenXml.LicenseContext.NonCommercial;
  1825. using (ExcelPackage package = new ExcelPackage())
  1826. {
  1827. ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("学生课中数据");
  1828. // 获取类的属性
  1829. PropertyInfo[] properties = typeof(StudentLessonItem).GetProperties();
  1830. // 添加表头
  1831. int currentRow = 1;
  1832. for (int i = 0; i < properties.Length; i++)
  1833. {
  1834. string summary = Regex.Replace(GetPropertySummary(properties[i], xmlDocument), @"\s+", "");
  1835. worksheet.Cells[currentRow, i + 1].Value = summary;
  1836. }
  1837. // 填充数据
  1838. currentRow = 2;
  1839. foreach (var item in items)
  1840. {
  1841. for (int i = 0; i < properties.Length; i++)
  1842. {
  1843. worksheet.Cells[currentRow, i + 1].Value = properties[i].GetValue(item);
  1844. }
  1845. currentRow++;
  1846. }
  1847. // 设置表格样式
  1848. worksheet.Cells[worksheet.Dimension.Address].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Left;
  1849. worksheet.Cells[worksheet.Dimension.Address].Style.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Top;
  1850. // 保存到文件
  1851. FileInfo fileInfo = new System.IO.FileInfo(filePath);
  1852. await package.SaveAsAsync(fileInfo);
  1853. }
  1854. }
  1855. private static string GetPropertySummary(PropertyInfo property,XmlDocument xmlDocument)
  1856. {
  1857. XmlNodeList? xmlNodeList = xmlDocument.DocumentElement?.SelectNodes("//member[@name='P:" + property.DeclaringType?.FullName + "." + property.Name + "']");
  1858. if (xmlNodeList!= null && xmlNodeList.Count > 0)
  1859. {
  1860. XmlNode? xmlNode = xmlNodeList[0];
  1861. if (xmlNode != null && xmlNode.FirstChild != null)
  1862. {
  1863. return xmlNode.FirstChild.InnerText;
  1864. }
  1865. }
  1866. return property.Name;
  1867. }
  1868. /// <summary>
  1869. /// 当前数超越集合的百分比
  1870. /// </summary>
  1871. /// <param name="nums"></param>
  1872. /// <param name="curr"></param>
  1873. /// <returns></returns>
  1874. public static (double persent,int count ) GetPersent(IEnumerable<double> nums, double curr)
  1875. {
  1876. int count = 0;
  1877. foreach (var op in nums.OrderBy(x => x))
  1878. {
  1879. if (op < curr)
  1880. {
  1881. count++;
  1882. }
  1883. else if (op == curr)
  1884. {
  1885. count++;
  1886. }
  1887. else
  1888. {
  1889. break;
  1890. }
  1891. }
  1892. return (count *1.0/ nums.Count() * 100,count);
  1893. }
  1894. }
  1895. /// <summary>
  1896. /// 学生导出Excel的Entity
  1897. /// </summary>
  1898. public class StudentLessonItem
  1899. {
  1900. /// <summary>
  1901. /// 学生id
  1902. /// </summary>
  1903. public string? studentId { get; set; }
  1904. /// <summary>
  1905. /// 互动发起次数
  1906. /// </summary>
  1907. public double hd_fqc { get; set; } = 0;
  1908. /// <summary>
  1909. /// 互动参与次数
  1910. /// </summary>
  1911. public double hd_cyc { get; set; } = 0;
  1912. /// <summary>
  1913. /// 互动正确次数
  1914. /// </summary>
  1915. public double hd_zqc { get; set; } = 0;
  1916. /// <summary>
  1917. /// 个人计分
  1918. /// </summary>
  1919. public double gr_jf { get; set; } = 0;
  1920. /// <summary>
  1921. /// 互动成效指数
  1922. /// </summary>
  1923. public double hd_cx { get; set; } = 0;
  1924. /// <summary>
  1925. /// 互动参与指数
  1926. /// </summary>
  1927. public double hd_cy { get; set; } = 0;
  1928. /// <summary>
  1929. /// 评测得分率
  1930. /// </summary>
  1931. public double pc_df { get; set; } = 0;
  1932. /// <summary>
  1933. /// 评测作答率
  1934. /// </summary>
  1935. public double pc_zd { get; set; } = 0;
  1936. /// <summary>
  1937. /// 任务发起次数
  1938. /// </summary>
  1939. public double rw_fqc { get; set; } = 0;
  1940. /// <summary>
  1941. /// 任务参与次数
  1942. /// </summary>
  1943. public double rw_cyc { get; set; } = 0;
  1944. /// <summary>
  1945. /// 任务成效指数
  1946. /// </summary>
  1947. public double rw_cx { get; set; } = 0;
  1948. /// <summary>
  1949. /// 任务参与指数
  1950. /// </summary>
  1951. public double rw_cy { get; set; } = 0;
  1952. /// <summary>
  1953. /// 评价发起次数
  1954. /// </summary>
  1955. public double pj_cs { get; set; } = 0;
  1956. /// <summary>
  1957. /// 投票发起次数
  1958. /// </summary>
  1959. public double pj_vc { get; set; } = 0;
  1960. /// <summary>
  1961. /// 投票得票数
  1962. /// </summary>
  1963. public double pj_vg { get; set; } = 0;
  1964. /// <summary>
  1965. /// 投票次数
  1966. /// </summary>
  1967. public double pj_vo { get; set; } = 0;
  1968. /// <summary>
  1969. /// 星光发起次数
  1970. /// </summary>
  1971. public double pj_gc { get; set; } = 0;
  1972. /// <summary>
  1973. /// 星光得分数
  1974. /// </summary>
  1975. public double pj_gg { get; set; } = 0;
  1976. /// <summary>
  1977. /// 星光评分次数
  1978. /// </summary>
  1979. public double pj_go { get; set; } = 0;
  1980. /// <summary>
  1981. /// 互评发起次数
  1982. /// </summary>
  1983. public double pj_pc { get; set; } = 0;
  1984. /// <summary>
  1985. /// 互评得分数
  1986. /// </summary>
  1987. public double pj_pg { get; set; } = 0;
  1988. /// <summary>
  1989. /// 互评评分次数
  1990. /// </summary>
  1991. public double pj_po { get; set; } = 0;
  1992. /// <summary>
  1993. /// 评价能力
  1994. /// </summary>
  1995. public double pj_nl { get; set; } = 0;
  1996. /// <summary>
  1997. /// 协作发起次数
  1998. /// </summary>
  1999. public double xz_fqc { get; set; } = 0;
  2000. /// <summary>
  2001. /// 协作参与次数
  2002. /// </summary>
  2003. public double xz_cyc { get; set; } = 0;
  2004. /// <summary>
  2005. /// 协作成果分数
  2006. /// </summary>
  2007. public double xz_cgf { get; set; } = 0;
  2008. /// <summary>
  2009. /// 协作能力指数
  2010. /// </summary>
  2011. public double xz_cx { get; set; } = 0;
  2012. /// <summary>
  2013. /// 协作参与指数
  2014. /// </summary>
  2015. public double xz_cy { get; set; } = 0;
  2016. /// <summary>
  2017. /// 学习成效
  2018. /// </summary>
  2019. public double xx_cx { get; set; } = 0;
  2020. /// <summary>
  2021. /// 学习参与
  2022. /// </summary>
  2023. public double xx_cy { get; set; } = 0;
  2024. }
  2025. /// <summary>
  2026. /// 历史课例的关键数据模型
  2027. /// </summary>
  2028. public class LessonDataAnalysisCluster: LessonDataAnalysisBase
  2029. {
  2030. /// <summary>
  2031. ///
  2032. /// </summary>
  2033. public List<KeyValuePair<double, List<double>>> clustersInteract { get; set; } = new List<KeyValuePair<double, List<double>>>();
  2034. ///// <summary>
  2035. /////
  2036. ///// </summary>
  2037. //public List<KeyValuePair<double, List<double>>> clustersPscore { get; set; } = new List<KeyValuePair<double, List<double>>>();
  2038. ///// <summary>
  2039. /////
  2040. ///// </summary>
  2041. //public List<KeyValuePair<double, List<double>>> clustersTscore { get; set; } = new List<KeyValuePair<double, List<double>>>();
  2042. ///// <summary>
  2043. /////
  2044. ///// </summary>
  2045. //public List<KeyValuePair<double, List<double>>> clustersGscore { get; set; } = new List<KeyValuePair<double, List<double>>>();
  2046. }
  2047. /// <summary>
  2048. ///
  2049. /// </summary>
  2050. public abstract class LessonDataAnalysisBase
  2051. {
  2052. ///// <summary>
  2053. ///// 协作次数
  2054. ///// </summary>
  2055. //public IEnumerable<double> cowork { get; set; } = new List<double>();
  2056. ///// <summary>
  2057. /////
  2058. ///// </summary>
  2059. //public IEnumerable<double> coworkBase { get; set; } = new List<double>();
  2060. /// <summary>
  2061. ///
  2062. /// </summary>
  2063. public List<double> task { get; set; } = new List<double>();
  2064. ///// <summary>
  2065. /////
  2066. ///// </summary>
  2067. //public IEnumerable<double> taskBase { get; set; } = new List<double>();
  2068. ///// <summary>
  2069. /////
  2070. ///// </summary>
  2071. //public IEnumerable<double> exam { get; set; } = new List<double>();
  2072. ///// <summary>
  2073. /////
  2074. ///// </summary>
  2075. //public IEnumerable<double> examBase { get; set; } = new List<double>();
  2076. ///// <summary>
  2077. /////
  2078. ///// </summary>
  2079. //public IEnumerable<double> smartRating { get; set; } = new List<double>();
  2080. ///// <summary>
  2081. /////
  2082. ///// </summary>
  2083. //public IEnumerable<double> smartRatingBase { get; set; } = new List<double>();
  2084. /// <summary>
  2085. ///
  2086. /// </summary>
  2087. public List<double> irs { get; set; } = new List<double>();
  2088. /// <summary>
  2089. ///
  2090. /// </summary>
  2091. public List<double> interactNormal { get; set; } = new List<double>();
  2092. /// <summary>
  2093. /// 个人计分
  2094. /// </summary>
  2095. public List<double> pscore { get; set; } = new List<double>();
  2096. /// <summary>
  2097. /// 小组计分
  2098. /// </summary>
  2099. public List<double> gscore { get; set; } = new List<double>();
  2100. /// <summary>
  2101. /// 互动计分
  2102. /// </summary>
  2103. public List<double> tscore { get; set; } = new List<double>();
  2104. /// <summary>
  2105. /// 作品上传数
  2106. /// </summary>
  2107. public List<List<double>> upload { get; set; } = new List<List<double>>();
  2108. /// <summary>
  2109. /// 学生协作成果数
  2110. /// </summary>
  2111. public List<double> stuCowork { get; set; } = new List<double>();
  2112. /// <summary>
  2113. /// 小组协作成果数
  2114. /// </summary>
  2115. public List<double> groupCowork { get; set; } = new List<double>();
  2116. ///// <summary>
  2117. ///// 挑人集合
  2118. ///// </summary>
  2119. //public List<List<string>> pickup { get; set; } = new List<List<string>>();
  2120. ///// <summary>
  2121. ///// 挑人集合-小组
  2122. ///// </summary>
  2123. //public List<List<string>> pickup_group { get; set; } = new List<List<string>>();
  2124. }
  2125. /// <summary>
  2126. /// 每月的课例模型数据
  2127. /// </summary>
  2128. public class LessonDataAnalysisMonth: LessonDataAnalysisBase
  2129. {
  2130. /// <summary>
  2131. /// 时间戳
  2132. /// </summary>
  2133. public long updateTime { get; set; }
  2134. /// <summary>
  2135. /// yyyyMM
  2136. /// </summary>
  2137. public string? yearMonth { get; set; }
  2138. }
  2139. /// <summary>
  2140. ///
  2141. /// </summary>
  2142. public class LessonLocal
  2143. {
  2144. /// <summary>
  2145. ///
  2146. /// </summary>
  2147. public LessonBase? lessonBase { get; set; }
  2148. /// <summary>
  2149. ///
  2150. /// </summary>
  2151. public TimeLineData? timeLineData { get; set; }
  2152. /// <summary>
  2153. ///
  2154. /// </summary>
  2155. public LessonRecord? lessonRecord { get; set; }
  2156. /// <summary>
  2157. ///
  2158. /// </summary>
  2159. public List<LocalStudent> studentLessonDatas { get; set; } = new List<LocalStudent>();
  2160. /// <summary>
  2161. ///
  2162. /// </summary>
  2163. public List<TaskData> taskDatas { get; set; } = new List<TaskData>();
  2164. /// <summary>
  2165. ///
  2166. /// </summary>
  2167. public List<SmartRatingData> smartRatingDatas { get; set; } = new List<SmartRatingData>();
  2168. /// <summary>
  2169. ///
  2170. /// </summary>
  2171. public List<IRSData> irsDatas { get; set; } = new List<IRSData>();
  2172. /// <summary>
  2173. ///
  2174. /// </summary>
  2175. public List<CoworkData> coworkDatas { get; set; } = new List<CoworkData>();
  2176. /// <summary>
  2177. ///
  2178. /// </summary>
  2179. public List<ExamData> examDatas { get; set; } = new List<ExamData>();
  2180. /// <summary>
  2181. ///
  2182. /// </summary>
  2183. public List<TimeLineEvent> sokratesDatas { get; set; } = new List<TimeLineEvent>();
  2184. }
  2185. /// <summary>
  2186. ///
  2187. /// </summary>
  2188. public class TechCount
  2189. {
  2190. public string? yearMonth { get; set; }
  2191. /// <summary>
  2192. ///
  2193. /// </summary>
  2194. public string? lessonId { get; set; }
  2195. /// <summary>
  2196. /// 评测数量
  2197. /// </summary>
  2198. public int examCount { get; set; }
  2199. /// <summary>
  2200. /// 任务数量
  2201. /// </summary>
  2202. public int taskCount { get; set; }
  2203. /// <summary>
  2204. /// IRS次数
  2205. /// </summary>
  2206. public int irsCount { get; set; }
  2207. /// <summary>
  2208. /// 互动次数
  2209. /// </summary>
  2210. //public int interactExamCount { get; set; }
  2211. /// <summary>
  2212. /// 互动次数
  2213. /// </summary>
  2214. public int interactNormalCount { get; set; }
  2215. /// <summary>
  2216. /// 协作次数
  2217. /// </summary>
  2218. public int coworkCount { get; set; }
  2219. /// <summary>
  2220. /// 智能评分次数
  2221. /// </summary>
  2222. public int smartRatingCount { get; set; }
  2223. /// <summary>
  2224. ///
  2225. /// </summary>
  2226. public List<CodeLong> timeCount { get; set; } = new List<CodeLong>();
  2227. /// <summary>
  2228. ///
  2229. /// </summary>
  2230. public IEnumerable<double> pscore { get; set; } = new List<double>();
  2231. /// <summary>
  2232. ///
  2233. /// </summary>
  2234. public IEnumerable<double> gscore { get; set; } = new List<double>();
  2235. /// <summary>
  2236. ///
  2237. /// </summary>
  2238. public IEnumerable<double> tscore { get; set; } = new List<double>();
  2239. /// <summary>
  2240. /// 评测数量
  2241. /// </summary>
  2242. public int examCountBase { get; set; }
  2243. /// <summary>
  2244. /// 任务数量
  2245. /// </summary>
  2246. public int taskCountBase { get; set; }
  2247. /// <summary>
  2248. /// IRS次数
  2249. /// </summary>
  2250. public int irsCountBase { get; set; }
  2251. /// <summary>
  2252. /// 互动次数
  2253. /// </summary>
  2254. //public int interactExamCountBase { get; set; }
  2255. /// <summary>
  2256. /// 互动次数
  2257. /// </summary>
  2258. public int interactNormalCountBase { get; set; }
  2259. /// <summary>
  2260. /// 协作次数
  2261. /// </summary>
  2262. public int coworkCountBase { get; set; }
  2263. /// <summary>
  2264. /// 智能评分次数
  2265. /// </summary>
  2266. public int smartRatingCountBase { get; set; }
  2267. /// <summary>
  2268. /// 作品上传数
  2269. /// </summary>
  2270. public List<List<double>> upload { get; set; } = new List<List<double>>();
  2271. /// <summary>
  2272. /// 学生协作成果数
  2273. /// </summary>
  2274. public List<double> stuCowork { get; set; } = new List<double>();
  2275. /// <summary>
  2276. /// 小组协作成果数
  2277. /// </summary>
  2278. public List<double> groupCowork { get; set; } = new List<double>();
  2279. }
  2280. }