123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- using HTEXLib.COMM.Helpers;
- using System.Text;
- using TEAMModelOS.SDK.Extension;
- using TEAMModelOS.SDK.Models;
- using TEAMModelOS.SDK.Models.Cosmos.OpenEntity;
- using TEAMModelOS.SDK.Models.Dtos;
- namespace TEAMModelOS.TEST
- {
- public class Program
- {
- static void Main(string[] args)
- {
- //List<string> groupNames = new List<string>() { "組別4", "組別2", "組別3", "組別4", "組別1", "組別1" };
- //groupNames =groupNames.OrderBy(x => x).ToList();
- //var jsonAuth = System.IO.File.ReadAllText("C:\\Users\\CrazyIter\\Downloads\\492266088181141504\\ActivityInfo.json", Encoding.UTF8);
- //var jsonData = jsonAuth.ToObject<LessonRecordActivityInfo>();
- string path = "C:\\Users\\CrazyIter\\Downloads\\消费清单(2022-2023)\\bill";
- List<List<string>> inputArray = new List<List<string>>
- {
- new List<string> { "2", "11" },
- new List<string> { "1", "22" },
- new List<string> { "1", "11", "111" },
- new List<string> { "2", "22", "222" },
- new List<string> { "1", "11" },
- new List<string> { "1", "11" },
- new List<string> { "1" },
- new List<string> { "2", "22", "222" },
- new List<string> { "2", "22" } ,
- };
- // 转换为层级结构
- List<ClassifiedItem> result = ClassifyHierarchy(inputArray);
- // 输出结果
- foreach (var item in result)
- {
- Console.WriteLine($"id: {item.Id}, count: {item.Count}, pid: {item.Pid}");
- }
- }
- static List<ClassifiedItem> ClassifyHierarchy(List<List<string>> inputArray)
- {
- Dictionary<string, int> hierarchyCount = new Dictionary<string, int>();
- List<ClassifiedItem> result = new List<ClassifiedItem>();
- foreach (var list in inputArray)
- {
- for (int i = 0; i < list.Count; i++)
- {
- string currentId = list[i];
- string parentId = (i > 0) ? list[i - 1] : null;
- string hierarchyKey = $"{currentId}|{parentId}";
- if (hierarchyCount.ContainsKey(hierarchyKey))
- {
- hierarchyCount[hierarchyKey]++;
- }
- else
- {
- hierarchyCount[hierarchyKey] = 1;
- }
- var item = result.Find(item => item.Id == currentId && item.Pid == parentId);
- if (item== null )
- {
- result.Add(new ClassifiedItem
- {
- Id = currentId,
- Pid = parentId,
- Count = 0
- });
- }
- }
- }
- foreach (var item in result)
- {
- string hierarchyKey = $"{item.Id}|{item.Pid}";
- item.Count = hierarchyCount.ContainsKey(hierarchyKey) ? hierarchyCount[hierarchyKey] : 0;
- }
- return result;
- }
- class ClassifiedItem
- {
- public string Id { get; set; }
- public int Count { get; set; }
- public string Pid { get; set; }
- }
- }
- public class LessonBase {
- public string? id { get; set; }
- public string? duration { get; set; }
- public string? schoolId { get; set; }
- public string? schoolName { get; set; }
- public string? scope { get; set; }
- public string? subjectId { get; set; }
- public string? subjectName { get; set; }
- public string? courseId { get; set; }
- public string? courseName { get; set; }
- public string? classId { get; set; }
- public string? className { get; set; }
- public string? gradeId { get; set; }
- public string? gradeName { get; set; }
- public string? teacherId { get; set; }
- public string? teacherName { get; set; }
- public long time { get; set; }
- public int memberCount { get; set; }
- }
- public class LessonStudent {
- public string? studentID { get; set; }
- public string? groupName { get; set; }
- public string? groupId { get; set; }
- /// <summary>
- /// 1开始,groupIndex=0 表示未分组
- /// </summary>
- public int groupIndex { get; set; }
- public int seatID { get; set; }
- public int studentIndex { get; set; }
- public string? studentName { get; set; }
- /// <summary>
- /// 学生类型 1 醍摩豆id, 2校内账号 ==对应字段 ies_Type //ID類型 1 tmdid,2 student 本地或動態班級的話會是0
- /// </summary>
- public int type { get; set; }
- /// <summary>
- /// 名单id
- /// </summary>
- public string? classId { get; set; }
- /// <summary>
- ///Uncall,//未點名
- ///Attended,//已出席
- ///Absent,//缺席
- ///DayOff,//請假
- ///Absent_Sick,//病假
- ///Absent_Personal,//事假
- ///Absent_Official,//公假
- /// </summary>
- public string? AttendState { get; set; }
- /// <summary>
- /// 个人积分
- /// </summary>
- public double score { get; set; }
- /// <summary>
- /// 小组积分
- /// </summary>
- public double groupScore { get; set; }
- /// <summary>
- /// 互动积分
- /// </summary>
- public double interactScore { get; set; }
- }
- }
|