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

[Feature] Prize support for Challenges #3906

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

b9aurav
Copy link

@b9aurav b9aurav commented Mar 25, 2023

This pull request is for the addition of the challenge prizes feature [fixes #3893]. This feature will allow hosts to offer rewards to the top-performing participants in a challenge.

To add prizes to a challenge:

  1. Define the prizes configuration in the challenge configuration file. The prizes should be specified in the following format:
prizes:
  - rank: 1
    amount: '1000USD'
  - rank: 2
    amount: '500USD'
  - rank: 3
    amount: '100USD'

# It also allows amount in decimal format with any three-letter currency (e.g. '100.50EUR', '10000INR').
  1. The validation will check that the rank values are unique and amount values are formatted correctly.
  2. If the validation passes, the has_prizes attribute in the challenge model will be set to True.
    • The prizes will be displayed in a separate tab section on the challenge details page. Participants will be able to see the rank and prize amount.
  • If host do not want to add prizes to the challenge, simply remove the prizes from challenge configuration file. In this case, the has_prizes attribute will remain False, and the prize tab section will be removed from the challenge details page.

Here's Screenshot of hosted challenge with above 'prizes' configuration:

image

To implement this feature,

  • Added ChallengePrize model and serializer to handle prizes in challenges.
  • Added has_prizes attribute to the Challenge model class.
  • Modified create_or_update_github_challenge method to create and update prize objects from configuration file.
  • Added configuration file validation for direct zip upload.
  • Added config value validation to ensure appropriate values in challenge configuration.
  • Added get_prizes_by_challenge method and URL to retrieve prize objects via API call.
  • Added API Call to get prize data of a challenge in the backend.
  • Added frontend page route and display file for the Prize section.

This commit contains all API files and validation for challenge configuration to implement this feature.

Changes:
- models.py:
	Added has_prizes attribute in challenge model class to check whether challenge has prizes.
	Added new ChallengePrize model for prize.

- serializers.py
	Added ChallengePrizeSerializer class to serialize ChallengePrize model.

- views.py:
	Modified create_or_update_github_challenge method to create and update prize objects defined in YAML file.
	Modified ZIP config validation method to validate prize data in YAML file and to create prize objects.
	Added get_prizes_by_challenge method to return prizes objects of challenge to an API call.

- urls.py
	Added url to call API for fetching ChallengePrize objects.

- challenge_config_utils.py
	Added Prize validation to ensure appropriate values for prizes in challenge configuration.
This commit contains migration file of model changes.
This commit contains all backend changes.

Changes:
- challengeCtrl.js
	Added API Call to get prize data of a challenge.

- route-config.js
	Added frontend page route of Prize section.
This commit contains all frontend changes.

Changes:
- prize.html
	This frontend file is for display the challenge prizes.

- challenge-page.html
	Added tab for prize section in challenge page.
@b9aurav b9aurav force-pushed the challenge-prizes branch 2 times, most recently from d1209c6 to 1549331 Compare March 31, 2023 09:44
@codecov-commenter
Copy link

codecov-commenter commented Mar 31, 2023

Codecov Report

Merging #3906 (a0f23e0) into master (96968d6) will decrease coverage by 1.81%.
The diff coverage is 34.77%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##           master    #3906      +/-   ##
==========================================
- Coverage   72.93%   71.12%   -1.81%     
==========================================
  Files          83       20      -63     
  Lines        5368     3276    -2092     
==========================================
- Hits         3915     2330    -1585     
+ Misses       1453      946     -507     
Impacted Files Coverage Δ
frontend/src/js/controllers/authCtrl.js 53.91% <6.38%> (-12.95%) ⬇️
frontend/src/js/controllers/permissionCtrl.js 36.36% <22.22%> (-63.64%) ⬇️
frontend/src/js/controllers/challengeCtrl.js 62.79% <32.25%> (-10.91%) ⬇️
frontend/src/js/controllers/updateProfileCtrl.js 82.55% <44.44%> (-10.30%) ⬇️
frontend/src/js/controllers/profileCtrl.js 80.89% <45.45%> (-11.96%) ⬇️
...ntend/src/js/controllers/challengeHostTeamsCtrl.js 70.50% <66.66%> (-1.18%) ⬇️
frontend/src/js/controllers/teamsCtrl.js 71.17% <75.00%> (ø)
frontend/src/js/controllers/challengeListCtrl.js 95.74% <80.00%> (+1.06%) ⬆️
frontend/src/js/controllers/ChallengeInviteCtrl.js 100.00% <100.00%> (ø)
frontend/src/js/controllers/SubmissionFilesCtrl.js 95.45% <100.00%> (ø)
... and 5 more

... and 63 files with indirect coverage changes

Impacted Files Coverage Δ
frontend/src/js/controllers/authCtrl.js 53.91% <6.38%> (-12.95%) ⬇️
frontend/src/js/controllers/permissionCtrl.js 36.36% <22.22%> (-63.64%) ⬇️
frontend/src/js/controllers/challengeCtrl.js 62.79% <32.25%> (-10.91%) ⬇️
frontend/src/js/controllers/updateProfileCtrl.js 82.55% <44.44%> (-10.30%) ⬇️
frontend/src/js/controllers/profileCtrl.js 80.89% <45.45%> (-11.96%) ⬇️
...ntend/src/js/controllers/challengeHostTeamsCtrl.js 70.50% <66.66%> (-1.18%) ⬇️
frontend/src/js/controllers/teamsCtrl.js 71.17% <75.00%> (ø)
frontend/src/js/controllers/challengeListCtrl.js 95.74% <80.00%> (+1.06%) ⬆️
frontend/src/js/controllers/ChallengeInviteCtrl.js 100.00% <100.00%> (ø)
frontend/src/js/controllers/SubmissionFilesCtrl.js 95.45% <100.00%> (ø)
... and 5 more

... and 63 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 923fbf9...a0f23e0. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Prize Money to Challenges
2 participants