LessonRecordController.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. using DocumentFormat.OpenXml.Office2010.Excel;
  2. using HTEX.Lib.ETL;
  3. using HTEX.Lib.ETL.Lesson;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.Azure.Cosmos;
  6. using Microsoft.OData.UriParser;
  7. using System.Collections.Generic;
  8. using System.IO;
  9. using System.Runtime.InteropServices;
  10. using System.Text.Json;
  11. using System.Xml;
  12. using TEAMModelOS.SDK;
  13. using TEAMModelOS.SDK.DI;
  14. using TEAMModelOS.SDK.Extension;
  15. using TEAMModelOS.SDK.Helper.Common.FileHelper;
  16. using TEAMModelOS.SDK.Models;
  17. using TEAMModelOS.SDK.Models.Cosmos.BI;
  18. using TEAMModelOS.SDK.Models.Cosmos.OpenEntity;
  19. namespace HTEX.DataETL.Controllers
  20. {
  21. [ApiController]
  22. [Route("lesson-record")]
  23. public class LessonRecordController : ControllerBase
  24. {
  25. private readonly ILogger<LessonRecordController> _logger;
  26. private readonly AzureCosmosFactory _azureCosmos;
  27. private readonly AzureStorageFactory _azureStorage;
  28. private readonly IConfiguration _configuration;
  29. private readonly IWebHostEnvironment _webHostEnvironment;
  30. public LessonRecordController(ILogger<LessonRecordController> logger, AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage
  31. , IConfiguration configuration, IWebHostEnvironment environment)
  32. {
  33. _logger = logger;
  34. _azureCosmos = azureCosmos;
  35. _azureStorage = azureStorage;
  36. _configuration = configuration;
  37. _webHostEnvironment = environment;
  38. }
  39. [HttpPost("process-local")]
  40. public async Task<IActionResult> ProcessLocal(JsonElement json)
  41. {
  42. List<StudentLessonData> studentLessonDatas = new List<StudentLessonData>();
  43. string? id = json.GetProperty("id").GetString();
  44. if (!string.IsNullOrWhiteSpace(id))
  45. {
  46. string? lessonPath= _configuration.GetValue<string>("LessonPath");
  47. string? path = $"{lessonPath}\\locals\\{id}";
  48. var files = FileHelper.ListAllFiles(path);
  49. // var sampleJson =System.IO. File.ReadAllTextAsync(path);
  50. LessonBase? lessonBase = null;
  51. List<LocalStudent> localStudents = new List<LocalStudent>();
  52. List<TaskData> taskDatas = new List<TaskData>();
  53. List<SmartRatingData> smartRatingDatas = new List<SmartRatingData>();
  54. List<IRSData> irsDatas = new List<IRSData>();
  55. List<CoworkData> coworkDatas = new List<CoworkData>();
  56. List<ExamData> examDatas = new List<ExamData>();
  57. TimeLineData? timeLineData = null;
  58. foreach (var item in files)
  59. {
  60. if (item.Contains("IES\\base.json"))
  61. {
  62. string jsons = await System.IO.File.ReadAllTextAsync(item);
  63. jsons = jsons.Replace("\"Uncall\"", "0").Replace("Uncall", "0");
  64. lessonBase = jsons.ToObject<LessonBase>();
  65. var data = LessonETLService.GetBaseData(lessonBase);
  66. localStudents = data.studentLessonDatas;
  67. }
  68. if (item.Contains("IES\\TimeLine.json"))
  69. {
  70. string jsons = await System.IO.File.ReadAllTextAsync(item);
  71. timeLineData = jsons.ToObject<TimeLineData>();
  72. }
  73. if (item.Contains("IES\\Task.json"))
  74. {
  75. string jsons = await System.IO.File.ReadAllTextAsync(item);
  76. taskDatas = jsons.ToObject<List<TaskData>>();
  77. }
  78. if (item.Contains("IES\\SmartRating.json"))
  79. {
  80. string jsons = await System.IO.File.ReadAllTextAsync(item);
  81. smartRatingDatas = jsons.ToObject<List<SmartRatingData>>();
  82. }
  83. if (item.Contains("IES\\IRS.json"))
  84. {
  85. string jsons = await System.IO.File.ReadAllTextAsync(item);
  86. irsDatas = jsons.ToObject<List<IRSData>>();
  87. }
  88. if (item.Contains("IES\\Cowork.json"))
  89. {
  90. string jsons = await System.IO.File.ReadAllTextAsync(item);
  91. coworkDatas = jsons.ToObject<List<CoworkData>>();
  92. }
  93. try
  94. {
  95. if (item.Contains($"\\{id}\\Exam\\") && item.EndsWith("Exam.json"))
  96. {
  97. string examsFile = item;
  98. if (examsFile.EndsWith("Exam.json"))
  99. {
  100. ExamData? examData = null;
  101. string jsons = await System.IO.File.ReadAllTextAsync(item);
  102. jsons = jsons.Replace("\"publish\": \"0\"", "\"publish\": 0").Replace("\"publish\": \"1\"", "\"publish\": 1");
  103. examData = jsons.ToObject<ExamData>();
  104. if (examData != null && examData.exam.papers.IsNotEmpty())
  105. {
  106. string paperId = examData.exam.papers.First().id;
  107. string paperPath = $"{path}\\ExamPaper\\{paperId}\\index.json";
  108. string jsonp = await System.IO.File.ReadAllTextAsync(paperPath);
  109. LessonPaper lessonPaper = jsonp.ToObject<LessonPaper>();
  110. examData.paper = lessonPaper;
  111. examDatas.Add(examData);
  112. }
  113. }
  114. }
  115. }
  116. catch (Exception ex)
  117. {
  118. _logger.LogError(ex, ex.Message);
  119. }
  120. }
  121. if (lessonBase!=null && timeLineData!=null)
  122. {
  123. studentLessonDatas = localStudents.ToJsonString().ToObject<List<StudentLessonData>>();
  124. studentLessonDatas = LessonETLService.GetIRSData(lessonBase, timeLineData, irsDatas, studentLessonDatas, examDatas, id);
  125. studentLessonDatas = LessonETLService.GetCoworkData(lessonBase, timeLineData, coworkDatas, studentLessonDatas,id);
  126. studentLessonDatas = LessonETLService.GetExamData(lessonBase, timeLineData, examDatas, studentLessonDatas, Constant.objectiveTypes, id);
  127. studentLessonDatas = LessonETLService.GetSmartRatingData(lessonBase, timeLineData, smartRatingDatas, studentLessonDatas, id);
  128. studentLessonDatas = LessonETLService.GetTaskData(lessonBase, timeLineData, taskDatas, studentLessonDatas,id);
  129. await System.IO.File.WriteAllTextAsync(Path.Combine(path, $"student-analysis.json"), studentLessonDatas.ToJsonString());
  130. string jsons = await System.IO.File.ReadAllTextAsync($"{lessonPath}\\analysis\\analysis.json");
  131. LessonDataAnalysisCluster lessonDataAnalysis = jsons.ToObject<LessonDataAnalysisCluster>();
  132. var lessonItems= LessonETLService.ProcessStudentData(studentLessonDatas, lessonDataAnalysis);
  133. XmlDocument xmlDocument = new XmlDocument();
  134. var runtimePath= System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
  135. xmlDocument.Load($"{runtimePath}\\summary.xml");
  136. await LessonETLService. ExportToExcel(lessonItems, $"{path}\\analysis.xlsx", xmlDocument);
  137. }
  138. }
  139. return Ok();
  140. }
  141. /// <summary>
  142. /// 课例数据ETL处理过程
  143. /// </summary>
  144. /// <param name="json"></param>
  145. /// <returns></returns>
  146. [HttpPost("process-history-students")]
  147. public async Task<IActionResult> ProcessHistoryStudents(JsonElement json)
  148. {
  149. return Ok();
  150. }
  151. /// <summary>
  152. /// 课例数据ETL处理过程
  153. /// </summary>
  154. /// <param name="json"></param>
  155. /// <returns></returns>
  156. [HttpPost("process-history")]
  157. public async Task<IActionResult> ProcessHistory(JsonElement json)
  158. {
  159. List<string> localIds = new List<string>();
  160. string? lessonBasePath = _configuration.GetValue<string>("LessonPath");
  161. string? pathLessons = $"{lessonBasePath}\\lessons";
  162. string? pathAnalysis = $"{lessonBasePath}\\analysis";
  163. var filesLessons = FileHelper.ListAllFiles(pathLessons);
  164. foreach (var file in filesLessons)
  165. {
  166. if (file.EndsWith("-local.json"))
  167. {
  168. string lessonId = file.Split("\\").Last().Replace("-local.json", "");
  169. localIds.Add(lessonId);
  170. }
  171. }
  172. bool loadLocal = true;
  173. List<LessonDataAnalysisMonth> lessonDataAnalysisMonths = new List<LessonDataAnalysisMonth>();
  174. var filesAnalysis = FileHelper.ListAllFiles(pathAnalysis);
  175. long stime = 1690819200000;//2023-08-01 00:00:00
  176. foreach (var file in filesAnalysis) {
  177. //读取每月的数据
  178. if (file.EndsWith("-m-analysis.json"))
  179. {
  180. string jsons = await System.IO.File.ReadAllTextAsync(file);
  181. LessonDataAnalysisMonth lessonDataAnalysis = jsons.ToObject<LessonDataAnalysisMonth>();
  182. lessonDataAnalysisMonths.Add(lessonDataAnalysis);
  183. }
  184. }
  185. if (lessonDataAnalysisMonths.IsNotEmpty()) {
  186. var maxUpdateTime = lessonDataAnalysisMonths.Max(x => x.updateTime);
  187. if (maxUpdateTime>0)
  188. {
  189. //更新周期是一周
  190. if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()- maxUpdateTime>604800000)
  191. {
  192. stime=maxUpdateTime;
  193. loadLocal =true;
  194. }
  195. else
  196. {
  197. stime=maxUpdateTime;
  198. loadLocal=false;
  199. }
  200. }
  201. }
  202. HashSet<string> yearMonth = new HashSet<string>();
  203. long newest = 0;
  204. if (loadLocal ||(json.TryGetProperty("force", out JsonElement _force)&& _force.ValueKind.Equals(JsonValueKind.True)))
  205. {
  206. List<LessonRecord> lessonRecords = new List<LessonRecord>();
  207. var resultSchool = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School)
  208. .GetList<LessonRecord>($"SELECT value c FROM c where c.startTime>={stime} and c.expire<=0 and c.status<>404 and c.duration>300 and c.pk='LessonRecord' and c.school<>'hbcn' and c.school<>'habook' and (c.tLevel>0 or c.pLevel>0) ", null);
  209. if (resultSchool.list.IsNotEmpty())
  210. {
  211. newest= resultSchool.list.Max(x => x.startTime);
  212. lessonRecords.AddRange(resultSchool.list);
  213. }
  214. else {
  215. newest=stime;
  216. }
  217. var resultTeacher = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
  218. .GetList<LessonRecord>($"SELECT value c FROM c where c.startTime>={stime} and c.expire<=0 and c.status<>404 and c.duration>300 and c.pk='LessonRecord' and (c.tLevel>0 or c.pLevel>0) ", null);
  219. if (resultTeacher.list.IsNotEmpty())
  220. {
  221. long max = resultTeacher.list.Max(x => x.startTime);
  222. if (max<newest)
  223. {
  224. newest=max;
  225. }
  226. lessonRecords.AddRange(resultTeacher.list);
  227. }
  228. List<string> ignore = new List<string>() { "PgJump", "PgRcv", "PgAdd" };
  229. if (lessonRecords.IsNotEmpty())
  230. {
  231. await foreach (var item in LessonETLService.GetLessonLocal(lessonRecords, localIds, _azureStorage, pathLessons))
  232. {
  233. string yearMonthPath = DateTimeOffset.FromUnixTimeMilliseconds(item.lessonRecord.startTime).ToString("yyyyMM");
  234. if (item.lessonBase!=null && item.lessonBase.student!=null)
  235. {
  236. TechCount techCount = new TechCount
  237. {
  238. lessonId=item.lessonRecord?.id,
  239. examCount = item.examDatas.Count,
  240. taskCount = item.taskDatas.Count,
  241. irsCount = item.irsDatas.Count,
  242. coworkCount = item.coworkDatas.Count,
  243. smartRatingCount =item.smartRatingDatas.Count,
  244. timeCount=item.sokratesDatas.Where(x => !ignore.Contains(x.Event) && !x.Event.Contains("End", StringComparison.OrdinalIgnoreCase)).GroupBy(x => x.Event).Select(x => new CodeLong() { code=x.Key, value= x.ToList().Count }).ToList()
  245. };
  246. await System.IO.File.WriteAllTextAsync($"{pathLessons}\\MM{yearMonthPath}\\{item.lessonRecord.id}-count.json", techCount.ToJsonString());
  247. await System.IO.File.WriteAllTextAsync($"{pathLessons}\\MM{yearMonthPath}\\{item.lessonRecord!.id}-local.json", item.ToJsonString());
  248. }
  249. else
  250. {
  251. System.IO.File.Delete($"{pathLessons}\\MM{yearMonthPath}\\{item.lessonRecord!.id}-local.json");
  252. System.IO.File.Delete($"{pathLessons}\\MM{yearMonthPath}\\{item.lessonRecord!.id}-count.json");
  253. }
  254. }
  255. }
  256. List<TechCount> techCounts = new List<TechCount>();
  257. filesLessons = FileHelper.ListAllFiles(pathLessons, "-local.json");
  258. await foreach (var item in GetTeachCount(lessonRecords, filesLessons, pathLessons, ignore, Constant.objectiveTypes, _azureStorage))
  259. {
  260. techCounts.Add(item);
  261. }
  262. var yearMonthDatas = techCounts.GroupBy(x => x.yearMonth).Select(x => new { key = x.Key, list = x.ToList() });
  263. // lessonDataAnalysisMonths = new List<LessonDataAnalysisMonth>();
  264. LessonDataAnalysisCluster lessonDataAnalysisCluster = new LessonDataAnalysisCluster();
  265. foreach (var yearMonthData in yearMonthDatas)
  266. {
  267. if (string.IsNullOrWhiteSpace(yearMonthData.key))
  268. {
  269. Console.WriteLine(yearMonthData.list.Select(x => x.lessonId).ToJsonString());
  270. }
  271. LessonDataAnalysisMonth lessonDataAnalysisMonth= new LessonDataAnalysisMonth() { updateTime= newest, yearMonth= yearMonthData.key };
  272. lessonDataAnalysisMonth.pscore = yearMonthData.list.SelectMany(x => x.pscore).ToList();
  273. lessonDataAnalysisMonth.tscore = yearMonthData.list.SelectMany(x => x.tscore).ToList();
  274. lessonDataAnalysisMonth.gscore = yearMonthData.list.SelectMany(x => x.gscore).ToList();
  275. lessonDataAnalysisMonth.irs= yearMonthData.list.Where(x => x.irsCount>0).Select(x =>(double)x.irsCount).ToList();
  276. lessonDataAnalysisMonth.interactNormal= yearMonthData.list.Where(x => x.interactNormalCount > 0).Select(x => (double)x.interactNormalCount).ToList();
  277. lessonDataAnalysisMonth.task = yearMonthData.list.Where(x => x.taskCount > 0).Select(x => (double)x.taskCount).ToList();
  278. lessonDataAnalysisMonth.stuCowork=yearMonthData.list.SelectMany(x => x.stuCowork).ToList();
  279. lessonDataAnalysisMonth.groupCowork=yearMonthData.list.SelectMany(x => x.groupCowork).ToList();
  280. System.IO.File.WriteAllText(Path.Combine(pathAnalysis, $"{yearMonthData.key}-m-analysis.json"), lessonDataAnalysisMonth.ToJsonString());
  281. // lessonDataAnalysisMonths.Add( lessonDataAnalysisMonth);
  282. if (lessonDataAnalysisMonth.task.IsNotEmpty())
  283. {
  284. lessonDataAnalysisCluster.task.AddRange(lessonDataAnalysisMonth.task);
  285. }
  286. if (lessonDataAnalysisMonth.irs.IsNotEmpty())
  287. {
  288. lessonDataAnalysisCluster.irs.AddRange(lessonDataAnalysisMonth.irs);
  289. }
  290. if (lessonDataAnalysisMonth.interactNormal.IsNotEmpty())
  291. {
  292. lessonDataAnalysisCluster.interactNormal.AddRange(lessonDataAnalysisMonth.interactNormal);
  293. }
  294. if (lessonDataAnalysisMonth.pscore.IsNotEmpty())
  295. {
  296. lessonDataAnalysisCluster.pscore.AddRange(lessonDataAnalysisMonth.pscore);
  297. }
  298. if (lessonDataAnalysisMonth.gscore.IsNotEmpty())
  299. {
  300. lessonDataAnalysisCluster.gscore.AddRange(lessonDataAnalysisMonth.gscore);
  301. }
  302. if (lessonDataAnalysisMonth.tscore.IsNotEmpty())
  303. {
  304. lessonDataAnalysisCluster.tscore.AddRange(lessonDataAnalysisMonth.tscore);
  305. }
  306. if (lessonDataAnalysisMonth.stuCowork.IsNotEmpty())
  307. {
  308. lessonDataAnalysisCluster.stuCowork.AddRange(lessonDataAnalysisMonth.stuCowork);
  309. }
  310. if (lessonDataAnalysisMonth.groupCowork.IsNotEmpty())
  311. {
  312. lessonDataAnalysisCluster.groupCowork.AddRange(lessonDataAnalysisMonth.groupCowork);
  313. }
  314. }
  315. //标准差偏差N倍,视为异常数据
  316. int thresholdMultiplier = 2;
  317. lessonDataAnalysisCluster.pscore= LessonETLService.CleanDataBySDThreshold(lessonDataAnalysisCluster.pscore.OrderBy(x => x), thresholdMultiplier);
  318. lessonDataAnalysisCluster.gscore= LessonETLService.CleanDataBySDThreshold(lessonDataAnalysisCluster.gscore.OrderBy(x => x), thresholdMultiplier);
  319. lessonDataAnalysisCluster.tscore= LessonETLService.CleanDataBySDThreshold(lessonDataAnalysisCluster.tscore.OrderBy(x => x), thresholdMultiplier);
  320. lessonDataAnalysisCluster.irs = LessonETLService.CleanDataBySDThreshold(lessonDataAnalysisCluster.irs.OrderBy(x => x), thresholdMultiplier);
  321. lessonDataAnalysisCluster.interactNormal=LessonETLService. CleanDataBySDThreshold(lessonDataAnalysisCluster.interactNormal.OrderBy(x => x), thresholdMultiplier);
  322. lessonDataAnalysisCluster.stuCowork=LessonETLService.CleanDataBySDThreshold(lessonDataAnalysisCluster.stuCowork.OrderBy(x=>x), thresholdMultiplier);
  323. lessonDataAnalysisCluster.groupCowork=LessonETLService.CleanDataBySDThreshold(lessonDataAnalysisCluster.groupCowork.OrderBy(x => x), thresholdMultiplier);
  324. List<KeyValuePair<double, List<int>>> clustersDataInteract = new();
  325. var clusterInteract = KMeansService.KMeans(lessonDataAnalysisCluster.interactNormal.Select(x => (int)x).OrderBy(x => x));
  326. //foreach (var item in clusterInteract)
  327. //{
  328. // Console.WriteLine($"dp:{item.Key} ,avg: {item.Value.Average()}, count: {item.Value.Count}, min:{item.Value.Min()}, max:{item.Value.Max()}");
  329. //}
  330. foreach (var s in clusterInteract.OrderBy(x => x.Key))
  331. {
  332. clustersDataInteract.Add(s);
  333. }
  334. lessonDataAnalysisCluster.clustersInteract= clustersDataInteract;
  335. System.IO.File.WriteAllText(Path.Combine(pathAnalysis, "analysis.json"), lessonDataAnalysisCluster.ToJsonString());
  336. }
  337. return Ok(new { yearMonth });
  338. }
  339. private static async IAsyncEnumerable<TechCount> GetTeachCount(List<LessonRecord> lessonRecords,List<string> filesLessons, string pathLessons, List<string> ignore, List<string> objectiveTypes,AzureStorageFactory azureStorage)
  340. {
  341. foreach (var item in filesLessons)
  342. {
  343. if (item.EndsWith("-local.json"))
  344. {
  345. TechCount count = null;
  346. string lessonId = item.Split("\\").Last().Replace("-local.json", "");
  347. string countFile = item.Replace("-local.json", "-count.json");
  348. if (System.IO.File.Exists(countFile))
  349. {
  350. if (System.IO.File.Exists(countFile))
  351. {
  352. string contjson = await System.IO.File.ReadAllTextAsync(countFile);
  353. count = contjson.ToObject<TechCount>();
  354. }
  355. }
  356. if (string.IsNullOrWhiteSpace(count?.yearMonth))
  357. {
  358. string localjson = await System.IO.File.ReadAllTextAsync(item);
  359. var lessonLocal = localjson.ToObject<LessonLocal>();
  360. count = new TechCount();
  361. count.lessonId=item.Split("\\").Last().Replace("-local.json", "");
  362. count.examCount= lessonLocal.examDatas.Count;
  363. count.taskCount= lessonLocal.taskDatas.Count;
  364. count.irsCount= lessonLocal.irsDatas.Count;
  365. count.interactNormalCount=count.irsCount;
  366. count.coworkCount= lessonLocal.coworkDatas.Count;
  367. count.smartRatingCount= lessonLocal.smartRatingDatas.Count;
  368. count.timeCount=lessonLocal.sokratesDatas.Where(x => !ignore.Contains(x.Event) && !x.Event.Contains("End", StringComparison.OrdinalIgnoreCase)).GroupBy(x => x.Event).Select(x => new CodeLong() { code=x.Key, value= x.ToList().Count }).ToList();
  369. if (string.IsNullOrWhiteSpace("636725021468921856"))
  370. {
  371. int d = 1;
  372. }
  373. if (lessonLocal.lessonRecord!=null)
  374. {
  375. count.yearMonth=DateTimeOffset.FromUnixTimeMilliseconds(lessonLocal.lessonRecord.startTime).ToString("yyyyMM");
  376. if (lessonLocal?.lessonBase?.summary!=null)
  377. {
  378. count.smartRatingCountBase=lessonLocal.lessonBase.summary.smartRatingCount;
  379. count.irsCountBase=lessonLocal.lessonBase.summary.interactionCount;
  380. count.taskCountBase=lessonLocal.lessonBase.summary.collateTaskCount;
  381. count.coworkCountBase=lessonLocal.lessonBase.summary.coworkTaskCount;
  382. count.examCountBase=lessonLocal.lessonBase.summary.examCount;
  383. count.interactNormalCountBase= count.interactNormalCount;
  384. }
  385. if (lessonLocal?.lessonBase?.report?.clientSummaryList!=null)
  386. {
  387. count.pscore= lessonLocal.lessonBase.report.clientSummaryList.Where(x => x.score>0).Select(x => x.score);
  388. count.gscore= lessonLocal.lessonBase.report.clientSummaryList.Where(x => x.groupScore>0).Select(x => x.groupScore);
  389. count.tscore= lessonLocal.lessonBase.report.clientSummaryList.Where(x => x.interactScore>0).Select(x => x.interactScore);
  390. }
  391. ///处理学生数据
  392. {
  393. List<StudentLessonData> studentLessonDatas = lessonLocal.studentLessonDatas.ToJsonString().ToObject<List<StudentLessonData>>();
  394. studentLessonDatas = LessonETLService.GetIRSData(lessonLocal.lessonBase!, lessonLocal.timeLineData!, lessonLocal.irsDatas, studentLessonDatas, lessonLocal.examDatas, lessonLocal.lessonRecord.id);
  395. studentLessonDatas = LessonETLService.GetCoworkData(lessonLocal.lessonBase!, lessonLocal.timeLineData!, lessonLocal.coworkDatas, studentLessonDatas, lessonLocal.lessonRecord.id);
  396. studentLessonDatas = LessonETLService.GetExamData(lessonLocal.lessonBase!, lessonLocal.timeLineData!, lessonLocal.examDatas, studentLessonDatas, objectiveTypes, lessonLocal.lessonRecord.id);
  397. studentLessonDatas = LessonETLService.GetSmartRatingData(lessonLocal.lessonBase!, lessonLocal.timeLineData!, lessonLocal.smartRatingDatas, studentLessonDatas, lessonLocal.lessonRecord.id);
  398. studentLessonDatas = LessonETLService.GetTaskData(lessonLocal.lessonBase!, lessonLocal.timeLineData!, lessonLocal.taskDatas, studentLessonDatas, lessonLocal.lessonRecord.id);
  399. // var techCount = techCounts.Find(x => !string.IsNullOrWhiteSpace(x.lessonId) && !string.IsNullOrWhiteSpace(lessonLocal?.lessonRecord?.id) && x.lessonId.Equals(lessonLocal.lessonRecord.id));
  400. int sumUpload = 0;
  401. int taskCount = 0;
  402. int maxUpload = 0;
  403. //HashSet<string> pickUp = new HashSet<string>();
  404. foreach (var stu in studentLessonDatas)
  405. {
  406. var countS = stu.taskRecord.itemRecords.Where(x => x.optCount>0);
  407. if (countS.Count()>0)
  408. {
  409. int stuUploadmax = stu.taskRecord.itemRecords.Where(x => x.optCount>0).Max(x => x.optCount);
  410. if (stuUploadmax> maxUpload)
  411. {
  412. maxUpload=stuUploadmax;
  413. }
  414. }
  415. int stuUpload = stu.taskRecord.itemRecords.Where(x => x.optCount>0).Sum(x => x.optCount);
  416. sumUpload+=stuUpload;
  417. if (stu.taskRecord.itemRecords.Count()> taskCount)
  418. {
  419. taskCount=stu.taskRecord.itemRecords.Count();
  420. }
  421. var stu_scores = stu.coworkRecord.itemRecords.Where(x => x.itemScore>0).Select(x => x.itemScore);
  422. if (stu_scores!=null && stu_scores.Count()>0)
  423. {
  424. count.stuCowork.AddRange(stu_scores);
  425. }
  426. var grp_scores = stu.group_coworkScore.Where(x => x>0);
  427. if (grp_scores!=null && grp_scores.Count()>0)
  428. {
  429. count.groupCowork.AddRange(grp_scores);
  430. }
  431. //if (stu.pickups.IsNotEmpty())
  432. //{
  433. // foreach (var pickup in stu.pickups)
  434. // {
  435. // pickUp.Add(pickup);
  436. // }
  437. //}
  438. }
  439. if (studentLessonDatas.Count>0&& taskCount>0 && maxUpload>0)
  440. {
  441. var avgUpload = sumUpload*1.0/(studentLessonDatas.Count *taskCount);
  442. count.upload.Add(new List<double>() { avgUpload, maxUpload });
  443. }
  444. //if (pickUp.Count>0)
  445. //{
  446. // count.pickup.Add(pickUp.ToList());
  447. //}
  448. string owner = lessonLocal.lessonRecord.scope.Equals("school") ? lessonLocal.lessonRecord.school : lessonLocal.lessonRecord.tmdid;
  449. // if (!azureStorage.GetBlobContainerClient(owner).GetBlobClient($"records/{lessonLocal.lessonRecord.id}/student-analysis.json").Exists())
  450. {
  451. }
  452. // if (!System.IO.File.Exists($"{pathLessons}\\MM{count.yearMonth}\\{lessonLocal.lessonRecord.id}-stu.json"))
  453. {
  454. }
  455. if (lessonRecords.FindAll(x => x.id.Equals(lessonLocal.lessonRecord.id)).IsNotEmpty())
  456. {
  457. await System.IO.File.WriteAllTextAsync($"{pathLessons}\\MM{count.yearMonth}\\{lessonLocal.lessonRecord.id}-stu.json", studentLessonDatas.ToJsonString());
  458. await azureStorage.GetBlobContainerClient(owner).UploadFileByContainer(studentLessonDatas.ToJsonString(), "records", $"{lessonLocal.lessonRecord.id}/student-analysis.json");
  459. await System.IO.File.WriteAllTextAsync($"{pathLessons}\\MM{count.yearMonth}\\{lessonLocal.lessonRecord.id}-count.json", count.ToJsonString());
  460. }
  461. }
  462. }
  463. }
  464. if (count!=null)
  465. {
  466. yield return count;
  467. }
  468. }
  469. }
  470. }
  471. }
  472. }