Explorar o código

处理课列相关结构

zhouj1203@hotmail.com %!s(int64=3) %!d(string=hai) anos
pai
achega
7b03af0216

+ 46 - 10
TEAMModelOS.SDK/Models/Service/LessonService.cs

@@ -105,12 +105,47 @@ namespace TEAMModelOS.SDK.Models.Service
             return lessonDis;
         }
 
+        public static LessonDis DisLessonCount_2(LessonRecord oldRecord, LessonRecord newRecord, LessonDis lessonDis)
+        {
+            //创建课堂的情况
+            if (oldRecord == null && newRecord != null)
+            {
+                lessonDis.record = 1;
+                //P分数量加减
+
+                if (newRecord.pScore >= 70)
+                {
+                    lessonDis.disPCount = 1;
+                }
+
+                //T分数量加减
+
+
+                if (newRecord.tScore >= 70)
+                {
+                    lessonDis.disTCount = 1;
+                }
+
+                //双绿灯数量
+
+
+                if (newRecord.tScore >= 70 && newRecord.pScore >= 70)
+                {
+                    lessonDis.disDCount = 1;
+                }
+
+            }
+            return lessonDis;
+        }
+
+
         public static async Task FixLessonCount(CosmosClient client, DingDing _dingDing, LessonRecord record, LessonRecord oldRecord, LessonDis lessonDis)
         {
             LessonRecord data = null;
             try
             {
-                if (record != null && oldRecord == null) {
+                if (record != null && oldRecord == null)
+                {
                     data = record;
                 }
                 if (record == null && oldRecord != null)
@@ -130,7 +165,7 @@ namespace TEAMModelOS.SDK.Models.Service
                 string code = string.Empty;
                 if (data.scope.Equals("school"))
                 {
-                    code = $"LessonCount-{data.school}-{year}";
+                    code = $"LessonCount-{data.school}-{year}-{data.periodId}";
                     tbname = "School";
                 }
                 else
@@ -144,10 +179,10 @@ namespace TEAMModelOS.SDK.Models.Service
                     using var json = await JsonDocument.ParseAsync(response.ContentStream);
                     LessonCount count = json.ToObject<LessonCount>();
 
-                    count.tCount[day-1] += lessonDis.disTCount;
-                    count.pCount[day-1] += lessonDis.disPCount;
-                    count.ptCount[day-1] += lessonDis.disDCount;
-                    count.beginCount[day-1] += lessonDis.record;
+                    count.tCount[day - 1] += lessonDis.disTCount;
+                    count.pCount[day - 1] += lessonDis.disPCount;
+                    count.ptCount[day - 1] += lessonDis.disDCount;
+                    count.beginCount[day - 1] += lessonDis.record;
                     /*if (!count.courseIds.Contains(data.courseId))
                     {
                         count.courseIds.Add(data.courseId);
@@ -170,10 +205,11 @@ namespace TEAMModelOS.SDK.Models.Service
                     List<double> listT = new List<double>(da);
                     List<double> listP = new List<double>(da);
                     List<double> listPT = new List<double>(da);
-                    list[day-1] += lessonDis.record;
-                    listT[day-1] += lessonDis.disTCount;
-                    listP[day-1] += lessonDis.disPCount;
-                    listPT[day-1] += lessonDis.disDCount;
+
+                    list[day - 1] += lessonDis.record;
+                    listT[day - 1] += lessonDis.disTCount;
+                    listP[day - 1] += lessonDis.disPCount;
+                    listPT[day - 1] += lessonDis.disDCount;
                     count.beginCount.AddRange(list);
                     count.tCount.AddRange(listT);
                     count.pCount.AddRange(listP);

+ 85 - 31
TEAMModelOS/Controllers/Analysis/ClassAnalysisController.cs

@@ -88,8 +88,8 @@ namespace TEAMModelOS.Controllers.Analysis
                         sc = json.ToObject<School>();
                     }
 
-                    List<(string name, double count)> rc = await getRecordCount(client, records, st, et, code.GetString(), tId);
-                    List<(int week, List<double> count)> tpc = await getTPCount(client, st, et, code.GetString(), tId);
+                    List<(string name, double count)> rc = await getRecordCount(client, records, st, et, code.GetString(), tId,pId.GetString());
+                    List<(int week, List<double> count)> tpc = await getTPCount(client, records, st, et, code.GetString(), tId, pId.GetString());
                     List<(string name, int count)> groups = getGroupCount(records);
                     List<(string name, int count)> grades = getGradeCount(records);
                     List<(string name, int count)> types = getTypeCount(records);
@@ -100,11 +100,12 @@ namespace TEAMModelOS.Controllers.Analysis
                     List<(string name, int count)> groc = new List<(string name, int count)>();
                     foreach (var item in groups)
                     {
-                        List<GroupListGrp>  grps  = await GroupListService.GetMemberInGroupList(_coreAPIHttpService, client, _dingDing, item.name,1, code.GetString(), new List<string> { "research" });
+                        List<GroupListGrp> grps = await GroupListService.GetMemberInGroupList(_coreAPIHttpService, client, _dingDing, item.name, 1, code.GetString(), new List<string> { "research" });
                         //groupIds.Add(item.name);
                         //List<(string name, int count)> groc = new List<(string name, int count)>();
-                        foreach (var grp in grps) {
-                            groc.Add((grp.name,item.count));
+                        foreach (var grp in grps)
+                        {
+                            groc.Add((grp.name, item.count));
                         }
                     }
                     //var gyc  =  groc.GroupBy(x => x.name).Select(y => new {name = y.Key, count = y.Sum(c => c.count) });
@@ -196,7 +197,7 @@ namespace TEAMModelOS.Controllers.Analysis
             }
             catch (Exception e)
             {
-                await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/analysis-recod()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
+                await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/analysis-recod()\n{e.Message}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
                 return BadRequest();
             }
 
@@ -251,8 +252,8 @@ namespace TEAMModelOS.Controllers.Analysis
                 }
                 if (records.Count > 0)
                 {
-                    List<(string name, double count)> rc = await getRecordCount(client, records, st, et, code.GetString(), tId);
-                    List<(int week, List<double> count)> tpc = await getTPCount(client, st, et, code.GetString(), tId);
+                    List<(string name, double count)> rc = await getRecordCount(client, records, st, et, code.GetString(), tId,"");
+                    List<(int week, List<double> count)> tpc = await getTPCount(client, records, st, et, code.GetString(), tId,"");
 
                     var total = rc.Select(x => new { x.name, value = x.count });
                     var trend = tpc.Select(x => new { name = x.week, value = x.count });
@@ -282,7 +283,8 @@ namespace TEAMModelOS.Controllers.Analysis
                 var c = records.Where(r => r.groupIds.Contains(groupId)).Count();
                 grCount.Add((groupId, c));
             }*/
-            foreach (var gr in subs) {
+            foreach (var gr in subs)
+            {
                 grCount.Add((gr.key, gr.count));
             }
             return grCount;
@@ -332,7 +334,7 @@ namespace TEAMModelOS.Controllers.Analysis
             return tyCount;
         }
         //课列趋势图
-        private async Task<List<(int week, List<double> count)>> getTPCount(CosmosClient client, long stime, long etime, string code, string tId)
+        private async Task<List<(int week, List<double> count)>> getTPCount(CosmosClient client, List<LessonRecord> records, long stime, long etime, string code, string tId,string periodId)
         {
             try
             {
@@ -351,6 +353,7 @@ namespace TEAMModelOS.Controllers.Analysis
                 List<LessonCount> scount = new List<LessonCount>();
                 List<LessonCount> tcount = new List<LessonCount>();
                 var queryClass = $"select value(c) from c ";
+                List<string> perId = records.Select(r => r.periodId).Distinct().ToList();
                 if (!string.IsNullOrEmpty(tId))
                 {
 
@@ -361,14 +364,26 @@ namespace TEAMModelOS.Controllers.Analysis
                     {
                         scount.Add(item);
                     }
+                    foreach (string pId in perId)
+                    {
+                        await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<LessonCount>(
+                                    queryText: queryClass,
+                                    requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonCount-{code}-{syear}-{pId}") }))
+                        {
+                            scount.Add(item);
+                        }
+                    }
 
                 }
-                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<LessonCount>(
-                        queryText: queryClass,
-                        requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonCount-{code}-{syear}") }))
-                {
-                    scount.Add(item);
+                else {
+                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<LessonCount>(
+                           queryText: queryClass,
+                           requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonCount-{code}-{syear}-{periodId}") }))
+                    {
+                        scount.Add(item);
+                    }
                 }
+               
                 List<List<double>> begin = new();
                 List<List<double>> t = new();
                 List<List<double>> p = new();
@@ -442,13 +457,25 @@ namespace TEAMModelOS.Controllers.Analysis
                                 {
                                     tcount.Add(item);
                                 }
+                                foreach (string pId in perId)
+                                {
+                                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<LessonCount>(
+                                                queryText: queryClass,
+                                                requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonCount-{code}-{tyear}-{pId}") }))
+                                    {
+                                        scount.Add(item);
+                                    }
+                                }
                             }
-                            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<LessonCount>(
-                            queryText: queryClass,
-                            requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonCount-{code}-{tyear}") }))
-                            {
-                                tcount.Add(item);
+                            else {
+                                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<LessonCount>(
+                                queryText: queryClass,
+                                requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonCount-{code}-{tyear}-{periodId}") }))
+                                {
+                                    tcount.Add(item);
+                                }
                             }
+                            
                             var eday = DateTimeOffset.UtcNow.DayOfYear;
                             int pydays = DateTimeHelper.getDays(tyear);
                             List<List<double>> e_begin = new();
@@ -518,7 +545,7 @@ namespace TEAMModelOS.Controllers.Analysis
             }
         }
 
-        private async Task<List<(string time, double count)>> getRecordCount(CosmosClient client, List<LessonRecord> records, long stime, long etime, string code, string tId)
+        private async Task<List<(string time, double count)>> getRecordCount(CosmosClient client, List<LessonRecord> records, long stime, long etime, string code, string tId,string periodId)
         {
             List<(string time, double count)> counts = new();
             counts.Add(("total", records.Count()));
@@ -533,6 +560,7 @@ namespace TEAMModelOS.Controllers.Analysis
             List<LessonCount> scount = new();
             List<LessonCount> tcount = new();
             DenseMatrix dense = null;
+            List<string> perId = records.Select(r => r.periodId).Distinct().ToList();
             var queryClass = $"select value(c) from c ";
             if (!string.IsNullOrEmpty(tId))
             {
@@ -543,13 +571,26 @@ namespace TEAMModelOS.Controllers.Analysis
                 {
                     scount.Add(item);
                 }
+                foreach (string pId in perId)
+                {
+                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<LessonCount>(
+                                queryText: queryClass,
+                                requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonCount-{code}-{syear}-{pId}") }))
+                    {
+                        scount.Add(item);
+                    }
+                }
             }
-            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<LessonCount>(
-                        queryText: queryClass,
-                        requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonCount-{code}-{syear}") }))
-            {
-                scount.Add(item);
+            else {
+                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<LessonCount>(
+                                queryText: queryClass,
+                                requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonCount-{code}-{syear}-{periodId}") }))
+                {
+                    scount.Add(item);
+                }
             }
+            
+
             //var response = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(syear.ToString(), new PartitionKey($"ClassCount-" + code));
             if (tyear > syear)
             {
@@ -562,13 +603,26 @@ namespace TEAMModelOS.Controllers.Analysis
                     {
                         tcount.Add(item);
                     }
+                    foreach (string pId in perId)
+                    {
+                        await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<LessonCount>(
+                               queryText: queryClass,
+                               requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonCount-{code}-{tyear}-{pId}") }))
+                        {
+                            tcount.Add(item);
+                        }
+                    }
                 }
-                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<LessonCount>(
-                            queryText: queryClass,
-                            requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonCount-{code}-{tyear}") }))
-                {
-                    tcount.Add(item);
+                else {
+                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<LessonCount>(
+                                   queryText: queryClass,
+                                   requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonCount-{code}-{tyear}-{periodId}") }))
+                    {
+                        tcount.Add(item);
+                    }
                 }
+               
+
                 if (tcount.Count > 0)
                 {
                     List<List<double>> be = new();

+ 24 - 0
TEAMModelOS/Controllers/XTest/FixDataController.cs

@@ -1355,6 +1355,30 @@ namespace TEAMModelOS.Controllers
             return Ok(new { infos });
         }
 
+        [ProducesDefaultResponseType]
+        //[AuthToken(Roles = "teacher")]
+        [HttpPost("fix-lesson-count")]
+        public async Task<IActionResult> FixLessonCount(JsonElement data)
+        {
+            if (!data.TryGetProperty("code", out JsonElement code)) return BadRequest();
+            var client = _azureCosmos.GetCosmosClient();
+            var queryClass = $"select value(c) from c";
+            List<LessonRecord> records = new List<LessonRecord>();
+            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<LessonRecord>(queryText: queryClass, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonRecord-{code}") }))
+            {
+                records.Add(item);
+
+            }
+            List<string> infos = new List<string>();
+            foreach (LessonRecord lesson in records) {
+                LessonDis dis = new LessonDis();
+                dis = LessonService.DisLessonCount_2(null,lesson, dis);
+                await LessonService.FixLessonCount(client, _dingDing, lesson, null, dis);
+            }
+            
+            return Ok(new { infos });
+        }
+
         /// <summary>
         /// add  admin 
         /// </summary>