using TEAMModelOS.SDK.Extension; using TEAMModelOS.SDK.Models; using System.Xml; using HTEX.Lib.ETL.Lesson; using Microsoft.AspNetCore.Mvc; using System.Text.Json; namespace HTEX.Test.Controllers { [ApiController] [Route("lesson-record")] public class MockDataController : ControllerBase { public MockDataController() { } [HttpPost("process-local")] public async Task MockData(JsonElement json) { #region 数据模拟 //学生人数 int scount = Random.Shared.Next(40, 45); //互动次数 int icount = Random.Shared.Next(21,22); //评测次数 int ecount = Random.Shared.Next(1, 3); //题目个数 int qcount = Random.Shared.Next(8, 15); //任务次数 int tcount = Random.Shared.Next(2, 3); //评价次数 int pcount = Random.Shared.Next(3, 4); //协作次数 int xcount = Random.Shared.Next(2, 3); //挑人次数 int kcount = Random.Shared.Next(2, 4); string type = "hd"; int count = 0; switch (true) { case bool when type.Equals("hd"): count=icount; break; case bool when type.Equals("pc"): count=ecount; break; case bool when type.Equals("rw"): count=tcount; break; case bool when type.Equals("pj"): count=pcount; break; case bool when type.Equals("xz"): count=xcount; break; } List s = new List(); for (var i = 1; i < count; i++) { var dd = await StudentLesson(scount,ecount,qcount,i,tcount,pcount,xcount,kcount); s.Add(dd.ToString()); }return Ok(s); } /// /// /// /// /// /// /// /// /// /// /// /// public async Task StudentLesson(int scount, int ecount, int qcount, int icount, int tcount, int pcount, int xcount, int kcount) { List students = new List(); //个人计分,小组计分 List gpitems = new List { new WeightedItem { Value = 0, Weight = 0.1 }, new WeightedItem { Value = 2, Weight = 0.2 }, new WeightedItem { Value = 5, Weight = 0.2 }, new WeightedItem { Value = 8, Weight = 0.02 }, new WeightedItem { Value = 3, Weight = 0.2 }, new WeightedItem { Value = 4, Weight = 0.2 }, new WeightedItem { Value = 6, Weight = 0.04 }, new WeightedItem { Value = 7, Weight = 0.04 } }; //互动积分 List titems = new List { new WeightedItem { Value = 0, Weight = 0.4 }, new WeightedItem { Value = 25, Weight = 0.1 }, new WeightedItem { Value = 15, Weight = 0.1 }, new WeightedItem { Value = 10, Weight = 0.05 }, new WeightedItem { Value = 30, Weight = 0.05 }, new WeightedItem { Value = 20, Weight = 0.02 }, new WeightedItem { Value = 40, Weight = 0.03 }, new WeightedItem { Value = 50, Weight = 0.05 }, new WeightedItem { Value = 5, Weight = 0.05 }, new WeightedItem { Value = 35, Weight = 0.05 }, new WeightedItem { Value = 45, Weight = 0.05 }, new WeightedItem { Value = 55, Weight = 0.05 } }; //for (var i = 0; i<100; i++) //{ // int randomValue = GetRandomValueByWeight(items); // Console.WriteLine(randomValue); //} //被评价的目标索引 List> cworkDist = new List>(xcount); //被评价目标的次数或分数 // List> cworkCount = new List>(xcount); for (int i = 0; i < xcount; i++) { //乱序取10-20人作为评价目标 var vt = Enumerable.Range(0, scount).OrderBy(x => Random.Shared.Next()).Take(Random.Shared.Next(10, 21)); cworkDist.Add(vt.ToList()); //var counts = new List(); //foreach (var v in vt) //{ // counts.Add(0); //} //cworkCount.Add(counts); } //被评价的目标索引 List> rateDist = new List>(pcount); //被评价目标的次数或分数 //List> rateCount = new List>(pcount); List types = new List(); for (int i = 0; i < pcount; i++) { //乱序取10-20人作为评价目标 var vt = Enumerable.Range(0, scount).OrderBy(x => Random.Shared.Next()).Take(Random.Shared.Next(10, 21)); rateDist.Add(vt.ToList()); // var counts = new List(); //foreach (var v in vt) //{ // counts.Add(0); //} //rateCount.Add(counts); var t = Random.Shared.Next(0, 1); switch (true) { case bool when i==0: types.Add("Voting"); break; case bool when i==1: types.Add("GrandRating"); break; case bool when i==2: types.Add("PeerAssessment"); break; } } string[] grouppick = new string[] { "PickupNthGrp", "PickupGrp", "PickupEachGrp" }; string[] pickupAll = new string[] { "PickupNameLst", "PickupOption", "PickupNthGrp", "PickupGrp", "PickupRange", "PickupEachGrp", "PickupDiff", "PickupWrong", "PickupNoDiff", "PickupRight", "PickupGener", "PickupWtoW", "PickupWtoR", "PickupLSA_WordFreq", "PickupLSA_Classify", "Pickup0_49" }; for (var s = 0; s x.resultWeight>0).Count()*1.0/tcount; student.taskRecord.itemRecords.Add(item); } //评价 for (var p = 0; p x.resultWeight>0).Count(); examRecord.allocation=allocation; examRecord.score= examRecord.itemRecords.Where(x => x.itemScore>=0).Select(x => x.itemScore).Sum();//得分 examRecord.scoreRate = Math.Round(examRecord.score * 1.0 / allocation, 4);//得分率 examRecord.answerRate= Math.Round(examRecord.itemRecords.Where(x => x.resultWeight>0).Count()*1.0/qcount, 4);//作答率 student.examRecords.Add(examRecord); } } for (var p = 0; p x.rateingRecord.itemRecords[p].itemScore); var maxItems = students.FindAll(x => x.rateingRecord.itemRecords[p].itemScore==order.First().rateingRecord.itemRecords[p].itemScore); var max = students.FindAll(x => x.rateingRecord.itemRecords[p].itemScore==order.First().rateingRecord.itemRecords[p].itemScore).First().rateingRecord.itemRecords[p].itemScore; var min = students.FindAll(x => x.rateingRecord.itemRecords[p].itemScore==order.Last().rateingRecord.itemRecords[p].itemScore).First().rateingRecord.itemRecords[p].itemScore; var sum = students.Sum(x => x.rateingRecord.itemRecords[p].itemScore); foreach (var student in students) { if (student.rateingRecord.itemRecords[p].itemScore>0 && student.rateingRecord.itemRecords[p].optCount>0) { student.rateingRecord.itemRecords[p].resultType=InteractReultType.TP; var data = LessonETLService.MinMaxNormalization(min, max, student.rateingRecord.itemRecords[p].itemScore); student.rateingRecord.itemRecords[p].resultWeight=Math.Round(InteractWeight.T1+ data * 1.0 / 100 * (InteractWeight.TT-InteractWeight.T1), 4); if (maxItems.Select(x => x.seatID).Contains(student.seatID)) { student.rateingRecord.itemRecords[p].resultType= InteractReultType.TT; student.rateingRecord.itemRecords[p].resultWeight= InteractWeight.TT; } } } } //个人协作 for (var p = 0; p x.coworkRecord.itemRecords[p].itemScore); var maxItems = students.FindAll(x => x.coworkRecord.itemRecords[p].itemScore==order.First().coworkRecord.itemRecords[p].itemScore); var max = students.FindAll(x => x.coworkRecord.itemRecords[p].itemScore==order.First().coworkRecord.itemRecords[p].itemScore).First().coworkRecord.itemRecords[p].itemScore; var min = students.FindAll(x => x.coworkRecord.itemRecords[p].itemScore==order.Last().coworkRecord.itemRecords[p].itemScore).First().coworkRecord.itemRecords[p].itemScore; var sum = students.Sum(x => x.coworkRecord.itemRecords[p].itemScore); foreach (var student in students) { if (student.coworkRecord.itemRecords[p].itemScore>0) { student.coworkRecord.itemRecords[p].resultType=InteractReultType.TP; var data = LessonETLService.MinMaxNormalization(min, max, student.coworkRecord.itemRecords[p].itemScore); student.coworkRecord.itemRecords[p].resultWeight=Math.Round(InteractWeight.T1+ data * 1.0 / 100 * (InteractWeight.TT-InteractWeight.T1), 4); if (maxItems.Select(x => x.seatID).Contains(student.seatID)) { student.coworkRecord.itemRecords[p].resultType= InteractReultType.TT; student.coworkRecord.itemRecords[p].resultWeight= InteractWeight.TT; } } } } #endregion 数据模拟 string jsons = await System.IO.File.ReadAllTextAsync("F:\\lesson-local\\analysis\\analysis-model.json"); long time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); LessonDataAnalysisModel lessonDataAnalysis = jsons.ToObject(); var codeBools = LessonETLService.GetCodeBools(students); var studentLessons = LessonETLService.ProcessStudentDataV2(students, lessonDataAnalysis, codeBools); var excleFile = $"F:\\mock-data\\{time}.xlsx"; var runtimePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load($"{runtimePath}\\summary.xml"); List noStujson = new List(); await LessonETLService.ExportToExcelLocal(studentLessons, excleFile, xmlDocument); await System.IO.File.WriteAllTextAsync($"F:\\mock-data\\{time}.json", new { scount, ecount, qcount, icount, tcount, pcount, xcount, students }.ToJsonString()); return $"{time}"; } //return Ok(new { scount, ecount, qcount, icount, tcount, pcount, xcount, students }); } }