CrazyIter_Bin 7 months ago
parent
commit
0b6a81e25c

+ 57 - 9
HTEX.DataETL/Controllers/LessonRecordController.cs

@@ -156,6 +156,29 @@ namespace HTEX.DataETL.Controllers
             return Ok();
         }
 
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="json"></param>
+        /// <returns></returns>
+        [HttpPost("process-fix-history-students")]
+        public async Task<IActionResult> ProcessFixHistoryStudents(JsonElement json)
+        {
+            string? lessonBasePath = _configuration.GetValue<string>("LessonPath");
+            string studentsPath = $"{lessonBasePath}\\students";
+            List<string> studentsPs = FileHelper.ListAllFiles(studentsPath);
+            string? pathLessons = $"{lessonBasePath}\\lessons";
+            List<string> filesLessons = FileHelper.ListAllFiles(pathLessons, "-local.json");
+            int index = 0;
+            foreach (var stu in studentsPs)
+            {
+                string stujson = await System.IO.File.ReadAllTextAsync(stu);
+                var studentSemester = stujson.ToObject<StudentSemesterRecord>();
+                await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).UpsertItemAsync(studentSemester,new PartitionKey(studentSemester.code));
+                index++;
+            }
+            return Ok();
+        }
         /// <summary>
         /// 
         /// </summary>
@@ -222,17 +245,23 @@ namespace HTEX.DataETL.Controllers
                                          studyYear=semester.studyYear,
                                          semesterId=semester.currSemester.id,
                                          period= period?.id,
-                                         
+                                         pk="StudentSemesterRecord"
                                      };
+                                     students.Add(studentSemester);
                                  }
                                  string lessonId = string.Empty;
-                                 if (studentLessonData.cooperation>0 &&studentLessonData.achieve>0&&studentLessonData.attitude>0 && studentLessonData.cowork>0 &&  studentLessonData.appraise>0)
+                                 StuLesson lesson = new StuLesson()
+                                 {
+                                     id= lessonLocal.lessonRecord.id,
+                                     time= lessonLocal.lessonRecord.startTime,
+                                     attend=0
+                                 };
+                                 if (studentLessonData.cooperation>0 || studentLessonData.achieve>0|| studentLessonData.attitude>0 || studentLessonData.cowork>0 ||  studentLessonData.appraise>0)
                                  {
-                                     lessonId=$"1--{lessonLocal.lessonRecord.id}";
+                                     lesson.attend=1;
+
                                      studentSemester.lessons.Add(new StuLessonLite
                                      {
-                                         id= lessonLocal.lessonRecord.id,
-                                         time= lessonLocal.lessonRecord.startTime,
                                          tmdid=lessonLocal.lessonRecord.tmdid,
                                          sid= lessonLocal.lessonRecord.subjectId,
                                          cid= lessonLocal.lessonRecord.courseId,
@@ -244,18 +273,37 @@ namespace HTEX.DataETL.Controllers
                                      });
                                  }
                                  else {
-                                     lessonId=$"0--{lessonLocal.lessonRecord.id}";
+                                     if (studentLessonData.attend==1)
+                                     {
+                                         lesson.attend=1;
+                                     }
+                                     else {
+                                         lesson.attend=0;
+                                     }
                                  }
-                                 studentSemester.lessonIds.Add(lessonId);
+                                 studentSemester.les.Add(lesson);
+                                // studentSemester.lessonIds.Add(lessonId);
                              }
                          }
-                         await LessonETLService.ExportToExcelAzureBlob(lessonItems, _azureStorage, owner, $"{lessonLocal.lessonRecord.id}/student-analysis.xlsx", xmlDocument);
-                         await _azureStorage.GetBlobContainerClient(owner).UploadFileByContainer(studentLessonDatas.ToJsonString(), "records", $"{lessonLocal.lessonRecord.id}/student-analysis.json");
+                        // await LessonETLService.ExportToExcelAzureBlob(lessonItems, _azureStorage, owner, $"{lessonLocal.lessonRecord.id}/student-analysis.xlsx", xmlDocument);
+                        // await _azureStorage.GetBlobContainerClient(owner).UploadFileByContainer(studentLessonDatas.ToJsonString(), "records", $"{lessonLocal.lessonRecord.id}/student-analysis.json");
                     } catch (Exception ex)
                     {
                         throw new Exception($"{fileLesson}", ex);
                     }
                  });
+            string studentsPath = $"{lessonBasePath}\\students";
+            foreach (var stu in students) 
+            {
+                string path = $"{studentsPath}\\{stu.school}\\{stu.studyYear}\\{stu.semesterId}";
+                if (!Directory.Exists(path)) 
+                {
+                    Directory.CreateDirectory(path);
+                }
+                await System.IO.File.WriteAllTextAsync($"{path}\\{stu.stuid}.json", stu.ToJsonString());
+            }
+            string schoolsPath = $"{lessonBasePath}\\schools";
+            await System.IO.File.WriteAllTextAsync($"{schoolsPath}\\school.json", schools.ToJsonString());
             return Ok();
         }
 

+ 119 - 10
TEAMModelOS.Extension/HTEX.Lib/ETL/Lesson/LessonETLService.cs

@@ -1,8 +1,11 @@
 using Azure;
 using Azure.Storage.Blobs.Models;
+using DocumentFormat.OpenXml.Drawing.Charts;
 using DocumentFormat.OpenXml.Office2010.Excel;
 using DocumentFormat.OpenXml.Office2013.Drawing.ChartStyle;
+using DocumentFormat.OpenXml.Office2016.Drawing.ChartDrawing;
 using MathNet.Numerics;
+using MathNet.Numerics.Distributions;
 using Microsoft.Azure.Cosmos;
 using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.Logging;
@@ -14,6 +17,7 @@ using System.IO;
 using System.Linq;
 using System.Reflection;
 using System.Text;
+using System.Text.Json;
 using System.Text.RegularExpressions;
 using System.Threading.Tasks;
 using System.Xml;
@@ -21,6 +25,7 @@ using TEAMModelOS.SDK;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models;
+using TEAMModelOS.SDK.Models.Cosmos.Common;
 using TEAMModelOS.SDK.Models.Cosmos.OpenEntity;
 
 namespace HTEX.Lib.ETL.Lesson
@@ -28,12 +33,7 @@ namespace HTEX.Lib.ETL.Lesson
     public class LessonETLService
     {
 
-        public static async void DoLessonStudentRecordV2(DingDing _dingding, SnowflakeId snowflakeId, LessonRecord lessonRecord, string scope, CosmosClient client, string school, string tmdid,
-        Teacher teacher, AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, IConfiguration _configuration, LessonBase lessonBase, AzureRedisFactory _azureRedis)
-        {
-
-        }
-
+     
 
         /// <summary>
         /// 生成学生student-analysis.json
@@ -42,7 +42,10 @@ namespace HTEX.Lib.ETL.Lesson
         /// <param name="azureStorage"></param>
         /// <param name="lessonLocal"></param>
         /// <returns></returns>
-        public static async Task<(List<StudentLessonData> studentLessonDatas, List<StudentLessonItem> lessonItems)> DoStudentLessonData(List<string> objectiveTypes, AzureStorageFactory azureStorage, LessonLocal lessonLocal,DingDing _dingDing)
+        public static async Task<(List<StudentLessonData> studentLessonDatas, List<StudentLessonItem> lessonItems)>
+            DoStudentLessonData(List<string> objectiveTypes, AzureStorageFactory azureStorage, LessonLocal lessonLocal,DingDing _dingDing,
+            CosmosClient client,string location 
+            )
         {
             List<StudentLessonData> studentLessonDatas = lessonLocal.studentLessonDatas.ToJsonString().ToObject<List<StudentLessonData>>();
             studentLessonDatas = LessonETLService.GetBaseInfo(lessonLocal.lessonBase!, studentLessonDatas, lessonLocal?.lessonRecord?.id);
@@ -78,6 +81,75 @@ namespace HTEX.Lib.ETL.Lesson
                 }
             }
             await azureStorage.GetBlobContainerClient(owner).UploadFileByContainer(studentLessonDatas.ToJsonString(), "records", $"{lessonLocal.lessonRecord.id}/student-analysis.json");
+            if (lessonLocal.lessonRecord.scope.Equals("school")&& !string.IsNullOrWhiteSpace(lessonLocal.lessonRecord.school)  && location.Equals("China",StringComparison.OrdinalIgnoreCase))
+            {
+                School school = null;
+                ResponseMessage response = await client.GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemStreamAsync(lessonLocal.lessonRecord.school, new PartitionKey("Base"));
+                if (response.IsSuccessStatusCode)
+                {
+                    school = JsonDocument.Parse(response.Content).RootElement.ToObject<School>();
+                }
+                if (school!=null)
+                {
+                    string? periodId = !string.IsNullOrWhiteSpace(lessonLocal.lessonRecord.periodId) ? lessonLocal.lessonRecord.periodId : school.period.FirstOrDefault()?.id;
+                    var period = school.period.Find(x => x.id.Equals(periodId));
+                    var semester = SchoolService.GetSemester(period, lessonLocal.lessonRecord.startTime);
+                    string pre_id = $"{semester.studyYear}-{semester.currSemester.id}";
+                    string code = $"StudentSemesterRecord-{school.id}";
+                    foreach (var studentLessonData in studentLessonDatas)
+                    {
+                        StudentSemesterRecord studentSemester = null;// students.Find(x => x.stuid.Equals(studentLessonData.id) &&x.id.Equals($"{pre_id}-{studentLessonData.id}") && x.code.Equals(code));
+                        if (studentSemester==null)
+                        {
+                            studentSemester= new StudentSemesterRecord
+                            {
+                                id= $"{pre_id}-{studentLessonData.id}",
+                                code=code,
+                                stuid= studentLessonData.id,
+                                userType=Constant.ScopeStudent,
+                                school=school.id,
+                                studyYear=semester.studyYear,
+                                semesterId=semester.currSemester.id,
+                                period= period?.id,
+                            };
+                          //  students.Add(studentSemester);
+                        }
+                        StuLesson lesson = new StuLesson()
+                        {
+                            id= lessonLocal.lessonRecord.id,
+                            time= lessonLocal.lessonRecord.startTime,
+                            attend=0
+                        };
+                        if (studentLessonData.cooperation>0 || studentLessonData.achieve>0|| studentLessonData.attitude>0 || studentLessonData.cowork>0 ||  studentLessonData.appraise>0)
+                        {
+                            lesson.attend=1;
+                            studentSemester.lessons.Add(new StuLessonLite
+                            {
+                                tmdid=lessonLocal.lessonRecord.tmdid,
+                                sid= lessonLocal.lessonRecord.subjectId,
+                                cid= lessonLocal.lessonRecord.courseId,
+                                hrate=studentLessonData.cooperation,
+                                crate=studentLessonData.achieve,
+                                trate=studentLessonData.attitude,
+                                xrate=studentLessonData.cowork,
+                                prate=studentLessonData.appraise
+                            });
+                        }
+                        else
+                        {
+                            if (studentLessonData.attend==1)
+                            {
+                                lesson.attend=1;
+                            }
+                            else
+                            {
+                                lesson.attend=0;
+                            }
+                        }
+                        studentSemester.les.Add(lesson);
+                    }
+                }
+            }
             return (studentLessonDatas, lessonItems);
         }
         public static void GenAnalysisData(string pathAnalysis, long newest, List<TechCount> techCounts)
@@ -1996,7 +2068,7 @@ namespace HTEX.Lib.ETL.Lesson
                     {
                         fxGrp=(pickRate+coworkRate+gscoreRate+groupTask)*0.8/groupType;
                     }
-                    lessonItem.hz_nl=fxGrp;
+                    lessonItem.hz_nl=Math.Round(fxGrp,4);
                 }
                 {
                     //任务相关指数
@@ -2130,7 +2202,7 @@ namespace HTEX.Lib.ETL.Lesson
                 }
                 if (avg_cx>0)
                 {
-                    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+ lessonItem.hz_nl* 1.0/avg_cx;
+                    xx_cx+=Math.Round(lessonItem.hd_cx * 1.0/avg_cx+ lessonItem.pc_df* 1.0/avg_cx+ lessonItem.rw_cx* 1.0/avg_cx+ lessonItem.pj_nl* 1.0/avg_cx+ lessonItem.xz_cx* 1.0/avg_cx+ lessonItem.hz_nl* 1.0/avg_cx,4);
                 }
                 if (lessonItem.xz_cy>0)
                 {
@@ -2158,7 +2230,7 @@ namespace HTEX.Lib.ETL.Lesson
                 }
                 if (avg_cy>0) 
                 {
-                    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+ lessonItem.hz_nl* 1.0/avg_cy;
+                    xx_cy+=Math.Round(lessonItem.hd_cy * 1.0/avg_cy+ lessonItem.pc_zd* 1.0/avg_cy+ lessonItem.rw_cy* 1.0/avg_cy+ lessonItem.pj_nl* 1.0/avg_cy+ lessonItem.xz_cy* 1.0/avg_cy+ lessonItem.hz_nl* 1.0/avg_cy,4);
                 }
                 lessonItem.xx_cx=xx_cx;
                 lessonItem.xx_cy=xx_cy;
@@ -2622,6 +2694,43 @@ namespace HTEX.Lib.ETL.Lesson
         public string? yearMonth { get; set; }
 
     }
+    public class LessonWeek
+    {
+        
+        /// <summary>
+        /// 第几周
+        /// </summary>
+        public int week { get; set; }
+        /// <summary>
+        /// 课例id
+        /// </summary>
+        public string? id { get; set;}
+        /// <summary>
+        /// 课程id
+        /// </summary>
+        public string? cid { get; set; }
+        /// <summary>
+        /// 科目id
+        /// </summary>
+        public string? sid { get; set;}
+        /// <summary>
+        /// 学校
+        /// </summary>
+        public string?school { get; set; }
+        /// <summary>
+        /// 名单id
+        /// </summary>
+        public string? gid { get; set; }
+        /// <summary>
+        /// 学段id
+        /// </summary>
+        //public string? pid { get; set; }
+        
+        public string? scope { get; set; }
+
+    }
+
+
     /// <summary>
     /// 
     /// </summary>

+ 1 - 1
TEAMModelOS.Extension/HTEX.Lib/summary.xml

@@ -8188,7 +8188,7 @@
             小组编号
             </summary>
         </member>
-        <member name="M:HTEX.Lib.ETL.Lesson.LessonETLService.DoStudentLessonData(System.Collections.Generic.List{System.String},TEAMModelOS.SDK.DI.AzureStorageFactory,HTEX.Lib.ETL.Lesson.LessonLocal,TEAMModelOS.SDK.DI.DingDing)">
+        <member name="M:HTEX.Lib.ETL.Lesson.LessonETLService.DoStudentLessonData(System.Collections.Generic.List{System.String},TEAMModelOS.SDK.DI.AzureStorageFactory,HTEX.Lib.ETL.Lesson.LessonLocal,TEAMModelOS.SDK.DI.DingDing,Microsoft.Azure.Cosmos.CosmosClient)">
             <summary>
             生成学生student-analysis.json
             </summary>

+ 30 - 1
TEAMModelOS.Function/IESServiceBusTrigger.cs

@@ -42,6 +42,8 @@ using System.Net.Http.Headers;
 using Microsoft.AspNetCore.Hosting;
 using Newtonsoft.Json.Linq;
 using HTEX.Lib.ETL.Lesson;
+using System.Globalization;
+using TEAMModelOS.SDK.Models.Cosmos.OpenEntity;
 
 namespace TEAMModelOS.Function
 {
@@ -1761,7 +1763,34 @@ namespace TEAMModelOS.Function
                                             studentLessonDatas=studentLessonDatas
                                         };
                                         try {
-                                            await LessonETLService.DoStudentLessonData(Constant.objectiveTypes, _azureStorage, lessonLocal,_dingDing);
+                                            if (lessonRecord.duration>0)
+                                            {
+
+                                                var location = Environment.GetEnvironmentVariable("Option:Location");
+                                                await LessonETLService.DoStudentLessonData(Constant.objectiveTypes, _azureStorage, lessonLocal, _dingDing, client, location);
+                                                
+                                                // 使用当前文化设置的日历
+                                                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 = $"LessonWeek:{lessonRecord.scope}:{lessonRecord.tmdid}:{DateTime.Now.Year}-{week}";
+                                                _azureRedis.GetRedisClient(8).HashSet(key, 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()
+                                                );
+                                            }
+                                           
                                         } catch (Exception ex) {
                                             await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}处理学生课中数据发生异常,{_lessonId}\n{ex.Message}\n{ex.StackTrace}\n\n{lessonRecord.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
                                         }

+ 34 - 27
TEAMModelOS.SDK/Models/Cosmos/Common/StudentScoreRecord.cs

@@ -45,30 +45,30 @@ namespace TEAMModelOS.SDK.Models.Cosmos.Common
         public int studyYear { get; set; }
         public string semesterId { get; set; }
         public string period { get; set; }
-        /// <summary>
-        /// 出席率
-        /// </summary>
-        public double arate { get; set; }
-        /// <summary>
-        /// 合作能力表现
-        /// </summary>
-        public double hrate { get; set;}
-        /// <summary>
-        /// 学习成效表现
-        /// </summary>
-        public double crate { get; set;}
-        /// <summary>
-        /// 学习态度表现
-        /// </summary>
-        public double trate { get; set;}
-        /// <summary>
-        /// 协作能力表现
-        /// </summary>
-        public double xrate { get; set;}
-        /// <summary>
-        /// 评价能力表现
-        /// </summary>
-        public double prate { get; set;}
+        ///// <summary>
+        ///// 出席率
+        ///// </summary>
+        //public double arate { get; set; }
+        ///// <summary>
+        ///// 合作能力表现
+        ///// </summary>
+        //public double hrate { get; set;}
+        ///// <summary>
+        ///// 学习成效表现
+        ///// </summary>
+        //public double crate { get; set;}
+        ///// <summary>
+        ///// 学习态度表现
+        ///// </summary>
+        //public double trate { get; set;}
+        ///// <summary>
+        ///// 协作能力表现
+        ///// </summary>
+        //public double xrate { get; set;}
+        ///// <summary>
+        ///// 评价能力表现
+        ///// </summary>
+        //public double prate { get; set;}
         /// <summary>
         /// 课例,有数据的。
         /// </summary>
@@ -76,11 +76,12 @@ namespace TEAMModelOS.SDK.Models.Cosmos.Common
         /// <summary>
         /// 课例id集合,1--id 代表出席,0--id代表未出席
         /// </summary>
-        public List<string> lessonIds { get; set; } = new List<string>();
+        //public List<string> lessonIds { get; set; } = new List<string>();
+        public List<StuLesson> les { get; set; }= new List<StuLesson>();
     }
-    public class StuLessonLite 
+
+    public class StuLesson
     {
-       
         /// <summary>
         /// 课例id
         /// </summary>
@@ -89,6 +90,12 @@ namespace TEAMModelOS.SDK.Models.Cosmos.Common
         /// 开课时间
         /// </summary>
         public long time { get; set; }
+        public int attend { get; set; }
+    }
+    public class StuLessonLite 
+    {
+       
+      
         /// <summary>
         /// 上课教师
         /// </summary>