This commit is contained in:
wangxiner55 2024-09-12 21:12:58 +08:00
parent 82960a6ebe
commit fe9c8a3f0c
9 changed files with 229 additions and 86 deletions

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StudentManager.Common
{
public class CursonManager
{
public int CursonIndex { get; set; } = 0;
public int CursonCount { get; set; } = 0;
public string CursonName { get; set; } = string.Empty;
}
}

View File

@ -1,4 +1,5 @@
using StudentManager.Data;
using DryIoc.ImTools;
using StudentManager.Data;
using System;
using System.Collections.Generic;
using System.Linq;
@ -7,80 +8,131 @@ using System.Threading.Tasks;
namespace StudentManager.Common
{
public class ErrorInfo
public class QuestionBase
{
public int ID { get; set; } = 0;
public bool Status { get; set; } = false;
}
public class ErrorBase
{
public QuestionBase QuestionBase { get; set; } = new QuestionBase();
public int TotalUseCount { get; set; } = 1;
public int ErrorCount { get; set; } = 1;
public int CorrectCount { get; set; } = 0;
}
public class ErrorSet
{
public int TotalCount { get; set; } = 0;
public int CorrectCount { get; set; } = 0;
public Dictionary<int, ErrorInfo> Errores { get; set; } = new Dictionary<int, ErrorInfo>();
public Dictionary<int, ErrorBase> Errores { get; set; } = new Dictionary<int, ErrorBase>();
public List<int> ErrorArray { get; set; } = new List<int>();
public List<int> CorrectArray { get; set; } = new List<int>();
public int CorrectThresholds { get; set; } = 2;
public void InitErrorSetData()
{
foreach (var item in Errores)
{
if(item.Value.Status == true) CorrectArray.Add(item.Value.ID);
else ErrorArray.Add(item.Value.ID);
if (item.Value.QuestionBase.Status == true) CorrectArray.Add(item.Value.QuestionBase.ID);
else ErrorArray.Add(item.Value.QuestionBase.ID);
}
}
public void AddQuestion(QuestionBase question)
{
if (question.Status)
{
AddCorrectQuestion(question);
}
else
{
AddErrorQuestion(question);
}
}
public void AddErrorQuestion(int id)
{
if (Errores.ContainsKey(id))
{
TotalCount++;
ErrorArray.Add(id);
}
else
{
Errores.Add(id, new ErrorInfo { ID = id });
}
}
public void AddCorrectQuestion(int id)
{
if (Errores.ContainsKey(id))
{
TotalCount++;
CorrectCount++;
Errores[id].Status = true;
ErrorArray.Remove(id);
CorrectArray.Add(id);
}
}
public void AddErrorQuestion(QuestionBase question)
{
if (Errores.ContainsKey(question.ID))
{
Errores[question.ID].TotalUseCount++;
Errores[question.ID].ErrorCount++;
public void AddErrorQuestion(QuestionData question)
{
if (Errores.ContainsKey(question.Id))
{
TotalCount++;
ErrorArray.Add(question.Id);
CompareToErrorArray(Errores[question.ID]);
}
else
{
Errores.Add(question.Id, new ErrorInfo { ID = question.Id });
TotalCount++;
Errores.Add(question.ID, new ErrorBase { QuestionBase = { ID = question.ID } });
ErrorArray.Add(question.ID);
}
}
public void AddErrorQuestion(QuestionData question)
{
}
public void AddCorrectQuestion(QuestionBase id)
{
if (Errores.ContainsKey(id.ID))
{
CorrectCount++;
Errores[id.ID].QuestionBase.Status = true;
Errores[id.ID].CorrectCount++;
CompareToCorrectArray(Errores[id.ID]);
}
}
private void CompareToErrorArray(ErrorBase id)
{
if (id.QuestionBase.Status == false || ErrorArray.Contains(id.QuestionBase.ID)) return;
if ((id.CorrectCount - id.CorrectCount) <= CorrectThresholds)
{
id.QuestionBase.Status = false;
CorrectArray.Remove(id.QuestionBase.ID);
ErrorArray.Add(id.QuestionBase.ID);
}
}
private void CompareToCorrectArray(ErrorBase id)
{
if (id.QuestionBase.Status == true || CorrectArray.Contains(id.QuestionBase.ID)) return;
if ((id.CorrectCount - id.CorrectCount) > CorrectThresholds)
{
id.QuestionBase.Status = true;
ErrorArray.Remove(id.QuestionBase.ID);
CorrectArray.Add(id.QuestionBase.ID);
}
}
public void AddCorrectQuestion(QuestionData question)
{
if (Errores.ContainsKey(question.Id))
{
TotalCount++;
CorrectCount++;
Errores[question.Id].Status = true;
ErrorArray.Remove(question.Id);
CorrectArray.Add(question.Id);
AddCorrectQuestion(new QuestionBase { ID = question.Id });
}
public void QueryErrorSet(int id)
{
Errores.Clear();
SQLHelper.Query<UserQuestionData>(Tables.UQTable, id).ForEach(x =>
{
AddQuestion(new QuestionBase { ID = x.PID, Status = x.Status});
});
}
}
}

View File

@ -21,17 +21,22 @@ namespace StudentManager.Common
work.AddHomeWork(item);
}
if (CommonHomeWork.QuestionInfo.Count > 0)
if (CommonHomeWork.Questions.Count > 0)
{
work.Append(CommonHomeWork);
}
student.CurentHomeWork = work;
}
public static void Public()
{
foreach (var item in StudentLib.StudentDic)
{
item.Value.PublicHomeWork();
}
}
}
}

View File

@ -1,4 +1,5 @@
using DryIoc.ImTools;
using StudentManager.Data;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@ -12,28 +13,28 @@ namespace StudentManager.Common
{
public int Lesson { get; set; } = 0;
public bool Status { get; set; } = false;
public HashSet<ErrorInfo> QuestionInfo { get; set; } = new HashSet<ErrorInfo>();
public HashSet<QuestionBase> Questions { get; set; } = new HashSet<QuestionBase>();
public void AddHomeWork(ErrorInfo workInfo)
public void AddHomeWork(QuestionBase workInfo)
{
QuestionInfo.Add(workInfo);
Questions.Add(workInfo);
}
public void AddHomeWork(int id)
{
QuestionInfo.Add(new ErrorInfo { ID = id });
Questions.Add(new QuestionBase { ID = id });
}
public void RemoveHomeWork(ErrorInfo workInfo)
public void RemoveHomeWork(QuestionBase workInfo)
{
QuestionInfo.Remove(workInfo);
Questions.Remove(workInfo);
}
public void Append(HomeWork homeWork)
{
foreach (var item in homeWork.QuestionInfo)
foreach (var item in homeWork.Questions)
{
QuestionInfo.Add(item);
Questions.Add(item);
}
}
@ -67,7 +68,7 @@ namespace StudentManager.Common
public ObservableCollection<HomeWork> GetAllByColl()
{
ObservableCollection <HomeWork> works = new ObservableCollection<HomeWork >();
ObservableCollection<HomeWork> works = new ObservableCollection<HomeWork>();
foreach (var item in HomeWorks)
{
@ -75,6 +76,18 @@ namespace StudentManager.Common
}
return works;
}
public void QueryCQSet(int id)
{
HomeWorks.Clear();
SQLHelper.Query<CursonQuestionsData>(Tables.CQTable, id).ForEach(x =>
{
HashSet<QuestionBase> Questions = new HashSet<QuestionBase>();
x.ProblemIDS.ForEach(y => Questions.Add(new QuestionBase { ID = y, Status = x.CorrectIDS.Contains(y) }));
HomeWorks.Add(x.Lesson, new HomeWork { Lesson = x.Lesson, Questions = Questions, Status = x.Status == 1 });
});
}
}
}

View File

@ -41,7 +41,7 @@ namespace StudentManager.Common
(data as StudentData).TotalsQuestions = (UInt16)reader[6];
(data as StudentData).CorrectionCount = (UInt16)reader[7];
}
else if(typeof(T) == typeof(QuestionData))
else if (typeof(T) == typeof(QuestionData))
{
DifficultyLevel dLevel = DifficultyLevel.easy;
QStatus qStatus = QStatus.published;
@ -68,6 +68,13 @@ namespace StudentManager.Common
(data as CursonQuestionsData).TotalCount = (data as CursonQuestionsData).ProblemIDS.Length;
(data as CursonQuestionsData).CorrectCount = (data as CursonQuestionsData).CorrectIDS.Length;
}
else if (typeof(T) == typeof(UserQuestionData))
{
(data as UserQuestionData).PID = (int)reader[1];
(data as UserQuestionData).ErrorCount = (byte)reader[2];
(data as UserQuestionData).CorrectCount = (byte)reader[3];
(data as UserQuestionData).Status = (byte)reader[4] == 1;
}

View File

@ -1,4 +1,5 @@
using Microsoft.VisualBasic;
using StudentManager.Common;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@ -12,7 +13,6 @@ namespace StudentManager.Data
{
public static class QuestionLib
{
public static string LibPath = "C:\\Users\\zc\\Desktop\\FileLib\\";
public static string FileName = "questionLib.dbqi";
public static Dictionary<int, QuestionData> QuestionDic { get; set; } = new Dictionary<int, QuestionData>();
@ -20,22 +20,18 @@ namespace StudentManager.Data
{
QuestionDic.Clear();
Debug.Assert(Path.Exists(LibPath));
string file = File.ReadAllText(LibPath + FileName);
Debug.Assert(Path.Exists(StudentLib.LibPath));
string file = File.ReadAllText(StudentLib.LibPath + FileName);
QuestionDic = JsonSerializer.Deserialize<Dictionary<int, QuestionData>>(file);
}
public static void Save()
{
File.WriteAllText((LibPath + FileName), JsonSerializer.Serialize(QuestionDic));
File.WriteAllText((StudentLib.LibPath + FileName), JsonSerializer.Serialize(QuestionDic));
}
public static void Test()
public static void FreshAllQuestion()
{
QuestionDic.Add(1, new QuestionData
{
Id = 1,
Type = "test"
});
SQLHelper.Query<QuestionData>(Tables.QuesTable).ForEach(x => QuestionDic.Add(x.Id, x));
}
public static QuestionData Get(int id)

View File

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection.Metadata.Ecma335;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
@ -12,7 +13,7 @@ namespace StudentManager.Data
{
public static class StudentLib
{
public static string LibPath = "C:\\Users\\zc\\Desktop\\FileLib\\";
public static string LibPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}\\FileLib\\";
public static string FileName = "studentLib.dbsi";
public static Dictionary<int, StudentInfo> StudentDic { get; set; } = new Dictionary<int, StudentInfo>();
@ -33,20 +34,39 @@ namespace StudentManager.Data
public static void Save()
{
Directory.CreateDirectory(Path.GetFullPath(LibPath));
File.WriteAllText((LibPath + FileName), JsonSerializer.Serialize(StudentDic));
}
public static void Test()
public static void FreshAllStudentInfo()
{
StudentDic.Add(1, new StudentInfo
StudentDic.Clear();
SQLHelper.Query<StudentData>(Tables.UserTable).ForEach(x =>
StudentDic.Add(x.UID, new StudentInfo
{
UID = 123,
Name = "John Doe",
Gender = "Male",
Contact = "123-456-7890",
Address = "123 Main St",
Grade = 10,
});
UID = x.UID,
Name = x.Name,
Address = x.Address,
Contact = x.Contact,
Grade = x.Grade,
}));
foreach (var item in StudentDic)
{
GetStudentDetailInfo(item.Value);
}
}
public static StudentInfo QueryStudentDetailInfo(int uid)
{
return GetStudentDetailInfo(Get(uid));
}
public static StudentInfo Get(int uid)
{
if (!StudentDic.ContainsKey(uid)) return null;
return StudentDic[uid];
}
public static void Remove(StudentInfo studentInfo)
@ -58,6 +78,19 @@ namespace StudentManager.Data
{
StudentDic.Remove(id);
}
public static StudentInfo GetStudentDetailInfo(StudentInfo studentData)
{
studentData.ErrorSet.QueryErrorSet(studentData.UID);
studentData.HomeWorkSet.QueryCQSet(studentData.UID);
return studentData;
}
public static void GetStudentDetailInfo(ref StudentInfo studentData)
{
studentData.ErrorSet.QueryErrorSet(studentData.UID);
studentData.HomeWorkSet.QueryCQSet(studentData.UID);
}
}
public class StudentInfo
@ -74,6 +107,9 @@ namespace StudentManager.Data
public HomeWork CurentHomeWork { get; set; } = new HomeWork();
public void PublicHomeWork()
{
HomeWorkSet.AddHomeWork(CurentHomeWork);
}
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StudentManager.Data
{
public class UserQuestionData : IDataCommon
{
public int PID { get; set; } = 0;
public int ErrorCount { get; set; } = 0;
public int CorrectCount { get; set; } = 0;
public bool Status = false;
}
}

View File

@ -135,14 +135,16 @@ namespace StudentManager.Model
this.regionManager = regionManager;
QueryAll();
StudentInfo studentInfo = new StudentInfo();
StudentLib.Test();
//QueryAll();
StudentLib.FreshAllStudentInfo();
StudentLib.Save();
QuestionLib.Test();
QuestionLib.Load();
QuestionLib.Save();
}