Skip to content
Snippets Groups Projects
Commit 816c6e20 authored by Jonas Eilertsen Hægdahl's avatar Jonas Eilertsen Hægdahl
Browse files

Format and comment code

parent 253a73ad
Branches master
No related tags found
No related merge requests found
Showing
with 176 additions and 177 deletions
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace CSAMS.APIModels
namespace CSAMS.APIModels
{
public interface IAPIModel
{
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace CSAMS.APIModels
{
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace CSAMS.APIModels
namespace CSAMS.APIModels
{
public class CommentModel : IAPIModel
{
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace CSAMS.APIModels
namespace CSAMS.APIModels
{
public class TopModel : IAPIModel
{
......@@ -11,15 +6,14 @@ namespace CSAMS.APIModels
public string AssingmentName { get; set; }
public int AssingmentID { get; set; }
public int ReviewerID { get; set; }
public string Type { get; set; }
public string type { get; set; }
public bool AssertEqual(IAPIModel other)
{
var otherProject = other as TopModel;
return (Grade == otherProject.Grade &&
AssingmentName == otherProject.AssingmentName &&
type == otherProject.type &&
Type == otherProject.Type &&
ReviewerID == otherProject.ReviewerID &&
AssingmentID == otherProject.AssingmentID);
}
......
using CSAMS.APIModels;
using CSAMS.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace CSAMS.Controllers
{
/// <summary>
/// Class for getting the Assignments
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class AssignmentController : ControllerBase
......@@ -21,9 +21,12 @@ namespace CSAMS.Controllers
_context = context;
}
/// <summary>
/// Get all Assignments
/// </summary>
/// <returns>Array of AssignmentModels</returns>
public async Task<AssignmentModel[]> Get()
{
Console.Write("Test");
return await _context.Assignments.Include(a => a.Course).Select(a => new AssignmentModel { ID = a.ID, Name = a.Name, Deadline = a.Deadline, ReviewDeadline = a.ReviewDeadline, Course = a.Course.CourseName }).ToArrayAsync();
}
}
......
......@@ -6,6 +6,9 @@ using System.Threading.Tasks;
namespace CSAMS.Controllers
{
/// <summary>
/// Controller that was originally meant to be part of an example
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class BasicController : ControllerBase
......@@ -17,6 +20,10 @@ namespace CSAMS.Controllers
_context = context;
}
/// <summary>
/// Call that is used to showcase Pagination on the frontend
/// </summary>
/// <returns>Array of UserReviews with a comment</returns>
[HttpGet("Comments")]
public async Task<ActionResult<UserReviews[]>> GetComments()
{
......
using CSAMS.APIModels;
using CSAMS.Models;
using CSAMS.DTOS;
using CSAMS.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System;
using System.Linq;
using System.Threading.Tasks;
namespace CSAMS.Controllers
{
/// <summary>
/// Class for getting filtered comments
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class CommentController : ControllerBase
......@@ -20,6 +22,11 @@ namespace CSAMS.Controllers
_context = context;
}
/// <summary>
/// Get UserReviews based on filtering by Reviewer
/// </summary>
/// <param name="filters"></param>
/// <returns>Array of filtered UserReviews</returns>
[HttpPost("reviewer")]
public async Task<ActionResult<CommentModel[]>> GetCommentsByReviewer(PostMessage filters)
{
......@@ -67,7 +74,11 @@ namespace CSAMS.Controllers
return returnValue.Select(m => new CommentModel { Target = m.UserTarget, Answer = m.Answer, AnswerType = m.Type, Comment = m.Comment, Reviewer = m.UserReviewer }).ToArray();
}
/// <summary>
/// Get UserReviews based on filtering by Assignment
/// </summary>
/// <param name="filters"></param>
/// <returns>Array of filtered UserReviews</returns>
[HttpPost("project")]
public async Task<ActionResult<CommentModel[]>> GetCommentsByAssignment(PostMessage filters)
{
......@@ -115,41 +126,12 @@ namespace CSAMS.Controllers
return returnValue.Select(m => new CommentModel { Target = m.UserTarget, Answer = m.Answer, AnswerType = m.Type, Comment = m.Comment, Reviewer = m.UserReviewer }).ToArray();
}
[HttpGet("project/{projectID}")]
public async Task<ActionResult<CommentModel[]>> GetProjectComments(int projectID)
{
var project = await _context.Assignments.Where(A => A.ID == projectID).FirstOrDefaultAsync();
if (project is null)
return BadRequest($"No project with ID {projectID} exist!");
var reviews = await _context.UserReviews.ToArrayAsync();
var returnValue = GetProjects(reviews, projectID);
if (returnValue is null)
return BadRequest($"Project with ID {projectID} has no commented reviews!");
return returnValue;
}
[HttpGet("reviewer/{reviewerID}")]
public async Task<ActionResult<CommentModel[]>> GetReviewerComments(int reviewerID)
{
Console.WriteLine(reviewerID);
var reviewer = await _context.Users.Where(u => u.ID == reviewerID).FirstOrDefaultAsync();
if (reviewer is null)
return BadRequest($"No reviewer with ID {reviewerID} exist!");
var reviews = await _context.UserReviews.ToArrayAsync();
var returnValue = GetReviewers(reviews, reviewerID);
if (returnValue is null)
return BadRequest($"Reviewer {reviewerID} has no commented reviews!");
return returnValue;
}
/// <summary>
/// Filters UserReviews based on projectID
/// </summary>
/// <param name="reviews"></param>
/// <param name="projectID"></param>
/// <returns>Array of filtered UserReviews</returns>
public static CommentModel[] GetProjects(UserReviews[] reviews, int projectID)
{
var proco = reviews.Where(r => r.AssignmentID == projectID && r.Comment != null)
......@@ -159,6 +141,12 @@ namespace CSAMS.Controllers
return null;
}
/// <summary>
/// Filters UserReviews based on reviewerID
/// </summary>
/// <param name="reviews"></param>
/// <param name="reviewerID"></param>
/// <returns>Array of filtered UserReviews</returns>
public static CommentModel[] GetReviewers(UserReviews[] reviews, int reviewerID)
{
var model = reviews.Where(m => m.UserReviewer == reviewerID && m.Comment != null)
......
using CSAMS.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Collections.Generic;
using System;
namespace CSAMS.Controllers
{
/// <summary>
/// This class is an early class for statistics. Functions are in StatisticsController as well, but the Rest API for this is used in MinMax on the frontend
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class MinMaxController : ControllerBase
......
......@@ -2,13 +2,14 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System.Threading.Tasks;
using System;
using CSAMS.DTOS;
namespace CSAMS.Controllers
{
/// <summary>
/// This class was supposed to be a sample for how to get data from the database
/// It is now used to get all Users in the database
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class SampleController : ControllerBase
......@@ -20,37 +21,14 @@ namespace CSAMS.Controllers
_context = context;
}
[HttpGet("review")]
public async Task<ActionResult<Reviews[]>> GetReviews()
{
return await _context.Reviews.Include(r => r.Form).ToArrayAsync();
}
/// <summary>
/// Get all users
/// </summary>
/// <returns>Array of Users</returns>
[HttpGet("user")]
public async Task<ActionResult<Users[]>> GetUsers()
{
return await _context.Users.Include(u => u.UserRole).ToArrayAsync();
}
//////////////////////////////
[HttpPost("post")]
public ActionResult<Users> PostUser(User newuser)
{
return Ok();
}
[HttpPost("user")]
public ActionResult<Users> PostUserFilter(UserFilter newuser)
{
return Ok();
}
///////////////////
}
}
using CSAMS.Models;
using CSAMS.DTOS;
using CSAMS.DTOS;
using CSAMS.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Collections.Generic;
using System;
namespace CSAMS.Controllers
{
/// <summary>
/// Class for getting statistics of the database
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class StatisticsController : ControllerBase
......@@ -20,38 +23,42 @@ namespace CSAMS.Controllers
_context = context;
}
/// <summary>
/// Get Userreviews based on filter
/// </summary>
/// <param name="filter"></param>
/// <returns>Array of filtered UserReviews</returns>
[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 != "")
if (filter.Assignment != "")
{
userReviews = ApplyFilterAssignment(userReviews, filter.assignment);
userReviews = ApplyFilterAssignment(userReviews, filter.Assignment);
}
if (filter.reviewerID != "")
if (filter.ReviewerID != "")
{
try
{
userReviews = ApplyFilterReviewerID(userReviews, Convert.ToInt32(filter.reviewerID));
userReviews = ApplyFilterReviewerID(userReviews, Convert.ToInt32(filter.ReviewerID));
}
catch (FormatException)
{
return BadRequest($"'{filter.reviewerID}' is not a valid userID!");
return BadRequest($"'{filter.ReviewerID}' is not a valid userID!");
}
}
if (filter.targetID != "")
if (filter.TargetID != "")
{
try
{
userReviews = ApplyFilterTargetID(userReviews, Convert.ToInt32(filter.targetID));
userReviews = ApplyFilterTargetID(userReviews, Convert.ToInt32(filter.TargetID));
}
catch (FormatException)
{
return BadRequest($"'{filter.targetID}' is not a valid userID!");
return BadRequest($"'{filter.TargetID}' is not a valid userID!");
}
}
......@@ -63,7 +70,7 @@ namespace CSAMS.Controllers
return userReviews;
}
public static UserReviews[] ApplyFilterAssignment(UserReviews[] userReviews, String assignmentName)
public static UserReviews[] ApplyFilterAssignment(UserReviews[] userReviews, string assignmentName)
{
UserReviews[] result = userReviews.Where(ur => ur.Assignment.Name == assignmentName).ToArray();
if (result.Length == 0)
......@@ -91,7 +98,10 @@ namespace CSAMS.Controllers
return result;
}
/// <summary>
///
/// </summary>
/// <returns>Array of UserReviews</returns>
[HttpGet("userReviews")]
public async Task<ActionResult<UserReviews[]>> GetUserReviews()
{
......@@ -103,53 +113,60 @@ namespace CSAMS.Controllers
return userReviews;
}
/// <summary>
/// Get statistics for all Reviews
/// </summary>
/// <returns>Array of strings</returns>
[HttpGet("userReviewsStatistics")]
public async Task<ActionResult<String[]>> GetUserReviewsStatistics()
public async Task<ActionResult<string[]>> GetUserReviewsStatistics()
{
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;
}
/// <summary>
/// Get statististics for all Reviews based on filtering
/// </summary>
/// <param name="filter"></param>
/// <returns>Filtered array of strings</returns>
[HttpPost("userReviewsFilteredStatistics")]
public async Task<ActionResult<String[]>> PostStatistics(Filter filter)
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 != "")
if (filter.Assignment != "")
{
userReviews = ApplyFilterAssignment(userReviews, filter.assignment);
userReviews = ApplyFilterAssignment(userReviews, filter.Assignment);
}
if (filter.reviewerID != "")
if (filter.ReviewerID != "")
{
try
{
userReviews = ApplyFilterReviewerID(userReviews, Convert.ToInt32(filter.reviewerID));
userReviews = ApplyFilterReviewerID(userReviews, Convert.ToInt32(filter.ReviewerID));
}
catch (FormatException)
{
return BadRequest($"'{filter.reviewerID}' is not a valid userID!");
return BadRequest($"'{filter.ReviewerID}' is not a valid userID!");
}
}
if (filter.targetID != "")
if (filter.TargetID != "")
{
try
{
userReviews = ApplyFilterTargetID(userReviews, Convert.ToInt32(filter.targetID));
userReviews = ApplyFilterTargetID(userReviews, Convert.ToInt32(filter.TargetID));
}
catch (FormatException)
{
return BadRequest($"'{filter.targetID}' is not a valid userID!");
return BadRequest($"'{filter.TargetID}' is not a valid userID!");
}
}
......@@ -160,10 +177,10 @@ namespace CSAMS.Controllers
}
//Return corresponding Statistics
String[] statistics = new String[] { };
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) };
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)
{
......@@ -172,6 +189,11 @@ namespace CSAMS.Controllers
return statistics;
}
/// <summary>
/// Get Mean answer score of UserReviews
/// </summary>
/// <param name="list"></param>
/// <returns>Mean</returns>
public float GetMean(UserReviews[] list)
{
float total = 0;
......@@ -184,6 +206,11 @@ namespace CSAMS.Controllers
return total / n;
}
/// <summary>
/// Get Median answer score of UserReviews
/// </summary>
/// <param name="list"></param>
/// <returns>Median</returns>
public float GetMedian(UserReviews[] list)
{
List<float> values = new List<float>();
......@@ -195,6 +222,11 @@ namespace CSAMS.Controllers
return values.ElementAt((values.Count - 1) / 2);
}
/// <summary>
/// Get Q1 answer score of UserReviews
/// </summary>
/// <param name="list"></param>
/// <returns>Q1</returns>
public float GetQ1(UserReviews[] list)
{
List<float> values = new List<float>();
......@@ -207,6 +239,11 @@ namespace CSAMS.Controllers
return values.ElementAt((values.Count - 1) / 4);
}
/// <summary>
/// Get Q3 answer score of UserReviews
/// </summary>
/// <param name="list"></param>
/// <returns>Q3</returns>
public float GetQ3(UserReviews[] list)
{
List<float> values = new List<float>();
......@@ -218,6 +255,11 @@ namespace CSAMS.Controllers
return values.ElementAt((3 * values.Count - 1) / 4);
}
/// <summary>
/// Get Standard Deviation answer score of UserReviews
/// </summary>
/// <param name="list"></param>
/// <returns>Standard Deviation</returns>
public float GetStandardDeviation(UserReviews[] list)
{
float mean = GetMean(list);
......@@ -232,6 +274,11 @@ namespace CSAMS.Controllers
return (float)Math.Sqrt(Convert.ToDouble(sd / n));
}
/// <summary>
/// Get Minimum answer score of UserReviews
/// </summary>
/// <param name="list"></param>
/// <returns>Minimum</returns>
public UserReviews GetMin(UserReviews[] list)
{
UserReviews minUR = new UserReviews();
......@@ -247,6 +294,11 @@ namespace CSAMS.Controllers
return minUR;
}
/// <summary>
/// Get Maximum answer score of UserReviews
/// </summary>
/// <param name="list"></param>
/// <returns>Maximum</returns>
public UserReviews GetMax(UserReviews[] list)
{
UserReviews minUR = new UserReviews();
......
......@@ -60,7 +60,14 @@ namespace CSAMS.Controllers
return ret;
}
// [HttpGet("Top/{N}/{Type}/{IsProject}")]
/// <summary>
/// Get the Mean Average
/// </summary>
/// <param name="userReviews"></param>
/// <param name="fields"></param>
/// <param name="IsProject"></param>
/// <param name="average">Mean average of all reviews</param>
/// <returns></returns>
public static TopModel TopProjects(UserReviews[] userReviews, Fields[] fields, bool IsProject, float average)
{
var child = userReviews
......@@ -83,7 +90,7 @@ namespace CSAMS.Controllers
AssingmentID = ur.r.AssignmentID,
AssingmentName = ur.r.Assignment.Name,
ReviewerID = ur.r.UserReviewer,
type = "Top"
Type = "Top"
})
.ToArray();
}
......@@ -96,7 +103,7 @@ namespace CSAMS.Controllers
AssingmentID = ur.r.AssignmentID,
AssingmentName = ur.r.Assignment.Name,
ReviewerID = ur.r.UserReviewer,
type = "Top"
Type = "Top"
})
.ToArray();
}
......@@ -114,7 +121,7 @@ namespace CSAMS.Controllers
AssingmentID = grades[0].AssingmentID,
AssingmentName = grades[0].AssingmentName,
ReviewerID = grades[0].ReviewerID,
type = "top"
Type = "top"
};
return model;
......
using System.Runtime.InteropServices;
using System;
namespace CSAMS.DTOS
{
public class User
{
public string id { get; set; }
public string role { get; set; }
}
public class UserFilter
{
public string id { get; set; }
}
public class Filter
{
public string assignment { get; set; }
public string reviewerID { get; set; }
public string targetID { get; set; }
public string errorMsg { get; set; }
public string Assignment { get; set; }
public string ReviewerID { get; set; }
public string TargetID { get; set; }
public string ErrorMsg { get; set; }
}
public class PostMessage
......
using Microsoft.EntityFrameworkCore;
using System;
using System.Diagnostics;
using System.IO;
namespace CSAMS.Models
{
......
using System;
using CSAMS.APIModels;
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using CSAMS.APIModels;
namespace CSAMS.Models
{
......
using System.ComponentModel.DataAnnotations;
using CSAMS.APIModels;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using CSAMS.APIModels;
namespace CSAMS.Models
{
......
using System.ComponentModel.DataAnnotations;
using CSAMS.APIModels;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using CSAMS.APIModels;
namespace CSAMS.Models
{
......
using System.ComponentModel.DataAnnotations;
using CSAMS.APIModels;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using CSAMS.APIModels;
namespace CSAMS.Models
{
......
using System.ComponentModel.DataAnnotations;
using CSAMS.APIModels;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using CSAMS.APIModels;
namespace CSAMS.Models
{
......
using System.ComponentModel.DataAnnotations;
using CSAMS.APIModels;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using CSAMS.APIModels;
namespace CSAMS.Models
{
......
using System.ComponentModel.DataAnnotations;
using CSAMS.APIModels;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using CSAMS.APIModels;
namespace CSAMS.Models
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment