123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026 |
- using Azure.Storage.Blobs.Models;
- using Microsoft.AspNetCore.Mvc;
- using System.Text.Json;
- using TEAMModelOS.SDK;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK.Models;
- using TEAMModelOS.SDK.Extension;
- using StackExchange.Redis;
- using System.Text.RegularExpressions;
- using System.Linq;
- using static TEAMModelOS.SDK.Models.Cosmos.Student.StudentAnalysis;
- namespace HTEX.Test.Controllers
- {
- [ApiController]
- [Route("lesson-record")]
- public class LessonRecordController : ControllerBase
- {
- private readonly ILogger<LessonRecordController> _logger;
- private readonly AzureCosmosFactory _azureCosmos;
- private readonly AzureStorageFactory _azureStorage;
- private readonly List<string> objectiveTypes=new List<string>(){ "single", "multiple", "sortmultiple" , "judge" };
- public LessonRecordController(ILogger<LessonRecordController> logger, AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage)
- {
- _logger = logger;
- _azureCosmos = azureCosmos;
- _azureStorage = azureStorage;
- }
- [HttpPost("read")]
- public async Task<IActionResult> Read(JsonElement json)
- {
- string m = await System.IO.File.ReadAllTextAsync("C:\\Users\\CrazyIter\\Downloads\\m.json");
- string p = await System.IO.File.ReadAllTextAsync("C:\\Users\\CrazyIter\\Downloads\\p.json");
- List<ItemInfo> mlist=m.ToObject<List<ItemInfo>>();
- List<ItemInfo> plist=p.ToObject<List<ItemInfo>>();
- var km = mlist.Where(x=> x.knowledge.IsNotEmpty()).SelectMany(x => x.knowledge).Distinct();
- var kp = plist.Where(x=> x.knowledge.IsNotEmpty()).SelectMany(x => x.knowledge).Distinct();
- List<CodeLong> cp = new List<CodeLong>();
- foreach (var item in kp)
- {
- var count = plist.Where(x => x.knowledge.Contains(item)).Count();
- cp.Add(new CodeLong() { code = item, value = count });
- }
- List<CodeLong> cm = new List<CodeLong>();
- foreach (var item in km)
- {
- var count = mlist.Where(x => x.knowledge.Contains(item)).Count();
- cm.Add(new CodeLong() { code = item, value = count });
- }
- return Ok(new { cm,cp });
- }
- [HttpPost("process-history")]
- public async Task<IActionResult> ProcessHistory(JsonElement json)
- {
- //1709222400000 2024.3.1
- var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School)
- .GetList<LessonRecord>($"SELECT value c FROM School AS c where c.startTime>1709222400000 and c.expire<=0 and c.status<>404",
- $"LessonRecord-{json.GetProperty("schoolId")}", pageSize: 20);
- if (result.list.IsNotEmpty())
- {
- foreach (var item in result.list)
- {
- //读取TimeLine.json
- TimeLineData? timeLineData = null;
- try
- {
- BlobDownloadResult timeLineBlobDownload = await _azureStorage.GetBlobContainerClient(item.school).GetBlobClient($"/records/{item.id}/IES/TimeLine.json").DownloadContentAsync();
- timeLineData = timeLineBlobDownload.Content.ToObjectFromJson<TimeLineData>();
- }
- catch (Exception ex)
- {
- if (!ex.Message.Contains("The specified blob does not exist"))
- {
- _logger.LogError(ex, $"文件不存在:/records/{item.id}/IES/TimeLine.json");
- }
- }
- //读取基础Base信息
- //base.json
- LessonBase? lessonBase = null;
- List<StudentLessonData> studentLessonDatas = new List<StudentLessonData>();
- //名单出席率低于30%的 不纳入计算。
- try
- {
- BlobDownloadResult baseblobDownload = await _azureStorage.GetBlobContainerClient(item.school).GetBlobClient($"/records/{item.id}/IES/base.json").DownloadContentAsync();
- string basejson = baseblobDownload.Content.ToString().Replace("\"Uncall\"", "0").Replace("Uncall", "0");
- lessonBase = basejson.ToObject<LessonBase>();
- var data = GetBaseData(item, lessonBase);
- studentLessonDatas=data.studentLessonDatas;
- }
- catch (Exception ex)
- {
- if (!ex.Message.Contains("The specified blob does not exist"))
- {
- _logger.LogError(ex, $"文件不存在:/records/{item.id}/IES/base.json");
- }
- }
- //读取Task.json
- ///Event 过滤类型 : 'WrkSpaceLoad'作品收集, 'WrkCmp' 作品贴上 文件:Task.json 根据clientWorks 中的seatID 匹配base.json 中的 student
- List<TaskData> taskDatas = new List<TaskData>();
- try
- {
- BlobDownloadResult taskBlobDownload = await _azureStorage.GetBlobContainerClient(item.school).GetBlobClient($"/records/{item.id}/IES/Task.json").DownloadContentAsync();
- taskDatas = taskBlobDownload.Content.ToObjectFromJson<List<TaskData>>();
- }
- catch (Exception ex)
- {
- if (!ex.Message.Contains("The specified blob does not exist"))
- {
- _logger.LogError(ex, $"文件不存在:/records/{item.id}/IES/Task.json");
- }
- }
-
- //读取互评信息
- //Event 过滤类型 'RatingStart'
- //smartRateSummary.mutualSummary.mutualType 互评【All(每人多件评分) Two(随机分配互评) Self(自评)】 smartRateSummary.meteor_VoteSummary 投票
- //读取SmartRating.json
- List<SmartRatingData> smartRatingDatas = new List<SmartRatingData>();
- try
- {
- BlobDownloadResult smartRatingBlobDownload = await _azureStorage.GetBlobContainerClient(item.school).GetBlobClient($"/records/{item.id}/IES/SmartRating.json").DownloadContentAsync();
- smartRatingDatas = smartRatingBlobDownload.Content.ToObjectFromJson<List<SmartRatingData>>();
- }
- catch (Exception ex)
- {
- if (!ex.Message.Contains("The specified blob does not exist"))
- {
- _logger.LogError(ex, $"文件不存在:/records/{item.id}/IES/SmartRating.json");
- }
- }
- //读取互动信息
- //Event 过滤类型 'PopQuesLoad', 'ReAtmpAnsStrt', 'BuzrAns','BuzrLoad'
- //TimeLine.json 中找到对应类型,根据Pgid 去 IRS.json 中找到对应数据,从clientAnswers 的下标对应 base.json 中的 student 找到对应学生信息 clientAnswers.length > 1 则表示有二次作答
- //读取IRS.json
- List<IRSData> irsDatas = new List<IRSData>();
- try
- {
- BlobDownloadResult irsBlobDownload = await _azureStorage.GetBlobContainerClient(item.school).GetBlobClient($"/records/{item.id}/IES/IRS.json").DownloadContentAsync();
- irsDatas = irsBlobDownload.Content.ToObjectFromJson<List<IRSData>>();
- }
- catch (Exception ex)
- {
- if (!ex.Message.Contains("The specified blob does not exist"))
- {
- _logger.LogError(ex, $"文件不存在:/records/{item.id}/IES/IRS.json");
- }
- }
- //读取协作信息
- ///Event 过滤类型 'CoworkLoad', "CoworkType":"CoworkGroup",类型
- //Cowork.json 中找到对应类型,根据Pgid 去 Cowork.json 中找到对应数据
- List<CoworkData> coworkDatas = new List<CoworkData>();
- try
- {
- BlobDownloadResult irsBlobDownload = await _azureStorage.GetBlobContainerClient(item.school).GetBlobClient($"/records/{item.id}/IES/Cowork.json").DownloadContentAsync();
- coworkDatas = irsBlobDownload.Content.ToObjectFromJson<List<CoworkData>>();
- }
- catch (Exception ex)
- {
- if (!ex.Message.Contains("The specified blob does not exist"))
- {
- _logger.LogError(ex, $"文件不存在:/records/{item.id}/IES/Cowork.json");
- }
- }
- //读取ExamData
- List<ExamData> examDatas = new List<ExamData>();
- try {
- var examPages = timeLineData?.events.Where(x => string.IsNullOrWhiteSpace(x.ExamId));
- if (examDatas!=null && examDatas.Count>0)
- {
- var examsFiles = await _azureStorage.GetBlobContainerClient(item.school).List($"/records/{item.id}/Exam/");
- var paperFiles = await _azureStorage.GetBlobContainerClient(item.school).List($"/records/{item.id}/ExamPaper/");
- foreach (var examsFile in examsFiles)
- {
- if (examsFile.EndsWith("Exam.json"))
- {
- ExamData? examData = null;
- try {
- BlobDownloadResult examDataDownload = await _azureStorage.GetBlobContainerClient(item.school).GetBlobClient(examsFile).DownloadContentAsync();
- examData = examDataDownload.Content.ToObjectFromJson<ExamData>();
- } catch (Exception ex)
- {
- if (!ex.Message.Contains("The specified blob does not exist"))
- {
- _logger.LogError(ex, $"文件不存在:{examsFile}");
- }
- }
-
- if (examData!=null && examData.exam.papers.IsNotEmpty())
- {
- string paperId= examData.exam.papers.First().id;
-
- if (_azureStorage.GetBlobContainerClient(item.school).GetBlobClient($"/records/{item.id}/ExamPaper/{paperId}/index.json").Exists())
- {
- LessonPaper lessonPaper = null;
- try {
- BlobDownloadResult paperblobDownload = await _azureStorage.GetBlobContainerClient(item.school).GetBlobClient($"/records/{item.id}/ExamPaper/{paperId}/index.json").DownloadContentAsync();
- lessonPaper = paperblobDownload.Content.ToObjectFromJson<LessonPaper>();
- examData.paper = lessonPaper;
- } catch (Exception ex) {
- if (!ex.Message.Contains("The specified blob does not exist"))
- {
- _logger.LogError(ex, $"文件不存在:/records/{item.id}/ExamPaper/{paperId}/index.json");
- }
- }
- }
- examDatas.Add(examData);
- }
- }
- }
- }
- }
- catch (Exception ex)
- {
- _logger.LogError(ex,ex.Message);
- }
- }
- }
- return Ok("Lesson records");
- }
- /// <summary>
- /// 处理base.json的数据
- /// </summary>
- /// <param name="lessonRecord"></param>
- /// <param name="lessonBase"></param>
- /// <returns></returns>
- private (LessonBase lessonBase, List<StudentLessonData> studentLessonDatas) GetBaseData(LessonRecord lessonRecord, LessonBase lessonBase)
- {
- //处理学生定位数据
- List<StudentLessonData> studentLessonDatas = new List<StudentLessonData>();
- int index = 0;
- lessonBase.student.ForEach(x =>
- {
- studentLessonDatas.Add(new StudentLessonData()
- {
- id = x.id,
- index = index,
- seatID =$"{x.seatID}",
- groupId = x.groupId,
- });
- index++;
- });
- return (lessonBase, studentLessonDatas);
- }
- /// <summary>
- ///读取互动信息
- ///Event 过滤类型 'PopQuesLoad', 'ReAtmpAnsStrt', 'BuzrAns','BuzrLoad'
- /// 在IRS.json处理 'PopQuesLoad'互动问答 , 'ReAtmpAnsStrt' 二次作答 , 'BuzrAns' 抢权(新), 'BuzrLoad'抢权(旧), PickupResult 挑人算不算互动?? 读取PickupMemberId "[\r\n 35\r\n]"
- ///TimeLine.json 中找到对应类型,根据Pgid 去 IRS.json 中找到对应数据,从clientAnswers 的下标对应 base.json 中的 student 找到对应学生信息 clientAnswers.length > 1 则表示有二次作答
- ///读取IRS.json
- /// </summary>
- /// <param name="lessonRecord"></param>
- /// <param name="lessonBase"></param>
- /// <param name="irsDatas"></param>
- /// <returns></returns>
- private List<StudentLessonData> GetIRSData(LessonRecord lessonRecord, LessonBase lessonBase, TimeLineData timeLineData, List<IRSData> irsDatas, List<StudentLessonData> studentLessonDatas,List<ExamData> examDatas)
- {
- List<string> interactTypes = new List<string>() { "PopQuesLoad", "ReAtmpAnsStrt", "BuzrAns", "BuzrLoad", "PickupResult" };
- //去重页面
- var enventsInteract = timeLineData.events.Where(x => interactTypes.Contains(x.Event)).GroupBy(x => x.Pgid) .Select(x => new { key = x.Key, list = x.ToList() });
- if (enventsInteract!= null)
- {
- var keys = enventsInteract.Select(x => x.key).ToList();
- foreach (var item in enventsInteract)
- {
- ProcessIRSPageData(irsDatas, studentLessonDatas,examDatas, item);
- }
- //处理其他,评测类型的互动,因为有可能不会记录在TimeLine.json中
- var envents_other = timeLineData.events.Where(x => !keys.Contains(x.Pgid)).GroupBy(x => x.Pgid) .Select(x => new { key = x.Key, list = x.ToList() });
- if (envents_other!=null)
- {
- foreach (var item in envents_other)
- {
- ProcessIRSPageData(irsDatas, studentLessonDatas,examDatas, item);
- }
- }
- }
- else
- {
- //处理其他,评测类型的互动,因为有可能不会记录在TimeLine.json中
- var envents_other = timeLineData.events.GroupBy(x => x.Pgid) .Select(x => new { key = x.Key, list = x.ToList() });
- if (envents_other!=null)
- {
- foreach (var item in envents_other)
- {
- ProcessIRSPageData(irsDatas, studentLessonDatas,examDatas, item);
- }
- }
- }
- //单独处理挑人的逻辑
- //是否从小组里面挑人。
- //不需要去重页面,直接获取挑人大类 PickupResult
- //小类处理:PickupRight , PickupOption , PickupNthGrp ,PickupEachGrp ,PickupDiff
- var enventsPickup = timeLineData.events.Where(x => x.Event.Equals("PickupResult"));
- if (enventsPickup.IsNotEmpty())
- {
- foreach (var item in enventsPickup)
- {
- List<int> mbrs = item.PickupMemberId.ToObject<List<int>>();
- foreach (var mbr in mbrs)
- {
- var studentLessonData = studentLessonDatas.Find(x => x.seatID!.Equals($"{mbr}"));
- if (studentLessonData!=null)
- {
- studentLessonData.interactRecord.interactRecords.Add(new ItemRecord()
- {
- resultWeight = InteractWeight.TT,
- resultType="TT",
- interactType = string.IsNullOrWhiteSpace(item.PickupType) ? "PickupResult" : item.PickupType
- });
- }
- }
- }
- }
- return studentLessonDatas;
- }
- private static List<StudentLessonData> ProcessIRSPageData(List<IRSData> irsDatas, List<StudentLessonData> studentLessonDatas, List<ExamData> examDatas, dynamic item)
- {
- var irsDataPages = irsDatas.Where(y => item.key.Equals(y.pageID));
- foreach (var irsDataPage in irsDataPages)
- {
- //检查是否设置正确答案。
- var answers_q = irsDataPage.question?["exercise"]?["answer"]?.ToJsonString().ToObject<List<string>>();
- var question_id = $"{irsDataPage.question?["id"]}";
- var xs= examDatas.Where(x =>x.paper!=null && x.paper.slides.Exists(x =>!string.IsNullOrWhiteSpace(x.url) && x.url.Equals($"{question_id}.json"))).FirstOrDefault();
- List<string> answers = new List<string>();
- answers_q?.ForEach(x => {
- if (!string.IsNullOrWhiteSpace(x))
- {
- answers.Add(x);
- }
- });
- var _objective = irsDataPage.question?["exercise"]?["objective"];
- var scoreNode = irsDataPage.question?["exercise"]?["score"];
- var _type = irsDataPage.question?["exercise"]?["type"];
- var _answerType = irsDataPage.question?["exercise"]?["answerType"];//file,audio,text,image
- double score = 0;
- bool objective = false;
-
- if (_objective!=null) {
- objective = _objective.GetValue<bool>();
- }
- //题型
- string type= string.Empty;
- if (_type!=null)
- {
- //题型
- type = _type.GetValue<string>();
- List<string> types = new List<string>() { "single", "multiple" , "judge" , "sortmultiple" };
- if (types.Contains(type))
- {
- objective = true;
- }
- else {
- objective = false;
- }
-
- }
- if (_answerType!=null)
- {
- _answerType.GetValue<string>();
- //暂不处理,可能存在依然传文字的情况
- //不是文本作答的处理,题目不是客观题,答案不记录
- //if (!_answerType.Equals("text"))
- //{
- // objective=false;
- // answers=new List<string>();
- //}
- }
- if (scoreNode!=null)
- {
- double.TryParse(scoreNode.ToString(), out score);
- }
- string interactType = string.Empty;
- if (irsDataPage.clientAnswers.IsNotEmpty())
- {
- //第一个list是几轮,一次作答,二次作答, 第二个list是学生的下标, 第三个list是 答案
- List<List<List<string>>> clientAnswers = new List<List<List<string>>>();
- foreach (var key in irsDataPage.clientAnswers.Keys)
- {
- clientAnswers.Add(irsDataPage.clientAnswers[key]);
- }
- // 获取第一个列表的长度作为比较基准
- int firstListLength = clientAnswers.First().Count;
- bool isSameLength = true;
- // 遍历剩余的列表并检查它们的长度是否与第一个列表相同
- foreach (var innerList in clientAnswers.Skip(1))
- {
- if (innerList.Count != firstListLength)
- {
- isSameLength = false;
- break;
- }
- }
- //并检查学生集合的长度是否与第一个列表相同
- if (!isSameLength && studentLessonDatas.Count()==firstListLength)
- {
- for (int index = 0; index< clientAnswers[0].Count; index++)
- {
- //index 代表学生下标
- List<ItemRecord> interactRecords = new List<ItemRecord>();
- if (clientAnswers.Count==1)
- {
- //即问即答
- interactType = "PopQuesLoad";
- var ans0 = clientAnswers[0][index];
- var IS0 = GetInteractResultHasAnswer(answers, ans0, objective,type);
- interactRecords.Add(new ItemRecord()
- {
- resultWeight = IS0.weight,
- resultType=IS0.reultType,
- interactType= interactType
- });
- }
- if (clientAnswers.Count==2)
- {
- //二次作答
- interactType="ReAtmpAnsStrt";
- var ans1 = clientAnswers[1][index];
- var IS1 = GetInteractResultHasAnswer(answers, ans1, objective,type);
- interactRecords.Add(new ItemRecord()
- {
- resultWeight = IS1.weight,
- resultType=IS1.reultType,
- interactType= interactType
- });
- }
- if (clientAnswers.Count>2)
- {
- //三次作答
- interactType="TeAtmpAnsStrt";
- var ans2 = clientAnswers[2][index];
- var IS2 = GetInteractResultHasAnswer(answers, ans2, objective,type);
- interactRecords.Add(new ItemRecord()
- {
- resultWeight = IS2.weight,
- resultType=IS2.reultType,
- interactType= interactType
- });
- }
- studentLessonDatas[index].interactRecord.interactRecords.AddRange(interactRecords);
- }
- }
- }
- //是否抢权作答的模式
- if (irsDataPage.isBuzz)
- {
- interactType = "BuzrAns";
- //处理参与抢权的
- Dictionary<string, ItemRecord> buzzParticipants = new Dictionary<string, ItemRecord>();
- foreach (var buzzParticipant in irsDataPage.buzzParticipants)
- {
- var studentData = studentLessonDatas.Find(x => x.seatID!.Equals(buzzParticipant));
- if (studentData != null)
- {
- buzzParticipants[buzzParticipant]=new ItemRecord() { resultWeight = InteractWeight.T1, interactType= interactType };
- }
- }
- //处理抢权成功的
- foreach (var buzzClient in irsDataPage.buzzClients)
- {
- buzzParticipants[buzzClient]=new ItemRecord() { resultWeight = InteractWeight.TT, interactType= interactType };
- }
- foreach (var studentLessonData in studentLessonDatas)
- {
- if (buzzParticipants.ContainsKey(studentLessonData.seatID!))
- {
- //处理已经有抢权结果的数据
- studentLessonData.interactRecord.interactRecords.Add(buzzParticipants[studentLessonData.seatID!]);
- }
- else
- {
- //处理未参与抢权的
- studentLessonData.interactRecord.interactRecords.Add(new ItemRecord() { resultWeight = InteractWeight.T0, interactType = interactType });
- }
- }
- }
-
- }
- return studentLessonDatas;
- }
- private static (double weight,string reultType) GetInteractResultHasAnswer(List<string>? answers, List<string> ans0 , bool objective,string type)
- {
- //List<string> ans0 = new List<string>();
- //ans?.ForEach(x => {
- // if (!string.IsNullOrWhiteSpace(x))
- // {
- // ans0.Add(x);
- // }
- // else { ans.Add("");}
- //});
- double weight = InteractWeight.T0;
- string reultType = InteractReultType.T0;
- if (answers.IsNotEmpty())
- {
- if (ans0.IsNotEmpty())
- {
- if (objective) //客观题
- {
- //标准答案等于作答的结果
- if (answers!.Count == ans0.Count)
- {
- if (answers.All(item => ans0.Contains(item)))
- {
- //完全正确
- weight= InteractWeight.TT;
- reultType= InteractReultType.TT;
- }
- else
- {
- //作答错误
- weight= InteractWeight.T1;
- reultType = InteractReultType.T1;
- }
- }
- //标准答案比作答的结果多
- else if (answers!.Count > ans0.Count)
- {
- if (ans0.All(item => answers.Contains(item)))
- {
- //部分正确
- weight= InteractWeight.TP;
- reultType = InteractReultType.TP;
- }
- else
- {
- //作答错误
- weight= InteractWeight.T1;
- reultType = InteractReultType.T1;
- }
- }
- //标准答案比作答结果少
- else
- {
- //作答错误
- weight= InteractWeight.T1;
- reultType = InteractReultType.T1;
- }
- }
- else
- {
- //填空题
- if ("complete".Equals(type) && answers!.Count==ans0.Count)
- {
- bool hasT = false;
- bool hasF = false;
- for (int i = 0; i < answers!.Count; i++)
- {
- if (answers[i].Equals(ans0[i]))
- {
- hasT=true;
- }
- else {
- hasF=true;
- }
- }
- if (hasT && !hasF)
- {
- //完全正确
- weight= InteractWeight.TT;
- reultType = InteractReultType.TT;
- }
- else if (hasT && hasF)
- {
- //部分正确
- weight= InteractWeight.TP;
- reultType = InteractReultType.TP;
- }
- else if (!hasT && hasF)
- {
- //没有正确的,但有错误的,代表参与了
- weight= InteractWeight.T1;
- reultType = InteractReultType.T1;
- }
- else if (!hasT && !hasF)
- {
- //没有正确的,也没有错误的,代表没有作答
- weight= InteractWeight.T0;
- reultType = InteractReultType.T0;
- }
- }
- else
- {
- //主观题,完全匹配的
- if (answers!.All(item => ans0.Contains(item)))
- {
- //完全正确
- weight= InteractWeight.TT;
- reultType = InteractReultType.TT;
- }
- else
- { // 使用LINQ查询来判断是否有匹配的答案
- bool hasMatchingAnswer = answers!.Intersect(ans0).Any();
- if (hasMatchingAnswer)
- {
- //主观题回答正确即为完全正确
- weight= InteractWeight.TT;
- reultType = InteractReultType.TT;
- }
- else
- {
- //
- //
- //
- //
- //
- //
- //
- //
- //
- //
- //
- //
- //
- //
- //
- //
- //
- //
- //
- //
- //
- //
- //
- //
- //
- //
- //
- //
- //
- //优先根据得分与标准分的占比算出得分率,如果没有得分率,如果是直接从互动,不知道是评测的 需要先去评测找作答得分。,则采用Levenshtein距离来评估两个字符串的相似度
- //没有匹配上答案,则采用Levenshtein距离来评估两个字符串的相似度
- var sc = CalculateSimilarity(answers![0], ans0[0]) * 1.0/100 *(InteractWeight.TT-InteractWeight.T1);
- weight = sc;
- reultType = InteractReultType.TP;
- }
- }
- }
- }
- }
- else
- {
- //没有作答
- weight= InteractWeight.T0;
- reultType = InteractReultType.T0;
- }
- }
- else
- {
- //没有答案的情况
- if (ans0.IsNotEmpty())
- {
- bool hasAns = false;
- ans0.ForEach(x => {
- if (!string.IsNullOrWhiteSpace(x)) {
- hasAns = true;
- }
- });
- if (hasAns)
- {
- //作答了
- weight= InteractWeight.T1;
- reultType = InteractReultType.T1;
- }
- else {
- //没有作答
- weight= InteractWeight.T0;
- reultType = InteractReultType.T0;
- }
-
- }
- else
- {
- //没有作答
- weight= InteractWeight.T0;
- reultType = InteractReultType.T0;
- }
- }
- return (weight,reultType);
- }
- #region C# 代码 如何判断两句话是否一个意思,非机器学习的算法。使用Levenshtein距离来评估两个字符串的相似度,但是不能判断它们是否表达了同一个意思,后续借助AI实现
- public static double CalculateSimilarity(string s1, string s2)
- {
- int n = s1.Length;
- int m = s2.Length;
- int[,] d = new int[n + 1, m + 1];
- for (int i = 0; i <= n; i++)
- {
- d[i, 0] = i;
- }
- for (int j = 0; j <= m; j++)
- {
- d[0, j] = j;
- }
- for (int i = 1; i <= n; i++)
- {
- for (int j = 1; j <= m; j++)
- {
- int cost = (s1[i - 1] == s2[j - 1]) ? 0 : 1;
- d[i, j] = Math.Min(Math.Min(d[i - 1, j] + 1, d[i, j - 1] + 1), d[i - 1, j - 1] + cost);
- }
- }
- return (1.0 - ((double)d[n, m] / Math.Max(s1.Length, s2.Length))) * 100;
- }
-
- #endregion
- /// <summary>
- /// 获取课中评测数据
- /// </summary>
- /// <param name="lessonRecord"></param>
- /// <param name="lessonBase"></param>
- /// <param name="timeLineData"></param>
- /// <param name="coworkDatas"></param>
- /// <param name="studentLessonDatas"></param>
- /// <returns></returns>
- private List<StudentLessonData> GetExamData(LessonRecord lessonRecord, LessonBase lessonBase, TimeLineData timeLineData, List<ExamData> examDatas, List<StudentLessonData> studentLessonDatas)
- {
- foreach (var examData in examDatas)
- {
- //直接取第一个元素的试卷,因为在HiTeach中,只会是一个试卷(一个科目),一个班参与。
- var allocation= examData?.exam?.papers?.FirstOrDefault()?.point?.Sum();
- var answersStd = examData?.exam?.papers?.FirstOrDefault()?.answers;
- List<List<string>> answers= new List<List<string>>();
- if (answersStd!=null)
- {
- answersStd.ForEach(x => //去除[""]此种类型的标准答案,转为[]
- {
- List<string> ans = new List<string>();
- if (x.Count!=0)
- {
- if (x.Count==1)
- {
- if (string.IsNullOrWhiteSpace(x[0]))
- {
- answers.Add(ans);
- }
- else
- {
- answers.Add(x);
- }
- }
- else
- {
- answers.Add(x);
- }
- }
- else {
- answers.Add(ans);
- }
- });
- }
- examData?.examClassResult?.ForEach(item =>{
- //学生下标
- int index = 0;
- if (item.studentAnswersArray.Count()>0
- && item.studentAnswersArray.Count() == item.studentIds.Count() //学生作答数量和学生id数量一致
- && item.studentScores.Count()==item.studentIds.Count()) //学生分数和学生id数量一致
- {
- item.studentAnswersArray.ForEach(stu => {
- var student = studentLessonDatas.Find(x => x.id!.Equals(item.studentIds[index]));
-
- if (student!=null)
- {
-
- //是否要判断主观题或者客观题, 多套试卷,有主观题的
- //,如果没获得结果,
- //主观题有回答的:608942756458532864\Clients\18782481024\Ans\27-4341670635487887360-examExchangeAnswerlist
- //27 从1开始的学生序号-4341670635487887360评测编号,内容qNo 是从1开始的题号。
- if (stu.IsNotEmpty() && answers.Count()==stu.Count && examData.exam.papers[0].type.Count()==answers.Count )
- {
- StudentExamRecord studentExam = new StudentExamRecord();
- var studentScore = item.studentScores[index];
- List<ItemRecord> answerRecords = new List<ItemRecord>();
- //题目下标
- int itemIndex = 0;
- stu.ForEach(ans =>
- {
- bool objective = objectiveTypes.Contains(examData.exam.papers[0].type[itemIndex]);
- var score = examData.exam.papers[0].point[itemIndex];
- string type = examData.exam.papers[0].type[itemIndex];
- var res= GetInteractResultHasAnswer(answers[itemIndex], ans, objective, type);
- ItemRecord interactRecord = new ItemRecord()
- {
- interactType="SPQStrt",//类型
- resultType=res.reultType,//作答结果类型
- resultWeight=res.weight,//得分权重
- criterion= score,//标准分
- interactScore= studentScore[itemIndex]//得分
- };
- answerRecords.Add(interactRecord);
- });
- studentExam.score= answerRecords.Where(x => x.interactScore>=0).Select(x => x.interactScore).Sum();//得分
- studentExam.scoreRate= allocation.HasValue && allocation.Value>0 ? studentExam.score * 1.0/allocation.Value : 0;//得分率
- studentExam.answerRate= answerRecords.Where(x => x.resultWeight>0).Count()*1.0/studentScore.Count();//作答率
- studentExam.examId=examData.exam.id;
- studentExam.itemRecords=answerRecords;
- student.examRecords.Add(studentExam);
- }
- }
- });
- }
- });
- }
- return studentLessonDatas;
- }
- /// <summary>
- /// 协作参与率 态度计算
- /// </summary>
- /// <param name="lessonRecord"></param>
- /// <param name="lessonBase"></param>
- /// <param name="timeLineData"></param>
- /// <param name="coworkDatas"></param>
- /// <param name="studentLessonDatas"></param>
- /// <returns></returns>
- private List<StudentLessonData> GetCoworkData(LessonRecord lessonRecord, LessonBase lessonBase, TimeLineData timeLineData, List<CoworkData> coworkDatas, List<StudentLessonData> studentLessonDatas)
- {
- foreach (var coworkData in coworkDatas)
- {
- var keys = coworkData.participateLevelList.Keys;
- foreach (var key in keys)
- {
- var student = studentLessonDatas.Find(x => x.seatID!.Equals(key));
- if (student!=null)
- {
- var score = coworkData.participateLevelList[key];
- var itemRecord = new ItemRecord { criterion=-1, interactType= coworkData.coworkType,interactScore=score };
- if (score>0)
- {
- itemRecord.resultWeight = InteractWeight.T1;
- itemRecord.resultType = InteractReultType.T1;
- }
- else {
- itemRecord.resultWeight = InteractWeight.T0;
- itemRecord.resultType = InteractReultType.T0;
- }
- student.coworkRecord.itemRecords.Add(itemRecord);
- }
- }
- }
- return studentLessonDatas;
- }
- /// <summary>
- /// 处理学生回推数据,并将回推纳入学习态度计算。
- /// </summary>
- /// <param name="lessonRecord"></param>
- /// <param name="lessonBase"></param>
- /// <param name="timeLineData"></param>
- /// <param name="taskDatas"></param>
- /// <param name="studentLessonDatas"></param>
- /// <returns></returns>
- private async Task<dynamic> GetTaskData(LessonRecord lessonRecord, LessonBase lessonBase, TimeLineData timeLineData, List<TaskData> taskDatas, List<StudentLessonData> studentLessonDatas)
- {
- //协作也算任务的一种,'WrkSpaceLoad' 作品收集, "isGroupItem": false,
- return Ok(lessonRecord);
- }
- /// <summary>
- /// 评分参与率 态度计算
- /// </summary>
- /// <param name="lessonRecord"></param>
- /// <param name="lessonBase"></param>
- /// <param name="timeLineData"></param>
- /// <param name="smartRatingDatas"></param>
- /// <param name="studentLessonDatas"></param>
- /// <returns></returns>
- private async Task<dynamic> GetSmartRatingData(LessonRecord lessonRecord, LessonBase lessonBase, TimeLineData timeLineData, List<SmartRatingData> smartRatingDatas, List<StudentLessonData> studentLessonDatas)
- {
- return Ok(lessonRecord);
- }
- }
-
- /// 互动参与指数(按倍数的权重设计)
- /// 无二次作答的互动,且未设置正确答案:1.未作答0
- /// 2.已作答1
- ///
- /// 无二次作答的互动,且设置了正确答案:3.未作答0
- /// 4.已作答1
- /// 5.不完全正确1.3
- /// 6.作答正确1.5
- ///
- ///
- /// 有二次作答的互动,且未设置正确答案:7.第一次未作答0,第二次未作答0=》0
- /// 8.第一次已作答1,第二次未作答0=》1
- /// 9.第一次未作答0,第二次已作答1=》1
- /// 10.第一次已作答1,第二次已作答1=》2
- ///
- /// 有二次作答的互动,且设置了正确答案:(16种可能)
- /// 11.第一次未作答0,第二次未作答0=》0
- /// 12.第一次已作答,不完全正确1.3,第二次未作答0=》1.3
- /// 13.第一次已作答,作答正确1.5,第二次未作答0=》1.5
- /// 14.第一次已作答,作答错误1,第二次未作答0=》1
- /// 15.第一次未作答0,第二次已作答,不完全正确1.3=》1.3
- /// 16.第一次未作答0,第二次已作答,作答正确1.5=》1.5
- /// 17.第一次未作答0,第二次已作答,作答错误1=》1
- /// 18.第一次已作答,作答错误1,第二次已作答,作答错误1=》2
- /// 19.第一次已作答,不完全正确1.3,第二次已作答,作答错误1=》2.3
- /// 20.第一次已作答,作答正确1.5,第二次已作答,作答错误1=》2.5
- /// 21.第一次已作答,作答错误1,第二次已作答,不完全正确1.3=》2.3
- /// 22.第一次已作答,作答错误1,第二次已作答,作答正确1.5=》2.5
- /// 23.第一次已作答,不完全正确1.3,第二次已作答,不完全正确1.3=》2.6
- /// 24.第一次已作答,不完全正确1.3,第二次已作答,作答正确1.5=》2.8
- /// 25.第一次已作答,作答正确1.5,第二次已作答,不完全正确1.3=》2.8
- /// 26.第一次已作答,作答正确1.5,第二次已作答,作答正确1.5=》3
- ///
- /// 抢权模式: 27.未参与抢权 0
- /// 28.参与抢权 1
- /// 29.抢权成功 1.5
- /// 挑人时被挑到 30.被挑到 1.5
- /// 有三次作答的互动,且设置了正确答案:(64种可能)
- /*
- 1 未作答0 未作答0 未作答0 0
- 2 未作答0 未作答0 不完全正确1.3 1.3
- 3 未作答0 未作答0 作答正确1.5 1.5
- 4 未作答0 未作答0 作答错误1 1
- 5 未作答0 不完全正确1.3 未作答0 1.3
- 6 未作答0 不完全正确1.3 不完全正确1.3 2.6
- 7 未作答0 不完全正确1.3 作答正确1.5 2.8
- 8 未作答0 不完全正确1.3 作答错误1 2.3
- 9 未作答0 作答正确1.5 未作答0 1.5
- 10 未作答0 作答正确1.5 不完全正确1.3 2.8
- 11 未作答0 作答正确1.5 作答正确1.5 3
- 12 未作答0 作答正确1.5 作答错误1 2.5
- 13 未作答0 作答错误1 未作答0 1
- 14 未作答0 作答错误1 不完全正确1.3 2.3
- 15 未作答0 作答错误1 作答正确1.5 2.5
- 16 未作答0 作答错误1 作答错误1 2
- 17 已作答错误1 未作答0 未作答0 1
- 18 已作答错误1 未作答0 不完全正确1.3 2.3
- 19 已作答错误1 未作答0 作答正确1.5 2.5
- 20 已作答错误1 未作答0 作答错误1 2
- 21 已作答错误1 不完全正确1.3 未作答0 2.3
- 22 已作答错误1 不完全正确1.3 不完全正确1.3 3.6
- 23 已作答错误1 不完全正确1.3 作答正确1.5 3.8
- 24 已作答错误1 不完全正确1.3 作答错误1 3.3
- 25 已作答错误1 作答正确1.5 未作答0 2.5
- 26 已作答错误1 作答正确1.5 不完全正确1.3 3.8
- 27 已作答错误1 作答正确1.5 作答正确1.5 4
- 28 已作答错误1 作答正确1.5 作答错误1 3.5
- 29 已作答错误1 作答错误1 未作答0 2
- 30 已作答错误1 作答错误1 不完全正确1.3 3.3
- 31 已作答错误1 作答错误1 作答正确1.5 3.5
- 32 已作答错误1 作答错误1 作答错误1 3
- 33 已作答不完全正确1.3 未作答0 未作答0 1.3
- 34 已作答不完全正确1.3 未作答0 不完全正确1.3 2.6
- 35 已作答不完全正确1.3 未作答0 作答正确1.5 2.8
- 36 已作答不完全正确1.3 未作答0 作答错误1 2.3
- 37 已作答不完全正确1.3 不完全正确1.3 未作答0 2.6
- 38 已作答不完全正确1.3 不完全正确1.3 不完全正确1.3 3.9
- 39 已作答不完全正确1.3 不完全正确1.3 作答正确1.5 4.1
- 40 已作答不完全正确1.3 不完全正确1.3 作答错误1 3.6
- 41 已作答不完全正确1.3 作答正确1.5 未作答0 2.8
- 42 已作答不完全正确1.3 作答正确1.5 不完全正确1.3 4.1
- 43 已作答不完全正确1.3 作答正确1.5 作答正确1.5 4.3
- 44 已作答不完全正确1.3 作答正确1.5 作答错误1 3.8
- 45 已作答不完全正确1.3 作答错误1 未作答0 2.3
- 46 已作答不完全正确1.3 作答错误1 不完全正确1.3 3.6
- 47 已作答不完全正确1.3 作答错误1 作答正确1.5 3.8
- 48 已作答不完全正确1.3 作答错误1 作答错误1 3.3
- 49 已作答正确1.5 未作答0 未作答0 1.5
- 50 已作答正确1.5 未作答0 不完全正确1.3 2.8
- 51 已作答正确1.5 未作答0 作答正确1.5 3
- 52 已作答正确1.5 未作答0 作答错误1 2.5
- 53 已作答正确1.5 不完全正确1.3 未作答0 2.8
- 54 已作答正确1.5 不完全正确1.3 不完全正确1.3 4.1
- 55 已作答正确1.5 不完全正确1.3 作答正确1.5 4.3
- 56 已作答正确1.5 不完全正确1.3 作答错误1 3.8
- 57 已作答正确1.5 作答正确1.5 未作答0 3
- 58 已作答正确1.5 作答正确1.5 不完全正确1.3 4.3
- 59 已作答正确1.5 作答正确1.5作答正确1.5 4.5
- 60 已作答正确1.5 作答正确1.5作答错误1 4
- 61 已作答正确1.5 作答错误1 未作答0 2.5
- 62 已作答正确1.5 作答错误1 不完全正确1.3 3.8
- 63 已作答正确1.5 作答错误1 作答正确1.54
- 64 已作答正确1.5 作答错误1 作答错误1 3.5
- */
- /*
- *
- /// 事件
- /// 推送相关 在Push.json处理 DifObjPush 推送给学生 差异化推送 "PushMemberId":[1,4,8,12,17,18,19,23,24,27,32,36] ,FastPgPush 同一推送
- /// 互动相关 在IRS.json处理 'PopQuesLoad'互动问答 , 'ReAtmpAnsStrt' 二次作答 , 'BuzrAns' 抢权(新), 'BuzrLoad'抢权(旧), PickupResult 挑人算不算互动?? 读取PickupMemberId "[\r\n 35\r\n]"
- /// 测验相关 在IRS.json处理 SPQStrt 测验模式
- /// 任务相关 在Task.json处理 'WrkSpaceLoad' 作品收集, 'WrkCmp' 作品贴上 是什么操作
- /// 评分相关 在SmartRating.json 处理 'SmartRating' 评分模式,分 投票Voting 和 GrandRating 星光大评分(All每人多件评分,Two随机分配互评, Self自评)
- /// 协作相关 在Cowork.json 处理 CoworkLoad 协作类型 coworkType All: '全体协作', Group: '分组协作', 其他的为 : '差异化协作',
- 问题汇总:
- TimeLine.json
- 挑人大类 Event= PickupResult 里面 分小类
- PickupType=PickupRight , PickupOption , PickupNthGrp ,PickupEachGrp ,PickupDiff 五种类型分别是什么意思,是否还有其他类型的。
- ,"PickupCount":1,"PickupOption":2 ,"PickupGroup":2 这三个字段是什么意思。
- "PickupMemberId":"[\r\n 1\r\n]" 里面是学生的座号还是数组下标。
- "Event":"PressGood","TargetClass":0,"MemberId":"[\r\n 1\r\n]","Count":1},
- 是代表什么意思。 MemberId 是座号还说下标。
- 8月27日 17:581. Task.json的 clientWorks.isGroupItem bool 类型 false代表什么意思 true代表什么意思
- 2. Cowork.json 的 coworkType All: '全体协作', Group: '分组协作', : '差异化协作', 差异化协作的简码是什么?
- 3. TimeLine.json 的 类型 PickupResult 挑人算不算互动?? 读取PickupMemberId "[\r\n 35\r\n]"
- 4. 小组任务具体详细信息如何获取? 需要精确到 所有小组任务信息和 某一小组的参与情况 用于计算小组任务参与率
- */
- }
|