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* ...@@ -163,3 +163,6 @@ yarn-error.log*
#Modules #Modules
node_modules/ node_modules/
package-lock.json 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 @@ ...@@ -2,6 +2,5 @@
"ExpandedNodes": [ "ExpandedNodes": [
"" ""
], ],
"SelectedNode": "\\CSAMS.sln",
"PreviewInSolutionExplorer": false "PreviewInSolutionExplorer": false
} }
\ No newline at end of file
...@@ -29,15 +29,12 @@ namespace CSAMS.Controllers ...@@ -29,15 +29,12 @@ namespace CSAMS.Controllers
[HttpGet("user")] [HttpGet("user")]
public async Task<ActionResult<Users[]>> GetUsers() public async Task<ActionResult<Users[]>> GetUsers()
{ {
Console.WriteLine("here");
return await _context.Users.Include(u => u.UserRole).ToArrayAsync(); return await _context.Users.Include(u => u.UserRole).ToArrayAsync();
} }
////////////////////////////// //////////////////////////////
[HttpPost("user")] [HttpPost("post")]
public ActionResult<Users> PostUser(User newuser) public ActionResult<Users> PostUser(User newuser)
{ {
......
using CSAMS.Models; using CSAMS.Models;
using CSAMS.DTOS;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System.Linq; using System.Linq;
...@@ -19,26 +20,167 @@ namespace CSAMS.Controllers ...@@ -19,26 +20,167 @@ namespace CSAMS.Controllers
_context = context; _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")] [HttpGet("userReviewsStatistics")]
public async Task<ActionResult<String[]>> GetUserReviewsStatistics() 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) }; 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; 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) public float GetMean(UserReviews[] list)
{ {
float total = 0; float total = 0;
float n = 0; float n = 0;
foreach (UserReviews UR in list) foreach (UserReviews UR in list)
{
if (UR.Type == "radio" && UR.Answer != null)
{ {
total += Convert.ToInt32(UR.Answer); total += Convert.ToInt32(UR.Answer);
n += 1; n += 1;
} }
}
return total / n; return total / n;
} }
...@@ -46,12 +188,9 @@ namespace CSAMS.Controllers ...@@ -46,12 +188,9 @@ namespace CSAMS.Controllers
{ {
List<float> values = new List<float>(); List<float> values = new List<float>();
foreach (UserReviews UR in list) foreach (UserReviews UR in list)
{
if (UR.Type == "radio" && UR.Answer != null)
{ {
values.Add((float)Convert.ToInt32(UR.Answer)); values.Add((float)Convert.ToInt32(UR.Answer));
} }
}
values.Sort(); values.Sort();
return values.ElementAt((values.Count - 1) / 2); return values.ElementAt((values.Count - 1) / 2);
} }
...@@ -61,11 +200,9 @@ namespace CSAMS.Controllers ...@@ -61,11 +200,9 @@ namespace CSAMS.Controllers
List<float> values = new List<float>(); List<float> values = new List<float>();
foreach (UserReviews UR in list) foreach (UserReviews UR in list)
{ {
if (UR.Type == "radio" && UR.Answer != null)
{
values.Add((float)Convert.ToInt32(UR.Answer)); values.Add((float)Convert.ToInt32(UR.Answer));
} }
}
values.Sort(); values.Sort();
return values.ElementAt((values.Count - 1) / 4); return values.ElementAt((values.Count - 1) / 4);
} }
...@@ -74,12 +211,9 @@ namespace CSAMS.Controllers ...@@ -74,12 +211,9 @@ namespace CSAMS.Controllers
{ {
List<float> values = new List<float>(); List<float> values = new List<float>();
foreach (UserReviews UR in list) foreach (UserReviews UR in list)
{
if (UR.Type == "radio" && UR.Answer != null)
{ {
values.Add((float)Convert.ToInt32(UR.Answer)); values.Add((float)Convert.ToInt32(UR.Answer));
} }
}
values.Sort(); values.Sort();
return values.ElementAt((3 * values.Count - 1) / 4); return values.ElementAt((3 * values.Count - 1) / 4);
} }
...@@ -91,13 +225,10 @@ namespace CSAMS.Controllers ...@@ -91,13 +225,10 @@ namespace CSAMS.Controllers
float n = 0; float n = 0;
foreach (UserReviews UR in list) foreach (UserReviews UR in list)
{
if (UR.Type == "radio" && UR.Answer != null)
{ {
n += 1; n += 1;
sd += ((float)Convert.ToInt32(UR.Answer) - mean) * ((float)Convert.ToInt32(UR.Answer) - mean); sd += ((float)Convert.ToInt32(UR.Answer) - mean) * ((float)Convert.ToInt32(UR.Answer) - mean);
} }
}
return (float)Math.Sqrt(Convert.ToDouble(sd / n)); return (float)Math.Sqrt(Convert.ToDouble(sd / n));
} }
...@@ -106,8 +237,6 @@ namespace CSAMS.Controllers ...@@ -106,8 +237,6 @@ namespace CSAMS.Controllers
UserReviews minUR = new UserReviews(); UserReviews minUR = new UserReviews();
int minScore = 1000; int minScore = 1000;
foreach (UserReviews UR in list) foreach (UserReviews UR in list)
{
if (UR.Type == "radio" && UR.Answer != null)
{ {
if (Convert.ToInt32(UR.Answer) < minScore) if (Convert.ToInt32(UR.Answer) < minScore)
{ {
...@@ -115,7 +244,6 @@ namespace CSAMS.Controllers ...@@ -115,7 +244,6 @@ namespace CSAMS.Controllers
minUR = UR; minUR = UR;
} }
} }
}
return minUR; return minUR;
} }
...@@ -124,8 +252,6 @@ namespace CSAMS.Controllers ...@@ -124,8 +252,6 @@ namespace CSAMS.Controllers
UserReviews minUR = new UserReviews(); UserReviews minUR = new UserReviews();
int minScore = -1000; int minScore = -1000;
foreach (UserReviews UR in list) foreach (UserReviews UR in list)
{
if (UR.Type == "radio" && UR.Answer != null)
{ {
if (Convert.ToInt32(UR.Answer) > minScore) if (Convert.ToInt32(UR.Answer) > minScore)
{ {
...@@ -133,7 +259,6 @@ namespace CSAMS.Controllers ...@@ -133,7 +259,6 @@ namespace CSAMS.Controllers
minUR = UR; minUR = UR;
} }
} }
}
return minUR; return minUR;
} }
} }
......
...@@ -16,5 +16,13 @@ namespace CSAMS.DTOS ...@@ -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;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using CSAMS.APIModels;
namespace CSAMS.Models namespace CSAMS.Models
{ {
public class Assignments public class Assignments : IAPIModel
{ {
[Key] [Key]
[MaxLength(11)] [MaxLength(11)]
...@@ -38,5 +39,22 @@ namespace CSAMS.Models ...@@ -38,5 +39,22 @@ namespace CSAMS.Models
[MaxLength(11)] [MaxLength(11)]
public int Reviewers { get; set; } 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;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using CSAMS.APIModels;
namespace CSAMS.Models namespace CSAMS.Models
{ {
...@@ -9,7 +10,7 @@ namespace CSAMS.Models ...@@ -9,7 +10,7 @@ namespace CSAMS.Models
Spring Spring
} }
public class Courses public class Courses : IAPIModel
{ {
[Key] [Key]
[MaxLength(11)] [MaxLength(11)]
...@@ -31,6 +32,18 @@ namespace CSAMS.Models ...@@ -31,6 +32,18 @@ namespace CSAMS.Models
[MaxLength(11)] [MaxLength(11)]
public int Year { get; set; } public int Year { get; set; }
public SemesterSeasons Semester { 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;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using CSAMS.APIModels;
namespace CSAMS.Models namespace CSAMS.Models
{ {
public class Forms public class Forms : IAPIModel
{ {
[Key] [Key]
[MaxLength] [MaxLength]
...@@ -16,5 +17,14 @@ namespace CSAMS.Models ...@@ -16,5 +17,14 @@ namespace CSAMS.Models
public string Name { get; set; } public string Name { get; set; }
[Timestamp] [Timestamp]
public byte[] Created { get; set; } 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;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using CSAMS.APIModels;
namespace CSAMS.Models namespace CSAMS.Models
{ {
public class Reviews public class Reviews : IAPIModel
{ {
[Key] [Key]
[MaxLength(11)] [MaxLength(11)]
...@@ -12,5 +13,13 @@ namespace CSAMS.Models ...@@ -12,5 +13,13 @@ namespace CSAMS.Models
[ForeignKey("Form")] [ForeignKey("Form")]
public int FormID { get; set; } public int FormID { get; set; }
public Forms Form { 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;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using CSAMS.APIModels;
namespace CSAMS.Models namespace CSAMS.Models
{ {
public class Roles public class Roles : IAPIModel
{ {
[Key] [Key]
[MaxLength(11)] [MaxLength(11)]
...@@ -14,5 +15,13 @@ namespace CSAMS.Models ...@@ -14,5 +15,13 @@ namespace CSAMS.Models
[MaxLength(256)] [MaxLength(256)]
[Column(TypeName = "VARCHAR")] [Column(TypeName = "VARCHAR")]
public string Name { get; set; } 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 register or to comment