public async Task <CourseReport> GetStatisticsForCourse(Guid courseId) { var course = await CourseReadonlyDbContext.Courses.Include(o => o.UserCourses).ThenInclude(u => u.User) .FirstOrDefaultAsync(c => c.CourseId == courseId); CourseReport result = null; if (course != null) { int userCount = course.UserCourses?.Count() ?? 0; result = new CourseReport() { CourseId = course.CourseId, CourseName = course.CourseName, TotalCapacity = course.TotalCapacity, CurrentNumberOfStudents = userCount, MinimumAge = userCount == 0?0:course.UserCourses.Min(o => o.User.Age), MaximumAge = userCount == 0 ? 0 : course.UserCourses.Max(o => o.User.Age), AverageAge = userCount == 0 ? 0 : course.UserCourses.Average(o => o.User.Age), TeacherId = course.TeacherUserId, StudentList = course.UserCourses.Select(o => o.User.Name) }; } return(result); }
public void SaveToFile(string directoryPath, string fileName, CourseReport report) { if (!Directory.Exists(directoryPath)) { Directory.CreateDirectory(directoryPath); } File.WriteAllText(Path.Combine(directoryPath, fileName), report.ToString()); }
public ActionResult AdminCourseReport() { CourseReport courseReport = new CourseReport { courseList = db.Course.ToList() }; return(View(courseReport)); }
public ActionResult CourseReports(int courseID) { List <Enrollment> enrollment = db.Enrollments.Where(c => c.CourseID == courseID).ToList(); CourseReport courseReport = new CourseReport { selectedCourse = db.Course.Find(courseID), NumOfStudents = enrollment.Count, enrollments = enrollment }; return(View(courseReport)); }
private static void SRPExercise() { var report = new CourseReport(); report.AddEntry(new CourseReportEntry { Name = "Patrones de diseño", Students = 1000, Rating = 5 }); report.AddEntry(new CourseReportEntry { Name = "Flutter", Students = 1900, Rating = 4.5 }); Console.WriteLine(report.ToString()); var saver = new FileSaver(); saver.SaveToFile(@"Reports", "WorkReport.txt", report); }
static void Main(string[] args) { var report = new CourseReport(); var fileSaver = new FileSaver(); report.AddEntry(new CourseReportEntry() { Name = "Arlington", Rating = 3, Students = 20 }); report.AddEntry(new CourseReportEntry() { Name = "Jose", Rating = 2, Students = 20 }); Console.WriteLine(report.ToString()); fileSaver.SaveToFile(@"Reports", "ResultReport.txt", report); }
public IActionResult Upload(CourseReport report) { var courseUpload = courseUploadBll.GetAll().FirstOrDefault(x => x.CourseId == report.CourseId); if (courseUpload != null) { return(RedirectToAction("Course", new { id = courseUpload.CourseId })); } else { courseUploadBll.Add(new CourseUpload() { CourseId = report.CourseId, CSVData = report.CsvData }); return(Ok()); } }
public List <CourseReport> GetReportForCourse(SystemCourse systemCourse, Week[] weeks) { var reports = new List <CourseReport>(); foreach (var group in systemCourse.Groups) { Console.WriteLine($"Generating report for the course '{systemCourse.Name}-{group}'"); var report = new CourseReport($" {systemCourse.Name}-{group}"); this.webDriver.NavigateTo(systemCourse.BaseUrl); this.webDriver.Sleep(300); this.webDriver.TrySwitchToFrame("//iframe[@id='main_frame']"); this.webDriver.Sleep(300); var myCourses = this.webDriver.GetClickableElement("//ul[@id='vhs_navigation']/li/a[text()='Meine Kurse']"); myCourses.Click(); var course = this.webDriver.GetClickableElement($"//table[@id='meine_kurse']//a[text()='{group}']"); course.Click(); var progressOverview = this.webDriver.GetClickableElement("//a[text()='Lernende und Lernstände anzeigen']"); progressOverview.Click(); var students = this.webDriver.GetVisibleElements("//table[@class='table_list space']/tbody/child::tr"); var tmpStudentList = new List <(Student, string)>(); foreach (var studentRow in students) { var firstName = studentRow.FindElement(By.ClassName("c_vorname")).Text; var lastName = studentRow.FindElement(By.ClassName("c_nachname")).Text; var link = studentRow.FindElement(By.XPath(".//img[1]")); var url = $"https://{link.GetAttribute("src").Substring(8, 2)}.vhs-lernportal.de/wws/9.php#/wws/{link.GetAttribute("data-href")}"; tmpStudentList.Add((new Student(firstName, lastName, weeks), url)); } foreach (var studentWrapper in tmpStudentList) { var student = studentWrapper.Item1; Console.Write($"[{(tmpStudentList.IndexOf(studentWrapper) + 1) * 100 / tmpStudentList.Count } %] Generating the report for '{student.FirstName} {student.LastName}' "); this.webDriver.NavigateTo(studentWrapper.Item2); this.webDriver.TrySwitchToFrame("//iframe[@id='main_frame']"); this.webDriver.Sleep(500); var lectureRows = this.webDriver.GetVisibleElements("(//table[@class='table_list space'])[2]/tbody/child::tr"); var lectureUrls = lectureRows .Where(lr => !string.IsNullOrWhiteSpace(lr.FindElement(By.XPath(".//td[2]")).Text)) .Select(lr => lr.FindElement(By.XPath(".//a[1]")).GetAttribute("href")).ToList(); var assignedExercisesUrl = this.webDriver.GetClickableElement("//a[text()='Zugewiesene Übungen']") .GetAttribute("href"); var assignedCompletedExercisesUrl = this.webDriver .GetClickableElement("//a[text()='Abgeschlossene zugewiesene Übungen']") .GetAttribute("href"); foreach (var lecture in lectureUrls) { this.webDriver.NavigateTo(lecture); this.webDriver.TrySwitchToFrame("//iframe[@id='main_frame']"); this.webDriver.Sleep(500); var exercises = this.GetExercisesFromTable(3); this.UpdateStudentReport(ref student, exercises); } this.UpdateStudentReport(ref student, this.LoadExercises(assignedExercisesUrl)); this.UpdateStudentReport(ref student, this.LoadExercises(assignedCompletedExercisesUrl)); report.Students.Add(student); Console.WriteLine(); } reports.Add(report); } return(reports); }