Program.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. using HTEXLib.COMM.Helpers;
  2. using Newtonsoft.Json;
  3. using System.Security.Policy;
  4. using System.Text;
  5. using System.Web;
  6. using TEAMModelOS.SDK.Extension;
  7. using TEAMModelOS.SDK.Models;
  8. using TEAMModelOS.SDK.Models.Cosmos.OpenEntity;
  9. using TEAMModelOS.SDK.Models.Dtos;
  10. namespace TEAMModelOS.TEST
  11. {
  12. public class Program
  13. {
  14. static void Main(string[] args)
  15. {
  16. //
  17. var uri = HttpUtility.UrlDecode("https://teammodeltest.blob.core.chinacloudapi.cn/hbcn/art/e9a5ec36-7299-45dc-9517-7457960346c4/report/202106005.pdf");
  18. var paths = uri.Split("/art/");
  19. if (paths.Length == 2)
  20. {
  21. var ps = paths[1].Split("/");
  22. if (ps.Length == 3)
  23. {
  24. Uri uris = new Uri(paths[0]);
  25. // 获取URL的Segments属性,这是一个String数组,包含URL中的每个部分
  26. string[] segments = uris.Segments;
  27. string key = $"ArtPDF:{ps[0]}";
  28. // 确保segments数组至少有一个元素
  29. if (segments.Length > 0)
  30. {
  31. // 获取数组中的最后一个元素,即最后一个'/'之后的部分
  32. string lastSegment = segments[segments.Length - 1];
  33. key = $"ArtPDF:{ps[0]}:{lastSegment}";
  34. }
  35. }
  36. }
  37. List<Dictionary<string, object>> jsonData = new List<Dictionary<string, object>>
  38. {
  39. new Dictionary<string, object> { { "user", "A" }, { "time", 1711414573130 } },
  40. new Dictionary<string, object> { { "user", "A" }, { "time", 1711414673130 } },
  41. new Dictionary<string, object> { { "user", "A" }, { "time", 1711415673130 } },
  42. new Dictionary<string, object> { { "user", "A" }, { "time", 1711435873130 } },
  43. new Dictionary<string, object> { { "user", "A" }, { "time", 1711436873130 } },
  44. new Dictionary<string, object> { { "user", "A" }, { "time", 1711455873130 } },
  45. new Dictionary<string, object> { { "user", "A" }, { "time", 1711495873130 } },
  46. new Dictionary<string, object> { { "user", "A" }, { "time", 1711495973130 } }
  47. };
  48. double totalDuration = GetUserDuration(jsonData);
  49. Console.WriteLine("用户使用时长: " + totalDuration + "小时");
  50. // 作品数据
  51. var works = new List<Work>
  52. {
  53. new Work { WorkId = "1", Subject = "语文" },
  54. new Work { WorkId = "2", Subject = "数学" },
  55. new Work { WorkId = "3", Subject = "英语" },
  56. new Work { WorkId = "4", Subject = "数学" },
  57. new Work { WorkId = "5", Subject = "英语" },
  58. new Work { WorkId = "6", Subject = "语文" },
  59. new Work { WorkId = "7", Subject = "语文" }
  60. };
  61. // 专家数据
  62. var experts = new List<ExpertS>
  63. {
  64. //new ExpertS { ExpertId = "a", Subjects = new List<string> { "语文", "数学" ,"英语"} },
  65. new ExpertS { ExpertId = "b", Subjects = new List<string> { "数学" } },
  66. //new ExpertS { ExpertId = "c", Subjects = new List<string> { "英语", "英语" } },
  67. new ExpertS { ExpertId = "d", Subjects = new List<string> { "数学" } },
  68. new ExpertS { ExpertId = "e", Subjects = new List<string> { "英语", "数学" } },
  69. //new ExpertS { ExpertId = "f", Subjects = new List<string> { "语文" } }
  70. };
  71. // 分配作品给专家
  72. int N = 1; // 指定评审次数
  73. var assignments = AssignWorksToExperts(works, experts, N);
  74. // 输出结果
  75. foreach (var assignment in assignments)
  76. {
  77. Console.WriteLine($"WorkId: {assignment.WorkId}, ExpertId: {assignment.ExpertId}");
  78. }
  79. string path = "C:\\Users\\CrazyIter\\Downloads\\消费清单(2022-2023)\\bill";
  80. List<List<string>> inputArray = new List<List<string>>
  81. {
  82. new List<string> { "2", "11" },
  83. new List<string> { "1", "22" },
  84. new List<string> { "1", "11", "111" },
  85. new List<string> { "2", "22", "222" },
  86. new List<string> { "1", "11" },
  87. new List<string> { "1", "11" },
  88. new List<string> { "1" },
  89. new List<string> { "2", "22", "222" },
  90. new List<string> { "2", "22" } ,
  91. };
  92. // 转换为层级结构
  93. List<ClassifiedItem> result = ClassifyHierarchy(inputArray);
  94. // 输出结果
  95. foreach (var item in result)
  96. {
  97. Console.WriteLine($"id: {item.Id}, count: {item.Count}, pid: {item.Pid}");
  98. }
  99. }
  100. static double GetUserDuration(List<Dictionary<string, object>> jsonData)
  101. {
  102. double totalDuration = 0;
  103. // DateTime lastTime = DateTimeOffset.FromUnixTimeMilliseconds((long)jsonData[0]["time"]).UtcDateTime;
  104. long ltime = (long)jsonData[0]["time"];
  105. for (int i = 1; i < jsonData.Count; i++)
  106. {
  107. long ctime = (long)jsonData[i]["time"];
  108. //DateTime currentTime = DateTimeOffset.FromUnixTimeMilliseconds((long)jsonData[i]["time"]).UtcDateTime;
  109. long timeDifference = ctime - ltime;
  110. if (timeDifference < 3600000)
  111. {
  112. totalDuration += timeDifference;
  113. }
  114. else
  115. {
  116. totalDuration += 1;
  117. }
  118. ltime = ctime;
  119. }
  120. return totalDuration;
  121. }
  122. static List<Assignment> AssignWorksToExperts(List<Work> works, List<ExpertS> experts, int N)
  123. {
  124. var assignments = new List<Assignment>();
  125. foreach (var work in works)
  126. {
  127. for (int i = 0; i < N; i++)
  128. {
  129. var availableExperts = experts
  130. .OrderBy(expert => assignments.Count(a => a.ExpertId == expert.ExpertId))
  131. .Where(expert => expert.Subjects.Contains(work.Subject) && !assignments.Any(a => a.WorkId == work.WorkId && a.ExpertId == expert.ExpertId))
  132. .ToList();
  133. if (availableExperts.Count > 0)
  134. {
  135. var selectedExpert = availableExperts.First();
  136. assignments.Add(new Assignment { WorkId = work.WorkId, ExpertId = selectedExpert.ExpertId });
  137. }
  138. else
  139. {
  140. Console.WriteLine($"No available expert for WorkId {work.WorkId} and subject {work.Subject} in attempt {i + 1}.");
  141. break;
  142. }
  143. }
  144. }
  145. return assignments;
  146. }
  147. static List<ClassifiedItem> ClassifyHierarchy(List<List<string>> inputArray)
  148. {
  149. Dictionary<string, int> hierarchyCount = new Dictionary<string, int>();
  150. List<ClassifiedItem> result = new List<ClassifiedItem>();
  151. foreach (var list in inputArray)
  152. {
  153. for (int i = 0; i < list.Count; i++)
  154. {
  155. string currentId = list[i];
  156. string parentId = (i > 0) ? list[i - 1] : null;
  157. string hierarchyKey = $"{currentId}|{parentId}";
  158. if (hierarchyCount.ContainsKey(hierarchyKey))
  159. {
  160. hierarchyCount[hierarchyKey]++;
  161. }
  162. else
  163. {
  164. hierarchyCount[hierarchyKey] = 1;
  165. }
  166. var item = result.Find(item => item.Id == currentId && item.Pid == parentId);
  167. if (item== null )
  168. {
  169. result.Add(new ClassifiedItem
  170. {
  171. Id = currentId,
  172. Pid = parentId,
  173. Count = 0
  174. });
  175. }
  176. }
  177. }
  178. foreach (var item in result)
  179. {
  180. string hierarchyKey = $"{item.Id}|{item.Pid}";
  181. item.Count = hierarchyCount.ContainsKey(hierarchyKey) ? hierarchyCount[hierarchyKey] : 0;
  182. }
  183. return result;
  184. }
  185. class ClassifiedItem
  186. {
  187. public string Id { get; set; }
  188. public int Count { get; set; }
  189. public string Pid { get; set; }
  190. }
  191. }
  192. class Work
  193. {
  194. public string WorkId { get; set; }
  195. public string Subject { get; set; }
  196. }
  197. class ExpertS
  198. {
  199. public string ExpertId { get; set; }
  200. public List<string> Subjects { get; set; }
  201. }
  202. class Assignment
  203. {
  204. public string WorkId { get; set; }
  205. public string ExpertId { get; set; }
  206. }
  207. public class LessonBase {
  208. public string? id { get; set; }
  209. public string? duration { get; set; }
  210. public string? schoolId { get; set; }
  211. public string? schoolName { get; set; }
  212. public string? scope { get; set; }
  213. public string? subjectId { get; set; }
  214. public string? subjectName { get; set; }
  215. public string? courseId { get; set; }
  216. public string? courseName { get; set; }
  217. public string? classId { get; set; }
  218. public string? className { get; set; }
  219. public string? gradeId { get; set; }
  220. public string? gradeName { get; set; }
  221. public string? teacherId { get; set; }
  222. public string? teacherName { get; set; }
  223. public long time { get; set; }
  224. public int memberCount { get; set; }
  225. }
  226. public class LessonStudent {
  227. public string? studentID { get; set; }
  228. public string? groupName { get; set; }
  229. public string? groupId { get; set; }
  230. /// <summary>
  231. /// 1开始,groupIndex=0 表示未分组
  232. /// </summary>
  233. public int groupIndex { get; set; }
  234. public int seatID { get; set; }
  235. public int studentIndex { get; set; }
  236. public string? studentName { get; set; }
  237. /// <summary>
  238. /// 学生类型 1 醍摩豆id, 2校内账号 ==对应字段 ies_Type //ID類型 1 tmdid,2 student 本地或動態班級的話會是0
  239. /// </summary>
  240. public int type { get; set; }
  241. /// <summary>
  242. /// 名单id
  243. /// </summary>
  244. public string? classId { get; set; }
  245. /// <summary>
  246. ///Uncall,//未點名
  247. ///Attended,//已出席
  248. ///Absent,//缺席
  249. ///DayOff,//請假
  250. ///Absent_Sick,//病假
  251. ///Absent_Personal,//事假
  252. ///Absent_Official,//公假
  253. /// </summary>
  254. public string? AttendState { get; set; }
  255. /// <summary>
  256. /// 个人积分
  257. /// </summary>
  258. public double score { get; set; }
  259. /// <summary>
  260. /// 小组积分
  261. /// </summary>
  262. public double groupScore { get; set; }
  263. /// <summary>
  264. /// 互动积分
  265. /// </summary>
  266. public double interactScore { get; set; }
  267. }
  268. // 用于反序列化JSON数据的类
  269. public class UsageRecord
  270. {
  271. [JsonProperty("user")]
  272. public string user { get; set; }
  273. [JsonProperty("time")]
  274. public long time { get; set; }
  275. }
  276. }