12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013 |
- using Microsoft.Azure.Cosmos;
- using ClouDASLibx;
- using Google.Protobuf.WellKnownTypes;
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Options;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.Json;
- using System.Threading.Tasks;
- using TEAMModelOS.Filter;
- using TEAMModelOS.SDK;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK.Extension;
- using TEAMModelOS.SDK.Helper.Common.StringHelper;
- using TEAMModelOS.SDK.Models;
- using TEAMModelOS.SDK.Models.Cosmos.Student;
- using StackExchange.Redis;
- namespace TEAMModelOS.Controllers.Analysis
- {
- [Route("analysis/art")]
- [ApiController]
- public class ArtAnalysisController : ControllerBase
- {
- private readonly AzureCosmosFactory _azureCosmos;
- private readonly DingDing _dingDing;
- private readonly Option _option;
- private readonly CoreAPIHttpService _coreAPIHttpService;
- private readonly AzureStorageFactory _azureStorage;
- private readonly AzureRedisFactory _azureRedis;
- public ArtAnalysisController(AzureCosmosFactory azureCosmos, DingDing dingDing, IOptionsSnapshot<Option> option, CoreAPIHttpService coreAPIHttpService, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis)
- {
- _azureCosmos = azureCosmos;
- _dingDing = dingDing;
- _option = option?.Value;
- _coreAPIHttpService = coreAPIHttpService;
- _azureStorage = azureStorage;
- _azureRedis = azureRedis;
- }
- /* [ProducesDefaultResponseType]
- [HttpPost("find")]
- //[Authorize(Roles = "IES")]
- //[AuthToken(Roles = "teacher,admin")]
- public async Task<IActionResult> find(JsonElement request)
- {
- if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
- var client = _azureCosmos.GetCosmosClient();
- List<ArtEvaluation> arts = new();
- try {
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryStreamIteratorSql(queryText: $"SELECT top 1 * FROM c where c.period.id ='{period}' order by c.createTime ",
- requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Art-{code}") }))
- {
- using var json = await JsonDocument.ParseAsync(item.Content);
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
- {
- arts.Add(obj.ToObject<ArtEvaluation>());
- }
- }
- } catch (Exception ex) {
- await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-analysis/art,find()\n{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
- }
- }*/
- [ProducesDefaultResponseType]
- [HttpPost("statistics")]
- //[Authorize(Roles = "IES")]
- //[AuthToken(Roles = "teacher,admin")]
- public async Task<IActionResult> getAnalysis(JsonElement request)
- {
- var client = _azureCosmos.GetCosmosClient();
- if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
- if (!request.TryGetProperty("periodId", out JsonElement periodId)) return BadRequest();
- if (!request.TryGetProperty("subjectId", out JsonElement subjectId)) return BadRequest();
- if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
- if (!request.TryGetProperty("classIds", out JsonElement cIds)) return BadRequest();
- if (!request.TryGetProperty("examId", out JsonElement examId)) return BadRequest();
- try
- {
- /*string url = string.Empty;
- if (!_azureStorage.GetBlobContainerClient($"{code}").GetBlobClient($"/art/{id}/{subjectId}.json").Exists())
- {*/
- List<ArtSubjectScore> As = new();
- List<(List<ArtSubjectScore> scs, string sIds, string cd)> stus = new();
- //List<ArtEvaluation> arts = new();
- string artId = id.GetString();
- List<string> classIds = cIds.ToObject<List<string>>();
- if (classIds.Count == 1)
- {
- RedisValue value = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:students:{code}:{classIds[0]}", $"students:{subjectId}:{id}");
- if (value != default && !value.IsNullOrEmpty)
- {
- var value_count = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:count:{code}", $"count:{subjectId}:{id}");
- var value_max = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:max:{code}", $"max:{subjectId}:{id}");
- var value_min = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:min:{code}", $"min:{subjectId}:{id}");
- var value_average = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:average:{code}:{classIds[0]}", $"average:{subjectId}:{id}");
- var value_excellent = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:excellent:{code}:{classIds[0]}", $"excellent:{subjectId}:{id}");
- var value_pass = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:pass:{code}:{classIds[0]}", $"pass:{subjectId}:{id}");
- var value_pow = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:pow:{code}:{classIds[0]}", $"pow:{subjectId}:{id}");
- var value_blks = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:blk:{code}", $"blk:{subjectId}:{id}");
- var value_kno = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:kno:{code}", $"kno:{subjectId}:{id}");
- var value_dim = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:dim:{code}", $"dim:{subjectId}:{id}");
- var value_optCount = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:optCount:{code}", $"optCount:{subjectId}:{id}");
- var value_realClassCount = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:realClassCount:{code}", $"realClassCount:{subjectId}:{id}");
- var value_cInfo = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:cInfo:{code}:{classIds[0]}", $"cInfo:{subjectId}:{id}");
- var value_gscore = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:gscore:{code}", $"gscore:{subjectId}:{id}");
- var count_1 = value_count.ToString().ToObject<JsonElement>();
- var scount_1 = value_realClassCount.ToString().ToObject<JsonElement>();
- var max_1 = value_max.ToString().ToObject<JsonElement>();
- var min_1 = value_min.ToString().ToObject<JsonElement>();
- var average_1 = value_average.ToString().ToObject<JsonElement>();
- var excellent_1 = value_excellent.ToString().ToObject<JsonElement>();
- var pass_1 = value_pass.ToString().ToObject<JsonElement>();
- var pow_1 = value_pow.ToString().ToObject<JsonElement>();
- var blk_1 = value_blks.ToString().ToObject<JsonElement>();
- var kno_1 = value_kno.ToString().ToObject<JsonElement>();
- var dim_1 = value_dim.ToString().ToObject<JsonElement>();
- var optCount_1 = value_optCount.ToString().ToObject<JsonElement>();
- var students_1 = value.ToString().ToObject<JsonElement>();
- var cInfo_1 = value_cInfo.ToString().ToObject<JsonElement>();
- var gscore_1 = value_gscore.ToString().ToObject<JsonElement>();
- return Ok(new
- {
- count = count_1,
- scount = scount_1,
- max = max_1,
- min = min_1,
- average = average_1,
- excellent = excellent_1,
- pass = pass_1,
- pow = pow_1,
- blk = blk_1,
- kno = kno_1,
- dim = dim_1,
- optCount = optCount_1,
- students = students_1,
- cInfo = cInfo_1,
- gscore = gscore_1
- });
- }
- }
- else if (classIds.Count == 0)
- {
- RedisValue value = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:grade:{code}:{classIds[0]}", $"grade:{subjectId}:{id}");
- if (value != default && !value.IsNullOrEmpty)
- {
- var value_count = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:count:{code}", $"count:{subjectId}:{id}");
- var value_max = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:max:{code}", $"max:{subjectId}:{id}");
- var value_min = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:min:{code}", $"min:{subjectId}:{id}");
- var value_average = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:average:{code}", $"average:{subjectId}:{id}");
- var value_excellent = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:excellent:{code}", $"excellent:{subjectId}:{id}");
- var value_pass = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:pass:{code}", $"pass:{subjectId}:{id}");
- var value_pow = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:pow:{code}", $"pow:{subjectId}:{id}");
- var value_blks = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:blk:{code}", $"blk:{subjectId}:{id}");
- var value_kno = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:kno:{code}", $"kno:{subjectId}:{id}");
- var value_dim = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:dim:{code}", $"dim:{subjectId}:{id}");
- var value_optCount = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:optCount:{code}", $"optCount:{subjectId}:{id}");
- var value_scount = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:scount:{code}", $"scount:{subjectId}:{id}");
- var count_1 = value_count.ToString().ToObject<JsonElement>();
- var scount_1 = value_scount.ToString().ToObject<JsonElement>();
- var max_1 = value_max.ToString().ToObject<JsonElement>();
- var min_1 = value_min.ToString().ToObject<JsonElement>();
- var average_1 = value_average.ToString().ToObject<JsonElement>();
- var excellent_1 = value_excellent.ToString().ToObject<JsonElement>();
- var pass_1 = value_pass.ToString().ToObject<JsonElement>();
- var pow_1 = value_pow.ToString().ToObject<JsonElement>();
- var blk_1 = value_blks.ToString().ToObject<JsonElement>();
- var kno_1 = value_kno.ToString().ToObject<JsonElement>();
- var dim_1 = value_dim.ToString().ToObject<JsonElement>();
- var optCount_1 = value_optCount.ToString().ToObject<JsonElement>();
- return Ok(new
- {
- count = count_1,
- scount = scount_1,
- max = max_1,
- min = min_1,
- average = average_1,
- excellent = excellent_1,
- pass = pass_1,
- pow = pow_1,
- blk = blk_1,
- kno = kno_1,
- dim = dim_1,
- optCount = optCount_1,
- });
- }
- }
- else {
- RedisValue value = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:cInfo:{code}", $"cInfo:{subjectId}:{id}");
- if (value != default && !value.IsNullOrEmpty)
- {
- var value_count = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:count:{code}", $"count:{subjectId}:{id}");
- var value_max = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:max:{code}", $"max:{subjectId}:{id}");
- var value_min = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:min:{code}", $"min:{subjectId}:{id}");
- var value_average = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:average:{code}", $"average:{subjectId}:{id}");
- var value_excellent = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:excellent:{code}", $"excellent:{subjectId}:{id}");
- var value_pass = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:pass:{code}", $"pass:{subjectId}:{id}");
- var value_pow = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:pow:{code}", $"pow:{subjectId}:{id}");
- var value_blks = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:blk:{code}", $"blk:{subjectId}:{id}");
- var value_kno = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:kno:{code}", $"kno:{subjectId}:{id}");
- var value_dim = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:dim:{code}", $"dim:{subjectId}:{id}");
- var value_optCount = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:optCount:{code}", $"optCount:{subjectId}:{id}");
- var value_scount = await _azureRedis.GetRedisClient(8).HashGetAsync($"ArtSchool:scount:{code}", $"scount:{subjectId}:{id}");
- var count_1 = value_count.ToString().ToObject<JsonElement>();
- var scount_1 = value_scount.ToString().ToObject<JsonElement>();
- var max_1 = value_max.ToString().ToObject<JsonElement>();
- var min_1 = value_min.ToString().ToObject<JsonElement>();
- var average_1 = value_average.ToString().ToObject<JsonElement>();
- var excellent_1 = value_excellent.ToString().ToObject<JsonElement>();
- var pass_1 = value_pass.ToString().ToObject<JsonElement>();
- var pow_1 = value_pow.ToString().ToObject<JsonElement>();
- var blk_1 = value_blks.ToString().ToObject<JsonElement>();
- var kno_1 = value_kno.ToString().ToObject<JsonElement>();
- var dim_1 = value_dim.ToString().ToObject<JsonElement>();
- var optCount_1 = value_optCount.ToString().ToObject<JsonElement>();
- var cInfo_1 = value.ToString().ToObject<JsonElement>();
- return Ok(new
- {
- count = count_1,
- scount = scount_1,
- max = max_1,
- min = min_1,
- average = average_1,
- excellent = excellent_1,
- pass = pass_1,
- pow = pow_1,
- blk = blk_1,
- kno = kno_1,
- dim = dim_1,
- optCount = optCount_1,
- cInfo = cInfo_1
- });
- }
- }
- if (!request.TryGetProperty("areaId", out JsonElement _areaId)) return BadRequest();
- ArtSetting setting = await client.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<ArtSetting>($"{_areaId}", partitionKey: new PartitionKey("ArtSetting"));
- //学校基本信息
- School scInfo = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>($"{code}", partitionKey: new PartitionKey("Base"));
- var perMore = scInfo.period.Where(c => c.id.Equals(periodId.GetString())).FirstOrDefault()?.grades;
- string queryScore = $" select c.studentId,c.classIds,c.totalScore,c.subjectScores,c.results from c ";
- if (classIds.Count == 1)
- {
- queryScore = $" select c.studentId,c.classIds,c.totalScore,c.subjectScores,c.results from c where array_contains(c.classIds,'{classIds[0]}') ";
- }
- //List<(string stu,List<string> cId)> clads = new();
- List<List<ArtQuotaResult>> results = new();
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Student).GetItemQueryStreamIteratorSql
- (queryText: queryScore, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"ArtResult-{artId}") }))
- {
- using var json = await JsonDocument.ParseAsync(item.Content);
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
- {
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
- {
- if (obj.TryGetProperty("subjectScores", out JsonElement subScore))
- {
- string sId = obj.GetProperty("studentId").GetString();
- List<ArtSubjectScore> sc = subScore.ToObject<List<ArtSubjectScore>>();
- string cd = obj.GetProperty("classIds").ToObject<List<string>>()[0];
- //clads.Add((sId,obj.GetProperty("classIds").ToObject<List<string>>()));
- As.AddRange(sc);
- stus.Add((sc, sId, cd));
- }
- else
- {
- As.AddRange(new List<ArtSubjectScore>());
- }
- results.Add(obj.GetProperty("results").ToObject<List<ArtQuotaResult>>());
- }
- }
- }
- var subjectScore = new
- {
- name = As.Where(a => a.subjectId.Equals(subjectId.GetString())).Select(x => x.score).Where(c => c > 0)
- };
- double max = subjectScore.name.Max(s => Math.Abs(s));
- double min = subjectScore.name.Min(s => Math.Abs(s));
- double total = subjectScore.name.Sum();
-
- //获取本次评测所有科目结算结果
- List<ExamResult> examResults = new();
- List<ExamClassResult> classResults = [];
- ExamInfo info = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(examId.ToString(), new PartitionKey($"Exam-{code}"));
- var query = $"select value(c) from c where c.examId = '{examId}' and c.subjectId = '{subjectId}' ";
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIteratorSql<ExamClassResult>(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{code}") }))
- {
- classResults.Add(item);
- }
- (List<RMember> tchList, List<RGroupList> classLists) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, classIds, code.GetString(), null, -1, info.startTime);
- //获取评测ID
- //var examId = arts[0].settings.SelectMany(s => s.task).Where(a => a.type == 1 && a.subject.Equals(subjectId.GetString())).FirstOrDefault().acId;
- //根据科目标识获取科目ID以及知识块和知识点关系TODO 引用不同试卷时 获取知识点得差异
- int index = 0;
- foreach (var pr in info.subjects)
- {
- if (pr.id.Equals(subjectId.GetString()))
- {
- break;
- }
- index++;
- }
- List<(string name, List<string> kno)> knos = new();
- if (string.IsNullOrEmpty(info.papers[index].periodId))
- {
- (string subId, List<(string name, List<string> kno)> values) = await getKnowledge("hbcn", client, subjectId.GetString(), "be32942d-97a9-52ba-45d6-2e5b722583f5");
- knos = values;
- }
- else
- {
- (string subId, List<(string name, List<string> kno)> values) = await getKnowledge(info.papers[index].code, client, subjectId.GetString(), info.papers[index].periodId);
- knos = values;
- }
- var queryClassResult = $"select c.id,c.name,c.subjectId,c.studentScores,c.studentIds,c.paper,c.classes,c.sRate,c.average,c.standard,c.lostStus,c.record,c.phc,c.plc from c where c.examId = '{examId}' and c.subjectId = '{subjectId}' ";
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIteratorSql<ExamResult>(queryText: queryClassResult, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamResult-{examId}") }))
- {
- examResults.Add(item);
- }
- List<KeyValuePair<string, List<(string name, double score, double aver)>>> pointPersent = new();
- List<KeyValuePair<string, List<(string name, double score, double point, string sId)>>> stuPersent = new();
- (KeyValuePair<string, List<string>> key1, KeyValuePair<string, List<string>> key2, KeyValuePair<string, List<(string name, double score, double average)>> key3,
- KeyValuePair<string, List<(string name, double score)>> key4, KeyValuePair<string, List<(string name, double score, double point, string cId)>> key5,
- KeyValuePair<string, List<(string name, double score, double point, string sId)>> key6, KeyValuePair<string, double> key7) = DoKnowledgePoint(examResults[0], info);
- //KeyValuePair<string, List<(string id, double sta, double pass, string stu)>> key = DoSubjectScatter(examResults[0]);
- pointPersent.Add(key3);
- stuPersent.Add(key6);
- List<(string name, double score, double av)> blockScore = new();
- List<(string name, double score, double av, string sId)> stuBlockScore = new();
- List<(string name, double score, double av, string cId)> claBlockScore = new();
- foreach (var block in knos)
- {
- double sc = 0;
- double av = 0;
- foreach (var no in pointPersent)
- {
- foreach (var (name, score, aver) in no.Value)
- {
- if (null != block.kno && block.kno.Contains(name))
- {
- sc += score;
- av += aver;
- }
- }
- }
- foreach (var (name, score, point, sId) in key6.Value)
- {
- double realScore = 0;
- double realPoint = 0;
- if (null != block.kno && block.kno.Contains(name))
- {
- realScore = score;
- realPoint = point;
- }
- stuBlockScore.Add((block.name, realScore, realPoint, sId));
- }
- foreach (var (name, score, point, cId) in key5.Value)
- {
- double realScore = 0;
- double realPoint = 0;
- if (null != block.kno && block.kno.Contains(name))
- {
- realScore = score;
- realPoint = point;
- }
- claBlockScore.Add((block.name, realScore, realPoint, cId));
- }
- blockScore.Add((block.name, sc, av));
- }
- var stuBlock = stuBlockScore.GroupBy(x => x.sId).Select(z => new
- {
- z.Key,
- block = z.ToList().GroupBy(c => c.name).Select(k => new
- {
- k.Key,
- score = k.ToList().Sum(p => p.score),
- point = k.ToList().Sum(p => p.av)
- })
- });
- var claBlock = claBlockScore.GroupBy(x => x.cId).Select(z => new
- {
- z.Key,
- block = z.ToList().GroupBy(c => c.name).Select(k => new
- {
- k.Key,
- score = k.ToList().Sum(p => p.score),
- point = k.ToList().Sum(p => p.av)
- })
- });
- var blk = blockScore.Select(x => new
- {
- x.name,
- x.score,
- persent = Math.Round(x.score > 0 ? x.av / x.score : 0, 4),
- dimension = setting.dimensions.Where(s => s.blocks.Contains(x.name)).Select(x => x.dimension)
- });
- //获取维度得分率
- List<(string stuId, double score, double point, string dim)> stuDims = new();
- List<(string claId, double score, double point, string dim)> claDims = new();
- foreach (var dimm in setting.dimensions)
- {
- if (dimm.subjectBind.Equals(subjectId.GetString()))
- {
- foreach (var stuDim in stuBlock)
- {
- double dimSScore = 0;
- double dimSPoint = 0;
- foreach (var dd in stuDim.block)
- {
- if (dimm.blocks.Contains(dd.Key))
- {
- dimSScore += dd.score;
- dimSPoint += dd.point;
- }
- }
- stuDims.Add((stuDim.Key, dimSScore, dimSPoint, dimm.dimension));
- }
- foreach (var claDim in claBlock)
- {
- double dimCScore = 0;
- double dimCPoint = 0;
- foreach (var dd in claDim.block)
- {
- if (dimm.blocks.Contains(dd.Key))
- {
- dimCScore += dd.score;
- dimCPoint += dd.point;
- }
- }
- claDims.Add((claDim.Key, dimCScore, dimCPoint, dimm.dimension));
- }
- }
- }
- var dim = setting.dimensions.Where(q => q.subjectBind.Equals(subjectId.GetString())).Select(x => new
- {
- x.dimension,
- persent = Math.Round(x.blocks.Select(c => new
- {
- persent =
- blockScore.Where(z => z.name.Equals(c)).Sum(v => v.score) > 0 ?
- blockScore.Where(z => z.name.Equals(c)).Sum(v => v.av) / blockScore.Where(z => z.name.Equals(c)).Sum(v => v.score) : 0
- }).Sum(o => o.persent), 4)
- });
- var kno = key4.Value.Select(x => new
- {
- x.name,
- persent = x.score,
- block = knos.Where(v => null != v.kno && v.kno.Contains(x.name)).Select(x => x.name)
- });
- var stuInfo = stus.Select(c => new
- {
- c.scs,
- c.sIds,
- c.cd
- });
- List<(string id, double score, string name, string classId, string className,string gradeId, List<(string kname, double persent, List<string> blok)> kno,
- List<(string kname, double persent)> block, List<(string kname, double persent)> dim)> stuAsync = [];
- await foreach (var ss in stuTask(stus, tchList, examResults, subjectId.GetString(), key6, knos, stuBlockScore, stuDims))
- {
- stuAsync = ss.students;
- }
- var students = stuAsync.Select(c => new {
- c.id,
- c.score,
- c.name,
- c.classId,
- c.className,
- c.gradeId,
- kno = c.kno.Select(x => new { name = x.kname,x.persent,x.blok}),
- block = c.block.Select(x => new { name = x.kname ,x.persent }),
- dim = c.dim.Select(x => new { name = x.kname, x.persent })
- });
- //学生信息
- /*var students = stus.Select(s => new
- {
- id = s.sIds,
- s.scs.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.subjectId) && x.subjectId.Equals(subjectId.GetString()))?.score,
- tchList.Where(t => t.id.Equals(s.sIds)).FirstOrDefault()?.name,
- classId = s.cd,
- className = examResults[0].classes.Where(c => c.id.Equals(s.cd)).FirstOrDefault()?.name,
- examResults[0].classes.Where(c => c.id.Equals(s.cd)).FirstOrDefault()?.gradeId,
- //key.Value.Where(c => c.id.Equals(s.sIds))?.FirstOrDefault().sta,
- //key.Value.Where(c => c.id.Equals(s.sIds))?.FirstOrDefault().pass,
- // key.Value.Where(c => c.id.Equals(s.sIds))?.FirstOrDefault().stu,
- kno = key6.Value.Where(c => c.sId.Equals(s.sIds))?.Select(z => new
- {
- z.name,
- persent = z.point > 0 ? Math.Round(z.score / z.point, 4) : 0,
- block = knos.Where(v => null != v.kno && v.kno.Contains(z.name))?.Select(x => x.name)
- }),
- block = stuBlock.Where(c => c.Key.Equals(s.sIds)).FirstOrDefault()?.block.Select(x => new
- {
- name = x.Key,
- persent = x.point > 0 ? Math.Round(x.score / x.point, 4) : 0
- }),
- dim = stuDims.Where(c => c.stuId.Equals(s.sIds))?.Select(z => new
- {
- name = z.dim,
- persent = z.point > 0 ? Math.Round(z.score / z.point, 4) : 0
- })
- });*/
- //List<(string cId, double sc, double max, double min, double excellent, double pass, double count)> clsInfo = new();
- var cInfo = students.GroupBy(c => (c.classId, c.className)).Select(x => new
- {
- id = x.Key.classId,
- name = x.Key.className,
- max = x.ToList().Where(p => p.score > 0).Select(z => z.score).ToList().Count > 0 ? x.ToList().Where(p => p.score > 0).Select(z => z.score).ToList().Max(s => Math.Abs((double)s)) : 0,
- min = x.ToList().Where(p => p.score > 0).Select(z => z.score).ToList().Count > 0 ? x.ToList().Where(p => p.score > 0).Select(z => z.score).ToList().Min(s => Math.Abs((double)s)) : 0,
- excellent = x.ToList().Where(p => p.score > 0).Select(z => z.score).ToList().Count > 0 ? Math.Round(x.ToList().Where(p => p.score > 0).Select(z => z.score).ToList().Where(s => s >= 80).Count() * 1.0 / x.ToList().Count, 4) : 0,
- pass = x.ToList().Where(p => p.score > 0).Select(z => z.score).ToList().Count > 0 ? Math.Round(x.ToList().Where(p => p.score > 0).Select(z => z.score).ToList().Where(s => s >= 60).Count() * 1.0 / x.ToList().Count, 4) : 0,
- score = x.ToList().Count > 0 ? Math.Round((double)x.ToList().Sum(z => z.score) * 1.0 / x.ToList().Count, 2) : 0,
- persent = x.ToList().Count > 0 ? Math.Round((double)x.ToList().Sum(z => z.score) * 1.0 / x.ToList().Count / key7.Value, 4) : 0,
- kno = key5.Value.Where(c => c.cId.Equals(x.Key.classId)).Select(z => new
- {
- z.name,
- persent = Math.Round(z.point > 0 ? z.score / z.point : 0, 4),
- block = knos.Where(v => null != v.kno && v.kno.Contains(z.name)).Select(x => x.name)
- }),
- block = claBlock.Count() > 0 ? claBlock.Where(c => c.Key.Equals(x.Key.classId))?.FirstOrDefault().block.Select(z => new
- {
- name = z.Key,
- persent = Math.Round(z.point > 0 ? z.score / z.point : 0, 4)
- }) : null,
- dim = claDims.Where(c => c.claId.Equals(x.Key.classId)).Select(z => new
- {
- name = z.dim,
- persent = Math.Round(z.point > 0 ? z.score / z.point : 0, 4)
- }),
- examResults[0].classes.Where(c => c.id.Equals(x.Key.classId))?.FirstOrDefault().gradeId
- });
-
-
- //年级信息
- var grades = students.GroupBy(c => c.gradeId).Select(x => new { gradeId = x.Key, list = x.ToList().Select(v => v.score).Where(c => c > 0) });
- var gscore = grades.Select(x => new
- {
- id = x.gradeId,
- name = perMore[int.Parse(x.gradeId)],
- score = x.list.Any() ? Math.Round((double)(x.list.Sum() / x.list.Count()), 2) : 0,
- persent = x.list.Any() ? Math.Round((double)(x.list.Sum() / x.list.Count()) / key7.Value, 4) : 0,
- max = x.list.Any() ? x.list.Max(s => Math.Abs((double)s)) : 0,
- min = x.list.Any() ? x.list.Min(s => Math.Abs((double)s)) : 0,
- excellent = x.list.Any() ? Math.Round(x.list.Where(s => s >= 80).Count() * 1.0 / x.list.Count(), 4) : 0,
- pass = x.list.Any() ? Math.Round(x.list.Where(s => s >= 60).Count() * 1.0 / x.list.Count(), 4) : 0
- });
- //获奖次数
- List<ArtAttachment> artAttachments = new();
- string sqlTask = $"select value(c) from c where c.artId = '{id}' and c.subjectId = '{subjectId}'";
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).
- GetItemQueryIteratorSql<ArtAttachment>(queryText: sqlTask, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"ArtAttachment-{code}") }))
- {
- artAttachments.Add(item);
- }
- List<int> level = artAttachments.Where(z => z.level > -1).Select(c => c.level).ToList();
- //List<Dictionary<string, int>> recorde = new List<Dictionary<string, int>>();
- Dictionary<int, int> optCount = new Dictionary<int, int>();
- foreach (var s in level)
- {
- if (optCount.ContainsKey(s))
- {
- optCount[s] = optCount[s] + 1;
- }
- else
- {
- optCount[s] = 1;
- }
- }
- //var Analysis_school = new { count = tchList.Count, scount = stus.Count - info.lostStu.Count, max, min, average, excellent, pass, pow, students, cInfo, blk, kno, dim, optCount, gscore };
- //url = await _azureStorage.GetBlobContainerClient($"{code}").UploadFileByContainer(Analysis_school.ToJsonString(), $"art/{id}", $"{subjectId}.json");
- /* }
- else {
- url = _azureStorage.GetBlobContainerClient($"{code}").GetBlobClient($"/art/{id}/{subjectId}.json").Uri.ToString();
- }*/
- var realCount = stus.Count - info.lostStu.Count;
- await _azureRedis.GetRedisClient(8).HashSetAsync($"ArtSchool:count:{code}", $"count:{subjectId}:{id}", tchList.Count.ToJsonString());
- await _azureRedis.GetRedisClient(8).HashSetAsync($"ArtSchool:max:{code}", $"max:{subjectId}:{id}", max.ToJsonString());
- await _azureRedis.GetRedisClient(8).HashSetAsync($"ArtSchool:min:{code}", $"min:{subjectId}:{id}", min.ToJsonString());
- await _azureRedis.GetRedisClient(8).HashSetAsync($"ArtSchool:blk:{code}", $"blk:{subjectId}:{id}", blk.ToJsonString());
- await _azureRedis.GetRedisClient(8).HashSetAsync($"ArtSchool:kno:{code}", $"kno:{subjectId}:{id}", kno.ToJsonString());
- await _azureRedis.GetRedisClient(8).HashSetAsync($"ArtSchool:dim:{code}", $"dim:{subjectId}:{id}", dim.ToJsonString());
- await _azureRedis.GetRedisClient(8).HashSetAsync($"ArtSchool:optCount:{code}", $"optCount:{subjectId}:{id}", optCount.ToJsonString());
- if (classIds.Count == 1)
- {
- var realClassCount = classResults.Where(c => c.info.id.Equals(classIds[0])).SelectMany(z => z.status).Count(k => k == 0);
- double average = Math.Round(total / realClassCount, 2);
- double excellent = Math.Round(subjectScore.name.Where(s => s >= 80).Count() * 1.0 / realClassCount, 2);
- double pass = Math.Round(subjectScore.name.Where(s => s >= 60).Count() * 1.0 / realClassCount, 2);
- double powSum = 0;
- foreach (var sc in subjectScore.name)
- {
- powSum += Math.Pow(sc - average, 2);
- }
- var pow = Math.Round(realClassCount > 0 ? Math.Pow(powSum / realClassCount, 0.5) : 0, 2);
-
- await _azureRedis.GetRedisClient(8).HashSetAsync($"ArtSchool:realClassCount:{code}", $"realClassCount:{subjectId}:{id}", realClassCount);
- await _azureRedis.GetRedisClient(8).HashSetAsync($"ArtSchool:students:{code}:{classIds[0]}", $"students:{subjectId}:{id}", students.ToJsonString());
- await _azureRedis.GetRedisClient(8).HashSetAsync($"ArtSchool:gscore:{code}", $"gscore:{subjectId}:{id}", gscore.ToJsonString());
- await _azureRedis.GetRedisClient(8).HashSetAsync($"ArtSchool:cInfo:{code}:{classIds[0]}", $"cInfo:{subjectId}:{id}", cInfo.ToJsonString());
- await _azureRedis.GetRedisClient(8).HashSetAsync($"ArtSchool:average:{code}:{classIds[0]}", $"average:{subjectId}:{id}", average.ToJsonString());
- await _azureRedis.GetRedisClient(8).HashSetAsync($"ArtSchool:excellent:{code}:{classIds[0]}", $"excellent:{subjectId}:{id}", excellent.ToJsonString());
- await _azureRedis.GetRedisClient(8).HashSetAsync($"ArtSchool:pass:{code}:{classIds[0]}", $"pass:{subjectId}:{id}", pass.ToJsonString());
- await _azureRedis.GetRedisClient(8).HashSetAsync($"ArtSchool:pow:{code}:{classIds[0]}", $"pow:{subjectId}:{id}", pow.ToJsonString());
- return Ok(new { count = tchList.Count, scount = realClassCount, max, min, average, excellent, pass, pow, blk, kno, dim, optCount, students, cInfo, gscore });
- }
- else if (classIds.Count == 0)
- {
- double average = Math.Round(total / realCount, 2);
- double excellent = Math.Round(subjectScore.name.Where(s => s >= 80).Count() * 1.0 / realCount, 2);
- double pass = Math.Round(subjectScore.name.Where(s => s >= 60).Count() * 1.0 / realCount, 2);
- double powSum = 0;
- foreach (var sc in subjectScore.name)
- {
- powSum += Math.Pow(sc - average, 2);
- }
- var pow = Math.Round(realCount > 0 ? Math.Pow(powSum / realCount, 0.5) : 0, 2);
- await _azureRedis.GetRedisClient(8).HashSetAsync($"ArtSchool:average:{code}", $"average:{subjectId}:{id}", average.ToJsonString());
- await _azureRedis.GetRedisClient(8).HashSetAsync($"ArtSchool:excellent:{code}", $"excellent:{subjectId}:{id}", excellent.ToJsonString());
- await _azureRedis.GetRedisClient(8).HashSetAsync($"ArtSchool:pass:{code}", $"pass:{subjectId}:{id}", pass.ToJsonString());
- await _azureRedis.GetRedisClient(8).HashSetAsync($"ArtSchool:pow:{code}", $"pow:{subjectId}:{id}", pow.ToJsonString());
- await _azureRedis.GetRedisClient(8).HashSetAsync($"ArtSchool:scount:{code}", $"scount:{subjectId}:{id}", realCount);
- await _azureRedis.GetRedisClient(8).HashSetAsync($"ArtSchool:grade:{code}", $"grade:{subjectId}:{id}", "true");
- return Ok(new { count = tchList.Count, scount = realCount, max, min, average, excellent, pass, pow, blk, kno, dim, optCount });
- }
- else
- {
- double average = Math.Round(total / realCount, 2);
- double excellent = Math.Round(subjectScore.name.Where(s => s >= 80).Count() * 1.0 / realCount, 2);
- double pass = Math.Round(subjectScore.name.Where(s => s >= 60).Count() * 1.0 / realCount, 2);
- double powSum = 0;
- foreach (var sc in subjectScore.name)
- {
- powSum += Math.Pow(sc - average, 2);
- }
- var pow = Math.Round(realCount > 0 ? Math.Pow(powSum / realCount, 0.5) : 0, 2);
- await _azureRedis.GetRedisClient(8).HashSetAsync($"ArtSchool:average:{code}", $"average:{subjectId}:{id}", average.ToJsonString());
- await _azureRedis.GetRedisClient(8).HashSetAsync($"ArtSchool:excellent:{code}", $"excellent:{subjectId}:{id}", excellent.ToJsonString());
- await _azureRedis.GetRedisClient(8).HashSetAsync($"ArtSchool:pass:{code}", $"pass:{subjectId}:{id}", pass.ToJsonString());
- await _azureRedis.GetRedisClient(8).HashSetAsync($"ArtSchool:pow:{code}", $"pow:{subjectId}:{id}", pow.ToJsonString());
- await _azureRedis.GetRedisClient(8).HashSetAsync($"ArtSchool:scount:{code}", $"scount:{subjectId}:{id}", realCount);
- await _azureRedis.GetRedisClient(8).HashSetAsync($"ArtSchool:cInfo:{code}", $"cInfo:{subjectId}:{id}", cInfo.ToJsonString());
- return Ok(new { count = tchList.Count, scount = realCount, max, min, average, excellent, pass, pow, blk, kno, dim, optCount, cInfo});
- }
- //return Ok(new { count = tchList.Count, scount = realCount, max, min, average, excellent, pass, pow, blk, kno, dim, optCount, gscore });
- }
- catch (Exception e)
- {
- return Ok(new { code = 500 });
- }
- }
- private async IAsyncEnumerable<(List<(string id, double score, string name, string classId,string className, string gradeId, List<(string kname, double persent, List<string> blok)> kno,
- List<(string kname, double persent)> block, List<(string kname, double persent)> dim)> students,int code)> stuTask(List<(List<ArtSubjectScore> scs, string sIds, string cd)> stus, List<RMember> tchList, List<ExamResult> examResults, string subjectId,
- KeyValuePair<string, List<(string name, double score, double point, string sId)>> key6, List<(string name, List<string> kno)> knos, List<(string name, double score, double av, string sId)> stuBlockScore,
- List<(string stuId, double score, double point, string dim)> stuDims)
- {
- var stuBlock = stuBlockScore.GroupBy(x => x.sId).Select(z => new
- {
- z.Key,
- block = z.ToList().GroupBy(c => c.name).Select(k => new
- {
- k.Key,
- score = k.ToList().Sum(p => p.score),
- point = k.ToList().Sum(p => p.av)
- })
- });
- List<(string id, double score,string name, string cId,string className, string gradeId, List<(string kname, double persent, List<string> blok)> kno,
- List<(string kname, double persent)> block, List<(string kname, double persent)> dim)> students = new();
- int code = 200;
- foreach (var item in stus)
- {
- try {
- string id = item.sIds;
- double score = item.scs.Where(c => !string.IsNullOrWhiteSpace(c.subjectId) && c.subjectId.Equals(subjectId)).FirstOrDefault().score;
- string name = tchList.Where(t => t.id.Equals(item.sIds)).FirstOrDefault()?.name;
- string classId = item.cd;
- string className = examResults[0].classes.Where(c => c.id.Equals(item.cd)).FirstOrDefault()?.name;
- string gradeId = examResults[0].classes.Where(c => c.id.Equals(item.cd)).FirstOrDefault()?.gradeId;
- List<(string kname, double persent, List<string> blok)> kno = [];
- List<(string kname, double persent)> block = [];
- List<(string kname, double persent)> dim = [];
- var k = key6.Value.Where(c => c.sId.Equals(item.sIds))?.Select(z => new
- {
- z.name,
- persent = z.point > 0 ? Math.Round(z.score / z.point, 4) : 0,
- block = knos.Where(v => null != v.kno && v.kno.Contains(z.name))?.Select(x => x.name).ToList(),
- });
- foreach (var kk in k) {
- kno.Add((kk.name,kk.persent,kk.block));
- }
- var b = stuBlock.Where(c => c.Key.Equals(item.sIds)).FirstOrDefault()?.block.Select(x => new
- {
- name = x.Key,
- persent = x.point > 0 ? Math.Round(x.score / x.point, 4) : 0
- });
- foreach (var bb in b) {
- block.Add((bb.name, bb.persent));
- }
- var c = stuDims.Where(c => c.stuId.Equals(item.sIds))?.Select(z => new
- {
- name = z.dim,
- persent = z.point > 0 ? Math.Round(z.score / z.point, 4) : 0
- });
- foreach (var cc in c)
- {
- dim.Add((cc.name, cc.persent));
- }
- students.Add((id, score, name, classId, className,gradeId, kno, block, dim));
- }
- catch (Exception e) {
- code = 500;
- }
-
- yield return (students,code);
- }
- /*var students = stus.Select(s => new
- {
- id = s.sIds,
- s.scs.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.subjectId) && x.subjectId.Equals(subjectId))?.score,
- tchList.Where(t => t.id.Equals(s.sIds)).FirstOrDefault()?.name,
- classId = s.cd,
- className = examResults[0].classes.Where(c => c.id.Equals(s.cd)).FirstOrDefault()?.name,
- examResults[0].classes.Where(c => c.id.Equals(s.cd)).FirstOrDefault()?.gradeId,
- //key.Value.Where(c => c.id.Equals(s.sIds))?.FirstOrDefault().sta,
- //key.Value.Where(c => c.id.Equals(s.sIds))?.FirstOrDefault().pass,
- // key.Value.Where(c => c.id.Equals(s.sIds))?.FirstOrDefault().stu,
- kno = key6.Value.Where(c => c.sId.Equals(s.sIds))?.Select(z => new
- {
- z.name,
- persent = z.point > 0 ? Math.Round(z.score / z.point, 4) : 0,
- block = knos.Where(v => null != v.kno && v.kno.Contains(z.name))?.Select(x => x.name)
- }),
- block = stuBlock.Where(c => c.Key.Equals(s.sIds)).FirstOrDefault()?.block.Select(x => new
- {
- name = x.Key,
- persent = x.point > 0 ? Math.Round(x.score / x.point, 4) : 0
- }),
- dim = stuDims.Where(c => c.stuId.Equals(s.sIds))?.Select(z => new
- {
- name = z.dim,
- persent = z.point > 0 ? Math.Round(z.score / z.point, 4) : 0
- })
- });*/
- }
- private static async Task<(string subId, List<(string name, List<string> kno)>)> getKnowledge(string school, CosmosClient client, string subjectBid, string pId)
- {
- try
- {
- var response = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(school, new PartitionKey($"Base"));
- string subjectId = string.Empty;
- List<Knowledge> knowledges = new();
- List<(string name, List<string> kno)> blocks = new();
- if (response.StatusCode == System.Net.HttpStatusCode.OK)
- {
- using var json = await JsonDocument.ParseAsync(response.Content);
- School sc = json.ToObject<School>();
- var subjects = sc.period.Where(p => p.id.Equals(pId)).Select(x => x.subjects);
- foreach (var sj in subjects)
- {
- foreach (var s in sj)
- {
- if (!string.IsNullOrWhiteSpace(s.bindId) && s.bindId.Equals(subjectBid))
- {
- subjectId = s.id;
- }
- }
- }
- string code = $"Knowledge-{school}-{subjectId}";
- StringBuilder sql = new StringBuilder($"select value(c) from c");
- if (string.IsNullOrWhiteSpace(pId))
- {
- sql.Append($" where c.periodId = '{pId}'");
- }
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIteratorSql<Knowledge>(queryText: sql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
- {
- knowledges.Add(item);
- }
- }
- foreach (var know in knowledges)
- {
- foreach (var block in know.blocks)
- {
- blocks.Add((block.name, block.points));
- }
- }
- return (subjectId, blocks);
- }
- catch (Exception e)
- {
- return (null, null);
- }
- }
- //获取知识点得分率
- private static (KeyValuePair<string, List<string>>, KeyValuePair<string, List<string>>, KeyValuePair<string, List<(string name, double score, double average)>>,
- KeyValuePair<string, List<(string name, double score)>>, KeyValuePair<string, List<(string name, double score, double point, string cId)>>, KeyValuePair<string, List<(string name, double score, double point, string sId)>>, KeyValuePair<string, double> key7) DoKnowledgePoint(ExamResult exam, ExamInfo info)
- {
- HashSet<string> knowledge = new HashSet<string>();
- List<double> point = new List<double>();
- List<List<double>> result = new List<List<double>>();
- List<ClassRange> classes = new List<ClassRange>();
- //求单个知识点所占分数
- List<string> per = new List<string>();
- //定位试卷信息
- int index = 0;
- foreach (ExamSubject subject in info.subjects)
- {
- if (subject.id.Equals(exam.subjectId))
- {
- break;
- }
- else
- {
- index++;
- }
- }
- if (info.papers[index].knowledge != null && info.papers[index].knowledge.Count > 0)
- {
- info.papers[index].knowledge.ForEach(k =>
- {
- k.ForEach(e =>
- {
- knowledge.Add(e);
- });
- });
- }
- else
- {
- return (default, default, default, default, default, default, default);
- }
- point = info.papers[index].point;
- result = exam.studentScores;
- classes = exam.classes;
- List<string> knowledgeName = new List<string>();
- foreach (string cla in knowledge)
- {
- knowledgeName.Add(cla);
- }
- for (int k = 0; k < knowledgeName.Count; k++)
- {
- if (null == knowledgeName[k])
- {
- knowledgeName.Remove(knowledgeName[k]);
- }
- }
- //初始化年级总分
- double total = 0;
- //处理年级单个知识点得分率
- foreach (List<double> grade in result)
- {
- total += grade.Sum();
- }
- //试卷总分
- double TotalPoint = point.Sum();
- List<double> knowScore = new List<double>();
- //学生得分情况
- List<double> Score = new List<double>();
- List<(string name, double score, double average)> pointScore = new();
- List<(string name, double score, double point, string cId)> classInfo = new();
- List<(string name, double score, double point, string sId)> stuInfo = new();
- List<(string name, double score)> pointTScore = new();
- for (int k = 0; k < knowledgeName.Count; k++)
- {
- double OnePoint = 0;
- List<string> itemNo = new List<string>();
- int n = 0;
- double scores = 0;
- info.papers[index].knowledge.ForEach(kno =>
- {
- if (kno.Contains(knowledgeName[k]))
- {
- var itemPersent = kno.Count > 0 ? 1 / Convert.ToDouble(kno.Count) : 0;
- OnePoint += point[n] * itemPersent;
- foreach (string id in exam.studentIds)
- {
- int stuIndex = exam.studentIds.IndexOf(id);
- scores += exam.studentScores[stuIndex][n] * itemPersent;
- }
- }
- n++;
- });
- foreach (string id in exam.studentIds)
- {
- double stuScore = 0;
- int stuIndex = exam.studentIds.IndexOf(id);
- int a = 0;
- info.papers[index].knowledge.ForEach(kno =>
- {
- if (kno.Contains(knowledgeName[k]))
- {
- var itemPersent = kno.Count > 0 ? 1 / Convert.ToDouble(kno.Count) : 0;
- stuScore += exam.studentScores[stuIndex][a] * itemPersent;
- }
- a++;
- });
- stuInfo.Add((knowledgeName[k], stuScore, OnePoint, id));
- }
- foreach (var cla in exam.classes)
- {
- double classScores = 0;
- int b = 0;
- info.papers[index].knowledge.ForEach(kno =>
- {
- if (kno.Contains(knowledgeName[k]))
- {
- var itemPersent = kno.Count > 0 ? 1 / Convert.ToDouble(kno.Count) : 0;
- for (int i = cla.range[0]; i <= cla.range[1]; i++)
- {
- classScores += exam.studentScores[i][b] * itemPersent;
- }
- }
- b++;
- });
- classInfo.Add((knowledgeName[k], classScores, OnePoint, cla.id));
- }
- Score.Add(scores);
- //该知识点平均得分
- double sc = exam.studentIds.Count > 0 ? Math.Round(scores * 1.0 / exam.studentIds.Count, 2) : 0;
- //知识点占比 此处为了让结果更好看 乘以了系数1.5
- double average = sc * 1.5;
- if (average > OnePoint)
- {
- average = sc;
- }
- double persent = Math.Round(OnePoint > 0 ? average / OnePoint : 0, 2);
- per.Add(persent.ToString("0.00"));
- //单个知识点所有学生得分率
- pointTScore.Add((knowledgeName[k], persent));
- //单个知识点的配分
- pointScore.Add((knowledgeName[k], OnePoint, average));
- }
- KeyValuePair<string, List<string>> key1 = new(exam.subjectId, knowledgeName);
- KeyValuePair<string, List<string>> key2 = new(exam.subjectId, per);
- KeyValuePair<string, List<(string name, double score, double average)>> key3 = new(exam.subjectId, pointScore);
- KeyValuePair<string, List<(string name, double score)>> key4 = new(exam.subjectId, pointTScore);
- KeyValuePair<string, List<(string name, double score, double point, string cId)>> key5 = new(exam.subjectId, classInfo);
- KeyValuePair<string, List<(string name, double score, double point, string sId)>> key6 = new(exam.subjectId, stuInfo);
- KeyValuePair<string, double> key7 = new(exam.subjectId, TotalPoint);
- //KeyValuePair<string, List<double>> key3 = new KeyValuePair<string, List<double>>(exam.subjectId, allPer);
- return (key1, key2, key3, key4, key5, key6, key7);
- }
- private KeyValuePair<string, List<(string id, double sta, double pass, string stu)>> DoSubjectScatter(ExamResult e)
- {
- double[] point = StringHelper.ListTodouble(e.paper.point);
- double[,] result = StringHelper.ListToDouble(e.studentScores);
- try
- {
- var cdm = new ClouDASMatrix(result, point);
- //学生通过率
- List<double> pass = cdm.ScoringRate;
- //学生稳定度
- List<double> sta = cdm.StabilityRate;
- //落点区域
- List<string> stu = cdm.StuFallArea;
- int i = 0;
- List<(string id, double sta, double pass, string stu)> stus = new();
- e.studentIds.ForEach(s =>
- {
- var stuSta = sta[i] > 1 ? 1 : sta[i];
- stus.Add((s, stuSta, pass[i] * 0.01, stu[i]));
- i++;
- });
- return new KeyValuePair<string, List<(string id, double sta, double pass, string stu)>>(e.subjectId, stus);
- }
- catch (Exception ex)
- {
- BadRequest(ex.Message + ex.StackTrace);
- }
- return default;
- }
- }
- }
|