|
@@ -1,4 +1,6 @@
|
|
|
using Azure.Cosmos;
|
|
|
+using DocumentFormat.OpenXml.Office2010.Excel;
|
|
|
+using MathNet.Numerics.Distributions;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
@@ -6,6 +8,7 @@ using System.Text;
|
|
|
using System.Text.Json;
|
|
|
using System.Threading.Tasks;
|
|
|
using TEAMModelOS.SDK.DI;
|
|
|
+using TEAMModelOS.SDK.Extension;
|
|
|
|
|
|
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)
|
|
|
{
|
|
|
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;
|
|
|
- }
|
|
|
- }*/
|
|
|
+ }*/
|
|
|
}
|
|
|
}
|