12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937 |
- using ClouDASLibx;
- using Microsoft.AspNetCore.Mvc;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using TEAMModelOS.SDK.Extension.DataResult.JsonRpcRequest;
- using TEAMModelOS.SDK.Extension.DataResult.JsonRpcResponse;
- using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
- using TEAMModelOS.SDK.Helper.Common.StringHelper;
- using TEAMModelOS.SDK.Module.AzureCosmosDB.Interfaces;
- using TEAMModelOS.SDK.Module.AzureTable.Interfaces;
- using TEAMModelOS.Service.Analysis.Interfaces;
- using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
- using System.Diagnostics;
- using TEAMModelOS.SDK.Helper.Common.JsonHelper;
- using TEAMModelOS.SDK.Helper.Security.ShaHash;
- using TEAMModelOS.SDK.Context.Exception;
- using TEAMModelOS.Service.Models;
- namespace TEAMModelOS.Controllers.Analysis
- {
- [Route("api/[controller]")]
- [ApiController]
- public class AchievementController : Controller
- {
- private readonly IAzureCosmosDBV3Repository azureCosmosDBRepository;
- private readonly IAchievementService achievementService;
- private const string CacheCosmosPrefix = "Analysis:";
- private const int timeoutSeconds = 3600;
- public AchievementController(IAchievementService _achievementService, IAzureCosmosDBV3Repository _azureCosmosDBRepository)
- {
- azureCosmosDBRepository = _azureCosmosDBRepository;
- achievementService = _achievementService;
- }
- [HttpPost("Achievement")]
- public async Task<BaseJosnRPCResponse> FindExam(JosnRPCRequest<Dictionary<string, object>> request)
- {
- JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
- Dictionary<string, dynamic> info = new Dictionary<string, dynamic>();
- if (RedisHelper.Instance != null)
- {
- info = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + request.method,
- ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(request.@params)), timeoutSeconds, () => { return FindExamRedis(request.@params, request.method); });
- //数据从redis读取过后进行转换格式
- builder.Data(JsonApiHelper.FromApiJson<System.Text.Json.JsonElement>(info.ToJson()));
- }
- else
- {
- info = await FindExamRedis(request.@params, request.method);
- builder.Data(JsonApiHelper.FromApiJson<System.Text.Json.JsonElement>(info.ToJson()));
- }
- return builder.build();
- }
- public async Task<List<ExamResult>> FindExamResultRedis(Dictionary<string, object> dict, string method)
- {
- try
- {
- List<ExamResult> info = await azureCosmosDBRepository.FindByDict<ExamResult>(dict);
- if (RedisHelper.Instance != null)
- {
- if (!RedisHelper.Exists(CacheCosmosPrefix + method))
- {
- await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), info);
- }
- else
- {
- await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), info);
- await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
- }
- }
- return info;
- }
- catch (Exception e)
- {
- throw new BizException(e.Message);
- }
- }
- public async Task<Dictionary<string, dynamic>> FindExamRedis(Dictionary<string, object> dict, string method) {
- JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
- //Console.WriteLine(DateTimeOffset.Now.Second);
- List<ExamResult> exams = new List<ExamResult>();
- if (RedisHelper.Instance != null)
- {
- exams = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + method + "resource",
- ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), timeoutSeconds, () => { return FindExamResultRedis(dict, method + "resource"); });
- }
- else
- {
- exams = await FindExamResultRedis(dict, method + "resource");
- }
- Dictionary<string, object> stuMap = new Dictionary<string, object>
- {
- { "schoolCode", "Habook" }
- };
- //声明进行标准用来设置进线标准,权重等参数
- dict.TryGetValue("Standard", out object Standard);
- List<Student> students = await azureCosmosDBRepository.FindByDict<Student>(stuMap);
- //Console.WriteLine(DateTimeOffset.Now.Second);
- List<Dictionary<string, object>> examList = new List<Dictionary<string, object>>();
- HashSet<string> classList = new HashSet<string>();
- HashSet<string> classId = new HashSet<string>();
- List<string> subjectAverage = new List<string>();
- List<List<string>> subjectPoints = new List<List<string>>();
- Dictionary<string, object> Average = new Dictionary<string, object>();
- Dictionary<string, object> entryTable = new Dictionary<string, object>();
- Dictionary<string, dynamic> achievementAnalysis = new Dictionary<string, dynamic>();
- List<string> arrSubject = new List<string>();
- List<string> keys = new List<string>();
- List<string> person = new List<string>();
- List<List<int>> subSum = new List<List<int>>();
- List<string> gAverage = new List<string>();
- List<string> cAverage = new List<string>();
- Dictionary<string, object> AclassAverage = new Dictionary<string, object>();
- Dictionary<string, object> passRateMap = new Dictionary<string, object>();
- List<List<string>> passALL = new List<List<string>>();
- List<string> gradeList = new List<string>();
- List<string> areaList = new List<string>();
- List<string> sbujectsList = new List<string>();
- if (exams.IsNotEmpty())
- {
- //存放进线情况统计key值
- keys.Add("name");
- keys.Add("className");
- keys.Add("gradeRank");
- keys.Add("score");
- //初始化进行人数
- double iPersons = 0;
- if (exams.IsNotEmpty())
- {
- int classLen = exams[0].classes.Count;
- for (int cls = 0; cls < classLen; cls++)
- {
- if (exams[0].classes[cls].TryGetValue(exams[0].classes[cls].Keys.ToArray<string>()[0], out int[] index))
- {
- List<int> stuScore = new List<int>();
- int stdLen = index[1] - index[0] + 1;
- for (int i = 0; i < stdLen; i++)
- {
- stuScore.Add(0);
- }
- subSum.Add(stuScore);
- }
- }
- }
- int xx = 0;
- //初始化总分
- int sumPoint = 0;
- int sumperson = exams[0].ids.Count;
- for (int i = 0; i < exams[0].ids.Count; i++)
- {
- if (exams[0].ids[i].Equals("0"))
- {
- sumperson--;
- }
- }
- exams.ForEach(e =>
- {
- //获取总分数
- e.result.ForEach(r =>
- {
- sumPoint += r.Sum();
- });
- });
- var gradeAverage = sumPoint / sumperson;
- //存放年级平均
- gAverage.Add(gradeAverage.ToString());
- //任意一次考试数据提取班级信息
- List<Dictionary<string, int[]>> classToName = exams[0].classes;
- //任意一次考试数据提取学生ID信息
- List<string> idToName = exams[0].ids;
- //var gradeAverage = Math.Floor(Math.Round(decimal.Parse((10 / 3).ToString("0.000")), 2));
- List<string> subjects = new List<string>();
- exams.ForEach(e =>
- {
- int peopleCount = 0;
- Dictionary<string, object> detail = new Dictionary<string, object>
- {
- { "name", e.subjectCode }
- };
- subjects.Add(e.subjectCode);
- List<string> ClassAverage = new List<string>();
- //计算试卷总分
- int sum = e.point.Sum();
- //及格分数
- double passRate = sum * 0.6;
- int gradeCount = 0;
- //初始化科目总分
- double subjectPoint = 0;
- //科目平均分
- double subAverage = 0;
- //计算班级平均分
- int classIndex = 0;
- List<string> passList = new List<string>();
- e.classes.ForEach(c =>
- {
- List<List<string>> classPRL = new List<List<string>>();
- //初始化班级总分
- int classPoint = 0;
- //初始化班级缺考人数
- int classCount = 0;
- //初始化班级平均分
- double points = 0;
- double passPoint = 0;
- //初始化及格人数
- int passCount = 0;
- //初始化各班参考人数
- int counts = 0;
- //c.Keys遍历key值
- foreach (string key in c.Keys)
- {
- classList.Add(key);
- }
- //每个班级平均分
- foreach (int[] value in c.Values)
- {
- for (int i = value[0]; i <= value[1]; i++)
- {
- //初始化学生单科个人得分
- int stuPoints = e.result[i].Sum();
- //Console.WriteLine("xx: "+xx+" classIndex:" + classIndex + ",i:" + i + " value[0]:" + value[0]+ " value[0]:" + value[1]);
- subSum[classIndex][i - value[0]] = stuPoints + subSum[classIndex][i - value[0]];
- if (stuPoints > passRate)
- {
- passCount++;
- gradeCount++;
- }
- classPoint += e.result[i].Sum();
- if (e.result[i].Sum() == 0)
- {
- classCount++;
- }
- }
- //每个班级实际参考人数
- counts = value[1] - value[0] - classCount + 1;
- points = Convert.ToDouble(classPoint) / counts;
- ClassAverage.Add(points.ToString("0.00"));
- person.Add(counts + "");
- }
- passPoint = Convert.ToDouble(passCount) / counts;
- passList.Add(passPoint.ToString("0.00"));
- //classPRM.Add(classPRL);
- classIndex += 1;
- });
- //科目平均分
- ClassAverage.ForEach(a =>
- {
- subjectPoint += Convert.ToDouble(a);
- });
- subAverage = subjectPoint / ClassAverage.Count();
- subjectAverage.Add(subAverage.ToString("0.00"));
- detail.Add("schoolAverage", subAverage.ToString("0.00"));
- detail.Add("areaAverage", subAverage.ToString("0.00"));
- detail.Add("score", ClassAverage);
- examList.Add(detail);
- //获取实际参考总人数
- e.ids.ForEach(i =>
- {
- if (!i.Equals("0"))
- {
- peopleCount++;
- }
- });
- //班级及格率
- passALL.Add(passList);
- //年级及格率
- double gradePass = Convert.ToDouble(gradeCount) / peopleCount;
- gradeList.Add(gradePass.ToString("0.00"));
- //passALL.Add(gradeList);
- //区级及格率
- //passALL.Add(areaList);
- //获取进线人数
- iPersons = peopleCount * 0.4;
- //计算每个学生单科成绩
- for (int i = 0; i < e.ids.Count(); i++)
- {
- List<string> info = new List<string>();
- //info = new List<string>();
- info.Add(e.ids[i]);
- info.Add(e.subjectCode);
- info.Add(e.result[i].Sum() + "");
- //classId.Add(e.Ids[i]);
- subjectPoints.Add(info);
- }
- keys.Add(e.subjectCode);
- xx += 1;
- //subjectPoints = GetMark(e.Result,e.Ids);
- });
- //subjectPoints.ForEach(f => f.GroupBy(f[0]));
- //进线情况统计
- Dictionary<string, List<List<string>>> dicts = new Dictionary<string, List<List<string>>>();
- foreach (IGrouping<string, List<string>> group in subjectPoints.GroupBy(c => c[0]))
- {
- // arr.Add(group.Key);
- dicts.Add(group.Key, group.ToList());
- };
- Average.Add("classList", classList);
- List<List<string>> sp = new List<List<string>>();
- //Dictionary<string, int> rankScore = new Dictionary<string, int>();
- List<int> rankScore = new List<int>();
- foreach (string key in dicts.Keys)
- {
- int score = 0;
- List<string> values = new List<string>();
- keys.ForEach(x =>
- {
- values.Add("-");
- });
- foreach (List<string> val in dicts[key])
- {
- int index = keys.IndexOf(val[1]);
- values[index] = val[2];
- values[keys.IndexOf("name")] = val[0];
- score += int.Parse(val[2]);
- values[keys.IndexOf("score")] = score + "";
- }
- rankScore.Add(score);
- sp.Add(values);
- }
- achievementService.ReName(sp, idToName, classToName, students);
- //处理人数为整
- string ip = iPersons.ToString("0");
- //初始化进线分数
- int ipoint = 0;
- //计算成绩年级排名
- rankScore.Sort(delegate (int s1, int s2) { return s2.CompareTo(s1); });
- ipoint = rankScore[int.Parse(ip)];
- foreach (List<string> rank in sp)
- {
- int index = rankScore.IndexOf(int.Parse(rank[3]));
- rank[2] = (index + 1) + "";
- }
- //排除成绩为零的选手
- for (int i = sp.Count - 1; i >= 0; i--)
- {
- if (sp[i][0].Equals("0"))
- {
- sp.Remove(sp[i]);
- }
- }
- entryTable.Add("keys", keys);
- entryTable.Add("datas", sp);
- //封装进线人数统计
- List<string> keyLine = new List<string>
- {
- "gradeRank",
- "name",
- "entryNum",
- "totalNum",
- "overAverageRate"
- };
- Dictionary<string, object> entryLineBar = new Dictionary<string, object>();
- //存放班级信息
- List<string> className = new List<string>();
- foreach (string cla in classList)
- {
- className.Add(cla);
- }
- List<List<string>> datas = new List<List<string>>();
- //记录各个班级进线率占比
- List<string> persent = new List<string>();
- int m = 0;
- foreach (List<int> points in subSum)
- {
- List<string> detail = new List<string>();
- keyLine.ForEach(x =>
- {
- detail.Add("-");
- });
- double sum = points.Count;
- int j = 0;
- for (int i = 0; i < points.Count; i++)
- {
- if (points[i] > ipoint)
- {
- j++;
- }
- }
- double Lines = j;
- detail[1] = className[m].ToString();
- detail[2] = j.ToString();
- detail[3] = points.Count.ToString();
- var t3 = Math.Floor(Math.Round(decimal.Parse((Lines / sum).ToString("0.000")), 2) * 100);
- persent.Add(t3.ToString());
- detail[4] = t3.ToString();
- datas.Add(detail);
- m++;
- }
- persent.Sort(delegate (string s1, string s2) { return int.Parse(s2).CompareTo(int.Parse(s1)); });
- //存放班级的年级排名
- List<string> ranks = new List<string>();
- foreach (List<string> des in datas)
- {
- int index = persent.IndexOf(des[4]);
- des[0] = (index + 1).ToString();
- ranks.Add((index + 1).ToString());
- }
- //预警统计
- Dictionary<string, object> early = new Dictionary<string, object>();
- List<List<string>> earlyWarning = new List<List<string>>();
- List<string> keyWarning = new List<string>
- {
- "classId",
- "totalNum",
- "average",
- "standardDeviation",
- "overAverageRate",
- "gradeRank"
- };
- int n = 0;
- foreach (List<int> points in subSum)
- {
- double sum = 0;
- List<string> classInfo = new List<string>();
- classInfo.Add(className[n]);
- classInfo.Add(points.Count.ToString());
- foreach (int point in points)
- {
- sum += point;
- }
- double Aver = sum / points.Count;
- classInfo.Add(Aver.ToString());
- //存放班级平均
- cAverage.Add(Aver.ToString());
- //标准差
- double powSum = 0;
- foreach (int point in points)
- {
- powSum += Math.Pow(point - Aver, 2);
- }
- var pow = Math.Pow(powSum / points.Count, 0.5);
- classInfo.Add(pow.ToString("0.00"));
- //超均率
- var super = (sum - (sum - 100)) / (sum - 100);
- classInfo.Add(super.ToString("0.00"));
- //年级排名
- classInfo.Add(ranks[n]);
- earlyWarning.Add(classInfo);
- n++;
- }
- //sbujectsList.Add(subjects);
- passRateMap.Add("subjects", subjects);
- passRateMap.Add("class", passALL);
- passRateMap.Add("grade", gradeList);
- passRateMap.Add("area", areaList);
- //passRate.Add("passRate", passALL);
- early.Add("keys", keyWarning);
- early.Add("datas", earlyWarning);
- AclassAverage = achievementService.GetAverage(exams, gAverage, cAverage, subSum, students);
- List<Dictionary<string, object>> rankPR = achievementService.GetPR(exams, subSum, students);
- entryLineBar.Add("keys", keyLine);
- entryLineBar.Add("datas", datas);
- //sp.Sort(delegate (string s1, string s2) { return int.Parse(s1).CompareTo(int.Parse(s2)); });
- Average.Add("subjectAverage", subjectAverage);
- Average.Add("datas", examList);
- achievementAnalysis.Add("passRate", passRateMap);
- achievementAnalysis.Add("average", Average);
- achievementAnalysis.Add("entryLineBar", entryLineBar);
- achievementAnalysis.Add("entryTable", entryTable);
- achievementAnalysis.Add("earlyWarning", early);
- achievementAnalysis.Add("rankPR", rankPR);
- achievementAnalysis.Add("stuAverage", AclassAverage);
- //Redis处理结果集
- if (RedisHelper.Instance != null)
- {
- if (!RedisHelper.Exists(CacheCosmosPrefix + method))
- {
- await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), achievementAnalysis);
- }
- else
- {
- await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), achievementAnalysis);
- await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
- }
- }
- return achievementAnalysis;
- }
- else return achievementAnalysis;
- }
- /* public List<string> GetMark(List<List<int>> point,List<string> ids) {
- List<string> info = null;
- for (int i = 0;i <= ids.Count();i++) {
- info = new List<string>();
- info.Add(ids[i]);
- info.Add(point[i].Sum()+"");
- }
- return info;
- }*/
- [HttpPost("PointAnalysis")]
- public async Task<BaseJosnRPCResponse> PointAnalysis(JosnRPCRequest<Dictionary<string, object>> request)
- {
- JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
- List<Dictionary<string, dynamic>> info = new List<Dictionary<string, dynamic>>();
- if (RedisHelper.Instance != null)
- {
- info = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + request.method,
- ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(request.@params)), timeoutSeconds, () => { return FindPointAnalysisRedis(request.@params, request.method); });
- //数据从redis读取过后进行转换格式
- builder.Data(JsonApiHelper.FromApiJson<System.Text.Json.JsonElement>(info.ToJson()));
- }
- else
- {
- info = await FindPointAnalysisRedis(request.@params, request.method);
- builder.Data(JsonApiHelper.FromApiJson<System.Text.Json.JsonElement>(info.ToJson()));
- }
- return builder.build();
- }
- public async Task<List<Dictionary<string, dynamic>>> FindPointAnalysisRedis(Dictionary<string, object> dict, string method)
- {
- //JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
- List<Dictionary<string, dynamic>> scatterAnalysis = new List<Dictionary<string, dynamic>>();
- //Dictionary<string, object> scatterAnalysis = new Dictionary<string, object>();
- List<ExamResult> exams = new List<ExamResult>();
- if (RedisHelper.Instance != null)
- {
- exams = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + method + "resource",
- ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), timeoutSeconds, () => { return FindExamResultRedis(dict, method + "resource"); });
- }
- else
- {
- exams = await FindExamResultRedis(dict, method + "resource");
- }
- Dictionary<string, object> stuMap = new Dictionary<string, object>
- {
- { "schoolCode", "Habook" }
- };
- List<Student> students = await azureCosmosDBRepository.FindByDict<Student>(stuMap);
- List<string> key = new List<string>
- {
- "name",
- "className",
- "x",
- "y",
- "memberId",
- "score",
- "trueNum",
- "falseNum",
- "hardList",
- "carefulList",
- "scatter"
- };
- //key.Add("areaName");
- if (exams.IsNotEmpty())
- {
- //提取班级信息
- List<Dictionary<string, int[]>> classToName = exams[0].classes;
- //提取学生ID信息
- List<string> idToName = exams[0].ids;
- exams.ForEach(e =>
- {
- Dictionary<string, object> detail = new Dictionary<string, object>
- {
- { "keys", key }
- };
- List<List<string>> datas = new List<List<string>>();
- Dictionary<string, object> subject = new Dictionary<string, object>
- {
- { "name", e.subjectCode }
- };
- double[] point = StringHelper.ListTodouble(e.point);
- double[,] result = StringHelper.ListToDouble(e.result);
- try
- {
- var cdm = new ClouDASMatrix(result, point);
- //学生通过率
- List<double> pass = cdm.PassingRate;
- //学生稳定度
- 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.ids.Count - 1; k >= 0; k--)
- {
- if (e.ids[k].Equals("0"))
- {
- e.ids.Remove(e.ids[k]);
- }
- }
- e.ids.ForEach(s =>
- {
- if (e.result[i].Sum() != 0)
- {
- List<string> info = new List<string>
- {
- s,
- "-",
- sta[i].ToString(),
- pass[i].ToString(),
- i + 1 + "",
- e.result[i].Sum().ToString()
- };
- int right = 0;
- int wrong = 0;
- foreach (int p in e.result[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() + ",";
- }
- info.Add(striveAll.Substring(0, striveAll.Length - 1));
- info.Add(careAll.Substring(0, careAll.Length - 1));
- info.Add(stu[i].ToString());
- datas.Add(info);
- }
- i++;
- });
- achievementService.ReName(datas, idToName, classToName, students);
- detail.Add("datas", datas);
- subject.Add("scatter", detail);
- scatterAnalysis.Add(subject);
- }
- catch (Exception ex)
- {
- //builder.Data(exams);
- //ex.Message;
- Console.WriteLine("---------------------" + ex.Message + "--------------------------");
- }
- });
- //Redis处理结果集
- if (RedisHelper.Instance != null)
- {
- if (!RedisHelper.Exists(CacheCosmosPrefix + method))
- {
- await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), scatterAnalysis);
- }
- else
- {
- await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), scatterAnalysis);
- await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
- }
- }
- return scatterAnalysis;
- }else return scatterAnalysis;
- }
- [HttpPost("ExerciseScatter")]
- public async Task<BaseJosnRPCResponse> ExerciseScatter(JosnRPCRequest<Dictionary<string, object>> request)
- {
- JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
- List<Dictionary<string, dynamic>> info = new List<Dictionary<string, dynamic>>();
- if (RedisHelper.Instance != null)
- {
- info = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + request.method,
- ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(request.@params)), timeoutSeconds, () => { return FindExerciseScatterRedis(request.@params, request.method); });
- //数据从redis读取过后进行转换格式
- builder.Data(JsonApiHelper.FromApiJson<System.Text.Json.JsonElement>(info.ToJson()));
- }
- else
- {
- info = await FindExerciseScatterRedis(request.@params, request.method);
- builder.Data(JsonApiHelper.FromApiJson<System.Text.Json.JsonElement>(info.ToJson()));
- }
- return builder.build();
- }
- public async Task<List<Dictionary<string, dynamic>>> FindExerciseScatterRedis(Dictionary<string, object> dict, string method)
- {
- JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
- HashSet<string> classList = new HashSet<string>();
- List<Dictionary<string, object>> exerciseScatter = new List<Dictionary<string, object>>();
- Dictionary<string, object> scatterAnalysis = new Dictionary<string, object>();
- dict.TryGetValue("subjectCode", out object subjectCode);
- dict.TryGetValue("schoolCode", out object schoolCode);
- dict.TryGetValue("examCode", out object examCode);
- dict.TryGetValue("code", out object code);
- Dictionary<string, object> sub = new Dictionary<string, object>
- {
- { "subjectCode", subjectCode.ToString()},
- { "code",code.ToString()}
- };
- Dictionary<string, object> examMap = new Dictionary<string, object>
- {
- { "subjectCode", subjectCode.ToString()},
- { "examCode", examCode.ToString()},
- { "schoolCode", schoolCode.ToString()}
- };
- //List<ExamResult> exams = await azureCosmosDBRepository.FindByDict<ExamResult>(examMap);
- List<ExamResult> exams = new List<ExamResult>();
- if (RedisHelper.Instance != null)
- {
- exams = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + method + "ExamResource",
- ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(examMap)), timeoutSeconds, () => { return FindExamResultRedis(examMap, method + "ExamResource"); });
- }
- else
- {
- exams = await FindExamResultRedis(examMap, method + "ExamResource");
- }
- List<Paper> paper = new List<Paper>();
- if (RedisHelper.Instance != null)
- {
- paper = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + method + "PaperResource",
- ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(sub)), timeoutSeconds, () => { return FindExamPaperRedis(sub, method + "PaperResource"); });
- }
- else
- {
- paper = await FindExamPaperRedis(sub, method + "PaperResource");
- }
- List<string> key = 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"
- };
- //key.Add("areaName");
- if (exams.IsNotEmpty())
- {
- exams.ForEach(e =>
- {
- List<double> gradeAnswer = new List<double>();
- List<string> grasdepersent = new List<string>();
- for (int n = 0; n < e.point.Count; n++)
- {
- gradeAnswer.Add(0);
- }
- //参考人数
- double Qnum = 0;
- e.ids.ForEach(i =>
- {
- if (!i.Equals("0"))
- {
- Qnum++;
- }
- });
- Dictionary<string, object> detail = new Dictionary<string, object>
- {
- { "keys", key }
- };
- List<List<string>> datas = new List<List<string>>();
- List<string[]> itemAnalysis = new List<string[]>();
- Dictionary<string, object> subject = new Dictionary<string, object>
- {
- { "name", e.subjectCode }
- };
- Dictionary<string, object> classPersent = new Dictionary<string, object>();
- List<List<string>> classdatas = new List<List<string>>();
- try
- {
- e.classes.ForEach(c =>
- {
- //初始化每题得分情况
- List<int> answerCount = new List<int>();
- List<string> persent = new List<string>();
- double peopleCount = 0;
- for (int n = 0; n < e.point.Count; n++)
- {
- answerCount.Add(0);
- }
- int qCount = 0;
- //int right = 0;
- //c.Keys遍历key值
- foreach (string keys in c.Keys)
- {
- classList.Add(keys);
- }
- //每个班级得分占比
- foreach (int[] value in c.Values)
- {
- for (int i = value[0]; i <= value[1]; i++)
- {
- if (e.result[i].Sum() > 0)
- {
- for (int j = 0; j < e.result[i].Count; j++)
- {
- if (e.result[i][j] > 0)
- {
- //记录班级每题得分数
- answerCount[j] = answerCount[j] + 1;
- //记录年级每题得分数
- gradeAnswer[j] = gradeAnswer[j] + 1;
- //right++;
- }
- }
- }
- else
- {
- qCount++;
- }
- peopleCount = value[1] - value[0] + 1 - qCount;
- }
- }
- foreach (int p in answerCount)
- {
- var t = Math.Floor(Math.Round(decimal.Parse((p / peopleCount).ToString("0.000")), 2) * 100);
- persent.Add(t.ToString());
- }
- classdatas.Add(persent);
- });
- classPersent.Add("classList", classList);
- classPersent.Add("datas", classdatas);
- exerciseScatter.Add(classPersent);
- double[] point = StringHelper.ListTodouble(e.point);
- double[,] result = StringHelper.ListToDouble(e.result);
- 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 Identify, double R1, double R2, double R3, double R4, double R5, double R6, double RH, double RL)> 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 gradeAnswer)
- {
- var t = Math.Floor(Math.Round(decimal.Parse((p / Qnum).ToString("0.000")), 2) * 100);
- grasdepersent.Add(t.ToString());
- }
- for (int k = 0; k < e.point.Count; k++)
- {
- List<string> values = new List<string>();
- key.ForEach(x =>
- {
- values.Add("-");
- });
- values[0] = (k + 1).ToString();
- values[1] = paper[0].item[k].type;
- values[2] = topic[k].ToString();
- values[3] = e.point[k].ToString();
- values[4] = itemAnalysis[k][0];
- values[5] = itemAnalysis[k][1];
- values[7] = grasdepersent[k];
- values[8] = grasdepersent[k];
- values[12] = itemAnalysis[k][2];
- values[13] = itemAnalysis[k][3];
- values[14] = itemAnalysis[k][4];
- values[15] = itemAnalysis[k][5];
- values[16] = itemAnalysis[k][6];
- values[17] = itemAnalysis[k][7];
- values[18] = itemAnalysis[k][8];
- values[19] = itemAnalysis[k][9];
- values[20] = quality[k].ToString();
- values[21] = answer[k].ToString();
- string pointName = "";
- if (paper[0].item[k].points.Count == 1 ) {
- foreach (string index in paper[0].item[k].points)
- {
- pointName = index ;
- }
- } else if (paper[0].item[k].points.Count > 1) {
- foreach (string index in paper[0].item[k].points)
- {
- pointName += index + ",";
- }
- }
- values[22] = pointName;
- datas.Add(values);
- }
- subject.Add("keys", key);
- subject.Add("datas", datas);
- exerciseScatter.Add(subject);
- }
- catch (Exception ex)
- {
- throw new BizException(ex.Message);
- }
- });
- //Redis处理结果集
- if (RedisHelper.Instance != null)
- {
- if (!RedisHelper.Exists(CacheCosmosPrefix + method))
- {
- await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), exerciseScatter);
- }
- else
- {
- await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), exerciseScatter);
- await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
- }
- }
- return exerciseScatter;
- }
- else return exerciseScatter;
- }
- public async Task<Dictionary<string, dynamic>> FindKnowledgePointRedis(Dictionary<string, object> dict, string method)
- {
- //JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
- dict.TryGetValue("subjectCode", out object subjectCode);
- dict.TryGetValue("schoolCode", out object schoolCode);
- dict.TryGetValue("examCode", out object examCode);
- dict.TryGetValue("code", out object code);
- Dictionary<string, object> sub = new Dictionary<string, object>
- {
- { "subjectCode", subjectCode.ToString()},
- { "code",code.ToString()}
- };
- Dictionary<string, object> examMap = new Dictionary<string, object>
- {
- { "schoolCode", schoolCode.ToString()},
- { "examCode", examCode.ToString()},
- { "subjectCode", subjectCode.ToString()}
- };
- List<ExamResult> exams = new List<ExamResult>();
- if (RedisHelper.Instance != null)
- {
- exams = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + method + "KnowledgeResource",
- ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(examMap)), timeoutSeconds, () => { return FindExamResultRedis(examMap, method + "KnowledgeResource"); });
- }
- else
- {
- exams = await FindExamResultRedis(examMap, method + "KnowledgeResource");
- }
- List<Paper> paper = new List<Paper>();
- if (RedisHelper.Instance != null)
- {
- paper = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + method + "KnowledgePaperResource",
- ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(sub)), timeoutSeconds, () => { return FindExamPaperRedis(sub, method + "KnowledgePaperResource"); });
- }
- else
- {
- paper = await FindExamPaperRedis(sub, method + "KnowledgePaperResource");
- }
- Dictionary<string, object> stuMap = new Dictionary<string, object>
- {
- { "schoolCode", "Habook" }
- };
- List<Student> students = await azureCosmosDBRepository.FindByDict<Student>(stuMap);
- HashSet<string> knowledge = new HashSet<string>();
- HashSet<string> area = new HashSet<string>();
- List<int> point = new List<int>();
- List<List<int>> result = new List<List<int>>();
- List<Dictionary<string, int[]>> classes = new List<Dictionary<string, int[]>>();
- List<string> ids = new List<string>();
- //string Type = "";
- if (dict.TryGetValue("type", out object Type))
- {
- paper.ForEach(p =>
- {
- p.item.ForEach(i =>
- {
- knowledge.Add(i.field);
- area.Add(i.field);
- });
- });
- }
- else {
- paper.ForEach(p =>
- {
- p.item.ForEach(i =>
- {
- i.points.ForEach(o =>
- {
- knowledge.Add(o);
- });
- area.Add(i.field);
- });
- });
- }
- double Qnum = 0;
- //确定高分组 低分组人数
- List<List<int>> re = exams[0].result;
- List<double> resultSum = new List<double>();
- foreach (List<int> data in re)
- {
- resultSum.Add(data.Sum());
- }
- //确定高分组 最低分数
- resultSum.Sort(delegate (double s1, double s2) { return s2.CompareTo(s1); });
- for (int i = resultSum.Count - 1; i >= 0; i--)
- {
- if (resultSum[i] == 0)
- {
- resultSum.Remove(resultSum[i]);
- }
- }
- double rhwCount = resultSum.Count * 0.27;
- double rhw = resultSum[int.Parse(rhwCount.ToString("0"))];
- //确定低分组 最高分数
- resultSum.Sort(delegate (double s1, double s2) { return s1.CompareTo(s2); });
- double rhlCount = resultSum.Count * 0.27;
- double rhl = resultSum[int.Parse(rhwCount.ToString("0"))];
- foreach (ExamResult ex in exams) {
- point = ex.point;
- result = ex.result;
- classes = ex.classes;
- ids = ex.ids;
- }
- /* exams.ForEach(e =>
- {
- point = e.Point;
- result = e.Result;
- classes = e.Classes;
- ids = e.Ids;
- });*/
- 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]);
- }
- }
- List<string> areaName = new List<string>();
- foreach (string cla in area)
- {
- areaName.Add(cla);
- }
- for (int k = 0; k < areaName.Count; k++)
- {
- if (null == areaName[k])
- {
- areaName.Remove(areaName[k]);
- }
- }
- //初始化年级总分
- double total = 0;
- //处理年级单个知识点得分率
- foreach (List<int> grade in result)
- {
- total += grade.Sum();
- }
- foreach (string id in ids)
- {
- if (!id.Equals("0"))
- {
- Qnum++;
- }
- }
- //试卷总分
- double TotalPoint = point.Sum();
- //计算认知层次占比
- List<string> fper = new List<string>();
- for (int a = 0; a < areaName.Count; a++)
- {
- double fieldPoint = 0;
- paper.ForEach(p =>
- {
- int n = 0;
- p.item.ForEach(i =>
- {
- if (i.field != null && i.field.Contains(areaName[a]))
- {
- fieldPoint += point[n];
- }
- n++;
- });
- });
- double fieldPersent = fieldPoint / TotalPoint;
- fper.Add(fieldPersent.ToString("0.00"));
- }
- //求单个知识点所占分数
- List<string> per = new List<string>();
- List<string> gper = new List<string>();
- List<string> knowPer = new List<string>();
- List<Dictionary<string, double>> eper = new List<Dictionary<string, double>>();
- Dictionary<string, object> knowledgeALL = new Dictionary<string, object>();
- Dictionary<string, object> knowledgeMap = new Dictionary<string, object>();
- Dictionary<string, object> classMap = new Dictionary<string, object>();
- Dictionary<string, object> wrongMap = new Dictionary<string, object>();
- HashSet<string> className = new HashSet<string>();
- List<List<string>> wrongPersent = new List<List<string>>();
- List<string> key = new List<string>
- {
- "id",
- "className",
- "seatNO",
- "point",
- "anwPoint",
- "persent"
- };
- List<string> keyWrong = new List<string>
- {
- "name",
- "point",
- "itemNO",
- "persent",
- "wrong",
- "rhw",
- "rlw"
- };
- for (int k = 0; k < knowledgeName.Count; k++)
- {
- List<string> knowledgeClass = new List<string>();
- List<List<string>> stuPersent = new List<List<string>>();
- double OnePoint = 0;
- //获取每个知识点占有多少分值
- double ePoint = 0;
- double anwGPoint = 0;
- double poG = 0;
- int m = 0;
- List<string> valuew = new List<string>();
- List<string> itemNo = new List<string>();
- keyWrong.ForEach(x =>
- {
- valuew.Add("-");
- });
- int wrongCount = 0;
- valuew[0] = knowledgeName[k];
- paper.ForEach(p =>
- {
- int n = 0;
- if (dict.TryGetValue("type", out object Type)) {
- p.item.ForEach(i =>
- {
- if (i.field != null && i.field.Contains(knowledgeName[k]))
- {
- OnePoint += point[n];
- itemNo.Add((n + 1).ToString());
- }
- n++;
- });
- } else {
- p.item.ForEach(i =>
- {
- if (i.points != null && i.points.Contains(knowledgeName[k]))
- {
- OnePoint += 1 / Convert.ToDouble(i.points.Count) * point[n];
- itemNo.Add((n + 1).ToString());
- }
- n++;
- });
- }
- valuew[1] = OnePoint.ToString();
- string itemNos = "";
- foreach (string index in itemNo)
- {
- itemNos += index + ",";
- }
- valuew[2] = itemNos[0..^1];
- });
- int rhwC = 0;
- int rhlC = 0;
- foreach (string id in ids)
- {
- if (id.Equals("0") || result[m].Sum() == 0)
- {
- m++;
- continue;
- }
- List<string> values = new List<string>();
- key.ForEach(x =>
- {
- values.Add("-");
- });
- foreach (Student info in students)
- {
- if (info.studentId.Equals(id))
- {
- values[2] = info.seatNo.ToString();
- break;
- }
- }
- //List<string> stu = new List<string>();
- values[0] = id;
- values[1] = "-";
- //List<List<string>> stuItem = new List<List<string>>();
- int statuCount = 0;
- paper.ForEach(p =>
- {
- int n = 0;
- double anwPoint = 0;
- double po = 0;
- p.item.ForEach(i =>
- {
- if (dict.TryGetValue("type", out object Type))
- {
- if (i.field!= null && i.field.Contains(knowledgeName[k]))
- {
- //Dictionary<string, double> mapkeyItem = new Dictionary<string, double>();
- //OnePoint += 1 / Convert.ToDouble(i.points.Count) * point[n];
- //当前认知层次在该题占比多少
- ePoint = 1;
- anwPoint += result[m][n] * ePoint;
- //所有学生单个认知层次得分情况
- anwGPoint += result[m][n] * ePoint;
- po += point[n] * ePoint;
- //认知层次所占分数
- poG += point[n] * ePoint;
- if (result[m][n] == 0 && statuCount == 0)
- {
- statuCount++;
- wrongCount++;
- if (result[m].Sum() >= rhw)
- {
- rhwC++;
- }
- if (result[m].Sum() <= rhl)
- {
- rhlC++;
- }
- }
- }
- n++;
- }
- else {
- if (i.points != null && i.points.Contains(knowledgeName[k]))
- {
- //Dictionary<string, double> mapkeyItem = new Dictionary<string, double>();
- //OnePoint += 1 / Convert.ToDouble(i.points.Count) * point[n];
- //当前知识点在该题占比多少
- ePoint = 1 / Convert.ToDouble(i.points.Count);
- anwPoint += result[m][n] * ePoint;
- //所有学生单个知识点得分情况
- anwGPoint += result[m][n] * ePoint;
- po += point[n] * ePoint;
- //知识点所占分数
- poG += point[n] * ePoint;
- if (result[m][n] == 0 && statuCount == 0)
- {
- statuCount++;
- wrongCount++;
- if (result[m].Sum() >= rhw)
- {
- rhwC++;
- }
- if (result[m].Sum() <= rhl)
- {
- rhlC++;
- }
- }
- }
- n++;
- }
- });
- double stuPser = anwPoint / po;
- values[3] = po.ToString();
- values[4] = anwPoint.ToString();
- values[5] = stuPser.ToString("0.00");
- //stuItem.Add(values);
- });
- stuPersent.Add(values);
- m++;
- }
- achievementService.ReName(stuPersent, ids, classes, students);
- double knowPser = anwGPoint / poG;
- knowPer.Add(knowPser.ToString("0.00"));
- //错题关系表
- valuew[3] = knowPser.ToString("0.00");
- valuew[4] = wrongCount.ToString();
- valuew[5] = rhwC.ToString();
- valuew[6] = rhlC.ToString();
- wrongPersent.Add(valuew);
- knowledgeMap.Add(knowledgeName[k], stuPersent);
- //知识点占比
- double persent = OnePoint / TotalPoint;
- foreach (Dictionary<string, int[]> map in classes)
- {
- List<string> classPoints = new List<string>();
- //初始化班级得分
- double anwCPoint = 0;
- double cpo = 0;
- foreach (KeyValuePair<string, int[]> kvp in map)
- {
- className.Add(kvp.Key);
- for (int n = kvp.Value[0]; n < kvp.Value[1]; n++)
- {
- if (result[n].Sum() == 0) continue;
- paper.ForEach(p =>
- {
- int x = 0;
- p.item.ForEach(i =>
- {
- if (dict.TryGetValue("type", out object Type))
- {
- if (i.field != null && i.field.Contains(knowledgeName[k]))
- {
- //当前认知层次在该题占比多少
- ePoint = 1;
- anwCPoint += result[n][x] * ePoint;
- cpo += point[x] * ePoint;
- }
- x++;
- }
- else {
- if (i.points != null && i.points.Contains(knowledgeName[k]))
- {
- //当前知识点在该题占比多少
- ePoint = 1 / Convert.ToDouble(i.points.Count);
- anwCPoint += result[n][x] * ePoint;
- cpo += point[x] * ePoint;
- }
- x++;
- }
- });
- });
- }
- }
- double classPser = anwCPoint / cpo;
- knowledgeClass.Add(classPser.ToString("0.00"));
- }
- classMap.Add(knowledgeName[k], knowledgeClass);
- per.Add(persent.ToString("0.00"));
- }
- knowledgeMap.Add("grade", knowPer);
- knowledgeMap.Add("keys", key);
- classMap.Add("className", className);
- wrongMap.Add("keys", keyWrong);
- wrongMap.Add("datas", wrongPersent);
- knowledgeALL.Add("pointList", knowledgeName);
- knowledgeALL.Add("per", per);
- knowledgeALL.Add("level", areaName);
- knowledgeALL.Add("fper", fper);
- knowledgeALL.Add("stupercent", knowledgeMap);
- knowledgeALL.Add("classpercent", classMap);
- knowledgeALL.Add("wrong", wrongMap);
- //builder.Data(knowledgeALL);
- //Redis处理结果集
- if (RedisHelper.Instance != null)
- {
- if (!RedisHelper.Exists(CacheCosmosPrefix + method))
- {
- await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), knowledgeALL);
- }
- else
- {
- await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), knowledgeALL);
- await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
- }
- }
- return knowledgeALL;
- }
- [HttpPost("knowledgePoint")]
- public async Task<BaseJosnRPCResponse> KnowledgePoint(JosnRPCRequest<Dictionary<string, object>> request)
- {
- JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
- Dictionary<string, dynamic> info = new Dictionary<string, dynamic>();
- if (RedisHelper.Instance != null)
- {
- info = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + request.method,
- ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(request.@params)), timeoutSeconds, () => { return FindKnowledgePointRedis(request.@params, request.method); });
- //数据从redis读取过后进行转换格式
- builder.Data(JsonApiHelper.FromApiJson<System.Text.Json.JsonElement>(info.ToJson()));
- }
- else
- {
- info = await FindKnowledgePointRedis(request.@params, request.method);
- builder.Data(JsonApiHelper.FromApiJson<System.Text.Json.JsonElement>(info.ToJson()));
- }
- return builder.build();
- }
- [HttpPost("FindExamInfo")]
- public async Task<BaseJosnRPCResponse> FindExamInfo(JosnRPCRequest<Dictionary<string, object>> request)
- {
- JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
- if (RedisHelper.Instance != null)
- {
- try {
- ///RedisHelper.Instance.CurrentSerialize = obj => System.Text.Json.JsonSerializer.Serialize(obj);
- /// RedisHelper.Instance.CurrentDeserialize = (json, type) => System.Text.Json.JsonSerializer.Deserialize(json, type);
- List<ExamInfo> info = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + request.method,
- ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(request.@params)), timeoutSeconds, () => { return FindExamInfoRedis(request.@params, request.method); });
-
- builder.Data(info);
- } catch (Exception e) {
- throw new BizException(e.Message);
- }
- }
- else
- {
- List<ExamInfo> info = await FindExamInfoRedis(request.@params,request.method);
- builder.Data(info);
- }
- return builder.build();
- }
- public async Task<List<ExamInfo>> FindExamInfoRedis(Dictionary<string, object> dict,string method)
- {
- try {
- List<ExamInfo> info = await azureCosmosDBRepository.FindByDict<ExamInfo>(dict);
- if (RedisHelper.Instance != null)
- {
- if (!RedisHelper.Exists(CacheCosmosPrefix + method))
- {
- await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), info);
- }
- else
- {
- await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), info);
- await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
- }
- }
- return info;
- } catch (Exception e) {
- throw new BizException(e.Message);
- }
- }
- [HttpPost("FindExamPaper")]
- public async Task<BaseJosnRPCResponse> FindExamPaper(JosnRPCRequest<Dictionary<string, object>> request)
- {
- JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
- if (RedisHelper.Instance != null)
- {
- List<Paper> info = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + request.method,
- ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(request.@params)), timeoutSeconds, () => { return FindExamPaperRedis(request.@params, request.method); });
- builder.Data(info);
- }
- else
- {
- List<Paper> info = await FindExamPaperRedis(request.@params, request.method);
- builder.Data(info);
- }
- return builder.build();
- }
- public async Task<List<Paper>> FindExamPaperRedis(Dictionary<string, object> dict, string method)
- {
- try
- {
- List<Paper> info = await azureCosmosDBRepository.FindByDict<Paper>(dict);
- if (RedisHelper.Instance != null)
- {
- if (!RedisHelper.Exists(CacheCosmosPrefix + method))
- {
- await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), info);
- }
- else
- {
- await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), info);
- await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
- }
- }
- return info;
- }
- catch (Exception e)
- {
- throw new BizException(e.Message);
- }
- }
- [HttpPost("FindExamAnswer")]
- public async Task<BaseJosnRPCResponse> FindExamAnswer(JosnRPCRequest<Dictionary<string, object>> request)
- {
- JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
- if (RedisHelper.Instance != null)
- {
- List<ExamAnswer> info = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + request.method,
- ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(request.@params)), timeoutSeconds, () => { return FindExamAnswerRedis(request.@params, request.method); });
- builder.Data(info);
- }
- else
- {
- List<ExamAnswer> info = await FindExamAnswerRedis(request.@params, request.method);
- builder.Data(info);
- }
- return builder.build();
- }
- public async Task<List<ExamAnswer>> FindExamAnswerRedis(Dictionary<string, object> dict, string method)
- {
- try
- {
- List<ExamAnswer> info = await azureCosmosDBRepository.FindByDict<ExamAnswer>(dict);
- if (RedisHelper.Instance != null)
- {
- if (!RedisHelper.Exists(CacheCosmosPrefix + method))
- {
- await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), info);
- }
- else
- {
- await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), info);
- await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
- }
- }
- return info;
- }
- catch (Exception e)
- {
- throw new BizException(e.Message);
- }
- }
- public async Task<List<ExamAnswer>> FindExamAnswerRedis(Dictionary<string, object> dict)
- {
- try
- {
- List<ExamAnswer> info = await azureCosmosDBRepository.FindByDict<ExamAnswer>(dict);
- if (RedisHelper.Instance != null)
- {
- if (!RedisHelper.Exists(CacheCosmosPrefix + "FindExamAnswer"))
- {
- await RedisHelper.HSetAsync(CacheCosmosPrefix + "FindExamAnswer", ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), info);
- }
- else
- {
- await RedisHelper.HSetAsync(CacheCosmosPrefix + "FindExamAnswer", ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), info);
- await RedisHelper.ExpireAsync(CacheCosmosPrefix + "FindExamAnswer", timeoutSeconds);
- }
- }
- return info;
- }
- catch (Exception e)
- {
- throw new BizException(e.Message);
- }
- }
- [HttpPost("HomeStatistics")]
- public async Task<BaseJosnRPCResponse> HomeStatistics(JosnRPCRequest<Dictionary<string, object>> request)
- {
- JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
- //request.@params.TryGetValue("subjectCode", out object subjectCode);
- request.@params.TryGetValue("schoolCode", out object schoolCode);
- request.@params.TryGetValue("code", out object code);
- Dictionary<string, object> eMap = new Dictionary<string, object>
- {
- { "code", code.ToString()}
- };
- Dictionary<string, object> SCMap = new Dictionary<string, object>
- {
- { "schoolCode", schoolCode.ToString()},
- };
- //说明 同学校、同类型考试数据
- List<ExamInfo> exams = await azureCosmosDBRepository.FindByDict<ExamInfo>(eMap);
- //查询学校对应的年级信息
- List<School> schools = await azureCosmosDBRepository.FindByDict<School>(SCMap);
- HashSet<string> classList = new HashSet<string>();
- HashSet<string> subjectList = new HashSet<string>();
- List<List<List<string>>> AllPoint = new List<List<List<string>>>();
- List<List<List<string>>> AllPointAverage = new List<List<List<string>>>();
- List<List<List<string>>> AllKeyLine = new List<List<List<string>>>();
- string Period = "";
- string Grade = "";
- List<double> CoreAverage = new List<double>();
- double weightSum = 0;
- try {
- List<Period> periods = new List<Period>();
- List<Grade> grades = new List<Grade>();
- foreach (School s in schools) {
- periods = s.period;
- }
- periods.ForEach(p =>
- {
- if (p.periodName.Equals("初中")) {
- grades = p.grades;
- } else if (p.periodName.Equals("高中")) {
- grades = p.grades;
- } else {
- grades = p.grades;
- }
- });
- //循环处理不同年级考试信息
- /*foreach (Grade g in grades) {
-
- }*/
- foreach (ExamInfo e in exams)
- {
- Dictionary<string, object> sub = new Dictionary<string, object>
- {
- { "examCode", e.id}
- };
- Period = e.conditions.period;
- Grade = e.conditions.grade;
- List<string> subjects = new List<string>();
- List<List<string>> SubjectClassAverage = new List<List<string>>();
- List<List<string>> SubjectAverage = new List<List<string>>();
- //List<List<string>> SubjectClassAverage = new List<List<string>>();
- List<ExamResult> simples = await azureCosmosDBRepository.FindByDict<ExamResult>(sub);
- // 学生总分
- double coreSum = 0;
- int stuCount = e.stuCount;
- //初始化进行人数
- double iPersons = 0;
- //获取进线人数
- iPersons = stuCount * 0.4;
- //
- List<List<int>> subSum = new List<List<int>>();
- if (simples.IsEmpty()) continue;
- double weight = 0.5;
- weightSum += weight;
- int classLen = simples[0].classes.Count;
- for (int cls = 0; cls < classLen; cls++)
- {
- if (simples[0].classes[cls].TryGetValue(simples[0].classes[cls].Keys.ToArray<string>()[0], out int[] indexs))
- {
- List<int> stuScore = new List<int>();
- int stdLen = indexs[1] - indexs[0] + 1;
- for (int i = 0; i < stdLen; i++)
- {
- stuScore.Add(0);
- }
- subSum.Add(stuScore);
- }
- }
- simples.ForEach(s =>
- {
- Dictionary<string, object> detail = new Dictionary<string, object>
- {
- { "name", s.subjectCode }
- };
- subjects.Add(s.subjectCode);
- subjectList.Add(s.subjectCode);
- //计算试卷总分
- int sum = s.point.Sum();
- //int stuSum = 0;
- int classIndex = 0;
- List<string> ClassAverage = new List<string>();
- List<string> Average = new List<string>();
- List<string> passList = new List<string>();
- s.classes.ForEach(c =>
- {
- List<List<string>> classPRL = new List<List<string>>();
- //初始化班级总分
- int classPoint = 0;
- //初始化班级缺考人数
- int classCount = 0;
- //初始化班级平均得分率
- double points = 0;
- //初始化班级平均得分率
- double AveragePoints = 0;
- //初始化各班参考人数
- int counts = 0;
- //c.Keys遍历key值
- foreach (string key in c.Keys)
- {
- classList.Add(key);
- }
- //每个班级平均分
- foreach (int[] value in c.Values)
- {
- for (int i = value[0]; i <= value[1]; i++)
- {
- //初始化学生单科个人得分
- int stuPoints = s.result[i].Sum();
- subSum[classIndex][i - value[0]] = stuPoints + subSum[classIndex][i - value[0]];
- classPoint += s.result[i].Sum();
- coreSum += s.result[i].Sum();
- if (s.result[i].Sum() == 0)
- {
- classCount++;
- }
- }
- //每个班级实际参考人数
- counts = value[1] - value[0] - classCount + 1;
- //stuSum += counts;
- points = Convert.ToDouble(classPoint) / counts / sum;
- //计算每个班级平均得分
- AveragePoints = Convert.ToDouble(classPoint) / counts;
- ClassAverage.Add(points.ToString("0.000"));
- Average.Add(AveragePoints.ToString());
- }
- classIndex += 1;
- });
- SubjectClassAverage.Add(ClassAverage);
- SubjectAverage.Add(Average);
- //subAverage = subjectPoint / ClassAverage.Count();
- //subjectAverage.Add(subAverage.ToString("0.00"));
- });
- double core = coreSum / stuCount * weight;
- CoreAverage.Add(core);
- AllPoint.Add(SubjectClassAverage);
- AllPointAverage.Add(SubjectAverage);
- //处理人数为整
- string ip = iPersons.ToString("0");
- //初始化进线分数
- int ipoint = 0;
- List<int> AllPoints = new List<int>();
- foreach (List<int> points in subSum)
- {
- foreach (int po in points)
- {
- AllPoints.Add(po);
- }
- }
- for (int i = 0; i < subSum.Count; i++)
- {
- for (int j = 0; j < subSum[i].Count; j++)
- {
- if (subSum[i][j].Equals("0"))
- {
- subSum[i].Remove(subSum[i][j]);
- }
- }
- }
- //计算成绩年级排名
- AllPoints.Sort(delegate (int s1, int s2) { return s2.CompareTo(s1); });
- ipoint = AllPoints[int.Parse(ip)];
- int m = 0;
- List<List<string>> KeyLine = new List<List<string>>();
- foreach (List<int> points in subSum)
- {
- List<string> detail = new List<string>();
- double sum = points.Count;
- int j = 0;
- for (int i = 0; i < points.Count; i++)
- {
- if (points[i] > ipoint)
- {
- j++;
- }
- }
- double Lines = j;
- detail.Add(Lines.ToString());
- detail.Add(points.Count.ToString());
- var t3 = Math.Floor(Math.Round(decimal.Parse((Lines / sum).ToString("0.000")), 2) * 100);
- detail.Add(t3.ToString());
- KeyLine.Add(detail);
- m++;
- }
- AllKeyLine.Add(KeyLine);
- }
- //年级成就指标
- if (weightSum == 0) {
- weightSum = 1;
- }
- double index = CoreAverage.Sum() / weightSum;
- List<List<double>> AveragePoint = new List<List<double>>();
- List<List<double>> AverageClassPoint = new List<List<double>>();
- //List<double> ClassCore = new List<double>();
- int k = AllPoint.Count;
- if (k > 0)
- {
- for (int m = 0; m < AllPoint[0].Count; m++)
- {
- List<double> SubjectAverage = new List<double>();
- for (int n = 0; n < AllPoint[0][m].Count; n++)
- {
- double startPoint = 0;
- for (int f = 0; f < k; f++)
- {
- startPoint = double.Parse(AllPoint[f][m][n]) + startPoint;
- }
- SubjectAverage.Add(startPoint / k);
- }
- AveragePoint.Add(SubjectAverage);
- }
- }
- //每个班级成就指标
- int p = AllPointAverage.Count;
- if (p > 0)
- {
- for (int m = 0; m < AllPointAverage[0].Count; m++)
- {
- List<double> SubjectAverage = new List<double>();
- for (int n = 0; n < AllPointAverage[0][m].Count; n++)
- {
- double startPoint = 0;
- for (int f = 0; f < k; f++)
- {
- startPoint = double.Parse(AllPointAverage[f][m][n]) + startPoint;
- }
- SubjectAverage.Add(startPoint / k);
- }
- AverageClassPoint.Add(SubjectAverage);
- }
- }
- int c = AverageClassPoint.Count;
- List<double> ClassCore = new List<double>();
- if (c > 0)
- {
- for (int j = 0; j < AverageClassPoint[0].Count; j++)
- {
- double startAverage = 0;
- for (int f = 0; f < c; f++)
- {
- startAverage = AverageClassPoint[f][j] + startAverage;
- }
- ClassCore.Add(startAverage / weightSum);
- }
- }
- //班级平均进线率
- int ExamCount = AllKeyLine.Count;
- List<List<double>> KeyLines = new List<List<double>>();
- if (ExamCount > 0)
- {
- for (int m = 0; m < AllKeyLine[0].Count; m++)
- {
- List<double> ClassLine = new List<double>();
- for (int n = 0; n < AllKeyLine[0][m].Count; n++)
- {
- double startPoint = 0;
- for (int f = 0; f < ExamCount; f++)
- {
- startPoint = double.Parse(AllKeyLine[f][m][n]) + startPoint;
- }
- ClassLine.Add(startPoint / ExamCount);
- }
- KeyLines.Add(ClassLine);
- }
- }
- Dictionary<string, object> AveragePointMap = new Dictionary<string, object>
- {
- { "Period",Period},
- { "Grade",Grade},
- { "index", index},
- { "className", classList },
- { "subjectName", subjectList },
- { "AveragePoint", AveragePoint },
- //{ "AverageClassPoint", AverageClassPoint },
- { "ClassCore", ClassCore },
- { "KeyLines",KeyLines}
- };
- builder.Data(AveragePointMap);
- return builder.build();
- } catch (Exception e) {
- Console.WriteLine("---------------------" + e.Message + "--------------------------");
- }
- builder.Data("");
- return builder.build();
- }
- }
- }
|