zhouj1203@hotmail.com 9 mēneši atpakaļ
vecāks
revīzija
1aef0115be
1 mainītis faili ar 102 papildinājumiem un 0 dzēšanām
  1. 102 0
      TEAMModelOS/Controllers/Common/ExamController.cs

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

@@ -41,6 +41,11 @@ using ClouDASLibx;
 using Azure.Storage.Blobs.Models;
 using Azure.Storage.Blobs.Models;
 using System.IO;
 using System.IO;
 using TEAMModelOS.SDK.Helper.Common.StringHelper;
 using TEAMModelOS.SDK.Helper.Common.StringHelper;
+using Microsoft.AspNetCore.SignalR;
+using static SKIT.FlurlHttpClient.Wechat.TenpayV3.Models.CreateApplyForSubjectApplymentRequest.Types;
+using TEAMModelOS.Controllers.Analysis;
+using DocumentFormat.OpenXml.Office2010.Excel;
+using DocumentFormat.OpenXml.Wordprocessing;
 
 
 
 
 namespace TEAMModelOS.Controllers
 namespace TEAMModelOS.Controllers
@@ -369,6 +374,103 @@ namespace TEAMModelOS.Controllers
 
 
             }
             }
         }
         }
+
+        [ProducesDefaultResponseType]
+        [AuthToken(Roles = "teacher,admin")]
+        [HttpPost("get-exam-point")]
+        [Authorize(Roles = "IES")]
+        public async Task<IActionResult> getExamPoint(JsonElement request)
+        {
+            try
+            {
+                if (!request.TryGetProperty("classIds", out JsonElement classId)) return BadRequest();
+                if (!request.TryGetProperty("school", out JsonElement code)) return BadRequest();
+                if (!request.TryGetProperty("startTime", out JsonElement startTime)) return BadRequest();
+                if (!request.TryGetProperty("endTime", out JsonElement endTime)) return BadRequest();
+                if (!request.TryGetProperty("periodId", out JsonElement periodId)) return BadRequest();              
+                var client = _azureCosmos.GetCosmosClient();
+                List<string> ids = new List<string>();
+                List<string> clds = classId.ToObject<List<string>>().ToList();
+                var queryExam = $"select c.id from c where c.period.id = '{periodId}' and array_contains(c.classes,'{clds[0]}') " +
+                    $"and c.qamode <> 2 and c.progress = 'finish' and c.scope = 'school' and c.startTime > {startTime} and c.startTime < {endTime} ";
+                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryStreamIteratorSql(queryText: queryExam, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Exam-{code}") }))
+                {
+                    using var json = await JsonDocument.ParseAsync(item.Content);
+                    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                    {
+                        var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
+                        while (accounts.MoveNext())
+                        {
+                            JsonElement account = accounts.Current;
+                            ids.Add(account.GetProperty("id").GetString());
+                        }
+                    }
+                }
+                var queryClass = $"select value(c) from c where c.info.id = '{clds[0]}'and c.examId in ({string.Join(",", ids.Select(o => $"'{o}'"))})";
+                List<ExamClassResult> classResults = new();
+                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIteratorSql<ExamClassResult>(queryText: queryClass, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{code}") }))
+                {
+                    classResults.Add(item);
+                }
+
+                //计算几次合并
+               
+                var examScore = classResults.GroupBy(c => c.subjectId).Select(x => new
+                {
+                    x.Key,
+                    cc = x.ToList().Count,
+                    students = x.ToList().SelectMany(z => z.studentIds).Distinct().ToList(),
+                    score = x.ToList().Select(k => k.sum).Aggregate((current, next) => current.Zip(next, (a, b) => a + b).ToList())
+                }) ;
+
+                List<(string sub, List<(string id, double score)> subScore,int cc)> stuScore = [];
+                foreach (var ss in examScore) {
+                    List<(string id, double score)> subScore = [];
+                    foreach (var item in ss.students) {
+                        int index = ss.students.IndexOf(item);
+                        subScore.Add((item, ss.score[index]));
+                    }
+                    stuScore.Add((ss.Key, subScore,ss.cc));
+
+                }
+                if (request.TryGetProperty("studentId", out JsonElement studentId) && !string.IsNullOrWhiteSpace($"{studentId}"))
+                {
+                    var orderScore = stuScore.Select(x => new
+                    {
+                        x.sub,
+                        classRate = x.subScore.Select(z => z.score).Sum() / x.subScore.Count,
+                        rank = x.subScore.OrderByDescending(x => x.score).Select(z => z.id).ToList().IndexOf(studentId.GetString()) + 1,
+                        stuRate = x.subScore.OrderByDescending(x => x.score).Select(z => new
+                        {
+                            z.id,
+                            per = z.score / x.cc
+                        }).ToList().Take(10)
+                    }) ;
+                    return Ok(new { orderScore, code = 200 });
+                }
+                else {
+                    var orderScore = stuScore.Select(x => new
+                    {
+                        x.sub,
+                        classRate = x.subScore.Select(z => z.score).Sum() / x.subScore.Count,
+                        stuRate = x.subScore.OrderByDescending(x => x.score).Select(z => new
+                        {
+                            z.id,
+                            per = z.score / x.cc
+                        }).ToList().Take(10)
+                    });
+                    return Ok(new { orderScore, code = 200 });
+                }
+                            
+
+            }
+            catch (Exception e)
+            {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},exam/get-exam-point()\n{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
+                return BadRequest();
+
+            }
+        }
         //TODO blob 批量删除
         //TODO blob 批量删除
         /// <summary>
         /// <summary>
         /// 删除
         /// 删除