CSCanvas Qualification Review
KEY FEATURES
Feel free to demo these features and try them out on your own! If you want working credentials to test out the student features:
EMAIL: rohin@gmail.com
PASSWORD: SecurePassword123$
Sign-Up Page
Log In Page
Stats Checker
Student Submission and Assignment Page
Teacher Review and Assigning Page
HOW IT WORKS
We'll go over it when speaking to the groups in our demonstration, but we'll go over it here as well.
JSON Web Tokens for Sign-Up and Login Pages
Authentication:
- Teachers and students have different sets of credentials (e.g., email and password) stored in a database.
- When a user attempts to log in by sending a POST request to /api/login/authenticate, the server first checks if the user exists in the database based on the provided email.
- If the user exists, the server checks if the provided password matches the stored password hash. This comparison is done securely using the SHA-256 hashing algorithm.
- If the provided credentials are correct, the server creates a JSON Web Token (JWT) containing user information (e.g., user role, user ID) and issues it to the client.
- The JWT is then securely stored as an HTTP-only cookie named "flashjwt."
Authorization and Secure Routes:
- Once a user is authenticated, they can access secure routes within the application.
- The /getYourUser endpoint is used to retrieve the user's information. It expects the user to have a valid JWT stored in the "flashjwt" cookie. The JWT contains user role information, allowing the server to distinguish between teachers and students.
- Based on the user's role, the server can determine which routes and data are accessible to that user. For example, certain routes and resources might be restricted to teachers, while others are accessible to students.
@PostMapping("/authenticate")
// public ResponseEntity<Object> authenticate(@RequestBody final Map<String, Object> map, @CookieValue(value = "flashjwt", required = false) String jwt, HttpServletResponse response) throws NoSuchAlgorithmException {
public ResponseEntity<Object> authenticate(@RequestBody final Map<String, Object> map, HttpServletResponse response) throws NoSuchAlgorithmException {
var popt = personJpaRepository.findByEmail((String) map.get("email"));
if (!popt.isPresent()) {
// error handling
Map<String, Object> resp = new HashMap<>();
resp.put("err", "No such user with email provided");
return new ResponseEntity<>(resp, HttpStatus.BAD_REQUEST);
}
var p = popt.get();
String password = (String) map.get("password");
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] encodedHash = digest.digest(
password.getBytes(StandardCharsets.UTF_8));
String computedPasswordHash = new String(encodedHash);
if (computedPasswordHash.equals(p.getPasswordHash())) {
// redact password
p.passwordHash = "REDACTED";
} else {
Map<String, Object> resp = new HashMap<>();
resp.put("err", "Incorrect Password");
return new ResponseEntity<>(resp, HttpStatus.BAD_REQUEST);
}
String jws = handler.createJwt(p);
Cookie cookie = new Cookie("flashjwt", jws);
cookie.setPath("/");
cookie.setHttpOnly(true);
response.addCookie(cookie);
return new ResponseEntity<>(jws, HttpStatus.OK);
}
Student & Teacher Pages
Authentication and Authorization:
-
Authentication and Authorization: The code enforces authentication through the use of JWTs, ensuring that only authorized users (admins) can create assignments and submissions. It checks the user's role to determine if they have permission to perform specific actions, like creating assignments.
-
Assignment Management: It provides endpoints for creating assignments, searching for assignments by name, and retrieving a list of all assignments. Teachers (admins) can create assignments, providing details such as the assignment name, description, and due date.
-
Submission Handling: The code also handles the creation of student submissions for assignments. Users provide a link and timestamp for their submissions, associating them with a specific assignment. It ensures that submissions are linked to existing assignments.
-
Error Handling and Responses: The code includes error handling and provides appropriate error responses in cases of unauthorized access, missing assignments, or empty result sets.
@PostMapping("/createSubmission")
public ResponseEntity<Object> createSubmission(@CookieValue("flashjwt") String jwt,
@RequestBody final Map<String, Object> map) throws IOException {
Person p = handler.decodeJwt(jwt);
Assignment assignment = assRepo.findById(Long.parseLong((String) map.get("assignmentID"))).orElse(null);
if (assignment != null) {
Submission submission = new Submission();
submission.setLink((String) map.get("link"));
submission.setTime((String) map.get("time"));
submission.setEmail((String) p.getEmail());
submission.setAssignment(assignment); // Associate submission with the assignment
subRepo.save(submission);
Map<String, Object> response = new HashMap<>();
response.put("err", false);
return new ResponseEntity<>(response, HttpStatus.CREATED);
} else {
Map<String, Object> response = new HashMap<>();
response.put("err", "Assignment not found");
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
}
}
Statistics Checker
MultiVarAnalyticsGradeRegression.java:
- This file defines a Java component for performing multiple variable regression analysis. It includes methods for normalizing data, calculating regression coefficients, displaying regression charts, and calculating quantiles.
- It has a performCrossValidation method for training a regression model on a dataset, making predictions, and calculating the Mean Squared Error (MSE) for testing.
- Additionally, the code provides functionality for creating regression charts and data visualization.
@Component
public class MultiVarAnalyticsGradeRegression {
public void performCrossValidation(int numStudents) {
double[][] xData = MockDataGenerator.generateXData(numStudents);
double[][] normalizedXData = normalize(xData);
double[] yData = MockDataGenerator.generateYData(xData);
// Split the data into training and testing sets (80-20 split)
int trainSize = (int) (0.8 * numStudents);
double[][] trainX = Arrays.copyOfRange(normalizedXData, 0, trainSize);
double[][] testX = Arrays.copyOfRange(normalizedXData, trainSize, numStudents);
double[] trainY = Arrays.copyOfRange(yData, 0, trainSize);
double[] testY = Arrays.copyOfRange(yData, trainSize, numStudents);
// Train the regression model on the training set
double[] coefficients = calculateCoefficients(trainX, trainY);
// Predict the grades for the testing set
double[] predictedY = new double[testY.length];
for (int i = 0; i < testX.length; i++) {
predictedY[i] = coefficients[0]; // bias term
for (int j = 0; j < testX[i].length; j++) {
predictedY[i] += coefficients[j + 1] * testX[i][j];
}
}
// Calculate the Mean Squared Error (MSE) for the testing set
double mse = 0;
for (int i = 0; i < testY.length; i++) {
mse += Math.pow(testY[i] - predictedY[i], 2);
}
mse /= testY.length;
System.out.println("Mean Squared Error on Testing Set: " + mse);
}
MockDataGenerator.java:
- This file contains a Java component that generates mock data for use in regression analysis. It includes methods for generating student data with metrics like commits, pull requests, issues, and repositories contributed to.
- The generateYData method calculates student grades based on the generated data and specific formulas for each metric.
public static double[] generateYData(double[][] xData) {
double[] yData = new double[xData.length];
for (int i = 0; i < xData.length; i++) {
yData[i] = calculateGrade((int)xData[i][0], (int)xData[i][1], (int)xData[i][2], (int)xData[i][3]);
}
return yData;
}
GradePredictionController.java:
- This file is a Spring Boot RESTful controller responsible for handling requests related to grade prediction. It uses the MultiVarAnalyticsGradeRegression service to perform regression analysis and generate grade prediction responses.
- It defines an endpoint for predicting grades based on student data and returns a response containing regression coefficients, chart images, and other relevant information.
@RestController
@RequestMapping("/api/grade")
public class GradePredictionController {
@Autowired
private MultiVarAnalyticsGradeRegression regressionService;
@PostMapping("/predict")
public ResponseEntity<GradePredictionResponse> predictGrade(@RequestBody GradePredictionRequest request) {
MultiVarAnalyticsGradeRegression.RegressionResult result = regressionService.performRegression(request.getNumStudents());
// Extract coefficients
double[] coeffs = result.getCoefficients();
// Generate charts for each metric and collect image URLs
String[] metrics = {"Commits", "Pulls", "Issues", "ReposContributedTo"};
List<String> imageUrls = new ArrayList<>();
for (String metric : metrics) {
MultiVarAnalyticsGradeRegression.displayChart(result.getXData()[0], result.getYData(), coeffs, metric); // Assuming XData[0] corresponds to the first metric
imageUrls.add("/images/" + metric + ".png");
}
// Construct the response
GradePredictionResponse response = new GradePredictionResponse();
response.setBias(coeffs[0]);
response.setCommitCoefficient(coeffs[1]);
response.setPullCoefficient(coeffs[2]);
response.setIssueCoefficient(coeffs[3]);
response.setReposContributedToCoefficient(coeffs[4]);
response.setImageUrls(imageUrls);
return ResponseEntity.ok(response);
}
PEER-GRADING
-
HOOK:
Points: 3.6-4.0
Reason:
-
KNOWLEDGE:
Points: 3.6-4.0
Reason:
-
VALUE:
Points: 0.6-1.0
Reason:
-
WOW FACTOR:
Reason:
CSCanvas Qualification Review
KEY FEATURES
Feel free to demo these features and try them out on your own! If you want working credentials to test out the student features:
EMAIL: rohin@gmail.com
PASSWORD: SecurePassword123$
Sign-Up Page
Log In Page
Stats Checker
Student Submission and Assignment Page
Teacher Review and Assigning Page
HOW IT WORKS
We'll go over it when speaking to the groups in our demonstration, but we'll go over it here as well.
JSON Web Tokens for Sign-Up and Login Pages
Authentication:
Authorization and Secure Routes:
Student & Teacher Pages
Authentication and Authorization:
Authentication and Authorization: The code enforces authentication through the use of JWTs, ensuring that only authorized users (admins) can create assignments and submissions. It checks the user's role to determine if they have permission to perform specific actions, like creating assignments.
Assignment Management: It provides endpoints for creating assignments, searching for assignments by name, and retrieving a list of all assignments. Teachers (admins) can create assignments, providing details such as the assignment name, description, and due date.
Submission Handling: The code also handles the creation of student submissions for assignments. Users provide a link and timestamp for their submissions, associating them with a specific assignment. It ensures that submissions are linked to existing assignments.
Error Handling and Responses: The code includes error handling and provides appropriate error responses in cases of unauthorized access, missing assignments, or empty result sets.
Statistics Checker
MultiVarAnalyticsGradeRegression.java:
MockDataGenerator.java:
GradePredictionController.java:
PEER-GRADING
HOOK:
Points: 3.6-4.0
Reason:
KNOWLEDGE:
Points: 3.6-4.0
Reason:
VALUE:
Points: 0.6-1.0
Reason:
WOW FACTOR:
Reason: