12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919 |
- using ClouDASLibx;
- using Microsoft.AspNetCore.Mvc;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.Json;
- using System.Threading.Tasks;
- using TEAMModelOS.SDK.Models;
- using TEAMModelOS.SDK;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK.Extension;
- using TEAMModelOS.SDK.Helper.Common.StringHelper;
- using Microsoft.Extensions.Options;
- using TEAMModelOS.Models;
- using Azure.Cosmos;
- using System.Text;
- using Microsoft.AspNetCore.Authorization;
- using TEAMModelOS.Filter;
- using TEAMModelOS.SDK.Models.Service;
- namespace TEAMModelOS.Controllers.Analysis
- {
- [Route("analysis")]
- [ApiController]
- public class AnalysisController : ControllerBase
- {
- private readonly AzureCosmosFactory _azureCosmos;
- private readonly DingDing _dingDing;
- private readonly Option _option;
- private const string CacheCosmosPrefix = "Analysis:";
- private const int timeoutSeconds = 3600;
- private readonly CoreAPIHttpService _coreAPIHttpService;
- public AnalysisController(AzureCosmosFactory azureCosmos, DingDing dingDing, IOptionsSnapshot<Option> option,CoreAPIHttpService coreAPIHttpService)
- {
- _azureCosmos = azureCosmos;
- _dingDing = dingDing;
- _option = option?.Value;
- _coreAPIHttpService = coreAPIHttpService;
- }
- [ProducesDefaultResponseType]
- [HttpPost("process")]
- [Authorize(Roles = "IES")]
- [AuthToken(Roles = "teacher,admin")]
- public async Task<IActionResult> getAnalysis(JsonElement request)
- {
- //获取评测的ID
- if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
- if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
- List<StudentAys> students = new List<StudentAys>();
- List<ClassAys> classes = new List<ClassAys>();
- List<GradeAys> grades = new List<GradeAys>();
- List<Dictionary<string, dynamic>> PointAnalysis = new List<Dictionary<string, dynamic>>();
- List<string> scatterKey = new List<string>
- {
- "name",
- "className",
- "x",
- "y",
- "memberId",
- "score",
- "trueNum",
- "falseNum",
- "hardList",
- "carefulList",
- "scatter"
- };
- List<string> paperKey = new List<string>
- {
- "id",
- "type",
- "areaName",
- "score",
- "diff",
- "identify",
- "classScoreRate",
- "gradeScoreRate",
- "areaScoreRate",
- "highScoreRate",
- "lowScoreRate",
- "knowledgePoint",
- "R1",
- "R2",
- "R3",
- "R4",
- "R5",
- "R6",
- "PH",
- "PL",
- "X",
- "Y",
- "knowledge",
- "examScoreRate"
- };
- List<string> knowkey = new List<string>
- {
- "id",
- "className",
- "seatNO",
- "point",
- "anwPoint",
- "persent"
- };
- List<string> keynowWrong = new List<string>
- {
- "name",
- "point",
- "itemNO",
- "persent",
- "wrong",
- "rhw",
- "rlw"
- };
- ExamInfo info = null;
- double ipoint = 0;
- List<KeyValuePair<string, List<List<string>>>> subjectPaperDatas = new List<KeyValuePair<string, List<List<string>>>>();
- List<Dictionary<string, object>> valuePairs = new List<Dictionary<string, object>>();
- List<KeyValuePair<string, List<KeyValuePair<string, List<double>>>>> classSubjectPaperDatas = new List<KeyValuePair<string, List<KeyValuePair<string, List<double>>>>>();
- List<KeyValuePair<string, List<string>>> knowNameDatas = new List<KeyValuePair<string, List<string>>>();
- List<KeyValuePair<string, List<string>>> knowPerDatas = new List<KeyValuePair<string, List<string>>>();
- List<KeyValuePair<string, List<double>>> knowAllPerDatas = new List<KeyValuePair<string, List<double>>>();
- List<KeyValuePair<string, List<double>>> knowScoreDatas = new List<KeyValuePair<string, List<double>>>();
- List<KeyValuePair<string, List<List<string>>>> wrongDatas = new List<KeyValuePair<string, List<List<string>>>>();
- List<KeyValuePair<string, List<KeyValuePair<string, List<double>>>>> stuPerDatas = new List<KeyValuePair<string, List<KeyValuePair<string, List<double>>>>>();
- //声明认知层次变量
- List<KeyValuePair<string, List<int>>> fieldNameDatas = new List<KeyValuePair<string, List<int>>>();
- List<KeyValuePair<string, List<string>>> fieldPerDatas = new List<KeyValuePair<string, List<string>>>();
- List<KeyValuePair<string, List<double>>> fieldAllPerDatas = new List<KeyValuePair<string, List<double>>>();
- List<KeyValuePair<string, List<double>>> fieldScoreDatas = new List<KeyValuePair<string, List<double>>>();
- List<KeyValuePair<string, List<List<string>>>> fieldwrongDatas = new List<KeyValuePair<string, List<List<string>>>>();
- List<KeyValuePair<string, List<KeyValuePair<string, List<double>>>>> fieldStuPerDatas = new List<KeyValuePair<string, List<KeyValuePair<string, List<double>>>>>();
- //获取进线标准以及踩线分数
- int touch = 0;
- int income = 0;
- List<ExamResult> examResults = new List<ExamResult>();
- try
- {
- var client = _azureCosmos.GetCosmosClient();
- //获取本次评测所有科目结算结果
- info = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"Exam-{code}"));
- //School school = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(code.ToString(), new PartitionKey($"Base"));
- var query = $"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 = '{id}' ";
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<ExamResult>(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamResult-{id}") }))
- {
- examResults.Add(item);
- }
- //获取本次评测所有班级作答结果
- List<ExamClassResult> examClassResults = new List<ExamClassResult>();
- if (info.owner.Equals("teacher") && info.scope.Equals("school"))
- {
- var queryClass = $"select c.id,c.name,c.subjectId,c.studentScores,c.studentIds,c.gradeId,c.info,c.standard,c.krate,c.phc,c.plc,c.pc,c.frate,c.fphc,c.fplc,c.fpc,c.status from c where c.examId = '{id}' and c.progress = true ";
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<ExamClassResult>(queryText: queryClass, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{info.school}") }))
- {
- examClassResults.Add(item);
- }
- }
- else {
- var queryClass = $"select c.id,c.name,c.subjectId,c.studentScores,c.studentIds,c.gradeId,c.info,c.standard,c.krate,c.phc,c.plc,c.pc,c.frate,c.fphc,c.fplc,c.fpc,c.status from c where c.examId = '{id}' and c.progress = true ";
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<ExamClassResult>(queryText: queryClass, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{code}") }))
- {
- examClassResults.Add(item);
- }
- }
- if (examClassResults.Count ==0) {
- return Ok(new { code = 404 ,msg = "数据还在结算中!"});
- }
- touch = info.touch;
- income = info.income;
- /*foreach (Period period in school.period)
- {
- if (info.period.id.Equals(period.id))
- {
-
- }
- }*/
- //计算每个年级参考人数并计算进线分数
- List<KeyValuePair<string, double>> keys = new List<KeyValuePair<string, double>>();
- List<double> gradeTotal = new List<double>();
- /*foreach (Grade grade in info.grades) {
- double ipoint = 0;
- int gradeCount = 0;
- //List<double> gradeTotal = new List<double>();
- HashSet<string> sno = new HashSet<string>();
- foreach (ExamClassResult examClassResult in examClassResults) {
- if (grade.id.Equals(examClassResult.gradeId)) {
- gradeCount += examClassResult.studentIds.Count;
- foreach (string s in examClassResult.studentIds) {
- sno.Add(s);
- }
- }
- }
- foreach (string sid in sno) {
- double total = 0;
- foreach (ExamClassResult examClassResult in examClassResults) {
- if (grade.id.Equals(examClassResult.gradeId))
- {
- int index = examClassResult.studentIds.IndexOf(sid);
- if (index == -1) continue;
- total += examClassResult.studentScores[index].Sum();
- }
- }
- gradeTotal.Add(total);
- }
- gradeTotal.Sort((s1, s2) => { return s2.CompareTo(s1); });
- //获取进线人数
- int personCount = (int)System.Math.Round(gradeCount / info.subjects.Count * (touch / 100.0), MidpointRounding.AwayFromZero);
- ipoint = gradeTotal[personCount];
- keys.Add(new KeyValuePair<string, double>(grade.id, ipoint));
- }*/
- //获取进线人数
- int personCount = (int)System.Math.Round(info.stuCount * (income / 100.0), MidpointRounding.AwayFromZero);
- /* //声明年级所有科目总分
- List<double> total = new List<double>();*/
- List<ClassRange> classReses = null;
- //按科目获取所有学生的分数
- Dictionary<string, List<double>> subjectTotal = new Dictionary<string, List<double>>();
- Dictionary<string, double> paperScore = new Dictionary<string, double>();
- List<KeyValuePair<string, List<KeyValuePair<string, List<string>>>>> subjectScatter = new List<KeyValuePair<string, List<KeyValuePair<string, List<string>>>>>();
- List<KeyValuePair<string, Dictionary<string, List<double>>>> gscores = new List<KeyValuePair<string, Dictionary<string, List<double>>>>();
- //声明全科总分
- double totalAll = 0;
- List<string> stuIds = new();
- foreach (ExamResult examResult in examResults)
- {
- (KeyValuePair<string, List<List<string>>> subjectData, KeyValuePair<string, List<KeyValuePair<string, List<double>>>> classSubjectData, Dictionary<string, List<double>> gscore) = DoExerciseScatteres(examResult, paperKey);
- (KeyValuePair<string, List<string>> knowName, KeyValuePair<string, List<string>> knowPer, KeyValuePair<string, List<double>> knowAllPer, KeyValuePair<string, List<double>> kScore, KeyValuePair<string, List<List<string>>> wrong, KeyValuePair<string, List<KeyValuePair<string, List<double>>>> stuPer) = DoKnowledgePoint(examResult, info, keynowWrong);
- (KeyValuePair<string, List<int>> fieldName, KeyValuePair<string, List<string>> fieldPer, KeyValuePair<string, List<double>> fieldAllPer, KeyValuePair<string, List<double>> fScore, KeyValuePair<string, List<List<string>>> fieldWrong, KeyValuePair<string, List<KeyValuePair<string, List<double>>>> fieldStuPer) = DoLevel(examResult, info, keynowWrong);
- gscores.Add(new KeyValuePair<string, Dictionary<string, List<double>>>(examResult.subjectId, gscore));
- /* Dictionary<string, dynamic> gpoint = new Dictionary<string, dynamic>();
- Dictionary<string, dynamic> glevel = new Dictionary<string, dynamic>();*/
- Dictionary<string, object> gpointList = new Dictionary<string, object>();
- subjectPaperDatas.Add(subjectData);
- classSubjectPaperDatas.Add(classSubjectData);
- subjectScatter.Add(DoSubjectScatter(examResult));
- knowNameDatas.Add(knowName);
- knowPerDatas.Add(knowPer);
- knowAllPerDatas.Add(knowAllPer);
- knowScoreDatas.Add(kScore);
- wrongDatas.Add(wrong);
- stuPerDatas.Add(stuPer);
- fieldNameDatas.Add(fieldName);
- fieldPerDatas.Add(fieldPer);
- fieldAllPerDatas.Add(fieldAllPer);
- fieldScoreDatas.Add(fScore);
- fieldwrongDatas.Add(fieldWrong);
- fieldStuPerDatas.Add(fieldStuPer);
- //gpointList.Add("subjectId", examResult.subjectId);
- //gpointList.Add("pointKey", DoKnowledgePoint(examResult, info));
- //gpointList.Add("levelKey", DoLevel(examResult, info));
- valuePairs.Add(gpointList);
- //获取一张试卷的满分
- totalAll += examResult.paper.point.Sum();
- paperScore.Add(examResult.subjectId, examResult.paper.point.Sum());
- List<double> StuSubjectTotals = new List<double>();
- classReses = examResult.classes;
- //处理个人
- foreach (var stuid in examResult.studentIds)
- {
- if (!stuIds.Contains(stuid))
- {
- stuIds.Add(stuid);
- }
- StudentAys student = null;
- int index = examResult.studentIds.IndexOf(stuid);
- if (students.Select(x => x.id).Contains(stuid))
- {
- student = students[index];
- }
- else
- {
- student = new StudentAys() { id = stuid };
- students.Add(student);
- }
- var score = Math.Round(examResult.studentScores[index].Sum(),2);
- student.total += score;
- student.total = Math.Round(student.total, 2);
- StuSubjectTotals.Add(score);
- if (student.subjects.Select(x => x.id).Contains(examResult.subjectId))
- {
- student.subjects.ForEach(y =>
- {
- if (y.id.Equals(examResult.subjectId))
- {
- y.score = score;
- y.sRate = Math.Round(examResult.paper.point.Sum() > 0 ? score / examResult.paper.point.Sum() : 0, 2);
- }
- });
- }
- else
- {
- StudentSubject subject = new StudentSubject
- {
- id = examResult.subjectId,
- scores = examResult.studentScores[examResult.studentIds.IndexOf(stuid)],
- name = info.subjects.Where(x => x.id == examResult.subjectId).FirstOrDefault().name,
- point = stuPerDatas.Where(x => x.Key == examResult.subjectId).SelectMany(va => va.Value).Where(stu => stu.Key == stuid).Select(pi => pi.Value).First(),
- fieldPoint = fieldStuPerDatas.Where(x => x.Key == examResult.subjectId).SelectMany(va => va.Value).Where(stu => stu.Key == stuid).Select(pi => pi.Value).First()
- };
- subject.score = score;
- subject.sRate = Math.Round(examResult.paper.point.Sum() > 0 ? score / examResult.paper.point.Sum() * 100 : 0, 2);
- student.subjects.Add(subject);
- }
- }
- subjectTotal.Add(examResult.subjectId, StuSubjectTotals);
- }
- //double powAll = 0;
- foreach (StudentAys student1 in students)
- {
- gradeTotal.Add(student1.total);
- student1.sRate = totalAll > 0 ? Math.Round(student1.total / totalAll * 100, 2) : 0;
- //powAll += Math.Pow(student1.total - examResult.studentIds.Count > 0 ? Math.Round(score * 1.0 / examResult.studentIds.Count, 2) : 0, 2);
- }
- //处理进线分数
- gradeTotal.Sort((s1, s2) => { return s2.CompareTo(s1); });
- if (personCount == 0)
- {
- ipoint = gradeTotal[personCount] + 1;
- }
- else
- {
- if (personCount == gradeTotal.Count)
- {
- ipoint = gradeTotal[personCount - 1];
- }
- else {
- ipoint = gradeTotal[personCount];
- }
-
- }
- //以班级为单位(此处处理的是行政班级,教学班如果被移除则会无法分析)
- List<string> clas = ExamService.getClasses(info.classes, info.stuLists);
- (List<RMember> members, List<RGroupList> classLists) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, clas, info.school, null,-1,info.startTime);
- foreach (RGroupList rGroup in classLists)
- {
- /* Class classroom = null;
- var sresponse = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(classId, new PartitionKey($"Class-{code}"));
- if (sresponse.Status == 200)
- {
- using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
- classroom = json.ToObject<Class>();
- }*/
- //处理班级
- var classRes = classReses.Where(x => x.id == rGroup.id).FirstOrDefault();
- var stuCount = classRes.range[1] - classRes.range[0] + 1;
- // 班级缺考人数
- var lostClassCount = examClassResults.Where(x => x.info.id.Equals(rGroup.id)).FirstOrDefault().status.Where(r => r == 1).ToList().Count;
-
- List<StudentAys> classStudents = new();
- /* foreach (string sid in stuIds)
- {
- foreach (var stu in students)
- {
- if (stu.id == sid && stu.classId == classRes.id)
- {
- classStudents.Add(stu);
- }
- }
- };*/
- for (int i = classRes.range[0]; i <= classRes.range[1]; i++) {
- foreach (var stu in students)
- {
- if (stu.id == examResults[0].studentIds[i])
- {
- classStudents.Add(stu);
- }
- }
- }
- //var classStudents = students.GetRange(classRes.range[0], classRes.range[1] - classRes.range[0] + 1);
- List<double> stuTotals = classStudents.Select(x => x.total).ToList();
- stuTotals.Sort((s1, s2) => { return s2.CompareTo(s1); });
- //初始化进线人数
- int lineCount = 0;
- //初始化班级总分
- double classTotal = stuTotals.Sum();
- //标准差
- double powSum = 0;
- //计算标准差
- //总平均分
- double totalAverage = 0;
- totalAverage = stuCount - lostClassCount > 0 ? classTotal * 1.0 / (stuCount - lostClassCount) : 0;
- //totalAverage = classTotal / stuCount;
- //获取整个班级 科目的分数情况
- List<KeyValuePair<string, double>> keyValues = new List<KeyValuePair<string, double>>();
- List<string> studentIds = new List<string>();
- List<KeyValuePair<string, List<double>>> pointClassTotal = new List<KeyValuePair<string, List<double>>>();
- List<KeyValuePair<string, List<double>>> fieldClassTotal = new List<KeyValuePair<string, List<double>>>();
- subjectTotal.Keys.ToList().ForEach(sub =>
- {
- var points = new List<double>();
- var fields = new List<double>();
- knowNameDatas.Where(su => su.Key == sub).First().Value.ForEach(x => { points.Add(0); });
- fieldNameDatas.Where(su => su.Key == sub).First().Value.ForEach(x => { fields.Add(0); });
- pointClassTotal.Add(new KeyValuePair<string, List<double>>(sub, points));
- fieldClassTotal.Add(new KeyValuePair<string, List<double>>(sub, fields));
- });
- /*List<Student> stus = new List<Student>();
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<Student>(queryText: $"select c.id,c.name,c.no from c where c.classId = '{classId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{code}") }))
- {
- stus.Add(item);
- }*/
- classStudents.ForEach(x =>
- {
- studentIds.Add(x.id);
- x.classId = rGroup.id;
- x.className = rGroup.name;
- //x.className = examClassResults.FirstOrDefault(e => e.info.id.Equals(rGroup.id)).info.name;
- x.gradeId = examClassResults.FirstOrDefault(e => e.info.id.Equals(rGroup.id)).gradeId;
- var stu = members.Where(s => s.id == x.id).FirstOrDefault();
- if (stu != null)
- {
- x.nickname = stu.nickname;
- x.name = stu.name;
- x.no = stu.no;
- }
- else
- {
- x.nickname = x.nickname;
- x.name = x.id;
- x.no = "-";
- }
- /* //班级得分率
- x.csRate = totalAll > 0 ? Math.Round(totalAverage / totalAll,2) : 0;*/
- //标准差 介于缺考人员的判定逻辑 多科考试必须多科同时缺考才能算整个评测缺考
- int inx = examClassResults.FirstOrDefault(e => e.info.id.Equals(rGroup.id)).studentIds.IndexOf(x.id);
- var statu = examClassResults.Where(e => e.info.id.Equals(rGroup.id)).Select(x => x.status).ToList();
- bool flag = false;
- foreach (var ets in statu) {
- if (ets[inx] == 0) {
- flag = true;
- break;
- }
- }
- if (flag) {
- powSum += Math.Pow(x.total - totalAverage, 2);
- }
-
- //进线人数
- if (x.total >= ipoint)
- {
- lineCount++;
- }
- //班级全科的pr
- int index = stuTotals.IndexOf(x.total);
- //double CPR = stuCount - lostClassCount > 0 ? Math.Floor(100 - (100 * (index + 1) - 50) * 1.0 / (stuCount - lostClassCount)) : 0;
- double CPR = 100 - (100 * (index + 1) - 50) / stuCount;
- x.cpr = CPR;
- x.csort = index + 1;
- //班级单科的pr
- x.subjects.ForEach(y =>
- {
- //y.point
- var subjectT = classStudents.SelectMany(s => s.subjects).Where(sub => sub.id == y.id).Select(scr => scr.score).ToList();
- subjectT.Sort((s1, s2) => { return s2.CompareTo(s1); });
- int index = subjectT.IndexOf(y.score);
- //double CPR = stuCount - lostClassCount > 0 ? Math.Floor(100 - (100 * (index + 1) - 50) * 1.0 / (stuCount - lostClassCount)) : 0;
- double CPR = 100 - (100 * (index + 1) - 50) / stuCount;
- y.cpr = CPR;
- y.csort = index + 1;
- //按科目获取一个班的分数
- keyValues.Add(new KeyValuePair<string, double>(y.id, y.score));
- var pintTalt = pointClassTotal.Where(su => su.Key == y.id).Select(pint => pint.Value).First();
- for (int i = 0; i < y.point.Count; i++)
- {
- pintTalt[i] = pintTalt[i] + y.point[i];
- }
- var fieldTalt = fieldClassTotal.Where(su => su.Key == y.id).Select(pint => pint.Value).First();
- for (int i = 0; i < y.fieldPoint.Count; i++)
- {
- fieldTalt[i] = fieldTalt[i] + y.fieldPoint[i];
- }
- });
- });
- var pow = stuCount - lostClassCount > 0 ? Math.Pow(powSum / (stuCount - lostClassCount), 0.5) : 0;
- //var pow = Math.Pow(powSum / stuCount, 0.5);
- ClassAys classAys = new ClassAys
- {
- gradeId = examClassResults.FirstOrDefault(e => e.info.id.Equals(rGroup.id)).gradeId ?? "",
- year = rGroup.year,
- studentIds = studentIds,
- stuCount = stuCount,
- classId = rGroup.id,
- csRate = totalAll > 0 ? Math.Round(totalAverage / totalAll * 100, 2) : 0,
- className = rGroup.name,
- totalAverage = totalAverage,
- lineCount = lineCount,
- standardDeviation = Math.Round(pow,2)
- };
- foreach (var key in paperScore.Keys)
- {
- var subScore = keyValues.Where(x => x.Key.Equals(key)).Select(x => x.Value).ToList();
- //计算及格率
- int passCount = 0;
- double passScore = paperScore[key] * 0.6;
- subScore.ForEach(x =>
- {
- if (x > passScore)
- {
- passCount += 1;
- }
- });
- double passPercent = stuCount - lostClassCount > 0 ? Math.Round(passCount * 1.0 / (stuCount - lostClassCount), 2) : 0;
- //double passPercent = Math.Round(passCount * 1.0 / stuCount,2) ;
- double average = stuCount - lostClassCount > 0 ? Math.Round(subScore.Sum() * 1.0 / (stuCount - lostClassCount), 2) : 0;
- //double average = Math.Round(subScore.Sum() * 1.0 / stuCount,2) ;
- List<double> tt = new List<double>();
- List<double> fieldPoints = new List<double>();
- var pp = pointClassTotal.Where(su => su.Key == key).Select(pint => pint.Value).First();
- pp.ForEach(s =>
- {
- tt.Add(stuCount - lostClassCount > 0 ? Math.Round(s * 1.0 / (stuCount - lostClassCount), 2) : 0);
- });
- var ff = fieldClassTotal.Where(su => su.Key == key).Select(pint => pint.Value).First();
- ff.ForEach(s =>
- {
- fieldPoints.Add(stuCount - lostClassCount > 0 ? Math.Round(s * 1.0 / (stuCount - lostClassCount), 2) : 0);
- });
- double val = examClassResults.FirstOrDefault(c => c.subjectId == key && c.info.id == rGroup.id).standard;
- List<double> krate = examClassResults.FirstOrDefault(c => c.subjectId == key && c.info.id == rGroup.id).krate;
- List<int> phc = examClassResults.FirstOrDefault(c => c.subjectId == key && c.info.id == rGroup.id).phc;
- List<int> plc = examClassResults.FirstOrDefault(c => c.subjectId == key && c.info.id == rGroup.id).plc;
- List<int> pc = examClassResults.FirstOrDefault(c => c.subjectId == key && c.info.id == rGroup.id).pc;
- List<double> frate = examClassResults.FirstOrDefault(c => c.subjectId == key && c.info.id == rGroup.id).frate;
- List<int> fphc = examClassResults.FirstOrDefault(c => c.subjectId == key && c.info.id == rGroup.id).fphc;
- List<int> fplc = examClassResults.FirstOrDefault(c => c.subjectId == key && c.info.id == rGroup.id).fplc;
- List<int> fpc = examClassResults.FirstOrDefault(c => c.subjectId == key && c.info.id == rGroup.id).fpc;
- classAys.subjects.Add(new AysSubject
- {
- point = tt,
- field = fieldPoints,
- id = key,
- passPercent = passPercent,
- passCount = passCount,
- average = average,
- standard = val,
- krate = krate,
- phc = phc,
- plc = plc,
- pc = pc,
- frate = frate,
- fphc = fphc,
- fplc = fplc,
- fpc = fpc,
- sRate = paperScore[key] > 0 ? Math.Round(average / paperScore[key] * 100, 2) : 0,
- name = info.subjects.Where(x => x.id == key).FirstOrDefault().name,
- item = classSubjectPaperDatas.Where(subd => subd.Key == key).First().Value.Where(cls => cls.Key == rGroup.id).First().Value
- });
- }
- classes.Add(classAys);
- }
- //处理年级
- var tgrades = classes.GroupBy(x => x.year).Select(x => x.Key).OrderBy(c => c).ToList();
- int n = 0;
- if (tgrades.Count > 0)
- {
- if (info.grades.Count > 0) {
- foreach (var greade in tgrades)
- {
- string gid = info.grades.Count > 0 ? info.grades[n].id ?? "-" : "-";
-
- var clases = classes.Where(x => x.year.Equals(greade));
- var classCount = clases.Count();
- var stu = clases.SelectMany(x => x.studentIds).ToList();
- var lineCount = clases.Select(x => x.lineCount).Sum();
- var totalAverage = clases.Select(x => x.totalAverage).Sum() * 1.0 / classCount;
- GradeAys gradeAys = new GradeAys
- {
- gradeId = gid,
- studentIds = stu,
- gradeName = info.grades.Count > 0 ? info.grades[n].name ?? "-" : "-",
- stuCount = stu.Count,
- lineCount = lineCount,
- totalAverage = totalAverage,
- };
- foreach (var key in paperScore.Keys)
- {
- var AysSubject = clases.SelectMany(c => c.subjects).Where(x => x.id.Equals(key)).Select(x => x).ToList();
- var passCount = AysSubject.Select(x => x.passCount).Sum();
- var average = Math.Round(AysSubject.Select(x => x.average).Sum() * 1.0 / classCount);
- var passPercent = stu.Count > 0 ? Math.Round(passCount * 1.0 / stu.Count, 2) : 0;
- //var passPercent = Math.Round(passCount * 1.0 / stu.Count,2);
- AysSubject subject = new AysSubject
- {
- id = key,
- passCount = passCount,
- passPercent = passPercent,
- average = average,
- name = info.subjects.Where(x => x.id == key).FirstOrDefault().name,
- item = gscores.Where(x => x.Key == key).FirstOrDefault().Value.Where(cls => cls.Key == gid).FirstOrDefault().Value
- };
- gradeAys.subjects.Add(subject);
- }
- grades.Add(gradeAys);
- //处理学生年级相关的pr值
- var studentAys = students;
- int lostGrade = 0;
- if (!gid.Equals("-")) {
- studentAys = students.Where(x => x.gradeId != null && x.gradeId.Equals(gid)).ToList();
- lostGrade = examClassResults.Where(x => x.gradeId.Equals(gid)).SelectMany(y => y.status).Where (r => r == 1).ToList().Count;
- }
- var stuGradeTotal = studentAys.Select(x => x.total).ToList();
- stuGradeTotal.Sort((s1, s2) => { return s2.CompareTo(s1); });
- var stuCount = stuGradeTotal.Count;
- studentAys.ForEach(x =>
- {
- //年级全科的pr
- int index = stuGradeTotal.IndexOf(x.total);
- //double GPR = stuCount - lostGrade > 0 ? Math.Floor(100 - (100 * (index + 1) - 50) * 1.0 / (stuCount - lostGrade)) : 0;
- double GPR = 100 - (100 * (index + 1) - 50) / stuCount;
- x.gpr = GPR;
- x.gsort = index + 1;
- //年级单科的pr
- x.subjects.ForEach(y =>
- {
- var subjectT = studentAys.SelectMany(s => s.subjects).Where(sub => sub.id == y.id).Select(scr => scr.score).ToList();
- subjectT.Sort((s1, s2) => { return s2.CompareTo(s1); });
- int index = subjectT.IndexOf(y.score);
- //double GPR = stuCount- lostGrade > 0 ? Math.Floor(100 - (100 * (index + 1) - 50) * 1.0 / (stuCount - lostGrade)) : 0;
- double GPR = 100 - (100 * (index + 1) - 50) / stuCount;
- y.gpr = GPR;
- y.gsort = index + 1;
- });
- });
- n++;
- }
- }
- }
-
- subjectScatter.ForEach(x =>
- {
- string subjectId = x.Key;
- x.Value.ForEach(s =>
- {
- string stuId = s.Key;
- var data = s.Value;
- var stu = students.Where(stu => stu.id == stuId).First();
- students.Where(stu => stu.id == stuId).First().subjects.Where(sub => sub.id == subjectId).ToList().ForEach(sc =>
- {
- //处理阵列的索引1的班级名称
- data[1] = stu.className;
- sc.scatter = data;
- //data[3] = sc.sRate.ToString();
- //sc.sRate = double.Parse(data[3]);
- });
- });
- });
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/process()\n{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
- }
- var sub = examResults.Select(e => new
- {
- e.id,
- info.subjects.FirstOrDefault(c => c.id == e.id).name,
- e.record,
- e.phc,
- e.plc,
- e.sRate,
- e.average,
- e.standard
- });
- /*var sub = info.subjects.Select(x => new
- {
- id = x.id,
- name = x.name,
- record = examResults.FirstOrDefault(c => c.id == x.id).record,
- phc = examResults.FirstOrDefault(c => c.id == x.id).phc,
- plc = examResults.FirstOrDefault(c => c.id == x.id).plc,
- sRate = examResults.FirstOrDefault(c => c.id == x.id).sRate,
- average = examResults.FirstOrDefault(c => c.id == x.id).average,
- standard = examResults.FirstOrDefault(c => c.id == x.id).standard
- });*/
- var subAll = new { info.sRate, info.average, info.standard, total = info.stuCount,lost = info.lostStu.Count };
- return Ok(new
- {
- students,
- classes,
- grades,
- paper = subjectPaperDatas,
- subjects = sub,
- scatterKey,
- paperKey,
- pointLevelKey = valuePairs,
- ipoint,
- touchScore = touch,
- knowKey = knowkey,
- wrongKey = keynowWrong,
- wrong = wrongDatas,
- knowName = knowNameDatas,
- knowPer = knowPerDatas,
- knowAllper = knowAllPerDatas,
- fieldwrong = fieldwrongDatas,
- fieldName = fieldNameDatas,
- fieldPer = fieldPerDatas,
- fieldAllPer = fieldAllPerDatas,
- kScores = knowScoreDatas,
- fScores = fieldScoreDatas,
- all = subAll
- });
- }
- private static (KeyValuePair<string, List<List<string>>>, KeyValuePair<string, List<KeyValuePair<string, List<double>>>>, Dictionary<string, List<double>>) DoExerciseScatteres(ExamResult e, List<string> paperKey)
- {
- List<int> examAnswer = new List<int>();
- List<string> examPersent = new List<string>();
- for (int n = 0; n < e.paper.point.Count; n++)
- {
- examAnswer.Add(0);
- }
- //参考人数
- double Qnum = 0;
- e.studentIds.ForEach(i =>
- {
- if (!i.Equals("0"))
- {
- Qnum++;
- }
- });
- List<List<string>> datas = new List<List<string>>();
- List<string[]> itemAnalysis = new List<string[]>();
- Dictionary<string, List<int>> gradeItemScore = new Dictionary<string, List<int>>();
- Dictionary<string, int> gradeItemStuCount = new Dictionary<string, int>();
- List<KeyValuePair<string, List<double>>> classdatas = new List<KeyValuePair<string, List<double>>>();
- try
- {
- e.classes.ForEach(c =>
- {
- //初始化每题得分情况
- List<int> answerCount = new List<int>();
- List<double> persent = new List<double>();
- int peopleCount = 0;
- for (int n = 0; n < e.paper.point.Count; n++)
- {
- answerCount.Add(0);
- }
- int qCount = 0;
- //每个班级得分占比
- for (int i = c.range[0]; i <= c.range[1]; i++)
- {
- if (e.studentScores[i].Sum() > 0)
- {
- for (int j = 0; j < e.studentScores[i].Count; j++)
- {
- if (e.studentScores[i][j] > 0)
- {
- //记录班级每题得分数
- answerCount[j] = answerCount[j] + 1;
- //记录年级每题得分数
- examAnswer[j] = examAnswer[j] + 1;
- }
- }
- }
- else
- {
- qCount++;
- }
- peopleCount = c.range[1] - c.range[0] + 1 - qCount;
- }
- foreach (int p in answerCount)
- {
- var t = peopleCount > 0 ? Math.Round(p * 1.0 / peopleCount * 100, 2) : 0;
- //var t = Math.Round(p * 1.0 / peopleCount * 100,2);
- persent.Add(t);
- }
- classdatas.Add(new KeyValuePair<string, List<double>>(c.id, persent));
- if (!string.IsNullOrEmpty(c.gradeId))
- {
- if (gradeItemScore.ContainsKey(c.gradeId))
- {
- var we = gradeItemScore[c.gradeId];
- List<int> count = we;
- for (int index = 0; index < count.Count; index++)
- {
- count[index] = count[index] + answerCount[index];
- }
- gradeItemScore[c.gradeId] = count;
- // gradeItemScore[c.gradeId].ForEach(x => { x = x + answerCount[index]; index += 1; });
- gradeItemStuCount[c.gradeId] = gradeItemStuCount[c.gradeId] + peopleCount;
- }
- else
- {
- gradeItemScore.Add(c.gradeId, answerCount);
- gradeItemStuCount.Add(c.gradeId, peopleCount);
- }
- }
- });
- double[] point = StringHelper.ListTodouble(e.paper.point);
- List<string> stus = e.studentIds.Except(e.lostStus).ToList();
- List<List<double>> etuScores = new();
- foreach (string stu in stus) {
- int index = e.studentIds.IndexOf(stu);
- etuScores.Add(e.studentScores[index]);
- }
- double[,] result = StringHelper.ListToDouble(etuScores);
- var cdm = new ClouDASMatrix(result, point);
- //试题Y
- List<double> answer = cdm.AnswerRate;
- //试题X
- List<double> quality = cdm.QualityRate;
- //试题区域
- List<string> topic = cdm.TopicFallArea;
- //试题相关分析结果
- List<(double Diff, double D, double R0,double R1, double R2, double R3, double R4, double R5, double R6, double PH, double PL)> rs = cdm.RS;
- for (int i = 0; i < rs.Count; i++)
- {
- string[] ex = new string[] { };
- string ss = rs[i].ToString()[1..^1];
- ex = ss.Split(",");
- itemAnalysis.Add(ex);
- }
- foreach (int p in examAnswer)
- {
- var t = Qnum > 0 ? Math.Round(p * 1.0 / Qnum * 100, 2) : 0;
- //var t = Math.Round(p * 1.0 / Qnum * 100,2);
- examPersent.Add(t.ToString());
- }
- for (int k = 0; k < e.paper.point.Count; k++)
- {
- List<string> values = new List<string>();
- paperKey.ForEach(x =>
- {
- values.Add("-");
- });
- values[0] = (k + 1).ToString();
- if (e.paper.type.Count > 0)
- {
- values[1] = e.paper.type[k].ToString();
- }
- else
- {
- values[1] = "";
- }
- values[2] = topic[k].ToString();
- values[3] = e.paper.point[k].ToString();
- /* List<string> sk = new List<string>();
- foreach (string kl in e.paper.knowledge[k]) {
- sk.Add(kl);
- }*/
- values[22] = string.Join(",", e.paper.knowledge[k]);
- if (itemAnalysis.Count > 0)
- {
- values[4] = itemAnalysis[k][0].Trim();
- values[5] = itemAnalysis[k][1].Trim();
- values[6] = itemAnalysis[k][2].Trim();
- values[12] = itemAnalysis[k][3].Trim();
- values[13] = itemAnalysis[k][4].Trim();
- values[14] = itemAnalysis[k][5].Trim();
- values[15] = itemAnalysis[k][6].Trim();
- values[16] = itemAnalysis[k][7].Trim();
- values[17] = itemAnalysis[k][8].Trim();
- values[18] = itemAnalysis[k][9].Trim();
- values[19] = itemAnalysis[k][10].Trim();
- }
- else
- {
- values[4] = "0";
- values[5] = "0";
- values[6] = "0";
- values[12] = "0";
- values[13] = "0";
- values[14] = "0";
- values[15] = "0";
- values[16] = "0";
- values[17] = "0";
- values[18] = "0";
- values[19] = "0";
- }
- Dictionary<string, double> its = new Dictionary<string, double>();
- classdatas.ForEach(cls => { its.Add(cls.Key, cls.Value[k]); });
- StringBuilder classBuilder = new StringBuilder();
- foreach (var key in its.Keys)
- {
- classBuilder.Append(key + ":" + its[key] + ",");
- }
- var cstr = classBuilder.ToString();
- values[7] = cstr[..^1];
- StringBuilder gradeBuilder = new StringBuilder();
- //处理年级的这个题的得分
- foreach (var key in gradeItemScore.Keys)
- {
- var data = gradeItemStuCount[key] > 0 ? Math.Round(gradeItemScore[key][k] * 1.0 / gradeItemStuCount[key] * 100, 2) : 0;
- //var data = Math.Round(gradeItemScore[key][k] * 1.0 / gradeItemStuCount[key] * 100, 2);
- gradeBuilder.Append(key + ":" + data + ",");
- }
- var gstr = gradeBuilder.ToString();
- values[8] = string.IsNullOrEmpty(gstr) ? "-" : gstr.Substring(0, gstr.Length - 1);
- values[20] = quality[k].ToString();
- values[21] = answer[k].ToString();
- // string pointName = "";
- values[23] = examPersent[k];
- datas.Add(values);
- }
- Dictionary<string, List<double>> dict = new Dictionary<string, List<double>>();
- //处理年级的这个题的得分
- foreach (var key in gradeItemScore.Keys)
- {
- List<double> gscores = new List<double>();
- gradeItemScore[key].ForEach(x =>
- {
- var data = gradeItemStuCount[key] > 0 ? Math.Round(x * 1.0 / gradeItemStuCount[key] * 100, 2) : 0;
- //var data = Math.Round(x * 1.0 / gradeItemStuCount[key] * 100, 2);
- gscores.Add(data);
- });
- dict.TryAdd(key, gscores);
- }
- KeyValuePair<string, List<List<string>>> keyValue = new(e.subjectId, datas);
- KeyValuePair<string, List<KeyValuePair<string, List<double>>>> classdata = new(e.subjectId, classdatas);
- return (keyValue, classdata, dict);
- }
- catch (Exception ex)
- {
- // throw new BizException(ex.Message);
- }
- return (default, default, default);
- }
- //落点分析
- private KeyValuePair<string, List<KeyValuePair<string, List<string>>>> DoSubjectScatter(ExamResult e)
- {
- List<KeyValuePair<string, List<string>>> datas = new List<KeyValuePair<string, List<string>>>();
- 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;
- //需努力的题型
- List<int[]> strive = cdm.StriveTopic;
- //需小心的题型
- List<int[]> careful = cdm.CarefulTopic;
- int i = 0;
- for (int k = e.studentIds.Count - 1; k >= 0; k--)
- {
- if (e.studentIds[k].Equals("0"))
- {
- e.studentIds.Remove(e.studentIds[k]);
- }
- }
- e.studentIds.ForEach(s =>
- {
- /* if (e.studentScores[i].Sum() != 0)
- {*/
- List<string> info = new List<string>
- {
- s,
- "-",
- sta[i] > 1 ? "1" : sta[i].ToString(),
- pass[i].ToString(),
- i + 1 + "",
- Math.Round(e.studentScores[i].Sum(),2).ToString()
- };
- int right = 0;
- int wrong = 0;
- foreach (int p in e.studentScores[i])
- {
- if (p > 0)
- {
- right++;
- }
- else
- {
- wrong++;
- }
- }
- info.Add(right + "");
- info.Add(wrong + "");
- int[] str = strive[i];
- string striveAll = "";
- foreach (int n in str)
- {
- striveAll += n.ToString() + ",";
- }
- int[] care = careful[i];
- string careAll = "";
- foreach (int n in care)
- {
- careAll += n.ToString() + ",";
- }
- if (string.IsNullOrEmpty(striveAll))
- {
- info.Add("-");
- }
- else
- {
- info.Add(striveAll.Substring(0, striveAll.Length - 1));
- }
- if (string.IsNullOrEmpty(careAll))
- {
- info.Add("-");
- }
- else
- {
- info.Add(careAll.Substring(0, careAll.Length - 1)); ;
- }
- info.Add(stu[i].ToString());
- KeyValuePair<string, List<string>> keyValue = new KeyValuePair<string, List<string>>(s, info);
- datas.Add(keyValue);
- //}
- i++;
- });
- return new KeyValuePair<string, List<KeyValuePair<string, List<string>>>>(e.subjectId, datas);
- }
- catch (Exception ex)
- {
- BadRequest(ex.Message + ex.StackTrace);
- Console.WriteLine("---------------------" + ex.Message + "--------------------------");
- }
- return default;
- }
- private static (KeyValuePair<string, List<string>>, KeyValuePair<string, List<string>>, KeyValuePair<string, List<double>>, KeyValuePair<string, List<double>>, KeyValuePair<string, List<List<string>>>, KeyValuePair<string, List<KeyValuePair<string, List<double>>>>) DoKnowledgePoint(ExamResult exam, ExamInfo info, List<string> keynowWrong)
- {
- HashSet<string> knowledge = new HashSet<string>();
- //HashSet<string> area = 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> ids = new List<string>();
- List<KeyValuePair<string, List<double>>> datas = new List<KeyValuePair<string, List<double>>>();
- //求单个知识点所占分数
- List<string> per = new List<string>();
- //List<string> gper = new List<string>();
- //List<string> knowPer = new List<string>();
- //Dictionary<string, object> wrongMap = new Dictionary<string, object>();
- List<List<string>> wrongPersent = new List<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);
- }
- point = info.papers[index].point;
- result = exam.studentScores;
- classes = exam.classes;
- //ids = exam.studentIds;
- //确定高分组 低分组人数
- //List<List<double>> re = exam.studentScores;
- /* List<double> resultSum = new List<double>();
- foreach (List<double> data in re)
- {
- resultSum.Add(data.Sum());
- }*/
- //确定高分组 最低分数
- double[] points = StringHelper.ListTodouble(exam.paper.point);
- double[,] scs = StringHelper.ListToDouble(exam.studentScores);
- var cdm = new ClouDASMatrix(scs, points);
- //scores.Sort((s1, s2) => { return s2.CompareTo(s1); });
- int rhwCount = cdm.SH.Count();
- double rhw = cdm.SH.LastOrDefault().Item2;
- int rhlCount = cdm.SL.Count();
- double rhl = cdm.SL.FirstOrDefault().Item2;
- /* resultSum.Sort((s1, s2) => { return s2.CompareTo(s1); });
- int rhwCount = 0;
- double rhw = 0;
- int rhlCount = 0;
- double rhl = 0;
- if (resultSum.Count > 3)
- {
- rhwCount = Convert.ToInt32(Math.Floor(resultSum.Count * 0.27));
- rhw = rhwCount > 0 ? resultSum[rhwCount - 1] : 0;
- rhlCount = Convert.ToInt32(Math.Ceiling(resultSum.Count * 0.73));
- rhl = rhlCount > 0 ? resultSum[rhlCount] : 0;
- }
- else {
- rhwCount = Convert.ToInt32(Math.Floor(resultSum.Count * 0.27));
- rhw = rhwCount > 0 ? resultSum[rhwCount] : 0;
- rhlCount = Convert.ToInt32(Math.Ceiling(resultSum.Count * 0.73));
- rhl = rhlCount > 0 ? resultSum[rhlCount-1] : 0;
- } */
- 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<double> kScore = new List<double>();
- for (int k = 0; k < knowledgeName.Count; k++)
- {
- double OnePoint = 0;
- List<string> valuew = new List<string>();
- List<string> itemNo = new List<string>();
- keynowWrong.ForEach(x =>
- {
- valuew.Add("-");
- });
- valuew[0] = knowledgeName[k];
- int n = 0;
- int wrong = 0;
- int rhwC = 0;
- int rhlC = 0;
- double scores = 0;
- //知识点分值
- double gPoint = 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;
- itemNo.Add((n + 1).ToString());
- //处理单个知识点错题人数
- int phCount = 0;
- int plCount = 0;
- foreach (string id in exam.studentIds)
- {
- int index = exam.studentIds.IndexOf(id);
- if (exam.studentScores[index][n] == 0)
- {
- wrong++;
- if (exam.studentScores[index].Sum() >= rhw && phCount < rhwCount)
- {
- rhwC++;
- phCount++;
- continue;
- }
- if (exam.studentScores[index].Sum() <= rhl && plCount < (exam.studentIds.Count - rhlCount))
- {
- rhlC++;
- plCount++;
- continue;
- }
- continue;
- }
- else
- {
- //单个知识点得分情况
- scores += exam.studentScores[index][n] * itemPersent;
- //scoreCount++;
- }
- /*if (exam.studentScores[index].Sum() >= rhw && phCount < rhwCount)
- {
- rhwC++;
- phCount++;
- continue;
- }
- if (exam.studentScores[index].Sum() <= rhl && plCount < (exam.studentIds.Count - rhlCount))
- {
- rhlC++;
- plCount++;
- continue;
- }*/
- }
- gPoint += point[n];
- }
- valuew[1] = OnePoint.ToString();
- string itemNos = "";
- if (itemNo.Count > 0)
- {
- valuew[2] = string.Join(",", itemNo);
- /*foreach (string np in itemNo)
- {
- itemNos += np + ",";
- }
- valuew[2] = itemNos[0..^1];*/
- }
- else
- {
- valuew[2] = itemNos;
- }
- n++;
- });
- kScore.Add(gPoint);
- Score.Add(scores);
- knowScore.Add(OnePoint);
- //该知识点平均得分
- double sc = (exam.studentIds.Count - exam.lostStus.Count) > 0 ? Math.Round(scores * 1.0 / (exam.studentIds.Count - exam.lostStus.Count), 2) : 0;
- //错题关系表
- valuew[3] = (OnePoint > 0 ? Math.Round(sc / OnePoint, 2) : 0).ToString(); ;
- valuew[4] = wrong.ToString();
- valuew[5] = rhwC.ToString();
- valuew[6] = rhlC.ToString();
- wrongPersent.Add(valuew);
- //知识点占比
- double persent = TotalPoint > 0 ? OnePoint / TotalPoint : 0;
- //double persent = OnePoint / TotalPoint;
- per.Add(persent.ToString("0.00"));
- }
- //本次考试知识点占比
- List<double> allPer = new List<double>();
- foreach (double sc in Score)
- {
- allPer.Add(exam.studentIds.Count > 0 ? Math.Round(sc * 1.0 / exam.studentIds.Count, 2) : 0);
- }
- int stuNo = 0;
- exam.studentIds.ForEach(e =>
- {
- List<double> valueKnow = new List<double>();
- foreach (string know in knowledge)
- {
- double anwPoint = 0;
- double itemPersent = 0;
- int sno = 0;
- info.papers[index].knowledge.ForEach(kno =>
- {
- if (kno.Contains(know))
- {
- //当前知识点在该题占比多少
- itemPersent = kno.Count > 0 ? 1 / Convert.ToDouble(kno.Count) : 0;
- //itemPersent = 1 / Convert.ToDouble(kno.Count);
- anwPoint += result[stuNo][sno] * itemPersent;
- }
- sno++;
- });
- valueKnow.Add(anwPoint);
- }
- KeyValuePair<string, List<double>> keyValue = new KeyValuePair<string, List<double>>(e, valueKnow);
- datas.Add(keyValue);
- stuNo++;
- });
- KeyValuePair<string, List<string>> key1 = new KeyValuePair<string, List<string>>(exam.subjectId, knowledgeName);
- KeyValuePair<string, List<string>> key2 = new KeyValuePair<string, List<string>>(exam.subjectId, per);
- KeyValuePair<string, List<double>> key3 = new KeyValuePair<string, List<double>>(exam.subjectId, allPer);
- KeyValuePair<string, List<double>> key4 = new KeyValuePair<string, List<double>>(exam.subjectId, kScore);
- KeyValuePair<string, List<List<string>>> keyValue = new KeyValuePair<string, List<List<string>>>(exam.subjectId, wrongPersent);
- KeyValuePair<string, List<KeyValuePair<string, List<double>>>> valuePair = new KeyValuePair<string, List<KeyValuePair<string, List<double>>>>(exam.subjectId, datas);
- return (key1, key2, key3, key4, keyValue, valuePair);
- }
- private static (KeyValuePair<string, List<int>>, KeyValuePair<string, List<string>>, KeyValuePair<string, List<double>>, KeyValuePair<string, List<double>>, KeyValuePair<string, List<List<string>>>, KeyValuePair<string, List<KeyValuePair<string, List<double>>>>) DoLevel(ExamResult exam, ExamInfo info, List<string> keynowWrong)
- {
- List<double> point = new List<double>();
- List<List<double>> result = new List<List<double>>();
- List<ClassRange> classes = new List<ClassRange>();
- List<KeyValuePair<string, List<double>>> datas = new List<KeyValuePair<string, List<double>>>();
- //求单个认知层次所占分数
- List<string> per = new List<string>();
- List<List<string>> wrongPersent = new List<List<string>>();
- List<int> knowledgeName = new List<int>();
- //定位试卷信息
- int index = 0;
- foreach (ExamSubject subject in info.subjects)
- {
- if (subject.id.Equals(exam.subjectId))
- {
- break;
- }
- else
- {
- index++;
- }
- }
- knowledgeName.Add(1);
- knowledgeName.Add(2);
- knowledgeName.Add(3);
- knowledgeName.Add(4);
- knowledgeName.Add(5);
- knowledgeName.Add(6);
- //double Qnum = 0;
- point = info.papers[index].point;
- result = exam.studentScores;
- classes = exam.classes;
- //ids = exam.studentIds;
- //确定高分组 低分组人数
- /*List<List<double>> re = exam.studentScores;
- List<double> resultSum = new List<double>();
- foreach (List<double> data in re)
- {
- resultSum.Add(data.Sum());
- }*/
- double[] points = StringHelper.ListTodouble(exam.paper.point);
- double[,] scs = StringHelper.ListToDouble(exam.studentScores);
- var cdm = new ClouDASMatrix(scs, points);
- //scores.Sort((s1, s2) => { return s2.CompareTo(s1); });
- int rhwCount = cdm.SH.Count();
- double rhw = cdm.SH.LastOrDefault().Item2;
- int rhlCount = cdm.SL.Count();
- double rhl = cdm.SL.FirstOrDefault().Item2;
- //确定高分组 最低分数
- /* resultSum.Sort((s1, s2) => { return s2.CompareTo(s1); });
- int rhwCount = 0;
- double rhw = 0;
- int rhlCount = 0;
- double rhl = 0;
- if (resultSum.Count > 3)
- {
- rhwCount = Convert.ToInt32(Math.Floor(resultSum.Count * 0.27));
- rhw = rhwCount > 0 ? resultSum[rhwCount - 1] : 0;
- rhlCount = Convert.ToInt32(Math.Ceiling(resultSum.Count * 0.73));
- rhl = rhlCount > 0 ? resultSum[rhlCount] : 0;
- }
- else
- {
- rhwCount = Convert.ToInt32(Math.Floor(resultSum.Count * 0.27));
- rhw = rhwCount > 0 ? resultSum[rhwCount] : 0;
- rhlCount = Convert.ToInt32(Math.Ceiling(resultSum.Count * 0.73));
- rhl = rhlCount > 0 ? resultSum[rhlCount - 1] : 0;
- }*/
- //初始化年级总分
- 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<double> kScore = new List<double>();
- //List<double> allPer = new List<double>();
- for (int k = 0; k < knowledgeName.Count; k++)
- {
- double OnePoint = 0;
- List<string> valuew = new List<string>();
- List<string> itemNo = new List<string>();
- keynowWrong.ForEach(x =>
- {
- valuew.Add("-");
- });
- valuew[0] = knowledgeName[k].ToString();
- int n = 0;
- int wrong = 0;
- int rhwC = 0;
- int rhlC = 0;
- //int scoreCount = 0;
- double scores = 0;
- //所有认知层次得分
- double anwGPoint = 0;
- double gPoint = 0;
- info.papers[index].field.ForEach(kno =>
- {
- if (kno == knowledgeName[k])
- {
- OnePoint += point[n];
- itemNo.Add((n + 1).ToString());
- //处理认知层次错题人数
- int phCount = 0;
- int plCount = 0;
- foreach (string id in exam.studentIds)
- {
- int index = exam.studentIds.IndexOf(id);
- if (exam.studentScores[index][n] == 0)
- {
- wrong++;
- if (exam.studentScores[index].Sum() >= rhw && phCount < rhwCount)
- {
- rhwC++;
- phCount++;
- continue;
- }
- if (exam.studentScores[index].Sum() <= rhl && plCount < (exam.studentIds.Count - rhlCount))
- {
- rhlC++;
- plCount++;
- continue;
- }
- continue;
- }
- else
- {
- //单个认知层次得分情况
- scores += exam.studentScores[index][n];
- }
- /* if (exam.studentScores[index].Sum() >= rhw && phCount < rhwCount && exam.studentScores[index][n] == 0)
- {
- rhwC++;
- phCount++;
- continue;
- }
- if (exam.studentScores[index].Sum() <= rhl && plCount < (exam.studentIds.Count - rhlCount) && exam.studentScores[index][n] == 0)
- {
- rhlC++;
- plCount++;
- continue;
- }*/
- //anwGPoint += exam.studentScores[index][n];
- }
- gPoint += point[n];
- }
- valuew[1] = OnePoint.ToString();
- string itemNos = "";
- if (itemNo.Count > 0)
- {
- foreach (string np in itemNo)
- {
- itemNos += np + ",";
- }
- valuew[2] = itemNos[0..^1];
- }
- else
- {
- valuew[2] = itemNos;
- }
- n++;
- });
- Score.Add(scores);
- kScore.Add(gPoint);
- knowScore.Add(OnePoint);
- double sc = (exam.studentIds.Count - exam.lostStus.Count) > 0 ? Math.Round(scores * 1.0 / (exam.studentIds.Count - exam.lostStus.Count), 2) : 0;
- //错题关系表
- valuew[3] = (OnePoint > 0 ? Math.Round(sc / OnePoint, 2) : 0).ToString();
- valuew[4] = wrong.ToString();
- valuew[5] = rhwC.ToString();
- valuew[6] = rhlC.ToString();
- wrongPersent.Add(valuew);
- //认知层次占比
- double persent = TotalPoint > 0 ? OnePoint / TotalPoint : 0;
- //allPer.Add(OnePoint > 0 ? Math.Round(sc / OnePoint, 2) : 0);
- per.Add(persent.ToString("0.00"));
- }
- //本次考试认知层次占比
- List<double> allPer = new List<double>();
- foreach (double sc in Score)
- {
- allPer.Add(exam.studentIds.Count > 0 ? Math.Round(sc * 1.0 / exam.studentIds.Count, 2) : 0);
- }
- int stuNo = 0;
- exam.studentIds.ForEach(e =>
- {
- List<double> valueKnow = new List<double>();
- foreach (int know in knowledgeName)
- {
- double anwPoint = 0;
- double itemPersent = 0;
- int sno = 0;
- info.papers[index].field.ForEach(kno =>
- {
- if (kno == know)
- {
- //当前认知层次在该题占比多少
- itemPersent = 1;
- anwPoint += result[stuNo][sno] * itemPersent;
- }
- sno++;
- });
- valueKnow.Add(anwPoint);
- }
- KeyValuePair<string, List<double>> keyValue = new KeyValuePair<string, List<double>>(e, valueKnow);
- datas.Add(keyValue);
- stuNo++;
- });
- KeyValuePair<string, List<int>> key1 = new KeyValuePair<string, List<int>>(exam.subjectId, knowledgeName);
- KeyValuePair<string, List<string>> key2 = new KeyValuePair<string, List<string>>(exam.subjectId, per);
- KeyValuePair<string, List<double>> key3 = new KeyValuePair<string, List<double>>(exam.subjectId, allPer);
- KeyValuePair<string, List<double>> key4 = new KeyValuePair<string, List<double>>(exam.subjectId, kScore);
- KeyValuePair<string, List<List<string>>> keyValue = new KeyValuePair<string, List<List<string>>>(exam.subjectId, wrongPersent);
- KeyValuePair<string, List<KeyValuePair<string, List<double>>>> valuePair = new KeyValuePair<string, List<KeyValuePair<string, List<double>>>>(exam.subjectId, datas);
- return (key1, key2, key3, key4, keyValue, valuePair);
- }
- [ProducesDefaultResponseType]
- [HttpPost("simple")]
- [Authorize(Roles = "IES")]
- [AuthToken(Roles = "teacher,admin")]
- public async Task<IActionResult> simple(JsonElement request)
- {
- //获取评测的ID
- if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
- if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
- try
- {
- List<Dictionary<string, object>> averageMap = new List<Dictionary<string, object>>();
- List<Dictionary<string, object>> averageTotal = new List<Dictionary<string, object>>();
- var client = _azureCosmos.GetCosmosClient();
- //todo 需要检查数据是否存在
- ExamInfo info = new();
- var response = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemStreamAsync(id.ToString(), new PartitionKey($"Exam-{code}"));
- if (response.Status == 200)
- {
- using var cJson = await JsonDocument.ParseAsync(response.ContentStream);
- info = cJson.ToObject<ExamInfo>();
- }
- else {
- return Ok(new { averageMap, averageTotal });
- }
- List<ExamResult> examResults = new List<ExamResult>();
- var query = $"select c.id,c.name,c.subjectId,c.studentScores,c.studentIds,c.paper,c.classes,c.afp,c.akp,c.lostStus from c where c.examId = '{id}' ";
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<ExamResult>(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamResult-{id}") }))
- {
- examResults.Add(item);
- }
- foreach (ExamResult result in examResults)
- {
- List<double> ClassAverage = new List<double>();
- List<ClassSimple> ClassName = new List<ClassSimple>();
- Dictionary<string, object> mapSubject = new Dictionary<string, object>();
- Dictionary<string, object> mapClass = new Dictionary<string, object>();
- int subIndex = 0;
- foreach (var sub in info.subjects)
- {
- if (sub.id.Equals(result.subjectId))
- {
- break;
- }
- else
- {
- subIndex++;
- }
- }
- List<double> points = info.papers[subIndex].point;
- HashSet<string> kn = new HashSet<string>();
- foreach (List<string> know in info.papers[subIndex].knowledge) {
- foreach (string k in know) {
- kn.Add(k);
- }
- }
- List<int> fs = new() { 1,2,3,4,5,6 };
- mapClass.Add("subjectId", result.subjectId);
- foreach (ClassRange range in result.classes)
- {
- ClassSimple classSimple = new()
- {
- id = range.id,
- name = range.name
- };
- ClassName.Add(classSimple);
- double totalClass = 0;
- List<string> counts = new();
- for (int i = range.range[0]; i <= range.range[1]; i++)
- {
- if (result.lostStus.Contains(result.studentIds[i])) {
- counts.Add(result.studentIds[i]);
- continue;
- }
- totalClass += result.studentScores.Count > 0 ? result.studentScores[i].Sum() : 0;
-
- }
- ClassAverage.Add(range.range[1] - range.range[0] + 1 - counts.Count > 0 ? totalClass * 1.0 / (range.range[1] - range.range[0] + 1 - counts.Count) : 0);
- }
- mapClass.Add("className", ClassName);
- mapClass.Add("ClassAverage", ClassAverage);
- averageMap.Add(mapClass);
- List<double> wn = await getWrongNum(result, points);
- List<double> SubjectTotal = new List<double>();
- foreach (List<double> score in result.studentScores)
- {
- SubjectTotal.Add(score.Sum());
- }
- mapSubject.Add("subjectId", result.subjectId);
- mapSubject.Add("total", SubjectTotal);
- mapSubject.Add("wrongNum", wn);
- mapSubject.Add("akp", result.akp);
- mapSubject.Add("afp", result.afp);
- mapSubject.Add("kn",kn);
- mapSubject.Add("fs", fs);
- averageTotal.Add(mapSubject);
- }
- return Ok(new { averageMap, averageTotal });
- }
- catch (Exception e)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/simple()\n{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
- return BadRequest();
- }
- }
- private Task<List<double>> getWrongNum(ExamResult result, List<double> points)
- {
- int num = 0;
- List<double> wn = new List<double>();
- foreach (var point in points)
- {
- int wnum = 0;
- double p = point * 0.8;
- foreach (ClassRange range in result.classes)
- {
- for (int i = range.range[0]; i <= range.range[1]; i++)
- {
- //判断推送的数据中,学生正常得分数据
- if (result.studentScores[i].Count > 0)
- {
- if (result.studentScores[i][num] < point)
- {
- if (result.studentScores[i][num] < p)
- {
- wnum++;
- }
- else
- {
- continue;
- }
- }
- else
- {
- continue;
- }
- }
- else
- {
- wnum++;
- }
- }
- }
- wn.Add(wnum);
- num++;
- }
- return Task.FromResult(wn);
- }
- public class ClassSimple
- {
- public string id { get; set; }
- public string name { get; set; }
- }
- [ProducesDefaultResponseType]
- [HttpPost("studentAnalysis")]
- [Authorize(Roles = "IES")]
- [AuthToken(Roles = "teacher,admin,student")]
- public async Task<IActionResult> studentAnalysis(JsonElement request)
- {
- //获取个人或者校本
- if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
- //评测Id
- if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
- if (!request.TryGetProperty("sId", out JsonElement sId)) return BadRequest();
- if (!request.TryGetProperty("cId", out JsonElement cId)) return BadRequest();
- if (!request.TryGetProperty("gId", out JsonElement gId)) return BadRequest();
- try
- {
- List<Dictionary<string, object>> averageMap = new();
- List<Dictionary<string, object>> averageTotal = new();
- List<List<double>> classAllAverage = new();
- School school = new();
- var client = _azureCosmos.GetCosmosClient();
- ExamInfo info = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"Exam-{code}"));
- var response = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(code.ToString(), new PartitionKey($"Base"));
- if (response.Status == 200)
- {
- using var json = await JsonDocument.ParseAsync(response.ContentStream);
- school = json.ToObject<School>();
- }
- //School school = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(code.ToString(), new PartitionKey($"Base"));
- List<ExamResult> examResults = new List<ExamResult>();
- var query = $"select c.id,c.name,c.subjectId,c.studentScores,c.studentIds,c.paper,c.classes from c where c.examId = '{id}' ";
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<ExamResult>(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamResult-{id}") }))
- {
- examResults.Add(item);
- }
- if (examResults.Count == 0)
- {
- return Ok(new { code = ResponseCode.DATA_EMPTY_NULL, v = "正在结算中" });
- }
- int indexClass = 0;
- HashSet<string> cla = new HashSet<string>();
- HashSet<string> stu = new HashSet<string>();
- double totalScore = 0;
- List<List<double>> allList = new List<List<double>>();
- double income = 0;
- foreach (Period period in school.period)
- {
- if (info.period.id.Equals(period.id))
- {
- income = period.analysis.income;
- }
- }
- //获取进线人数
- int count = (int)System.Math.Round(info.stuCount * (income / 100.0), MidpointRounding.AwayFromZero);
- foreach (ExamResult result in examResults)
- {
- List<double> ClassAverage = new List<double>();
- List<int> personCount = new List<int>();
- List<string> ClassId = new List<string>();
- Dictionary<string, object> mapClass = new Dictionary<string, object>();
- int index = result.studentIds.IndexOf(sId.ToString());
- //个人总分
- totalScore += result.studentScores[index].Sum();
- mapClass.Add("subjectId", result.subjectId);
- double totalGrade = 0;
- List<double> gradeScores = new List<double>();
- List<List<double>> classScores = new List<List<double>>();
- //此处声明集合存储原本的成绩序列
- List<List<double>> cScores = new List<List<double>>();
- /*var sc = result.classes.GroupBy(m => new { m.gradeId }).Select(c => new { gId = c.Key.gradeId, ranges = c.ToList() }).ToList();
- foreach (var aa in sc)
- {
- foreach (ClassRange range in aa.ranges)
- {
- List<double> scores = new();
- List<double> finalScores = new();
- ClassId.Add(range.id);
- cla.Add(range.id);
- double totalClass = 0;
- for (int i = range.range[0]; i <= range.range[1]; i++)
- {
- totalClass += result.studentScores[i].Sum();
- scores.Add(result.studentScores[i].Sum());
- finalScores.Add(result.studentScores[i].Sum());
- gradeScores.Add(result.studentScores[i].Sum());
- totalGrade += result.studentScores[i].Sum();
- stu.Add(result.studentIds[i]);
- }
- classScores.Add(scores);
- cScores.Add(finalScores);
- ClassAverage.Add(range.range[1] - range.range[0] + 1 > 0 ? Math.Round(totalClass * 1.0 / (range.range[1] - range.range[0] + 1), 2) : 0);
- personCount.Add(range.range[1] - range.range[0] + 1);
- }
- classAllAverage.Add(ClassAverage);
- gradeScores.Sort((s1, s2) => { return s2.CompareTo(s1); });
- indexClass = ClassId.IndexOf(cId.ToString());
- //单科成绩
- allList.Add(cScores[indexClass]);
- classScores[indexClass].Sort((s1, s2) => { return s2.CompareTo(s1); });
- mapClass.Add("scoreSum", result.paper.point.Sum());
- mapClass.Add("score", result.studentScores[index].Sum());
- mapClass.Add("classAverage", ClassAverage[indexClass]);
- mapClass.Add("classCount", personCount[indexClass]);
- mapClass.Add("classRank", classScores[indexClass].IndexOf(result.studentScores[index].Sum()));
- mapClass.Add("gradeAverage", result.studentIds.Count > 0 ? Math.Round(totalGrade * 1.0 / result.studentIds.Count, 2) : 0);
- mapClass.Add("gradeCount", result.studentIds.Count);
- mapClass.Add("gradeRank", gradeScores.IndexOf(result.studentScores[index].Sum()));
- averageMap.Add(mapClass);
- }
- */
- foreach (ClassRange range in result.classes)
- {
- List<double> scores = new List<double>();
- List<double> finalScores = new List<double>();
- ClassId.Add(range.id);
- cla.Add(range.id);
- double totalClass = 0;
- for (int i = range.range[0]; i <= range.range[1]; i++)
- {
- totalClass += result.studentScores[i].Sum();
- scores.Add(result.studentScores[i].Sum());
- finalScores.Add(result.studentScores[i].Sum());
- gradeScores.Add(result.studentScores[i].Sum());
- totalGrade += result.studentScores[i].Sum();
- stu.Add(result.studentIds[i]);
- }
- classScores.Add(scores);
- cScores.Add(finalScores);
- ClassAverage.Add(range.range[1] - range.range[0] + 1 > 0 ? Math.Round(totalClass * 1.0 / (range.range[1] - range.range[0] + 1), 2) : 0);
- personCount.Add(range.range[1] - range.range[0] + 1);
- }
- }
- //处理班级/年级全科均分
- List<double> AllAverage = new List<double>();
- double a = 0;
- for (int k = 0; k < cla.Count; k++)
- {
- for (int i = 0; i < classAllAverage.Count; i++)
- {
- a += classAllAverage[i][k];
- }
- AllAverage.Add(a);
- }
- List<double> classScore = new List<double>();
- for (int i = 0; i < allList[0].Count; i++)
- {
- double b = 0;
- for (int m = 0; m < allList.Count; m++)
- {
- b += allList[m][i];
- }
- classScore.Add(b);
- }
- classScore.Sort((s1, s2) => { return s2.CompareTo(s1); });
- //处理年级总分以及排名
- List<double> GradeScore = new List<double>();
- foreach (string ss in stu)
- {
- double score = 0;
- foreach (ExamResult result in examResults)
- {
- int index = result.studentIds.IndexOf(ss);
- score += result.studentScores[index].Sum();
- }
- GradeScore.Add(score);
- }
- GradeScore.Sort((s1, s2) => { return s2.CompareTo(s1); });
- double ipoint = GradeScore[count];
- return Ok(new { income = ipoint, rankc = classScore.IndexOf(totalScore), rankg = GradeScore.IndexOf(totalScore), classAverage = Math.Round(AllAverage[indexClass], 2), gradeAverage = cla.Count > 0 ? Math.Round(AllAverage.Sum() * 1.0 / cla.Count, 2) : 0, averageMap }); ;
- }
- catch (Exception e)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/studentAnalysis()\n{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
- return BadRequest();
- }
- }
- [ProducesDefaultResponseType]
- [HttpPost("education-analysis")]
- [Authorize(Roles = "IES")]
- [AuthToken(Roles = "teacher,admin,student")]
- public async Task<IActionResult> education(JsonElement request) {
- if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
- if (!request.TryGetProperty("period", out JsonElement period)) return BadRequest();
- if (!request.TryGetProperty("gId", out JsonElement gId)) return BadRequest();
- try {
- var client = _azureCosmos.GetCosmosClient();
- List<ExamInfo> infos = new List<ExamInfo>();
- var query = $"select c.id,c.name,c.source from c where c.period.id = '{period}'";
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<ExamInfo>(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Exam-{code}") }))
- {
- infos.Add(item);
- }
- return Ok();
- } catch (Exception e) {
- return Ok(new { code = 500});
- }
- }
- public async Task<string> getGId(int cyear, string periodId, string code)
- {
- var client = _azureCosmos.GetCosmosClient();
- School sc = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(code, new Azure.Cosmos.PartitionKey("Base"));
- string gradeId = "";
- foreach (Period period in sc.period)
- {
- if (period.id.Equals(periodId))
- {
- foreach (Semester semester in period.semesters)
- {
- if (semester.start == 1)
- {
- int year = DateTimeOffset.UtcNow.Year;
- int month = DateTimeOffset.UtcNow.Month;
- int day = DateTimeOffset.UtcNow.Day;
- int time = 0;
- if (month == semester.month)
- {
- time = day >= semester.day ? 0 : 1;
- }
- else
- {
- time = month > semester.month ? 0 : 1;
- }
- int eyear = year - time;
- gradeId = (eyear - cyear).ToString();
- }
- }
- }
- }
- return gradeId;
- }
- }
- }
|