|
@@ -18,7 +18,7 @@ namespace TEAMModelFunction
|
|
|
{
|
|
|
public class TriggerExam
|
|
|
{
|
|
|
- public static async void Trigger(AzureCosmosFactory _azureCosmos, AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, DingDing _dingDing,
|
|
|
+ public static async void Trigger( AzureCosmosFactory _azureCosmos, AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, DingDing _dingDing,
|
|
|
CosmosClient client, Document input, string code, long stime, long etime, string school)
|
|
|
{
|
|
|
ExamInfo info = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamInfo>(input.Id, new Azure.Cosmos.PartitionKey($"{code}"));
|
|
@@ -69,15 +69,15 @@ namespace TEAMModelFunction
|
|
|
message.ApplicationProperties.Add("name", "Exam");
|
|
|
if (records.Count > 0)
|
|
|
{
|
|
|
- await _serviceBus.GetServiceBusClient().cancelMessage("active-task", records[0].sequenceNumber);
|
|
|
- long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync("active-task", message, DateTimeOffset.FromUnixTimeMilliseconds(stime));
|
|
|
+ await _serviceBus.GetServiceBusClient().cancelMessage(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), records[0].sequenceNumber);
|
|
|
+ long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), message, DateTimeOffset.FromUnixTimeMilliseconds(stime));
|
|
|
records[0].sequenceNumber = start;
|
|
|
await _azureStorage.SaveOrUpdate<ChangeRecord>(records[0]);
|
|
|
//await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(record, record.id, new Azure.Cosmos.PartitionKey($"{record.code}"));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync("active-task", message, DateTimeOffset.FromUnixTimeMilliseconds(stime));
|
|
|
+ long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), message, DateTimeOffset.FromUnixTimeMilliseconds(stime));
|
|
|
ChangeRecord changeRecord = new ChangeRecord
|
|
|
{
|
|
|
RowKey = input.Id,
|
|
@@ -90,46 +90,7 @@ namespace TEAMModelFunction
|
|
|
}
|
|
|
break;
|
|
|
case "going":
|
|
|
- //ActivityData data;
|
|
|
- //if (info.scope == "school")
|
|
|
- //{
|
|
|
- // data = new ActivityData
|
|
|
- // {
|
|
|
- // id = info.id,
|
|
|
- // code = $"Activity-{info.school}",
|
|
|
- // type = "exam",
|
|
|
- // name = info.name,
|
|
|
- // startTime = info.startTime,
|
|
|
- // endTime = info.endTime,
|
|
|
- // scode = info.code,
|
|
|
- // scope = info.scope,
|
|
|
- // classes = info.classes.IsNotEmpty() ? info.classes : new List<string> { "" },
|
|
|
- // tmdids = new List<string> { "" },
|
|
|
- // progress = "going",
|
|
|
- // subjects = sub
|
|
|
- // };
|
|
|
- // await client.GetContainer("TEAMModelOS", "School").UpsertItemAsync<ActivityData>(data, new Azure.Cosmos.PartitionKey(data.code));
|
|
|
- //}
|
|
|
- //else if (info.scope == "private")
|
|
|
- //{
|
|
|
- // data = new ActivityData
|
|
|
- // {
|
|
|
- // id = info.id,
|
|
|
- // code = $"Activity-Common",
|
|
|
- // type = "exam",
|
|
|
- // name = info.name,
|
|
|
- // startTime = info.startTime,
|
|
|
- // endTime = info.endTime,
|
|
|
- // scode = info.code,
|
|
|
- // scope = info.scope,
|
|
|
- // progress = "going",
|
|
|
- // classes = info.classes.IsNotEmpty() ? info.classes : new List<string> { "" },
|
|
|
- // tmdids = new List<string> { "" },
|
|
|
- // subjects = sub
|
|
|
- // };
|
|
|
- // await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync<ActivityData>(data, new Azure.Cosmos.PartitionKey(data.code));
|
|
|
- //}
|
|
|
- (List<string> tmdids, List<Students> studentss) = await TriggerStuActivity.GetStuList(client, info.classes, info.school);
|
|
|
+ (List<string> tmdids, List<Students> studentss) = await TriggerStuActivity.GetStuList(client, _dingDing, info.classes, info.school);
|
|
|
List<StuActivity> stuActivities = new List<StuActivity>();
|
|
|
List<StuActivity> tmdActivities = new List<StuActivity>();
|
|
|
if (tmdids.IsNotEmpty())
|
|
@@ -150,7 +111,8 @@ namespace TEAMModelFunction
|
|
|
school = info.school,
|
|
|
creatorId = info.creatorId,
|
|
|
subjects = sub,
|
|
|
- blob = null
|
|
|
+ blob = null,
|
|
|
+ owner = info.owner
|
|
|
|
|
|
});
|
|
|
});
|
|
@@ -173,33 +135,33 @@ namespace TEAMModelFunction
|
|
|
school = info.school,
|
|
|
creatorId = info.creatorId,
|
|
|
subjects = sub,
|
|
|
- blob = null
|
|
|
+ blob = null,
|
|
|
+ owner = info.owner
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
- await TriggerStuActivity.SaveStuActivity(client, stuActivities, tmdActivities);
|
|
|
+ await TriggerStuActivity.SaveStuActivity(client, _dingDing, stuActivities, tmdActivities);
|
|
|
//向学生或醍摩豆账号发起通知
|
|
|
#region
|
|
|
Notice notice = new Notice()
|
|
|
{
|
|
|
- sid = info.id,
|
|
|
- scode = info.code,
|
|
|
- spk = info.pk,
|
|
|
- scope = info.scope,
|
|
|
- school = info.school,
|
|
|
- stime = info.startTime,
|
|
|
- etime = info.endTime,
|
|
|
+ msgId=info.id,
|
|
|
+ creation = info.startTime,
|
|
|
+ expire = info.endTime,
|
|
|
creatorId = info.creatorId,
|
|
|
stuids = studentss,
|
|
|
tmdids = tmdids,
|
|
|
- type = "exam-join",//评测参加通知
|
|
|
- level = 1,
|
|
|
- data = new { }.ToJsonString()
|
|
|
+ type = "notice",//评测参加通知
|
|
|
+ priority = "normal",
|
|
|
+ school = info.school,
|
|
|
+ scope = info.scope,
|
|
|
+ //data = new { }.ToJsonString()
|
|
|
+ body = new Body {sid=info.id,scode=info.code,spk=info.pk,biztype= "exam-join" }
|
|
|
|
|
|
};
|
|
|
//var messageBlob = new ServiceBusMessage(notice.ToJsonString());
|
|
|
//messageBlob.ApplicationProperties.Add("name", "Notice");
|
|
|
- //await _serviceBus.GetServiceBusClient().SendMessageAsync("active-task", messageBlob);
|
|
|
+ //await _serviceBus.GetServiceBusClient().SendMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageBlob);
|
|
|
#endregion
|
|
|
if (examClassResults.Count == 0)
|
|
|
{
|
|
@@ -322,15 +284,15 @@ namespace TEAMModelFunction
|
|
|
messageEnd.ApplicationProperties.Add("name", "Exam");
|
|
|
if (records.Count > 0)
|
|
|
{
|
|
|
- long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync("active-task", messageEnd, DateTimeOffset.FromUnixTimeMilliseconds(etime));
|
|
|
- await _serviceBus.GetServiceBusClient().cancelMessage("active-task", records[0].sequenceNumber);
|
|
|
+ long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageEnd, DateTimeOffset.FromUnixTimeMilliseconds(etime));
|
|
|
+ await _serviceBus.GetServiceBusClient().cancelMessage(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), records[0].sequenceNumber);
|
|
|
records[0].sequenceNumber = end;
|
|
|
await _azureStorage.SaveOrUpdate<ChangeRecord>(records[0]);
|
|
|
//await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(record, record.id, new Azure.Cosmos.PartitionKey($"{record.code}"));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync("active-task", messageEnd, DateTimeOffset.FromUnixTimeMilliseconds(etime));
|
|
|
+ long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageEnd, DateTimeOffset.FromUnixTimeMilliseconds(etime));
|
|
|
ChangeRecord changeRecord = new ChangeRecord
|
|
|
{
|
|
|
RowKey = input.Id,
|
|
@@ -357,97 +319,95 @@ namespace TEAMModelFunction
|
|
|
}
|
|
|
break;
|
|
|
case "finish":
|
|
|
- if (info.papers.Count > 0) {
|
|
|
- int fno = 0;
|
|
|
- foreach (ExamSubject subject in info.subjects)
|
|
|
- {
|
|
|
- await createClassResultAsync(info, examClassResults, subject, fno, _azureCosmos, _dingDing, _azureStorage);
|
|
|
- fno++;
|
|
|
- }
|
|
|
+ int fno = 0;
|
|
|
+ foreach (ExamSubject subject in info.subjects)
|
|
|
+ {
|
|
|
+ await createClassResultAsync(info, examClassResults, subject, fno, _azureCosmos, _dingDing, _azureStorage);
|
|
|
+ fno++;
|
|
|
+ }
|
|
|
|
|
|
- //计算单次考试简易统计信息
|
|
|
- List<ExamResult> examResults = new List<ExamResult>();
|
|
|
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<ExamResult>(
|
|
|
- queryText: $"select value(c) from c where c.examId = '{info.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"ExamResult-{info.id}") }))
|
|
|
+ //计算单次考试简易统计信息
|
|
|
+ List<ExamResult> examResults = new List<ExamResult>();
|
|
|
+ await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<ExamResult>(
|
|
|
+ queryText: $"select value(c) from c where c.examId = '{info.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"ExamResult-{info.id}") }))
|
|
|
+ {
|
|
|
+ examResults.Add(item);
|
|
|
+ }
|
|
|
+ //结算单科单班的标准差和平均分
|
|
|
+ foreach (ExamClassResult classResult in examClassResults)
|
|
|
+ {
|
|
|
+ //标记单科单班总得分
|
|
|
+ double subScore = 0;
|
|
|
+ //标准差
|
|
|
+ double sPowSum = 0;
|
|
|
+ var scount = classResult.studentIds.Count;
|
|
|
+ foreach (List<double> sc in classResult.studentScores)
|
|
|
{
|
|
|
- examResults.Add(item);
|
|
|
+ subScore += sc.Sum();
|
|
|
}
|
|
|
- //结算单科单班的标准差和平均分
|
|
|
- foreach (ExamClassResult classResult in examClassResults)
|
|
|
+ foreach (string sid in classResult.studentIds)
|
|
|
{
|
|
|
- //标记单科单班总得分
|
|
|
- double subScore = 0;
|
|
|
- //标准差
|
|
|
- double sPowSum = 0;
|
|
|
- var scount = classResult.studentIds.Count;
|
|
|
- foreach (List<double> sc in classResult.studentScores)
|
|
|
- {
|
|
|
- subScore += sc.Sum();
|
|
|
- }
|
|
|
- foreach (string sid in classResult.studentIds)
|
|
|
- {
|
|
|
- double ssc = classResult.studentScores[classResult.studentIds.IndexOf(sid)].Sum();
|
|
|
- sPowSum += Math.Pow(ssc - scount > 0 ? Math.Round(subScore * 1.0 / scount, 2) : 0, 2);
|
|
|
+ double ssc = classResult.studentScores[classResult.studentIds.IndexOf(sid)].Sum();
|
|
|
+ sPowSum += Math.Pow(ssc - scount > 0 ? Math.Round(subScore * 1.0 / scount, 2) : 0, 2);
|
|
|
|
|
|
- }
|
|
|
- classResult.standard = Math.Round(scount > 0 ? Math.Pow(sPowSum / scount, 0.5) : 0, 2);
|
|
|
- classResult.average = scount > 0 ? Math.Round(subScore / scount, 2) : 0;
|
|
|
- await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(classResult, classResult.id, new Azure.Cosmos.PartitionKey($"{classResult.code}"));
|
|
|
}
|
|
|
- //记录某次考试所有学生得分总分
|
|
|
- double score = 0;
|
|
|
- double allScore = 0;
|
|
|
- int stuCount = 0;
|
|
|
- //整体平均分
|
|
|
- double average = 0;
|
|
|
- //标准差
|
|
|
- double powSum = 0;
|
|
|
- List<string> losStu = new List<string>();
|
|
|
- //先与第一个值取并集
|
|
|
- if (examResults.Count > 0)
|
|
|
+ classResult.standard = Math.Round(scount > 0 ? Math.Pow(sPowSum / scount, 0.5) : 0, 2);
|
|
|
+ classResult.average = scount > 0 ? Math.Round(subScore / scount, 2) : 0;
|
|
|
+ await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(classResult, classResult.id, new Azure.Cosmos.PartitionKey($"{classResult.code}"));
|
|
|
+ }
|
|
|
+ //记录某次考试所有学生得分总分
|
|
|
+ double score = 0;
|
|
|
+ double allScore = 0;
|
|
|
+ int stuCount = 0;
|
|
|
+ //整体平均分
|
|
|
+ double average = 0;
|
|
|
+ //标准差
|
|
|
+ double powSum = 0;
|
|
|
+ List<string> losStu = new List<string>();
|
|
|
+ //先与第一个值取并集
|
|
|
+ if (examResults.Count > 0)
|
|
|
+ {
|
|
|
+ losStu.Union(examResults[0].lostStus);
|
|
|
+ foreach (ExamResult examResult in examResults)
|
|
|
{
|
|
|
- losStu.Union(examResults[0].lostStus);
|
|
|
- foreach (ExamResult examResult in examResults)
|
|
|
+ if (info.id == examResult.examId)
|
|
|
{
|
|
|
- if (info.id == examResult.examId)
|
|
|
+ foreach (List<double> sc in examResult.studentScores)
|
|
|
{
|
|
|
- foreach (List<double> sc in examResult.studentScores)
|
|
|
- {
|
|
|
- score += sc.Sum();
|
|
|
- }
|
|
|
- stuCount = examResult.studentIds.Count;
|
|
|
+ score += sc.Sum();
|
|
|
}
|
|
|
- //powSum += Math.Pow(score - examResult.studentIds.Count > 0 ? Math.Round(score * 1.0 / examResult.studentIds.Count, 2) : 0, 2);
|
|
|
- //取交集
|
|
|
- losStu = losStu.Intersect(examResult.lostStus).ToList();
|
|
|
+ stuCount = examResult.studentIds.Count;
|
|
|
}
|
|
|
+ //powSum += Math.Pow(score - examResult.studentIds.Count > 0 ? Math.Round(score * 1.0 / examResult.studentIds.Count, 2) : 0, 2);
|
|
|
+ //取交集
|
|
|
+ losStu = losStu.Intersect(examResult.lostStus).ToList();
|
|
|
}
|
|
|
- double NewsRateScore = stuCount > 0 ? Math.Round(score * 1.0 / stuCount, 2) : 0;
|
|
|
- foreach (PaperSimple simple in info.papers)
|
|
|
- {
|
|
|
- allScore += simple.point.Sum();
|
|
|
- }
|
|
|
- //计算全科标准差
|
|
|
- foreach (string id in examResults[0].studentIds)
|
|
|
- {
|
|
|
- double sc = 0;
|
|
|
- foreach (ExamResult result in examResults)
|
|
|
- {
|
|
|
- sc += result.studentScores[result.studentIds.IndexOf(id)].Sum();
|
|
|
- }
|
|
|
- powSum += Math.Pow(sc - NewsRateScore, 2);
|
|
|
- }
|
|
|
- info.standard = Math.Round(examResults[0].studentIds.Count > 0 ? Math.Pow(powSum / examResults[0].studentIds.Count, 0.5) : 0, 2);
|
|
|
- double NewsRate = allScore > 0 ? Math.Round(NewsRateScore / allScore * 100, 2) : 0;
|
|
|
- info.lostStu = losStu;
|
|
|
- //判断均分是否发生变化,便于实时的更新评测基本信息
|
|
|
- if (info.sRate != NewsRate || info.average != NewsRateScore)
|
|
|
+ }
|
|
|
+ double NewsRateScore = stuCount > 0 ? Math.Round(score * 1.0 / stuCount, 2) : 0;
|
|
|
+ foreach (PaperSimple simple in info.papers)
|
|
|
+ {
|
|
|
+ allScore += simple.point.Sum();
|
|
|
+ }
|
|
|
+ //计算全科标准差
|
|
|
+ foreach (string id in examResults[0].studentIds)
|
|
|
+ {
|
|
|
+ double sc = 0;
|
|
|
+ foreach (ExamResult result in examResults)
|
|
|
{
|
|
|
- info.sRate = NewsRate;
|
|
|
- info.average = NewsRateScore;
|
|
|
- await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync<ExamInfo>(info, info.id, new Azure.Cosmos.PartitionKey(info.code));
|
|
|
+ sc += result.studentScores[result.studentIds.IndexOf(id)].Sum();
|
|
|
}
|
|
|
- }
|
|
|
+ powSum += Math.Pow(sc - NewsRateScore, 2);
|
|
|
+ }
|
|
|
+ info.standard = Math.Round(examResults[0].studentIds.Count > 0 ? Math.Pow(powSum / examResults[0].studentIds.Count, 0.5) : 0, 2);
|
|
|
+ double NewsRate = allScore > 0 ? Math.Round(NewsRateScore / allScore * 100, 2) : 0;
|
|
|
+ info.lostStu = losStu;
|
|
|
+ //判断均分是否发生变化,便于实时的更新评测基本信息
|
|
|
+ if (info.sRate != NewsRate || info.average != NewsRateScore)
|
|
|
+ {
|
|
|
+ info.sRate = NewsRate;
|
|
|
+ info.average = NewsRateScore;
|
|
|
+ await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync<ExamInfo>(info, info.id, new Azure.Cosmos.PartitionKey(info.code));
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
}
|