Skip to content
Snippets Groups Projects
Commit 89ceafd0 authored by Dimitrios Chaskopoulos's avatar Dimitrios Chaskopoulos
Browse files

Merge branch 'master' into 'TopBackend'

# Conflicts:
#   Backend/Test-Framework/TestData/TestData.cs
parents 77b89516 a6dc0b4b
No related branches found
No related tags found
No related merge requests found
Showing
with 242 additions and 1050 deletions
......@@ -163,3 +163,6 @@ yarn-error.log*
#Modules
node_modules/
package-lock.json
# Visual Studio cache/options directory
.vs/
File deleted
File deleted
File deleted
File deleted
File deleted
This diff is collapsed.
File deleted
File deleted
{
"CurrentProjectSetting": null
}
\ No newline at end of file
......@@ -2,6 +2,5 @@
"ExpandedNodes": [
""
],
"SelectedNode": "\\CSAMS.sln",
"PreviewInSolutionExplorer": false
}
\ No newline at end of file
......@@ -29,15 +29,12 @@ namespace CSAMS.Controllers
[HttpGet("user")]
public async Task<ActionResult<Users[]>> GetUsers()
{
Console.WriteLine("here");
return await _context.Users.Include(u => u.UserRole).ToArrayAsync();
}
//////////////////////////////
[HttpPost("user")]
[HttpPost("post")]
public ActionResult<Users> PostUser(User newuser)
{
......
using CSAMS.Models;
using CSAMS.DTOS;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System.Linq;
......@@ -19,26 +20,167 @@ namespace CSAMS.Controllers
_context = context;
}
[HttpPost("userReviewsFiltered")]
public async Task<ActionResult<UserReviews[]>> PostUserReviews(Filter filter)
{
UserReviews[] userReviews = await _context.UserReviews.Include(ur => ur.Assignment).Where(ur => ur.Type == "radio").Where(ur => ur.Answer != null).ToArrayAsync();
if (filter.assignment != "")
{
userReviews = ApplyFilterAssignment(userReviews, filter.assignment);
}
if (filter.reviewerID != "")
{
try
{
userReviews = ApplyFilterReviewerID(userReviews, Convert.ToInt32(filter.reviewerID));
}
catch (FormatException)
{
return BadRequest($"'{filter.reviewerID}' is not a valid userID!");
}
}
if (filter.targetID != "")
{
try
{
userReviews = ApplyFilterTargetID(userReviews, Convert.ToInt32(filter.targetID));
}
catch (FormatException)
{
return BadRequest($"'{filter.targetID}' is not a valid userID!");
}
}
if (userReviews is null || userReviews.Length == 0)
{
return BadRequest($"There are no user reviews corresponding to these values!");
}
return userReviews;
}
public static UserReviews[] ApplyFilterAssignment(UserReviews[] userReviews, String assignmentName)
{
UserReviews[] result = userReviews.Where(ur => ur.Assignment.Name == assignmentName).ToArray();
if (result.Length == 0)
{
return null;
}
return result;
}
public static UserReviews[] ApplyFilterReviewerID(UserReviews[] userReviews, int reviewerID)
{
UserReviews[] result = userReviews.Where(ur => ur.UserReviewer == reviewerID).ToArray();
if (result.Length == 0)
{
return null;
}
return result;
}
public static UserReviews[] ApplyFilterTargetID(UserReviews[] userReviews, int targetID)
{
UserReviews[] result = userReviews.Where(ur => ur.UserTarget == targetID).ToArray();
if (result.Length == 0)
{
return null;
}
return result;
}
[HttpGet("userReviews")]
public async Task<ActionResult<UserReviews[]>> GetUserReviews()
{
UserReviews[] userReviews = await _context.UserReviews.Include(ur => ur.Assignment).Where(ur => ur.Type == "radio").Where(ur => ur.Answer != null).ToArrayAsync();
if (userReviews.Length == 0)
{
return BadRequest($"There are no user reviews corresponding to these values!");
}
return userReviews;
}
[HttpGet("userReviewsStatistics")]
public async Task<ActionResult<String[]>> GetUserReviewsStatistics()
{
UserReviews[] all = await _context.UserReviews.Include(ur => ur.Review).Include(ur => ur.Review.Form).Include(ur => ur.Target).Include(ur => ur.Target.UserRole).Include(ur => ur.Reviewer).Include(ur => ur.Reviewer.UserRole).ToArrayAsync();
UserReviews[] all = await _context.UserReviews.Where(ur => ur.Type == "radio").Where(ur => ur.Answer != null).ToArrayAsync();
if (all.Length == 0)
{
return BadRequest($"There are no user reviews corresponding to these values!");
}
String[] array = new String[] { "Min: " + GetMin(all).Answer, "Max: "+GetMax(all).Answer,"Mean: " + GetMean(all), "Median: " + GetMedian(all), "Q1: " + GetQ1(all), "Q3: " + GetQ3(all), "Standard Deviation: " + GetStandardDeviation(all) };
return array;
}
[HttpPost("userReviewsFilteredStatistics")]
public async Task<ActionResult<String[]>> PostStatistics(Filter filter)
{
//Get all UserReviews
UserReviews[] userReviews = await _context.UserReviews.Include(ur => ur.Assignment).Where(ur => ur.Type == "radio").Where(ur => ur.Answer != null).ToArrayAsync();
//Filter them
if (filter.assignment != "")
{
userReviews = ApplyFilterAssignment(userReviews, filter.assignment);
}
if (filter.reviewerID != "")
{
try
{
userReviews = ApplyFilterReviewerID(userReviews, Convert.ToInt32(filter.reviewerID));
}
catch (FormatException)
{
return BadRequest($"'{filter.reviewerID}' is not a valid userID!");
}
}
if (filter.targetID != "")
{
try
{
userReviews = ApplyFilterTargetID(userReviews, Convert.ToInt32(filter.targetID));
}
catch (FormatException)
{
return BadRequest($"'{filter.targetID}' is not a valid userID!");
}
}
//In case the filters doesn't correspond to any userReview
if (userReviews is null || userReviews.Length == 0)
{
return BadRequest($"There are no user reviews corresponding to these values!");
}
//Return corresponding Statistics
String[] statistics = new String[] { };
try
{
statistics = new String[] { "Min: " + GetMin(userReviews).Answer, "Max: " + GetMax(userReviews).Answer, "Mean: " + GetMean(userReviews), "Median: " + GetMedian(userReviews), "Q1: " + GetQ1(userReviews), "Q3: " + GetQ3(userReviews), "Standard Deviation: " + GetStandardDeviation(userReviews) };
}
catch (FormatException)
{
return BadRequest($"One of the Answer values is not a number!");
}
return statistics;
}
public float GetMean(UserReviews[] list)
{
float total = 0;
float n = 0;
foreach (UserReviews UR in list)
{
if (UR.Type == "radio" && UR.Answer != null)
{
total += Convert.ToInt32(UR.Answer);
n += 1;
}
}
return total / n;
}
......@@ -46,12 +188,9 @@ namespace CSAMS.Controllers
{
List<float> values = new List<float>();
foreach (UserReviews UR in list)
{
if (UR.Type == "radio" && UR.Answer != null)
{
values.Add((float)Convert.ToInt32(UR.Answer));
}
}
values.Sort();
return values.ElementAt((values.Count - 1) / 2);
}
......@@ -61,11 +200,9 @@ namespace CSAMS.Controllers
List<float> values = new List<float>();
foreach (UserReviews UR in list)
{
if (UR.Type == "radio" && UR.Answer != null)
{
values.Add((float)Convert.ToInt32(UR.Answer));
}
}
values.Sort();
return values.ElementAt((values.Count - 1) / 4);
}
......@@ -74,12 +211,9 @@ namespace CSAMS.Controllers
{
List<float> values = new List<float>();
foreach (UserReviews UR in list)
{
if (UR.Type == "radio" && UR.Answer != null)
{
values.Add((float)Convert.ToInt32(UR.Answer));
}
}
values.Sort();
return values.ElementAt((3 * values.Count - 1) / 4);
}
......@@ -91,13 +225,10 @@ namespace CSAMS.Controllers
float n = 0;
foreach (UserReviews UR in list)
{
if (UR.Type == "radio" && UR.Answer != null)
{
n += 1;
sd += ((float)Convert.ToInt32(UR.Answer) - mean) * ((float)Convert.ToInt32(UR.Answer) - mean);
}
}
return (float)Math.Sqrt(Convert.ToDouble(sd / n));
}
......@@ -106,8 +237,6 @@ namespace CSAMS.Controllers
UserReviews minUR = new UserReviews();
int minScore = 1000;
foreach (UserReviews UR in list)
{
if (UR.Type == "radio" && UR.Answer != null)
{
if (Convert.ToInt32(UR.Answer) < minScore)
{
......@@ -115,7 +244,6 @@ namespace CSAMS.Controllers
minUR = UR;
}
}
}
return minUR;
}
......@@ -124,8 +252,6 @@ namespace CSAMS.Controllers
UserReviews minUR = new UserReviews();
int minScore = -1000;
foreach (UserReviews UR in list)
{
if (UR.Type == "radio" && UR.Answer != null)
{
if (Convert.ToInt32(UR.Answer) > minScore)
{
......@@ -133,7 +259,6 @@ namespace CSAMS.Controllers
minUR = UR;
}
}
}
return minUR;
}
}
......
......@@ -16,5 +16,13 @@ namespace CSAMS.DTOS
}
public class Filter
{
public string assignment { get; set; }
public string reviewerID { get; set; }
public string targetID { get; set; }
public string errorMsg { get; set; }
}
}
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using CSAMS.APIModels;
namespace CSAMS.Models
{
public class Assignments
public class Assignments : IAPIModel
{
[Key]
[MaxLength(11)]
......@@ -38,5 +39,22 @@ namespace CSAMS.Models
[MaxLength(11)]
public int Reviewers { get; set; }
public bool AssertEqual(IAPIModel other)
{
var otherModel = other as Assignments;
return (otherModel.ID == ID &&
otherModel.Name == Name &&
otherModel.Description == Description &&
otherModel.Created == Created &&
otherModel.PublishedDate == PublishedDate &&
otherModel.Deadline == Deadline &&
otherModel.CourseID == CourseID &&
otherModel.SubmissionID == SubmissionID &&
otherModel.ReviewEnabled == ReviewEnabled &&
otherModel.ReviewID == ReviewID &&
otherModel.ReviewDeadline == ReviewDeadline &&
otherModel.Reviewers == Reviewers);
}
}
}
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using CSAMS.APIModels;
namespace CSAMS.Models
{
......@@ -9,7 +10,7 @@ namespace CSAMS.Models
Spring
}
public class Courses
public class Courses : IAPIModel
{
[Key]
[MaxLength(11)]
......@@ -31,6 +32,18 @@ namespace CSAMS.Models
[MaxLength(11)]
public int Year { get; set; }
public SemesterSeasons Semester { get; set; }
public bool AssertEqual(IAPIModel other)
{
var otherModel = other as Courses;
return (otherModel.ID == ID &&
otherModel.Hash == Hash &&
otherModel.CourseCode == CourseCode &&
otherModel.CourseName == CourseName &&
otherModel.Teacher == Teacher &&
otherModel.User.AssertEqual(User) &&
otherModel.Description == Description &&
otherModel.Year == Year &&
otherModel.Semester == Semester);
}
}
}
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using CSAMS.APIModels;
namespace CSAMS.Models
{
public class Forms
public class Forms : IAPIModel
{
[Key]
[MaxLength]
......@@ -16,5 +17,14 @@ namespace CSAMS.Models
public string Name { get; set; }
[Timestamp]
public byte[] Created { get; set; }
public bool AssertEqual(IAPIModel other)
{
var otherModel = other as Forms;
return (otherModel.ID == ID &&
otherModel.Prefix == Prefix &&
otherModel.Name == Name &&
otherModel.Created == Created);
}
}
}
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using CSAMS.APIModels;
namespace CSAMS.Models
{
public class Reviews
public class Reviews : IAPIModel
{
[Key]
[MaxLength(11)]
......@@ -12,5 +13,13 @@ namespace CSAMS.Models
[ForeignKey("Form")]
public int FormID { get; set; }
public Forms Form { get; set; }
public bool AssertEqual(IAPIModel other)
{
var otherModel = other as Reviews;
return (otherModel.ID == ID &&
otherModel.FormID == FormID &&
otherModel.Form.AssertEqual(Form));
}
}
}
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using CSAMS.APIModels;
namespace CSAMS.Models
{
public class Roles
public class Roles : IAPIModel
{
[Key]
[MaxLength(11)]
......@@ -14,5 +15,13 @@ namespace CSAMS.Models
[MaxLength(256)]
[Column(TypeName = "VARCHAR")]
public string Name { get; set; }
public bool AssertEqual(IAPIModel other)
{
var otherModel = other as Roles;
return (otherModel.ID == ID &&
otherModel.Name == Name &&
otherModel.Key == Key);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment