123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068 |
- using Azure.Storage.Blobs.Models;
- using DocumentFormat.OpenXml.Drawing.Charts;
- using DocumentFormat.OpenXml.Spreadsheet;
- using HTEX.Lib.ETL.Lesson;
- using MathNet.Numerics.Distributions;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Azure.Cosmos;
- using Microsoft.Extensions.Logging;
- using StackExchange.Redis;
- using System.Collections.Concurrent;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Globalization;
- using System.Reflection;
- using System.Text.Json;
- using System.Text.RegularExpressions;
- using System.Xml;
- using TEAMModelOS.SDK;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK.Extension;
- using TEAMModelOS.SDK.Helper.Common.FileHelper;
- using TEAMModelOS.SDK.Models;
- using TEAMModelOS.SDK.Models.Cosmos.BI;
- using TEAMModelOS.SDK.Models.Cosmos.Common;
- using TEAMModelOS.SDK.Models.Cosmos.OpenEntity;
- using static TEAMModelOS.SDK.Models.Service.SystemService;
- namespace HTEX.DataETL.Controllers
- {
- [ApiController]
- [Route("lesson-record")]
- public class LessonRecordController : ControllerBase
- {
- private readonly ILogger<LessonRecordController> _logger;
- private readonly AzureCosmosFactory _azureCosmos;
- private readonly AzureStorageFactory _azureStorage;
- private readonly IConfiguration _configuration;
- private readonly IWebHostEnvironment _webHostEnvironment;
- private readonly DingDing _dingDing;
- private readonly AzureRedisFactory _azureRedis;
- public LessonRecordController(ILogger<LessonRecordController> logger, AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage , IConfiguration configuration, IWebHostEnvironment environment,DingDing dingDing,AzureRedisFactory azureRedis )
- {
- _logger = logger;
- _azureCosmos = azureCosmos;
- _azureStorage = azureStorage;
- _configuration = configuration;
- _webHostEnvironment = environment;
- _dingDing = dingDing;
- _azureRedis = azureRedis;
- }
- [HttpPost("schools")]
- public async Task<IActionResult> Schools(JsonElement json)
- {
- List<string> ids = new List<string> { "cdscxx",
- "sdsyxq",
- "cdsxxx",
- "cdssz",
- "cdsshx",
- "ptszx",
- "cdwwsz",
- "csdswz",
- "cdfczx",
- "sdsy",
- "qyszgh",
- "sdsydq",
- "sslzxq",
- "cd37z",
- "cdqysz",
- "cd11z",
- "xhlxx",
- "cdpxjj",
- "xcfxqy",
- "csdswx",
- "thgjxx",
- "cdwwsx",
- "cdsjy",
- "cdsxwy",
- "cdsxzq",
- "cdsxmd",
- "cdsxcf",
- "cdsxqh",
- "cdsyxx",
- "cdsxx",
- "sxgkxx",
- "cdqbxx",
- "qyszfx",
- "cdpxxq",
- "cdpxlz",
- "cdpx",
- "cdkhxx",
- "cdhmxx",
- "cdjsxx",
- "cdhhxx",
- "cdhygj",
- "hygjqb",
- "cdglxx",
- "cddpxx",
- "cddcg",
- "cdctzm",
- "cdctxx",
- "cdchxx",
- "cdctxq",
- "sdsyqb",
- "sslzsx",
- "sslzjs",
- "cdjsxc",
- "cdjsxb",
- "yfsxwy",
- "sdyzhy",
- "yxmdfs",
- "cdcgxc",
- "cdcgxa" };
- foreach (string id in ids) {
- var res = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).GetList<Student>("select value c from c ", $"Base-{id}");
- if (res.list.IsNotEmpty())
- {
- var change= res.list.FindAll(x => x.graduate==1);
- if (change.IsNotEmpty())
- {
- foreach (var item in change)
- {
- item.graduate=0;
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).UpsertItemAsync(item, new PartitionKey(item.code));
- }
- }
-
- }
- }
- return Ok(new { });
- }
- [HttpPost("process-lesson")]
- public async Task<IActionResult> ProcessLesson(JsonElement json)
- {
- string scope = "";
- string tmdid = "";
- string lessonId;
- string school = null;
- string tbname = Constant.Teacher;
- string lcode = string.Empty;
- string blobname;
- var client = _azureCosmos.GetCosmosClient();
- scope = $"private";
- tmdid = $"6712127960";
- lessonId = $"648770551606808576";
- blobname = $"{tmdid}";
- lcode = $"LessonRecord";
- tbname = "Teacher";
- LessonRecord oldlessonRecord = null;
- LessonRecord lessonRecord = null;
- ResponseMessage response = await client.GetContainer(Constant.TEAMModelOS, tbname).ReadItemStreamAsync(lessonId, new PartitionKey(lcode));
- if (response.StatusCode == System.Net.HttpStatusCode.OK)
- {
- var doc = JsonDocument.Parse(response.Content);
- lessonRecord = doc.RootElement.ToObject<LessonRecord>();
- oldlessonRecord = doc.RootElement.ToObject<LessonRecord>();
- }
- else
- {
- lessonRecord = null;
- }
- //读取TimeLine.json
- List<int> PickupMemberIds = new List<int>();
- TimeLineData timeLineData = new TimeLineData();
- try
- {
- BlobDownloadResult timeLineBlobDownload = await _azureStorage.GetBlobContainerClient(blobname).GetBlobClient($"/records/{lessonId}/IES/TimeLine.json").DownloadContentAsync();
- timeLineData = timeLineBlobDownload.Content.ToObjectFromJson<TimeLineData>();
- lessonRecord.hitaClientCmpCount = timeLineData.events.Where(z => !string.IsNullOrWhiteSpace(z.WrkCmpSrcType) && z.WrkCmpSrcType.Equals("HitaClientCmp")).Count();
- //lessonRecord.collateTaskCount = lessonRecord.hitaClientCmpCount;
- List<TimeLineEvent> timeLineEvents = timeLineData.events.FindAll(z => !string.IsNullOrWhiteSpace(z.Event) && z.Event.Equals("PickupResult"));
- if (timeLineEvents.IsNotEmpty())
- {
- foreach (var timeLineEvent in timeLineEvents)
- {
- var memberIds = timeLineEvent.PickupMemberId.ToObject<List<int>>();
- PickupMemberIds.AddRange(memberIds);
- }
- }
- }
- catch (Exception ex)
- {
- if (!ex.Message.Contains("The specified blob does not exist"))
- {
- await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")},TimeLine.json转换异常,{ex.Message}{ex.StackTrace},{lessonRecord.id}", GroupNames.成都开发測試群組);
- }
- }
- //读取Task.json
- ///Event 过滤类型 : 'WrkSpaceLoad', 'WrkCmp' 文件:Task.json 根据clientWorks 中的seatID 匹配base.json 中的 student
- List<TaskData> taskDatas = new List<TaskData>();
- try
- {
- BlobDownloadResult taskBlobDownload = await _azureStorage.GetBlobContainerClient(blobname).GetBlobClient($"/records/{lessonId}/IES/Task.json").DownloadContentAsync();
- taskDatas = taskBlobDownload.Content.ToObjectFromJson<List<TaskData>>();
- }
- catch (Exception ex)
- {
- if (!ex.Message.Contains("The specified blob does not exist"))
- {
- await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")},Task.json转换异常,{ex.Message}{ex.StackTrace},{lessonRecord.id}", GroupNames.成都开发測試群組);
- }
- }
- //读取互评信息
- //Event 过滤类型 'RatingStart'
- //smartRateSummary.mutualSummary.mutualType 互评【All(每人多件评分) Two(随机分配互评) Self(自评)】 smartRateSummary.meteor_VoteSummary 投票
- //读取IRS.json
- List<SmartRatingData> smartRatingDatas = new List<SmartRatingData>();
- try
- {
- BlobDownloadResult smartRatingBlobDownload = await _azureStorage.GetBlobContainerClient(blobname).GetBlobClient($"/records/{lessonId}/IES/IRS.json").DownloadContentAsync();
- smartRatingDatas = smartRatingBlobDownload.Content.ToObjectFromJson<List<SmartRatingData>>();
- }
- catch (Exception ex)
- {
- if (!ex.Message.Contains("The specified blob does not exist"))
- {
- await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")},IRS.json转换异常,{ex.Message}{ex.StackTrace},{lessonRecord.id}", GroupNames.成都开发測試群組);
- }
- }
- //读取互动信息
- //Event 过滤类型 'PopQuesLoad', 'ReAtmpAnsStrt', 'BuzrAns','BuzrLoad'
- //TimeLine.json 中找到对应类型,根据Pgid 去 IRS.json 中找到对应数据,从clientAnswers 的下标对应 base.json 中的 student 找到对应学生信息 clientAnswers.length > 1 则表示有二次作答
- //读取IRS.json
- List<IRSData> irsDatas = new List<IRSData>();
- try
- {
- BlobDownloadResult irsBlobDownload = await _azureStorage.GetBlobContainerClient(blobname).GetBlobClient($"/records/{lessonId}/IES/IRS.json").DownloadContentAsync();
- irsDatas = irsBlobDownload.Content.ToObjectFromJson<List<IRSData>>();
- }
- catch (Exception ex)
- {
- if (!ex.Message.Contains("The specified blob does not exist"))
- {
- await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")},IRS.json转换异常,{ex.Message}{ex.StackTrace},{lessonRecord.id}", GroupNames.成都开发測試群組);
- }
- }
- //读取协作信息
- ///Event 过滤类型 'CoworkLoad'
- //TimeLine.json 中找到对应类型,根据Pgid 去 Cowork.json 中找到对应数据
- List<CoworkData> coworkDatas = new List<CoworkData>();
- try
- {
- BlobDownloadResult irsBlobDownload = await _azureStorage.GetBlobContainerClient(blobname).GetBlobClient($"/records/{lessonId}/IES/Cowork.json").DownloadContentAsync();
- coworkDatas = irsBlobDownload.Content.ToObjectFromJson<List<CoworkData>>();
- }
- catch (Exception ex)
- {
- if (!ex.Message.Contains("The specified blob does not exist"))
- {
- await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")},IRS.json转换异常,{ex.Message}{ex.StackTrace},{lessonRecord.id}", GroupNames.成都开发測試群組);
- }
- }
- //苏格拉底文件信息
- //Sokrates/SokratesRecords.json
- List<TimeLineEvent> sokratesDatas = new List<TimeLineEvent>();
- try
- {
- BlobDownloadResult irsBlobDownload = await _azureStorage.GetBlobContainerClient(blobname).GetBlobClient($"/records/{lessonId}/Sokrates/SokratesRecords.json").DownloadContentAsync();
- sokratesDatas = irsBlobDownload.Content.ToObjectFromJson<List<TimeLineEvent>>();
- }
- catch (Exception ex)
- {
- if (!ex.Message.Contains("The specified blob does not exist"))
- {
- await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")},IRS.json转换异常,{ex.Message}{ex.StackTrace},{lessonRecord.id}", GroupNames.成都开发測試群組);
- }
- }
- //读取base.json信息
- //如果有更新 则去读取/{lessonId}/IES/base.json
- List<LocalStudent> studentLessonDatas = new List<LocalStudent>();
- LessonBase lessonBase = null;
- try
- {
- // await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")},课堂id:{lessonId} 收到更新", GroupNames.醍摩豆服務運維群組);
- BlobDownloadResult baseblobDownload = await _azureStorage.GetBlobContainerClient(blobname).GetBlobClient($"/records/{lessonId}/IES/base.json").DownloadContentAsync();
- //attendState
- string basejson = baseblobDownload.Content.ToString().Replace("\"Uncall\"", "0").Replace("Uncall", "0");
- try
- {
- lessonBase = basejson.ToObject<LessonBase>();
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")},base.json转换异常,{ex.Message}{ex.StackTrace}{basejson},{lessonRecord.id}", GroupNames.成都开发測試群組);
- //lessonBase = baseblobDownload.Content.ToObjectFromJson<LessonBase>();
- }
- //await _dingDing.SendBotMsg($"课例记录文件base.json:{lessonBase.ToJsonString()}", GroupNames.成都开发測試群組);
- if (lessonBase != null && lessonBase.summary != null)
- {
- var baseData = LessonETLService.GetBaseData(lessonBase!);
- studentLessonDatas= baseData.studentLessonDatas;
- //lessonRecord.name = lessonBase.summary.activityName;
- lessonRecord.attendCount = lessonBase.summary.attendCount;
- lessonRecord.clientCount = lessonBase.summary.clientCount;
- lessonRecord.attendRate = lessonBase.summary.attendRate;
- lessonRecord.groupCount = lessonBase.summary.groupCount;
- lessonRecord.collateTaskCount = lessonBase.summary.collateTaskCount;
- lessonRecord.hitaClientCmpCount = lessonBase.summary.collateTaskCount + lessonRecord.hitaClientCmpCount;
- lessonRecord.collateCount = lessonBase.summary.collateCount;
- lessonRecord.pushCount = lessonBase.summary.pushCount;
- lessonRecord.totalPoint = lessonBase.summary.totalPoint;
- lessonRecord.examQuizCount = lessonBase.summary.examQuizCount;
- lessonRecord.interactionCount = lessonBase.summary.interactionCount;
- lessonRecord.examPointRate = lessonBase.summary.examPointRate;
- lessonRecord.clientInteractionCount = lessonBase.summary.clientInteractionCount;
- lessonRecord.clientInteractionAverge = lessonBase.summary.clientInteractionAverge;
- lessonRecord.examCount = lessonBase.summary.examCount;
- lessonRecord.totalInteractPoint = lessonBase.summary.totalInteractPoint;
- lessonRecord.learningCategory = lessonBase.summary.learningCategory;
- if (lessonRecord.learningCategory == null)
- {
- lessonRecord.learningCategory = new LearningCategory();
- }
- if (lessonRecord.hitaClientCmpCount > 0)
- {
- lessonRecord.learningCategory.cooperation = 1;
- }
- if (!string.IsNullOrWhiteSpace(lessonRecord.school))
- {
- lessonBase.student.ForEach(x =>
- {
- if (string.IsNullOrWhiteSpace(x.school))
- {
- x.school = lessonRecord.school;
- }
- });
- }
- //计算TP灯
- {
- int T = -1;
- int P = -1;
- if (lessonRecord.clientInteractionAverge <= 0)
- {
- T = 0;
- }
- else if (lessonRecord.clientInteractionAverge > 0 && lessonRecord.clientInteractionAverge < 2)
- // else if (lessonRecord.clientInteractionAverge >= 1 && lessonRecord.clientInteractionAverge <= 2)
- {
- T = 1;
- }
- else
- {
- T = 2;
- }
- //if (lessonRecord.examCount > 0)
- //{
- // //有评测次数大于0则P是直接绿灯
- // P = 2;
- //}
- //else {
- //}
- int a = lessonRecord.hitaClientCmpCount;
- int b = lessonRecord.pushCount;
- int c = lessonRecord.examCount;
- switch (true)
- {
- case bool when T == 0:
- P = 0;
- break;
- case bool when T == 1 || T == 2:
- if (a == 0 && b == 0 && c == 0)
- {
- P = 0;
- }
- else if ((a > 0 && b > 0) || (a > 0 && c > 0) || (b > 0 && c > 0))
- {
- P = 2;
- }
- else
- {
- P = 1;
- }
- break;
- }
- lessonRecord.tLevel = T;
- lessonRecord.pLevel = P;
- }
- //LessonStudentRecord lessonStudentRecord = new LessonStudentRecord
- //{
- // clientSummaryList = lessonBase.report.clientSummaryList,
- // students = lessonBase.student,
- // name = lessonRecord.name,
- // school = lessonRecord.school,
- // id = lessonRecord.id,
- // scope = lessonRecord.scope,
- // tmdid = lessonRecord.tmdid,
- // code = "LessonStudentRecord",
- // pk = "LessonStudentRecord",
- // courseId =lessonRecord.courseId,
- // groupIds= lessonRecord.groupIds,
- // periodId = lessonRecord.periodId,
- // subjectId = lessonRecord.subjectId,
- //};
- //await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS,Constant.Student).UpsertItemAsync<LessonStudentRecord>(lessonStudentRecord, new PartitionKey("LessonStudentRecord"));
- }
- //有上传 base.josn.
- lessonRecord.upload = 1;
- // await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")},课堂id:{lessonId} 更新完成", GroupNames.醍摩豆服務運維群組);
- //await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")},课堂id:{lessonId} blob刷新完成!", GroupNames.醍摩豆服務運維群組);
- List<ExamData> examDatas = new List<ExamData>();
- if (lessonBase!=null && lessonBase.student!=null)
- {
- string owner = lessonRecord.scope.Equals("school") ? lessonRecord.school : lessonRecord.tmdid;
- examDatas = await LessonETLService.GetExamInfo(lessonRecord, timeLineData, _azureStorage, owner);
- sokratesDatas= sokratesDatas.IsNotEmpty() ? sokratesDatas : timeLineData!=null ? timeLineData.events : new List<TimeLineEvent>();
- }
- LessonLocal lessonLocal = new LessonLocal()
- {
- lessonBase=lessonBase,
- timeLineData= timeLineData,
- lessonRecord= lessonRecord,
- taskDatas= taskDatas,
- smartRatingDatas= smartRatingDatas,
- irsDatas= irsDatas,
- coworkDatas= coworkDatas,
- examDatas=examDatas,
- sokratesDatas= sokratesDatas,
- studentLessonDatas=studentLessonDatas
- };
- try
- {
- if (lessonRecord.duration>0)
- {
- var location = "China";
- var studatas = LessonETLService.GenStudentLessonData(lessonLocal, Constant.objectiveTypes);
- string owner = lessonRecord.scope.Equals("school") ? lessonRecord.school : lessonRecord.tmdid;
- if (location.Equals("China", StringComparison.OrdinalIgnoreCase))
- {
- List<School> schools = new List<School>();
- List<StudentSemesterRecord> studentSemesterRecords = new List<StudentSemesterRecord>();
- List<OverallEducation> overallEducations = new List<OverallEducation>();
- List<Student> studentsBase = new List<Student>();
- List<StudentSemesterRecord> students = new List<StudentSemesterRecord>();
- LessonDataAnalysisModel lessonDataAnalysis = null;
- bool exists = await _azureStorage.GetBlobContainerClient("0-public").GetBlobClient($"/lesson/analysis/analysis-model.json").ExistsAsync();
- if (exists)
- {
- BlobDownloadResult blobDownload = await _azureStorage.GetBlobContainerClient("0-public").GetBlobClient($"/lesson/analysis/analysis-model.json").DownloadContentAsync();
- lessonDataAnalysis = blobDownload.Content.ToObjectFromJson<LessonDataAnalysisModel>();
- string studentSql = $"select value c from c where c.id in ({string.Join(",", lessonLocal.studentLessonDatas.Select(x => $"'{x.id}'"))})";
- var studentResults = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).GetList<Student>(studentSql, $"Base-{school}");
- if (studentResults.list.IsNotEmpty())
- {
- studentsBase.AddRange(studentResults.list);
- }
- School schoolBase = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<School>(school, new PartitionKey("Base"));
- schools.Add(schoolBase);
- string? periodId = !string.IsNullOrWhiteSpace(lessonLocal.lessonRecord.periodId) ? lessonLocal.lessonRecord.periodId : schoolBase.period.FirstOrDefault()?.id;
- var period = schoolBase.period.Find(x => x.id.Equals(periodId));
- var semester = SchoolService.GetSemester(period, lessonLocal.lessonRecord.startTime);
- string code = $"StudentSemesterRecord-{schoolBase.id}";
- string studentSemesterRecordSql = $"select value c from c where c.stuid in ({string.Join(",", lessonLocal.studentLessonDatas.Select(x => $"'{x.id}'"))}) and c.semesterId='{semester.currSemester.id}' and c.studyYear={semester.studyYear}";
- var studentSemesterRecordResults = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).GetList<StudentSemesterRecord>(studentSemesterRecordSql, code);
- if (studentSemesterRecordResults.list.IsNotEmpty())
- {
- studentSemesterRecords.AddRange(studentSemesterRecordResults.list);
- }
- string overallEducationSql = $"select value c from c where c.studentId in ({string.Join(",", lessonLocal.studentLessonDatas.Select(x => $"'{x.id}'"))}) and c.semesterId='{semester.currSemester.id}' and c.year={semester.studyYear}";
- var overallEducationResults = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).GetList<OverallEducation>(overallEducationSql, $"OverallEducation-{schoolBase.id}");
- if (overallEducationResults.list.IsNotEmpty())
- {
- overallEducations.AddRange(overallEducationResults.list);
- }
- var studata = LessonETLService.DoStudentLessonDataV2(Constant.objectiveTypes, lessonLocal, location, studentSemesterRecords, overallEducations, lessonDataAnalysis, studentsBase, schools);
- await Parallel.ForEachAsync(studentSemesterRecords, async (studentSemester, cancellationToken) =>
- {
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).UpsertItemAsync(studentSemester, new PartitionKey(studentSemester.code));
- });
- await Parallel.ForEachAsync(overallEducations, async (overallEducation, cancellationToken) =>
- {
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).UpsertItemAsync(overallEducation, partitionKey: new PartitionKey(overallEducation.code));
- string key = $"OverallEducation:{overallEducation.schoolCode}:{overallEducation.periodId}:{overallEducation.year}:{overallEducation.semesterId}:{overallEducation?.classId}";
- await _azureRedis.GetRedisClient(8).HashSetAsync(key, overallEducation.studentId, overallEducation.ToJsonString());
- await _azureRedis.GetRedisClient(8).KeyExpireAsync(key, new TimeSpan(180 *24, 0, 0));
- });
- await _azureStorage.GetBlobContainerClient(owner).UploadFileByContainer(studata.studentLessonDatas.ToJsonString(), "records", $"{lessonRecord.id}/student-analysis.json");
- XmlDocument xmlDocument = new XmlDocument();
- var runtimePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
- xmlDocument.Load($"{runtimePath}\\summary.xml");
- PropertyInfo[] properties = typeof(StudentLessonItem).GetProperties();
- List<string> summaryes = new List<string>();
- for (int i = 0; i < properties.Length; i++)
- {
- string summary = Regex.Replace(LessonETLService.GetPropertySummary(properties[i], xmlDocument), @"\s+", "");
- summaryes.Add(summary);
- }
- await LessonETLService.ExportToExcelAzureBlob(studata.lessonItems, _azureStorage, owner, $"{lessonRecord.id}/student-analysis.xlsx", xmlDocument, summaryes, properties);
- }
- }
- else
- {
- await _azureStorage.GetBlobContainerClient(owner).UploadFileByContainer(studatas.studentLessonDatas.ToJsonString(), "records", $"{lessonRecord.id}/student-analysis.json");
- }
- // 使用当前文化设置的日历
- CultureInfo cultureInfo = CultureInfo.CurrentCulture;
- Calendar calendar = cultureInfo.Calendar;
- //表示如果一年的第一个星期至少有4天在同一年,则该星期被视为第一周,DayOfWeek.Monday和DayOfWeek.Sunday分别表示一周的第一天是星期一或星期日。
- var week = calendar.GetWeekOfYear(DateTime.Now, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
- string key = $"LessonWeekly:{lessonRecord.scope}:{DateTime.Now.Year}-{week}";
- _azureRedis.GetRedisClient(8).HashSet(key, $"{lessonRecord.tmdid}:{lessonRecord.id}",
- new LessonWeek
- {
- week=week,
- id = lessonRecord.id,
- cid=lessonRecord.courseId,
- sid= lessonRecord.subjectId,
- school=lessonRecord.school,
- gid= lessonRecord.groupIds?.FirstOrDefault(),
- //pid= lessonRecord.periodId,
- scope= lessonRecord.scope,
- }.ToJsonString()
- );
- await _azureRedis.GetRedisClient(8).KeyExpireAsync(key, TimeSpan.FromDays(10));
- }
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}处理学生课中数据发生异常,{lessonId}\n{ex.Message}\n{ex.StackTrace}\n\n{lessonRecord.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
- }
-
- }
- catch (Exception ex) { }
- return Ok();
- }
- [HttpPost("process-local")]
- public async Task<IActionResult> ProcessLocal(JsonElement json)
- {
- List<StudentLessonData> studentLessonDatas = new List<StudentLessonData>();
- string? id = json.GetProperty("id").GetString();
- if (!string.IsNullOrWhiteSpace(id))
- {
- string? lessonPath = _configuration.GetValue<string>("LessonPath");
- string? path = $"{lessonPath}\\locals\\{id}";
- var files = FileHelper.ListAllFiles(path);
- // var sampleJson =System.IO. File.ReadAllTextAsync(path);
- LessonBase? lessonBase = null;
- List<LocalStudent> localStudents = new List<LocalStudent>();
- List<TaskData> taskDatas = new List<TaskData>();
- List<SmartRatingData> smartRatingDatas = new List<SmartRatingData>();
- List<IRSData> irsDatas = new List<IRSData>();
- List<CoworkData> coworkDatas = new List<CoworkData>();
- List<ExamData> examDatas = new List<ExamData>();
- TimeLineData? timeLineData = null;
- foreach (var item in files)
- {
- if (item.Contains("IES\\base.json"))
- {
- string jsons = await System.IO.File.ReadAllTextAsync(item);
- jsons = jsons.Replace("\"Uncall\"", "0").Replace("Uncall", "0");
- lessonBase = jsons.ToObject<LessonBase>();
- var data = LessonETLService.GetBaseData(lessonBase);
- localStudents = data.studentLessonDatas;
- }
- if (item.Contains("IES\\TimeLine.json"))
- {
- string jsons = await System.IO.File.ReadAllTextAsync(item);
- timeLineData = jsons.ToObject<TimeLineData>();
- }
- if (item.Contains("IES\\Task.json"))
- {
- string jsons = await System.IO.File.ReadAllTextAsync(item);
- taskDatas = jsons.ToObject<List<TaskData>>();
- }
- if (item.Contains("IES\\SmartRating.json"))
- {
- string jsons = await System.IO.File.ReadAllTextAsync(item);
- smartRatingDatas = jsons.ToObject<List<SmartRatingData>>();
- }
- if (item.Contains("IES\\IRS.json"))
- {
- string jsons = await System.IO.File.ReadAllTextAsync(item);
- irsDatas = jsons.ToObject<List<IRSData>>();
- }
- if (item.Contains("IES\\Cowork.json"))
- {
- string jsons = await System.IO.File.ReadAllTextAsync(item);
- coworkDatas = jsons.ToObject<List<CoworkData>>();
- }
- try
- {
- if (item.Contains($"\\{id}\\Exam\\") && item.EndsWith("Exam.json"))
- {
- string examsFile = item;
- if (examsFile.EndsWith("Exam.json"))
- {
- ExamData? examData = null;
- string jsons = await System.IO.File.ReadAllTextAsync(item);
- jsons = jsons.Replace("\"publish\": \"0\"", "\"publish\": 0").Replace("\"publish\": \"1\"", "\"publish\": 1");
- examData = jsons.ToObject<ExamData>();
- if (examData != null && examData.exam.papers.IsNotEmpty())
- {
- string paperId = examData.exam.papers.First().id;
- string paperPath = $"{path}\\ExamPaper\\{paperId}\\index.json";
- string jsonp = await System.IO.File.ReadAllTextAsync(paperPath);
- LessonPaper lessonPaper = jsonp.ToObject<LessonPaper>();
- examData.paper = lessonPaper;
- examDatas.Add(examData);
- }
- }
- }
- }
- catch (Exception ex)
- {
- _logger.LogError(ex, ex.Message);
- }
- }
- if (lessonBase!=null && timeLineData!=null)
- {
- studentLessonDatas = localStudents.ToJsonString().ToObject<List<StudentLessonData>>();
- studentLessonDatas = LessonETLService.GetBaseInfo(lessonBase!, studentLessonDatas, id);
- studentLessonDatas = LessonETLService.GetIRSData(lessonBase, timeLineData, irsDatas, studentLessonDatas, examDatas, id);
- studentLessonDatas = LessonETLService.GetCoworkData(lessonBase, timeLineData, coworkDatas, studentLessonDatas, id);
- studentLessonDatas = LessonETLService.GetExamData(lessonBase, timeLineData, examDatas, studentLessonDatas, Constant.objectiveTypes, id);
- studentLessonDatas = LessonETLService.GetSmartRatingData(lessonBase, timeLineData, smartRatingDatas, studentLessonDatas, id);
- studentLessonDatas = LessonETLService.GetTaskData(lessonBase, timeLineData, taskDatas, studentLessonDatas, id);
- var pickupData = LessonETLService.GetPickupData(lessonBase, timeLineData, studentLessonDatas, id);
- studentLessonDatas= pickupData.studentLessonDatas;
- var codeBools= LessonETLService.GetCodeBools(studentLessonDatas);
- await System.IO.File.WriteAllTextAsync(Path.Combine(path, $"student-analysis.json"), studentLessonDatas.ToJsonString());
- string jsons = await System.IO.File.ReadAllTextAsync($"{lessonPath}\\analysis\\analysis-model.json");
- LessonDataAnalysisModel lessonDataAnalysis = jsons.ToObject<LessonDataAnalysisModel>();
-
- var studentLessons = LessonETLService.ProcessStudentDataV2(studentLessonDatas, lessonDataAnalysis,codeBools);
- XmlDocument xmlDocument = new XmlDocument();
- var runtimePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
- xmlDocument.Load($"{runtimePath}\\summary.xml");
- await LessonETLService.ExportToExcelLocal(studentLessons, $"{path}\\analysis.xlsx", xmlDocument);
- }
- }
- return Ok();
- }
-
- /// <summary>
- ///
- /// </summary>
- /// <param name="json"></param>
- /// <returns></returns>
- [HttpPost("process-history-students")]
- public async Task<IActionResult> ProcessHistoryStudents(JsonElement json)
- {
- string? lessonBasePath = _configuration.GetValue<string>("LessonPath");
- string? pathLessons = $"{lessonBasePath}\\lessons";
- string? pathAnalysis = $"{lessonBasePath}\\analysis";
- string jsons = await System.IO.File.ReadAllTextAsync($"{pathAnalysis}\\analysis-model.json");
- LessonDataAnalysisModel lessonDataAnalysis = jsons.ToObject<LessonDataAnalysisModel>();
- List<string> filesLessons = FileHelper.ListAllFiles(pathLessons, "-local.json");
- List<string> filesStudata = FileHelper.ListAllFiles(pathLessons, "-sdata.json");
- var runtimePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
- XmlDocument xmlDocument = new XmlDocument();
- xmlDocument.Load($"{runtimePath}\\summary.xml");
- List<School> schools = new List<School>();
- // await Parallel.ForEachAsync(filesLessons, async (fileLesson, _) =>
- List<string> localIds = new List<string>();
- foreach (var file in filesLessons)
- {
- string lessonId = file.Split("\\").Last().Replace("-local.json", "");
- localIds.Add(lessonId);
- }
- List<LessonLocal> lessonLocals = new List<LessonLocal>();
-
- List<LessonRecord> lessonRecords = new List<LessonRecord>();
- string recordsPtah = $"{lessonBasePath}\\records\\records.json";
- long stime = 0;//2023-09-01 00:00:00
- long etime = 0;//2024-11-13 23:59:59
- //if (System.IO.File.Exists(recordsPtah))
- //{
- // string jsonData = await System.IO.File.ReadAllTextAsync(recordsPtah);
- // lessonRecords= jsonData.ToObject<List<LessonRecord>>();
- // stime= lessonRecords.Max(x => x.startTime);
- // etime= lessonRecords.Max(x => x.startTime);
- //}
- if (stime==0)
- {
- stime = 1693497600000;//2023-09-01 00:00:00
- }
- if (etime==0)
- {
- etime = 1731513599000;//2024-11-13 23:59:59
- }
- List<LessonLocal> locals= await LessonETLService.FixLocalData(localIds, _azureCosmos, _azureStorage, pathLessons, stime, etime);
- if (locals.IsNotEmpty())
- {
- lessonLocals.AddRange(locals);
- }
- int u = 0;
- Parallel.ForEach(filesLessons, file =>
- {
- string jsonp = System.IO.File.ReadAllText(file);
- var lessonLocal = jsonp.ToObject<LessonLocal>();
- if (lessonLocal.lessonBase!=null && lessonLocal.lessonBase.student.IsNotEmpty())
- {
- lessonLocals.Add(lessonLocal);
- }
- else
- {
- System.IO.File.Delete(file);
- System.IO.File.Delete(file.Replace("-local.json", "-count.json"));
- u++;
- }
- });
- List<string> ignore = new List<string>() { "PgJump", "PgRcv", "PgAdd" };
- if (lessonLocals.IsNotEmpty())
- {
- lessonRecords=lessonLocals.Where(x => x.lessonRecord.scope.Equals("school")).Select(x =>x.lessonRecord).ToList();
- }
- if (lessonRecords.IsNotEmpty())
- {
- await System.IO.File.WriteAllTextAsync(recordsPtah, lessonRecords.ToJsonString());
- List<StudentSemesterRecord> studentSemesterRecords= new List<StudentSemesterRecord>();
- List<OverallEducation> overallEducations= new List<OverallEducation>();
- List<Student> studentsBase = new List<Student>();
- string schoolPtah = $"{lessonBasePath}\\schools\\school.json";
- if (System.IO.File.Exists(schoolPtah))
- {
- string jsonData = await System.IO.File.ReadAllTextAsync(schoolPtah);
- schools= jsonData.ToObject<List<School>>();
- }
- var schoolGroup = lessonLocals.Where(x => !string.IsNullOrWhiteSpace(x.lessonRecord?.school)).GroupBy(x => x.lessonRecord?.school).Select(x => new { key = x.Key, list = x.ToList() });
- var newschoolIds = schoolGroup.Select(x=>x.key).ExceptBy(schools.Select(x => x.id), x => x);
- if (newschoolIds!=null && newschoolIds.Count()>0)
- {
- string schoolSql = $"select value c from c where c.id in ({string.Join(",", schoolGroup.Select(x => $"'{x.key}'"))})";
- var schoolResults = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetList<School>(schoolSql, "Base");
- if (schoolResults.list.IsNotEmpty())
- {
- schools.AddRange(schoolResults.list);
- }
- }
- await System.IO.File.WriteAllTextAsync($"{lessonBasePath}\\schools\\school.json", schools.ToJsonString());
- foreach (var group in schoolGroup)
- {
- string students_path = $"{lessonBasePath}\\students\\{group.key}\\students.json";
- string records_path = $"{lessonBasePath}\\students\\{group.key}\\records.json";
- string overall_path = $"{lessonBasePath}\\students\\{group.key}\\overall.json";
- if (!Directory.Exists($"{lessonBasePath}\\students\\{group.key}"))
- {
- Directory.CreateDirectory($"{lessonBasePath}\\students\\{group.key}");
- }
- var studentIds = group.list.SelectMany(x => x.studentLessonDatas).Where(x=>!string.IsNullOrWhiteSpace(x.id)).Select(x => x.id).Distinct();
- List<Student> schoolStudent = new List<Student>();
- if (System.IO.File.Exists(students_path))
- {
- string jsonData = await System.IO.File.ReadAllTextAsync(students_path);
- schoolStudent= jsonData.ToObject<List<Student>>();
- studentsBase.AddRange(schoolStudent);
- }
- var newIds= studentIds.ExceptBy(schoolStudent.Where(x=>x.schoolId.Equals(group.key)).Select(x=>x.id),x=>x);
- if (newIds!=null && newIds.Count()>0)
- {
- string studentSql = $"select value c from c where c.id in ({string.Join(",", newIds.Select(x => $"'{x}'"))})";
- var studentResults = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).GetList<Student>(studentSql, $"Base-{group.key}");
- if (studentResults.list.IsNotEmpty())
- {
- schoolStudent.AddRange(studentResults.list);
- studentsBase.AddRange(studentResults.list);
- }
- }
- await System.IO.File.WriteAllTextAsync(students_path, schoolStudent.ToJsonString());
- List<StudentSemesterRecord> schoolStudentSemesterRecords=new List<StudentSemesterRecord>();
- if (System.IO.File.Exists(records_path))
- {
- string jsonData = await System.IO.File.ReadAllTextAsync(records_path);
- schoolStudentSemesterRecords= jsonData.ToObject<List<StudentSemesterRecord>>();
- studentSemesterRecords.AddRange(schoolStudentSemesterRecords);
- }
- var newstuIds = studentIds.ExceptBy(studentSemesterRecords.Where(x => x.school.Equals(group.key)).Select(x => x.stuid), x => x);
- if (newstuIds!=null && newstuIds.Count()>0)
- {
- string studentSemesterRecordSql = $"select value c from c where c.stuid in ({string.Join(",", newstuIds.Distinct().Select(x => $"'{x}'"))}) and c.studyYear>=2023";
- var studentSemesterRecordResults = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).GetList<StudentSemesterRecord>(studentSemesterRecordSql, $"StudentSemesterRecord-{group.key}");
- if (studentSemesterRecordResults.list.IsNotEmpty())
- {
- schoolStudentSemesterRecords.AddRange(studentSemesterRecordResults.list);
- studentSemesterRecords.AddRange(studentSemesterRecordResults.list);
- }
- }
-
- await System.IO.File.WriteAllTextAsync(records_path, schoolStudentSemesterRecords.ToJsonString());
- List<OverallEducation> schoolOverallEducations = new List<OverallEducation>();
- if (System.IO.File.Exists(overall_path))
- {
- string jsonData = await System.IO.File.ReadAllTextAsync(overall_path);
- schoolOverallEducations= jsonData.ToObject<List<OverallEducation>>();
- overallEducations.AddRange(schoolOverallEducations);
- }
- var newstuoIds = studentIds.ExceptBy(schoolOverallEducations.Where(x => x.schoolCode.Equals(group.key)).Select(x => x.studentId), x => x);
- if (newstuIds!=null && newstuIds.Count()>0)
- {
- string overallEducationSql = $"select value c from c where c.studentId in ({string.Join(",", newstuoIds.Select(x => $"'{x}'"))}) and c.year>=2023";
- var overallEducationResults = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).GetList<OverallEducation>(overallEducationSql, $"OverallEducation-{group.key}");
- if (overallEducationResults.list.IsNotEmpty())
- {
- schoolOverallEducations.AddRange(overallEducationResults.list);
- overallEducations.AddRange(overallEducationResults.list);
- }
- }
- await System.IO.File.WriteAllTextAsync(overall_path, schoolOverallEducations.ToJsonString());
- }
-
- //List<(string id,string owner, List<StudentLessonData> studentLessonData)> studentLessonDatas= new List<(string id, string owner, List<StudentLessonData>)>();
- ConcurrentQueue<LessonStudentResult> lessonItems = new ConcurrentQueue<LessonStudentResult>();
- int v = 0;
- Parallel.ForEach(filesStudata, file =>
- {
- string jsonp = System.IO.File.ReadAllText(file);
- var studentResult = jsonp.ToObject<LessonStudentResult>();
- lessonItems.Enqueue(studentResult);
- v++;
- });
- int n = 0;
- lessonLocals= lessonLocals.ExceptBy(lessonItems.Select(x => x.id), y => y.lessonRecord.id).ToList();
- Parallel.ForEach(lessonLocals, (item, con) =>
- {
- try
- {
- var studata = LessonETLService.DoStudentLessonDataV2(Constant.objectiveTypes, item, "China", studentSemesterRecords, overallEducations, lessonDataAnalysis, studentsBase, schools);
- if (studata.codeBools.FindAll(x => x.value).IsNotEmpty())
- {
- string owner = item.lessonRecord.scope.Equals("school") ? item.lessonRecord.school : item.lessonRecord.tmdid;
- //studentLessonDatas.Add((item.lessonRecord.id, owner, studata.studentLessonDatas));
- LessonStudentResult result = new LessonStudentResult { id= item.lessonRecord.id, owner= owner, studentLessons= studata.lessonItems, codeBools= studata.codeBools, lessonDatas= studata.studentLessonDatas };
- string yearMonthPath = DateTimeOffset.FromUnixTimeMilliseconds(item.lessonRecord.startTime).ToString("yyyyMM");
- System.IO.File.WriteAllText($"{pathLessons}\\MM{yearMonthPath}\\{item.lessonRecord!.id}-sdata.json", item.ToJsonString());
- lessonItems.Enqueue(result);
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine($"{ex.Message},{ex.StackTrace}");
- throw new Exception(ex.Message, ex);
- }
- n++;
- });
- foreach (var group in schoolGroup)
- {
- string students_path = $"{lessonBasePath}\\students\\{group.key}\\students.json";
- string records_path = $"{lessonBasePath}\\students\\{group.key}\\records.json";
- string overall_path = $"{lessonBasePath}\\students\\{group.key}\\overall.json";
- if (!Directory.Exists($"{lessonBasePath}\\students\\{group.key}"))
- {
- Directory.CreateDirectory($"{lessonBasePath}\\students\\{group.key}");
- }
- var schoolStudent = studentsBase.FindAll(x => x.schoolId.Equals(group.key));
- var schoolStudentSemesterRecords= studentSemesterRecords.FindAll(x => x.school.Equals(group.key));
- var schoolOverallEducations = overallEducations.FindAll(x => x.schoolCode.Equals(group.key));
- await System.IO.File.WriteAllTextAsync(students_path, schoolStudent.ToJsonString());
- await System.IO.File.WriteAllTextAsync(records_path, schoolStudentSemesterRecords.ToJsonString());
- await System.IO.File.WriteAllTextAsync(overall_path, schoolOverallEducations.ToJsonString());
- }
- int m = 0;
- var grpdata = studentSemesterRecords.GroupBy(x => x.code).Select(x => new { key = x.Key, list = x.ToList() });
- foreach (var group in grpdata)
- {
- var pages = group.list.Page(100);
-
- foreach (var page in pages)
- {
- List<Task<ItemResponse<StudentSemesterRecord>>> list = new();
- foreach (var studentSemester in page)
- {
- list.Add(_azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).UpsertItemAsync(studentSemester, new PartitionKey(studentSemester.code))) ;
- m++;
- }
- await Task.WhenAll(list);
- }
- }
- int k = 0;
- var gpover = overallEducations.GroupBy(x => x.code).Select(x => new { key = x.Key, list = x.ToList() });
- foreach (var item in gpover)
- {
- var pages = item.list.Page(100);
- foreach (var page in pages)
- {
- List<Task<ItemResponse<OverallEducation>>> list = new();
- foreach (var overallEducation in page)
- {
- list.Add(_azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).UpsertItemAsync(overallEducation, partitionKey: new PartitionKey(overallEducation.code)));
-
- //string key = $"OverallEducation:{overallEducation.schoolCode}:{overallEducation.periodId}:{overallEducation.year}:{overallEducation.semesterId}:{overallEducation?.classId}";
- //await _azureRedis.GetRedisClient(8).HashSetAsync(key, overallEducation.studentId, overallEducation.ToJsonString());
- //await _azureRedis.GetRedisClient(8).KeyExpireAsync(key, new TimeSpan(180 *24, 0, 0));
-
- }
- await Task.WhenAll(list);
- }
- }
- int p = 0;
- // 获取类的属性
- PropertyInfo[] properties = typeof(StudentLessonItem).GetProperties();
- List<string> summaryes= new List<string>();
- for (int i = 0; i < properties.Length; i++)
- {
- string summary = Regex.Replace(LessonETLService.GetPropertySummary(properties[i], xmlDocument), @"\s+", "");
- summaryes.Add(summary);
- }
- await Parallel.ForEachAsync(lessonItems, async (lessonItem, _) => {
- await _azureStorage.GetBlobContainerClient(lessonItem.owner).UploadFileByContainer(lessonItem.lessonDatas.ToJsonString(), "records", $"{lessonItem.id}/student-analysis.json");
- await LessonETLService.ExportToExcelAzureBlob(lessonItem.studentLessons, _azureStorage, lessonItem.owner, $"{lessonItem.id}/student-analysis.xlsx", xmlDocument, summaryes, properties);
- p++;
- });
- return Ok(new { p, m, k,n,u});
- }
- return Ok(new {});
- }
-
- /// <summary>
- /// 课例数据ETL处理过程
- /// </summary>
- /// <param name="json"></param>
- /// <returns></returns>
- [HttpPost("process-history")]
- public async Task<IActionResult> ProcessHistory(JsonElement json)
- {
- Stopwatch stopwatch= new Stopwatch();
- List<string> localIds = new List<string>();
- string? lessonBasePath = _configuration.GetValue<string>("LessonPath");
- string? pathLessons = $"{lessonBasePath}\\lessons";
- string? pathAnalysis = $"{lessonBasePath}\\analysis";
- var filesLessons = FileHelper.ListAllFiles(pathLessons);
- foreach (var file in filesLessons)
- {
- if (file.EndsWith("-local.json"))
- {
- string lessonId = file.Split("\\").Last().Replace("-local.json", "");
- localIds.Add(lessonId);
- }
- }
- bool loadLocal = true;
- var filesAnalysis = FileHelper.ListAllFiles(pathAnalysis);
- long stime = 1693497600000;//2023-09-01 00:00:00
- bool force = false;
- if ((json.TryGetProperty("force", out JsonElement _force)&& _force.ValueKind.Equals(JsonValueKind.True)))
- {
- force= _force.GetBoolean();
- }
- if (force)
- {
- List<LessonDataAnalysisMonth> lessonDataAnalysisMonths = new List<LessonDataAnalysisMonth>();
- foreach (var file in filesAnalysis)
- {
- //读取每月的数据
- if (file.EndsWith("-m-analysis.json"))
- {
- string jsons = await System.IO.File.ReadAllTextAsync(file);
- LessonDataAnalysisMonth lessonDataAnalysis = jsons.ToObject<LessonDataAnalysisMonth>();
- lessonDataAnalysisMonths.Add(lessonDataAnalysis);
- }
- }
- if (lessonDataAnalysisMonths.IsNotEmpty())
- {
- var maxUpdateTime = lessonDataAnalysisMonths.Max(x => x.updateTime);
- if (maxUpdateTime>0)
- {
- //更新周期是一周
- if (DateTimeOffset.Now.ToUnixTimeMilliseconds()- maxUpdateTime>604800000)
- {
- stime=maxUpdateTime;
- loadLocal =true;
- }
- else
- {
- stime=maxUpdateTime;
- loadLocal=false;
- }
- }
- }
- }
-
- // if (loadLocal ||force)
- {
-
- List<string> ignore = new List<string>() { "PgJump", "PgRcv", "PgAdd" };
- await LessonETLService.FixLocalData(localIds, _azureCosmos, _azureStorage, pathLessons, stime, DateTimeOffset.Now.ToUnixTimeMilliseconds());
- List<TechCount> techCounts = new List<TechCount>();
- filesLessons = FileHelper.ListAllFiles(pathLessons, "-local.json");
-
- List<LessonLocal> lessonLocals = new List<LessonLocal>();
- int u = 0;
- if (force)
- {
- stopwatch.Start();
- Parallel.ForEach(filesLessons, file =>
- {
- string jsonp = System.IO.File.ReadAllText(file);
- var lessonLocal = jsonp.ToObject<LessonLocal>();
- if (lessonLocal.lessonBase!=null && lessonLocal.lessonBase.student.IsNotEmpty())
- {
- lessonLocals.Add(lessonLocal);
- }
- else
- {
- System.IO.File.Delete(file);
- System.IO.File.Delete(file.Replace("-local.json", "-count.json"));
- u++;
- }
- });
- stopwatch.Stop();
- }
- _logger.LogInformation($"Loaded {lessonLocals.Count} lessons in {stopwatch.Elapsed.TotalSeconds} seconds");
- int index = 0;
- await Parallel.ForEachAsync(filesLessons, async (item, _) => {
- TechCount techCount= await LessonETLService.GetTeachCount(_azureCosmos, item, pathLessons, ignore, Constant.objectiveTypes, _azureStorage, force, lessonLocals);
- if (techCount != null) {
- techCounts.Add(techCount);
- }
- index++;
- });
- long newest = lessonLocals.Max(x=>x.lessonRecord.startTime);
- await LessonETLService.GenAnalysisData(pathAnalysis, newest, techCounts,_azureStorage);
- }
- return Ok(new { });
- }
- }
- }
|