zhouj1203@hotmail.com 1 year ago
parent
commit
f63b25bf48

+ 102 - 99
TEAMModelOS.FunctionV4/CosmosDB/TriggerArt.cs

@@ -363,117 +363,120 @@ namespace TEAMModelOS.FunctionV4.CosmosDB
                             {
                             {
 
 
                             }
                             }
-                            List<Task<ItemResponse<StudentArtResult>>> tasks = new List<Task<ItemResponse<StudentArtResult>>>();
-                            //新增数据推送 obj => Portrait
-                            Portrait portrait = new()
-                            {
-                                schoolCode = art.school,
-                                periodId = art.period.id,
-                                subjectId = "subject_art"
-                            };
-                            var period = scInfo.period.Where(x => x.id.Equals(art.period.id)).FirstOrDefault();
-                            //获取学期信息
-                            var (currSemester, studyYear, date, nextSemester) =  SchoolService.GetSemester(period, art.startTime);
-                            //总分的占比情况
+                            if (art.publish == 0) {
+                                List<Task<ItemResponse<StudentArtResult>>> tasks = new List<Task<ItemResponse<StudentArtResult>>>();
+                                //新增数据推送 obj => Portrait
+                                Portrait portrait = new()
+                                {
+                                    schoolCode = art.school,
+                                    periodId = art.period.id,
+                                    subjectId = "subject_art"
+                                };
+                                var period = scInfo.period.Where(x => x.id.Equals(art.period.id)).FirstOrDefault();
+                                //获取学期信息
+                                var (currSemester, studyYear, date, nextSemester) = SchoolService.GetSemester(period, art.startTime);
+                                //总分的占比情况
 
 
-                            foreach (var rs in studentArtResults)
-                            {
-                                foreach (var res in rs.results) {
-                                    if (res.quotaId.Equals("quota_21") && res.score > -1 && res.score < 95) {
-                                        /*res.score *= 1.5;
-                                        if (res.score >= 95) {
-                                            res.score = new Random().Next(90, 99);
-                                        }*/
-                                        res.score = Math.Round(res.score);
-                                    }
-                                }
-                                
-                                //if (rs.totalScore == 0)
-                                //{
-                                foreach (var sc in rs.subjectScores)
+                                foreach (var rs in studentArtResults)
                                 {
                                 {
-                                    //if (sc.score == 0)
+                                    foreach (var res in rs.results)
+                                    {
+                                        if (res.quotaId.Equals("quota_21") && res.score > -1 && res.score < 95)
+                                        {
+                                            /*res.score *= 1.5;
+                                            if (res.score >= 95) {
+                                                res.score = new Random().Next(90, 99);
+                                            }*/
+                                            res.score = Math.Round(res.score);
+                                        }
+                                    }
+
+                                    //if (rs.totalScore == 0)
                                     //{
                                     //{
-                                    /* var subjectMore = rs.results.GroupBy(x => x.subjectId).Select(c => new { subject = c.Key, list = c.ToList().Select(m => new { m.quotaId,m.score}) });
-                                     var totalScore = subjectMore.Select(x => new { 
-                                         x.subject,
-                                         quotaScroe =  x.list.Select(c => new {
-                                             c.quotaId,
-                                             c.score
-                                         }),
-                                     });*/
-                                    var quotaPercent = setting.quotas.Select(x => new
+                                    foreach (var sc in rs.subjectScores)
                                     {
                                     {
-                                        x.id,
-                                        x.percent,
-                                        score = x.children.Select(c => new
+                                        //if (sc.score == 0)
+                                        //{
+                                        /* var subjectMore = rs.results.GroupBy(x => x.subjectId).Select(c => new { subject = c.Key, list = c.ToList().Select(m => new { m.quotaId,m.score}) });
+                                         var totalScore = subjectMore.Select(x => new { 
+                                             x.subject,
+                                             quotaScroe =  x.list.Select(c => new {
+                                                 c.quotaId,
+                                                 c.score
+                                             }),
+                                         });*/
+                                        var quotaPercent = setting.quotas.Select(x => new
                                         {
                                         {
-                                            real = rs.results.Where(r => r.quotaId.Equals(c.id) && r.subjectId.Equals(sc.subjectId) && r.score > -1).FirstOrDefault()?.score * c.percent * 0.01,
-                                            score = c.children.Select(s => new
+                                            x.id,
+                                            x.percent,
+                                            score = x.children.Select(c => new
                                             {
                                             {
-                                                real = rs.results.Where(r => r.quotaId.Equals(s.id) && r.subjectId.Equals(sc.subjectId) && r.score > -1).FirstOrDefault()?.score * s.percent * 0.01
-                                            }).Sum(n => n.real) * c.percent * 0.01
-                                        }).Sum(n => n.real + n.score) * x.percent * 0.01
-                                    });
-                                    double realScore = Math.Round((double)quotaPercent.Sum(c => c.score),2);                                   
-                                    sc.score = realScore;
+                                                real = rs.results.Where(r => r.quotaId.Equals(c.id) && r.subjectId.Equals(sc.subjectId) && r.score > -1).FirstOrDefault()?.score * c.percent * 0.01,
+                                                score = c.children.Select(s => new
+                                                {
+                                                    real = rs.results.Where(r => r.quotaId.Equals(s.id) && r.subjectId.Equals(sc.subjectId) && r.score > -1).FirstOrDefault()?.score * s.percent * 0.01
+                                                }).Sum(n => n.real) * c.percent * 0.01
+                                            }).Sum(n => n.real + n.score) * x.percent * 0.01
+                                        });
+                                        double realScore = Math.Round((double)quotaPercent.Sum(c => c.score), 2);
+                                        sc.score = realScore;
+                                        //}
+                                    }
+                                    rs.totalScore = Math.Round(rs.subjectScores.Where(m => m.score >= 0).Sum(z => z.score), 2);
+                                    tasks.Add(client.GetContainer(Constant.TEAMModelOS, Constant.Student).ReplaceItemAsync(rs, rs.id, new PartitionKey(rs.code)));
+                                    PortraitStudent student = new()
+                                    {
+                                        studentId = rs.studentId,
+                                        name = rs.studentName,
+                                        classId = rs.classIds[0]
+                                    };
+                                    SemesterData semesterData = new()
+                                    {
+                                        examName = art.name,
+                                        examId = art.id,
+                                        examDate = art.startTime,
+                                        examType = "",
+                                        year = studyYear,
+                                        semesterId = currSemester.id,
+                                        totalScore = 200,
+                                        sumScore = rs.totalScore,
+                                        excellenceRate = 0,
+                                        passRate = 0,
+                                    };
+                                    int index = 0;
+                                    foreach (var sj in art.subjects)
+                                    {
+                                        ItemScore item = new()
+                                        {
+                                            name = sj.name,
+                                            score = rs.subjectScores.Where(x => x.subjectId.Equals(sj.id)).FirstOrDefault().score,
+                                            time = art.startTime,
+                                            totalScore = 100,
+                                            type = sj.id
+                                        };
+                                        index++;
+                                        semesterData.itemScore.Add(item);
+                                    }
+                                    student.semesterData.Add(semesterData);
+
+                                    portrait.students.Add(student);
                                     //}
                                     //}
                                 }
                                 }
-                                rs.totalScore = Math.Round(rs.subjectScores.Where(m => m.score >= 0).Sum(z => z.score),2);
-                                tasks.Add(client.GetContainer(Constant.TEAMModelOS, Constant.Student).ReplaceItemAsync(rs, rs.id, new PartitionKey(rs.code)));
-                                PortraitStudent student = new()
-                                {
-                                    studentId = rs.studentId,
-                                    name = rs.studentName,
-                                    classId = rs.classIds[0]
-                                };
-                                SemesterData semesterData = new()
-                                {
-                                    examName = art.name,
-                                    examId = art.id,
-                                    examDate = art.startTime,
-                                    examType = "",
-                                    year = studyYear,
-                                    semesterId = currSemester.id,
-                                    totalScore = 200,
-                                    sumScore = rs.totalScore,
-                                    excellenceRate = 0,
-                                    passRate = 0,
-                                };
-                                int index = 0;
-                                foreach (var sj in art.subjects)
+                                if (tasks.Count > 0)
                                 {
                                 {
-                                    ItemScore item = new()
-                                    {
-                                        name = sj.name,
-                                        score = rs.subjectScores.Where(x => x.subjectId.Equals(sj.id)).FirstOrDefault().score,
-                                        time = art.startTime,
-                                        totalScore = 100,
-                                        type = sj.id
-                                    };
-                                    index++;
-                                    semesterData.itemScore.Add(item);
+                                    await Task.WhenAll(tasks);
                                 }
                                 }
-                                student.semesterData.Add(semesterData);
-
-                                portrait.students.Add(student);
-                                //}
-                            }
-                            if (tasks.Count > 0)
-                            {
-                                await Task.WhenAll(tasks);
-                            }
-                          
-                            //获取学生信息
-                            //(List<RMember> rmembers, List<RGroupList> groups) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, art.classes, art.school);
-                           /* foreach (var member in studentArtResults)
-                            {                                
-                                
-                            }*/
-                            string location = $"{Environment.GetEnvironmentVariable("Option:Location")}";
-                            var responseData = await _httpTrigger.RequestHttpTrigger(portrait.ToJson(), location, "upsert-student-portrait");
 
 
+                                //获取学生信息
+                                //(List<RMember> rmembers, List<RGroupList> groups) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, art.classes, art.school);
+                                /* foreach (var member in studentArtResults)
+                                 {                                
 
 
+                                 }*/
+                                string location = $"{Environment.GetEnvironmentVariable("Option:Location")}";
+                                var responseData = await _httpTrigger.RequestHttpTrigger(portrait.ToJson(), location, "upsert-student-portrait");
+                            }
+                           
                             break;
                             break;
                     }
                     }
                 }
                 }

+ 148 - 25
TEAMModelOS.SDK/Models/Service/ExamService.cs

@@ -1,4 +1,6 @@
 using Azure.Cosmos;
 using Azure.Cosmos;
+using DocumentFormat.OpenXml.Office2010.Excel;
+using MathNet.Numerics.Distributions;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Linq;
 using System.Linq;
@@ -6,6 +8,7 @@ using System.Text;
 using System.Text.Json;
 using System.Text.Json;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.DI;
+using TEAMModelOS.SDK.Extension;
 
 
 namespace TEAMModelOS.SDK.Models.Service
 namespace TEAMModelOS.SDK.Models.Service
 {
 {
@@ -59,6 +62,126 @@ namespace TEAMModelOS.SDK.Models.Service
 
 
             }
             }
         }
         }
+
+        public static async Task<List<(string name, List<(string className, double average)> classMore, double total,List<(string sname, double scores)>)>> getGradeScore(CoreAPIHttpService _coreAPIHttpService, DingDing _dingDing, CosmosClient client, int gradeId, string gradeName, string periodId, string schooCode, long stime, long etime)
+        {
+            List<(string name, List<(string className,double average)> classMore, double total, List<(string sname, double scores)> stus)> grades = new();
+            //List<(string grade, double score)> grades = new();
+            try
+            {
+                //获取该年级所有班级ID
+                List<string> classIds = new();
+                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: $"select c.id from c where c.year = {gradeId} and c.pk = 'Class' and c.periodId = '{periodId}' ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Class-{schooCode}") }))
+                {
+                    using var jsonTask = await JsonDocument.ParseAsync(item.ContentStream);
+                    if (jsonTask.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                    {
+                        var accounts = jsonTask.RootElement.GetProperty("Documents").EnumerateArray();
+                        while (accounts.MoveNext())
+                        {
+                            JsonElement account = accounts.Current;
+                            classIds.Add(account.GetProperty("id").GetString());
+                        }
+                    }
+                }
+                if (classIds.Count == 0)
+                {
+                    return grades;
+                }
+                else
+                {
+                    //获取该学期内学校发生的所有评测活动(不包含个人评测活动)
+                    List<ExamInfo> exams = new();
+                    School sc = new();
+                    var response = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(schooCode.ToString(), new PartitionKey($"Base"));
+                    if (response.Status == 200)
+                    {
+                        using var json = await JsonDocument.ParseAsync(response.ContentStream);
+                        sc = json.ToObject<School>();
+                    }
+                    //var gradeNames = sc.period.Where(x => x.id.Equals(periodId.ToString()))?.FirstOrDefault().grades;
+                    //var index = gradeNames.IndexOf(gradeName.ToString());
+                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<ExamInfo>(queryText: $"select value(c) from c join A0 in c.grades where A0.name = '{gradeName}' and c.startTime >= {stime} and c.startTime < {etime} order by c.createTime desc", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Exam-{schooCode}") }))
+                    {
+                        exams.Add(item);
+                    }
+                    List<ExamInfo> newExams = new();
+                    exams = exams.Where(x => x.period.id.Equals(periodId)).ToList();
+                    foreach (ExamInfo info in exams)
+                    {
+                        bool flag = true;
+                        foreach (string id in classIds)
+                        {
+                            if (!info.classes.Contains(id))
+                            {
+                                flag = false;
+                            }
+                        }
+                        if (flag) {
+                            newExams.Add(info);
+                        }                        
+                    }
+                    if (newExams.Count > 3) {
+                        newExams = newExams.Take(3).ToList();
+                    }
+                    List<string> examIds = newExams.Select(x => x.id).ToList();
+                    List<ExamClassResult> classResults = new();
+                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<ExamClassResult>(
+                    queryText: $"select value(c) from c where c.examId in ({string.Join(",", examIds.Select(x => $"'{x}'"))})",
+                    requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{schooCode}") }))
+                    {
+                        classResults.Add(item);
+                    }
+                    (List<RMember> rmembers, List<RGroupList> groups) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, classIds, schooCode);
+                    foreach (ExamInfo info in newExams) {
+                        double totalScore = info.papers.SelectMany(x => x.point).Sum();
+                        var classResult = classResults.Where(x => x.examId.Equals(info.id)).ToList();
+                        var classScores = classResult.GroupBy(x => x.info.name).Select(c => new { className =  c.Key, average = c.ToList().Sum(z => z.average) / info.subjects.Count / totalScore }).ToList();
+                        List<(string className, double average)> classMore = new();
+                        foreach (var cs in classScores) {
+                            classMore.Add((cs.className,cs.average));
+                        }
+                        var gradeScores = info.average / totalScore;
+                        List<(string sname, double scores)> stus = new();
+                        foreach (RMember member in rmembers) {
+                            double scroe = 0;
+                            foreach (ExamClassResult result in classResult) {
+                                if (result.studentIds.Contains(member.id)) {
+                                    int index = result.studentIds.IndexOf(member.id);
+                                    scroe += result.sum[index];
+                                }
+                            }
+                            stus.Add((member.name, scroe));
+                        }
+                        grades.Add((info.name, classMore, gradeScores, stus));
+                    }
+
+                }
+            }
+            catch (Exception e)
+            {
+
+            }
+            /*await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: $"select c.id from c where c.cid = '{id}' ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"CorrectTask-{tId}") }))
+            {
+                using var jsonTask = await JsonDocument.ParseAsync(item.ContentStream);
+                if (jsonTask.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                {
+                    var accounts = jsonTask.RootElement.GetProperty("Documents").EnumerateArray();
+                    while (accounts.MoveNext())
+                    {
+                        JsonElement account = accounts.Current;
+                        correctIds.Add(account.GetProperty("id").GetString());
+                    }
+                }
+            }
+            if (correctIds.Count > 0)
+            {
+                await client.GetContainer(Constant.TEAMModelOS, "Teacher").DeleteItemsStreamAsync(correctIds, $"CorrectTask-{tId}");
+
+            }*/
+            return grades;
+        }
         public static async Task<string> saveMoreAsync(CosmosClient client, DingDing _dingDing, ExamLite trExam)
         public static async Task<string> saveMoreAsync(CosmosClient client, DingDing _dingDing, ExamLite trExam)
         {
         {
             try
             try
@@ -102,38 +225,38 @@ namespace TEAMModelOS.SDK.Models.Service
 
 
             }
             }
         }
         }
-/*
-        public static async Task<string> getKnowledges(List<string> knowledges,List<ExamClassResult> answers ,string sub,List<List<string>> kones,List<double> point) {
-            foreach (string k in knowledges)
-            {
-                double score = 0;
-                double allScore = 0;
-                int n = 0;
-                int count = 0;
-                foreach (ExamClassResult result in answers)
-                {
-                    if (result.subjectId.Equals(sub))
+        /*
+                public static async Task<string> getKnowledges(List<string> knowledges,List<ExamClassResult> answers ,string sub,List<List<string>> kones,List<double> point) {
+                    foreach (string k in knowledges)
                     {
                     {
-                        foreach (List<string> str in kones)
+                        double score = 0;
+                        double allScore = 0;
+                        int n = 0;
+                        int count = 0;
+                        foreach (ExamClassResult result in answers)
                         {
                         {
-                            if (str.Contains(k))
+                            if (result.subjectId.Equals(sub))
                             {
                             {
-                                var itemPersent = str.Count > 0 ? 1 / Convert.ToDouble(str.Count) : 0;
-                                allScore += point.Count > 0 ? point[n] * itemPersent : 0;
-
-                                if (result.studentScores.Count > 0)
+                                foreach (List<string> str in kones)
                                 {
                                 {
-                                    score += result.studentScores.Sum(r => r.Sum()) * itemPersent;
+                                    if (str.Contains(k))
+                                    {
+                                        var itemPersent = str.Count > 0 ? 1 / Convert.ToDouble(str.Count) : 0;
+                                        allScore += point.Count > 0 ? point[n] * itemPersent : 0;
+
+                                        if (result.studentScores.Count > 0)
+                                        {
+                                            score += result.studentScores.Sum(r => r.Sum()) * itemPersent;
+                                        }
+                                    }
+                                    n++;
                                 }
                                 }
+
+                                count += result.studentIds.Count;
                             }
                             }
-                            n++;
                         }
                         }
-
-                        count += result.studentIds.Count;
+                        double per = count > 0 ? Math.Round(score / count, 2) : 0;
                     }
                     }
-                }
-                double per = count > 0 ? Math.Round(score / count, 2) : 0;
-            }
-        }*/
+                }*/
     }
     }
 }
 }

+ 9 - 0
TEAMModelOS/Controllers/Common/ExamController.cs

@@ -285,6 +285,15 @@ namespace TEAMModelOS.Controllers
             }
             }
 
 
         }
         }
+       /* [ProducesDefaultResponseType]
+        //[AuthToken(Roles = "teacher,admin")]
+        [HttpPost("read-score")]
+       // [Authorize(Roles = "IES")]
+        public async Task<IActionResult> getAverage(JsonElement request) {
+            var client = _azureCosmos.GetCosmosClient();
+            var grades =  ExamService.getGradeScore(_coreAPIHttpService,_dingDing,client,2021,"二年级", "463db08d-cbe7-48a0-a81a-fc39b3c1fep1","hbcn", 1688349974000, 1693706774000);
+            return Ok(grades);
+        }*/
 
 
         /// <summary>
         /// <summary>
         /// 保存考试信息
         /// 保存考试信息