Skip to content
Snippets Groups Projects
Commit daa70641 authored by Louis Guo's avatar Louis Guo
Browse files

[WIP][Frontend][Top][Refacto]

Removed commented code and changed assgnment to assignment in the mode,
controler and tests
parent ac44650e
Branches
Tags
No related merge requests found
...@@ -8,8 +8,8 @@ namespace CSAMS.APIModels ...@@ -8,8 +8,8 @@ namespace CSAMS.APIModels
public class TopModel : IAPIModel public class TopModel : IAPIModel
{ {
public float Grade { get; set; } public float Grade { get; set; }
public string AssingmentName { get; set; } public string AssignmentName { get; set; }
public int AssingmentID { get; set; } public int AssignmentID { get; set; }
public int ReviewerID { get; set; } public int ReviewerID { get; set; }
...@@ -18,10 +18,10 @@ namespace CSAMS.APIModels ...@@ -18,10 +18,10 @@ namespace CSAMS.APIModels
{ {
var otherProject = other as TopModel; var otherProject = other as TopModel;
return (Grade == otherProject.Grade && return (Grade == otherProject.Grade &&
AssingmentName == otherProject.AssingmentName && AssignmentName == otherProject.AssignmentName &&
type == otherProject.type && type == otherProject.type &&
ReviewerID==otherProject.ReviewerID&& ReviewerID==otherProject.ReviewerID&&
AssingmentID == otherProject.AssingmentID); AssignmentID == otherProject.AssignmentID);
} }
} }
} }
...@@ -27,110 +27,8 @@ namespace CSAMS.Controllers ...@@ -27,110 +27,8 @@ namespace CSAMS.Controllers
} }
/*
[HttpGet("Top/{N}/{Type}/{IsProject}")]
public async Task<ActionResult<TopModel[]>> GetTopReviews(int N, string Type, Boolean IsProject)
{
// var test = await _context.Assignments.ToArrayAsync();
var fields = await _context.Fields.ToArrayAsync();
// TopModel[][] child = new TopModel[test.ToList().Count][];
Console.WriteLine($"N is {N} and Type is {Type}");
var t = _context.UserReviews.Include(r => r.Review).Include(r => r.Assignment)
.AsEnumerable()
// .GroupBy(r => r.AssignmentID)
// .Select(r => TopProjects(r.ToArray(), fields, IsProject))
.Where(p => p != null)
.ToArray();
if (IsProject == true)
{
if (Type == "Top")
{
return t
.GroupBy(r => r.AssignmentID)
.Select(r => TopProjects(r.ToArray(), fields, IsProject,0))
.Where(r => r != null)
.OrderByDescending(p => p.Grade)
.Take(N)
.ToArray();
;
}
else if (Type == "Bottom")
{
Console.WriteLine(t.Length);
var x = t
.GroupBy(r => r.AssignmentID)
.Select(r => TopProjects(r.ToArray(), fields, IsProject, 0))
.Where(r => r != null)
.OrderBy(p => p.Grade)
.Take(N)
.ToArray();
return x;
}
else
{
return t
.GroupBy(r => r.AssignmentID)
.Select(r => TopProjects(r.ToArray(), fields, IsProject, 0))
.Where(r => r != null)
.Take(2)
.ToArray();
;
}
}
else////////////////////////////
{
var average = GetMiddle(_context.UserReviews.Include(r => r.Review).ToArray(), fields);
if (Type == "Top")
{
return t
.GroupBy(r => r.UserReviewer)
.Select(r => TopProjects(r.ToArray(), fields, IsProject, average))
.Where(r => r != null)
.OrderBy(p=>p.Grade)
.Take(N)
.ToArray();
;
}
else if (Type == "Bottom")
{
return t
.GroupBy(r => r.UserReviewer)
.Select(r => TopProjects(r.ToArray(), fields, IsProject, average))
.Where(r => r != null)
.OrderByDescending(p => p.Grade)
.Take(N)
.ToArray();
}
else
{
return t
.GroupBy(r => r.ReviewID)
.Select(r => TopProjects(r.ToArray(), fields, IsProject, average))
.Where(r => r != null)
.Take(2)
.ToArray();
;
}
}
}
*/
[HttpGet("Top/{N}/{Type}/{IsProject}")] [HttpGet("Top/{N}/{Type}/{IsProject}")]
public static TopModel TopProjects(UserReviews[] userReviews, Fields[] fields, Boolean IsProject,float average) public static TopModel TopProjects(UserReviews[] userReviews, Fields[] fields, Boolean IsProject,float average)
{ {
...@@ -152,8 +50,8 @@ namespace CSAMS.Controllers ...@@ -152,8 +50,8 @@ namespace CSAMS.Controllers
.Select(ur => new TopModel .Select(ur => new TopModel
{ {
Grade = float.Parse(ur.r.Answer) * ur.Item2, Grade = float.Parse(ur.r.Answer) * ur.Item2,
AssingmentID = ur.r.AssignmentID, AssignmentID = ur.r.AssignmentID,
AssingmentName = ur.r.Assignment.Name, AssignmentName = ur.r.Assignment.Name,
ReviewerID = ur.r.UserReviewer, ReviewerID = ur.r.UserReviewer,
type = "Top" type = "Top"
...@@ -168,7 +66,7 @@ namespace CSAMS.Controllers ...@@ -168,7 +66,7 @@ namespace CSAMS.Controllers
return null; return null;
Console.WriteLine(child2[0].ReviewerID); Console.WriteLine(child2[0].ReviewerID);
var ret = child2.Sum(r => r.Grade) / child.Sum(ur => ur.Item2); var ret = child2.Sum(r => r.Grade) / child.Sum(ur => ur.Item2);
TopModel model = new TopModel { Grade = MathF.Round(ret, 2), AssingmentID = child2[0].AssingmentID, AssingmentName = child2[0].AssingmentName,ReviewerID=child2[0].ReviewerID, type = "top" }; TopModel model = new TopModel { Grade = MathF.Round(ret, 2), AssignmentID = child2[0].AssignmentID, AssignmentName = child2[0].AssignmentName,ReviewerID=child2[0].ReviewerID, type = "top" };
return model; return model;
} }
else else
...@@ -178,8 +76,8 @@ namespace CSAMS.Controllers ...@@ -178,8 +76,8 @@ namespace CSAMS.Controllers
.Select(ur => new TopModel .Select(ur => new TopModel
{ {
Grade = MathF.Abs(float.Parse(ur.r.Answer) * ur.Item2 - average), Grade = MathF.Abs(float.Parse(ur.r.Answer) * ur.Item2 - average),
AssingmentID = ur.r.AssignmentID, AssignmentID = ur.r.AssignmentID,
AssingmentName = ur.r.Assignment.Name, AssignmentName = ur.r.Assignment.Name,
ReviewerID = ur.r.UserReviewer, ReviewerID = ur.r.UserReviewer,
type = "Top" type = "Top"
...@@ -191,7 +89,7 @@ namespace CSAMS.Controllers ...@@ -191,7 +89,7 @@ namespace CSAMS.Controllers
if (child.Length == 0) if (child.Length == 0)
return null; return null;
var ret = child2.Sum(r => r.Grade)/child.Sum(ur => ur.Item2); var ret = child2.Sum(r => r.Grade)/child.Sum(ur => ur.Item2);
TopModel model = new TopModel { Grade = MathF.Round(ret, 2), AssingmentID = child2[0].AssingmentID, AssingmentName = child2[0].AssingmentName, ReviewerID = child2[0].ReviewerID, type = "top" }; TopModel model = new TopModel { Grade = MathF.Round(ret, 2), AssignmentID = child2[0].AssignmentID, AssignmentName = child2[0].AssignmentName, ReviewerID = child2[0].ReviewerID, type = "top" };
return model; return model;
} }
} }
......
...@@ -15,15 +15,15 @@ namespace Test_Framework.GlobalStatistics ...@@ -15,15 +15,15 @@ namespace Test_Framework.GlobalStatistics
{ {
public readonly TopModel[] ExpectedProjectResultTopOne = public readonly TopModel[] ExpectedProjectResultTopOne =
{ {
new TopModel{Grade= 4,AssingmentName= "Cloud 2021 - Assignment 2",AssingmentID= 6,ReviewerID=33, type= "top"} new TopModel{Grade= 4,AssignmentName= "Cloud 2021 - Assignment 2",AssignmentID= 6,ReviewerID=33, type= "top"}
// new TopModel{Grade= 5,AssingmentName= "PROG2006 Assignment 1 tic-tac-roll",AssingmentID= 5,type= "top"}, // new TopModel{Grade= 5,AssingmentName= "PROG2006 Assignment 1 tic-tac-roll",AssingmentID= 5,type= "top"},
//new TopModel{Grade= 40,AssingmentName= "Cloud 2021 - Assignment 1",AssingmentID= 1,type= "top"} //new TopModel{Grade= 40,AssingmentName= "Cloud 2021 - Assignment 1",AssingmentID= 1,type= "top"}
}; };
public readonly TopModel[] ExpectedProjectResulToptTwo = public readonly TopModel[] ExpectedProjectResulToptTwo =
{ {
new TopModel{Grade=1.21F,AssingmentName= "PROG2006 Assignment 1 tic-tac-roll",AssingmentID= 5,ReviewerID=97,type= "top"}, new TopModel{Grade=1.21F,AssignmentName= "PROG2006 Assignment 1 tic-tac-roll",AssignmentID= 5,ReviewerID=97,type= "top"},
new TopModel{Grade= 2.79F,AssingmentName= "Cloud 2021 - Assignment 1",AssingmentID= 1,ReviewerID=19,type= "top"} new TopModel{Grade= 2.79F,AssignmentName= "Cloud 2021 - Assignment 1",AssignmentID= 1,ReviewerID=19,type= "top"}
// new TopModel{Grade= 1,AssingmentName= "Cloud 2021 - Assignment 2",AssingmentID= 6,type= "Bottom"} // new TopModel{Grade= 1,AssingmentName= "Cloud 2021 - Assignment 2",AssingmentID= 6,type= "Bottom"}
...@@ -31,13 +31,13 @@ namespace Test_Framework.GlobalStatistics ...@@ -31,13 +31,13 @@ namespace Test_Framework.GlobalStatistics
public readonly TopModel[] ExpectedProjectResultBottomOne = public readonly TopModel[] ExpectedProjectResultBottomOne =
{ {
new TopModel{Grade= 3.73F,AssingmentName= "Cloud 2021 - Assignment 1",AssingmentID= 1,ReviewerID=27, type= "top"}, new TopModel{Grade= 3.73F,AssignmentName= "Cloud 2021 - Assignment 1",AssignmentID= 1,ReviewerID=27, type= "top"},
new TopModel{Grade= 3,AssingmentName= "PROG2006 Assignment 1 tic-tac-roll",AssingmentID= 5,ReviewerID=97, type= "top"} new TopModel{Grade= 3,AssignmentName= "PROG2006 Assignment 1 tic-tac-roll",AssignmentID= 5,ReviewerID=97, type= "top"}
}; };
public readonly TopModel[] ExpectedProjectResulBottomtTwo = public readonly TopModel[] ExpectedProjectResulBottomtTwo =
{ {
new TopModel{Grade= 3.62F,AssingmentName= "Cloud 2021 - Assignment 1",AssingmentID= 1,ReviewerID=27, type= "top"} new TopModel{Grade= 3.62F,AssignmentName= "Cloud 2021 - Assignment 1",AssignmentID= 1,ReviewerID=27, type= "top"}
}; };
...@@ -53,8 +53,8 @@ namespace Test_Framework.GlobalStatistics ...@@ -53,8 +53,8 @@ namespace Test_Framework.GlobalStatistics
for (int i = 0; i < TopOne.Length; i++) for (int i = 0; i < TopOne.Length; i++)
{ {
Console.WriteLine(TopOne.Length + ":length "); Console.WriteLine(TopOne.Length + ":length ");
Console.WriteLine(TopOne[i].AssingmentName + " " + i + " :A.Name "); Console.WriteLine(TopOne[i].AssignmentName + " " + i + " :A.Name ");
Console.WriteLine(TopOne[i].AssingmentID + " " + i + " :A.ID "); Console.WriteLine(TopOne[i].AssignmentID + " " + i + " :A.ID ");
Console.WriteLine(TopOne[i].Grade + " " + i + " :Grade "); Console.WriteLine(TopOne[i].Grade + " " + i + " :Grade ");
Console.WriteLine(TopOne[i].ReviewerID + " " + i + " :R.ID "); Console.WriteLine(TopOne[i].ReviewerID + " " + i + " :R.ID ");
Console.WriteLine(TopOne[i].type + " " + i + " :type "); Console.WriteLine(TopOne[i].type + " " + i + " :type ");
...@@ -69,8 +69,8 @@ namespace Test_Framework.GlobalStatistics ...@@ -69,8 +69,8 @@ namespace Test_Framework.GlobalStatistics
for (int i = 0; i < TopTwo.Length; i++) for (int i = 0; i < TopTwo.Length; i++)
{ {
Console.WriteLine(TopTwo.Length + ":length "); Console.WriteLine(TopTwo.Length + ":length ");
Console.WriteLine(TopTwo[i].AssingmentName + " " + i + " :A.Name "); Console.WriteLine(TopTwo[i].AssignmentName + " " + i + " :A.Name ");
Console.WriteLine(TopTwo[i].AssingmentID + " " + i + " :A.ID "); Console.WriteLine(TopTwo[i].AssignmentID + " " + i + " :A.ID ");
Console.WriteLine(TopTwo[i].Grade + " " + i + " :Grade "); Console.WriteLine(TopTwo[i].Grade + " " + i + " :Grade ");
Console.WriteLine(TopTwo[i].ReviewerID + " " + i + " :R.ID "); Console.WriteLine(TopTwo[i].ReviewerID + " " + i + " :R.ID ");
Console.WriteLine(TopTwo[i].type + " "+i+" :type "); Console.WriteLine(TopTwo[i].type + " "+i+" :type ");
...@@ -85,8 +85,8 @@ namespace Test_Framework.GlobalStatistics ...@@ -85,8 +85,8 @@ namespace Test_Framework.GlobalStatistics
for (int i = 0; i < BottomOne.Length; i++) for (int i = 0; i < BottomOne.Length; i++)
{ {
Console.WriteLine(BottomOne.Length + ":length "); Console.WriteLine(BottomOne.Length + ":length ");
Console.WriteLine(BottomOne[i].AssingmentName + " " + i + " :A.Name "); Console.WriteLine(BottomOne[i].AssignmentName + " " + i + " :A.Name ");
Console.WriteLine(BottomOne[i].AssingmentID + " " + i + " :A.ID "); Console.WriteLine(BottomOne[i].AssignmentID + " " + i + " :A.ID ");
Console.WriteLine(BottomOne[i].Grade + " " + i + " :Grade "); Console.WriteLine(BottomOne[i].Grade + " " + i + " :Grade ");
Console.WriteLine(BottomOne[i].ReviewerID + " " + i + " :R.ID "); Console.WriteLine(BottomOne[i].ReviewerID + " " + i + " :R.ID ");
Console.WriteLine(BottomOne[i].type + " " + i + " :type "); Console.WriteLine(BottomOne[i].type + " " + i + " :type ");
...@@ -101,8 +101,8 @@ namespace Test_Framework.GlobalStatistics ...@@ -101,8 +101,8 @@ namespace Test_Framework.GlobalStatistics
for (int i = 0; i < BottomTwo.Length; i++) for (int i = 0; i < BottomTwo.Length; i++)
{ {
Console.WriteLine(BottomTwo.Length + ":length "); Console.WriteLine(BottomTwo.Length + ":length ");
Console.WriteLine(BottomTwo[i].AssingmentName + " " + i + " :A.Name "); Console.WriteLine(BottomTwo[i].AssignmentName + " " + i + " :A.Name ");
Console.WriteLine(BottomTwo[i].AssingmentID + " " + i + " :A.ID "); Console.WriteLine(BottomTwo[i].AssignmentID + " " + i + " :A.ID ");
Console.WriteLine(BottomTwo[i].Grade + " " + i + " :Grade "); Console.WriteLine(BottomTwo[i].Grade + " " + i + " :Grade ");
Console.WriteLine(BottomTwo[i].ReviewerID + " " + i + " :R.ID "); Console.WriteLine(BottomTwo[i].ReviewerID + " " + i + " :R.ID ");
Console.WriteLine(BottomTwo[i].type + " " + i + " :type "); Console.WriteLine(BottomTwo[i].type + " " + i + " :type ");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment