public CourseDataForm(CourseData inputCourseData) { this.courseData = inputCourseData; InitializeComponent(); groupBox1 = new GroupBox() { Text = string.Empty, Location = new Point(50, 30), Size = new Size(650, 100), AutoSize = true, }; this.Controls.Add(groupBox1); groupBox2 = new GroupBox() { Text = string.Empty, Location = new Point(50, 170), Size = new Size(650, 100), AutoSize = true, }; this.Controls.Add(groupBox2); var courseNameLabel = new Label() { Text = courseData.Name.Replace("\"", ""), Font = new Font("微软雅黑", 18, FontStyle.Regular), Location = new Point(30, 30), AutoSize = true }; groupBox1.Controls.Add(courseNameLabel); var overallGPALabel = new Label() { Text = $"课程均绩/样本量:{courseData.OverallGPAOfThisCourse:F2}/{courseData.TotalSampleSize}", Font = new Font("微软雅黑", 12, FontStyle.Regular), Location = new Point(30, 90), AutoSize = true }; if (courseData.TotalSampleSize > 999) { overallGPALabel.Text = $"课程均绩/样本量:{courseData.OverallGPAOfThisCourse:F2}/999+"; } groupBox1.Controls.Add(overallGPALabel); DisplayResults(courseData.CourseTeachers); }
public void GetTeacherDataFromCsv(FileStream file) { TeacherData.totalTeacherList.Clear(); //读取前先清空当前已读取的内容 CourseData.courseDataList.Clear(); FacultyData.FacultyList.Clear(); using (StreamReader streamReader = new StreamReader(file, Encoding.Default)) { string teacherLine = string.Empty; while ((teacherLine = streamReader.ReadLine()) != null) { var Line = teacherLine.Split(','); TeacherData thisTeacher = new TeacherData() { Name = Line[0], ID = int.Parse(Line[1]), Url = Line[2], }; thisTeacher.Faculty = FacultyData.GetFaculty(thisTeacher, Line[3]); thisTeacher.Score = (Line[4] == "N/A") ? 0 : double.Parse(Line[4]); thisTeacher.CallNameRate = double.Parse(Line[5].Replace("%", "")) / 100.0; thisTeacher.VoteNum = (Line[6] == "<5") ? 0 : int.Parse(Line[6]); thisTeacher.CommentNum = (Line[7] == "<5") ? 0 : int.Parse(Line[7]); if (thisTeacher.VoteNum < 5) { thisTeacher.HasEnoughData = false; thisTeacher.CallNameState = TeacherData.CallName_enum.Unknown; } else if (thisTeacher.CallNameRate > 0.5) { thisTeacher.CallNameState = TeacherData.CallName_enum.Yes; } else if (thisTeacher.CallNameRate > 0.2) { thisTeacher.CallNameState = TeacherData.CallName_enum.Possible; } else { thisTeacher.CallNameState = TeacherData.CallName_enum.No; } var hisCourseList = new List <CourseData>(); double overallGPA_number; for (int i = 8; i < Line.Length - 2; i++) { string courseName; if ((courseName = Line[i]) == string.Empty) { break; } while (true) { i++; try { overallGPA_number = double.Parse(Line[i]); break; } catch { courseName += $",{Line[i]}"; } } i++; string overallGPASize_string = Line[i]; int overallGPASize_int = int.Parse(overallGPASize_string.Replace("+", "")); var thisCourseData = new CourseData() { Name = courseName, GPASampleSizeOfTeacher_string = overallGPASize_string, GPASampleSizeOfTeacher_int = overallGPASize_int, OverallGPAOfTeacher = overallGPA_number }; hisCourseList.Add(thisCourseData); var query = from c in CourseData.courseDataList//需要debug where c.Name == courseName select c; if (!query.Any()) { var courseData = new CourseData(); courseData.Name = courseName; courseData.CourseTeachers = new List <TeacherData>(); courseData.CourseTeachers.Add(thisTeacher); courseData.TotalGPA += overallGPA_number * overallGPASize_int; courseData.TotalSampleSize += overallGPASize_int; courseData.OverallGPAOfThisCourse = courseData.TotalGPA / courseData.TotalSampleSize; CourseData.courseDataList.Add(courseData); } else { foreach (var courseData in CourseData.courseDataList.Select(x => x).Where(x => x.Name == courseName)) { courseData.CourseTeachers.Add(thisTeacher); courseData.TotalGPA += overallGPA_number * overallGPASize_int; courseData.TotalSampleSize += overallGPASize_int; courseData.OverallGPAOfThisCourse = courseData.TotalGPA / courseData.TotalSampleSize; } } } thisTeacher.CourseList = hisCourseList; var commentString = streamReader.ReadLine(); var comments = commentString.Split(','); var count = comments.Count(); for (int i = 0; i < count - 1; i = i + 3) { thisTeacher.CommentList.Add(new CommentData() { Text = comments[i].Replace("&NewLine", Environment.NewLine), Vote = int.Parse(comments[i + 1]), Time = DateTime.Parse(comments[i + 2]) }); } TeacherData.totalTeacherList.Add(thisTeacher); } } }
private void DisplayResults(List <TeacherData> teacherList) { groupBox2.Size = new Size(650, 100); int i = 0; int step = 45; groupBox2.Controls.Add(new Label() { Text = "教师姓名", Font = new Font("微软雅黑", 11, FontStyle.Underline), Location = new Point(30, 30), AutoSize = true, }); var scoreLabel1 = new Label() { Text = "教师评分", Font = new Font("微软雅黑", 11, FontStyle.Underline), Location = new Point(250, 30), AutoSize = true, }; scoreLabel1.Click += (s, arg) => { groupBox2.Controls.Clear(); DisplayResults(teacherList.OrderByDescending(m => m.Score).ToList()); }; scoreLabel1.MouseEnter += (s, arg) => { scoreLabel1.BackColor = SystemColors.GradientInactiveCaption; }; scoreLabel1.MouseLeave += (s, arg) => { scoreLabel1.BackColor = SystemColors.Control; }; groupBox2.Controls.Add(scoreLabel1); var gpaLabel1 = new Label() { Text = "教师均绩", Font = new Font("微软雅黑", 11, FontStyle.Underline), Location = new Point(470, 30), AutoSize = true, }; gpaLabel1.Click += (s, arg) => { groupBox2.Controls.Clear(); DisplayResults(teacherList.OrderByDescending(m => m.TemporaryCourse.OverallGPAOfTeacher).ToList()); }; gpaLabel1.MouseEnter += (s, arg) => { gpaLabel1.BackColor = SystemColors.GradientInactiveCaption; }; gpaLabel1.MouseLeave += (s, arg) => { gpaLabel1.BackColor = SystemColors.Control; }; groupBox2.Controls.Add(gpaLabel1); foreach (TeacherData teacher in teacherList) { var teacherNameLabel = new Label() { Text = teacher.Name, Font = new Font("微软雅黑", 11, FontStyle.Regular), Location = new Point(30, 80 + i * step), AutoSize = true, }; CourseData selectedCourse = null; foreach (CourseData course in teacher.CourseList) { if (course.Name == courseData.Name) { teacher.TemporaryCourse = selectedCourse = course; break; } } teacherNameLabel.Click += (s, arg) => { new TeacherDataForm(teacher) { TopMost = true, StartPosition = FormStartPosition.CenterScreen, } .Show(); }; teacherNameLabel.MouseEnter += (s, arg) => { teacherNameLabel.BackColor = SystemColors.GradientInactiveCaption; }; teacherNameLabel.MouseLeave += (s, arg) => { teacherNameLabel.BackColor = SystemColors.Control; }; groupBox2.Controls.Add(teacherNameLabel); var scoreLabel = new Label() { Location = new Point(250, 80 + i * step), Text = teacher.ToString("Score"), Font = new Font("微软雅黑", 13), AutoSize = true, }; if (!teacher.HasEnoughData) { scoreLabel.ForeColor = Color.DarkGray; } else if (teacher.Score > 9) { scoreLabel.ForeColor = Color.Green; } else if (teacher.Score > 7.5) { scoreLabel.ForeColor = Color.Blue; } else if (teacher.Score > 6) { scoreLabel.ForeColor = Color.Goldenrod; } else if (teacher.Score > 4) { scoreLabel.ForeColor = Color.IndianRed; } else { scoreLabel.ForeColor = Color.Maroon; } groupBox2.Controls.Add(scoreLabel); var hisCourseGPALabel = new Label() { Text = $"{selectedCourse.OverallGPAOfTeacher:F2}/{selectedCourse.GPASampleSizeOfTeacher_string}", Font = new Font("微软雅黑", 13), Location = new Point(470, 80 + i * step), AutoSize = true }; if (selectedCourse.GPASampleSizeOfTeacher_int == 0 || selectedCourse.OverallGPAOfTeacher == 0) { hisCourseGPALabel.ForeColor = Color.DarkGray; } else if (selectedCourse.OverallGPAOfTeacher / courseData.OverallGPAOfThisCourse > 1.07) { hisCourseGPALabel.ForeColor = Color.Green; } else if (selectedCourse.OverallGPAOfTeacher / courseData.OverallGPAOfThisCourse > 0.93) { hisCourseGPALabel.ForeColor = Color.Goldenrod; } else { hisCourseGPALabel.ForeColor = Color.Maroon; } groupBox2.Controls.Add(hisCourseGPALabel); i++; } var emptyLabel = new Label() { Text = string.Empty, Location = new Point(80, 275 + i * step), AutoSize = true }; this.Controls.Add(emptyLabel); }
public void Analyze(CourseData course) { }
private void ListAllItems() { var score_string = teacherData.ToString("Score"); this.Text = $"{teacherData.Name}, 分数:{score_string}"; var groupBox1 = new GroupBox() { Text = string.Empty, Location = new Point(50, 30), Size = new Size(650, 100), AutoSize = true, }; this.Controls.Add(groupBox1); var nameLabel = new Label() { Text = teacherData.Name, Font = new Font("微软雅黑", 18, FontStyle.Regular), Location = new Point(30, 30), AutoSize = true }; groupBox1.Controls.Add(nameLabel); var facultyLabel = new Label() { Text = teacherData.Faculty.Name, Font = new Font("微软雅黑", 11, FontStyle.Regular), Location = new Point(35, 90), AutoSize = true }; groupBox1.Controls.Add(facultyLabel); var scoreLabel = new Label() { Text = $"分数:{teacherData.ToString("Score")}", Font = new Font("微软雅黑", 11, FontStyle.Regular), Location = new Point(35, 120), AutoSize = true }; groupBox1.Controls.Add(scoreLabel); var hotLabel = new Label() { Text = $"热度:{teacherData.ToString("HotNum")}", Font = new Font("微软雅黑", 11, FontStyle.Regular), Location = new Point(400, 90), AutoSize = true }; groupBox1.Controls.Add(hotLabel); var callNameRateLabel = new Label() { Text = $"点名率:{teacherData.ToString("CallNameRate")}", Font = new Font("微软雅黑", 11, FontStyle.Regular), Location = new Point(35, 150), AutoSize = true }; groupBox1.Controls.Add(callNameRateLabel); var groupBox2 = new GroupBox() { Text = string.Empty, Location = new Point(50, 230), Size = new Size(650, 100), AutoSize = true, }; this.Controls.Add(groupBox2); var courseLabel = new Label() { Text = "课程名称(点击查看详情)", Font = new Font("微软雅黑", 12, FontStyle.Underline), Location = new Point(35, 20), AutoSize = true }; groupBox2.Controls.Add(courseLabel); var courseGPALabel = new Label() { Text = $"平均绩点/样本量", Font = new Font("微软雅黑", 12, FontStyle.Underline), Location = new Point(400, 20), AutoSize = true }; groupBox2.Controls.Add(courseGPALabel); int i = 0; int step = 45; if (teacherData.CourseList.Count == 0) { var noCourseLabel = new Label() { Text = "暂无这位老师的授课数据", Font = new Font("微软雅黑", 11, FontStyle.Regular), Location = new Point(35, 70), AutoSize = true }; groupBox2.Controls.Add(noCourseLabel); } else { foreach (CourseData thisCourse in teacherData.CourseList) { var thisCourseLabel = new Label() { Text = thisCourse.Name.Replace("\"", ""), Font = new Font("微软雅黑", 11, FontStyle.Regular), Location = new Point(35, 70 + i * step), AutoSize = true }; CourseData selectedCourse = null; foreach (CourseData course in CourseData.courseDataList) { if (course.Name.Replace("\"", "") == thisCourseLabel.Text) { selectedCourse = course; break; } } thisCourseLabel.Click += (s, arg) => { if (selectedCourse != null) { new CourseDataForm(selectedCourse) { TopMost = true, StartPosition = FormStartPosition.CenterScreen, } .Show(); } }; thisCourseLabel.MouseEnter += (s, arg) => { thisCourseLabel.BackColor = SystemColors.GradientInactiveCaption; }; thisCourseLabel.MouseLeave += (s, arg) => { thisCourseLabel.BackColor = SystemColors.Control; }; groupBox2.Controls.Add(thisCourseLabel); var thisCourseGPALabel = new Label() { Text = $"{thisCourse.OverallGPAOfTeacher:F2}/{thisCourse.GPASampleSizeOfTeacher_int}", Font = new Font("微软雅黑", 11, FontStyle.Regular), Location = new Point(400, 70 + i * step), AutoSize = true }; if (thisCourse.GPASampleSizeOfTeacher_int == 0 || thisCourse.OverallGPAOfTeacher == 0) { thisCourseGPALabel.ForeColor = Color.DarkGray; } else if (thisCourse.OverallGPAOfTeacher > 4.5) { thisCourseGPALabel.ForeColor = Color.Green; } else if (thisCourse.OverallGPAOfTeacher > 4) { thisCourseGPALabel.ForeColor = Color.Blue; } else if (thisCourse.OverallGPAOfTeacher > 3.5) { thisCourseGPALabel.ForeColor = Color.Goldenrod; } else if (thisCourse.OverallGPAOfTeacher > 3) { thisCourseGPALabel.ForeColor = Color.IndianRed; } else { thisCourseGPALabel.ForeColor = Color.Maroon; } groupBox2.Controls.Add(thisCourseGPALabel); i++; if (thisCourseLabel.Text.Length > 17) { var nameLabel2 = new Label() { Location = new Point(35, 70 + i * step), Text = thisCourse.Name.Replace("\"", "").Substring(17), Font = new Font("微软雅黑", 11), AutoSize = true }; nameLabel2.Click += (s, arg) => { new CourseDataForm(thisCourse) { TopMost = true, StartPosition = FormStartPosition.CenterScreen } .Show(); }; nameLabel2.MouseEnter += (s, arg) => { nameLabel2.BackColor = SystemColors.GradientInactiveCaption; }; nameLabel2.MouseLeave += (s, arg) => { nameLabel2.BackColor = SystemColors.Control; }; groupBox2.Controls.Add(nameLabel2); thisCourseLabel.Text = thisCourseLabel.Text.Substring(0, 17); i++; } } } var emptyLabel = new Label() { Text = string.Empty, Location = new Point(450, 290 + i * step + 25), AutoSize = true }; this.Controls.Add(emptyLabel); }