Skip to content

Commit

Permalink
Merge pull request #29 from ucdavis/feature/StudentClassYear
Browse files Browse the repository at this point in the history
Feature/student class year
  • Loading branch information
bsedwards committed Aug 12, 2024
2 parents 720fec4 + db3788f commit 0713ce1
Show file tree
Hide file tree
Showing 12 changed files with 562 additions and 222 deletions.
6 changes: 5 additions & 1 deletion web/Areas/Computing/Controllers/PersonController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@ public PersonController(VIPERContext context, IHttpClientFactory factory)
}

[HttpGet]
public async Task<ActionResult<List<PersonSimple>>> GetPeople(bool? active = null)
public async Task<ActionResult<List<PersonSimple>>> GetPeople(bool? active = null, string? name = null)
{
var people = context.People
.AsQueryable();
if (active != null)
{
people = people.Where(p => p.Current == 1 || p.Future == 1);
}
if(name != null)
{
people = people.Where(p => p.FirstName.Contains(name) || p.LastName.Contains(name));
}
return await people
.OrderBy(p => p.LastName)
.ThenBy(p => p.FirstName)
Expand Down
34 changes: 19 additions & 15 deletions web/Areas/Students/Controller/DvmController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,17 @@ public DvmStudentsController(VIPERContext context, RAPSContext rapsContext)
}

/// <summary>
/// Get all student class years records for a given class year. Returns students with the class year as their active year only.
/// Get a single student
/// </summary>
/// <param name="classYear"></param>
/// <param name="personId"></param>
/// <returns></returns>
[HttpGet("byClassYear/{classYear}")]
[Permission(Allow = "SVMSecure.SIS.AllStudents")]
public async Task<ActionResult<IEnumerable<StudentClassYear>>> GetDvmStudentGradYears(int classYear)
[HttpGet("{personId}")]
[Permission(Allow ="SVMSecure.Students")]
public async Task<ActionResult<Models.Student>> GetDvmStudent(int personId)
{
//get students with all grad years
var students = context.StudentClassYears
.Where(s => s.ClassYear == classYear && s.Active)
.OrderBy(s => s.Student == null ? "" : s.Student.LastName)
.ThenBy(s => s.Student == null ? "" : s.Student.FirstName);

return await students.ToListAsync();
}
var student = await studentList.GetStudent(personId);
return student == null ? NotFound() : student;
}

/// <summary>
/// Get students by term and class level. Uses AAUD student info table, which is driven by registration data and exceptions.
Expand All @@ -82,6 +77,15 @@ public async Task<ActionResult<IEnumerable<StudentClassYear>>> GetDvmStudentGrad
return await studentList.GetStudentsByTermCodeAndClassLevel(termCode, classLevel);
}

[HttpGet("classYearReport")]
[Permission(Allow = "SVMSecure.SIS.AllStudents")]
public async Task<ActionResult<List<StudentClassYearProblem>>> ClassYearReport(int? classYear)
{
var problems = await studentList.GetStudentClassYearProblems(classYear);
return problems;
}


/// <summary>
/// Import the listed people into a class year. Must be their first class year.
/// </summary>
Expand Down Expand Up @@ -262,10 +266,10 @@ public async Task<ActionResult<List<int>>> GetClassYears(bool activeOnly = true,
{
var termCodeService = new TermCodeService(context);
List<int> activeClassYears = (await termCodeService.GetActiveClassYears((await termCodeService.GetActiveTerm()).TermCode));
if(!activeOnly)
if (!activeOnly)
{
var minCY = activeClassYears[0];
for(var i = minCY - 1; i >= (minClassYear ?? minCY - 10); i--)
for (var i = minCY - 1; i >= (minClassYear ?? minCY - 10); i--)
{
activeClassYears = activeClassYears.Prepend(i).ToList();
}
Expand Down
26 changes: 18 additions & 8 deletions web/Areas/Students/Controller/StudentsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.EntityFrameworkCore;
using Polly;
using Viper.Areas.CMS.Data;
using Viper.Areas.Curriculum.Services;
using Viper.Areas.Students.Services;
using Viper.Classes;
using Viper.Classes.SQLContext;
using Web.Authorization;
Expand Down Expand Up @@ -33,18 +37,17 @@ public override async Task OnActionExecutionAsync(ActionExecutingContext context
ActionExecutionDelegate next)
{
await base.OnActionExecutionAsync(context, next);
await next();
ViewData["ViperLeftNav"] = Nav();
}

public NavMenu Nav()
{
var nav = new List<NavMenuItem>
var menu = new LeftNavMenu().GetLeftNavMenus(friendlyName: "viper-students")?.FirstOrDefault();
if (menu != null)
{
new() { MenuItemText = "Home", MenuItemURL = "Home" }
};

return new NavMenu("Student Resources", nav);
ConvertNavLinksForDevelopment(menu);
}
return menu ?? new NavMenu("", new List<NavMenuItem>());
}

[Route("/[area]")]
Expand All @@ -54,11 +57,18 @@ public IActionResult Index()
}

[Route("/[area]/[action]")]
public IActionResult StudentClassYear(string? import = null, int? classYear= null)
public IActionResult StudentClassYear(string? import = null, int? classYear = null)
{
return import != null
return import != null
? View("~/Areas/Students/Views/StudentClassYearImport.cshtml")
: View("~/Areas/Students/Views/StudentClassYear.cshtml");
}

[Route("/[area]/[action]")]
public IActionResult StudentClassYearreport()
{
return View("~/Areas/Students/Views/StudentClassYearReport.cshtml");
}

}
}
20 changes: 19 additions & 1 deletion web/Areas/Students/Models/Student.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public class Student
public string FirstName { get; set; } = null!;
public string? MiddleName { get; set; }
public string FullName { get; set; } = null!;
public string? ClassLevel { get; set; } = null!;
public string? ClassLevel { get; set; }
public int? TermCode { get; set; }
public int? ClassYear { get; set; }
public string Email => MailId + "@ucdavis.edu";
public bool CurrentClassYear { get; set; }
Expand All @@ -24,6 +25,22 @@ public Student()

}

public Student(Student s)
{
PersonId = s.PersonId;
MailId = s.MailId;
LastName = s.LastName;
FirstName = s.FirstName;
MiddleName = s.MiddleName;
FullName = s.FullName;
ClassLevel = s.ClassLevel;
TermCode = s.TermCode;
ClassYear = s.ClassYear;
CurrentClassYear = s.CurrentClassYear;
Active = s.Active;
ClassYears = s.ClassYears;
}

public Student(Person p)
{
PersonId = p.PersonId;
Expand All @@ -33,6 +50,7 @@ public Student(Person p)
MiddleName = p.MiddleName;
FullName = p.FullName;
ClassLevel = p.StudentInfo?.ClassLevel;
TermCode = p.StudentInfo?.TermCode;
Active = p.CurrentStudent || p.FutureStudent;
CurrentClassYear = false;
}
Expand Down
10 changes: 10 additions & 0 deletions web/Areas/Students/Models/StudentClassYearProblem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Viper.Areas.Students.Models
{
public class StudentClassYearProblem : Student
{
public int? ExpectedClassYear { get; set; }
public string Problems { get; set; } = string.Empty;

public StudentClassYearProblem(Student s) : base(s) { }
}
}
65 changes: 60 additions & 5 deletions web/Areas/Students/Services/GradYearClassLevel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Identity.Client;
using Microsoft.AspNetCore.Connections.Features;
using Microsoft.Identity.Client;

namespace Viper.Areas.Students.Services
{
Expand Down Expand Up @@ -29,14 +30,68 @@ public class GradYearClassLevel
//202309: V1 2027 V4 2024
//202402: V1 2027 V4 2024
//202404: V4 2025
if(term == 2 || term == 4 || term == 9)
if (term == 2 || term == 4 || term == 9)
{
return year + (5 - classYear) - (term == 2 ? 1 : 0);
}
}
}
return null;
}

/// <summary>
/// Get the "best" termcode and class level for a grad year.
/// For V1-V3, use the current term if it's fall or spring. If it's summer, use the upcoming fall term.
/// For V4, use the current term.
/// If the grad year is in the past, use the spring term they graduated.
/// </summary>
/// <param name="gradYear"></param>
/// <param name="currentTerm"></param>
/// <returns></returns>
static public Tuple<int, string> GetTermCodeAndClassLevelForGradYear(int gradYear, int currentTerm)
{
int termYear = currentTerm / 100;
int termPart = currentTerm % 100;
if (gradYear <= termYear)
{
return Tuple.Create((termYear * 100) + 2, "V4");
}

var termAndClassLevel = Tuple.Create(currentTerm, "");
switch (termPart)
{
case 2:
termAndClassLevel = Tuple.Create(currentTerm, "V" + (4 - (gradYear - termYear)).ToString());
break;
case 9:
termAndClassLevel = Tuple.Create(currentTerm, "V" + (5 - (gradYear - termYear)).ToString());
break;
case 4:
if (gradYear - termYear == 1)
{
termAndClassLevel = Tuple.Create(currentTerm, "V4");
}
else
{
termAndClassLevel = Tuple.Create((termYear * 100) + 9, "V" + (5 - (gradYear - termYear)).ToString());
}
break;
}

if (ValidClassYears.Contains(termAndClassLevel.Item2))
{
return termAndClassLevel;
}

//grad year is a future class level, they will enter fall of grad year - 4
return Tuple.Create(((gradYear - 4) * 100) + 9, "V1");
}

/// <summary>
/// Get the DVM class level (V1-V4) for the given grad year and the current term code
/// </summary>
/// <param name="gradYear"></param>
/// <param name="termCode"></param>
/// <returns></returns>
static public string GetDvmClassLevel(int gradYear, int termCode)
{
var classLevel = "";
Expand All @@ -60,7 +115,7 @@ static public string GetDvmClassLevel(int gradYear, int termCode)
//Summer and Fall - if they graduate next year, V4, if they graduate two years from now, V3, etc.}
else
{
switch(gradYear - currentYear)
switch (gradYear - currentYear)
{

case 1: classLevel = "V4"; break;
Expand All @@ -70,7 +125,7 @@ static public string GetDvmClassLevel(int gradYear, int termCode)
default: break;
}
}

return classLevel;
}

Expand Down
Loading

0 comments on commit 0713ce1

Please sign in to comment.