123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- using Azure.Cosmos;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.Json;
- using System.Threading.Tasks;
- using TEAMModelOS.SDK.DI;
- namespace TEAMModelOS.SDK.Models.Service
- {
- public static class ExamService
- {
- public static List<string> getClasses(List<string> cla, List<string> stus)
- {
- List<string> classes = new List<string>();
- try
- {
- if (cla.Count > 0)
- {
- foreach (string cl in cla)
- {
- classes.Add(cl);
- }
- }
- if (stus.Count > 0)
- {
- foreach (string stu in stus)
- {
- classes.Add(stu);
- }
- }
- return classes;
- }
- catch (Exception)
- {
- return classes;
- }
- }
- public static async Task deleteAsync(CosmosClient client, string id, string tId)
- {
- List<string> correctIds = new List<string>();
- 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}");
- }
- }
- public static async Task<string> saveMoreAsync(CosmosClient client, DingDing _dingDing, ExamLite trExam)
- {
- try
- {
- trExam.ttl = -1;
- trExam.code = "ExamLite-" + trExam.school;
- trExam.scope = "school";
- long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
- trExam.createTime = now;
- if (trExam.publish == 1)
- {
- trExam.progress = "pending";
- }
- else
- {
- if (trExam.startTime > now)
- {
- trExam.progress = "pending";
- }
- else
- {
- trExam.progress = "going";
- }
- }
- if (string.IsNullOrEmpty(trExam.id))
- {
- trExam.id = Guid.NewGuid().ToString();
- await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(trExam, new PartitionKey($"{trExam.code}"));
- }
- else
- {
- await client.GetContainer("TEAMModelOS", "Common").UpsertItemAsync(trExam, new PartitionKey($"{trExam.code}"));
- }
- return trExam.id;
- }
- catch (Exception e)
- {
- await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ExamService-saveMore\n{e.Message}{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
- return "";
- }
- }
- /*
- 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))
- {
- foreach (List<string> str in kones)
- {
- 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;
- }
- }
- double per = count > 0 ? Math.Round(score / count, 2) : 0;
- }
- }*/
- }
- }
|