vardaansinha / cscanvasfrontend

MIT License
1 stars 0 forks source link

CSCanvas Qualification Review & Peer-Grading #5

Open vardaansinha opened 10 months ago

vardaansinha commented 10 months ago

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:

  1. Teachers and students have different sets of credentials (e.g., email and password) stored in a database.
  2. 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.
  3. 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.
  4. 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.
  5. The JWT is then securely stored as an HTTP-only cookie named "flashjwt."


Authorization and Secure Routes:

  1. Once a user is authenticated, they can access secure routes within the application.
  2. 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.
  3. 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:

  1. 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.

  2. 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.

  3. 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.

  4. 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:

@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:

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:

@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

  1. HOOK: Points: 3.6-4.0 Reason:

  2. KNOWLEDGE: Points: 3.6-4.0 Reason:

  3. VALUE: Points: 0.6-1.0 Reason:

  4. WOW FACTOR: Reason:

jm1021 commented 10 months ago

Criteria/Key Features:

HOOK: Points: 3.6-4.0 Reason:

KNOWLEDGE: Points: 3.6-4.0 Reason:

VALUE: Points: 0.6-1.0 Reason:

WOW FACTOR: Reason:

anawandh commented 10 months ago

Criteria/Key Features:

HOOK: 3.94 Points: 3.6-4.0 Reason: Their hook clearly defined the problem they are trying to solve. They described it well and was attention grabbing.

KNOWLEDGE: 3.8 Points: 3.6-4.0 Reason: Thy showed the backend being updated with the assignment. One place to improve is to show the backend as a site deployed and not on AWS.

VALUE: 1 Points: 0.6-1.0 Reason: Very good problem to solve as it makes a del norte specific site. Easier for teachers

WOW FACTOR: Reason: The stats and showing the teacher website on their fronted are good factors.

8.74/9

STG-7 commented 10 months ago

HOOK: 3.95 Points: 3.6-4.0 Reason:

KNOWLEDGE: 3.9 Points: 3.6-4.0 Reason:

VALUE: 1.0 Points: 0.6-1.0 Reason:

WOW FACTOR: Reason:

8.85/9

tanayp327 commented 10 months ago

Criteria/Key Features:

HOOK: Points: 3.85 Reason: I liked the UI and the way they brought me in as someone who is a student.

KNOWLEDGE: Points: 4.0 Reason: They went in depth with the backend, talking about the data that they store about the assignments and the security needed to make sure students and teachers don't access each other's stuff.

VALUE: Points: 1 Reason: It is a very valuable project, useful for students in CS to submit their assignments, I think Mr. Mort would love to use this.

WOW FACTOR: Reason: I love the project, they basically made Canvas for Computer Science students

8.85/9

safinsingh commented 10 months ago

Criteria/Key Features:

HOOK: Points: 3.9 Reason: Great hook with an introduction describing your ideas and the value of your project

KNOWLEDGE: Points: 3.5 Reason: Decent knowledge about key technicals and very amazing blogs documenting progress and issues

VALUE: Points: 0.9 Reason: Good value with a good purpose and vision for integration in the classroom

WOW FACTOR: N/A Reason:

jm1021 commented 10 months ago

Criteria/Key Features:

HOOK: Points: 3.6-4.0 Reason: Hub for student work.

KNOWLEDGE: Points: 3.6-4.0 Reason: Discussed different level of users. Shared CRUD operations. Shared blogging page.

VALUE: Points: 0.6-1.0 Reason: New canvas/teacher combination site.

WOW FACTOR: Reason: Stats to grades.

9.1/10, all the right stuff is just a bit disconnected.

AniCricKet commented 10 months ago

Criteria/Key Features:

HOOK: Points: 3.6-4.0 Reason: Granting more accessibility to the large amounts of coding options we have in our classroom 3.9

KNOWLEDGE: Points: 3.6-4.0 Reason: Talked about verifying users and deciding between person and teacher. Teachers are verified and can chat with other users. Wide variety of code and knowledge of backend aspects 3.9

VALUE: Points: 0.6-1.0 Reason: Provide a wide variety of options such as a github stats checker/grader , jwt token gen, and 1

WOW FACTOR: Reason: No agile but pretty engaging

8.8/9

AdiBricks commented 10 months ago

image

(Extra Credit For Aditya R) Criteria/Key Features: Frontend - Done Backend - Done API - Done Agile - Done HOOK: Points: 3.5 Reason: Underwhelming but inclusive and intriguing.

KNOWLEDGE: Points: 4.0 Reason: Knew everything like the back of their hands, very knowledgeable.

VALUE: Points: 0.75 Reason: Nothing too surprising and somewhat of a basic website.

overall: 8.25/9

ad1tyad3sa1 commented 10 months ago

Criteria/Key Features:

HOOK: Points: 3.5-4.0 Reason: Allowed for interaction with the website, but limited.

KNOWLEDGE: Points: 4.0-4.0 Reason: Explained reasoning and code, pulled it up and answered questions in an understandable way.

VALUE: Points: 0.7-1.0 Reason: Seemed useful but could have been more interesting website.

WOW FACTOR: Reason: Stats of grades included and overall functionality worked.

8.2/9, website worked well, but could have been more engaging.

raunak2007 commented 10 months ago

Criteria/Key Features:

Frontend Backend API Database Agile, several students interacting with answering questions. HOOK: Points: 3.6-4.0 Reason: Interactive. Applicable to students 3.6

KNOWLEDGE: Points: 3.6-4.0 Reason: Shared 2 APIs, talked about classes. API takes a long time to load. 3.5

VALUE: Points: 0.6-1.0 Reason: Applicable to students. Very nice! .8

WOW FACTOR: Reason: Useful and applicable to students. 8.9/10