Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Programming exercises: Fix an issue where the result export does not work with structured grading criteria #10174

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

chrisknedl
Copy link
Contributor

@chrisknedl chrisknedl commented Jan 20, 2025

Checklist

General

Client

  • Important: I implemented the changes with a very good performance, prevented too many (unnecessary) REST calls and made sure the UI is responsive, even with large data (e.g. using paging).
  • I strictly followed the principle of data economy for all client-server REST calls.
  • I strictly followed the client coding and design guidelines.
  • Following the theming guidelines, I specified colors only in the theming variable files and checked that the changes look consistent in both the light and the dark theme.
  • I fixed the related test (Jest) (with a high test coverage), while following the test guidelines.
  • I documented the TypeScript code using JSDoc style.

Motivation and Context

Closes #10000

Description

The client assumed that the Java map is converted to a proper JS map. However, on deserialization, the map still is still in JSON format with key-value pairs. We first have to create a map with Object.entries() so that we can then call the Map.forEach() function. The test was also adapted to use the format that is actually received from the server.

Steps for Testing

Prerequisites:

  • An exercise with manual assessments and grading instructions.
  • One student submission that has been manually assessed while using grading instructions for the manually added feedback.
  1. Go to the scores list for the exercise.
  2. Top right: Export > Export Results.
  3. All three options should work (i.e. download a file).

Testserver States

Note

These badges show the state of the test servers.
Green = Currently available, Red = Currently locked
Click on the badges to get to the test servers.







Review Progress

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Test Coverage

Screenshots

Summary by CodeRabbit

  • Type Changes

    • Updated pointsPerCriterion property to support both Map and object representations.
    • Enhanced type flexibility for handling different data formats.
  • Type Safety Improvements

    • Added type checks in point retrieval methods to ensure correct data handling.
    • Improved handling of points per criterion across service and component layers.
  • Test Updates

    • Modified test cases to use a plain object for pointsPerCriterion, simplifying the data structure representation.

@chrisknedl chrisknedl self-assigned this Jan 20, 2025
@github-actions github-actions bot added tests client Pull requests that update TypeScript code. (Added Automatically!) labels Jan 20, 2025
@chrisknedl chrisknedl added programming Pull requests that affect the corresponding module assessment Pull requests that affect the corresponding module labels Jan 21, 2025
@chrisknedl chrisknedl marked this pull request as ready for review January 21, 2025 15:03
@chrisknedl chrisknedl requested a review from a team as a code owner January 21, 2025 15:03
@chrisknedl chrisknedl changed the title Programming exercises: Fix an issue where the result export did not work with structured grading criteria Programming exercises: Fix an issue where the result export does not work with structured grading criteria Jan 21, 2025
Copy link

coderabbitai bot commented Jan 21, 2025

Walkthrough

The pull request modifies the handling of the pointsPerCriterion property across multiple TypeScript files to improve flexibility and type safety. The pointsPerCriterion property in the ResultWithPointsPerGradingCriterion class has been updated to accept both a Map<GradingCriterionId, Points> and a plain object ({ [key: string]: number }). This change addresses issues related to exporting results, specifically resolving a TypeError that occurred when attempting to process incompatible data structures.

Changes

File Change Summary
src/main/webapp/app/entities/result-with-points-per-grading-criterion.model.ts Updated pointsPerCriterion type to support both Map<GradingCriterionId, Points> and { [key: string]: number }
src/main/webapp/app/exercises/shared/exercise-scores/exercise-scores-export-button.component.ts Added type check for pointsPerCriterion to ensure correct method access
src/main/webapp/app/exercises/shared/result/result.service.ts Modified convertResultsWithPointsResponse to use Object.entries() for processing points per criterion
src/test/javascript/spec/service/result.service.spec.ts Updated test case to use object literal for pointsPerCriterion

Assessment against linked issues

Objective Addressed Explanation
Result export functionality
Handle different data structures for points per criterion
Resolve TypeError in export process

Possibly related PRs

Suggested labels

server, ready to merge

Suggested reviewers

  • BBesrour
  • az108
  • krusche
  • EneaGore
  • SimonEntholzer

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a8aab26 and a8c1b50.

📒 Files selected for processing (1)
  • src/main/webapp/app/exercises/shared/exercise-scores/exercise-scores-export-button.component.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/webapp/app/exercises/shared/exercise-scores/exercise-scores-export-button.component.ts
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: client-tests-selected
  • GitHub Check: client-tests
  • GitHub Check: server-style
  • GitHub Check: server-tests
  • GitHub Check: Build and Push Docker Image
  • GitHub Check: Analyse
  • GitHub Check: Build .war artifact

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
src/main/webapp/app/entities/result-with-points-per-grading-criterion.model.ts (1)

9-10: LGTM! Consider using a type alias for better maintainability.

The union type correctly handles both JSON objects and Maps, addressing the deserialization issue. The comment clearly explains the rationale.

Consider extracting the union type to a type alias for better reusability:

+type PointsPerCriterion = { [key: string]: number } | Map<GradingCriterionId, Points>;
+
 export class ResultWithPointsPerGradingCriterion {
     result: Result;
     totalPoints: Points;
-    pointsPerCriterion: { [key: string]: number } | Map<GradingCriterionId, Points>;
+    pointsPerCriterion: PointsPerCriterion;
 }
src/main/webapp/app/exercises/shared/result/result.service.ts (1)

263-264: LGTM! Consider adding error handling for invalid keys.

The change correctly handles the JSON format from the server. The use of Object.entries() and the unary plus operator for key conversion is appropriate.

Consider adding validation for key conversion:

     Object.entries(resultWithPoints.pointsPerCriterion).forEach(([key, value]) => {
-        pointsMap.set(+key, value);
+        const numericKey = +key;
+        if (Number.isFinite(numericKey)) {
+            pointsMap.set(numericKey, value);
+        } else {
+            console.warn(`Invalid criterion ID: ${key}`);
+        }
     });
src/test/javascript/spec/service/result.service.spec.ts (1)

158-158: LGTM! Consider adding edge case tests.

The test data correctly reflects the JSON format received from the server. The verification of the conversion to Map is appropriate.

Consider adding test cases for edge cases:

// Test empty object
resultWithPoints3.pointsPerCriterion = {};

// Test invalid keys
resultWithPoints4.pointsPerCriterion = { 'invalid': 20, '2': 30 };

// Test invalid values
resultWithPoints5.pointsPerCriterion = { '1': null, '2': undefined };
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1543e3e and a8aab26.

📒 Files selected for processing (4)
  • src/main/webapp/app/entities/result-with-points-per-grading-criterion.model.ts (1 hunks)
  • src/main/webapp/app/exercises/shared/exercise-scores/exercise-scores-export-button.component.ts (1 hunks)
  • src/main/webapp/app/exercises/shared/result/result.service.ts (1 hunks)
  • src/test/javascript/spec/service/result.service.spec.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
src/test/javascript/spec/service/result.service.spec.ts (1)

Pattern src/test/javascript/spec/**/*.ts: jest: true; mock: NgMocks; bad_practices: avoid_full_module_import; perf_improvements: mock_irrelevant_deps; service_testing: mock_http_for_logic; no_schema: avoid_NO_ERRORS_SCHEMA; expectation_specificity: true; solutions: {boolean: toBeTrue/False, reference: toBe, existence: toBeNull/NotNull, undefined: toBeUndefined, class_obj: toContainEntries/toEqual, spy_calls: {not_called: not.toHaveBeenCalled, once: toHaveBeenCalledOnce, with_value: toHaveBeenCalledWith|toHaveBeenCalledExactlyOnceWith}}

src/main/webapp/app/exercises/shared/exercise-scores/exercise-scores-export-button.component.ts (1)

Pattern src/main/webapp/**/*.ts: angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

src/main/webapp/app/entities/result-with-points-per-grading-criterion.model.ts (1)

Pattern src/main/webapp/**/*.ts: angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

src/main/webapp/app/exercises/shared/result/result.service.ts (1)

Pattern src/main/webapp/**/*.ts: angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Codacy Static Code Analysis

Copy link

coderabbitai bot commented Jan 21, 2025

Walkthrough

The pull request addresses an issue with result export functionality by modifying the handling of pointsPerCriterion across multiple TypeScript files. The changes introduce a more flexible type definition that can accommodate both Map and plain object representations of points per grading criterion. This modification aims to resolve compatibility issues when deserializing data from the server, specifically addressing type conversion and access problems in the result export process.

Changes

File Change Summary
src/main/webapp/app/entities/result-with-points-per-grading-criterion.model.ts Updated pointsPerCriterion type to support both Map and plain object representations
src/main/webapp/app/exercises/shared/exercise-scores/exercise-scores-export-button.component.ts Added type assertion for pointsPerCriterion to ensure Map method access
src/main/webapp/app/exercises/shared/result/result.service.ts Modified points conversion logic to handle object entries and ensure numeric keys
src/test/javascript/spec/service/result.service.spec.ts Updated test case to use plain object for pointsPerCriterion

Assessment against linked issues

Objective Addressed Explanation
Result export functionality
Handle different data formats for points
Resolve TypeError in export process

Possibly related PRs

Suggested labels

server, ready to merge

Suggested reviewers

  • BBesrour
  • LeonWehrhahn
  • HawKhiem
  • SimonEntholzer
  • eceeeren
  • krusche
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
src/main/webapp/app/entities/result-with-points-per-grading-criterion.model.ts (1)

9-10: LGTM! Consider enhancing the comment.

The type union effectively addresses the deserialization issue. The comment explains the reason for the change, but could be more specific about the data flow.

Consider expanding the comment to be more specific:

-    // type union is needed here, because deserialized java maps are actually represented as plain JSON key-value pairs
+    // Type union is needed here because Java maps are deserialized from the server as plain JSON key-value pairs instead of JavaScript Map objects
src/main/webapp/app/exercises/shared/result/result.service.ts (1)

263-264: LGTM! Consider adding error handling.

The conversion from plain object to Map is implemented correctly. However, it might be good to add error handling for invalid numeric keys.

Consider adding validation:

     Object.entries(resultWithPoints.pointsPerCriterion).forEach(([key, value]) => {
+        const numericKey = +key;
+        if (Number.isNaN(numericKey)) {
+            console.warn(`Invalid numeric key in pointsPerCriterion: ${key}`);
+            return;
+        }
-        pointsMap.set(+key, value);
+        pointsMap.set(numericKey, value);
     });
src/test/javascript/spec/service/result.service.spec.ts (1)

158-158: LGTM! Consider adding more test cases.

The test data now correctly reflects the server response format. However, we could improve test coverage.

Consider adding these test cases:

  1. Invalid numeric keys: { 'abc': 20 }
  2. Empty object: {}
  3. Null/undefined values: { '1': null }
  4. Already a Map (edge case): new Map([[1, 20]])
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1543e3e and a8aab26.

📒 Files selected for processing (4)
  • src/main/webapp/app/entities/result-with-points-per-grading-criterion.model.ts (1 hunks)
  • src/main/webapp/app/exercises/shared/exercise-scores/exercise-scores-export-button.component.ts (1 hunks)
  • src/main/webapp/app/exercises/shared/result/result.service.ts (1 hunks)
  • src/test/javascript/spec/service/result.service.spec.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
src/main/webapp/app/exercises/shared/exercise-scores/exercise-scores-export-button.component.ts (1)

Pattern src/main/webapp/**/*.ts: angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

src/test/javascript/spec/service/result.service.spec.ts (1)

Pattern src/test/javascript/spec/**/*.ts: jest: true; mock: NgMocks; bad_practices: avoid_full_module_import; perf_improvements: mock_irrelevant_deps; service_testing: mock_http_for_logic; no_schema: avoid_NO_ERRORS_SCHEMA; expectation_specificity: true; solutions: {boolean: toBeTrue/False, reference: toBe, existence: toBeNull/NotNull, undefined: toBeUndefined, class_obj: toContainEntries/toEqual, spy_calls: {not_called: not.toHaveBeenCalled, once: toHaveBeenCalledOnce, with_value: toHaveBeenCalledWith|toHaveBeenCalledExactlyOnceWith}}

src/main/webapp/app/entities/result-with-points-per-grading-criterion.model.ts (1)

Pattern src/main/webapp/**/*.ts: angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

src/main/webapp/app/exercises/shared/result/result.service.ts (1)

Pattern src/main/webapp/**/*.ts: angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Codacy Static Code Analysis

@github-actions github-actions bot removed assessment Pull requests that affect the corresponding module programming Pull requests that affect the corresponding module labels Jan 21, 2025
Copy link

⚠️ Unable to deploy to test servers ⚠️

Testserver "artemis-test1.artemis.cit.tum.de" is already in use by PR #10156.

@github-actions github-actions bot added the deployment-error Added by deployment workflows if an error occured label Jan 22, 2025
@github-actions github-actions bot removed the deployment-error Added by deployment workflows if an error occured label Jan 22, 2025
@HawKhiem HawKhiem temporarily deployed to artemis-test5.artemis.cit.tum.de January 22, 2025 14:08 — with GitHub Actions Inactive
Copy link

@zagemello zagemello left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on TS5, all works as expected:
image

Copy link

@Cathy0123456789 Cathy0123456789 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on TS5. All three options work

Copy link

@HawKhiem HawKhiem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on TS5. Works as described

Copy link

@sachmii sachmii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on TS5, works fine.

@Longppham
Copy link

Tested on TS5

Worked as expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix client Pull requests that update TypeScript code. (Added Automatically!) ready for review tests
Projects
Status: Ready For Review
Development

Successfully merging this pull request may close these issues.

Result export does not work
8 participants