Program.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. using HTEXLib.COMM.Helpers;
  2. using System.Text;
  3. using TEAMModelOS.SDK.Extension;
  4. using TEAMModelOS.SDK.Models;
  5. using TEAMModelOS.SDK.Models.Cosmos.OpenEntity;
  6. using TEAMModelOS.SDK.Models.Dtos;
  7. namespace TEAMModelOS.TEST
  8. {
  9. public class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. // 作品数据
  14. var works = new List<Work>
  15. {
  16. new Work { WorkId = "1", Subject = "语文" },
  17. new Work { WorkId = "2", Subject = "数学" },
  18. new Work { WorkId = "3", Subject = "英语" },
  19. new Work { WorkId = "4", Subject = "数学" },
  20. new Work { WorkId = "5", Subject = "英语" },
  21. new Work { WorkId = "6", Subject = "语文" },
  22. new Work { WorkId = "7", Subject = "语文" }
  23. };
  24. // 专家数据
  25. var experts = new List<ExpertS>
  26. {
  27. //new ExpertS { ExpertId = "a", Subjects = new List<string> { "语文", "数学" ,"英语"} },
  28. new ExpertS { ExpertId = "b", Subjects = new List<string> { "数学" } },
  29. //new ExpertS { ExpertId = "c", Subjects = new List<string> { "英语", "英语" } },
  30. new ExpertS { ExpertId = "d", Subjects = new List<string> { "数学" } },
  31. new ExpertS { ExpertId = "e", Subjects = new List<string> { "英语", "数学" } },
  32. //new ExpertS { ExpertId = "f", Subjects = new List<string> { "语文" } }
  33. };
  34. // 分配作品给专家
  35. int N = 1; // 指定评审次数
  36. var assignments = AssignWorksToExperts(works, experts, N);
  37. // 输出结果
  38. foreach (var assignment in assignments)
  39. {
  40. Console.WriteLine($"WorkId: {assignment.WorkId}, ExpertId: {assignment.ExpertId}");
  41. }
  42. string path = "C:\\Users\\CrazyIter\\Downloads\\消费清单(2022-2023)\\bill";
  43. List<List<string>> inputArray = new List<List<string>>
  44. {
  45. new List<string> { "2", "11" },
  46. new List<string> { "1", "22" },
  47. new List<string> { "1", "11", "111" },
  48. new List<string> { "2", "22", "222" },
  49. new List<string> { "1", "11" },
  50. new List<string> { "1", "11" },
  51. new List<string> { "1" },
  52. new List<string> { "2", "22", "222" },
  53. new List<string> { "2", "22" } ,
  54. };
  55. // 转换为层级结构
  56. List<ClassifiedItem> result = ClassifyHierarchy(inputArray);
  57. // 输出结果
  58. foreach (var item in result)
  59. {
  60. Console.WriteLine($"id: {item.Id}, count: {item.Count}, pid: {item.Pid}");
  61. }
  62. }
  63. static List<Assignment> AssignWorksToExperts(List<Work> works, List<ExpertS> experts, int N)
  64. {
  65. var assignments = new List<Assignment>();
  66. foreach (var work in works)
  67. {
  68. for (int i = 0; i < N; i++)
  69. {
  70. var availableExperts = experts
  71. .OrderBy(expert => assignments.Count(a => a.ExpertId == expert.ExpertId))
  72. .Where(expert => expert.Subjects.Contains(work.Subject) && !assignments.Any(a => a.WorkId == work.WorkId && a.ExpertId == expert.ExpertId))
  73. .ToList();
  74. if (availableExperts.Count > 0)
  75. {
  76. var selectedExpert = availableExperts.First();
  77. assignments.Add(new Assignment { WorkId = work.WorkId, ExpertId = selectedExpert.ExpertId });
  78. }
  79. else
  80. {
  81. Console.WriteLine($"No available expert for WorkId {work.WorkId} and subject {work.Subject} in attempt {i + 1}.");
  82. break;
  83. }
  84. }
  85. }
  86. return assignments;
  87. }
  88. static List<ClassifiedItem> ClassifyHierarchy(List<List<string>> inputArray)
  89. {
  90. Dictionary<string, int> hierarchyCount = new Dictionary<string, int>();
  91. List<ClassifiedItem> result = new List<ClassifiedItem>();
  92. foreach (var list in inputArray)
  93. {
  94. for (int i = 0; i < list.Count; i++)
  95. {
  96. string currentId = list[i];
  97. string parentId = (i > 0) ? list[i - 1] : null;
  98. string hierarchyKey = $"{currentId}|{parentId}";
  99. if (hierarchyCount.ContainsKey(hierarchyKey))
  100. {
  101. hierarchyCount[hierarchyKey]++;
  102. }
  103. else
  104. {
  105. hierarchyCount[hierarchyKey] = 1;
  106. }
  107. var item = result.Find(item => item.Id == currentId && item.Pid == parentId);
  108. if (item== null )
  109. {
  110. result.Add(new ClassifiedItem
  111. {
  112. Id = currentId,
  113. Pid = parentId,
  114. Count = 0
  115. });
  116. }
  117. }
  118. }
  119. foreach (var item in result)
  120. {
  121. string hierarchyKey = $"{item.Id}|{item.Pid}";
  122. item.Count = hierarchyCount.ContainsKey(hierarchyKey) ? hierarchyCount[hierarchyKey] : 0;
  123. }
  124. return result;
  125. }
  126. class ClassifiedItem
  127. {
  128. public string Id { get; set; }
  129. public int Count { get; set; }
  130. public string Pid { get; set; }
  131. }
  132. }
  133. class Work
  134. {
  135. public string WorkId { get; set; }
  136. public string Subject { get; set; }
  137. }
  138. class ExpertS
  139. {
  140. public string ExpertId { get; set; }
  141. public List<string> Subjects { get; set; }
  142. }
  143. class Assignment
  144. {
  145. public string WorkId { get; set; }
  146. public string ExpertId { get; set; }
  147. }
  148. public class LessonBase {
  149. public string? id { get; set; }
  150. public string? duration { get; set; }
  151. public string? schoolId { get; set; }
  152. public string? schoolName { get; set; }
  153. public string? scope { get; set; }
  154. public string? subjectId { get; set; }
  155. public string? subjectName { get; set; }
  156. public string? courseId { get; set; }
  157. public string? courseName { get; set; }
  158. public string? classId { get; set; }
  159. public string? className { get; set; }
  160. public string? gradeId { get; set; }
  161. public string? gradeName { get; set; }
  162. public string? teacherId { get; set; }
  163. public string? teacherName { get; set; }
  164. public long time { get; set; }
  165. public int memberCount { get; set; }
  166. }
  167. public class LessonStudent {
  168. public string? studentID { get; set; }
  169. public string? groupName { get; set; }
  170. public string? groupId { get; set; }
  171. /// <summary>
  172. /// 1开始,groupIndex=0 表示未分组
  173. /// </summary>
  174. public int groupIndex { get; set; }
  175. public int seatID { get; set; }
  176. public int studentIndex { get; set; }
  177. public string? studentName { get; set; }
  178. /// <summary>
  179. /// 学生类型 1 醍摩豆id, 2校内账号 ==对应字段 ies_Type //ID類型 1 tmdid,2 student 本地或動態班級的話會是0
  180. /// </summary>
  181. public int type { get; set; }
  182. /// <summary>
  183. /// 名单id
  184. /// </summary>
  185. public string? classId { get; set; }
  186. /// <summary>
  187. ///Uncall,//未點名
  188. ///Attended,//已出席
  189. ///Absent,//缺席
  190. ///DayOff,//請假
  191. ///Absent_Sick,//病假
  192. ///Absent_Personal,//事假
  193. ///Absent_Official,//公假
  194. /// </summary>
  195. public string? AttendState { get; set; }
  196. /// <summary>
  197. /// 个人积分
  198. /// </summary>
  199. public double score { get; set; }
  200. /// <summary>
  201. /// 小组积分
  202. /// </summary>
  203. public double groupScore { get; set; }
  204. /// <summary>
  205. /// 互动积分
  206. /// </summary>
  207. public double interactScore { get; set; }
  208. }
  209. }